From b6745b2906002938472d142c6d376f4664d04838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Tue, 7 Sep 2021 17:39:12 +0200 Subject: [PATCH] Renderer: Fix A8, L8 and LA8 support for both OpenGL and Vulkan --- include/Nazara/OpenGLRenderer/Utils.inl | 4 +++- src/Nazara/OpenGLRenderer/OpenGLTexture.cpp | 12 ++++++++++++ src/Nazara/VulkanRenderer/VulkanTexture.cpp | 13 +++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/Nazara/OpenGLRenderer/Utils.inl b/include/Nazara/OpenGLRenderer/Utils.inl index 7b85e519d..303c3a20f 100644 --- a/include/Nazara/OpenGLRenderer/Utils.inl +++ b/include/Nazara/OpenGLRenderer/Utils.inl @@ -15,7 +15,7 @@ namespace Nz // TODO: Fill this switch switch (pixelFormat) { - case PixelFormat::A8: return GLTextureFormat{ GL_R8, GL_RED, GL_UNSIGNED_BYTE, GL_ZERO, GL_ZERO, GL_ZERO, GL_RED }; + case PixelFormat::A8: return GLTextureFormat{ GL_R8, GL_RED, GL_UNSIGNED_BYTE, GL_ONE, GL_ONE, GL_ONE, GL_RED }; case PixelFormat::BGR8: return GLTextureFormat{ GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, GL_BLUE, GL_GREEN, GL_RED, GL_ONE }; case PixelFormat::BGR8_SRGB: return GLTextureFormat{ GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE, GL_BLUE, GL_GREEN, GL_RED, GL_ONE }; case PixelFormat::BGRA8: return GLTextureFormat{ GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA }; @@ -24,6 +24,8 @@ namespace Nz case PixelFormat::Depth24Stencil8: return GLTextureFormat{ GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_RED, GL_GREEN, GL_ZERO, GL_ZERO }; case PixelFormat::Depth32F: return GLTextureFormat{ GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT, GL_RED, GL_ZERO, GL_ZERO, GL_ZERO }; case PixelFormat::Depth32FStencil8: return GLTextureFormat{ GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_RED, GL_GREEN, GL_ZERO, GL_ZERO }; + case PixelFormat::L8: return GLTextureFormat{ GL_R8, GL_RED, GL_UNSIGNED_BYTE, GL_RED, GL_RED, GL_RED, GL_ONE }; + case PixelFormat::LA8: return GLTextureFormat{ GL_RG8, GL_RG, GL_UNSIGNED_BYTE, GL_RED, GL_RED, GL_RED, GL_GREEN }; case PixelFormat::RGB8: return GLTextureFormat{ GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, GL_RED, GL_GREEN, GL_BLUE, GL_ONE }; case PixelFormat::RGB8_SRGB: return GLTextureFormat{ GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE, GL_RED, GL_GREEN, GL_BLUE, GL_ONE }; case PixelFormat::RGBA8: return GLTextureFormat{ GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA }; diff --git a/src/Nazara/OpenGLRenderer/OpenGLTexture.cpp b/src/Nazara/OpenGLRenderer/OpenGLTexture.cpp index 8866598fe..91e5e6a2f 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLTexture.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLTexture.cpp @@ -78,6 +78,18 @@ namespace Nz auto format = DescribeTextureFormat(m_params.pixelFormat); assert(format); + const GL::Context& context = m_texture.EnsureDeviceContext(); + + UInt8 bpp = PixelFormatInfo::GetBytesPerPixel(m_params.pixelFormat); + if (bpp % 8 == 0) + context.glPixelStorei(GL_UNPACK_ALIGNMENT, 8); + else if (bpp % 4 == 0) + context.glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + else if (bpp % 2 == 0) + context.glPixelStorei(GL_UNPACK_ALIGNMENT, 2); + else + context.glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + switch (m_params.type) { case ImageType::E1D: diff --git a/src/Nazara/VulkanRenderer/VulkanTexture.cpp b/src/Nazara/VulkanRenderer/VulkanTexture.cpp index 200ffad84..e4911e4b3 100644 --- a/src/Nazara/VulkanRenderer/VulkanTexture.cpp +++ b/src/Nazara/VulkanRenderer/VulkanTexture.cpp @@ -249,6 +249,19 @@ namespace Nz // TODO: Fill this switch switch (pixelFormat) { + case PixelFormat::A8: + { + createImage.format = VK_FORMAT_R8_UNORM; + createImageView.format = createImage.format; + createImageView.components = { + VK_COMPONENT_SWIZZLE_ONE, + VK_COMPONENT_SWIZZLE_ONE, + VK_COMPONENT_SWIZZLE_ONE, + VK_COMPONENT_SWIZZLE_R + }; + break; + } + case PixelFormat::BGR8: case PixelFormat::BGR8_SRGB: case PixelFormat::BGRA8: