Added support for compressed texture upload to Render::NewTexture 24/77124/5
authorFerran Sole <ferran.sole@samsung.com>
Tue, 28 Jun 2016 15:46:45 +0000 (16:46 +0100)
committerFerran Sole <ferran.sole@samsung.com>
Wed, 29 Jun 2016 11:48:43 +0000 (12:48 +0100)
Change-Id: I864026078391a5b98caaa62ffa2c2d9a0db6a919

automated-tests/src/dali-devel/utc-Dali-Atlas.cpp
automated-tests/src/dali-devel/utc-Dali-PixelData.cpp
automated-tests/src/dali-devel/utc-Dali-Texture.cpp
automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h
dali/devel-api/images/pixel-data.cpp
dali/devel-api/images/pixel-data.h
dali/internal/event/images/pixel-data-impl.cpp
dali/internal/event/images/pixel-data-impl.h
dali/internal/event/rendering/texture-impl.cpp
dali/internal/render/renderers/render-texture.cpp
dali/internal/render/renderers/render-texture.h

index 34d4457..966aecb 100644 (file)
@@ -51,7 +51,7 @@ PixelData CreatePixelData(unsigned int width, unsigned int height, Pixel::Format
   unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( pixelFormat );
   unsigned char* buffer = new unsigned char [ bufferSize ];
 
-  return PixelData::New( buffer, width, height, pixelFormat, PixelData::DELETE_ARRAY );
+  return PixelData::New( buffer, bufferSize, width, height, pixelFormat, PixelData::DELETE_ARRAY );
 }
 
 }
index dda4296..f2d66bf 100644 (file)
@@ -33,7 +33,7 @@ int UtcDaliPixelData01(void)
   unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::RGB888 );
 
   unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
-  PixelData pixelData = PixelData::New( buffer, width, height, Pixel::RGB888, PixelData::FREE );
+  PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE );
 
   DALI_TEST_CHECK( pixelData );
   DALI_TEST_CHECK( pixelData.GetWidth() == width );
@@ -53,7 +53,7 @@ int UtcDaliPixelData02(void)
   unsigned char* buffer = new unsigned char [ bufferSize ];
   buffer[0] = 'a';
 
-  PixelData pixelData = PixelData::New( buffer, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
+  PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
 
   DALI_TEST_CHECK( pixelData);
   DALI_TEST_CHECK( pixelData.GetWidth() == width );
@@ -71,7 +71,7 @@ int UtcDaliPixelDataCopyConstructor(void)
   unsigned int height = 10u;
   unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
   unsigned char* buffer = new unsigned char [ bufferSize ];
-  PixelData pixelData = PixelData::New( buffer, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
+  PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
 
   PixelData pixelDataCopy(pixelData);
 
@@ -87,7 +87,7 @@ int UtcDaliPixelDataAssignmentOperator(void)
   unsigned int height = 10u;
   unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
   unsigned char* buffer = new unsigned char [ bufferSize ];
-  PixelData pixelData = PixelData::New( buffer, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
+  PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
 
   PixelData pixelData2;
   DALI_TEST_EQUALS( (bool)pixelData2, false, TEST_LOCATION );
index fe3f396..ff7ad76 100644 (file)
@@ -133,8 +133,9 @@ int UtcDaliTextureUpload01(void)
   //Upload data to the texture
   callStack.Reset();
 
-  unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( width * height * 4 ) );
-  PixelData pixelData = PixelData::New( buffer, width, height, Pixel::RGBA8888, PixelData::FREE );
+  unsigned int bufferSize( width * height * 4 );
+  unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
+  PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
   texture.Upload( pixelData );
   application.SendNotification();
   application.Render();
@@ -148,8 +149,9 @@ int UtcDaliTextureUpload01(void)
 
   //Upload part of the texture
   callStack.Reset();
-  buffer = reinterpret_cast<unsigned char*>( malloc( width * height * 2 ) );
-  PixelData pixelDataSubImage = PixelData::New( buffer, width, height, Pixel::RGBA8888, PixelData::FREE );
+  bufferSize =  width * height * 2;
+  buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
+  PixelData pixelDataSubImage = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
   texture.Upload( pixelDataSubImage, 0u, 0u, width/2, height/2, width/2, height/2 );
   application.SendNotification();
   application.Render();
@@ -189,8 +191,9 @@ int UtcDaliTextureUpload02(void)
     DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
   }
 
-  unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( width * height * 4 ) );
-  PixelData pixelData = PixelData::New( buffer, width, height, Pixel::RGBA8888, PixelData::FREE );
+  unsigned int bufferSize( width * height * 4 );
+  unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
+  PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
 
   //Upload data to the POSITIVE_X face of the texture
   {
@@ -315,12 +318,15 @@ int UtcDaliTextureUpload03(void)
 
   //Upload data to the texture mipmap 0 and mipmap 1
   callStack.Reset();
-  unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( width * height * 4 ) );
-  PixelData pixelData = PixelData::New( buffer, width, height, Pixel::RGBA8888, PixelData::FREE );
+
+  unsigned int bufferSize( width * height * 4 );
+  unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc(  bufferSize ) );
+  PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
   texture.Upload( pixelData, 0u, 0u, 0u, 0u, width, height );
 
