New Texture API clean-up 60/73760/4
authorFerran Sole <ferran.sole@samsung.com>
Thu, 9 Jun 2016 10:25:28 +0000 (11:25 +0100)
committerFerran Sole <ferran.sole@samsung.com>
Thu, 9 Jun 2016 13:52:27 +0000 (14:52 +0100)
- New API to upload data to textures and to set output texture of a framebuffer
- Added test cases for Texture and FrameBuffer objects

Change-Id: I99aa20da83ab2a6c76655b331d1520cdc90c7916

21 files changed:
automated-tests/src/dali-devel/CMakeLists.txt
automated-tests/src/dali-devel/utc-Dali-Atlas.cpp
automated-tests/src/dali-devel/utc-Dali-FrameBuffer.cpp [new file with mode: 0644]
automated-tests/src/dali-devel/utc-Dali-Texture.cpp [new file with mode: 0644]
automated-tests/src/dali-devel/utc-Dali-TextureSet.cpp
automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h
automated-tests/src/dali/utc-Dali-BufferImage.cpp
dali/devel-api/rendering/frame-buffer.cpp
dali/devel-api/rendering/frame-buffer.h
dali/devel-api/rendering/shader.h
dali/devel-api/rendering/texture.cpp
dali/devel-api/rendering/texture.h
dali/internal/event/rendering/texture-impl.cpp
dali/internal/event/rendering/texture-impl.h
dali/internal/event/rendering/texture-set-impl.cpp
dali/internal/render/common/render-manager.cpp
dali/internal/render/common/render-manager.h
dali/internal/render/renderers/render-texture.cpp
dali/internal/render/renderers/render-texture.h
dali/internal/update/manager/update-manager.cpp
dali/internal/update/manager/update-manager.h

index a0091c8..59fca0d 100644 (file)
@@ -12,9 +12,11 @@ SET(TC_SOURCES
         utc-Dali-Context.cpp
         utc-Dali-Constrainer.cpp
         utc-Dali-DistanceField.cpp
+        utc-Dali-FrameBuffer.cpp
         utc-Dali-Geometry.cpp
         utc-Dali-Hash.cpp
         utc-Dali-HitTestAlgorithm.cpp
+        utc-Dali-Texture.cpp
         utc-Dali-TextureSet.cpp
         utc-Dali-Mutex.cpp
         utc-Dali-PixelData.cpp
index 78e49c2..34d4457 100644 (file)
@@ -146,7 +146,9 @@ int UtcDaliAtlasClear(void)
   application.SendNotification();
   callStack.Enable(false);
 
-  DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", "0, 0, 16, 32") );
+  std::stringstream out;
+  out << GL_TEXTURE_2D <<", "<< 0u << ", " << 0u << ", " << 0u << ", " << 16u <<", "<< 32u;
+  DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str() ) );
 
   END_TEST;
 }
@@ -182,9 +184,21 @@ int UtcDaliAtlasUpload01P(void)
   application.SendNotification();
   callStack.Enable(false);
 
-  DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", "0, 0, 16, 16") );
-  DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", "0, 16, 16, 16") );
-  DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", "2, 32, 6, 8") );
+  {
+    std::stringstream out;
+    out << GL_TEXTURE_2D <<", "<< 0u << ", " << 0u << ", " << 0u << ", " << 16u <<", "<< 16u;
+    DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str() ) );
+  }
+  {
+    std::stringstream out;
+    out << GL_TEXTURE_2D <<", "<< 0u << ", " << 0u << ", " << 16u << ", " << 16u <<", "<< 16u;
+    DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str() ) );
+  }
+  {
+    std::stringstream out;
+    out << GL_TEXTURE_2D <<", "<< 0u << ", " << 2u << ", " << 32u << ", " << 6u <<", "<< 8u;
+    DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str() ) );
+  }
 
   END_TEST;
 }
@@ -219,9 +233,21 @@ int UtcDaliAtlasUpload02P(void)
   application.SendNotification();
   callStack.Enable(false);
 
-  DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", "0, 0, 16, 16") );
-  DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", "6, 6, 12, 12") );
-  DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", "10, 10, 8, 8") );
+  {
+    std::stringstream out;
+    out << GL_TEXTURE_2D <<", "<< 0u << ", " << 0u << ", " << 0u << ", " << 16u <<", "<< 16u;
+    DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str() ) );
+  }
+  {
+    std::stringstream out;
+    out << GL_TEXTURE_2D <<", "<< 0u << ", " << 6u << ", " << 6u << ", " << 12u <<", "<< 12u;
+    DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str() ) );
+  }
+  {
+    std::stringstream out;
+    out << GL_TEXTURE_2D <<", "<< 0u << ", " << 10u << ", " << 10u << ", " << 8u <<", "<< 8u;
+    DALI_TEST_CHECK( callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str() ) );
+  }
 
   END_TEST;
 }
