From 38afb3c669aff3fdb7fef9ffca6f68355f867fe5 Mon Sep 17 00:00:00 2001 From: Xiangyin Ma Date: Fri, 2 Oct 2015 15:15:19 +0100 Subject: [PATCH] (Geometry) Allow to set index buffer when using triangle strip/fan Change-Id: I969530bca9df4bc22a474f26cd3d8f53e8513f26 --- .../src/dali-devel/utc-Dali-Geometry.cpp | 172 ++++++++++++++++++++- dali/internal/render/renderers/render-geometry.cpp | 26 +++- 2 files changed, 190 insertions(+), 8 deletions(-) diff --git a/automated-tests/src/dali-devel/utc-Dali-Geometry.cpp b/automated-tests/src/dali-devel/utc-Dali-Geometry.cpp index 7933b06..7c32d69 100644 --- a/automated-tests/src/dali-devel/utc-Dali-Geometry.cpp +++ b/automated-tests/src/dali-devel/utc-Dali-Geometry.cpp @@ -311,11 +311,11 @@ int UtcDaliGeometrySetIndexBuffer(void) END_TEST; } -int UtcDaliGeometrySetGetGeometryType(void) +int UtcDaliGeometrySetGetGeometryType01(void) { TestApplication application; - tet_infoline("Test SetGeometryType and GetGeometryType"); + tet_infoline("Test SetGeometryType and GetGeometryType: without index buffer"); unsigned int numVertex = 4u; PropertyBuffer vertexBuffer = CreateVertexBuffer("aPosition", "aTexCoord" ); @@ -394,9 +394,177 @@ int UtcDaliGeometrySetGetGeometryType(void) DALI_TEST_EQUALS( geometry.GetGeometryType(), Geometry::POINTS, TEST_LOCATION); + /*****************************************************/ + //TRIANGLE_STRIP, no index buffer + geometry.SetGeometryType( Geometry::TRIANGLE_STRIP ); + + drawTrace.Reset(); + drawTrace.Enable(true); + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + drawTrace.Enable( false ); + + // geometry type is set as GL_POINTS + // no index buffer, call glDrawArrays, + DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawArrays" ), 2, TEST_LOCATION); + out.str(""); + 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); + + /*****************************************************/ + //TRIANGLE_FAN, no index buffer + geometry.SetGeometryType( Geometry::TRIANGLE_FAN ); + + drawTrace.Reset(); + drawTrace.Enable(true); + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + drawTrace.Enable( false ); + + // geometry type is set as GL_POINTS + // no index buffer, call glDrawArrays, + DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawArrays" ), 2, TEST_LOCATION); + out.str(""); + out << GL_TRIANGLE_FAN << ", " << 0 << ", " << numVertex; + DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawArrays", out.str()), true, TEST_LOCATION); + + DALI_TEST_EQUALS( geometry.GetGeometryType(), Geometry::TRIANGLE_FAN, TEST_LOCATION); + END_TEST; } +int UtcDaliGeometrySetGetGeometryType02(void) +{ + TestApplication application; + + tet_infoline("Test SetGeometryType and GetGeometryType: with index buffer"); + + unsigned int numVertex = 4u; + unsigned int numIndex = 3u; // 6 unsigned short + PropertyBuffer vertexBuffer = CreateVertexBuffer("aPosition", "aTexCoord" ); + PropertyBuffer indexBuffer = CreateIndexBuffer( ); + + Geometry geometry = Geometry::New(); + geometry.AddVertexBuffer( vertexBuffer ); + geometry.SetIndexBuffer( indexBuffer ); + + Material material = CreateMaterial(1.f); + Renderer renderer = Renderer::New(geometry, material); + 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(); + + /****************************************************/ + // Default (TRIANGLES), no index buffer + drawTrace.Reset(); + drawTrace.Enable(true); + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + drawTrace.Enable( false ); + + // Test the default geometry type is GL_TRIANGLE + DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawElements" ), 2, TEST_LOCATION); + std::stringstream out; + out << GL_TRIANGLES << ", " << numIndex << ", " << GL_UNSIGNED_SHORT<<", "<<"indices"; + DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawElements", out.str()), true, TEST_LOCATION); + + DALI_TEST_EQUALS( geometry.GetGeometryType(), Geometry::TRIANGLES, TEST_LOCATION); + + /*********************************************************/ + // LINES, no index buffer + geometry.SetGeometryType( Geometry::LINES ); + + drawTrace.Reset(); + drawTrace.Enable(true); + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + drawTrace.Enable( false ); + + // geometry type is set as GL_LINES + DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawElements" ), 2, TEST_LOCATION); + out.str(""); + out << GL_LINES << ", " << numIndex << ", " << GL_UNSIGNED_SHORT<<", "<<"indices"; + DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawElements", out.str()), true, TEST_LOCATION); + + DALI_TEST_EQUALS( geometry.GetGeometryType(), Geometry::LINES, TEST_LOCATION); + + /*****************************************************/ + //POINTS + geometry.SetGeometryType( Geometry::POINTS ); + + drawTrace.Reset(); + drawTrace.Enable(true); + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + drawTrace.Enable( false ); + + // geometry type is set as GL_POINTS + // As Points does not use the index buffer, call glDrawArrays, + DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawArrays" ), 2, TEST_LOCATION); + out.str(""); + out << GL_POINTS << ", " << 0 << ", " << numVertex; + DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawArrays", out.str()), true, TEST_LOCATION); + + DALI_TEST_EQUALS( geometry.GetGeometryType(), Geometry::POINTS, TEST_LOCATION); + + /*****************************************************/ + //TRIANGLE_STRIP + geometry.SetGeometryType( Geometry::TRIANGLE_STRIP ); + + drawTrace.Reset(); + drawTrace.Enable(true); + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + drawTrace.Enable( false ); + + // geometry type is set as GL_POINTS + DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawElements" ), 2, TEST_LOCATION); + out.str(""); + out << GL_TRIANGLE_STRIP << ", " << numIndex << ", " << GL_UNSIGNED_SHORT<<", "<<"indices"; + DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawElements", out.str()), true, TEST_LOCATION); + + DALI_TEST_EQUALS( geometry.GetGeometryType(), Geometry::TRIANGLE_STRIP, TEST_LOCATION); + + /*****************************************************/ + //TRIANGLE_FAN + geometry.SetGeometryType( Geometry::TRIANGLE_FAN ); + + drawTrace.Reset(); + drawTrace.Enable(true); + application.SendNotification(); + application.Render(0); + application.Render(); + application.SendNotification(); + drawTrace.Enable( false ); + + // geometry type is set as GL_POINTS + DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawElements" ), 2, TEST_LOCATION); + out.str(""); + out << GL_TRIANGLE_FAN << ", " << numIndex << ", " << GL_UNSIGNED_SHORT<<", "<<"indices"; + DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawElements", out.str()), true, TEST_LOCATION); + + DALI_TEST_EQUALS( geometry.GetGeometryType(), Geometry::TRIANGLE_FAN, TEST_LOCATION); + + END_TEST; +} int UtcDaliGeometrySetGetRequireDepthTesting(void) { TestApplication application; diff --git a/dali/internal/render/renderers/render-geometry.cpp b/dali/internal/render/renderers/render-geometry.cpp index 5675db0..77ca794 100644 --- a/dali/internal/render/renderers/render-geometry.cpp +++ b/dali/internal/render/renderers/render-geometry.cpp @@ -196,16 +196,30 @@ void RenderGeometry::UploadAndDraw( } case Dali::Geometry::TRIANGLE_STRIP: { - const PropertyBufferDataProvider& firstVertexBuffer = mVertexBuffers[0]->GetDataProvider(); - unsigned int numVertices = firstVertexBuffer.GetElementCount( bufferIndex ); - context.DrawArrays(GL_TRIANGLE_STRIP, 0, numVertices ); + if( numIndices ) + { + context.DrawElements(GL_TRIANGLE_STRIP, numIndices, GL_UNSIGNED_SHORT, 0); + } + else + { + const PropertyBufferDataProvider& firstVertexBuffer = mVertexBuffers[0]->GetDataProvider(); + unsigned int numVertices = firstVertexBuffer.GetElementCount( bufferIndex ); + context.DrawArrays(GL_TRIANGLE_STRIP, 0, numVertices ); + } break; } case Dali::Geometry::TRIANGLE_FAN: { - const PropertyBufferDataProvider& firstVertexBuffer = mVertexBuffers[0]->GetDataProvider(); - unsigned int numVertices = firstVertexBuffer.GetElementCount( bufferIndex ); - context.DrawArrays(GL_TRIANGLE_FAN, 0, numVertices ); + if( numIndices ) + { + context.DrawElements(GL_TRIANGLE_FAN, numIndices, GL_UNSIGNED_SHORT, 0); + } + else + { + const PropertyBufferDataProvider& firstVertexBuffer = mVertexBuffers[0]->GetDataProvider(); + unsigned int numVertices = firstVertexBuffer.GetElementCount( bufferIndex ); + context.DrawArrays(GL_TRIANGLE_FAN, 0, numVertices ); + } break; } default: -- 2.7.4