-  buffer = reinterpret_cast<unsigned char*>( malloc( widthMipmap1 * heightMipmap1 * 4 ) );
-  PixelData pixelDataMipmap1 = PixelData::New( buffer, width, height, Pixel::RGBA8888, PixelData::FREE );
+  bufferSize = widthMipmap1 * heightMipmap1 * 4;
+  buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
+  PixelData pixelDataMipmap1 = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
   texture.Upload( pixelDataMipmap1, 0u, 1u, 0u, 0u, widthMipmap1, heightMipmap1 );
   application.SendNotification();
   application.Render();
@@ -356,12 +362,14 @@ int UtcDaliTextureUpload04(void)
   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
 
   //Upload data to the NEGATIVE_X face mipmap 0 and mipmap 1
-  unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( width * height * 4 ) );
-  PixelData pixelData = PixelData::New( buffer, width, height, Pixel::RGBA8888, PixelData::FREE );
+  unsigned int bufferSize( width * height * 4 );
+  unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
+  PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
   texture.Upload( pixelData, CubeMap::NEGATIVE_X, 0u, 0u, 0u, width, height );
 
-  buffer= reinterpret_cast<unsigned char*>( malloc( widthMipmap1 * heightMipmap1 * 4 ) );
-  PixelData pixelDataMipmap1 = PixelData::New( buffer, width, height, Pixel::RGBA8888, PixelData::FREE );
+  bufferSize = widthMipmap1 * heightMipmap1 * 4;
+  buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
+  PixelData pixelDataMipmap1 = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
   texture.Upload( pixelDataMipmap1, CubeMap::NEGATIVE_X, 1u, 0u, 0u, widthMipmap1, heightMipmap1 );
   application.SendNotification();
   application.Render();
@@ -381,6 +389,66 @@ int UtcDaliTextureUpload04(void)
   END_TEST;
 }
 
