[Tizen] Using Depth and Stencil buffer & texture
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-texture.cpp
index 59c1206..d6783a1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -20,6 +20,9 @@
 // EXTERNAL INCLUDES
 #include <math.h>   //floor, log2
 
+// INTERNAL INCLUDES
+#include <dali/devel-api/images/native-image-interface-extension.h>
+
 namespace Dali
 {
 namespace Internal
@@ -120,43 +123,44 @@ GLint WrapModeToGL( WrapMode::Type wrapMode, GLint defaultWrapMode )
 }
 
 /**
- * @brief Retrive GL internal format and pixel data type from a Pixel::Format
- * @param[in] pixelFormat The pixel format
- * @param[out] pixelDataType The data type of the pixel data
- * @param[out] internalFormat The internal format
+ * @brief Retrives the GL format, GL internal format and pixel data type from a Pixel::Format
+ * @param[in] pixelFormat The pixel format.
+ * @param[out] glFormat The gl format.
+ * @param[out] glInternalFormat The gl internal format.
+ * @param[out] pixelDataType The data type of the pixel data.
  */
-void PixelFormatToGl( Pixel::Format pixelformat, unsigned& pixelDataType, unsigned& internalFormat )
+void PixelFormatToGl( Pixel::Format pixelFormat, GLenum& glFormat, GLint& glInternalFormat, GLenum& pixelDataType )
 {
   // Compressed textures have no pixelDataType, so init to an invalid value:
   pixelDataType  = -1;
 
-  switch( pixelformat )
+  switch( pixelFormat )
   {
     case Pixel::A8:
     {
       pixelDataType = GL_UNSIGNED_BYTE;
-      internalFormat= GL_ALPHA;
+      glFormat= GL_ALPHA;
       break;
     }
 
     case Pixel::L8:
     {
       pixelDataType = GL_UNSIGNED_BYTE;
-      internalFormat= GL_LUMINANCE;
+      glFormat= GL_LUMINANCE;
       break;
     }
 
     case Pixel::LA88:
     {
       pixelDataType = GL_UNSIGNED_BYTE;
-      internalFormat= GL_LUMINANCE_ALPHA;
+      glFormat= GL_LUMINANCE_ALPHA;
       break;
     }
 
     case Pixel::RGB565:
     {
       pixelDataType = GL_UNSIGNED_SHORT_5_6_5;
-      internalFormat= GL_RGB;
+      glFormat= GL_RGB;
       break;
     }
 
@@ -165,9 +169,9 @@ void PixelFormatToGl( Pixel::Format pixelformat, unsigned& pixelDataType, unsign
       DALI_LOG_ERROR("Pixel format BGR565 is not supported by GLES.\n");
       pixelDataType  = GL_UNSIGNED_SHORT_5_6_5;
 #ifdef _ARCH_ARM_
-      internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
+      glFormat= GL_BGRA_EXT; // alpha is reserved but not used
 #else
-      internalFormat= GL_RGBA;     // alpha is reserved but not used
+      glFormat= GL_RGBA;     // alpha is reserved but not used
 #endif
       break;
     }
@@ -175,7 +179,7 @@ void PixelFormatToGl( Pixel::Format pixelformat, unsigned& pixelDataType, unsign
     case Pixel::RGBA4444:
     {
       pixelDataType = GL_UNSIGNED_SHORT_4_4_4_4;
-      internalFormat= GL_RGBA;
+      glFormat= GL_RGBA;
       break;
     }
 
@@ -184,9 +188,9 @@ void PixelFormatToGl( Pixel::Format pixelformat, unsigned& pixelDataType, unsign
       DALI_LOG_ERROR("Pixel format BGRA4444 is not supported by GLES.\n");
       pixelDataType  = GL_UNSIGNED_SHORT_4_4_4_4;
 #ifdef _ARCH_ARM_
-      internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
+      glFormat= GL_BGRA_EXT; // alpha is reserved but not used
 #else
-      internalFormat= GL_RGBA;     // alpha is reserved but not used
+      glFormat= GL_RGBA;     // alpha is reserved but not used
 #endif
       break;
     }
@@ -194,7 +198,7 @@ void PixelFormatToGl( Pixel::Format pixelformat, unsigned& pixelDataType, unsign
     case Pixel::RGBA5551:
     {
       pixelDataType = GL_UNSIGNED_SHORT_5_5_5_1;
-      internalFormat= GL_RGBA;
+      glFormat= GL_RGBA;
       break;
     }
 
@@ -203,9 +207,9 @@ void PixelFormatToGl( Pixel::Format pixelformat, unsigned& pixelDataType, unsign
       DALI_LOG_ERROR("Pixel format BGRA5551 is not supported by GLES.\n");
       pixelDataType  = GL_UNSIGNED_SHORT_5_5_5_1;
 #ifdef _ARCH_ARM_
-      internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
+      glFormat= GL_BGRA_EXT; // alpha is reserved but not used
 #else
-      internalFormat= GL_RGBA;     // alpha is reserved but not used
+      glFormat= GL_RGBA;     // alpha is reserved but not used
 #endif
       break;
     }
@@ -213,14 +217,14 @@ void PixelFormatToGl( Pixel::Format pixelformat, unsigned& pixelDataType, unsign
     case Pixel::RGB888:
     {
       pixelDataType = GL_UNSIGNED_BYTE;
-      internalFormat= GL_RGB;
+      glFormat= GL_RGB;
       break;
     }
 
     case Pixel::RGB8888:
     {
       pixelDataType = GL_UNSIGNED_BYTE;
-      internalFormat= GL_RGBA;     // alpha is reserved but not used
+      glFormat= GL_RGBA;     // alpha is reserved but not used
       break;
     }
 
@@ -228,9 +232,9 @@ void PixelFormatToGl( Pixel::Format pixelformat, unsigned& pixelDataType, unsign
     {
       pixelDataType = GL_UNSIGNED_BYTE;
 #ifdef GL_BGRA_EXT
-      internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
+      glFormat= GL_BGRA_EXT; // alpha is reserved but not used
 #else
-      internalFormat= GL_RGBA;     // alpha is reserved but not used
+      glFormat= GL_RGBA;     // alpha is reserved but not used
 #endif
     break;
     }
@@ -238,7 +242,7 @@ void PixelFormatToGl( Pixel::Format pixelformat, unsigned& pixelDataType, unsign
     case Pixel::RGBA8888:
     {
       pixelDataType = GL_UNSIGNED_BYTE;
-      internalFormat= GL_RGBA;
+      glFormat= GL_RGBA;
       break;
     }
 
@@ -246,9 +250,9 @@ void PixelFormatToGl( Pixel::Format pixelformat, unsigned& pixelDataType, unsign
     {
       pixelDataType = GL_UNSIGNED_BYTE;
 #ifdef GL_BGRA_EXT
-      internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
+      glFormat= GL_BGRA_EXT; // alpha is reserved but not used
 #else
-      internalFormat= GL_RGBA;     // alpha is reserved but not used
+      glFormat= GL_RGBA;     // alpha is reserved but not used
 #endif
       break;
     }
@@ -257,13 +261,13 @@ void PixelFormatToGl( Pixel::Format pixelformat, unsigned& pixelDataType, unsign
     case Pixel::COMPRESSED_RGB8_ETC1:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using non-standard GLES 2.0 extension compressed pixel format COMPRESSED_RGB8_ETC1.\n" );
-      internalFormat = 0x8D64; ///! < Hardcoded so we can test before we move to GLES 3.0 or greater.
+      glFormat = 0x8D64; ///! < Hardcoded so we can test before we move to GLES 3.0 or greater.
       break;
     }
     case Pixel::COMPRESSED_RGB_PVRTC_4BPPV1:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using non-standard GLES 2.0 extension compressed pixel format COMPRESSED_RGB_PVRTC_4BPPV1.\n" );
-      internalFormat = 0x8C00; ///! < Hardcoded so we can test before we move to GLES 3.0 or greater.
+      glFormat = 0x8C00; ///! < Hardcoded so we can test before we move to GLES 3.0 or greater.
       break;
     }
 
@@ -271,61 +275,61 @@ void PixelFormatToGl( Pixel::Format pixelformat, unsigned& pixelDataType, unsign
     case Pixel::COMPRESSED_R11_EAC:
     {
       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_R11_EAC.\n");
-      internalFormat = GL_COMPRESSED_R11_EAC;
+      glFormat = GL_COMPRESSED_R11_EAC;
       break;
     }
     case Pixel::COMPRESSED_SIGNED_R11_EAC:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SIGNED_R11_EAC.\n" );
-      internalFormat = GL_COMPRESSED_SIGNED_R11_EAC;
+      glFormat = GL_COMPRESSED_SIGNED_R11_EAC;
       break;
     }
     case Pixel::COMPRESSED_RG11_EAC:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RG11_EAC.\n" );
-      internalFormat = GL_COMPRESSED_RG11_EAC;
+      glFormat = GL_COMPRESSED_RG11_EAC;
       break;
     }
     case Pixel::COMPRESSED_SIGNED_RG11_EAC:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SIGNED_RG11_EAC.\n" );
-      internalFormat = GL_COMPRESSED_SIGNED_RG11_EAC;
+      glFormat = GL_COMPRESSED_SIGNED_RG11_EAC;
       break;
     }
     case Pixel::COMPRESSED_RGB8_ETC2:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGB8_ETC2.\n" );
-      internalFormat = GL_COMPRESSED_RGB8_ETC2;
+      glFormat = GL_COMPRESSED_RGB8_ETC2;
       break;
     }
     case Pixel::COMPRESSED_SRGB8_ETC2:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_ETC2.\n" );
-      internalFormat = GL_COMPRESSED_SRGB8_ETC2;
+      glFormat = GL_COMPRESSED_SRGB8_ETC2;
       break;
     }
     case Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2.\n" );
-      internalFormat = GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
+      glFormat = GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
       break;
     }
     case Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2.\n" );
-      internalFormat = GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
+      glFormat = GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
       break;
     }
     case Pixel::COMPRESSED_RGBA8_ETC2_EAC:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGBA8_ETC2_EAC.\n" );
-      internalFormat = GL_COMPRESSED_RGBA8_ETC2_EAC;
+      glFormat = GL_COMPRESSED_RGBA8_ETC2_EAC;
       break;
     }
     case Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ETC2_EAC.\n" );
