Syncing test harness 25/257125/1
authorDavid Steele <david.steele@samsung.com>
Mon, 19 Apr 2021 10:07:16 +0000 (11:07 +0100)
committerDavid Steele <david.steele@samsung.com>
Mon, 19 Apr 2021 10:07:16 +0000 (11:07 +0100)
Change-Id: Ibca06fbc35ce4943c019cb159ca3494068005096

automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-actor-utils.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-actor-utils.h
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-application.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-gl-abstraction.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-gl-abstraction.h
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-graphics-controller.cpp

index 756deb5..bf62bb8 100644 (file)
@@ -91,6 +91,35 @@ Actor CreateRenderableActor(Texture texture, const std::string& vertexShader, co
   return actor;
 }
 
+Actor CreateRenderableActor2(TextureSet textures, const std::string& vertexShader, const std::string& fragmentShader)
+{
+  // Create the geometry
+  Geometry geometry = CreateQuadGeometry();
+
+  // Create Shader
+  Shader shader = Shader::New(vertexShader, fragmentShader);
+
+  // Create renderer from geometry and material
+  Renderer renderer = Renderer::New(geometry, shader);
+
+  // Create actor and set renderer
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+
+  // If we a texture, then create a texture-set and add to renderer
+  if(textures)
+  {
+    renderer.SetTextures(textures);
+
+    auto texture = textures.GetTexture(0);
+
+    // Set actor to the size of the texture if set
+    actor.SetProperty(Actor::Property::SIZE, Vector2(texture.GetWidth(), texture.GetHeight()));
+  }
+
+  return actor;
+}
+
 Texture CreateTexture(TextureType::Type type, Pixel::Format format, int width, int height)
 {
   Texture texture = Texture::New(type, format, width, height);
index 523fea5..0dbe07e 100644 (file)
@@ -19,6 +19,7 @@
  */
 
 // EXTERNAL INCLUDES
+#include <dali/public-api/rendering/texture-set.h>
 #include <dali/public-api/rendering/texture.h>
 #include <string>
 
@@ -50,6 +51,15 @@ Actor CreateRenderableActor(Texture texture);
  */
 Actor CreateRenderableActor(Texture texture, const std::string& vertexShader, const std::string& fragmentShader);
 
+/**
+ * @brief Creates a renderable-actor with a texture and custom shaders.
+ * @param[in] textures TextureSet to set.
+ * @param[in] vertexShader The vertex-shader.
+ * @param[in] fragmentShader The fragment-shader.
+ * @return An actor with a renderer.
+ */
+Actor CreateRenderableActor2(TextureSet textures, const std::string& vertexShader, const std::string& fragmentShader);
+
 Texture CreateTexture(TextureType::Type type, Pixel::Format format, int width, int height);
 
 } // namespace Dali
index 22ff2fb..6075c8f 100644 (file)
@@ -79,9 +79,9 @@ void TestApplication::CreateScene()
 
   // Create render target for the scene
   Graphics::RenderTargetCreateInfo rtInfo{};
-  rtInfo.SetExtent( {mSurfaceWidth, mSurfaceHeight });
-  mRenderTarget = mGraphicsController.CreateRenderTarget( rtInfo, nullptr );
-  mScene.SetSurfaceRenderTarget( mRenderTarget.get() );
+  rtInfo.SetExtent({mSurfaceWidth, mSurfaceHeight});
+  mRenderTarget = mGraphicsController.CreateRenderTarget(rtInfo, nullptr);
+  mScene.SetSurfaceRenderTarget(mRenderTarget.get());
 }
 
 void TestApplication::InitializeCore()
index ddeb1d9..b85cf4d 100644 (file)
@@ -49,7 +49,6 @@ void TestGlAbstraction::Initialize()
   mCurrentProgram                  = 0;
   mCompileStatus                   = GL_TRUE;
   mLinkStatus                      = GL_TRUE;
-  mNumberOfActiveUniforms          = 0;
   mGetErrorResult                  = 0;
   mGetStringResult                 = NULL;
   mIsBufferResult                  = 0;
@@ -115,6 +114,31 @@ void TestGlAbstraction::Initialize()
   {
     mVertexAttribArrayState[i] = false;
   }