+int UtcDaliTextureUpload05(void)
+{
+  TestApplication application;
+
+  //Create a texture with a compressed format
+  unsigned int width(64);
+  unsigned int height(64);
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR, width, height );
+
+  application.GetGlAbstraction().EnableTextureCallTrace(true);
+
+  application.SendNotification();
+  application.Render();
+
+  TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
+
+  //CompressedTexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
+  {
+    std::stringstream out;
+    out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
+    DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str() ) );
+  }
+
+  //Upload data to the texture
+  callStack.Reset();
+
+  unsigned int bufferSize( width * height * 4 );
+  unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
+  PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR, PixelData::FREE );
+  texture.Upload( pixelData );
+  application.SendNotification();
+  application.Render();
+
+  //CompressedTexImage2D should be called to upload the data
+  {
+    std::stringstream out;
+    out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
+    DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str() ) );
+  }
+
+  //Upload part of the texture
+  callStack.Reset();
+  bufferSize =  width * height * 2;
+  buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
+  PixelData pixelDataSubImage = PixelData::New( buffer, bufferSize, width, height, Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR, PixelData::FREE );
+  texture.Upload( pixelDataSubImage, 0u, 0u, width/2, height/2, width/2, height/2 );
+  application.SendNotification();
+  application.Render();
+
+  //CompressedTexSubImage2D should be called to upload the data
+  {
+    std::stringstream out;
+    out << GL_TEXTURE_2D <<", "<< 0u << ", " << width/2 << ", " <<  height/2 << ", " << width/2 << ", " <<  height/2;
+    DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexSubImage2D", out.str().c_str() ) );
+  }
+
+
+  END_TEST;
+}
+
 int UtcDaliTextureGenerateMipmaps(void)
 {
   TestApplication application;
index 9a93c8e..e445084 100644 (file)
@@ -295,10 +295,34 @@ public:
 
   inline void CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void* data)
   {
+    std::stringstream out;
+    out << target<<", "<<level<<", "<<width << ", " << height;
+
+    TraceCallStack::NamedParams namedParams;
+    namedParams["target"] = ToString(target);
+    namedParams["level"] = ToString(level);
+    namedParams["internalformat"] = ToString(internalformat);
+    namedParams["width"] = ToString(width);
+    namedParams["height"] = ToString(height);
+    namedParams["border"] = ToString(border);
+    namedParams["size"] = ToString(imageSize);
+
+    mTextureTrace.PushCall("CompressedTexImage2D", out.str(), namedParams);
   }
 
   inline void CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void* data)
   {
+    std::stringstream out;
+    out << target << ", "<<level <<", " << xoffset << ", " << yoffset << ", " << width << ", " << height;
+
+    TraceCallStack::NamedParams namedParams;
+    namedParams["target"] = ToString(target);
+    namedParams["level"] = ToString(level);
+    namedParams["xoffset"] = ToString(xoffset);
+    namedParams["yoffset"] = ToString(yoffset);
+    namedParams["width"] = ToString(width);
+    namedParams["height"] = ToString(height);
+    mTextureTrace.PushCall("CompressedTexSubImage2D", out.str(), namedParams);
   }
 
   inline void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
index c9febc0..14f5e45 100644 (file)
@@ -28,12 +28,13 @@ namespace Dali
 {
 
 PixelData PixelData::New(unsigned char* buffer,
+                         unsigned int bufferSize,
                          unsigned int width,
                          unsigned int height,
                          Pixel::Format pixelFormat,
                          ReleaseFunction releaseFunction)
 {
-  IntrusivePtr<Internal::PixelData> internal = Internal::PixelData::New( buffer, width, height, pixelFormat, releaseFunction );
+  IntrusivePtr<Internal::PixelData> internal = Internal::PixelData::New( buffer, bufferSize, width, height, pixelFormat, releaseFunction );
   return PixelData( internal.Get() );
 }
 
index cecc3e6..f3ea4fc 100644 (file)
@@ -49,12 +49,14 @@ public:
    * @brief Create a PixelData object.
    *
    * @param [in] buffer           The raw pixel data.
+   * @param [in] bufferSize       The size of the buffer in bytes
    * @param [in] width            Buffer width in pixels
    * @param [in] height           Buffer height in pixels
    * @param [in] pixelFormat      The pixel format
    * @param [in] releaseFunction  The function used to release the memory.
    */
   static PixelData New( unsigned char* buffer,
+                        unsigned int bufferSize,
                         unsigned int width,
                         unsigned int height,
                         Pixel::Format pixelFormat,
index 479b0f9..44a7e1d 100644 (file)
@@ -28,11 +28,13 @@ namespace Internal
 {
 
 PixelData::PixelData( unsigned char* buffer,
+                      unsigned int bufferSize,
                       unsigned int width,
                       unsigned int height,
                       Pixel::Format pixelFormat,
                       Dali::PixelData::ReleaseFunction releaseFunction )
 : mBuffer( buffer ),
+  mBufferSize( bufferSize ),
   mWidth( width ),
   mHeight( height ),
   mPixelFormat( pixelFormat ),
@@ -56,12 +58,13 @@ PixelData::~PixelData()
  }
 
 PixelDataPtr PixelData::New(unsigned char* buffer,
+                            unsigned int bufferSize,
                             unsigned int width,
                             unsigned int height,
                             Pixel::Format pixelFormat,
                             Dali::PixelData::ReleaseFunction releaseFunction)
 {
-  return new PixelData( buffer, width, height, pixelFormat, releaseFunction );
+  return new PixelData( buffer, bufferSize, width, height, pixelFormat, releaseFunction );
 }
 
 unsigned int PixelData::GetWidth() const
@@ -84,6 +87,11 @@ unsigned char* PixelData::GetBuffer() const
   return mBuffer;
 }
 
+unsigned int PixelData::GetBufferSize() const
+{
+  return mBufferSize;
+}
+
 }// namespace Internal
 
 }// namespace Dali
