SVACE fix in gles-graphics-texture.cpp
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles-impl / gles-graphics-texture.cpp
index 9b997c6..cd4b66d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -204,29 +204,32 @@ bool Texture::InitializeTexture()
         gl->GenTextures(1, &texture);
         context->BindTexture(GL_TEXTURE_2D, GetTextureTypeId(), texture);
 
-        // Allocate memory for the texture
-        if(!mIsCompressed)
+        if(mCreateInfo.allocationPolicy == Graphics::TextureAllocationPolicy::CREATION || mCreateInfo.data)
         {
-          gl->TexImage2D(GL_TEXTURE_2D,
-                         0,
-                         format.internalFormat,
-                         mCreateInfo.size.width,
-                         mCreateInfo.size.height,
-                         0,
-                         format.format,
-                         format.type,
-                         (mCreateInfo.data ? mStagingBuffer.data() : nullptr));
-        }
-        else
-        {
-          gl->CompressedTexImage2D(GL_TEXTURE_2D,
-                                   0,
-                                   format.internalFormat,
-                                   mCreateInfo.size.width,
-                                   mCreateInfo.size.height,
-                                   0,
-                                   mCreateInfo.dataSize,
-                                   (mCreateInfo.data ? mStagingBuffer.data() : nullptr));
+          // Allocate memory for the texture
+          if(!mIsCompressed)
+          {
+            gl->TexImage2D(GL_TEXTURE_2D,
+                           0,
+                           format.internalFormat,
+                           mCreateInfo.size.width,
+                           mCreateInfo.size.height,
+                           0,
+                           format.format,
+                           format.type,
+                           (mCreateInfo.data ? mStagingBuffer.data() : nullptr));
+          }
+          else
+          {
+            gl->CompressedTexImage2D(GL_TEXTURE_2D,
+                                     0,
+                                     format.internalFormat,
+                                     mCreateInfo.size.width,
+                                     mCreateInfo.size.height,
+                                     0,
+                                     mCreateInfo.dataSize,
+                                     (mCreateInfo.data ? mStagingBuffer.data() : nullptr));
+          }
         }
 
         // Clear staging buffer if there was any
@@ -257,31 +260,34 @@ bool Texture::InitializeTexture()
         SetSamplerParameter(GL_TEXTURE_WRAP_S, mDefaultSamplerState.wrapS, GL_WRAP_DEFAULT);
         SetSamplerParameter(GL_TEXTURE_WRAP_T, mDefaultSamplerState.wrapT, GL_WRAP_DEFAULT);
 
-        // Allocate memory for the texture
-        for(uint32_t i = 0; i < 6; ++i)
+        if(mCreateInfo.allocationPolicy == Graphics::TextureAllocationPolicy::CREATION || mCreateInfo.data)
         {
-          if(!mIsCompressed)
+          // Allocate memory for the texture
+          for(uint32_t i = 0; i < 6; ++i)
           {
-            gl->TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
-                           0,
-                           format.internalFormat,
-                           mCreateInfo.size.width,
-                           mCreateInfo.size.height,
-                           0,
-                           format.format,
-                           format.type,
-                           (mCreateInfo.data ? mStagingBuffer.data() : nullptr));
-          }
-          else
-          {
-            gl->CompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
-                                     0,
-                                     format.internalFormat,
-                                     mCreateInfo.size.width,
-                                     mCreateInfo.size.height,
-                                     0,
-                                     mCreateInfo.dataSize,
-                                     (mCreateInfo.data ? mStagingBuffer.data() : nullptr));
+            if(!mIsCompressed)
+            {
+              gl->TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
+                             0,
+                             format.internalFormat,
+                             mCreateInfo.size.width,
+                             mCreateInfo.size.height,
+                             0,
+                             format.format,
+                             format.type,
+                             (mCreateInfo.data ? mStagingBuffer.data() : nullptr));
+            }
+            else
+            {
+              gl->CompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
+                                       0,
+                                       format.internalFormat,
+                                       mCreateInfo.size.width,
+                                       mCreateInfo.size.height,
+                                       0,
+                                       mCreateInfo.dataSize,
+                                       (mCreateInfo.data ? mStagingBuffer.data() : nullptr));
+            }
           }
         }
 
@@ -346,6 +352,12 @@ void Texture::Bind(const TextureBinding& binding) const
 
     auto mipMapMode = samplerCreateInfo.mipMapMode;
 
+    // @todo : Should we always ignore mipmap mode when it is compressed, and never bind higher level mipmap?
+    if(mMaxMipMapLevel == 0u && mIsCompressed)
+    {
+      mipMapMode = Graphics::SamplerMipmapMode::NONE;
+    }
+
     SetSamplerParameter(GL_TEXTURE_MIN_FILTER, mDefaultSamplerState.minFilter, GLSamplerFilterAndMipMapMode(samplerCreateInfo.minFilter, mipMapMode).glFilter);
     SetSamplerParameter(GL_TEXTURE_MAG_FILTER, mDefaultSamplerState.magFilter, GLSamplerFilter(samplerCreateInfo.magFilter).glFilter);
     SetSamplerParameter(GL_TEXTURE_WRAP_S, mDefaultSamplerState.wrapS, GLAddressMode(samplerCreateInfo.addressModeU).texParameter);
@@ -379,14 +391,6 @@ void Texture::Prepare()
   NativeImageInterfacePtr nativeImage = mCreateInfo.nativeImagePtr;
   if(nativeImage)
   {
-    if(nativeImage->SourceChanged())
-    {
-      // Update size
-      uint32_t width  = mCreateInfo.nativeImagePtr->GetWidth();
-      uint32_t height = mCreateInfo.nativeImagePtr->GetHeight();
-      mCreateInfo.SetSize({width, height}); // Size may change
-    }
-
     nativeImage->PrepareTexture();
   }
 }
@@ -420,9 +424,9 @@ bool Texture::TryConvertPixelData(const void* pData, Graphics::Format srcFormat,
 
 void Texture::SetSamplerParameter(uint32_t param, uint32_t& cacheValue, uint32_t value) const
 {
-  if(cacheValue != value)
+  auto gl = mController.GetGL();
+  if(gl && cacheValue != value)
   {
-    auto gl = mController.GetGL();
     gl->TexParameteri(mGlTarget, param, value);
     cacheValue = value;
   }