[3.0] Fix bug binding native image textures 22/128622/3
authorFerran Sole <ferran.sole@samsung.com>
Tue, 13 Dec 2016 14:29:36 +0000 (14:29 +0000)
committerNick Holland <nick.holland@partner.samsung.com>
Wed, 10 May 2017 14:14:46 +0000 (15:14 +0100)
NewTexture was always binding native image textures to GL_TEXTURE_2D binding point
even if textures required a different binding point

Change-Id: I54fc18def180c63bbd43f92417608b14039bfd7f
  (cherry picked from commit 7ab48a9570568e52dd82c26d219732c18416073f)

automated-tests/src/dali/utc-Dali-Texture.cpp
dali/internal/render/renderers/render-texture.cpp
dali/internal/render/renderers/render-texture.h

index 12fd9a7..43d06cb 100644 (file)
@@ -540,3 +540,21 @@ int UtcDaliTextureContextLoss(void)
 
   END_TEST;
 }
+
+int UtcDaliNativeImageTexture(void)
+{
+  TestApplication application;
+  tet_infoline( "UtcDaliNativeImageTexture" );
+
+  TestNativeImagePointer imageInterface = TestNativeImage::New( 16, 16 );
+  Texture texture = Texture::New( *(imageInterface.Get()) );
+  DALI_TEST_CHECK( texture );
+
+  application.SendNotification();
+  application.Render(16);
+
+  DALI_TEST_CHECK( texture );
+
+  END_TEST;
+}
+
index 4f26bb7..7e32f92 100644 (file)
@@ -16,6 +16,7 @@
 
 // CLASS HEADER
 #include <dali/internal/render/renderers/render-texture.h>
+#include <dali/devel-api/images/native-image-interface-extension.h>
 
 // EXTERNAL INCLUDES
 #include <math.h>   //floor, log2
@@ -590,6 +591,7 @@ bool IsCompressedFormat(Pixel::Format pixelFormat)
 
 NewTexture::NewTexture( Type type, Pixel::Format format, unsigned int width, unsigned int height )
 :mId( 0 ),
+ mTarget( (type == TextureType::TEXTURE_2D)? GL_TEXTURE_2D : GL_TEXTURE_CUBE_MAP ),
  mType( type ),
  mSampler(),
  mNativeImage(),
@@ -605,6 +607,7 @@ NewTexture::NewTexture( Type type, Pixel::Format format, unsigned int width, uns
 
 NewTexture::NewTexture( NativeImageInterfacePtr nativeImageInterface )
 :mId( 0 ),
+ mTarget( GL_TEXTURE_2D ),
  mType( TextureType::TEXTURE_2D ),
  mSampler(),
  mNativeImage( nativeImageInterface ),
@@ -644,15 +647,21 @@ void NewTexture::Initialize(Context& context)
   {
     if( mNativeImage->GlExtensionCreate() )
     {
+      NativeImageInterface::Extension* extension = mNativeImage->GetExtension();
+      if( extension )
+      {
+        mTarget = extension->GetEglImageTextureTarget();
+      }
+
       context.GenTextures( 1, &mId );
-      context.Bind2dTexture( mId );
+      context.BindTexture( mTarget, mId );
       context.PixelStorei( GL_UNPACK_ALIGNMENT, 1 ); // We always use tightly packed data
 
       //Apply default sampling parameters
-      context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, DALI_MINIFY_DEFAULT );
-      context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, DALI_MAGNIFY_DEFAULT );
-      context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_WRAP_DEFAULT );
-      context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_WRAP_DEFAULT );
+      context.TexParameteri( mTarget, GL_TEXTURE_MIN_FILTER, DALI_MINIFY_DEFAULT );
+      context.TexParameteri( mTarget, GL_TEXTURE_MAG_FILTER, DALI_MAGNIFY_DEFAULT );
+      context.TexParameteri( mTarget, GL_TEXTURE_WRAP_S, GL_WRAP_DEFAULT );
+      context.TexParameteri( mTarget, GL_TEXTURE_WRAP_T, GL_WRAP_DEFAULT );
 
       // platform specific implementation decides on what GL extension to use
       if( mNativeImage->TargetTexture() != 0u )
