Updated test harness to match dali-core : CullFace/Blend 84/253484/2
authorDavid Steele <david.steele@samsung.com>
Thu, 11 Feb 2021 11:13:37 +0000 (11:13 +0000)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Mon, 15 Feb 2021 17:36:06 +0000 (17:36 +0000)
Change-Id: Ia6806c94a51b0f81f485d0b12f9ca8f0452f2de8

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
automated-tests/src/dali-toolkit/utc-Dali-ImageVisual.cpp
automated-tests/src/dali-toolkit/utc-Dali-TransitionData.cpp
automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp

index b414084..5679a01 100644 (file)
@@ -407,10 +407,10 @@ public:
   inline void CullFace(GLenum mode) override
   {
     std::stringstream out;
-    out << mode;
+    out << std::hex << mode;
 
     TraceCallStack::NamedParams namedParams;
-    namedParams["program"] << mode;
+    namedParams["mode"] << std::hex << mode;
 
     mCullFaceTrace.PushCall("CullFace", out.str(), namedParams);
   }
@@ -498,7 +498,7 @@ public:
   inline void DepthFunc(GLenum func) override
   {
     std::stringstream out;
-    out << func;
+    out << std::hex << func;
 
     TraceCallStack::NamedParams namedParams;
     namedParams["func"] << std::hex << func;
@@ -533,7 +533,7 @@ public:
   inline void Disable(GLenum cap) override
   {
     std::stringstream out;
-    out << cap;
+    out << std::hex << cap;
     TraceCallStack::NamedParams namedParams;
     namedParams["cap"] << std::hex << cap;
     mEnableDisableTrace.PushCall("Disable", out.str(), namedParams);
@@ -576,7 +576,7 @@ public:
   inline void Enable(GLenum cap) override
   {
     std::stringstream out;
-    out << cap;
+    out << std::hex << cap;
     TraceCallStack::NamedParams namedParams;
     namedParams["cap"] << std::hex << cap;
     mEnableDisableTrace.PushCall("Enable", out.str(), namedParams);
@@ -631,6 +631,7 @@ public:
 
   inline void FrontFace(GLenum mode) override
   {
+    // do nothing
   }
 
   inline void GenBuffers(GLsizei n, GLuint* buffers) override
index 578285b..a8357c1 100644 (file)
@@ -318,6 +318,125 @@ GLenum GetTopology(Graphics::PrimitiveTopology topology)
   return GL_TRIANGLES;
 }
 
+GLenum GetCullFace(Graphics::CullMode cullMode)
+{
+  switch(cullMode)
+  {
+    case Graphics::CullMode::NONE:
+      return GL_NONE;
+    case Graphics::CullMode::FRONT:
+      return GL_FRONT;
+    case Graphics::CullMode::BACK:
+      return GL_BACK;
+    case Graphics::CullMode::FRONT_AND_BACK:
+      return GL_FRONT_AND_BACK;
+  }
+  return GL_NONE;
+}
+
+GLenum GetFrontFace(Graphics::FrontFace frontFace)
+{
+  if(frontFace == Graphics::FrontFace::CLOCKWISE)
+  {
+    return GL_CW;
+  }
+  return GL_CCW;
+}
+
+GLenum GetBlendFactor(Graphics::BlendFactor blendFactor)
+{
+  GLenum glFactor = GL_ZERO;
+
+  switch(blendFactor)
+  {
+    case Graphics::BlendFactor::ZERO:
+      glFactor = GL_ZERO;
+      break;
+    case Graphics::BlendFactor::ONE:
+      glFactor = GL_ONE;
+      break;
+    case Graphics::BlendFactor::SRC_COLOR:
+      glFactor = GL_SRC_COLOR;
+      break;
+    case Graphics::BlendFactor::ONE_MINUS_SRC_COLOR:
+      glFactor = GL_ONE_MINUS_SRC_COLOR;
+      break;
+    case Graphics::BlendFactor::DST_COLOR:
+      glFactor = GL_DST_COLOR;
+      break;
+    case Graphics::BlendFactor::ONE_MINUS_DST_COLOR:
+      glFactor = GL_ONE_MINUS_DST_COLOR;
+      break;
+    case Graphics::BlendFactor::SRC_ALPHA:
+      glFactor = GL_SRC_ALPHA;
+      break;
+    case Graphics::BlendFactor::ONE_MINUS_SRC_ALPHA:
+      glFactor = GL_ONE_MINUS_SRC_ALPHA;
+      break;
+    case Graphics::BlendFactor::DST_ALPHA:
+      glFactor = GL_DST_ALPHA;
+      break;
+    case Graphics::BlendFactor::ONE_MINUS_DST_ALPHA:
+      glFactor = GL_ONE_MINUS_DST_ALPHA;
+      break;
+    case Graphics::BlendFactor::CONSTANT_COLOR:
+      glFactor = GL_CONSTANT_COLOR;
+      break;
+    case Graphics::BlendFactor::ONE_MINUS_CONSTANT_COLOR:
+      glFactor = GL_ONE_MINUS_CONSTANT_COLOR;
+      break;
+    case Graphics::BlendFactor::CONSTANT_ALPHA:
+      glFactor = GL_CONSTANT_ALPHA;
+      break;
+    case Graphics::BlendFactor::ONE_MINUS_CONSTANT_ALPHA:
+      glFactor = GL_ONE_MINUS_CONSTANT_ALPHA;
+      break;
+    case Graphics::BlendFactor::SRC_ALPHA_SATURATE:
+      glFactor = GL_SRC_ALPHA_SATURATE;
+      break;
+      // GLES doesn't appear to have dual source blending.
+    case Graphics::BlendFactor::SRC1_COLOR:
+      glFactor = GL_SRC_COLOR;
+      break;
+    case Graphics::BlendFactor::ONE_MINUS_SRC1_COLOR:
+      glFactor = GL_ONE_MINUS_SRC_COLOR;
+      break;
+    case Graphics::BlendFactor::SRC1_ALPHA:
+      glFactor = GL_SRC_ALPHA;
+      break;
+    case Graphics::BlendFactor::ONE_MINUS_SRC1_ALPHA:
+      glFactor = GL_ONE_MINUS_SRC_ALPHA;
+      break;
+  }
+  return glFactor;
+}
+
+GLenum GetBlendOp(Graphics::BlendOp blendOp)
+{
+  GLenum op = GL_FUNC_ADD;
+  switch(blendOp)
+  {
+    case Graphics::BlendOp::ADD:
+      op = GL_FUNC_ADD;
+      break;
+    case Graphics::BlendOp::SUBTRACT:
+      op = GL_FUNC_SUBTRACT;
+      break;
+    case Graphics::BlendOp::REVERSE_SUBTRACT:
+      op = GL_FUNC_REVERSE_SUBTRACT;
+      break;
+    case Graphics::BlendOp::MIN:
+      op = GL_MIN;
+      break;
+    case Graphics::BlendOp::MAX:
+      op = GL_MAX;
+      break;
+
+      // @todo Add advanced blend equations
+  }
+  return op;
+}
+
 void TestGraphicsController::SubmitCommandBuffers(const Graphics::SubmitInfo& submitInfo)
 {
   TraceCallStack::NamedParams namedParams;
@@ -381,6 +500,50 @@ void TestGraphicsController::SubmitCommandBuffers(const Graphics::SubmitInfo& su
                               reinterpret_cast<void*>(attributeOffset));
     }
 
+    // Cull face setup
+    auto& rasterizationState = commandBuffer->mPipeline->rasterizationState;
+    if(rasterizationState.cullMode == Graphics::CullMode::NONE)
+    {
+      mGl.Disable(GL_CULL_FACE);
+    }
+    else
+    {
+      mGl.Enable(GL_CULL_FACE);
+      mGl.CullFace(GetCullFace(rasterizationState.cullMode));
+    }
+
+    mGl.FrontFace(GetFrontFace(rasterizationState.frontFace));
+    // We don't modify glPolygonMode in our context/abstraction from GL_FILL (the GL default),
+    // so it isn't present in the API (and won't have any tests!)
+
+    // Blending setup
+    auto& colorBlendState = commandBuffer->mPipeline->colorBlendState;
+    if(colorBlendState.blendEnable)
+    {
+      mGl.Enable(GL_BLEND);
+
+      mGl.BlendFuncSeparate(GetBlendFactor(colorBlendState.srcColorBlendFactor),
+                            GetBlendFactor(colorBlendState.dstColorBlendFactor),
+                            GetBlendFactor(colorBlendState.srcAlphaBlendFactor),
+                            GetBlendFactor(colorBlendState.dstAlphaBlendFactor));
+      if(colorBlendState.colorBlendOp != colorBlendState.alphaBlendOp)
+      {
+        mGl.BlendEquationSeparate(GetBlendOp(colorBlendState.colorBlendOp), GetBlendOp(colorBlendState.alphaBlendOp));
+      }
+      else
+      {
+        mGl.BlendEquation(GetBlendOp(colorBlendState.colorBlendOp));
+      }
+      mGl.BlendColor(colorBlendState.blendConstants[0],
+                     colorBlendState.blendConstants[1],
+                     colorBlendState.blendConstants[2],
+                     colorBlendState.blendConstants[3]);
+    }
+    else
+    {
+      mGl.Disable(GL_BLEND);
+    }
+
     // draw call
     auto topology = commandBuffer->mPipeline->inputAssemblyState.topology;
 
index ce1a022..4ffeeef 100644 (file)
@@ -784,7 +784,7 @@ int UtcDaliImageVisualAnimateMixColor(void)
   glAbstraction.EnableEnableDisableCallTrace( true );
   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
   std::ostringstream blendStr;
-  blendStr << GL_BLEND;
+  blendStr << std::hex << GL_BLEND;
 
   application.SendNotification();
   application.Render(0); // Ensure animation starts
@@ -795,7 +795,7 @@ int UtcDaliImageVisualAnimateMixColor(void)
   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>( "uColor", Vector4( 0.5f, 0.5f, 0.5f, 0.75f ) ), true, TEST_LOCATION );
   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>( "mixColor", testColor ), true, TEST_LOCATION );
 