index cf2b299..0f12c23 100644 (file)
@@ -39,12 +39,14 @@ public:
    * @brief Create a PixelData object.
    *
    * @param [in] buffer           The raw pixel data.
+   * @param [in] bufferSize       The size of the buffer in bytes
    * @param [in] width            Buffer width in pixels
    * @param [in] height           Buffer height in pixels
    * @param [in] pixelFormat      The pixel format
    * @param [in] releaseFunction  The function used to release the memory.
    */
   static PixelDataPtr New( unsigned char* buffer,
+                           unsigned int bufferSize,
                            unsigned int width,
                            unsigned int height,
                            Pixel::Format pixelFormat,
@@ -54,12 +56,14 @@ public:
    * @brief Constructor.
    *
    * @param [in] buffer           The raw pixel data.
+   * @param [in] bufferSize       The size of the buffer in bytes
    * @param [in] width            Buffer width in pixels
    * @param [in] height           Buffer height in pixels
    * @param [in] pixelFormat      The pixel format
    * @param [in] releaseFunction  The function used to release the memory.
    */
   PixelData( unsigned char* buffer,
+             unsigned int bufferSize,
              unsigned int width,
              unsigned int height,
              Pixel::Format pixelFormat,
@@ -100,6 +104,12 @@ public:
    */
   unsigned char* GetBuffer() const;
 
+  /**
+   * Get the size of the buffer in bytes
+   * @return The size of the buffer
+   */
+  unsigned int GetBufferSize() const;
+
 private:
 
   /*
@@ -114,9 +124,10 @@ private:
 
 private:
 
-  unsigned char* mBuffer;           ///< The raw pixel data.
-  unsigned int   mWidth;            ///< Buffer width in pixels.
-  unsigned int   mHeight;           ///< Buffer height in pixels.
+  unsigned char* mBuffer;           ///< The raw pixel data
+  unsigned int   mBufferSize;       ///< Buffer sized in bytes
+  unsigned int   mWidth;            ///< Buffer width in pixels
+  unsigned int   mHeight;           ///< Buffer height in pixels
   Pixel::Format  mPixelFormat;      ///< Pixel format
   Dali::PixelData::ReleaseFunction mReleaseFunction;  ///< Function for releasing memory
 };
index 5f8d4ee..abea005 100644 (file)
@@ -120,8 +120,8 @@ void NewTexture::Upload( PixelDataPtr pixelData,
         {
           DALI_LOG_ERROR( "Pixel data of an incorrect size when trying to update texture");
         }
-        else if( ( xOffset + width  > static_cast<unsigned int>( mWidth  / (1<<mipmap ))) ||
-            ( yOffset + height > static_cast<unsigned int>( mHeight / (1<<mipmap ))))
+        else if( ( xOffset + width  > ( mWidth  / (1<<mipmap) ) ) ||
+                 ( yOffset + height > ( mHeight / (1<<mipmap) ) ) )
         {
           DALI_LOG_ERROR( "Texture update area out of bounds");
         }
index faa7c74..a99944a 100644 (file)
@@ -511,6 +511,82 @@ void PixelFormatToGl( Pixel::Format pixelformat, unsigned& pixelDataType, unsign
   }
 }
 
+/**
+ * @brief Whether specified pixel format is compressed.
+ *
+ * @param [in] pixelformat Pixel format
+ * @return true if format is compressed, false otherwise
+ */
+bool IsCompressedFormat(Pixel::Format pixelFormat)
+{
+  switch (pixelFormat)
+  {
+    case Pixel::L8:
+    case Pixel::A8:
+    case Pixel::LA88:
+    case Pixel::RGB565:
+    case Pixel::RGBA4444:
+    case Pixel::RGBA5551:
+    case Pixel::BGR565:
+    case Pixel::BGRA4444:
+    case Pixel::BGRA5551:
+    case Pixel::RGB888:
+    case Pixel::RGB8888:
+    case Pixel::BGR8888:
+    case Pixel::RGBA8888:
+    case Pixel::BGRA8888:
+    case Pixel::INVALID:
+    {
+      return false;
+    }
+
+    case Pixel::COMPRESSED_R11_EAC:
+    case Pixel::COMPRESSED_SIGNED_R11_EAC:
+    case Pixel::COMPRESSED_RG11_EAC:
+    case Pixel::COMPRESSED_SIGNED_RG11_EAC:
+    case Pixel::COMPRESSED_RGB8_ETC2:
+    case Pixel::COMPRESSED_SRGB8_ETC2:
+    case Pixel::COMPRESSED_RGB8_ETC1:
+    case Pixel::COMPRESSED_RGB_PVRTC_4BPPV1:
+    case Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
+    case Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
+    case Pixel::COMPRESSED_RGBA8_ETC2_EAC:
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
+    case Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR:
+    case Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR:
+    case Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR:
+    case Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR:
+    case Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR:
+    case Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR:
+    case Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR:
+    case Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR:
+    case Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR:
+    case Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR:
+    case Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR:
+    case Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR:
+    case Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR:
+    case Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR:
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
+    case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
+    {
+      return true;
+    }
+  }
+
+  return false;
+}
 
 } //Unnamed namespace
 
@@ -524,7 +600,8 @@ NewTexture::NewTexture( Type type, Pixel::Format format, unsigned int width, uns
  mPixelDataType(GL_UNSIGNED_BYTE),
  mWidth( width ),
  mHeight( height ),
- mHasAlpha( HasAlpha( format ) )
+ mHasAlpha( HasAlpha( format ) ),
+ mIsCompressed( IsCompressedFormat( format ) )
 {
   PixelFormatToGl( format, mPixelDataType, mInternalFormat );
 }
@@ -538,7 +615,8 @@ NewTexture::NewTexture( NativeImageInterfacePtr nativeImageInterface )
  mPixelDataType(GL_UNSIGNED_BYTE),
  mWidth( nativeImageInterface->GetWidth() ),
  mHeight( nativeImageInterface->GetHeight() ),
- mHasAlpha( nativeImageInterface->RequiresBlending() )
+ mHasAlpha( nativeImageInterface->RequiresBlending() ),
+ mIsCompressed( false )
 {
 }
 
@@ -581,7 +659,15 @@ void NewTexture::Initialize(Context& context)
     {
       //Creates the texture and reserves memory for the first mipmap level.
       context.Bind2dTexture( mId );
-      context.TexImage2D(GL_TEXTURE_2D, 0, mInternalFormat, mWidth, mHeight, 0, mInternalFormat, mPixelDataType, 0 );
+
+      if( !mIsCompressed )
+      {
+        context.TexImage2D(GL_TEXTURE_2D, 0, mInternalFormat, mWidth, mHeight, 0, mInternalFormat, mPixelDataType, 0 );
+      }
+      else
+      {
+        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 );
@@ -593,9 +679,20 @@ void NewTexture::Initialize(Context& context)
     {
       //Creates the texture and reserves memory for the first mipmap level.
       context.BindCubeMapTexture( mId );
-      for( unsigned int i(0); i<6; ++i )
+
+      if( !mIsCompressed )
+      {
+        for( unsigned int i(0); i<6; ++i )
+        {
+          context.TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, mInternalFormat, mWidth, mHeight, 0, mInternalFormat, mPixelDataType, 0 );
+        }
+      }
+      else
       {
-        context.TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, mInternalFormat, mWidth, mHeight, 0, mInternalFormat, mPixelDataType, 0 );
+        for( unsigned int i(0); i<6; ++i )
+        {
+          context.CompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, mInternalFormat, mWidth, mHeight, 0, 0, 0 );
+        }
       }
 
       //Apply default sampling parameters
@@ -642,47 +739,52 @@ 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 );
-    context.PixelStorei( GL_UNPACK_ALIGNMENT, 1 );
+    target = GL_TEXTURE_2D;
+  }
+  else if( mType == TextureType::TEXTURE_CUBE )
+  {
+    context.BindCubeMapTexture( mId );
+    target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + params.layer;
+  }
 