@@ -665,13 +674,19 @@ void NewTexture::Initialize(Context& context)
   }
   else
   {
+    //Create the texture and reserve memory for the first mipmap level.
     context.GenTextures( 1, &mId );
+    context.BindTexture( mTarget, mId );
+    context.PixelStorei( GL_UNPACK_ALIGNMENT, 1 ); // We always use tightly packed data
+
+    //Apply default sampling parameters
+    context.TexParameteri( mTarget, GL_TEXTURE_MIN_FILTER, DALI_MINIFY_DEFAULT );
+    context.TexParameteri( mTarget, GL_TEXTURE_MAG_FILTER, DALI_MAGNIFY_DEFAULT );
+    context.TexParameteri( mTarget, GL_TEXTURE_WRAP_S, GL_WRAP_DEFAULT );
+    context.TexParameteri( mTarget, GL_TEXTURE_WRAP_T, GL_WRAP_DEFAULT );
 
     if( mType == TextureType::TEXTURE_2D )
     {
-      //Creates the texture and reserves memory for the first mipmap level.
-      context.Bind2dTexture( mId );
-
       if( !mIsCompressed )
       {
         context.TexImage2D(GL_TEXTURE_2D, 0, mInternalFormat, mWidth, mHeight, 0, mInternalFormat, mPixelDataType, 0 );
@@ -680,18 +695,9 @@ void NewTexture::Initialize(Context& context)
       {
         context.CompressedTexImage2D(GL_TEXTURE_2D, 0, mInternalFormat, mWidth, mHeight, 0, 0, 0 );
       }
-
-      //Apply default sampling parameters
-      context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, DALI_MINIFY_DEFAULT );
-      context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, DALI_MAGNIFY_DEFAULT );
-      context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_WRAP_DEFAULT );
-      context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_WRAP_DEFAULT );
     }
     else if( mType == TextureType::TEXTURE_CUBE )
     {
-      //Creates the texture and reserves memory for the first mipmap level.
-      context.BindCubeMapTexture( mId );
-
       if( !mIsCompressed )
       {
         for( unsigned int i(0); i<6; ++i )
@@ -706,13 +712,7 @@ void NewTexture::Initialize(Context& context)
           context.CompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, mInternalFormat, mWidth, mHeight, 0, 0, 0 );
         }
       }
-
-      //Apply default sampling parameters
-      context.TexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, DALI_MINIFY_DEFAULT );
-      context.TexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, DALI_MAGNIFY_DEFAULT );
-      context.TexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_WRAP_DEFAULT );
-      context.TexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_WRAP_DEFAULT );
-      context.TexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_WRAP_DEFAULT );
+      context.TexParameteri( mTarget, GL_TEXTURE_WRAP_R, GL_WRAP_DEFAULT );
     }
   }
 }