-  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
 
   glEnableStack.Reset();
 
@@ -808,7 +808,7 @@ int UtcDaliImageVisualAnimateMixColor(void)
   // GL_BLEND should not be changed: Keep enabled
   // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
 //  DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
-  DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Disable", blendStr.str().c_str() ) );
+  DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
 
   TestMixColor( visual, Visual::Property::MIX_COLOR, TARGET_MIX_COLOR );
 
@@ -845,12 +845,12 @@ int UtcDaliImageVisualAnimateOpacity(void)
   glAbstraction.EnableEnableDisableCallTrace( true );
   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
   std::ostringstream blendStr;
-  blendStr << GL_BLEND;
+  blendStr << std::hex << GL_BLEND;
 
   application.SendNotification();
   application.Render();
 
-  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str()) );
 
   {
     tet_infoline( "Test that the opacity can be increased to full via animation, and that the blend mode is set appropriately at the start and end of the animation." );
@@ -888,7 +888,7 @@ int UtcDaliImageVisualAnimateOpacity(void)
 
     // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
 //    DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
-    DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Disable", blendStr.str().c_str() ) );
+    DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
   }
 
 
@@ -920,7 +920,7 @@ int UtcDaliImageVisualAnimateOpacity(void)
     DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
     DALI_TEST_EQUALS( color.a, 0.55f, TEST_LOCATION );
 
