Makes Models use common shader manager
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / scene-definition.cpp
index cf5aa61..370e926 100644 (file)
@@ -48,39 +48,50 @@ const std::map<Property::Type, Constraint (*)(Actor&, Property::Index)>& GetCons
 {
   static const std::map<Property::Type, Constraint (*)(Actor&, Property::Index)> sConstraintFactory = {
     {Property::Type::BOOLEAN,
-     [](Actor& a, Property::Index i) {
-       return Constraint::New<bool>(a, i, [](bool& current, const PropertyInputContainer& inputs) { current = inputs[0]->GetBoolean(); });
+     [](Actor& a, Property::Index i)
+     {
+       return Constraint::New<bool>(a, i, [](bool& current, const PropertyInputContainer& inputs)
+                                    { current = inputs[0]->GetBoolean(); });
      }},
     {Property::Type::INTEGER,
-     [](Actor& a, Property::Index i) {
-       return Constraint::New<int>(a, i, [](int& current, const PropertyInputContainer& inputs) { current = inputs[0]->GetInteger(); });
+     [](Actor& a, Property::Index i)
+     {
+       return Constraint::New<int>(a, i, [](int& current, const PropertyInputContainer& inputs)
+                                   { current = inputs[0]->GetInteger(); });
      }},
     {Property::Type::FLOAT,
-     [](Actor& a, Property::Index i) {
+     [](Actor& a, Property::Index i)
+     {
        return Constraint::New<float>(a, i, EqualToConstraint());
      }},
     {Property::Type::VECTOR2,
-     [](Actor& a, Property::Index i) {
+     [](Actor& a, Property::Index i)
+     {
        return Constraint::New<Vector2>(a, i, EqualToConstraint());
      }},
     {Property::Type::VECTOR3,
-     [](Actor& a, Property::Index i) {
+     [](Actor& a, Property::Index i)
+     {
        return Constraint::New<Vector3>(a, i, EqualToConstraint());
      }},
     {Property::Type::VECTOR4,
-     [](Actor& a, Property::Index i) {
+     [](Actor& a, Property::Index i)
+     {
        return Constraint::New<Vector4>(a, i, EqualToConstraint());
      }},
     {Property::Type::MATRIX,
-     [](Actor& a, Property::Index i) {
+     [](Actor& a, Property::Index i)
+     {
        return Constraint::New<Matrix>(a, i, EqualToConstraint());
      }},
     {Property::Type::MATRIX3,
-     [](Actor& a, Property::Index i) {
+     [](Actor& a, Property::Index i)
+     {
        return Constraint::New<Matrix3>(a, i, EqualToConstraint());
      }},
     {Property::Type::ROTATION,
-     [](Actor& a, Property::Index i) {
+     [](Actor& a, Property::Index i)
+     {
        return Constraint::New<Quaternion>(a, i, EqualToConstraint());
      }},
   };
@@ -159,7 +170,7 @@ void AddJointDebugVisual(Actor aJoint)
 
   aJoint.SetVisible(true);
 }
-#endif //DEBUG_JOINTS
+#endif // DEBUG_JOINTS
 
 class ActorCreatorVisitor : public NodeDefinition::IVisitor
 {
@@ -234,7 +245,8 @@ void SortAndDeduplicateRequests(std::vector<RequestType>& requests)
     ++iter;
   } while(true);
 
-  requests.erase(std::remove_if(requests.begin(), requests.end(), [](const RequestType& sscr) { return !sscr.mShader; }),
+  requests.erase(std::remove_if(requests.begin(), requests.end(), [](const RequestType& sscr)
+                                { return !sscr.mShader; }),
                  requests.end());
 }
 
@@ -371,7 +383,10 @@ void SceneDefinition::CountResourceRefs(Index iNode, const Customization::Choice
 
     void Register(ResourceType::Value type, Index id)
     {
-      ++(*refCounts)[type][id];
+      if((!(*refCounts)[type].Empty()) && (id >= 0) && ((*refCounts)[type].Size() > id))
+      {
+        ++(*refCounts)[type][id];
+      }
     }
   };
 
@@ -479,15 +494,15 @@ bool SceneDefinition::ReparentNode(const std::string& name, const std::string& n
   auto& node  = *nodePtr;
   auto  iNode = std::distance(mNodes.data(), nodePtr);
 
-  DEBUG_ONLY(auto dumpNode = [](NodeDefinition const& n) {
+  DEBUG_ONLY(auto dumpNode = [](NodeDefinition const& n)
+             {
     std::ostringstream stream;
     stream << n.mName << " (" << n.mParentIdx << "):";
     for(auto i : n.mChildren)
     {
       stream << i << ", ";
     }
-    LOGD(("%s", stream.str().c_str()));
-  };)
+    LOGD(("%s", stream.str().c_str())); };)
 
   // Remove node from children of previous parent (if any).
   if(node->mParentIdx != INVALID_INDEX)
@@ -533,15 +548,16 @@ bool SceneDefinition::RemoveNode(const std::string& name)
   auto&                                                 thisNodes = mNodes;
   unsigned int                                          numReset  = 0;
   std::function<void(std::unique_ptr<NodeDefinition>&)> resetFn =
-    [&thisNodes, &resetFn, &numReset](std::unique_ptr<NodeDefinition>& nd) {
-      LOGD(("resetting %d", &nd - thisNodes.data()));
-      for(auto i : nd->mChildren)
-      {
-        resetFn(thisNodes[i]);
-      }
-      nd.reset();
-      ++numReset;
-    };
+    [&thisNodes, &resetFn, &numReset](std::unique_ptr<NodeDefinition>& nd)
+  {
+    LOGD(("resetting %d", &nd - thisNodes.data()));
+    for(auto i : nd->mChildren)
+    {
+      resetFn(thisNodes[i]);
+    }
+    nd.reset();
+    ++numReset;
+  };
 
   resetFn(*node);
 
@@ -564,7 +580,8 @@ bool SceneDefinition::RemoveNode(const std::string& name)
   {
     INDEX_FOR_REMOVAL = INVALID_INDEX
   };
-  auto offsetter = [&offsets](Index& i) {
+  auto offsetter = [&offsets](Index& i)
+  {
     auto iFind = std::lower_bound(offsets.begin(), offsets.end(), i);
     if(iFind != offsets.end() && *iFind == i)
     {
@@ -604,7 +621,8 @@ bool SceneDefinition::RemoveNode(const std::string& name)
 void SceneDefinition::GetNodeModelStack(Index index, MatrixStack& model) const
 {
   auto&                    thisNodes  = mNodes;
-  std::function<void(int)> buildStack = [&model, &thisNodes, &buildStack](int i) {
+  std::function<void(int)> buildStack = [&model, &thisNodes, &buildStack](int i)
+  {
     auto node = thisNodes[i].get();
     if(node->mParentIdx != INVALID_INDEX)
     {
@@ -619,7 +637,8 @@ NodeDefinition* SceneDefinition::FindNode(const std::string& name, Index* outInd
 {
   auto iBegin = mNodes.begin();
   auto iEnd   = mNodes.end();
-  auto iFind  = std::find_if(iBegin, iEnd, [&name](const std::unique_ptr<NodeDefinition>& nd) { return nd->mName == name; });
+  auto iFind  = std::find_if(iBegin, iEnd, [&name](const std::unique_ptr<NodeDefinition>& nd)
+                            { return nd->mName == name; });
 
   auto result = iFind != iEnd ? iFind->get() : nullptr;
   if(result && outIndex)
@@ -633,7 +652,8 @@ const NodeDefinition* SceneDefinition::FindNode(const std::string& name, Index*
 {
   auto iBegin = mNodes.begin();
   auto iEnd   = mNodes.end();
-  auto iFind  = std::find_if(iBegin, iEnd, [&name](const std::unique_ptr<NodeDefinition>& nd) { return nd->mName == name; });
+  auto iFind  = std::find_if(iBegin, iEnd, [&name](const std::unique_ptr<NodeDefinition>& nd)
+                            { return nd->mName == name; });
 
   auto result = iFind != iEnd ? iFind->get() : nullptr;
   if(result && outIndex)
@@ -647,7 +667,8 @@ Index SceneDefinition::FindNodeIndex(const NodeDefinition& node) const
 {
   auto iBegin = mNodes.begin();
   auto iEnd   = mNodes.end();
-  auto iFind  = std::find_if(iBegin, iEnd, [&node](const std::unique_ptr<NodeDefinition>& n) { return n.get() == &node; });
+  auto iFind  = std::find_if(iBegin, iEnd, [&node](const std::unique_ptr<NodeDefinition>& n)
+                            { return n.get() == &node; });
   return iFind != iEnd ? std::distance(iBegin, iFind) : INVALID_INDEX;
 }
 
@@ -938,7 +959,8 @@ bool SceneDefinition::FindNode(const std::string& name, std::unique_ptr<NodeDefi
   // We're searching from the end assuming a higher probability of operations targeting
   // recently added nodes. (conf.: root, which is immovable, cannot be removed, and was
   // the first to be added, is index 0.)
-  auto iFind = std::find_if(mNodes.rbegin(), mNodes.rend(), [&name](const std::unique_ptr<NodeDefinition>& nd) { return nd->mName == name; })
+  auto iFind = std::find_if(mNodes.rbegin(), mNodes.rend(), [&name](const std::unique_ptr<NodeDefinition>& nd)
+                            { return nd->mName == name; })
                  .base();
 
   const bool success = iFind != mNodes.begin();