@@ -751,15 +751,11 @@ void NewTexture::Upload( Context& context, PixelDataPtr pixelData, const Interna
 #endif
 
   //Upload data to the texture
-  GLenum target( GL_NONE );
-  if( mType == TextureType::TEXTURE_2D )
-  {
-    context.Bind2dTexture( mId );
-    target = GL_TEXTURE_2D;
-  }
-  else if( mType == TextureType::TEXTURE_CUBE )
+
+  context.BindTexture( mTarget, mId );
+  GLenum target( mTarget );
+  if( mType == TextureType::TEXTURE_CUBE )
   {
-    context.BindCubeMapTexture( mId );
     target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + params.layer;
   }
 
@@ -806,21 +802,11 @@ bool NewTexture::Bind( Context& context, unsigned int textureUnit, Render::Sampl
   if( mId != 0 )
   {
     context.ActiveTexture( static_cast<TextureUnit>(textureUnit) );
-
-    if( mType == TextureType::TEXTURE_2D )
-    {
-      context.Bind2dTexture( mId );
-    }
-    else if( mType == TextureType::TEXTURE_CUBE )
-    {
-      context.BindCubeMapTexture( mId );
-    }
-
+    context.BindTexture( mTarget, mId );
     ApplySampler( context, sampler );
 
     if( mNativeImage )
     {
-      //Allow implementation specific operations after binding the texture
       mNativeImage->PrepareTexture();
     }
 
@@ -840,31 +826,31 @@ void NewTexture::ApplySampler( Context& context, Render::Sampler* sampler )
     if( mSampler.mMinificationFilter != oldSampler.mMinificationFilter )
     {
       GLint glFilterMode = FilterModeToGL( mSampler.mMinificationFilter, DALI_MINIFY_DEFAULT, GL_MINIFY_DEFAULT );
-      context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, glFilterMode );
+      context.TexParameteri( mTarget, GL_TEXTURE_MIN_FILTER, glFilterMode );
     }
 
     if( mSampler.mMagnificationFilter != oldSampler.mMagnificationFilter )
     {
       GLint glFilterMode = FilterModeToGL( mSampler.mMagnificationFilter, DALI_MAGNIFY_DEFAULT, GL_MAGNIFY_DEFAULT );
-      context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, glFilterMode );
+      context.TexParameteri( mTarget, GL_TEXTURE_MAG_FILTER, glFilterMode );
     }
 
     if( mSampler.mSWrapMode != oldSampler.mSWrapMode )
     {
       GLint glWrapMode = WrapModeToGL( mSampler.mSWrapMode, GL_WRAP_DEFAULT );
-      context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, glWrapMode );
+      context.TexParameteri( mTarget, GL_TEXTURE_WRAP_S, glWrapMode );
     }
 
     if( mSampler.mTWrapMode != oldSampler.mTWrapMode )
     {
       GLint glWrapMode = WrapModeToGL( mSampler.mTWrapMode, GL_WRAP_DEFAULT );
-      context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, glWrapMode );
+      context.TexParameteri( mTarget, GL_TEXTURE_WRAP_T, glWrapMode );
     }
 
     if( mType == TextureType::TEXTURE_CUBE && mSampler.mRWrapMode != oldSampler.mRWrapMode )
     {
       GLint glWrapMode = WrapModeToGL( mSampler.mRWrapMode, GL_WRAP_DEFAULT );
-      context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, glWrapMode );
+      context.TexParameteri( mTarget, GL_TEXTURE_WRAP_R, glWrapMode );
     }
   }
 }
@@ -876,16 +862,8 @@ bool NewTexture::HasAlphaChannel()
 
 void NewTexture::GenerateMipmaps( Context& context )
 {
-  if( mType == TextureType::TEXTURE_2D )
-  {
-    context.Bind2dTexture( mId );
-    context.GenerateMipmap( GL_TEXTURE_2D );
-  }
-  else if( mType == TextureType::TEXTURE_CUBE )
-  {
-    context.BindCubeMapTexture( mId );
-    context.GenerateMipmap( GL_TEXTURE_CUBE_MAP );
-  }
+  context.BindTexture( mTarget, mId );
+  context.GenerateMipmap( mTarget );
 }
 
 } //Render
index 74255cc..2833a4d 100644 (file)
@@ -212,16 +212,17 @@ private:
    */
   void ApplySampler( Context& context, Render::Sampler* sampler );
 
-  GLuint mId;                         ///<Id of the texture
-  Type mType;                         ///<Type of the texture
-  Render::Sampler mSampler;           ///<The current sampler state
-  NativeImageInterfacePtr mNativeImage; ///<Pointer to native image
-  GLenum mInternalFormat;             ///<The format of the pixel data
-  GLenum mPixelDataType;              ///<The data type of the pixel data
-  unsigned int mWidth;                ///<Widht of the texture
-  unsigned int mHeight;               ///<Height of the texture
-  bool mHasAlpha : 1;                 ///<Whether the format has an alpha channel
-  bool mIsCompressed : 1;             ///<Whether the format is compressed
+  GLuint mId;                           ///< Id of the texture
+  GLuint mTarget;                       ///< Specifies the target to which the texture is bound.
+  Type mType;                           ///< Type of the texture
+  Render::Sampler mSampler;             ///< The current sampler state
+  NativeImageInterfacePtr mNativeImage; ///< Pointer to native image
+  GLenum mInternalFormat;               ///< The format of the pixel data
+  GLenum mPixelDataType;                ///< The data type of the pixel data
+  unsigned int mWidth;                  ///< Widht of the texture
+  unsigned int mHeight;                 ///< Height of the texture
+  bool mHasAlpha : 1;                   ///< Whether the format has an alpha channel
+  bool mIsCompressed : 1;               ///< Whether the format is compressed
 };