Allow to get Shader::Hint by integer 20/300320/1
authorEunki Hong <eunkiki.hong@samsung.com>
Sat, 21 Oct 2023 14:01:29 +0000 (23:01 +0900)
committerEunki Hong <eunkiki.hong@samsung.com>
Sat, 21 Oct 2023 14:11:56 +0000 (23:11 +0900)
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 <eunkiki.hong@samsung.com>
automated-tests/src/dali/utc-Dali-Shader.cpp
dali/internal/event/rendering/shader-impl.cpp

index 75ea5d1..bf37850 100644 (file)
@@ -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>();
+  std::string          f      = (*outMap)["fragment"].Get<std::string>();
+  std::string          h      = (*outMap)["hints"].Get<std::string>();
+  int32_t              r      = (*outMap)["renderPassTag"].Get<int32_t>();
+
+  DALI_TEST_CHECK(v == map["vertex"].Get<std::string>());
+  DALI_TEST_CHECK(f == map["fragment"].Get<std::string>());
+  // Note : shader.GetProperty return string even we input hints as enum.
+  DALI_TEST_CHECK(h == hintSet);
+  DALI_TEST_CHECK(r == map["renderPassTag"].Get<int32_t>());
+
+  END_TEST;
+}
+
 int UtcDaliShaderPropertyValueConstructorArray(void)
 {
   TestApplication application;
index e505140..57b8b59 100644 (file)
@@ -110,11 +110,19 @@ void GetShaderData(const Property::Map& shaderMap, std::string& vertexShader, st
 
   if(Property::Value* value = shaderMap.Find("hints"))
   {
-    static_cast<void>( // ignore return
-      Scripting::GetEnumeration<Dali::Shader::Hint::Value>(value->Get<std::string>().c_str(),
-                                                           ShaderHintsTable,
-                                                           ShaderHintsTableSize,
-                                                           hints));
+    int32_t hintInteger = 0;
+    if(value->Get(hintInteger))
+    {
+      hints = static_cast<Dali::Shader::Hint::Value>(hintInteger);
+    }
+    else
+    {
+      static_cast<void>( // ignore return
+        Scripting::GetEnumeration<Dali::Shader::Hint::Value>(value->Get<std::string>().c_str(),
+                                                             ShaderHintsTable,
+                                                             ShaderHintsTableSize,
+                                                             hints));
+    }
   }
 }