From 849d3771c69990afb9cac2b6562d996b98f5814a Mon Sep 17 00:00:00 2001 From: Eunki Hong Date: Sat, 21 Oct 2023 23:01:29 +0900 Subject: [PATCH] Allow to get Shader::Hint by integer Previously Shader::Hint value could be assigned only by string. Let we allow to assing hint value Shader::Hint::Value (as int32_t) if user know the enum correctly. Change-Id: Ifc6dbb8ea76180b8e454dace28ae3ed4de447037 Signed-off-by: Eunki Hong --- automated-tests/src/dali/utc-Dali-Shader.cpp | 33 +++++++++++++++++++++++++++ dali/internal/event/rendering/shader-impl.cpp | 18 +++++++++++---- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-Shader.cpp b/automated-tests/src/dali/utc-Dali-Shader.cpp index 75ea5d1..bf37850 100644 --- a/automated-tests/src/dali/utc-Dali-Shader.cpp +++ b/automated-tests/src/dali/utc-Dali-Shader.cpp @@ -530,6 +530,39 @@ int UtcDaliShaderPropertyValueConstructorMap(void) END_TEST; } +int UtcDaliShaderPropertyValueConstructorMap2(void) +{ + TestApplication application; + + tet_infoline("UtcDaliShaderPropertyValueConstructorMap2"); + + std::string hintSet = "MODIFIES_GEOMETRY"; + Property::Map map; + map["vertex"] = VertexSource; + map["fragment"] = FragmentSource; + map["renderPassTag"] = 0; + map["hints"] = Shader::Hint::Value::MODIFIES_GEOMETRY; + + Shader shader = Shader::New(map); + + Property::Value value = shader.GetProperty(Shader::Property::PROGRAM); + DALI_TEST_CHECK(value.GetType() == Property::MAP); + + const Property::Map* outMap = value.GetMap(); + std::string v = (*outMap)["vertex"].Get(); + std::string f = (*outMap)["fragment"].Get(); + std::string h = (*outMap)["hints"].Get(); + int32_t r = (*outMap)["renderPassTag"].Get(); + + DALI_TEST_CHECK(v == map["vertex"].Get()); + DALI_TEST_CHECK(f == map["fragment"].Get()); + // Note : shader.GetProperty return string even we input hints as enum. + DALI_TEST_CHECK(h == hintSet); + DALI_TEST_CHECK(r == map["renderPassTag"].Get()); + + END_TEST; +} + int UtcDaliShaderPropertyValueConstructorArray(void) { TestApplication application; diff --git a/dali/internal/event/rendering/shader-impl.cpp b/dali/internal/event/rendering/shader-impl.cpp index e505140..57b8b59 100644 --- a/dali/internal/event/rendering/shader-impl.cpp +++ b/dali/internal/event/rendering/shader-impl.cpp @@ -110,11 +110,19 @@ void GetShaderData(const Property::Map& shaderMap, std::string& vertexShader, st if(Property::Value* value = shaderMap.Find("hints")) { - static_cast( // ignore return - Scripting::GetEnumeration(value->Get().c_str(), - ShaderHintsTable, - ShaderHintsTableSize, - hints)); + int32_t hintInteger = 0; + if(value->Get(hintInteger)) + { + hints = static_cast(hintInteger); + } + else + { + static_cast( // ignore return + Scripting::GetEnumeration(value->Get().c_str(), + ShaderHintsTable, + ShaderHintsTableSize, + hints)); + } } } -- 2.7.4