Added GetImage() and GetSampler() and GetTextureCount() to TextureSet 95/66395/3
authorFerran Sole <ferran.sole@samsung.com>
Mon, 18 Apr 2016 14:17:56 +0000 (15:17 +0100)
committerFerran Sole <ferran.sole@samsung.com>
Mon, 18 Apr 2016 15:11:06 +0000 (16:11 +0100)
-Added getters for image and samplers in TextureSet and a method
to check the number of textures present in the TextureSet

Change-Id: I7d17988a00102f420550b6e5b438a24861cc2a14

automated-tests/src/dali-devel/utc-Dali-TextureSet.cpp
dali/devel-api/rendering/renderer.h
dali/devel-api/rendering/texture-set.cpp
dali/devel-api/rendering/texture-set.h
dali/internal/event/rendering/texture-set-impl.cpp
dali/internal/event/rendering/texture-set-impl.h

index c34becf..868c448 100644 (file)
@@ -459,3 +459,81 @@ int UtcDaliTextureSetSetSampler(void)
   END_TEST;
 }
 
+int UtcDaliTextureSetGetImage(void)
+{
+  TestApplication application;
+
+  TextureSet textureSet = CreateTextureSet();
+  DALI_TEST_EQUALS( textureSet.GetImage(0), Image(), TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetImage(1), Image(), TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetImage(2), Image(), TEST_LOCATION );
+
+  Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
+  textureSet.SetImage( 0u, image );
+
+  DALI_TEST_EQUALS( textureSet.GetImage(0), image, TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetImage(1), Image(), TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetImage(2), Image(), TEST_LOCATION );
+
+  textureSet.SetImage( 2u, image );
+  DALI_TEST_EQUALS( textureSet.GetImage(0), image, TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetImage(1), Image(), TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetImage(2), image, TEST_LOCATION );
+
+  textureSet.SetImage( 2u, Image() );
+  DALI_TEST_EQUALS( textureSet.GetImage(0), image, TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetImage(1), Image(), TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetImage(2), Image(), TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliTextureSetGetSampler(void)
+{
+  TestApplication application;
+
+  TextureSet textureSet = CreateTextureSet();
+  DALI_TEST_EQUALS( textureSet.GetSampler(0), Sampler(), TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetSampler(2), Sampler(), TEST_LOCATION );
+
+  Sampler sampler = Sampler::New();
+  sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
+  textureSet.SetSampler( 0u, sampler );
+
+  DALI_TEST_EQUALS( textureSet.GetSampler(0), sampler, TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetSampler(2), Sampler(), TEST_LOCATION );
+
+  textureSet.SetSampler( 2u, sampler );
+  DALI_TEST_EQUALS( textureSet.GetSampler(0), sampler, TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetSampler(2), sampler, TEST_LOCATION );
+
+  textureSet.SetSampler( 2u, Sampler() );
+  DALI_TEST_EQUALS( textureSet.GetSampler(0), sampler, TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetSampler(1), Sampler(), TEST_LOCATION );
+  DALI_TEST_EQUALS( textureSet.GetSampler(2), Sampler(), TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliTextureSetGetTextureCount(void)
+{
+  TestApplication application;
+
+  TextureSet textureSet = CreateTextureSet();
+  DALI_TEST_EQUALS( textureSet.GetTextureCount(), 0u, TEST_LOCATION );
+
+  Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
+  textureSet.SetImage( 0u, image );
+  DALI_TEST_EQUALS( textureSet.GetTextureCount(), 1u, TEST_LOCATION );
+
+  textureSet.SetImage( 1u, image );
+  DALI_TEST_EQUALS( textureSet.GetTextureCount(), 2u, TEST_LOCATION );
+
+  textureSet.SetSampler( 2u, Sampler::New() );
+  DALI_TEST_EQUALS( textureSet.GetTextureCount(), 3u, TEST_LOCATION );
+
+  END_TEST;
+}
index b2860fc..e77a6c2 100644 (file)
@@ -18,9 +18,6 @@
  *
  */
 
-// EXTERNAL INCLUDES
-#include <string> // std::string
-
 // INTERNAL INCLUDES
 #include <dali/public-api/actors/blending.h> // Dali::BlendingMode, Dali::BlendingEquation, Dali::BlendingFactor
 #include <dali/public-api/object/handle.h> // Dali::Handle
index 2d8daba..0211527 100644 (file)
@@ -69,6 +69,12 @@ void TextureSet::SetImage( size_t index, Image image )
   }
 }
 
+Image TextureSet::GetImage( size_t index ) const
+{
+  Internal::Image* imagePtr = GetImplementation(*this).GetImage( index );
+  return Dali::Image( imagePtr );
+}
+
 void TextureSet::SetSampler( size_t index, Sampler sampler )
 {
   if( sampler )
@@ -78,10 +84,21 @@ void TextureSet::SetSampler( size_t index, Sampler sampler )
   }
   else
   {
-    DALI_LOG_ERROR( "Error adding invalid image %s to TextureSet" );
+    GetImplementation(*this).SetSampler( index, NULL );
   }
 }
 
+Sampler TextureSet::GetSampler( size_t index ) const
+{
+  Internal::Sampler* samplerPtr = GetImplementation(*this).GetSampler( index );
+  return Dali::Sampler( samplerPtr );
+}
+
+size_t TextureSet::GetTextureCount() const
+{
+  return GetImplementation(*this).GetTextureCount();
+}
+
 TextureSet::TextureSet( Internal::TextureSet* pointer )
 : Handle( pointer )
 {
index 21062a9..68d4b1e 100644 (file)
@@ -20,7 +20,6 @@
 
 // EXTERNAL INCLUDES
 #include <cstddef> // std::size_t
-#include <string> // std::string
 
 // INTERNAL INCLUDES
 #include <dali/public-api/images/image.h> // Dali::Image
@@ -92,12 +91,33 @@ public:
   void SetImage( size_t index, Image image );
 
   /**
-   * @brief Set the sampler to be used by the image at position "index"
+   * @brief Get the image at position "index"
    * @param[in] index The position in the texture set of the image
-   * @param[in] image The sampler to use
+   * @return A handle to the image at the the specified position
+   */
+  Image GetImage( size_t index ) const;
+
+  /**
+   * @brief Set the sampler to be used by the image at position "index"
+   * @param[in] index The position in the texture set of the sampler
+   * @param[in] sampler The sampler to use
    */
   void SetSampler( size_t index, Sampler sampler );
 
+  /**
+   * @brief Set the sampler to be used by the image at position "index"
+   * @param[in] index The position in the texture set of the image
+   * @return A handle to the sampler at the specified position
+   */
+  Sampler GetSampler( size_t index ) const;
+
+  /**
+   * @brief Get the number of textures present in the TextureSet
+   *
+   * @return The number of textures in the TextureSet
+   */
+  size_t GetTextureCount() const;
+
 public:
   /**
    * @brief The constructor
index 189edf2..01104d3 100644 (file)
@@ -91,6 +91,21 @@ void TextureSet::SetImage( size_t index, ImagePtr image )
   }
 }
 
+Image* TextureSet::GetImage( size_t index ) const
+{
+  Image* result(0);
+  if( index < mTextures.size() )
+  {
+    result = mTextures[index].image.Get();
+  }
+  else
+  {
+    DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetImage");
+  }
+
+  return result;
+}
+
 void TextureSet::SetSampler( size_t index, SamplerPtr sampler )
 {
   size_t textureCount( mTextures.size() );
@@ -115,21 +130,26 @@ void TextureSet::SetSampler( size_t index, SamplerPtr sampler )
   SceneGraph::SetSamplerMessage( GetEventThreadServices(), *mSceneObject, index, renderSampler );
 }
 
-ImagePtr TextureSet::GetImage( size_t index )
+Sampler* TextureSet::GetSampler( size_t index ) const
 {
-  ImagePtr result(0);
+  Sampler* result(0);
   if( index < mTextures.size() )
   {
-    result = mTextures[index].image;
+    result = mTextures[index].sampler.Get();
   }
   else
   {
-    DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetImage");
+    DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetSampler");
   }
 
   return result;
 }
 
+size_t TextureSet::GetTextureCount() const
+{
+  return mTextures.size();
+}
+
 const SceneGraph::TextureSet* TextureSet::GetTextureSetSceneObject() const
 {
   return mSceneObject;
index c563cb8..0a3b2c9 100644 (file)
@@ -63,16 +63,24 @@ public:
   void SetImage( size_t index, ImagePtr image );
 
   /**
+   * @copydoc Dali::TextureSet::GetImage()
+   */
+  Image* GetImage( size_t index ) const;
+
+  /**
    * @copydoc Dali::TextureSet::SetSampler()
    */
   void SetSampler( size_t index, SamplerPtr sampler );
 
   /**
-   * @brief Get the image at position "index" in the texture set
-   * @param[in] index The index of the image
-   * @return A pointer to the image at position "index"
+   * @copydoc Dali::TextureSet::GetSampler()
+   */
+  Sampler* GetSampler( size_t index ) const;
+
+  /**
+   * @copydoc Dali::TextureSet::GetTextureCount()
    */
-  ImagePtr GetImage( size_t index );
+  size_t GetTextureCount() const;
 
  /**
    * @brief Get the TextureSet scene object