Changed handling of uniforms of arrays of structs
[platform/core/uifw/dali-core.git] / dali / internal / update / common / uniform-map.h
index 8080c82..0a505de 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_SCENE_GRAPH_UNIFORM_MAP_H
 
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
@@ -40,19 +40,44 @@ namespace SceneGraph
 class UniformPropertyMapping
 {
 public:
+  using Hash = unsigned long;
+
   /**
    * Constructor
    */
   UniformPropertyMapping(ConstString theUniformName, const PropertyInputImpl* thePropertyPtr)
   : propertyPtr(thePropertyPtr),
-    uniformName(theUniformName)
+    uniformName(theUniformName),
+    uniformNameHash(0u),
+    uniformNameHashNoArray(0u),
+    arrayIndex(0u)
   {
+    // Look for array index closing bracket
+    auto nameStringView = theUniformName.GetStringView();
+    auto pos            = nameStringView.rfind("]");
+
+    // If found, extract the array index and store it, if it's an element in an array of basic types.
+    if(pos != std::string::npos)
+    {
+      auto pos0 = theUniformName.GetStringView().rfind("[", pos);
+      if(pos == nameStringView.length() - 1) // if element is in struct, don't set array index.
+      {
+        arrayIndex = atoi(theUniformName.GetCString() + pos0 + 1);
+      }
+      // Calculate hash from name without array index
+      uniformNameHashNoArray = Dali::CalculateHash(theUniformName.GetStringView().substr(0, pos0).data(), '[');
+    }
+    uniformName     = theUniformName;
+    uniformNameHash = Dali::CalculateHash(theUniformName.GetCString());
   }
 
   UniformPropertyMapping() = default;
 
   const PropertyInputImpl* propertyPtr{nullptr};
-  ConstString              uniformName;
+  ConstString              uniformName{};
+  Hash                     uniformNameHash{0u};
+  Hash                     uniformNameHashNoArray{0u};
+  int32_t                  arrayIndex{0u};
 };
 
 /**