diff --git a/automated-tests/src/dali-devel/utc-Dali-FrameBuffer.cpp b/automated-tests/src/dali-devel/utc-Dali-FrameBuffer.cpp
new file mode 100644 (file)
index 0000000..9943923
--- /dev/null
@@ -0,0 +1,275 @@
+/*
+ * Copyright (c) 2015 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/public-api/dali-core.h>
+#include <dali-test-suite-utils.h>
+#include <dali/devel-api/rendering/frame-buffer.h>
+
+using namespace Dali;
+
+#include <mesh-builder.h>
+
+void framebuffer_set_startup(void)
+{
+  test_return_value = TET_UNDEF;
+}
+
+void framebuffer_set_cleanup(void)
+{
+  test_return_value = TET_PASS;
+}
+
+int UtcDaliFrameBufferNew01(void)
+{
+  TestApplication application;
+
+  unsigned int width(64);
+  unsigned int height(64);
+  FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR );
+
+  DALI_TEST_CHECK( frameBuffer );
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliFrameBufferNew02(void)
+{
+  TestApplication application;
+
+  unsigned int width(64);
+  unsigned int height(64);
+  FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR_DEPTH );
+
+  DALI_TEST_CHECK( frameBuffer );
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliFrameBufferNew03(void)
+{
+  TestApplication application;
+
+  unsigned int width(64);
+  unsigned int height(64);
+  FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR_STENCIL );
+
+  DALI_TEST_CHECK( frameBuffer );
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliFrameBufferNew04(void)
+{
+  TestApplication application;
+
+  unsigned int width(64);
+  unsigned int height(64);
+  FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR_DEPTH_STENCIL );
+
+  DALI_TEST_CHECK( frameBuffer );
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliFrameBufferNew05(void)
+{
+  TestApplication application;
+  FrameBuffer frameBuffer;
+  DALI_TEST_CHECK( !frameBuffer );
+  END_TEST;
+}
+
+int UtcDaliFrameBufferCopyConstructor(void)
+{
+  TestApplication application;
+
+  unsigned int width(64);
+  unsigned int height(64);
+  FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR );
+
+  FrameBuffer frameBufferCopy( frameBuffer );
+
+  DALI_TEST_CHECK( frameBufferCopy );
+
+  END_TEST;
+}
+
+int UtcDaliFrameBufferAssignmentOperator(void)
+{
+  TestApplication application;
+
+  unsigned int width(64);
+  unsigned int height(64);
+  FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR );
+
+  FrameBuffer frameBuffer2;
+  DALI_TEST_CHECK( !frameBuffer2 );
+
+  frameBuffer2 = frameBuffer;
+  DALI_TEST_CHECK( frameBuffer2 );
+
+  END_TEST;
+}
+
+int UtcDaliFrameBufferDownCast01(void)
+{
+  TestApplication application;
+  unsigned int width(64);
+  unsigned int height(64);
+  FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR );
+
+  BaseHandle handle(frameBuffer);
+  FrameBuffer frameBuffer2 = FrameBuffer::DownCast(handle);
+  DALI_TEST_CHECK( frameBuffer2 );
+
+  END_TEST;
+}
+
+int UtcDaliFrameBufferDownCast02(void)
+{
+  TestApplication application;
+
+  Handle handle = Handle::New(); // Create a custom object
+  FrameBuffer frameBuffer = FrameBuffer::DownCast(handle);
+  DALI_TEST_CHECK( !frameBuffer );
+  END_TEST;
+}
+
+int UtcDaliFrameBufferAttachColorTexture01(void)
+{
+  TestApplication application;
+
+  unsigned int width(64);
+  unsigned int height(64);
+  FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR_DEPTH_STENCIL );
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
+  frameBuffer.AttachColorTexture( texture );
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliFrameBufferAttachColorTexture02(void)
+{
+  TestApplication application;
+
+  unsigned int width(64);
+  unsigned int height(64);
+  FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR );
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
+  texture.GenerateMipmaps();
+
+  //Attach mipmap 1
+  frameBuffer.AttachColorTexture( texture, 0u, 1u );
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliFrameBufferAttachColorTexture03(void)
+{
+  TestApplication application;
+
+  unsigned int width(64);
+  unsigned int height(64);
+  FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR );
+  Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
+  texture.GenerateMipmaps();
+
+  //Attach NEGATIVE_Y face of the cubemap
+  frameBuffer.AttachColorTexture( texture, 0u, CubeMap::NEGATIVE_Y );
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliFrameBufferGetColorTexture01(void)
+{
+  TestApplication application;
+
+  unsigned int width(64);
+  unsigned int height(64);
+  FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR );
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
+  frameBuffer.AttachColorTexture( texture );
+
+  DALI_TEST_EQUALS(frameBuffer.GetColorTexture(), texture, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliFrameBufferGetColorTexture02(void)
+{
+  TestApplication application;
+
+  unsigned int width(64);
+  unsigned int height(64);
+  FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR );
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
+  frameBuffer.AttachColorTexture( texture, 0u, 1u );
+
+  DALI_TEST_EQUALS(frameBuffer.GetColorTexture(), texture, TEST_LOCATION);
+
+  END_TEST;
+}
+
diff --git a/automated-tests/src/dali-devel/utc-Dali-Texture.cpp b/automated-tests/src/dali-devel/utc-Dali-Texture.cpp
new file mode 100644 (file)
index 0000000..7dcea18
--- /dev/null
@@ -0,0 +1,443 @@
+/*
+ * Copyright (c) 2015 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/public-api/dali-core.h>
+#include <dali-test-suite-utils.h>
+
+using namespace Dali;
+
+#include <mesh-builder.h>
+
+void texture_set_startup(void)
+{
+  test_return_value = TET_UNDEF;
+}
+
+void texture_set_cleanup(void)
+{
+  test_return_value = TET_PASS;
+}
+
+int UtcDaliTextureNew01(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 );
+  END_TEST;
+}
+
+int UtcDaliTextureNew02(void)
+{
+  TestApplication application;
+  Texture texture;
+  DALI_TEST_CHECK( !texture );
+  END_TEST;
+}
+
+int UtcDaliTextureCopyConstructor(void)
+{
+  TestApplication application;
+
+  unsigned int width(64);
+  unsigned int height(64);
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
+
+  Texture textureCopy(texture);
+
+  DALI_TEST_CHECK( textureCopy );
+
+  END_TEST;
+}
+
+int UtcDaliTextureAssignmentOperator(void)
+{
+  TestApplication application;
+  unsigned int width(64);
+  unsigned int height(64);
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
+
+  Texture texture2;
+  DALI_TEST_CHECK( !texture2 );
+
+  texture2 = texture;
+  DALI_TEST_CHECK( texture2 );
+
+  END_TEST;
+}
+
+int UtcDaliTextureDownCast01(void)
+{
+  TestApplication application;
+  unsigned int width(64);
+  unsigned int height(64);
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
+
+  BaseHandle handle(texture);
+  Texture texture2 = Texture::DownCast(handle);
+  DALI_TEST_CHECK( texture2 );
+
+  END_TEST;
+}
+
+int UtcDaliTextureDownCast02(void)
+{
+  TestApplication application;
+
+  Handle handle = Handle::New(); // Create a custom object
+  Texture texture = Texture::DownCast(handle);
+  DALI_TEST_CHECK( !texture );
+  END_TEST;
+}
+
+int UtcDaliTextureUpload01(void)
+{
+  TestApplication application;
+
+  //Create the texture
+  unsigned int width(64);
+  unsigned int height(64);
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
+
+  application.GetGlAbstraction().EnableTextureCallTrace(true);
+
+  application.SendNotification();
+  application.Render();
+
+  TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
+
+  //TexImage2D 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("TexImage2D", out.str().c_str() ) );
+  }
+
+  //Upload data to the texture
+  callStack.Reset();
+  Vector<unsigned char> data;
+  data.Resize( width * height * 4 );
+  texture.Upload( data );
+  application.SendNotification();
+  application.Render();
+
+  //TexImage2D should be called to upload the data
+  {
+    std::stringstream out;
+    out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
+    DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
+  }
+
+  //Upload part of the texture
+  callStack.Reset();
+  Vector<unsigned char> subImage;
+  subImage.Resize( width * height * 2 );
+  texture.Upload( subImage, 0u, 0u, width/2, height/2, width/2, height/2 );
+  application.SendNotification();
+  application.Render();
+
+  //TexSubImage2D 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("TexSubImage2D", out.str().c_str() ) );
+  }
+
+
+  END_TEST;
+}
+
+int UtcDaliTextureUpload02(void)
+{
+  TestApplication application;
+
+  //Create the texture
+  unsigned int width(64);
+  unsigned int height(64);
+  Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
+
+  application.GetGlAbstraction().EnableTextureCallTrace(true);
+
+  application.SendNotification();
+  application.Render();
+
+  TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
+
+  //TexImage2D should be called six times with a null pointer to reserve storage for the six textures of the cube map
+  for( unsigned int i(0); i<6; ++i )
+  {
+    std::stringstream out;
+    out << GL_TEXTURE_CUBE_MAP_POSITIVE_X + i <<", "<< 0u << ", " << width <<", "<< height;
+    DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
+  }
+
+  //Upload data to the POSITIVE_X face of the texture
+  {
+    callStack.Reset();
+    Vector<unsigned char> data;
+    data.Resize( width * height * 4 );
+    texture.Upload( data, CubeMap::POSITIVE_X, 0u, 0u, 0u, width, height );
+    application.SendNotification();
+    application.Render();
+
+    //TexImage2D should be called to upload the data to the POSITIVE_X face
+    {
+      std::stringstream out;
+      out << GL_TEXTURE_CUBE_MAP_POSITIVE_X <<", "<< 0u << ", " << width <<", "<< height;
+      DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
+    }
+  }
+
+  //Upload data to the NEGATIVE_X face of the texture
+  {
+    callStack.Reset();
+    Vector<unsigned char> data;
+    data.Resize( width * height * 4 );
+    texture.Upload( data, CubeMap::NEGATIVE_X, 0u, 0u, 0u, width, height );
+    application.SendNotification();
+    application.Render();
+
+    //TexImage2D should be called to upload the data to the NEGATIVE_X face
+    {
+      std::stringstream out;
+      out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X <<", "<< 0u << ", " << width <<", "<< height;
+      DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
+    }
+  }
+
+  //Upload data to the POSITIVE_Y face of the texture
+  {
+    callStack.Reset();
+    Vector<unsigned char> data;
+    data.Resize( width * height * 4 );
+    texture.Upload( data, CubeMap::POSITIVE_Y, 0u, 0u, 0u, width, height );
+    application.SendNotification();
+    application.Render();
+
+    //TexImage2D should be called to upload the data to the POSITIVE_Y face
+    {
+      std::stringstream out;
+      out << GL_TEXTURE_CUBE_MAP_POSITIVE_Y <<", "<< 0u << ", " << width <<", "<< height;
+      DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
+    }
+  }
+
+  //Upload data to the NEGATIVE_Y face of the texture
+  {
+    callStack.Reset();
+    Vector<unsigned char> data;
+    data.Resize( width * height * 4 );
+    texture.Upload( data, CubeMap::NEGATIVE_Y, 0u, 0u, 0u, width, height );
+    application.SendNotification();
+    application.Render();
+
+    //TexImage2D should be called to upload the data to the NEGATIVE_Y face
+    {
+      std::stringstream out;
+      out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Y <<", "<< 0u << ", " << width <<", "<< height;
+      DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
+    }
+  }
+
+  //Upload data to the POSITIVE_Z face of the texture
+  {
+    callStack.Reset();
+    Vector<unsigned char> data;
+    data.Resize( width * height * 4 );
+    texture.Upload( data, CubeMap::POSITIVE_Z, 0u, 0u, 0u, width, height );
+    application.SendNotification();
+    application.Render();
+
+    //TexImage2D should be called to upload the data to the POSITIVE_Z face
+    {
+      std::stringstream out;
+      out << GL_TEXTURE_CUBE_MAP_POSITIVE_Z <<", "<< 0u << ", " << width <<", "<< height;
+      DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
+    }
+  }
+
+  //Upload data to the NEGATIVE_Z face of the texture
+  {
+    callStack.Reset();
+    Vector<unsigned char> data;
+    data.Resize( width * height * 4 );
+    texture.Upload( data, CubeMap::NEGATIVE_Z, 0u, 0u, 0u, width, height );
+    application.SendNotification();
+    application.Render();
+
+    //TexImage2D should be called to upload the data to the NEGATIVE_Z face
+    {
+      std::stringstream out;
+      out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Z <<", "<< 0u << ", " << width <<", "<< height;
+      DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
+    }
+  }
+
+  END_TEST;
+}
+
+int UtcDaliTextureUpload03(void)
+{
+  TestApplication application;
+
+  //Create the texture
+  unsigned int width(64);
+  unsigned int height(64);
+  unsigned int widthMipmap1(32);
+  unsigned int heightMipmap1(32);
+
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
+
+  application.GetGlAbstraction().EnableTextureCallTrace(true);
+
+  application.SendNotification();
+  application.Render();
+
+  TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
+
+  //TexImage2D 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("TexImage2D", out.str().c_str() ) );
+  }
+
+  //Upload data to the texture mipmap 0 and mipmap 1
+  callStack.Reset();
+  Vector<unsigned char> data;
+  data.Resize( width * height * 4 );
+  texture.Upload( data, 0u, 0u, 0u, 0u, width, height );
+
+  Vector<unsigned char> dataMipmap1;
+  dataMipmap1.Resize( widthMipmap1 * heightMipmap1 * 4 );
+  texture.Upload( dataMipmap1, 0u, 1u, 0u, 0u, widthMipmap1, heightMipmap1 );
+  application.SendNotification();
+  application.Render();
+
+  //TexImage2D should be called to upload the data to mipmaps 0 and 1
+  {
+    std::stringstream out;
+    out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
+    DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
+  }
+  {
+    std::stringstream out;
+    out << GL_TEXTURE_2D <<", "<< 1u << ", " << widthMipmap1 <<", "<< heightMipmap1;
+    DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
+  }
+
+  END_TEST;
+}
+
+int UtcDaliTextureUpload04(void)
+{
+  TestApplication application;
+
+  //Create the texture
+  unsigned int width(64);
+  unsigned int height(64);
+  unsigned int widthMipmap1(32);
+  unsigned int heightMipmap1(32);
+
+  Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
+
+  application.GetGlAbstraction().EnableTextureCallTrace(true);
+  TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
+
+  //Upload data to the NEGATIVE_X face mipmap 0 and mipmap 1
+  Vector<unsigned char> data;
+  data.Resize( width * height * 4 );
+  texture.Upload( data, CubeMap::NEGATIVE_X, 0u, 0u, 0u, width, height );
+
+  Vector<unsigned char> dataMipmap1;
+  dataMipmap1.Resize( widthMipmap1 * widthMipmap1 * 4 );
+  texture.Upload( dataMipmap1, CubeMap::NEGATIVE_X, 1u, 0u, 0u, widthMipmap1, heightMipmap1 );
+  application.SendNotification();
+  application.Render();
+
+  //TexImage2D should be called to upload the data to mipmaps 0 and 1
+  {
+    std::stringstream out;
+    out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X <<", "<< 0u << ", " << width <<", "<< height;
+    DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
+  }
+  {
+    std::stringstream out;
+    out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X <<", "<< 1u << ", " << widthMipmap1 <<", "<< heightMipmap1;
+    DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
+  }
+
+  END_TEST;
+}
+
+int UtcDaliTextureGenerateMipmaps(void)
+{
+  TestApplication application;
+  unsigned int width(64);
+  unsigned int height(64);
+
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
+  texture.GenerateMipmaps();
+
+  Texture textureCubemap = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
+  textureCubemap.GenerateMipmaps();
+
+  application.GetGlAbstraction().EnableTextureCallTrace(true);
+  TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
+  application.SendNotification();
+  application.Render();
+
+  {
+    std::stringstream out;
+    out << GL_TEXTURE_2D;
+    DALI_TEST_CHECK( callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str() ) );
+  }
+  {
+    std::stringstream out;
+    out << GL_TEXTURE_CUBE_MAP;
+    DALI_TEST_CHECK( callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str() ) );
+  }
+
+  END_TEST;
+}
+
+int UtcDaliTextureGetWidth(void)
+{
+  TestApplication application;
+  unsigned int width(64);
+  unsigned int height(64);
+
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
+  DALI_TEST_EQUALS( texture.GetWidth(), width, TEST_LOCATION );
+  END_TEST;
+}
+
+int UtcDaliTextureGetHeight(void)
+{
+  TestApplication application;
+  unsigned int width(64);
+  unsigned int height(64);
+
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
+  DALI_TEST_EQUALS( texture.GetHeight(), height, TEST_LOCATION );
+
+  END_TEST;
+}
+
index 1c7be48..2c5d75d 100644 (file)
@@ -22,15 +22,6 @@ using namespace Dali;
 
 #include <mesh-builder.h>
 
-namespace
-{
-void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
-{
-  current.b = 0.0f;
-}
-}
-
-
 void texture_set_test_startup(void)
 {
   test_return_value = TET_UNDEF;
@@ -201,6 +192,96 @@ int UtcDaliTextureSetSetImage02(void)
   END_TEST;
 }
 
+int UtcDaliTextureSetTexture01(void)
+{
+  TestApplication application;
+
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
+
+  Shader shader = CreateShader();
+  TextureSet textureSet = CreateTextureSet();
+  textureSet.SetTexture( 0u, texture );
+
+  Geometry geometry = Geometry::QUAD();
+  Renderer renderer = Renderer::New( geometry, shader );
+  renderer.SetTextures( textureSet );
+
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetParentOrigin( ParentOrigin::CENTER );
+  actor.SetSize(400, 400);
+
+  Stage::GetCurrent().Add( actor );
+
+  TestGlAbstraction& gl = application.GetGlAbstraction();
+
+  TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
+  texParameterTrace.Reset();
+  texParameterTrace.Enable( true );
+  application.SendNotification();
+  application.Render();
+
+  int textureUnit=-1;
+  DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
+  DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
+
+  texParameterTrace.Enable( false );
+
+  // Verify gl state
+  // There are four calls to TexParameteri when the texture is first created
+  // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri
+  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 4, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliTextureSetTexture02(void)
+{
+  TestApplication application;
+
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
+
+  Shader shader = CreateShader();
+  TextureSet textureSet = CreateTextureSet();
+
+  Sampler sampler = Sampler::New();
+  sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
+  textureSet.SetTexture( 0u, texture );
+  textureSet.SetSampler( 0u, sampler );
+
+  Geometry geometry = Geometry::QUAD();
+  Renderer renderer = Renderer::New( geometry, shader );
+  renderer.SetTextures( textureSet );
+
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetParentOrigin( ParentOrigin::CENTER );
+  actor.SetSize(400, 400);
+
+  Stage::GetCurrent().Add( actor );
+
+  TestGlAbstraction& gl = application.GetGlAbstraction();
+
+  TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
+  texParameterTrace.Reset();
+  texParameterTrace.Enable( true );
+  application.SendNotification();
+  application.Render();
+
+  int textureUnit=-1;
+  DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
+  DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
+
+  texParameterTrace.Enable( false );
+
+  // Verify gl state
+  // There are four calls to TexParameteri when the texture is first created
+  // Texture minification and magnification filters are now different than default so
+  //there should have been two extra TexParameteri calls to set the new filter mode
+  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 6, TEST_LOCATION);
+
+  END_TEST;
+}
 int UtcDaliTextureSetSetSampler(void)
 {
   TestApplication application;
@@ -236,7 +317,7 @@ int UtcDaliTextureSetSetSampler(void)
   texParameterTrace.Enable( false );
 
   // Verify gl state
-  // There are three calls to TexParameteri when the texture is first created
+  // There are 4 calls to TexParameteri when the texture is first created
   // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri
   DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION);
 
@@ -290,6 +371,35 @@ int UtcDaliTextureSetGetImage(void)
   END_TEST;
 }
 
+int UtcDaliTextureSetGetTexture(void)
+{
+  TestApplication application;
+
+  TextureSet textureSet = CreateTextureSet();
+  DALI_TEST_EQUALS( textureSet.GetTexture(0), Texture(), TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetTexture(1), Texture(), TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetTexture(2), Texture(), TEST_LOCATION );
+
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
+  textureSet.SetTexture( 0u, texture );
+
+  DALI_TEST_EQUALS( textureSet.GetTexture(0), texture, TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetTexture(1), Texture(), TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetTexture(2), Texture(), TEST_LOCATION );
+
+  textureSet.SetTexture( 2u, texture );
+  DALI_TEST_EQUALS( textureSet.GetTexture(0), texture, TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetTexture(1), Texture(), TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetTexture(2), texture, TEST_LOCATION );
+
+  textureSet.SetTexture( 2u, Texture() );
+  DALI_TEST_EQUALS( textureSet.GetTexture(0), texture, TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetTexture(1), Texture(), TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetTexture(2), Texture(), TEST_LOCATION );
+
+  END_TEST;
+}
+
 int UtcDaliTextureSetGetSampler(void)
 {
   TestApplication application;
index a40d776..f910d51 100644 (file)
@@ -491,6 +491,9 @@ public:
 
   inline void GenerateMipmap(GLenum target)
   {
+    std::stringstream out;
+    out<<target;
+    mTextureTrace.PushCall("GenerateMipmap", out.str());
   }
 
   inline void GenFramebuffers(GLsizei n, GLuint* framebuffers)
@@ -884,7 +887,7 @@ public:
   inline void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* pixels)
   {
     std::stringstream out;
-    out << width << ", " << height;
+    out << target<<", "<<level<<", "<<width << ", " << height;
     mTextureTrace.PushCall("TexImage2D", out.str());
   }
 
@@ -919,7 +922,7 @@ public:
   inline void TexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* pixels)
   {
     std::stringstream out;
-    out << xoffset << ", " << yoffset << ", " << width << ", " << height;
+    out << target << ", "<<level <<", " << xoffset << ", " << yoffset << ", " << width << ", " << height;
     mTextureTrace.PushCall("TexSubImage2D", out.str());
   }
 
index fcac6d8..a00c619 100644 (file)
@@ -384,7 +384,10 @@ int UtcDaliBufferImageUpdate01(void)
   application.SendNotification();
 
   const TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
-  DALI_TEST_EQUALS( callStack.TestMethodAndParams(0, "TexSubImage2D", "0, 0, 16, 16"), true, TEST_LOCATION);
+
+  std::stringstream out;
+  out << GL_TEXTURE_2D <<", "<< 0u << ", " << 0u << ", " << 0u << ", " << 16u <<", "<< 16u;
+  DALI_TEST_EQUALS( callStack.TestMethodAndParams(0, "TexSubImage2D", out.str().c_str() ), true, TEST_LOCATION);
 
   DALI_TEST_CHECK( SignalReceived == true );
   SignalReceived = false;
@@ -429,9 +432,24 @@ int UtcDaliBufferImageUpdate02(void)
   application.SendNotification();
 
   const TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
-  DALI_TEST_EQUALS( callStack.TestMethodAndParams(0, "TexSubImage2D", "9, 9, 5, 5"), true, TEST_LOCATION);
-  DALI_TEST_EQUALS( callStack.TestMethodAndParams(1, "TexSubImage2D", "2, 2, 4, 4"), true, TEST_LOCATION);
-  DALI_TEST_EQUALS( callStack.TestMethodAndParams(2, "TexSubImage2D", "3, 3, 1, 6"), true, TEST_LOCATION);
+
+  {
+    std::stringstream out;
+    out << GL_TEXTURE_2D <<", "<< 0u << ", " << 9u << ", " << 9u << ", " << 5u <<", "<< 5u;
+    DALI_TEST_EQUALS( callStack.TestMethodAndParams(0, "TexSubImage2D", out.str().c_str()), true, TEST_LOCATION);
+  }
+
+  {
+    std::stringstream out;
+    out << GL_TEXTURE_2D <<", "<< 0u << ", " << 2u << ", " << 2u << ", " << 4u <<", "<< 4u;
+    DALI_TEST_EQUALS( callStack.TestMethodAndParams(1, "TexSubImage2D", out.str().c_str()), true, TEST_LOCATION);
+  }
+
+  {
+    std::stringstream out;
+    out << GL_TEXTURE_2D <<", "<< 0u << ", " << 3u << ", " << 3u << ", " << 1u <<", "<< 6u;
+    DALI_TEST_EQUALS( callStack.TestMethodAndParams(2, "TexSubImage2D", out.str().c_str()), true, TEST_LOCATION);
+  }
 
   DALI_TEST_CHECK( SignalReceived == true );
   SignalReceived = false;
index 43c8aac..63c29bc 100644 (file)
@@ -60,6 +60,11 @@ FrameBuffer::FrameBuffer( Internal::FrameBuffer* pointer )
 {
 }
 
+void FrameBuffer::AttachColorTexture( Texture& texture )
+{
+  AttachColorTexture( texture, 0u, 0u );
+}
+
 void FrameBuffer::AttachColorTexture( Texture& texture, unsigned int mipmapLevel, unsigned int layer )
 {
   if( texture )
index a0fe3e2..11bc3ed 100644 (file)
@@ -90,14 +90,22 @@ public:
   FrameBuffer& operator=( const FrameBuffer& handle );
 
   /**
-   * @brief Attach a texture for color rendering
+   * @brief Attach the base LOD of a 2D texture to the framebuffer for color rendering
+   * @param[in] texture The texture that will be used as output when rendering
+   * @note The texture has to have the same size than the FrameBuffer
+   * otherwise it won't be attached
+   */
+  void AttachColorTexture( Texture& texture );
+
+  /**
+   * @brief Attach a texture to the framebuffer for color rendering
    * @param[in] texture The texture that will be used as output when rendering
    * @param[in] mipmapLevel The mipmap of the texture to be attached
    * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
    * @note The specified texture mipmap has to have the same size than the FrameBuffer
    * otherwise it won't be attached
    */
