Fixes an issue when element buffer count is 0 in render-geometry. 92/68592/8
authorAdam Bialogonski <adam.b@samsung.com>
Fri, 6 May 2016 16:29:43 +0000 (17:29 +0100)
committerFerran Sole <ferran.sole@samsung.com>
Mon, 9 May 2016 15:07:20 +0000 (16:07 +0100)
- elementBufferCount = 0 states for whole or remaining buffer from elementBufferOffset.

Added two test cases covering that issue ( going out of bounds of the index buffer andusing 0 as number of elements )

Change-Id: I5d29401a3c2d717d173ce63a9cc9ba3b2ecb0e64

automated-tests/src/dali-devel/utc-Dali-Renderer.cpp
dali/internal/render/renderers/render-geometry.cpp
dali/internal/render/renderers/render-geometry.h

index 6059540..7c93806 100644 (file)
@@ -1860,6 +1860,28 @@ int UtcDaliRendererSetIndexRange(void)
     DALI_TEST_CHECK( result );
   }
 
+  // Index out of bounds
+  {
+    renderer.SetIndexRange( 15, 30 );
+    geometry.SetGeometryType( Geometry::LINE_STRIP );
+    sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
+    application.SendNotification();
+    application.Render();
+    bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
+    DALI_TEST_CHECK( result );
+  }
+
+  // drawing whole buffer starting from 15 ( last valid primitive )
+  {
+    renderer.SetIndexRange( 15, 0 );
+    geometry.SetGeometryType( Geometry::LINE_STRIP );
+    sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
+    application.SendNotification();
+    application.Render();
+    bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
+    DALI_TEST_CHECK( result );
+  }
+
   END_TEST;
 }
 
index e151493..803b6eb 100644 (file)
@@ -157,24 +157,26 @@ void Geometry::UploadAndDraw(
     base += mVertexBuffers[i]->EnableVertexAttributes( context, attributeLocation, base );
   }
 
-  GLenum geometryGLType(0);
-  unsigned int numIndices(0u);
+  size_t numIndices(0u);
   intptr_t firstIndexOffset(0u);
   if( mIndexBuffer )
   {
     numIndices = mIndices.Size();
 
-    if( elementBufferOffset )
+    if( elementBufferOffset != 0u )
     {
-      elementBufferOffset = elementBufferOffset >= numIndices ? numIndices- 1 : elementBufferOffset;
+      elementBufferOffset = elementBufferOffset >= numIndices ? numIndices - 1 : elementBufferOffset;
       firstIndexOffset = elementBufferOffset * sizeof(GLushort);
+      numIndices -= elementBufferOffset;
     }
-    if ( elementBufferCount )
+
+    if( elementBufferCount != 0u )
     {
-      numIndices = std::min( elementBufferCount, numIndices - elementBufferOffset );
+      numIndices = std::min( elementBufferCount, numIndices );
     }
   }
 
+  GLenum geometryGLType(GL_NONE);
   switch(mGeometryType)
   {
     case Dali::Geometry::TRIANGLES:
@@ -212,11 +214,6 @@ void Geometry::UploadAndDraw(
       geometryGLType = GL_LINE_STRIP;
       break;
     }
-    default:
-    {
-      DALI_ASSERT_ALWAYS( 0 && "Geometry type not supported (yet)" );
-      break;
-    }
   }
 
   //Draw call
index 90f06af..a46f0ca 100644 (file)
@@ -123,7 +123,7 @@ public:
    * @param[in] bufferIndex The current buffer index
    * @param[in] attributeLocation The location for the attributes in the shader
    * @param[in] elementBufferOffset The index of first element to draw if index buffer bound
-   * @param[in] elementBufferCount Number of elements to draw if index buffer bound
+   * @param[in] elementBufferCount Number of elements to draw if index buffer bound, uses whole buffer when 0
    */
   void UploadAndDraw(Context& context,
                      BufferIndex bufferIndex,