-    if( params.xOffset == 0 && params.yOffset == 0 &&
-        params.width  == static_cast<unsigned int>(mWidth  / (1<<params.mipmap)) &&
-        params.height == static_cast<unsigned int>(mHeight / (1<<params.mipmap)) )
+  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) ) )
+  {
+    //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 )
     {
-      //Specifying the whole image for the mipmap. We cannot assume that storage for that mipmap has been created so we need to use TexImage2D
-      context.TexImage2D(GL_TEXTURE_2D, params.mipmap, mInternalFormat, params.width, params.height, 0, pixelDataFormat, pixelDataElementType, buffer );
+      context.TexImage2D( target, params.mipmap, mInternalFormat, params.width, params.height, 0, pixelDataFormat, pixelDataElementType, buffer );
     }
     else
     {
-      //Specifying part of the image for the mipmap
-      context.TexSubImage2D( GL_TEXTURE_2D, params.mipmap, params.xOffset, params.yOffset, params.width, params.height, pixelDataFormat, pixelDataElementType, buffer );
+      context.CompressedTexImage2D( target, params.mipmap, mInternalFormat, params.width, params.height, 0, pixelData->GetBufferSize(), buffer );
     }
   }
-  else if( mType == TextureType::TEXTURE_CUBE )
+  else
   {
-    context.BindCubeMapTexture( mId );
-    context.PixelStorei( GL_UNPACK_ALIGNMENT, 1 );
-
-    if( params.xOffset == 0 && params.yOffset == 0 &&
-        params.width  == static_cast<unsigned int>(mWidth  / (1<<params.mipmap)) &&
-        params.height == static_cast<unsigned int>(mHeight / (1<<params.mipmap)) )
+    //Specifying part of the image for the mipmap
+    if( !mIsCompressed )
     {
-      //Specifying the whole image for the mipmap. We cannot assume that storage for that mipmap has been created so we need to use TexImage2D
-      context.TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + params.layer, params.mipmap, mInternalFormat,
-                         params.width, params.height, 0,
-                         pixelDataFormat, pixelDataElementType, buffer );
+      context.TexSubImage2D( target, params.mipmap,
+                             params.xOffset, params.yOffset, params.width, params.height,
+                             pixelDataFormat, pixelDataElementType, buffer );
     }
     else
     {
-      //Specifying part of the image for the mipmap
-      context.TexSubImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X + params.layer, params.mipmap,
-                             params.xOffset, params.yOffset, params.width, params.height,
-                             pixelDataFormat, pixelDataElementType, buffer );
+      context.CompressedTexSubImage2D( target, params.mipmap,
+                                       params.xOffset, params.yOffset, params.width, params.height,
+                                       pixelDataFormat, pixelData->GetBufferSize(), buffer );
     }
   }
 
+
   //Destroy temp buffer used for conversion RGB->RGBA
   delete[] tempBuffer;
 }
index b117a14..cc17d1e 100644 (file)
@@ -226,6 +226,7 @@ private:
   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
 };