[dali_2.3.22] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-graphics-reflection.cpp
index 2822c0a..22d09e1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
@@ -15,6 +15,7 @@
  */
 
 #include "test-graphics-reflection.h"
+#include "test-graphics-controller.h"
 #include "test-graphics-shader.h"
 
 #include <dali/public-api/object/property-map.h>
@@ -33,6 +34,7 @@ namespace
 {
 static const std::vector<UniformData> UNIFORMS =
   {
+    UniformData("uColor", Property::Type::VECTOR4),
     UniformData("uRendererColor", Property::Type::FLOAT),
     UniformData("uCustom", Property::Type::INTEGER),
     UniformData("uCustom3", Property::Type::VECTOR3),
@@ -46,13 +48,13 @@ static const std::vector<UniformData> UNIFORMS =
     UniformData("sTexture", Property::Type::FLOAT),
     UniformData("sTextureRect", Property::Type::FLOAT),
     UniformData("sGloss", Property::Type::FLOAT),
-    UniformData("uColor", Property::Type::VECTOR4),
     UniformData("uActorColor", Property::Type::VECTOR4),
     UniformData("uModelMatrix", Property::Type::MATRIX),
     UniformData("uModelView", Property::Type::MATRIX),
     UniformData("uMvpMatrix", Property::Type::MATRIX),
     UniformData("uNormalMatrix", Property::Type::MATRIX3),
     UniformData("uProjection", Property::Type::MATRIX),
+    UniformData("uScale", Property::Type::VECTOR3),
     UniformData("uSize", Property::Type::VECTOR3),
     UniformData("uViewMatrix", Property::Type::MATRIX),
     UniformData("uLightCameraProjectionMatrix", Property::Type::MATRIX),
@@ -110,8 +112,9 @@ constexpr int GetSizeForType(Property::Type type)
 
 } // namespace
 
-TestGraphicsReflection::TestGraphicsReflection(TestGlAbstraction& gl, uint32_t programId, Property::Array& vfs, const Graphics::ProgramCreateInfo& createInfo, std::vector<UniformData>& customUniforms, std::vector<TestGraphicsReflection::TestUniformBlockInfo>& customUniformBlocks)
-: mGl(gl),
+TestGraphicsReflection::TestGraphicsReflection(TestGraphicsController& controller, TestGlAbstraction& gl, uint32_t programId, Property::Array& vfs, const Graphics::ProgramCreateInfo& createInfo, std::vector<UniformData>& customUniforms, std::vector<TestGraphicsReflection::TestUniformBlockInfo>& customUniformBlocks)
+: mController(controller),
+  mGl(gl),
   mCustomUniforms(customUniforms)
 {
   for(Property::Array::SizeType i = 0; i < vfs.Count(); ++i)
@@ -137,19 +140,6 @@ TestGraphicsReflection::TestGraphicsReflection(TestGlAbstraction& gl, uint32_t p
   mDefaultUniformBlock.members.clear();
 
   int offset = 0;
-  for(const auto& data : UNIFORMS)
-  {
-    mDefaultUniformBlock.members.emplace_back();
-    auto& item   = mDefaultUniformBlock.members.back();
-    item.name    = data.name;
-    item.binding = 0;
-    item.offsets.push_back(offset);
-    item.locations.push_back(gl.GetUniformLocation(programId, data.name.c_str()));
-    item.bufferIndex  = 0;
-    item.uniformClass = Graphics::UniformClass::UNIFORM;
-    item.type         = data.type;
-    offset += GetSizeForType(data.type);
-  }
 
   for(const auto& data : mCustomUniforms)
   {
@@ -230,6 +220,21 @@ TestGraphicsReflection::TestGraphicsReflection(TestGlAbstraction& gl, uint32_t p
       offset += GetSizeForType(data.type);
     }
   }
+
+  for(const auto& data : UNIFORMS)
+  {
+    mDefaultUniformBlock.members.emplace_back();
+    auto& item   = mDefaultUniformBlock.members.back();
+    item.name    = data.name;
+    item.binding = 0;
+    item.offsets.push_back(offset);
+    item.locations.push_back(gl.GetUniformLocation(programId, data.name.c_str()));
+    item.bufferIndex  = 0;
+    item.uniformClass = Graphics::UniformClass::UNIFORM;
+    item.type         = data.type;
+    offset += GetSizeForType(data.type);
+  }
+
   mDefaultUniformBlock.size = offset;
 
   mUniformBlocks.push_back(mDefaultUniformBlock);
@@ -241,19 +246,19 @@ TestGraphicsReflection::TestGraphicsReflection(TestGlAbstraction& gl, uint32_t p
 
 uint32_t TestGraphicsReflection::GetVertexAttributeLocation(const std::string& name) const
 {
-  // Automatically assign locations to named attributes when requested
   auto iter = std::find(mAttributes.begin(), mAttributes.end(), name);
   if(iter != mAttributes.end())
   {
     return iter - mAttributes.begin();
   }
-  else
+  else if(mController.AutoAttrCreation())
   {
     uint32_t location = mAttributes.size();
     mAttributes.push_back(name);
     return location;
   }
-  return 0u;
+
+  return -1;
 }
 
 Dali::Graphics::VertexInputAttributeFormat TestGraphicsReflection::GetVertexAttributeFormat(uint32_t location) const
@@ -326,6 +331,7 @@ bool TestGraphicsReflection::GetUniformBlock(uint32_t index, Dali::Graphics::Uni
     out.members[i].uniformClass = Graphics::UniformClass::UNIFORM;
     out.members[i].offset       = memberUniform.offsets[0];
     out.members[i].location     = memberUniform.locations[0];
+    out.members[i].elementCount = memberUniform.numElements;
   }
 
   return true;