Added API to apply native texture modification to shader 82/243982/2
authorDavid Steele <david.steele@samsung.com>
Fri, 11 Sep 2020 16:20:47 +0000 (17:20 +0100)
committerDavid Steele <david.steele@samsung.com>
Mon, 14 Sep 2020 09:55:52 +0000 (10:55 +0100)
If a given texture is using a Native Image, then update the shader
using the custom prefix and sampler from that NativeImage.

Change-Id: Ic94e5b6eb90ad453d9e7e288837964634f20a2db
Signed-off-by: David Steele <david.steele@samsung.com>
automated-tests/src/dali/utc-Dali-Texture.cpp
dali/devel-api/file.list
dali/devel-api/rendering/texture-devel.cpp [new file with mode: 0644]
dali/devel-api/rendering/texture-devel.h [new file with mode: 0644]
dali/internal/event/rendering/texture-impl.cpp
dali/internal/event/rendering/texture-impl.h

index 60810d1..95cb6c8 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <dali-test-suite-utils.h>
 #include <dali/devel-api/images/pixel-data-devel.h>
+#include <dali/devel-api/rendering/texture-devel.h>
 #include <dali/public-api/dali-core.h>
 #include <test-native-image.h>
 
@@ -940,3 +941,122 @@ int UtcDaliTextureGetHeightNegative(void)
   }
   END_TEST;
 }
