From f844cb9df34956739dc3a8f404b3394a80ae0366 Mon Sep 17 00:00:00 2001 From: Xiangyin Ma Date: Thu, 12 May 2016 13:53:17 +0100 Subject: [PATCH] Added static function Geometry::QUAD() Change-Id: I4091191b45c3516adf9967aa2dbd9405a380fca2 --- .../src/dali-devel/utc-Dali-Geometry.cpp | 50 +++++++++++++++++++--- dali/devel-api/rendering/geometry.cpp | 21 +++++++++ dali/devel-api/rendering/geometry.h | 10 +++++ 3 files changed, 75 insertions(+), 6 deletions(-) diff --git a/automated-tests/src/dali-devel/utc-Dali-Geometry.cpp b/automated-tests/src/dali-devel/utc-Dali-Geometry.cpp index 978e38e..edd6e4c 100644 --- a/automated-tests/src/dali-devel/utc-Dali-Geometry.cpp +++ b/automated-tests/src/dali-devel/utc-Dali-Geometry.cpp @@ -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; +} + diff --git a/dali/devel-api/rendering/geometry.cpp b/dali/devel-api/rendering/geometry.cpp index 1e504d0..2f648e1 100644 --- a/dali/devel-api/rendering/geometry.cpp +++ b/dali/devel-api/rendering/geometry.cpp @@ -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 ) { diff --git a/dali/devel-api/rendering/geometry.h b/dali/devel-api/rendering/geometry.h index 9b00dc9..8f6264e 100644 --- a/dali/devel-api/rendering/geometry.h +++ b/dali/devel-api/rendering/geometry.h @@ -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 -- 2.7.4