-  void AttachColorTexture( Texture& texture, unsigned int mipmapLevel = 0u, unsigned int layer = 0u );
+  void AttachColorTexture( Texture& texture, unsigned int mipmapLevel, unsigned int layer );
 
   /**
    * @brief Get the color texture used as output in the FrameBuffer
index 51179d0..af8094c 100644 (file)
@@ -73,8 +73,8 @@ public:
   enum ShaderHints
   {
     HINT_NONE                     = 0x00, ///< no hints
-    HINT_OUTPUT_IS_TRANSPARENT    = 0x02, ///< Might generate transparent alpha from opaque inputs
-    HINT_MODIFIES_GEOMETRY        = 0x08, ///< Might change position of vertices,
+    HINT_OUTPUT_IS_TRANSPARENT    = 0x01, ///< Might generate transparent alpha from opaque inputs
+    HINT_MODIFIES_GEOMETRY        = 0x02, ///< Might change position of vertices,
                                           ///< this option disables any culling optimizations
   };
 
index 6253d2e..dd33866 100644 (file)
@@ -55,12 +55,20 @@ Texture& Texture::operator=( const Texture& handle )
   return *this;
 }
 
-void Texture::Upload( Vector<unsigned char>& buffer, const TextureUploadParams& params )
+void Texture::Upload( Vector<unsigned char>& buffer )
 {
-  return GetImplementation(*this).Upload( buffer, params );
+  return GetImplementation(*this).Upload( buffer );
 }
 
-void Texture::Upload( PixelData pixelData, const TextureUploadParams& params )
+void Texture::Upload( Vector<unsigned char>& buffer,
+               unsigned int layer, unsigned int mipmap,
+               unsigned int xOffset, unsigned int yOffset,
+               unsigned int width, unsigned int height )
+{
+  return GetImplementation(*this).Upload( buffer, layer, mipmap, xOffset, yOffset, width, height );
+}
+
+void Texture::Upload( PixelData pixelData )
 {
   //TODO: Implement this method once PixelData uses handle/body pattern
   DALI_ASSERT_ALWAYS( false && "Not implemented yet");
index 8ea159d..876dbce 100644 (file)
@@ -56,18 +56,6 @@ namespace CubeMap
   const unsigned int NEGATIVE_Z  = 5u;
 }
 
-/**
- * @brief Structure used to pass parameters to the Upload method
- */
-struct TextureUploadParams
-{
-  unsigned int layer;    ///< Specifies the layer of a cube map or array texture
-  unsigned int mipmap;   ///< Specifies the level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image.
-  unsigned int x0;       ///< Specifies a texel offset in the x direction within the texture array.
-  unsigned int y0;       ///< Specifies a texel offset in the y direction within the texture array.
-  unsigned int width;    ///< Specifies the width of the texture subimage
-  unsigned int height;   ///< Specifies the height of the texture subimage.
-};
 
 /**
  * @brief Texture represents a texture object used as input or output by shaders
@@ -124,19 +112,35 @@ public:
   /**
    * @brief Upload data to the texture
    * @param[in] buffer A vector with the data to be uploaded
-   * @param[in] params A struct with the parameters for the upload. See TextureUploadParams
    * @note buffer data will be moved after this call. If the application needs to keep the data,
-   * it will have to pass a copy of the original buffer into this function, otherwise, the data
+   * it will have to pass a copy of the original buffer into this function, otherwise the data
+   * will be lost
+   */
+  void Upload( Vector<unsigned char>& buffer );
+
+  /**
+   * @brief Upload data to the texture
+   * @param[in] buffer A vector with the data to be uploaded
+   * @param[in] layer Specifies the layer of a cube map or array texture. (Unused for 2D textures)
+   * @param[in] mipmap Specifies the level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image
+   * @param[in] xOffset Specifies a texel offset in the x direction within the texture array
+   * @param[in] yOffset Specifies a texel offset in the y direction within the texture array
+   * @param[in] width Specifies the width of the texture subimage
+   * @param[in] height Specifies the height of the texture subimage
+   * @note buffer data will be moved after this call. If the application needs to keep the data,
+   * it will have to pass a copy of the original buffer into this function, otherwise the data
    * will be lost
    */