+
+int UtcDaliTextureCheckNativeP(void)
+{
+  TestApplication        application;
+  TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
+  Texture                nativeTexture   = Texture::New(*testNativeImage);
+
+  DALI_TEST_CHECK(nativeTexture);
+  DALI_TEST_CHECK(DevelTexture::IsNative(nativeTexture));
+  END_TEST;
+}
+
+int UtcDaliTextureCheckNativeN1(void)
+{
+  TestApplication application;
+  unsigned int    width(64);
+  unsigned int    height(64);
+  Texture         texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
+
+  DALI_TEST_CHECK(texture);
+  DALI_TEST_CHECK(!DevelTexture::IsNative(texture));
+  END_TEST;
+}
+
+int UtcDaliTextureCheckNativeN2(void)
+{
+  TestApplication application;
+  Texture         texture;
+  try
+  {
+    bool native = DevelTexture::IsNative(texture);
+    DALI_TEST_CHECK(native != native);
+  }
+  catch(...)
+  {
+    DALI_TEST_CHECK(true);
+  }
+  END_TEST;
+}
+
+int UtcDaliTextureApplyFragShaderP1(void)
+{
+  TestApplication        application;
+  TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
+  Texture                nativeTexture   = Texture::New(*testNativeImage);
+  DALI_TEST_CHECK(nativeTexture);
+
+  const std::string baseFragShader =
+    "varying mediump vec4 uColor;\n"
+    "void main(){\n"
+    "  gl_FragColor=uColor;\n"
+    "}\n";
+  std::string fragShader = baseFragShader;
+  bool        applied    = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
+
+  DALI_TEST_CHECK(applied);
+  DALI_TEST_CHECK(baseFragShader.compare(fragShader));
+  DALI_TEST_CHECK(!fragShader.empty());
+  END_TEST;
+}
+
+int UtcDaliTextureApplyFragShaderP2(void)
+{
+  TestApplication        application;
+  TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
+  Texture                nativeTexture   = Texture::New(*testNativeImage);
+  DALI_TEST_CHECK(nativeTexture);
+
+  const std::string baseFragShader =
+    "varying mediump vec4 uColor;\n"
+    "varying vec2 vTexCoord;\n"
+    "uniform sampler2D uNative;\n"
+    "void main(){\n"
+    "  gl_FragColor=uColor*texture2D(uNative, vTexCoord);\n"
+    "}\n";
+  std::string fragShader = baseFragShader;
+  bool        applied    = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
+
+  DALI_TEST_CHECK(applied);
+  DALI_TEST_CHECK(baseFragShader.compare(fragShader));
+  DALI_TEST_CHECK(!fragShader.empty());
+  DALI_TEST_CHECK(fragShader.find("samplerExternalOES") < fragShader.length());
+  END_TEST;
+}
+
+int UtcDaliTextureApplyFragShaderN1(void)
+{
+  TestApplication        application;
+  TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
+  Texture                nativeTexture   = Texture::New(*testNativeImage);
+  DALI_TEST_CHECK(nativeTexture);
+
+  std::string fragShader;
+  bool        applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
+
+  DALI_TEST_CHECK(!applied);
+  DALI_TEST_CHECK(fragShader.empty());
+  END_TEST;
+}
+
+int UtcDaliTextureApplyFragShaderN2(void)
+{
+  TestApplication application;
+  unsigned int    width(64);
+  unsigned int    height(64);
+  Texture         texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
+
+  const std::string baseFragShader =
+    "varying mediump vec4 uColor;\n"
+    "void main(){\n"
+    "  gl_FragColor=uColor;\n"
+    "}\n";
+  std::string fragShader = baseFragShader;
+  bool        applied    = DevelTexture::ApplyNativeFragmentShader(texture, fragShader);
+
+  DALI_TEST_CHECK(!applied);
+  DALI_TEST_CHECK(!baseFragShader.compare(fragShader));
+  END_TEST;
+}
index dc872d3..a6dba21 100644 (file)
@@ -30,6 +30,7 @@ SET( devel_api_src_files
   ${devel_api_src_dir}/object/csharp-type-registry.cpp
   ${devel_api_src_dir}/rendering/frame-buffer-devel.cpp
   ${devel_api_src_dir}/rendering/renderer-devel.cpp
+  ${devel_api_src_dir}/rendering/texture-devel.cpp
   ${devel_api_src_dir}/scripting/scripting.cpp
   ${devel_api_src_dir}/signals/signal-delegate.cpp
   ${devel_api_src_dir}/threading/conditional-wait.cpp
@@ -107,6 +108,7 @@ SET( devel_api_core_object_header_files
 SET( devel_api_core_rendering_header_files
   ${devel_api_src_dir}/rendering/frame-buffer-devel.h
   ${devel_api_src_dir}/rendering/renderer-devel.h
+  ${devel_api_src_dir}/rendering/texture-devel.h
 )
 
 
diff --git a/dali/devel-api/rendering/texture-devel.cpp b/dali/devel-api/rendering/texture-devel.cpp
new file mode 100644 (file)
index 0000000..d56cae6
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dali/devel-api/rendering/texture-devel.h>
+#include <dali/internal/event/rendering/texture-impl.h>
+
+namespace Dali
+{
+namespace DevelTexture
+{
+bool IsNative(Dali::Texture texture)
+{
+  auto& impl = GetImplementation(texture);
+  return impl.IsNative();
+}
+
+bool ApplyNativeFragmentShader(Dali::Texture texture, std::string& shader)
+{
+  auto& impl = GetImplementation(texture);
+  return impl.ApplyNativeFragmentShader(shader);
+}
+
+} // namespace DevelTexture
+} // namespace Dali
diff --git a/dali/devel-api/rendering/texture-devel.h b/dali/devel-api/rendering/texture-devel.h
new file mode 100644 (file)
index 0000000..0204a41
--- /dev/null
@@ -0,0 +1,50 @@
+#ifndef DALI_TEXTURE_DEVEL_H
+#define DALI_TEXTURE_DEVEL_H
+
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali/public-api/rendering/texture.h>
+
+namespace Dali
+{
+namespace DevelTexture
+{
+/**
+ * @brief Function to determine if a texture is backed by a native image.
+ *
+ * @return True if the texture is a native image.
+ */
+bool DALI_CORE_API IsNative(Dali::Texture texture);
+
+/**
+ * @brief Converts shader for native image.
+ *
+ * Applies any specific native shader prefix and sampler code to the
+ * given shader.
+ *
+ * @param[in] texture The texture the shader will apply to
+ * @param[in] shader The fragment shader code to modify
+ * @return True if the shader code was modified
+ */
+bool DALI_CORE_API ApplyNativeFragmentShader(Dali::Texture texture, std::string& shader);
+
+} // namespace DevelTexture
+} // namespace Dali
+
+#endif // DALI_TEXTURE_DEVEL_H
index 7dbc73d..54d611f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 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.
 #include <dali/internal/event/rendering/texture-impl.h> // Dali::Internal::Texture
 
 // INTERNAL INCLUDES
-#include <dali/internal/update/manager/update-manager.h>
-#include <dali/internal/event/common/stage-impl.h>
 #include <dali/integration-api/render-controller.h>
+#include <dali/internal/event/common/stage-impl.h>
+#include <dali/internal/update/manager/update-manager.h>
+
+// EXTERNAL INCLUDES
+#include <cstring>
+
+namespace
+{
+const char* DEFAULT_SAMPLER_TYPENAME = "sampler2D";
+} // namespace
 
 namespace Dali
 {
 namespace Internal
 {
-
-TexturePtr Texture::New(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height )
+TexturePtr Texture::New(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height)
 {
-  constexpr auto max_value = std::numeric_limits< uint16_t >::max();
-  DALI_ASSERT_ALWAYS( ( width < max_value )&&( height < max_value )&& "Size out of range" );
-  TexturePtr texture( new Texture( type, format, ImageDimensions( width, height) ) );
+  constexpr auto max_value = std::numeric_limits<uint16_t>::max();
+  DALI_ASSERT_ALWAYS((width < max_value) && (height < max_value) && "Size out of range");
+  TexturePtr texture(new Texture(type, format, ImageDimensions(width, height)));
   texture->Initialize();
   return texture;
 }
 
-TexturePtr Texture::New( NativeImageInterface& nativeImageInterface )
+TexturePtr Texture::New(NativeImageInterface& nativeImageInterface)
 {
-  TexturePtr texture( new Texture( &nativeImageInterface ) );
+  TexturePtr texture(new Texture(&nativeImageInterface));
   texture->Initialize();
 
   // Request event processing and update forcely.
-  texture->mEventThreadServices.GetRenderController().RequestProcessEventsOnIdle( true );
+  texture->mEventThreadServices.GetRenderController().RequestProcessEventsOnIdle(true);
   texture->mEventThreadServices.ForceNextUpdate();
   return texture;
 }
@@ -53,112 +60,115 @@ Render::Texture* Texture::GetRenderObject() const
   return mRenderObject;
 }
 
-Texture::Texture(TextureType::Type type, Pixel::Format format, ImageDimensions size )
-: mEventThreadServices( EventThreadServices::Get() ),
-  mRenderObject( nullptr ),
+Texture::Texture(TextureType::Type type, Pixel::Format format, ImageDimensions size)
+: mEventThreadServices(EventThreadServices::Get()),
+  mRenderObject(nullptr),
   mNativeImage(),
-  mSize( size ),
-  mType( type ),
-  mFormat( format )
+  mSize(size),
+  mType(type),
+  mFormat(format)
 {
 }
 
-Texture::Texture( NativeImageInterfacePtr nativeImageInterface )
-: mEventThreadServices( EventThreadServices::Get() ),
-  mRenderObject( nullptr ),
-  mNativeImage( nativeImageInterface ),
-  mSize( nativeImageInterface->GetWidth(), nativeImageInterface->GetHeight() ),
-  mType( TextureType::TEXTURE_2D ),
-  mFormat( Pixel::RGB888 )
+Texture::Texture(NativeImageInterfacePtr nativeImageInterface)
+: mEventThreadServices(EventThreadServices::Get()),
+  mRenderObject(nullptr),
+  mNativeImage(nativeImageInterface),
+  mSize(nativeImageInterface->GetWidth(), nativeImageInterface->GetHeight()),
+  mType(TextureType::TEXTURE_2D),
+  mFormat(Pixel::RGB888)
 {
 }
 
 void Texture::Initialize()
 {
-  if( EventThreadServices::IsCoreRunning() )
+  if(EventThreadServices::IsCoreRunning())
   {
-    if( mNativeImage )
+    if(mNativeImage)
     {
-      mRenderObject = new Render::Texture( mNativeImage );
+      mRenderObject = new Render::Texture(mNativeImage);
     }
     else
     {
-      mRenderObject = new Render::Texture( mType, mFormat, mSize );
+      mRenderObject = new Render::Texture(mType, mFormat, mSize);
     }
 
-    OwnerPointer< Render::Texture > transferOwnership( mRenderObject );
-    AddTexture( mEventThreadServices.GetUpdateManager(), transferOwnership );
+    OwnerPointer<Render::Texture> transferOwnership(mRenderObject);
+    AddTexture(mEventThreadServices.GetUpdateManager(), transferOwnership);
   }
 }
 
 Texture::~Texture()
 {
-  if( EventThreadServices::IsCoreRunning() && mRenderObject )
+  if(EventThreadServices::IsCoreRunning() && mRenderObject)
   {
-    RemoveTexture( mEventThreadServices.GetUpdateManager(), *mRenderObject );
+    RemoveTexture(mEventThreadServices.GetUpdateManager(), *mRenderObject);
   }
 }
 
-bool Texture::Upload( PixelDataPtr pixelData )
+bool Texture::Upload(PixelDataPtr pixelData)
 {
-  return Upload( pixelData, 0u, 0u, 0u, 0u, pixelData->GetWidth(), pixelData->GetHeight() );
+  return Upload(pixelData, 0u, 0u, 0u, 0u, pixelData->GetWidth(), pixelData->GetHeight());
 }
 
-bool Texture::Upload( PixelDataPtr pixelData,
-                      unsigned int layer, unsigned int mipmap,
-                      unsigned int xOffset, unsigned int yOffset,
-                      unsigned int width, unsigned int height )
+bool Texture::Upload(PixelDataPtr pixelData,
+                     unsigned int layer,
+                     unsigned int mipmap,
+                     unsigned int xOffset,
+                     unsigned int yOffset,
+                     unsigned int width,
+                     unsigned int height)
 {
-  constexpr auto max_value = std::numeric_limits< uint16_t >::max();
-  DALI_ASSERT_ALWAYS( layer < max_value &&
-                      mipmap < max_value &&
-                      xOffset < max_value &&
-                      yOffset < max_value &&
-                      width < max_value &&
-                      height < max_value &&
-                      "Parameter value out of range" );
+  constexpr auto max_value = std::numeric_limits<uint16_t>::max();
+  DALI_ASSERT_ALWAYS(layer < max_value &&
+                     mipmap < max_value &&
+                     xOffset < max_value &&
+                     yOffset < max_value &&
+                     width < max_value &&
+                     height < max_value &&
+                     "Parameter value out of range");
 
   bool result(false);
-  if( EventThreadServices::IsCoreRunning() && mRenderObject )
+  if(EventThreadServices::IsCoreRunning() && mRenderObject)
   {
-    if( mNativeImage )
+    if(mNativeImage)
     {
-      DALI_LOG_ERROR( "OpenGL ES does not support uploading data to native texture\n");
+      DALI_LOG_ERROR("OpenGL ES does not support uploading data to native texture\n");
     }
     else
     {
-      unsigned int pixelDataSize = pixelData->GetWidth()*pixelData->GetHeight();
-      if( pixelData->GetBuffer() == nullptr || pixelDataSize == 0 )
+      unsigned int pixelDataSize = pixelData->GetWidth() * pixelData->GetHeight();
+      if(pixelData->GetBuffer() == nullptr || pixelDataSize == 0)
       {
-        DALI_LOG_ERROR( "PixelData is empty\n");
+        DALI_LOG_ERROR("PixelData is empty\n");
       }
       else
       {
         Pixel::Format pixelDataFormat = pixelData->GetPixelFormat();
-        if( ( pixelDataFormat == mFormat ) || ( (pixelDataFormat == Pixel::RGB888 ) && ( mFormat == Pixel::RGBA8888 ) ) )
+        if((pixelDataFormat == mFormat) || ((pixelDataFormat == Pixel::RGB888) && (mFormat == Pixel::RGBA8888)))
         {
-          if( pixelDataSize < width * height )
+          if(pixelDataSize < width * height)
           {
-            DALI_LOG_ERROR( "PixelData of an incorrect size when trying to update texture\n");
+            DALI_LOG_ERROR("PixelData of an incorrect size when trying to update texture\n");
           }
-          else if( ( xOffset + width  > ( mSize.GetWidth()  / (1u << mipmap) ) ) ||
-              ( yOffset + height > ( mSize.GetHeight() / (1u << mipmap) ) ) )
+          else if((xOffset + width > (mSize.GetWidth() / (1u << mipmap))) ||
+                  (yOffset + height > (mSize.GetHeight() / (1u << mipmap))))
           {
-            DALI_LOG_ERROR( "Texture update area out of bounds\n");
+            DALI_LOG_ERROR("Texture update area out of bounds\n");
           }
           else
           {
             //Parameters are correct. Send message to upload data to the texture
-            UploadParams params = { static_cast< uint16_t >( layer ),
-                                    static_cast< uint16_t >( mipmap ),
-                                    static_cast< uint16_t >( xOffset ),
-                                    static_cast< uint16_t >( yOffset ),
-                                    static_cast< uint16_t >( width ),
-                                    static_cast< uint16_t >( height ) };
-            UploadTextureMessage( mEventThreadServices.GetUpdateManager(), *mRenderObject, pixelData, params );
+            UploadParams params = {static_cast<uint16_t>(layer),
+                                   static_cast<uint16_t>(mipmap),
+                                   static_cast<uint16_t>(xOffset),
+                                   static_cast<uint16_t>(yOffset),
+                                   static_cast<uint16_t>(width),
+                                   static_cast<uint16_t>(height)};
+            UploadTextureMessage(mEventThreadServices.GetUpdateManager(), *mRenderObject, pixelData, params);
 
             // Request event processing and update forcely
-            mEventThreadServices.GetRenderController().RequestProcessEventsOnIdle( true );
+            mEventThreadServices.GetRenderController().RequestProcessEventsOnIdle(true);
             mEventThreadServices.ForceNextUpdate();
 
             result = true;
@@ -166,7 +176,7 @@ bool Texture::Upload( PixelDataPtr pixelData,
         }
         else
         {
-          DALI_LOG_ERROR( "Bad format\n");
+          DALI_LOG_ERROR("Bad format\n");
         }
       }
     }
@@ -177,9 +187,9 @@ bool Texture::Upload( PixelDataPtr pixelData,
 
 void Texture::GenerateMipmaps()
 {
-  if( EventThreadServices::IsCoreRunning() && mRenderObject )
+  if(EventThreadServices::IsCoreRunning() && mRenderObject)
   {
-    GenerateMipmapsMessage(mEventThreadServices.GetUpdateManager(), *mRenderObject );
+    GenerateMipmapsMessage(mEventThreadServices.GetUpdateManager(), *mRenderObject);
   }
 }
 
@@ -193,5 +203,46 @@ unsigned int Texture::GetHeight() const
   return mSize.GetHeight();
 }
 
+bool Texture::IsNative() const
+{
+  return mNativeImage != nullptr;
+}
+
+bool Texture::ApplyNativeFragmentShader(std::string& shader)
+{
+  std::string fragmentShader;
+  bool        modified = false;
+  if(mNativeImage != nullptr && !shader.empty())
+  {
+    const char* fragmentPrefix        = mNativeImage->GetCustomFragmentPrefix();
+    const char* customSamplerTypename = mNativeImage->GetCustomSamplerTypename();
+
+    if(fragmentPrefix != nullptr)
+    {
+      modified       = true;
+      fragmentShader = fragmentPrefix;
+      fragmentShader += "\n";
+    }
+    fragmentShader += shader;
+
+    if(customSamplerTypename != nullptr)
+    {
+      modified   = true;
+      size_t pos = fragmentShader.find(DEFAULT_SAMPLER_TYPENAME);
+      if(pos < fragmentShader.length())
+      {
+        fragmentShader.replace(pos, strlen(DEFAULT_SAMPLER_TYPENAME), customSamplerTypename);
+      }
+    }
+  }
+
+  if(modified)
+  {
+    shader = fragmentShader;
+  }
+
+  return modified;
+}
+
 } // namespace Internal
 } // namespace Dali
index d7f6b4a..57b098d 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_NEW_TEXTURE_H
 
 /*
- * 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.
  */
 
 // INTERNAL INCLUDES
-#include <dali/public-api/common/dali-common.h> // DALI_ASSERT_ALWAYS
-#include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
-#include <dali/public-api/object/base-object.h>
-#include <dali/public-api/images/pixel.h>
-#include <dali/public-api/images/image-operations.h> // Dali::ImageDimensions
-#include <dali/public-api/rendering/texture.h> // Dali::Internal::Render::Texture
 #include <dali/internal/event/common/event-thread-services.h>
 #include <dali/internal/event/images/pixel-data-impl.h>
+#include <dali/public-api/common/dali-common.h>      // DALI_ASSERT_ALWAYS
+#include <dali/public-api/common/intrusive-ptr.h>    // Dali::IntrusivePtr
+#include <dali/public-api/images/image-operations.h> // Dali::ImageDimensions
+#include <dali/public-api/images/pixel.h>
+#include <dali/public-api/object/base-object.h>
+#include <dali/public-api/rendering/texture.h> // Dali::Internal::Render::Texture
 
 namespace Dali
 {
@@ -43,18 +43,17 @@ using TexturePtr = IntrusivePtr<Texture>;
 class Texture : public BaseObject
 {
 public:
-
   /**
    * @brief Structure used to pass parameters to the Upload method
    */
   struct UploadParams
   {
-    uint16_t layer;    ///< Specifies the layer of a cube map or array texture
-    uint16_t mipmap;   ///< Specifies the level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image.
-    uint16_t xOffset;  ///< Specifies a texel offset in the x direction within the texture array.
-    uint16_t yOffset;  ///< Specifies a texel offset in the y direction within the texture array.
-    uint16_t width;    ///< Specifies the width of the texture subimage
-    uint16_t height;   ///< Specifies the height of the texture subimage.
+    uint16_t layer;   ///< Specifies the layer of a cube map or array texture
+    uint16_t mipmap;  ///< Specifies the level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image.
+    uint16_t xOffset; ///< Specifies a texel offset in the x direction within the texture array.
+    uint16_t yOffset; ///< Specifies a texel offset in the y direction within the texture array.
+    uint16_t width;   ///< Specifies the width of the texture subimage
+    uint16_t height;  ///< Specifies the height of the texture subimage.
   };
 
   /**
@@ -73,7 +72,7 @@ public:
    * @param[in] nativeImageInterface The native image
    * @return A smart-pointer to the newly allocated Texture.
    */
-  static TexturePtr New( NativeImageInterface& nativeImageInterface );
+  static TexturePtr New(NativeImageInterface& nativeImageInterface);
 
   /**
    * @brief Get the texture render object
@@ -85,15 +84,18 @@ public:
   /**
    * @copydoc Dali::Texture::Upload()
    */
-  bool Upload( PixelDataPtr pixelData );
+  bool Upload(PixelDataPtr pixelData);
 
   /**
    * @copydoc Dali::Texture::Upload()
    */
-  bool Upload( PixelDataPtr pixelData,
-               unsigned int layer, unsigned int mipmap,
-               unsigned int xOffset, unsigned int yOffset,
-               unsigned int width, unsigned int height );
+  bool Upload(PixelDataPtr pixelData,
+              unsigned int layer,
+              unsigned int mipmap,
+              unsigned int xOffset,
+              unsigned int yOffset,
+              unsigned int width,
+              unsigned int height);
 
   /**
    * @copydoc Dali::Texture::GenerateMipmaps()
@@ -110,21 +112,35 @@ public:
    */
   unsigned int GetHeight() const;
 
-private: // implementation
+  /**
+   * @brief Determine if the texture is a native image
+   *
+   * @return true if the texture has been initialized with a native image
+   */
+  bool IsNative() const;
+
+  /**
+   * @brief Apply any native texture code to the given fragment shader
+   *
+   * @param[in,out] shader The fragment shader
+   * @return true if the shader has been modified.
+   */
+  bool ApplyNativeFragmentShader(std::string& shader);
 
+private: // implementation
   /**
    * Constructor
    * @param[in] type The type of the texture
    * @param[in] format The format of the pixel data
    * @param[in] size The size of the texture
    */
-  Texture(TextureType::Type type, Pixel::Format format, ImageDimensions size );
+  Texture(TextureType::Type type, Pixel::Format format, ImageDimensions size);
 
   /**
    * Constructor from native image
    * @param[in] nativeImageInterface The native image
    */
-  Texture( NativeImageInterfacePtr nativeImageInterface );
+  Texture(NativeImageInterfacePtr nativeImageInterface);
 
   /**
    * Second stage initialization of the Texture
@@ -132,26 +148,23 @@ private: // implementation
   void Initialize();
 
 protected:
-
   /**
    * A reference counted object may only be deleted by calling Unreference()
    */
   ~Texture() override;
 
 private: // unimplemented methods
-  Texture( const Texture& );
-  Texture& operator=( const Texture& );
+  Texture(const Texture&);
+  Texture& operator=(const Texture&);
 
-private: // data
-
-  Internal::EventThreadServices& mEventThreadServices;    ///<Used to send messages to the render thread via update thread
-  Internal::Render::Texture* mRenderObject;            ///<The Render::Texture associated to this texture
+private:                                               // data
+  Internal::EventThreadServices& mEventThreadServices; ///<Used to send messages to the render thread via update thread
+  Internal::Render::Texture*     mRenderObject;        ///<The Render::Texture associated to this texture
 
   NativeImageInterfacePtr mNativeImage; ///< Pointer to native image
-  ImageDimensions mSize;                ///< Size of the texture
+  ImageDimensions         mSize;        ///< Size of the texture
   Dali::TextureType::Type mType;        ///< Texture type (cached)
-  Pixel::Format mFormat;                ///< Pixel format
-
+  Pixel::Format           mFormat;      ///< Pixel format
 };
 
 } // namespace Internal