Revert "Move new mesh API to devel-api"
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-geometry.cpp
index c5b7ec6..4713775 100644 (file)
@@ -69,15 +69,12 @@ void RenderGeometry::UploadAndDraw(
     mIndexBuffer->BindBuffer( context, program );
   }
 
-//  BindBuffers( context, bufferIndex, program );
-//  EnableVertexAttributes( context, bufferIndex, program );
   Draw( context, bufferIndex, dataProviders );
 
   for( unsigned int i = 0; i < mVertexBuffers.Count(); ++i )
   {
     mVertexBuffers[i]->DisableVertexAttributes( context, bufferIndex, program );
   }
-  //DisableVertexAttributes( context, bufferIndex, program );
 }
 
 void RenderGeometry::GeometryUpdated()
@@ -90,15 +87,24 @@ void RenderGeometry::UploadVertexData(
   BufferIndex bufferIndex,
   const RenderDataProvider* dataProviders )
 {
-  if( mDataNeedsUploading ) // @todo Or if any of the property buffers are dirty
+  if( mDataNeedsUploading )
   {
-    DoUpload( context, bufferIndex, dataProviders );
+    SetUpPropertyBuffers( context, bufferIndex, dataProviders );
+
+    for( unsigned int i = 0; i < mVertexBuffers.Count(); ++i )
+    {
+      mVertexBuffers[i]->Upload( context, bufferIndex );
+    }
+    if( mIndexBuffer )
+    {
+      mIndexBuffer->Upload( context, bufferIndex );
+    }
 
     mDataNeedsUploading = false;
   }
 }
 
-void RenderGeometry::DoUpload(
+void RenderGeometry::SetUpPropertyBuffers(
   Context& context,
   BufferIndex bufferIndex,
   const RenderDataProvider* dataProvider )
@@ -112,9 +118,10 @@ void RenderGeometry::DoUpload(
   {
     const PropertyBufferDataProvider* vertexBuffer = vertexBuffers[i];
 
-    RenderPropertyBuffer* propertyBuffer = new RenderPropertyBuffer( *vertexBuffer, false );
-
-    propertyBuffer->DoUpload( context, bufferIndex );
+    RenderPropertyBuffer* propertyBuffer = new RenderPropertyBuffer(
+      *vertexBuffer,
+      GpuBuffer::ARRAY_BUFFER,
+      GpuBuffer::STATIC_DRAW ); // TODO: MESH_REWORK: change this for animated meshes
 
     mVertexBuffers.PushBack( propertyBuffer );
   }
@@ -123,9 +130,10 @@ void RenderGeometry::DoUpload(
   const PropertyBufferDataProvider* indexBuffer = dataProvider->GetIndexBuffer();
   if( indexBuffer )
   {
-    mIndexBuffer = new RenderPropertyBuffer( *indexBuffer, true );
-
-    mIndexBuffer->DoUpload( context, bufferIndex );
+    mIndexBuffer = new RenderPropertyBuffer(
+      *indexBuffer,
+      GpuBuffer::ELEMENT_ARRAY_BUFFER,
+      GpuBuffer::STATIC_DRAW ); // TODO: MESH_REWORK: change this for animated meshes
   }
 }
 
@@ -172,25 +180,42 @@ void RenderGeometry::Draw( Context& context, BufferIndex bufferIndex, const Rend
   unsigned int numIndices = 0;
   if( indexBuffer )
   {
-    numIndices = /* TODO: MESH_REWORK remove this 2, should implement unsigned short properties  */ 2 * indexBuffer->GetDataSize(bufferIndex) / indexBuffer->GetElementSize(bufferIndex);
+    numIndices = indexBuffer->GetDataSize(bufferIndex) / indexBuffer->GetElementSize(bufferIndex);
   }
 
   switch(type)
   {
     case Dali::Geometry::TRIANGLES:
     {
-      context.DrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, 0);
+      if( numIndices )
+      {
+        context.DrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, 0);
+      }
+      else
+      {
+        const PropertyBufferDataProvider* firstVertexBuffer = dataProvider->GetVertexBuffers()[0];
+        unsigned int numVertices = firstVertexBuffer->GetElementCount( bufferIndex );
+        context.DrawArrays( GL_TRIANGLES, 0, numVertices );
+      }
       break;
     }
     case Dali::Geometry::LINES:
     {
-      context.DrawElements(GL_LINES, numIndices, GL_UNSIGNED_SHORT, 0);
+      if( numIndices )
+      {
+        context.DrawElements(GL_LINES, numIndices, GL_UNSIGNED_SHORT, 0);
+      }
+      else
+      {
+        const PropertyBufferDataProvider* firstVertexBuffer = dataProvider->GetVertexBuffers()[0];
+        unsigned int numVertices = firstVertexBuffer->GetElementCount( bufferIndex );
+        context.DrawArrays( GL_LINES, 0, numVertices );
+      }
       break;
     }
     case Dali::Geometry::POINTS:
     {
       const PropertyBufferDataProvider* firstVertexBuffer = dataProvider->GetVertexBuffers()[0];
-
       unsigned int numVertices = firstVertexBuffer->GetElementCount( bufferIndex );
       context.DrawArrays(GL_POINTS, 0, numVertices );
       break;