-  void Upload( Vector<unsigned char>& buffer, const TextureUploadParams& params );
+  void Upload( Vector<unsigned char>& buffer,
+               unsigned int layer, unsigned int mipmap,
+               unsigned int xOffset, unsigned int yOffset,
+               unsigned int width, unsigned int height );
 
   /**
    * @brief Upload data to the texture from a PixelData object
    * @param[in] pixelData The pixelData object
-   * @param[in] params A struct with the parameters for the upload. See TextureUploadParams
    */
-  void Upload( PixelData pixelData, const TextureUploadParams& params );
+  void Upload( PixelData pixelData );
 
   /**
    * @brief Generate mipmaps for the texture
index 445a2bc..5d3f4c5 100644 (file)
@@ -64,9 +64,44 @@ NewTexture::~NewTexture()
   }
 }
 
-void NewTexture::Upload( Vector<unsigned char>& buffer, const TextureUploadParams& params )
+bool NewTexture::CheckUploadParametres( const Vector<unsigned char>& buffer, const UploadParams& parameters ) const
 {
-  UploadTextureMessage(mEventThreadServices.GetUpdateManager(), *mRenderObject, buffer, params );
+  if(  buffer.Size() < GetBytesPerPixel( mFormat ) * parameters.width * parameters.height )
+  {
+    DALI_LOG_ERROR( "Error: Buffer of an incorrect size when trying to update texture");
+    return false;
+  }
+  else if( ( parameters.xOffset + parameters.width  > static_cast<unsigned int>( mWidth/(1<<parameters.mipmap ))) ||
+           ( parameters.yOffset + parameters.height > static_cast<unsigned int>( mHeight/(1<<parameters.mipmap ))))
+  {
+    DALI_LOG_ERROR( "Error: Out of bounds texture update");
+    return false;
+  }
+  else
+  {
+    return true;
+  }
+}
+
+void NewTexture::Upload( Vector<unsigned char>& buffer,
+                         unsigned int layer, unsigned int mipmap,
+                         unsigned int xOffset, unsigned int yOffset,
+                         unsigned int width, unsigned int height )
+{
+  UploadParams params = { layer, mipmap, xOffset, yOffset, width, height };
+  if( CheckUploadParametres( buffer, params ) )
+  {
+    UploadTextureMessage(mEventThreadServices.GetUpdateManager(), *mRenderObject, buffer, params );
+  }
+}
+
+void NewTexture::Upload( Vector<unsigned char>& buffer )
+{
+  UploadParams params = {0u,0u,0u,0u,mWidth,mHeight};
+  if( CheckUploadParametres( buffer, params ) )
+  {
+    UploadTextureMessage(mEventThreadServices.GetUpdateManager(), *mRenderObject, buffer, params );
+  }
 }
 
 void NewTexture::GenerateMipmaps()
index 76a3301..5e56c53 100644 (file)
@@ -43,6 +43,19 @@ class NewTexture : public BaseObject
 public:
 
   /**
+   * @brief Structure used to pass parameters to the Upload method
+   */
+  struct UploadParams
+  {
+    unsigned int layer;    ///< Specifies the layer of a cube map or array texture
+    unsigned int mipmap;   ///< Specifies the level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image.
+    unsigned int xOffset;  ///< Specifies a texel offset in the x direction within the texture array.
+    unsigned int yOffset;  ///< Specifies a texel offset in the y direction within the texture array.
+    unsigned int width;    ///< Specifies the width of the texture subimage
+    unsigned int height;   ///< Specifies the height of the texture subimage.
+  };
+
+  /**
    * @brief Create a new Texture.
    *
    * @param[in] type The type of the texture
@@ -63,7 +76,15 @@ public:
   /**
    * @copydoc Dali::Texture::Upload()
    */
-  void Upload( Vector<unsigned char>& buffer, const TextureUploadParams& params );
+  void Upload( Vector<unsigned char>& buffer );
+
+  /**
+   * @copydoc Dali::Texture::Upload()
+   */
+  void Upload( Vector<unsigned char>& buffer,
+               unsigned int layer, unsigned int mipmap,
+               unsigned int xOffset, unsigned int yOffset,
+               unsigned int width, unsigned int height );
 
   /**
    * @copydoc Dali::Texture::GenerateMipmaps()
@@ -106,6 +127,13 @@ private: // unimplemented methods
 
 private: // data
 
+  /**
+   * @brief Helper method to check that upload parameters are correct
+   * @param[in] buffer A vector with the data to be uploaded
+   * @param[in] parameters The uploading parameters
+   */
+  bool CheckUploadParametres( const Vector<unsigned char>& buffer, const UploadParams& parameters) const;
+
   Internal::EventThreadServices& mEventThreadServices;    ///<Used to send messages to the render thread via update thread
   Internal::Render::NewTexture* mRenderObject;            ///<The Render::Texture associated to this texture
 
index 1f60235..d5342e3 100644 (file)
@@ -102,9 +102,13 @@ void TextureSet::SetTexture( size_t index, NewTexturePtr texture )
 
   mNewTextures[index]= texture;
 
