From 879f080433b3428e90ed19ed3c7287a98c9158d6 Mon Sep 17 00:00:00 2001 From: Chu Hoang Date: Mon, 14 Sep 2015 16:20:50 +0100 Subject: [PATCH] Added GetUniformName to Sampler. Change-Id: I962305f3cdf5b19ac5d2d1c23186c3204057be6e --- .../src/dali-devel/utc-Dali-Sampler.cpp | 47 ++++++++++++++++++++++ dali/devel-api/rendering/sampler.cpp | 5 +++ dali/devel-api/rendering/sampler.h | 7 ++++ dali/internal/event/rendering/sampler-impl.cpp | 5 +++ dali/internal/event/rendering/sampler-impl.h | 5 +++ 5 files changed, 69 insertions(+) diff --git a/automated-tests/src/dali-devel/utc-Dali-Sampler.cpp b/automated-tests/src/dali-devel/utc-Dali-Sampler.cpp index 4cecb5f..81ae455 100644 --- a/automated-tests/src/dali-devel/utc-Dali-Sampler.cpp +++ b/automated-tests/src/dali-devel/utc-Dali-Sampler.cpp @@ -15,6 +15,7 @@ * */ +#include #include #include @@ -189,6 +190,52 @@ int UtcDaliSamplerSetUniformName02(void) END_TEST; } +int UtcDaliSamplerGetUniformName01(void) +{ + TestApplication application; + + Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 ); + std::string uniformName = "sTextureTEST"; + Sampler sampler = Sampler::New(image, uniformName); + + std::string actual = sampler.GetUniformName(); + + DALI_TEST_EQUALS( uniformName, actual, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliSamplerGetUniformName02(void) +{ + TestApplication application; + + Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 ); + Sampler sampler = Sampler::New(image, "sTextureFAIL" ); + + std::string uniformName = "sTextureTEST"; + sampler.SetUniformName( uniformName ); + + Material material = CreateMaterial(1.0f); + material.AddSampler( sampler ); + Geometry geometry = CreateQuadGeometry(); + Renderer renderer = Renderer::New( geometry, material ); + Actor actor = Actor::New(); + actor.AddRenderer(renderer); + actor.SetParentOrigin( ParentOrigin::CENTER ); + actor.SetSize(400, 400); + + Stage::GetCurrent().Add( actor ); + + application.SendNotification(); + application.Render(); + + std::string actual = sampler.GetUniformName(); + + DALI_TEST_EQUALS( uniformName, actual, TEST_LOCATION ); + + END_TEST; +} + int UtcDaliSamplerSetGetImage(void) { TestApplication application; diff --git a/dali/devel-api/rendering/sampler.cpp b/dali/devel-api/rendering/sampler.cpp index d56ed24..2b2ab5e 100644 --- a/dali/devel-api/rendering/sampler.cpp +++ b/dali/devel-api/rendering/sampler.cpp @@ -61,6 +61,11 @@ void Sampler::SetUniformName( const std::string& name ) GetImplementation(*this).SetTextureUnitUniformName( name ); } +const std::string& Sampler::GetUniformName() const +{ + return GetImplementation(*this).GetTextureUnitUniformName(); +} + void Sampler::SetImage( Image& image ) { Internal::ImagePtr imagePtr = &GetImplementation( image ); diff --git a/dali/devel-api/rendering/sampler.h b/dali/devel-api/rendering/sampler.h index b5d53d7..4d1b80d 100644 --- a/dali/devel-api/rendering/sampler.h +++ b/dali/devel-api/rendering/sampler.h @@ -129,6 +129,13 @@ public: void SetUniformName( const std::string& name ); /** + * @brief Gets the name of the shader uniform that this sampler uses + * + * @return Returns the name of the uniform + */ + const std::string& GetUniformName() const; + + /** * @brief Set the image used by this sampler * * @param[in] image Image used by this sampler diff --git a/dali/internal/event/rendering/sampler-impl.cpp b/dali/internal/event/rendering/sampler-impl.cpp index 1787179..3fb8ca4 100644 --- a/dali/internal/event/rendering/sampler-impl.cpp +++ b/dali/internal/event/rendering/sampler-impl.cpp @@ -68,6 +68,11 @@ void Sampler::SetTextureUnitUniformName( const std::string& name ) SetTextureUnitUniformNameMessage( GetEventThreadServices(), *mSceneObject, name); } +const std::string& Sampler::GetTextureUnitUniformName() const +{ + return mSceneObject->GetTextureUnitUniformName(); +} + void Sampler::SetImage( ImagePtr& image ) { // Keep a reference to the image object diff --git a/dali/internal/event/rendering/sampler-impl.h b/dali/internal/event/rendering/sampler-impl.h index 340f140..33015f9 100644 --- a/dali/internal/event/rendering/sampler-impl.h +++ b/dali/internal/event/rendering/sampler-impl.h @@ -59,6 +59,11 @@ public: void SetTextureUnitUniformName( const std::string& name ); /** + * @copydoc Dali::Sampler::GetUniformName() + */ + const std::string& GetTextureUnitUniformName() const; + + /** * @copydoc Dali::Sampler::SetImage() */ void SetImage( ImagePtr& image ); -- 2.7.4