-      internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
+      glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
       break;
     }
 
@@ -333,181 +337,243 @@ void PixelFormatToGl( Pixel::Format pixelformat, unsigned& pixelDataType, unsign
     case Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_4x4_KHR.\n" );
-      internalFormat = GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
+      glFormat = GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
       break;
     }
     case Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_5x4_KHR.\n" );
-      internalFormat = GL_COMPRESSED_RGBA_ASTC_5x4_KHR;
+      glFormat = GL_COMPRESSED_RGBA_ASTC_5x4_KHR;
       break;
     }
     case Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_5x5_KHR.\n" );
-      internalFormat = GL_COMPRESSED_RGBA_ASTC_5x5_KHR;
+      glFormat = GL_COMPRESSED_RGBA_ASTC_5x5_KHR;
       break;
     }
     case Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_6x5_KHR.\n" );
-      internalFormat = GL_COMPRESSED_RGBA_ASTC_6x5_KHR;
+      glFormat = GL_COMPRESSED_RGBA_ASTC_6x5_KHR;
       break;
     }
     case Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_6x6_KHR.\n" );
-      internalFormat = GL_COMPRESSED_RGBA_ASTC_6x6_KHR;
+      glFormat = GL_COMPRESSED_RGBA_ASTC_6x6_KHR;
       break;
     }
     case Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_8x5_KHR.\n" );