+  Render::NewTexture* renderTexture(0);
+  if( texture )
+  {
+    renderTexture = texture->GetRenderObject();
+  }
 
-  SceneGraph::SetTextureMessage( mEventThreadServices, *mSceneObject, index, texture->GetRenderObject() );
-
+  SceneGraph::SetTextureMessage( mEventThreadServices, *mSceneObject, index, renderTexture );
 }
 
 Image* TextureSet::GetImage( size_t index ) const
index d613ad7..d3190bf 100644 (file)
@@ -325,7 +325,7 @@ void RenderManager::RemoveTexture( Render::NewTexture* texture )
 
   TextureOwnerContainer& textures = mImpl->textureContainer;
 
-  // Find the sampler
+  // Find the texture
   for ( TextureOwnerIter iter = textures.Begin(); iter != textures.End(); ++iter )
   {
     if ( *iter == texture )
@@ -337,7 +337,7 @@ void RenderManager::RemoveTexture( Render::NewTexture* texture )
   }
 }
 
-void RenderManager::UploadTexture( Render::NewTexture* texture, Vector<unsigned char>& buffer, const TextureUploadParams& params )
+void RenderManager::UploadTexture( Render::NewTexture* texture, Vector<unsigned char>& buffer, const NewTexture::UploadParams& params )
 {
   texture->Upload( mImpl->context, buffer, params );
 }