+
+  mActiveUniforms = std::vector<ActiveUniform>{
+    {"uRendererColor", GL_FLOAT, 1},
+    {"uCustom", GL_FLOAT_VEC3, 1},
+    {"uCustom3", GL_FLOAT_VEC3, 1},
+    {"uFadeColor", GL_FLOAT_VEC4, 1},
+    {"uUniform1", GL_FLOAT_VEC4, 1},
+    {"uUniform2", GL_FLOAT_VEC4, 1},
+    {"uUniform3", GL_FLOAT_VEC4, 1},
+    {"uFadeProgress", GL_FLOAT, 1},
+    {"uANormalMatrix", GL_FLOAT_MAT3, 1},
+    {"sEffect", GL_SAMPLER_2D, 1},
+    {"sTexture", GL_SAMPLER_2D, 1},
+    {"sTextureRect", GL_SAMPLER_2D, 1},
+    {"sGloss", GL_SAMPLER_2D, 1},
+    {"uColor", GL_FLOAT_VEC4, 1},
+    {"uModelMatrix", GL_FLOAT_MAT4, 1},
+    {"uModelView", GL_FLOAT_MAT4, 1},
+    {"uMvpMatrix", GL_FLOAT_MAT4, 1},
+    {"uNormalMatrix", GL_FLOAT_MAT4, 1},
+    {"uProjection", GL_FLOAT_MAT4, 1},
+    {"uSize", GL_FLOAT_VEC3, 1},
+    {"uViewMatrix", GL_FLOAT_MAT4, 1},
+    {"uLightCameraProjectionMatrix", GL_FLOAT_MAT4, 1},
+    {"uLightCameraViewMatrix", GL_FLOAT_MAT4, 1}};
 }
 
 void TestGlAbstraction::PreRender()
index 760f678..aec9f5d 100644 (file)
@@ -49,6 +49,13 @@ struct UniformData
   }
 };
 
+struct ActiveUniform
+{
+  std::string name;
+  GLenum      type;
+  GLint       size;
+};
+
 class DALI_CORE_API TestGlAbstraction : public Dali::Integration::GlAbstraction
 {
 public:
@@ -754,27 +761,18 @@ public:
   {
   }
 
+  inline void SetActiveUniforms(const std::vector<ActiveUniform>& uniforms)
+  {
+    mActiveUniforms = uniforms;
+  }
+
   inline void GetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name) override
   {
-    switch(index)
+    if(index < mActiveUniforms.size())
     {
-      case 0:
-        *length = snprintf(name, bufsize, "sTexture");
-        *type   = GL_SAMPLER_2D;
-        *size   = 1;
-        break;
-      case 1:
-        *length = snprintf(name, bufsize, "sEffect");
-        *type   = GL_SAMPLER_2D;
-        *size   = 1;
-        break;
-      case 2:
-        *length = snprintf(name, bufsize, "sGloss");
-        *type   = GL_SAMPLER_2D;
-        *size   = 1;
-        break;
-      default:
-        break;
+      *length = snprintf(name, bufsize, "%s", mActiveUniforms[index].name.c_str());
+      *type   = mActiveUniforms[index].type;
+      *size   = mActiveUniforms[index].size;
     }
   }
 
@@ -842,7 +840,7 @@ public:
         *params = mProgramBinaryLength;
         break;
       case GL_ACTIVE_UNIFORMS:
-        *params = mNumberOfActiveUniforms;
+        *params = mActiveUniforms.size();
         break;
       case GL_ACTIVE_UNIFORM_MAX_LENGTH:
         *params = 100;
@@ -986,31 +984,10 @@ public:
     namedParams["program"] << program;
     mShaderTrace.PushCall("LinkProgram", out.str(), namedParams);
 
-    mNumberOfActiveUniforms = 3;
-
-    GetUniformLocation(program, "uRendererColor");
-    GetUniformLocation(program, "uCustom");
-    GetUniformLocation(program, "uCustom3");
-    GetUniformLocation(program, "uFadeColor");
-    GetUniformLocation(program, "uUniform1");
-    GetUniformLocation(program, "uUniform2");
-    GetUniformLocation(program, "uUniform3");
-    GetUniformLocation(program, "uFadeProgress");
-    GetUniformLocation(program, "uANormalMatrix");
-    GetUniformLocation(program, "sEffect");
-    GetUniformLocation(program, "sTexture");
-    GetUniformLocation(program, "sTextureRect");
-    GetUniformLocation(program, "sGloss");
-    GetUniformLocation(program, "uColor");
-    GetUniformLocation(program, "uModelMatrix");
-    GetUniformLocation(program, "uModelView");
-    GetUniformLocation(program, "uMvpMatrix");
-    GetUniformLocation(program, "uNormalMatrix");
-    GetUniformLocation(program, "uProjection");
-    GetUniformLocation(program, "uSize");
-    GetUniformLocation(program, "uViewMatrix");
-    GetUniformLocation(program, "uLightCameraProjectionMatrix");
-    GetUniformLocation(program, "uLightCameraViewMatrix");
+    for(const auto& uniform : mActiveUniforms)
+    {
+      GetUniformLocation(program, uniform.name.c_str());
+    }
 
     for(const auto& uniform : mCustomUniformData)
     {
@@ -2470,14 +2447,13 @@ public: // TEST FUNCTIONS
     mBufferSubDataCalls.clear();
   }
 
