Added possibility of adding multiple vertices to VBO_ITEM at once

This commit is contained in:
Maciej Suminski 2013-05-13 11:14:35 +02:00
parent bce9f685ea
commit 32784ea191
3 changed files with 43 additions and 25 deletions

View File

@ -651,28 +651,16 @@ void OPENGL_GAL::DrawSegment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndP
VECTOR2D v3( aEndPoint.x - ( aWidth * cos( beta ) / 2.0 ),
aEndPoint.y + ( aWidth * sin( beta ) / 2.0 ) );
// First triangle
GLfloat newVertex1[] = { v0.x, v0.y, layerDepth,
strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a };
GLfloat newVertex2[] = { v1.x, v1.y, layerDepth,
strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a };
GLfloat newVertex3[] = { v2.x, v2.y, layerDepth,
strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a };
// Second triangle
GLfloat newVertex4[] = { v0.x, v0.y, layerDepth,
strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a };
GLfloat newVertex5[] = { v2.x, v2.y, layerDepth,
strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a };
GLfloat newVertex6[] = { v3.x, v3.y, layerDepth,
strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a };
curVboItem->PushVertex( newVertex1 );
curVboItem->PushVertex( newVertex2 );
curVboItem->PushVertex( newVertex3 );
curVboItem->PushVertex( newVertex4 );
curVboItem->PushVertex( newVertex5 );
curVboItem->PushVertex( newVertex6 );
// Two triangles
GLfloat newVertices[] = {
v0.x, v0.y, layerDepth, strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a,
v1.x, v1.y, layerDepth, strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a,
v2.x, v2.y, layerDepth, strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a,
v0.x, v0.y, layerDepth, strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a,
v2.x, v2.y, layerDepth, strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a,
v3.x, v3.y, layerDepth, strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a
};
curVboItem->PushVertices( newVertices, 6 );
}
if( isFillEnabled )

View File

@ -61,7 +61,7 @@ void VBO_ITEM::PushVertex( const GLfloat* aVertex )
if( m_vertices )
{
// Copy all previous vertices data
memcpy( newVertices, m_vertices, ( m_size ) * VertSize );
memcpy( newVertices, m_vertices, m_size * VertSize );
delete m_vertices;
}
m_vertices = newVertices;
@ -73,7 +73,7 @@ void VBO_ITEM::PushVertex( const GLfloat* aVertex )
if( m_indices )
{
// Copy all previous vertices data
memcpy( newIndices, m_indices, ( m_size ) * IndSize );
memcpy( newIndices, m_indices, m_size * IndSize );
delete m_indices;
}
m_indices = newIndices;
@ -88,7 +88,36 @@ void VBO_ITEM::PushVertex( const GLfloat* aVertex )
void VBO_ITEM::PushVertices( const GLfloat* aVertex, GLuint aSize )
{
// FIXME to be done
int newSize = m_size + aSize;
GLfloat* newVertices = new GLfloat[newSize * VertStride];
GLuint* newIndices = new GLuint[newSize * IndStride];
// Handle new vertices
if( m_vertices )
{
// Copy all previous vertices data
memcpy( newVertices, m_vertices, ( m_size ) * VertSize );
delete m_vertices;
}
m_vertices = newVertices;
// Add the new vertex
memcpy( &newVertices[m_size * VertStride], aVertex, aSize * VertSize );
// Handle new indices
if( m_indices )
{
// Copy all previous vertices data
memcpy( newIndices, m_indices, ( m_size ) * IndSize );
delete m_indices;
}
m_indices = newIndices;
// Add the new vertex
for( int i = m_size; i < newSize; ++i )
m_indices[i] = m_offset + i;
m_size += aSize;
m_isDirty = true;
}

View File

@ -96,6 +96,7 @@ private:
///< Packed by 7 floats for each vertex: {X, Y, Z, R, G, B, A}
GLfloat* m_vertices;
///< Indices of vertices
GLuint* m_indices;
///< Offset and size of data in VBO.