-      internalFormat = GL_COMPRESSED_RGBA_ASTC_8x5_KHR;
+      glFormat = GL_COMPRESSED_RGBA_ASTC_8x5_KHR;
       break;
     }
     case Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_8x6_KHR.\n" );
-      internalFormat = GL_COMPRESSED_RGBA_ASTC_8x6_KHR;
+      glFormat = GL_COMPRESSED_RGBA_ASTC_8x6_KHR;
       break;
     }
     case Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_8x8_KHR.\n" );
-      internalFormat = GL_COMPRESSED_RGBA_ASTC_8x8_KHR;
+      glFormat = GL_COMPRESSED_RGBA_ASTC_8x8_KHR;
       break;
     }
     case Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_10x5_KHR.\n" );
-      internalFormat = GL_COMPRESSED_RGBA_ASTC_10x5_KHR;
+      glFormat = GL_COMPRESSED_RGBA_ASTC_10x5_KHR;
       break;
     }
     case Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_10x6_KHR.\n" );
-      internalFormat = GL_COMPRESSED_RGBA_ASTC_10x6_KHR;
+      glFormat = GL_COMPRESSED_RGBA_ASTC_10x6_KHR;
       break;
     }
     case Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_10x8_KHR.\n" );
-      internalFormat = GL_COMPRESSED_RGBA_ASTC_10x8_KHR;
+      glFormat = GL_COMPRESSED_RGBA_ASTC_10x8_KHR;
       break;
     }
     case Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_10x10_KHR.\n" );