-    DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+    DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
 
     glEnableStack.Reset();
 
@@ -931,9 +931,10 @@ int UtcDaliImageVisualAnimateOpacity(void)
     DALI_TEST_EQUALS( color.a, 0.1f, TEST_LOCATION );
 
     // GL_BLEND should not be changed: Keep enabled
-    // TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
-//    DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
-    DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Disable", blendStr.str().c_str() ) );
+// @todo
+// TODO: Temporarily commented out the line below when caching is disabled. Will need to add it back.
+//    DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
+    DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
   }
 
   END_TEST;
@@ -1006,14 +1007,14 @@ int UtcDaliImageVisualAnimateOpacity02(void)
   glAbstraction.EnableEnableDisableCallTrace( true );
   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
   std::ostringstream blendStr;
-  blendStr << GL_BLEND;
+  blendStr << std::hex << GL_BLEND;
 
   application.SendNotification();
   application.Render(0);     // Ensure animation starts
   application.Render(2000u); // Halfway point through animation
   application.SendNotification(); // Handle any signals
 
-  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
 
   Vector4 color;
   DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
@@ -1027,7 +1028,7 @@ int UtcDaliImageVisualAnimateOpacity02(void)
   DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue< Vector4 >( "uColor", color ) );
   DALI_TEST_EQUALS( color.a, 1.0f, TEST_LOCATION );
 
-  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Disable", blendStr.str().c_str() ) );
+  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
 
   END_TEST;
 }
