Added static function Geometry::QUAD() 08/69308/3
authorXiangyin Ma <x1.ma@samsung.com>
Thu, 12 May 2016 12:53:17 +0000 (13:53 +0100)
committerXiangyin Ma <x1.ma@samsung.com>
Fri, 13 May 2016 15:20:08 +0000 (16:20 +0100)
Change-Id: I4091191b45c3516adf9967aa2dbd9405a380fca2

automated-tests/src/dali-devel/utc-Dali-Geometry.cpp
dali/devel-api/rendering/geometry.cpp
dali/devel-api/rendering/geometry.h

index 978e38e..edd6e4c 100644 (file)
@@ -396,7 +396,7 @@ int UtcDaliGeometrySetGetGeometryType01(void)
   application.SendNotification();
   drawTrace.Enable( false );
 
-  // geometry type is set as GL_POINTS
+  // geometry type is set as GL_TRIANGLE_STRIP
   // no index buffer, call glDrawArrays,
   DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawArrays" ), 2, TEST_LOCATION);
   out.str("");
@@ -417,7 +417,7 @@ int UtcDaliGeometrySetGetGeometryType01(void)
   application.SendNotification();
   drawTrace.Enable( false );
 
-  // geometry type is set as GL_POINTS
+  // geometry type is set as GL_TRIANGLE_FAN
   // no index buffer, call glDrawArrays,
   DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawArrays" ), 2, TEST_LOCATION);
   out.str("");
@@ -456,7 +456,7 @@ int UtcDaliGeometrySetGetGeometryType02(void)
   TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
 
   /****************************************************/
-  // Default (TRIANGLES), no index buffer
+  // Default (TRIANGLES), with index buffer
   drawTrace.Reset();
   drawTrace.Enable(true);
   application.SendNotification();
@@ -474,7 +474,7 @@ int UtcDaliGeometrySetGetGeometryType02(void)
   DALI_TEST_EQUALS( geometry.GetGeometryType(), Geometry::TRIANGLES, TEST_LOCATION);
 
   /*********************************************************/
-  // LINES, no index buffer
+  // LINES, with index buffer
   geometry.SetGeometryType( Geometry::LINES );
 
   drawTrace.Reset();
@@ -526,7 +526,7 @@ int UtcDaliGeometrySetGetGeometryType02(void)
   application.SendNotification();
   drawTrace.Enable( false );
 
-  // geometry type is set as GL_POINTS
+  // geometry type is set as GL_TRIANGLE_STRIP
   DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawElements" ), 2, TEST_LOCATION);
   out.str("");
   out << GL_TRIANGLE_STRIP << ", " << numIndex << ", " << GL_UNSIGNED_SHORT<<", "<<"indices";
@@ -546,7 +546,7 @@ int UtcDaliGeometrySetGetGeometryType02(void)
   application.SendNotification();
   drawTrace.Enable( false );
 
-  // geometry type is set as GL_POINTS
+  // geometry type is set as GL_TRIANGLE_FAN
   DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawElements" ), 2, TEST_LOCATION);
   out.str("");
   out << GL_TRIANGLE_FAN << ", " << numIndex << ", " << GL_UNSIGNED_SHORT<<", "<<"indices";
@@ -557,3 +557,41 @@ int UtcDaliGeometrySetGetGeometryType02(void)
   END_TEST;
 }
 
+int UtcDaliGeometryQUAD(void)
+{
+  TestApplication application;
+
+  tet_infoline("Test Geometry::QUAD()");
+
+  Geometry geometry = Geometry::QUAD();
+  Shader shader = CreateShader();
+  Renderer renderer = Renderer::New(geometry, shader);
+  Actor actor = Actor::New();
+  actor.SetSize(Vector3::ONE * 100.f);
+  actor.AddRenderer(renderer);
+  Stage::GetCurrent().Add(actor);
+
+  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+  TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
+
+  drawTrace.Reset();
+  drawTrace.Enable(true);
+  application.SendNotification();
+  application.Render(0);
+  application.Render();
+  application.SendNotification();
+  drawTrace.Enable( false );
+
+  // geometry type is set as GL_TRIANGLE_STRIP, no index buffer
+  // no index buffer, call glDrawArrays,
+  DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawArrays" ), 2, TEST_LOCATION);
+  std::stringstream out;
+  int numVertex = 4;
+  out << GL_TRIANGLE_STRIP << ", " << 0 << ", " << numVertex;
+  DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawArrays", out.str()), true, TEST_LOCATION);
+
+  DALI_TEST_EQUALS( geometry.GetGeometryType(), Geometry::TRIANGLE_STRIP, TEST_LOCATION);
+
+  END_TEST;
+}
+
index 1e504d0..2f648e1 100644 (file)
@@ -85,6 +85,27 @@ Geometry::GeometryType Geometry::GetGeometryType() const
   return GetImplementation(*this).GetGeometryType();
 }
 
+Geometry Geometry::QUAD()
+{
+  Dali::Property::Map quadVertexFormat;
+  quadVertexFormat["aPosition"] = Dali::Property::VECTOR2;
+  Dali::PropertyBuffer vertexData = Dali::PropertyBuffer::New( quadVertexFormat );
+
+  const float halfQuadSize = .5f;
+  struct QuadVertex { Dali::Vector2 position; };
+  QuadVertex quadVertexData[4] = {
+      { Dali::Vector2(-halfQuadSize, -halfQuadSize) },
+      { Dali::Vector2(-halfQuadSize, halfQuadSize) },
+      { Dali::Vector2( halfQuadSize, -halfQuadSize) },
+      { Dali::Vector2( halfQuadSize, halfQuadSize) } };
+  vertexData.SetData(quadVertexData, 4);
+
+  Dali::Geometry quad = Dali::Geometry::New();
+  quad.AddVertexBuffer( vertexData );
+  quad.SetGeometryType( Dali::Geometry::TRIANGLE_STRIP );
+  return quad;
+}
+
 Geometry::Geometry( Internal::Geometry* pointer )
 : BaseHandle( pointer )
 {
index 9b00dc9..8f6264e 100644 (file)
@@ -146,6 +146,16 @@ public:
    */
   GeometryType GetGeometryType() const;
 
+  /**
+   * @brief Unit quad geometry.
+   *
+   * The quad has its four corners located at [-0.5, -0.5], [-0.5, 0.5], [0.5, -0.5] and [0.5, 0.5].
+   * The attribute name for vertex position is 'aPosition'.
+   *
+   * @return The quad geometry.
+   */
+  static Geometry QUAD();
+
 public:
   /**
    * @brief The constructor