-      internalFormat = GL_COMPRESSED_RGBA_ASTC_10x10_KHR;
+      glFormat = GL_COMPRESSED_RGBA_ASTC_10x10_KHR;
       break;
     }
     case Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_12x10_KHR.\n" );
-      internalFormat = GL_COMPRESSED_RGBA_ASTC_12x10_KHR;
+      glFormat = GL_COMPRESSED_RGBA_ASTC_12x10_KHR;
       break;
     }
     case Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_12x12_KHR.\n" );
-      internalFormat = GL_COMPRESSED_RGBA_ASTC_12x12_KHR;
+      glFormat = GL_COMPRESSED_RGBA_ASTC_12x12_KHR;
       break;
     }
     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR.\n" );
-      internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
+      glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
       break;
     }
     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR.\n" );
-      internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
+      glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
       break;
     }
     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR.\n" );
-      internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
+      glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
       break;
     }
     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR.\n" );
-      internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
+      glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
       break;
     }
     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR.\n" );
-      internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
+      glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
       break;
     }
     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR.\n" );
-      internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
+      glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
       break;
     }
     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR.\n" );
-      internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
+      glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
       break;
     }
     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR.\n" );
-      internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
+      glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
       break;
     }
     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR.\n" );
-      internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
+      glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
       break;
     }
     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR.\n" );
-      internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
+      glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
       break;
     }
     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR.\n" );
-      internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
+      glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
       break;
     }
     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR.\n" );
-      internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
+      glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
       break;
     }
     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR.\n" );
-      internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
+      glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
       break;
     }
     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
     {
       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR.\n" );
-      internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
+      glFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
+      break;
+    }
+
+    // GLES 3.0 floating point formats.
+    case Pixel::RGB16F:
+    {
+      glFormat = GL_RGB;
+      pixelDataType = GL_HALF_FLOAT;
+      break;
+    }
+    case Pixel::RGB32F:
+    {
+      glFormat = GL_RGB;
+      pixelDataType = GL_FLOAT;
+      break;
+    }
+
+    // GLES 3.0 depth and stencil formats
+    case Pixel::DEPTH_UNSIGNED_INT:
+    {
+      glFormat = GL_DEPTH_COMPONENT;
+      pixelDataType = GL_UNSIGNED_INT;
+      break;
+    }
+
+    case Pixel::DEPTH_FLOAT:
+    {
+      glFormat = GL_DEPTH_COMPONENT;
+      pixelDataType = GL_FLOAT;
+      break;
+    }
+
+    case Pixel::DEPTH_STENCIL:
+    {
+      glFormat = GL_DEPTH_STENCIL;
+      pixelDataType = GL_UNSIGNED_INT_24_8;
       break;
     }
 
     case Pixel::INVALID:
     {
       DALI_LOG_ERROR( "Invalid pixel format for bitmap\n" );
-      internalFormat = 0;
+      glFormat = 0;
       break;
     }
   }