@@ -2368,8 +2369,8 @@ int UtcDaliImageVisualCustomShader(void)
 
   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
   std::ostringstream blendStr;
-  blendStr << GL_BLEND;
-  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+  blendStr << std::hex << GL_BLEND;
+  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
 
   END_TEST;
 }
index a68ac7a..439098f 100644 (file)
@@ -592,7 +592,7 @@ int UtcDaliTransitionDataMap5P(void)
   glAbstraction.EnableEnableDisableCallTrace( true );
   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
   std::ostringstream blendStr;
-  blendStr << GL_BLEND;
+  blendStr << std::hex << GL_BLEND;
 
   Renderer renderer = actor.GetRendererAt(0);
   Property::Index mixColorIndex = renderer.GetPropertyIndex( ColorVisual::Property::MIX_COLOR );
@@ -606,8 +606,8 @@ int UtcDaliTransitionDataMap5P(void)
   DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 0.0f, 0.001f, TEST_LOCATION );
 
   // The Renderer is transparent. So rendering is skipped. The state should not be changed.
-  DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
-  DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Disable", blendStr.str().c_str() ) );
+  DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
+  DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
 
   anim.Play();
 
@@ -621,7 +621,7 @@ int UtcDaliTransitionDataMap5P(void)
   DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 0.5f, 0.001f, TEST_LOCATION );
 
   // Should not be changed
-  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
 
   glEnableStack.Reset();
 
@@ -631,7 +631,7 @@ int UtcDaliTransitionDataMap5P(void)
   DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION );
   DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION );
 
-  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Disable", blendStr.str().c_str() ) );
+  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
 
   END_TEST;
 }
@@ -682,7 +682,7 @@ int UtcDaliTransitionDataMap6P(void)
   glAbstraction.EnableEnableDisableCallTrace( true );
   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
   std::ostringstream blendStr;
-  blendStr << GL_BLEND;
+  blendStr << std::hex << GL_BLEND;
 
   application.SendNotification();
   application.Render(0);
@@ -693,7 +693,7 @@ int UtcDaliTransitionDataMap6P(void)
   DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 1.0f, 0.001f, TEST_LOCATION );
 
   // Default state is disabled. So test if "Enabled" is not called.
-  DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+  DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
 
   anim.Play();
 
@@ -707,7 +707,7 @@ int UtcDaliTransitionDataMap6P(void)
   DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector3 >( mixColorIndex ), Vector3(Color::MAGENTA), TEST_LOCATION);
   DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 0.5f, 0.001f, TEST_LOCATION );
 
-  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
 
   glEnableStack.Reset();
 
@@ -718,7 +718,7 @@ int UtcDaliTransitionDataMap6P(void)
   DALI_TEST_EQUALS( renderer.GetCurrentProperty< float >( DevelRenderer::Property::OPACITY ), 0.0f, 0.001f, TEST_LOCATION );
 
   // GL_BLEND should not be changed: Keep enabled
-  DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Disable", blendStr.str().c_str() ) );
+  DALI_TEST_CHECK( !glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
 
   END_TEST;
 }
index fbf3438..0f5f410 100644 (file)
@@ -1972,7 +1972,7 @@ int UtcDaliVisualAnimatePrimitiveVisual(void)
     glAbstraction.EnableEnableDisableCallTrace( true );
     TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
     std::ostringstream blendStr;
-    blendStr << GL_BLEND;
+    blendStr << std::hex << GL_BLEND;
 
     application.SendNotification();
     application.Render(0);
@@ -1983,7 +1983,7 @@ int UtcDaliVisualAnimatePrimitiveVisual(void)
     DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, halfwayColor.a )), true, TEST_LOCATION );
     DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(halfwayColor) ), true, TEST_LOCATION );
 
-    DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+    DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str() ) );
 
     glEnableStack.Reset();
 
@@ -1994,7 +1994,7 @@ int UtcDaliVisualAnimatePrimitiveVisual(void)
     DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4( 1.0f, 1.0f, 1.0f, TARGET_MIX_COLOR.a ) ), true, TEST_LOCATION );
     DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(TARGET_MIX_COLOR) ), true, TEST_LOCATION );
 
-    DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Disable", blendStr.str().c_str() ) );
+    DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Disable", blendStr.str() ) );
 
     actor.Unparent();
   }