index 50b8916..70c8116 100644 (file)
@@ -25,6 +25,7 @@
 #include <dali/internal/render/common/texture-uploaded-dispatcher.h>
 #include <dali/internal/render/gl-resources/gpu-buffer.h>
 #include <dali/internal/render/renderers/render-property-buffer.h>
+#include <dali/internal/event/rendering/texture-impl.h>
 
 namespace Dali
 {
@@ -282,7 +283,7 @@ public:
    * @param[in] buffer Vector with the data to be uploaded
    * @param[in] params The parameters for the upload
    */
-  void UploadTexture( Render::NewTexture* texture, Vector<unsigned char>& buffer, const TextureUploadParams& params );
+  void UploadTexture( Render::NewTexture* texture, Vector<unsigned char>& buffer, const NewTexture::UploadParams& params );
 
   /**
    * Generates mipmaps for a given texture
@@ -312,13 +313,6 @@ public:
   void AttachColorTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::NewTexture* texture, unsigned int mipmapLevel, unsigned int layer );
 
   /**
-   * Attach a texture as depth-stencil to an existing FrameBuffer
-   * @param[in] frameBuffer The FrameBuffer
-   * @param[in] texture The texture that will be used as depth-stencil buffer when rendering
-   */
-  void AttachDepthStencilTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::NewTexture* texture );
-
-  /**
    * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
    * tracker. The lifetime of the tracker is related to the lifetime of the tracked
    * object, usually an offscreen render task.
index fc2234a..1fd3d78 100644 (file)
@@ -574,14 +574,14 @@ void NewTexture::Initialize(Context& context)
   }
 }
 
-void NewTexture::Upload( Context& context, Vector<unsigned char>& buffer, const Dali::TextureUploadParams& params  )
+void NewTexture::Upload( Context& context, Vector<unsigned char>& buffer, const Internal::NewTexture::UploadParams& params  )
 {
   if( mType == TextureType::TEXTURE_2D )
   {
     context.Bind2dTexture( mId );
     context.PixelStorei( GL_UNPACK_ALIGNMENT, 1 );
 
-    if( params.x0 == 0 && params.y0 == 0 &&
+    if( params.xOffset == 0 && params.yOffset == 0 &&
         params.width == (unsigned int)(mWidth / (1<<params.mipmap)) &&
         params.height == (unsigned int)(mHeight / (1<<params.mipmap)) )
     {
@@ -591,7 +591,7 @@ void NewTexture::Upload( Context& context, Vector<unsigned char>& buffer, const
     else
     {
       //Specifying part of the image for the mipmap
-      context.TexSubImage2D( GL_TEXTURE_2D, params.mipmap, params.x0, params.y0, params.width, params.height, mInternalFormat, mPixelDataType, &buffer[0] );
+      context.TexSubImage2D( GL_TEXTURE_2D, params.mipmap, params.xOffset, params.yOffset, params.width, params.height, mInternalFormat, mPixelDataType, &buffer[0] );
     }
   }
   else if( mType == TextureType::TEXTURE_CUBE )
@@ -599,17 +599,21 @@ void NewTexture::Upload( Context& context, Vector<unsigned char>& buffer, const
     context.BindCubeMapTexture( mId );
     context.PixelStorei( GL_UNPACK_ALIGNMENT, 1 );
 
-    if( params.x0 == 0 && params.y0 == 0 &&
-        params.width == (unsigned int)(mWidth / (1<<params.mipmap)) &&
-        params.height == (unsigned int)(mHeight / (1<<params.mipmap)) )
+    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 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, mInternalFormat, mPixelDataType, &buffer[0] );
+      context.TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + params.layer, params.mipmap, mInternalFormat,
+                         params.width, params.height, 0,
+                         mInternalFormat, mPixelDataType, &buffer[0] );
     }
     else
     {
       //Specifying part of the image for the mipmap
-      context.TexSubImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X + params.layer, params.mipmap, params.x0, params.y0, params.width, params.height, mInternalFormat, mPixelDataType, &buffer[0] );
+      context.TexSubImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X + params.layer, params.mipmap,
+                             params.xOffset, params.yOffset, params.width, params.height,
+                             mInternalFormat, mPixelDataType, &buffer[0] );
     }
   }
 }
index cc58c2f..8b02123 100644 (file)
@@ -23,6 +23,7 @@
 // INTERNAL INCLUDES
 #include <dali/devel-api/rendering/sampler.h>
 #include <dali/devel-api/rendering/texture.h>
+#include <dali/internal/event/rendering/texture-impl.h>
 #include <dali/integration-api/resource-declarations.h>
 
 #include <dali/internal/render/gl-resources/context.h>
@@ -135,9 +136,9 @@ public:
    * Uploads data to the texture.
    * @param[in] context The GL context
    * @param[in] buffer A vector with the data to be uploaded
-   * @param[in] params Upload parameters. See TextureUploadParams
+   * @param[in] params Upload parameters. See UploadParams
    */