+
+  switch( pixelFormat )
+  {
+    case Pixel::RGB16F:
+    case Pixel::RGB32F: // FALL THROUGH
+    {
+      glInternalFormat = GL_R11F_G11F_B10F;
+      break;
+    }
+    case Pixel::DEPTH_FLOAT:
+    {
+      glInternalFormat = GL_DEPTH_COMPONENT32F;
+      break;
+    }
+    case Pixel::DEPTH_STENCIL:
+    {
+      glInternalFormat = GL_DEPTH24_STENCIL8;
+      break;
+    }
+    default:
+    {
+      glInternalFormat = glFormat;
+    }
+  }
+
 }
 
+
 /**
  * @brief Whether specified pixel format is compressed.
  *
@@ -532,6 +598,11 @@ bool IsCompressedFormat(Pixel::Format pixelFormat)
     case Pixel::BGR8888:
     case Pixel::RGBA8888:
     case Pixel::BGRA8888:
+    case Pixel::RGB16F:
+    case Pixel::RGB32F:
+    case Pixel::DEPTH_UNSIGNED_INT:
+    case Pixel::DEPTH_FLOAT:
+    case Pixel::DEPTH_STENCIL:
     case Pixel::INVALID:
     {
       return false;
@@ -588,141 +659,172 @@ bool IsCompressedFormat(Pixel::Format pixelFormat)
 } //Unnamed namespace
 
 
-NewTexture::NewTexture( Type type, Pixel::Format format, unsigned int width, unsigned int height )
-:mId( 0 ),
- mType( type ),
- mSampler(),
- mNativeImage(),
- mInternalFormat(GL_RGB),
- mPixelDataType(GL_UNSIGNED_BYTE),
- mWidth( width ),
- mHeight( height ),
- mHasAlpha( HasAlpha( format ) ),
- mIsCompressed( IsCompressedFormat( format ) )
+Texture::Texture( Type type, Pixel::Format format, ImageDimensions size )
+: mNativeImage(),
+  mSampler(),
+  mId( 0 ),
+  mTarget( ( type == TextureType::TEXTURE_2D ) ? GL_TEXTURE_2D : GL_TEXTURE_CUBE_MAP ),
+  mGlInternalFormat( GL_RGB ),
+  mGlFormat( GL_RGB ),
+  mPixelDataType( GL_UNSIGNED_BYTE ),
+  mWidth( size.GetWidth() ),
+  mHeight( size.GetHeight() ),
+  mMaxMipMapLevel( 0 ),
+  mType( type ),
+  mHasAlpha( HasAlpha( format ) ),
+  mIsCompressed( IsCompressedFormat( format ) )
 {
-  PixelFormatToGl( format, mPixelDataType, mInternalFormat );
+  PixelFormatToGl( format,
+                   mGlFormat,
+                   mGlInternalFormat,
+                   mPixelDataType );
 }
 
-NewTexture::NewTexture( NativeImageInterfacePtr nativeImageInterface )
-:mId( 0 ),
- mType( TextureType::TEXTURE_2D ),
- mSampler(),
- mNativeImage( nativeImageInterface ),
- mInternalFormat(GL_RGB),
- mPixelDataType(GL_UNSIGNED_BYTE),
- mWidth( nativeImageInterface->GetWidth() ),
- mHeight( nativeImageInterface->GetHeight() ),
- mHasAlpha( nativeImageInterface->RequiresBlending() ),
- mIsCompressed( false )
+Texture::Texture( NativeImageInterfacePtr nativeImageInterface )
+: mNativeImage( nativeImageInterface ),
+  mSampler(),
+  mId( 0 ),
+  mTarget( GL_TEXTURE_2D ),
+  mGlInternalFormat( GL_RGB ),
+  mGlFormat( GL_RGB ),
+  mPixelDataType( GL_UNSIGNED_BYTE ),
+  mWidth( static_cast<uint16_t >( nativeImageInterface->GetWidth() ) ), // ignoring overflow, not happening in practice
+  mHeight( static_cast<uint16_t >( nativeImageInterface->GetHeight() ) ), // ignoring overflow, not happening in practice
+  mMaxMipMapLevel( 0 ),
+  mType( TextureType::TEXTURE_2D ),
+  mHasAlpha( nativeImageInterface->RequiresBlending() ),
+  mIsCompressed( false )
 {
 }
 
-NewTexture::~NewTexture()
+Texture::~Texture()
 {}
 
-void NewTexture::Destroy( Context& context )
+void Texture::Destroy( Context& context )
 {
   if( mId )
   {
     context.DeleteTextures( 1, &mId );
+
+    if( mNativeImage )
+    {
+      mNativeImage->GlExtensionDestroy();
+    }
   }
 }
 
-void NewTexture::Initialize(Context& context)
+void Texture::GlContextDestroyed()
+{
+  mId = 0u;
+}
+
+void Texture::Initialize(Context& context)
 {
   if( mNativeImage )
   {
     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
-      mNativeImage->TargetTexture();
+      if( mNativeImage->TargetTexture() != 0u )
+      {
+        context.DeleteTextures( 1, &mId );
+        mNativeImage->GlExtensionDestroy();
+        mId = 0u;
+      }
     }
   }
   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 );
+        context.TexImage2D(GL_TEXTURE_2D, 0, mGlInternalFormat, mWidth, mHeight, 0, mGlFormat, mPixelDataType, 0 );
       }
       else
       {
-        context.CompressedTexImage2D(GL_TEXTURE_2D, 0, mInternalFormat, mWidth, mHeight, 0, 0, 0 );
+        context.CompressedTexImage2D(GL_TEXTURE_2D, 0, mGlInternalFormat, 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 )
+        for( uint32_t i(0); i<6; ++i )
         {
-          context.TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, mInternalFormat, mWidth, mHeight, 0, mInternalFormat, mPixelDataType, 0 );
+          context.TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, mGlInternalFormat, mWidth, mHeight, 0, mGlFormat, mPixelDataType, 0 );
         }
       }
       else
       {
-        for( unsigned int i(0); i<6; ++i )
+        for( uint32_t i(0); i<6; ++i )
         {
-          context.CompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, mInternalFormat, mWidth, mHeight, 0, 0, 0 );
+          context.CompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, mGlInternalFormat, 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 );
     }
   }
 }
 
-void NewTexture::Upload( Context& context, PixelDataPtr pixelData, const Internal::NewTexture::UploadParams& params  )
+void Texture::Upload( Context& context, PixelDataPtr pixelData, const Internal::Texture::UploadParams& params  )
 {
   DALI_ASSERT_ALWAYS( mNativeImage == NULL );
 
   //Get pointer to the data of the PixelData object
-  unsigned char* buffer( pixelData->GetBuffer() );
+  uint8_t* buffer( pixelData->GetBuffer() );
 
   //This buffer is only used if manually converting from RGB to RGBA
-  unsigned char* tempBuffer(0);
+  std::vector< uint8_t > tempBuffer;
+
+  //Retrieves the pixel data element type, the gl format and gl internal format of the data contained in the PixelData object.
+  GLenum glFormat;
+  GLint glInternalFormat;
+  GLenum pixelDataElementType;
+  PixelFormatToGl( pixelData->GetPixelFormat(), glFormat, glInternalFormat, pixelDataElementType );
+
+  //Get the maximum mipmap level to set GL_TEXTURE_MAX_LEVEL parameter in GLES3x because is not
+  //necessary to upload all the mipmap levels
+  mMaxMipMapLevel = ( mMaxMipMapLevel > params.mipmap ) ? mMaxMipMapLevel : params.mipmap;
 
-  //Get pixel format and data type of the data contained in the PixelData object
-  GLenum pixelDataFormat, pixelDataElementType;
-  PixelFormatToGl( pixelData->GetPixelFormat(), pixelDataElementType, pixelDataFormat );
+  const bool isSubImage = ( ( params.xOffset != 0 ) ||
+                            ( params.yOffset != 0 ) ||
+                            ( params.width  != ( mWidth  / ( 1 << params.mipmap ) ) ) ||
+                            ( params.height != ( mHeight / ( 1 << params.mipmap ) ) ) );
 
-#if DALI_GLES_VERSION < 30
-  if( pixelDataFormat == GL_RGB && mInternalFormat == GL_RGBA )
+  if( context.TextureRequiresConverting( glFormat, mGlFormat, isSubImage ) )
   {
-    //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;
-    tempBuffer = new unsigned char[dataSize*4u];
-    for( size_t i(0u); i<dataSize; i++ )
+    uint32_t dataSize = static_cast< uint32_t >( params.width ) * params.height;
+    //reserve() does not allocate the memory on some systems so can crash if not populated using push_back
+    tempBuffer.resize( dataSize * 4u );
+    for( uint32_t i = 0u; i < dataSize; ++i )
     {
       tempBuffer[i*4u]   = buffer[i*3u];
       tempBuffer[i*4u+1] = buffer[i*3u+1];
@@ -730,38 +832,31 @@ void NewTexture::Upload( Context& context, PixelDataPtr pixelData, const Interna
       tempBuffer[i*4u+3] = 0xFF;
     }
 
-    buffer = tempBuffer;
-    pixelDataFormat = mInternalFormat;
+    buffer = &tempBuffer[0];
+    glFormat = mGlFormat; // Set the glFormat to GL_RGBA
   }
-#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;
   }
 
   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 )
     {
-      context.TexImage2D( target, params.mipmap, mInternalFormat, params.width, params.height, 0, pixelDataFormat, pixelDataElementType, buffer );
+      context.TexImage2D( target, params.mipmap, mGlInternalFormat, params.width, params.height, 0, glFormat, pixelDataElementType, buffer );
     }
     else
     {
-      context.CompressedTexImage2D( target, params.mipmap, mInternalFormat, params.width, params.height, 0, pixelData->GetBufferSize(), buffer );
+      context.CompressedTexImage2D( target, params.mipmap, mGlInternalFormat, params.width, params.height, 0, static_cast<GLsizei>( pixelData->GetBufferSize() ), buffer );
     }
   }
   else
@@ -771,37 +866,33 @@ void NewTexture::Upload( Context& context, PixelDataPtr pixelData, const Interna
     {
       context.TexSubImage2D( target, params.mipmap,
                              params.xOffset, params.yOffset, params.width, params.height,
-                             pixelDataFormat, pixelDataElementType, buffer );
+                             glFormat, pixelDataElementType, buffer );
     }
     else
     {
       context.CompressedTexSubImage2D( target, params.mipmap,
                                        params.xOffset, params.yOffset, params.width, params.height,
-                                       pixelDataFormat, pixelData->GetBufferSize(), buffer );
+                                       glFormat, static_cast<GLsizei>( pixelData->GetBufferSize() ), buffer );
     }
   }
-
-
-  //Destroy temp buffer used for conversion RGB->RGBA
-  delete[] tempBuffer;
 }
 
-bool NewTexture::Bind( Context& context, unsigned int textureUnit, Render::Sampler* sampler )
+bool Texture::Bind( Context& context, uint32_t textureUnit, Render::Sampler* sampler )
 {
+  if( mNativeImage && mId == 0 )
+  {
+    Initialize( context );
+  }
+
   if( mId != 0 )
   {
-    context.ActiveTexture( static_cast<TextureUnit>(textureUnit) );
+    context.BindTextureForUnit( static_cast<TextureUnit>( textureUnit ), mTarget, mId );
+    ApplySampler( context, sampler );
 
-    if( mType == TextureType::TEXTURE_2D )
+    if( mNativeImage )
     {
-      context.Bind2dTexture( mId );
+      mNativeImage->PrepareTexture();
     }
-    else if( mType == TextureType::TEXTURE_CUBE )
-    {
-      context.BindCubeMapTexture( mId );
-    }
-
-    ApplySampler( context, sampler );
 
     return true;
   }
@@ -809,62 +900,64 @@ bool NewTexture::Bind( Context& context, unsigned int textureUnit, Render::Sampl
   return false;
 }
 
-void NewTexture::ApplySampler( Context& context, Render::Sampler* sampler )
+void Texture::ApplySampler( Context& context, Render::Sampler* sampler )
 {
   Render::Sampler oldSampler = mSampler;
   mSampler = sampler ? *sampler : Sampler();
 
-  if( mSampler.mBitfield != oldSampler.mBitfield )
+  if( mSampler != oldSampler )
   {
-    if( mSampler.mMinificationFilter != oldSampler.mMinificationFilter )
+    GLint mode = FilterModeToGL( mSampler.mMinificationFilter, DALI_MINIFY_DEFAULT, GL_MINIFY_DEFAULT );
+    if( mode != FilterModeToGL( oldSampler.mMinificationFilter, DALI_MINIFY_DEFAULT, GL_MINIFY_DEFAULT ) )
     {
-      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, mode );
     }
 
-    if( mSampler.mMagnificationFilter != oldSampler.mMagnificationFilter )
+    mode = FilterModeToGL( mSampler.mMagnificationFilter, DALI_MAGNIFY_DEFAULT, GL_MAGNIFY_DEFAULT );
+    if( mode != FilterModeToGL( oldSampler.mMagnificationFilter, DALI_MAGNIFY_DEFAULT, GL_MAGNIFY_DEFAULT ) )
     {
-      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, mode );
     }
 
-    if( mSampler.mSWrapMode != oldSampler.mSWrapMode )
+    mode = WrapModeToGL( mSampler.mSWrapMode, GL_WRAP_DEFAULT );
+    if( mode != WrapModeToGL( oldSampler.mSWrapMode, GL_WRAP_DEFAULT ) )
     {
-      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, mode );
     }
 
-    if( mSampler.mTWrapMode != oldSampler.mTWrapMode )
+    mode = WrapModeToGL( mSampler.mTWrapMode, GL_WRAP_DEFAULT );
+    if( mode != WrapModeToGL( oldSampler.mTWrapMode, GL_WRAP_DEFAULT ) )
     {
-      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, mode );
+    }
+
+    if( mType == TextureType::TEXTURE_CUBE )
+    {
+      mode = WrapModeToGL( mSampler.mRWrapMode, GL_WRAP_DEFAULT );
+      if( mode != WrapModeToGL( oldSampler.mRWrapMode, GL_WRAP_DEFAULT ) )
+      {
+        context.TexParameteri( mTarget, GL_TEXTURE_WRAP_R, mode );
+      }
     }
 
-    if( mType == TextureType::TEXTURE_CUBE && mSampler.mRWrapMode != oldSampler.mRWrapMode )
+    if(mMaxMipMapLevel)
     {
-      GLint glWrapMode = WrapModeToGL( mSampler.mRWrapMode, GL_WRAP_DEFAULT );
-      context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, glWrapMode );
+      context.TexParameteri( mTarget, GL_TEXTURE_MAX_LEVEL, mMaxMipMapLevel );
     }
   }
 }
 
-bool NewTexture::HasAlphaChannel()
+bool Texture::HasAlphaChannel() const
 {
   return mHasAlpha;
 }
 
-void NewTexture::GenerateMipmaps( Context& context )
+void Texture::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 );
-  }
+  //GL_TEXTURE_MAX_LEVEL does not need to be set when mipmaps are generated by GL
+  mMaxMipMapLevel = 0;
+  context.BindTexture( mTarget, mId );
+  context.GenerateMipmap( mTarget );
 }
 
 } //Render