-private:
+public:
   GLuint                                mCurrentProgram;
   GLuint                                mCompileStatus;
   BufferDataCalls                       mBufferDataCalls;
   BufferSubDataCalls                    mBufferSubDataCalls;
   GLvoid*                               mMappedBuffer{nullptr};
   GLuint                                mLinkStatus;
-  GLint                                 mNumberOfActiveUniforms;
   GLenum                                mGetErrorResult;
   GLubyte*                              mGetStringResult;
   GLboolean                             mIsBufferResult;
@@ -2552,8 +2528,8 @@ private:
   typedef std::map<std::string, GLint>   UniformIDMap;
   typedef std::map<GLuint, UniformIDMap> ProgramUniformMap;
   ProgramUniformMap                      mUniforms;
-
-  std::vector<UniformData> mCustomUniformData{};
+  std::vector<ActiveUniform>             mActiveUniforms;
+  std::vector<UniformData>               mCustomUniformData{};
 
   template<typename T>
   struct ProgramUniformValue : public std::map<GLuint, std::map<GLint, T> >
index 282f7a4..e398236 100644 (file)
@@ -176,7 +176,6 @@ std::ostream& operator<<(std::ostream& o, const Graphics::FramebufferCreateInfo&
   return o;
 }
 
-
 int GetNumComponents(Graphics::VertexInputFormat vertexFormat)
 {
   switch(vertexFormat)
@@ -385,7 +384,6 @@ GLenum GetBlendOp(Graphics::BlendOp blendOp)
   return op;
 }
 
-
 class TestGraphicsMemory : public Graphics::Memory
 {
 public:
@@ -453,7 +451,6 @@ TestGraphicsController::TestGraphicsController()
   trace.EnableLogging(true);
 }
 
-
 void TestGraphicsController::SubmitCommandBuffers(const Graphics::SubmitInfo& submitInfo)
 {
   TraceCallStack::NamedParams namedParams;
@@ -693,10 +690,10 @@ void TestGraphicsController::ProcessCommandBuffer(TestGraphicsCommandBuffer& com
             {
               // Test scissor area and RT size
               const auto& area = cmd.data.beginRenderPass.renderArea;
-              if( area.x == 0 &&
-              area.y == 0 &&
-              area.width == renderTarget->mCreateInfo.extent.width &&
-              area.height == renderTarget->mCreateInfo.extent.height )
+              if(area.x == 0 &&
+                 area.y == 0 &&
+                 area.width == renderTarget->mCreateInfo.extent.width &&
+                 area.height == renderTarget->mCreateInfo.extent.height)
               {
                 mGl.Disable(GL_SCISSOR_TEST);
                 mGl.Clear(mask);
@@ -704,8 +701,7 @@ void TestGraphicsController::ProcessCommandBuffer(TestGraphicsCommandBuffer& com
               else
               {
                 mGl.Enable(GL_SCISSOR_TEST);
-                mGl.Scissor(cmd.data.beginRenderPass.renderArea.x, cmd.data.beginRenderPass.renderArea.y,
-                            cmd.data.beginRenderPass.renderArea.width, cmd.data.beginRenderPass.renderArea.height);
+                mGl.Scissor(cmd.data.beginRenderPass.renderArea.x, cmd.data.beginRenderPass.renderArea.y, cmd.data.beginRenderPass.renderArea.width, cmd.data.beginRenderPass.renderArea.height);
                 mGl.Clear(mask);
                 mGl.Disable(GL_SCISSOR_TEST);
               }
@@ -784,6 +780,9 @@ void TestGraphicsController::BindPipeline(TestGraphicsPipeline* pipeline)
   {
     mGl.Disable(GL_BLEND);
   }
+
+  auto* program = static_cast<const TestGraphicsProgram*>(pipeline->programState.program);
+  mGl.UseProgram(program->mImpl->mId);
 }
 
 /**