-  void Upload( Context& context, Vector<unsigned char>& buffer, const Dali::TextureUploadParams& params );
+  void Upload( Context& context, Vector<unsigned char>& buffer, const Internal::NewTexture::UploadParams& params );
 
   /**
    * Bind the texture to the given texture unit and applies the given sampler
@@ -149,6 +150,7 @@ public:
 
   /**
    * Auto generates mipmaps for the texture
+   * @param[in] context The GL context
    */
   void GenerateMipmaps( Context& context );
 
@@ -158,21 +160,37 @@ public:
    */
   bool HasAlphaChannel();
 
+  /**
+   * Get the id of the texture
+   * @return Id of the texture
+   */
   GLuint GetId()
   {
     return mId;
   }
 
+  /**
+   * Get the width of the texture
+   * @return Width of the texture
+   */
   unsigned int GetWidth() const
   {
     return mWidth;
   }
 
+  /**
+   * Get the height of the texture
+   * @return Height of the texture
+   */
   unsigned int GetHeight() const
   {
     return mHeight;
   }
 
+  /**
+   * Get the type of the texture
+   * @return Type of the texture
+   */
   Type GetType() const
   {
     return mType;
index d682022..df573cf 100644 (file)
@@ -1312,7 +1312,7 @@ void UpdateManager::RemoveTexture( Render::NewTexture* texture)
   new (slot) DerivedType( &mImpl->renderManager,  &RenderManager::RemoveTexture, texture );
 }
 
-void UpdateManager::UploadTexture( Render::NewTexture* texture, Vector<unsigned char>& buffer, const TextureUploadParams& params )
+void UpdateManager::UploadTexture( Render::NewTexture* texture, Vector<unsigned char>& buffer, const NewTexture::UploadParams& params )
 {
   typedef UploadTextureDataMessage< RenderManager > DerivedType;
 
index a0ce591..1c8f2a9 100644 (file)
@@ -37,6 +37,7 @@
 #include <dali/internal/update/rendering/scene-graph-renderer.h>
 #include <dali/internal/render/shaders/scene-graph-shader.h>
 #include <dali/internal/render/renderers/render-property-buffer.h>
+#include <dali/internal/event/rendering/texture-impl.h>
 
 namespace Dali
 {
@@ -493,7 +494,7 @@ public:
    * @param[in] buffer Vector with the data to be uploaded
    * @param[in] params The parameters for the upload
    */
-  void UploadTexture( Render::NewTexture* texture, Vector<unsigned char>& buffer, const TextureUploadParams& params );
+  void UploadTexture( Render::NewTexture* texture, Vector<unsigned char>& buffer, const NewTexture::UploadParams& params );
 
   /**
    * Generates mipmaps for a texture owned by the RenderManager
@@ -524,13 +525,6 @@ public:
    */
   void AttachColorTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::NewTexture* texture, unsigned int mipmapLevel, unsigned int face );
 
-  /**
-   * Attach a texture as depth-stencil to an existing FrameBuffer
-   * @param[in] frameBuffer The FrameBuffer
-   * @param[in] texture The texture that will be used as depth-stencil buffer when rendering
-   */
-  void AttachDepthStencilTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::NewTexture* texture );
-
 public:
 
   /**
@@ -1236,7 +1230,7 @@ public:
   /**
    * Constructor which does a Vector::Swap()
    */
-  UploadTextureDataMessage( T* manager, Render::NewTexture* texture, Dali::Vector<unsigned char>& data, const Dali::TextureUploadParams& params )
+  UploadTextureDataMessage( T* manager, Render::NewTexture* texture, Dali::Vector<unsigned char>& data, const NewTexture::UploadParams& params )
   : MessageBase(),
     mManager( manager ),
     mRenderTexture( texture ),
@@ -1266,10 +1260,10 @@ private:
   T* mManager;
   Render::NewTexture* mRenderTexture;
   Dali::Vector<unsigned char> mData;
-  Dali::TextureUploadParams mParams;
+  NewTexture::UploadParams mParams;
 };
 
-inline void UploadTextureMessage( UpdateManager& manager, Render::NewTexture& texture, Dali::Vector<unsigned char>& data, const Dali::TextureUploadParams& params )
+inline void UploadTextureMessage( UpdateManager& manager, Render::NewTexture& texture, Dali::Vector<unsigned char>& data, const NewTexture::UploadParams& params )
 {
   typedef UploadTextureDataMessage< UpdateManager > LocalType;