[3.0] Fix for texture Upload() 15/133315/2
authorVictor Cebollada <v.cebollada@samsung.com>
Fri, 9 Jun 2017 13:15:02 +0000 (14:15 +0100)
committerPaul Wisbey <p.wisbey@samsung.com>
Fri, 9 Jun 2017 17:27:15 +0000 (17:27 +0000)
* When a full texture is loaded in a GLES3.x context
  and the pixel data format is RGB and the internal format
  is RGBA, it needs to be converted to RGBA.

Change-Id: Idcd3635d2d1bd378b9ffe96266c4fb8ced5e4087
Signed-off-by: Victor Cebollada <v.cebollada@samsung.com>
dali/internal/render/renderers/render-texture.cpp

index 9025a31..689d53b 100644 (file)
@@ -737,11 +737,20 @@ void NewTexture::Upload( Context& context, PixelDataPtr pixelData, const Interna
   //necessary to upload all the mipmap levels
   mMaxMipMapLevel = ( mMaxMipMapLevel > params.mipmap ) ? mMaxMipMapLevel : params.mipmap;
 
-#if DALI_GLES_VERSION < 30
-  if( pixelDataFormat == GL_RGB && mInternalFormat == GL_RGBA )
+  const bool isSubImage = ( ( params.xOffset != 0 ) ||
+                            ( params.yOffset != 0 ) ||
+                            ( params.width  != ( mWidth  / ( 1 << params.mipmap ) ) ) ||
+                            ( params.height != ( mHeight / ( 1 << params.mipmap ) ) ) );
+
+  bool convert = ( ( pixelDataFormat == GL_RGB ) && ( mInternalFormat == GL_RGBA ) );
+#if DALI_GLES_VERSION >= 30
+  // Don't convert manually from RGB to RGBA if GLES >= 3.0 and a sub-image is uploaded.
+  convert = convert && !isSubImage;
+#endif
+
+  if( convert )
   {
-    //Convert manually from RGB to RGBA if GLES < 3 ( GLES 3 can do the conversion automatically when uploading )
-    size_t dataSize = params.width * params.height;
+    size_t dataSize = static_cast< size_t >( params.width ) * params.height;
     tempBuffer = new unsigned char[dataSize*4u];
     for( size_t i(0u); i<dataSize; i++ )
     {
@@ -754,7 +763,6 @@ void NewTexture::Upload( Context& context, PixelDataPtr pixelData, const Interna
     buffer = tempBuffer;
     pixelDataFormat = mInternalFormat;
   }
-#endif
 
   //Upload data to the texture
 
@@ -767,9 +775,7 @@ void NewTexture::Upload( Context& context, PixelDataPtr pixelData, const Interna
 
   context.PixelStorei( GL_UNPACK_ALIGNMENT, 1 );
 
-  if( params.xOffset == 0 && params.yOffset == 0 &&
-      params.width  == ( mWidth  / (1<<params.mipmap) ) &&
-      params.height == ( mHeight / (1<<params.mipmap) ) )
+  if( !isSubImage )
   {
     //Specifying the whole image for the mipmap. We cannot assume that storage for that mipmap has been created so we need to use TexImage2D
     if( !mIsCompressed )