From: David Steele Date: Wed, 12 May 2021 10:30:05 +0000 (+0100) Subject: Using correct internal formats for image uploading X-Git-Tag: dali_2.0.28~3^2~5^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F25%2F258225%2F2;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git Using correct internal formats for image uploading Adding packed small float pixel format KTX supports packed small float pixel format, adding to DALi pixel format. Modified texture upload to ensure the right internal format is used for the destination texture, and the right method is chosen for uploading cube map image. Change-Id: I877ec5e5573c5f0482afc2b6c201ea8dda032cdc Signed-off-by: David Steele --- diff --git a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-texture.cpp b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-texture.cpp index adeeeca..9e1ad3e 100644 --- a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-texture.cpp +++ b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-texture.cpp @@ -183,6 +183,7 @@ bool IsCompressedFormat(Graphics::Format pixelFormat) case Graphics::Format::R64G64B64A64_SINT: case Graphics::Format::R64G64B64A64_SFLOAT: case Graphics::Format::B10G11R11_UFLOAT_PACK32: + case Graphics::Format::R11G11B10_UFLOAT_PACK32: case Graphics::Format::E5B9G9R9_UFLOAT_PACK32: case Graphics::Format::D16_UNORM: case Graphics::Format::X8_D24_UNORM_PACK32: @@ -618,6 +619,12 @@ void PixelFormatToGl(Graphics::Format pixelFormat, GLenum& glFormat, GLint& glIn glFormat = 0; break; } + case Graphics::Format::R11G11B10_UFLOAT_PACK32: + { + glFormat = GL_RGB; + pixelDataType = GL_FLOAT; + break; + } case Graphics::Format::R4G4_UNORM_PACK8: case Graphics::Format::A1R5G5B5_UNORM_PACK16: @@ -768,6 +775,7 @@ void PixelFormatToGl(Graphics::Format pixelFormat, GLenum& glFormat, GLint& glIn { case Graphics::Format::R16G16B16A16_SFLOAT: case Graphics::Format::R32G32B32A32_SFLOAT: + case Graphics::Format::R11G11B10_UFLOAT_PACK32: { glInternalFormat = GL_R11F_G11F_B10F; break; diff --git a/dali/internal/graphics/gles-impl/egl-graphics-controller.cpp b/dali/internal/graphics/gles-impl/egl-graphics-controller.cpp index e75727e..cec007e 100644 --- a/dali/internal/graphics/gles-impl/egl-graphics-controller.cpp +++ b/dali/internal/graphics/gles-impl/egl-graphics-controller.cpp @@ -563,11 +563,12 @@ void EglGraphicsController::ProcessTextureUpdateQueue() // GPU memory must be already allocated. // Check if it needs conversion - auto* texture = static_cast(info.dstTexture); - const auto& createInfo = texture->GetCreateInfo(); - auto srcFormat = GLES::GLTextureFormatType(info.srcFormat).format; - auto destFormat = GLES::GLTextureFormatType(createInfo.format).format; - auto destType = GLES::GLTextureFormatType(createInfo.format).type; + auto* texture = static_cast(info.dstTexture); + const auto& createInfo = texture->GetCreateInfo(); + auto srcFormat = GLES::GLTextureFormatType(info.srcFormat).format; + auto srcType = GLES::GLTextureFormatType(info.srcFormat).type; + auto destInternalFormat = GLES::GLTextureFormatType(createInfo.format).internalFormat; + auto destFormat = GLES::GLTextureFormatType(createInfo.format).format; // From render-texture.cpp const bool isSubImage(info.dstOffset2D.x != 0 || info.dstOffset2D.y != 0 || @@ -581,56 +582,49 @@ void EglGraphicsController::ProcessTextureUpdateQueue() // Convert RGB to RGBA if necessary. texture->TryConvertPixelData(source.memorySource.memory, info.srcFormat, createInfo.format, info.srcSize, info.srcExtent2D.width, info.srcExtent2D.height, tempBuffer); sourceBuffer = &tempBuffer[0]; + srcFormat = destFormat; + srcType = GLES::GLTextureFormatType(createInfo.format).type; } // Calculate the maximum mipmap level for the texture texture->SetMaxMipMapLevel(std::max(texture->GetMaxMipMapLevel(), info.level)); - switch(createInfo.textureType) - { - // Texture 2D - case Graphics::TextureType::TEXTURE_2D: - { - mGlAbstraction->PixelStorei(GL_UNPACK_ALIGNMENT, 1); - - mGlAbstraction->BindTexture(GL_TEXTURE_2D, texture->GetGLTexture()); - - mGlAbstraction->TexSubImage2D(GL_TEXTURE_2D, - info.level, - info.dstOffset2D.x, - info.dstOffset2D.y, - info.srcExtent2D.width, - info.srcExtent2D.height, - destFormat, - destType, - sourceBuffer); - break; - } - // Texture Cubemap - case Graphics::TextureType::TEXTURE_CUBEMAP: - { - mGlAbstraction->PixelStorei(GL_UNPACK_ALIGNMENT, 1); + GLenum bindTarget{GL_TEXTURE_2D}; + GLenum target{GL_TEXTURE_2D}; - mGlAbstraction->BindTexture(GL_TEXTURE_CUBE_MAP, texture->GetGLTexture()); + if(createInfo.textureType == Graphics::TextureType::TEXTURE_CUBEMAP) + { + bindTarget = GL_TEXTURE_CUBE_MAP; + target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + info.layer; + } - mGlAbstraction->TexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + info.layer, - info.level, - info.dstOffset2D.x, - info.dstOffset2D.y, - info.srcExtent2D.width, - info.srcExtent2D.height, - destFormat, - destType, - sourceBuffer); + mGlAbstraction->PixelStorei(GL_UNPACK_ALIGNMENT, 1); + mGlAbstraction->BindTexture(bindTarget, texture->GetGLTexture()); - break; - } - default: - { - // nothing? - } + if(!isSubImage) + { + mGlAbstraction->TexImage2D(target, + info.level, + destInternalFormat, + info.srcExtent2D.width, + info.srcExtent2D.height, + 0, + srcFormat, + srcType, + sourceBuffer); + } + else + { + mGlAbstraction->TexSubImage2D(target, + info.level, + info.dstOffset2D.x, + info.dstOffset2D.y, + info.srcExtent2D.width, + info.srcExtent2D.height, + srcFormat, + srcType, + sourceBuffer); } - // free staging memory free(source.memorySource.memory); } diff --git a/dali/internal/graphics/gles-impl/gles-graphics-texture.cpp b/dali/internal/graphics/gles-impl/gles-graphics-texture.cpp index 7cd0d02..bb1dd30 100644 --- a/dali/internal/graphics/gles-impl/gles-graphics-texture.cpp +++ b/dali/internal/graphics/gles-impl/gles-graphics-texture.cpp @@ -189,7 +189,7 @@ bool Texture::InitializeTexture() // Allocate memory for the texture gl->TexImage2D(GL_TEXTURE_2D, 0, - format.format, + format.internalFormat, mCreateInfo.size.width, mCreateInfo.size.height, 0, @@ -231,7 +231,7 @@ bool Texture::InitializeTexture() { gl->TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, - format.format, + format.internalFormat, mCreateInfo.size.width, mCreateInfo.size.height, 0, diff --git a/dali/internal/graphics/gles-impl/gles-graphics-types.h b/dali/internal/graphics/gles-impl/gles-graphics-types.h index 141fba1..6b232cb 100644 --- a/dali/internal/graphics/gles-impl/gles-graphics-types.h +++ b/dali/internal/graphics/gles-impl/gles-graphics-types.h @@ -548,7 +548,7 @@ struct GLTextureFormatType case Graphics::Format::R16G16B16_SFLOAT: { // GLES 3.0 floating point formats. - Assign(GL_RGB, GL_HALF_FLOAT); + AssignInternal(GL_RGB, GL_R11F_G11F_B10F, GL_HALF_FLOAT); // DALi uses compact internal format break; } case Graphics::Format::R16G16B16A16_UNORM: @@ -628,8 +628,7 @@ struct GLTextureFormatType } case Graphics::Format::R32G32B32_SFLOAT: { - // GLES 3.0 floating point formats. - Assign(GL_RGB, GL_FLOAT); + AssignInternal(GL_RGB, GL_R11F_G11F_B10F, GL_FLOAT); // DALi uses compact internal format break; } case Graphics::Format::R32G32B32A32_UINT: @@ -707,6 +706,11 @@ struct GLTextureFormatType Assign(0, 0); break; } + case Graphics::Format::R11G11B10_UFLOAT_PACK32: + { + AssignInternal(GL_RGB, GL_R11F_G11F_B10F, GL_FLOAT); + break; + } case Graphics::Format::B10G11R11_UFLOAT_PACK32: { Assign(0, 0); @@ -731,7 +735,7 @@ struct GLTextureFormatType case Graphics::Format::D32_SFLOAT: { // GLES 3.0 depth and stencil formats - Assign(GL_DEPTH_COMPONENT, GL_FLOAT); + AssignInternal(GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT32F, GL_FLOAT); break; } case Graphics::Format::S8_UINT: @@ -747,7 +751,7 @@ struct GLTextureFormatType case Graphics::Format::D24_UNORM_S8_UINT: { // GLES 3.0 depth and stencil formats - Assign(GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8); + AssignInternal(GL_DEPTH_STENCIL, GL_DEPTH24_STENCIL8, GL_UNSIGNED_INT_24_8); break; } case Graphics::Format::D32_SFLOAT_S8_UINT: @@ -1108,11 +1112,19 @@ struct GLTextureFormatType constexpr inline void Assign(uint32_t f, uint32_t t) { - format = f; - type = t; + format = f; + internalFormat = f; + type = t; + } + constexpr inline void AssignInternal(uint32_t f, uint32_t i, uint32_t t) + { + format = f; + internalFormat = i; + type = t; } uint32_t format{0}; + uint32_t internalFormat{0}; uint32_t type{0}; }; diff --git a/dali/internal/imaging/common/pixel-manipulation.cpp b/dali/internal/imaging/common/pixel-manipulation.cpp index 9c3f526..e4c3fe0 100644 --- a/dali/internal/imaging/common/pixel-manipulation.cpp +++ b/dali/internal/imaging/common/pixel-manipulation.cpp @@ -328,6 +328,7 @@ bool HasChannel(Dali::Pixel::Format pixelFormat, Channel channel) case Dali::Pixel::BGR8888: case Dali::Pixel::RGB16F: case Dali::Pixel::RGB32F: + case Dali::Pixel::R11G11B10F: { return (channel == RED || channel == GREEN || channel == BLUE); }