From 8c90d7b3d02277c730fe1c277f715de6ea2904e2 Mon Sep 17 00:00:00 2001 From: Benau Date: Thu, 13 Apr 2023 12:56:06 +0800 Subject: [PATCH] Fix missing srgb for compressed textures --- lib/graphics_engine/src/ge_vulkan_texture.cpp | 7 ++++--- lib/graphics_engine/src/ge_vulkan_texture.hpp | 13 +++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/graphics_engine/src/ge_vulkan_texture.cpp b/lib/graphics_engine/src/ge_vulkan_texture.cpp index 9e0a4ef0b..c3d977ec7 100644 --- a/lib/graphics_engine/src/ge_vulkan_texture.cpp +++ b/lib/graphics_engine/src/ge_vulkan_texture.cpp @@ -291,7 +291,7 @@ bool GEVulkanTexture::createImage(VkImageUsageFlags usage) if (m_image_view_type == VK_IMAGE_VIEW_TYPE_CUBE || m_image_view_type == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) image_info.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; - if (m_internal_format == VK_FORMAT_R8G8B8A8_UNORM) + if (m_internal_format != getSRGBformat(m_internal_format)) image_info.flags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; m_vma_info = {}; @@ -449,10 +449,11 @@ bool GEVulkanTexture::createImageView(VkImageAspectFlags aspect_flags) { image_view.get()->store(view_ptr); m_image_view = image_view; - if (m_internal_format == VK_FORMAT_R8G8B8A8_UNORM) + VkFormat srgb_format = getSRGBformat(m_internal_format); + if (m_internal_format != srgb_format) { image_view = std::make_shared >(); - view_info.format = VK_FORMAT_R8G8B8A8_SRGB; + view_info.format = srgb_format; view_ptr = VK_NULL_HANDLE; if (vkCreateImageView(m_vulkan_device, &view_info, NULL, &view_ptr) == VK_SUCCESS) diff --git a/lib/graphics_engine/src/ge_vulkan_texture.hpp b/lib/graphics_engine/src/ge_vulkan_texture.hpp index 9ba9426d3..a0973d986 100644 --- a/lib/graphics_engine/src/ge_vulkan_texture.hpp +++ b/lib/graphics_engine/src/ge_vulkan_texture.hpp @@ -67,6 +67,19 @@ protected: GEVulkanDriver* m_vk; + // ------------------------------------------------------------------------ + VkFormat getSRGBformat(VkFormat format) + { + if (format == VK_FORMAT_R8G8B8A8_UNORM) + return VK_FORMAT_R8G8B8A8_SRGB; + else if (format == VK_FORMAT_ASTC_4x4_UNORM_BLOCK) + return VK_FORMAT_ASTC_4x4_SRGB_BLOCK; + else if (format == VK_FORMAT_BC7_UNORM_BLOCK) + return VK_FORMAT_BC7_SRGB_BLOCK; + else if (format == VK_FORMAT_BC3_UNORM_BLOCK) + return VK_FORMAT_BC3_SRGB_BLOCK; + return format; + } // ------------------------------------------------------------------------ bool createTextureImage(uint8_t* texture_data, bool generate_hq_mipmap); // ------------------------------------------------------------------------