CubeMap support 67/257567/3
authorRichard Huang <r.huang@samsung.com>
Tue, 27 Apr 2021 16:07:34 +0000 (17:07 +0100)
committerDavid Steele <david.steele@samsung.com>
Fri, 30 Apr 2021 13:48:25 +0000 (14:48 +0100)
Change-Id: Idbe013328b3acb5e72931f16def48df609dbdb6f

dali/internal/graphics/gles-impl/egl-graphics-controller.cpp
dali/internal/graphics/gles-impl/gles-graphics-texture.cpp

index 5546800..2f3d5aa 100644 (file)
@@ -583,19 +583,52 @@ void EglGraphicsController::ProcessTextureUpdateQueue()
         sourceBuffer = &tempBuffer[0];
       }
 
-      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);
+      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);
+
+          mGlAbstraction->BindTexture(GL_TEXTURE_CUBE_MAP, texture->GetGLTexture());
+
+          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);
+
+
+          break;
+        }
+        default:
+        {
+          // nothing?
+        }
+      }
 
       // free staging memory
       free(source.memorySource.memory);
index 7e84495..cb75d68 100644 (file)
@@ -207,6 +207,46 @@ bool Texture::InitializeTexture()
       }
       break;
     }
+    // Texture Cubemap
+    case Graphics::TextureType::TEXTURE_CUBEMAP:
+    {
+      Graphics::GLES::GLTextureFormatType format(mCreateInfo.format);
+
+      if(format.format && format.type)
+      {
+        // Bind texture
+        gl->GenTextures(1, &texture);
+        gl->BindTexture(GL_TEXTURE_CUBE_MAP, texture);
+        gl->PixelStorei(GL_UNPACK_ALIGNMENT, 1); // We always use tightly packed data
+
+        gl->TexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, Graphics::GLES::GLSamplerFilterAndMipMapMode(Graphics::SamplerFilter::LINEAR, SamplerMipmapMode::NONE));
+        gl->TexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, Graphics::GLES::GLSamplerFilterAndMipMapMode(Graphics::SamplerFilter::LINEAR, SamplerMipmapMode::NONE));
+        gl->TexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_WRAP_DEFAULT);
+        gl->TexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_WRAP_DEFAULT);
+
+        // Allocate memory for the texture
+        for(uint32_t i = 0; i < 6; ++i)
+        {
+          gl->TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
+                         0,
+                         format.format,
+                         mCreateInfo.size.width,
+                         mCreateInfo.size.height,
+                         0,
+                         format.format,
+                         format.type,
+                         (mCreateInfo.data ? mStagingBuffer.data() : nullptr));
+        }
+
+        // Clear staging buffer if there was any
+        mStagingBuffer.clear();
+
+        mTextureId = texture;
+
+        gl->TexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_WRAP_DEFAULT);
+      }
+      break;
+    }
     default:
     {
       // nothing?