//============================== // OvrDebugLinesLocal::InitVBO void OvrDebugLinesLocal::InitVBO( GlGeometry & geo, LineVertex_t * vertices, const int maxVerts, LineIndex_t * indices, const int maxIndices ) { const int numVertexBytes = maxVerts * sizeof( LineVertex_t ); // create vertex array object glGenVertexArraysOES_( 1, &geo.vertexArrayObject ); glBindVertexArrayOES_( geo.vertexArrayObject ); // create the vertex buffer glGenBuffers( 1, &geo.vertexBuffer ); glBindBuffer( GL_ARRAY_BUFFER, geo.vertexBuffer ); glBufferData( GL_ARRAY_BUFFER, numVertexBytes, (void*)vertices, GL_DYNAMIC_DRAW ); glEnableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_POSITION ); // x, y and z glVertexAttribPointer( VERTEX_ATTRIBUTE_LOCATION_POSITION, 3, GL_FLOAT, false, sizeof( LineVertex_t ), (void*)0 ); glEnableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_COLOR ); // color glVertexAttribPointer( VERTEX_ATTRIBUTE_LOCATION_COLOR, 4, GL_FLOAT, true, sizeof( LineVertex_t ), (void*)12 ); const int numIndexBytes = maxIndices * sizeof( LineIndex_t ); glGenBuffers( 1, &geo.indexBuffer ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, geo.indexBuffer ); glBufferData( GL_ELEMENT_ARRAY_BUFFER, numIndexBytes, (void*)indices, GL_STATIC_DRAW ); geo.indexCount = 0; // nothing to render right now }
void WarpGeometry_CreateQuad( WarpGeometry * geometry ) { struct vertices_t { float positions[4][3]; float uvs[4][2]; float colors[4][4]; } vertices = { { { -1, -1, 0 }, { -1, 1, 0 }, { 1, -1, 0 }, { 1, 1, 0 } }, { { 0, 1 }, { 1, 1 }, { 0, 0 }, { 1, 0 } }, { { 1, 1, 1, 0 }, { 1, 1, 1, 0 }, { 1, 1, 1, 0 }, { 1, 1, 1, 0 } } }; unsigned short indices[6] = { 0, 1, 2, 2, 1, 3 }; geometry->vertexCount = 4; geometry->indexCount = 6; glGenVertexArraysOES_( 1, &geometry->vertexArrayObject ); glBindVertexArrayOES_( geometry->vertexArrayObject ); glGenBuffers( 1, &geometry->vertexBuffer ); glBindBuffer( GL_ARRAY_BUFFER, geometry->vertexBuffer ); glBufferData( GL_ARRAY_BUFFER, sizeof( vertices ), &vertices, GL_STATIC_DRAW ); glGenBuffers( 1, &geometry->indexBuffer ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, geometry->indexBuffer ); glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof( indices ), indices, GL_STATIC_DRAW ); glEnableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_POSITION ); glVertexAttribPointer( VERTEX_ATTRIBUTE_LOCATION_POSITION, 3, GL_FLOAT, false, sizeof( vertices.positions[0] ), (const GLvoid *)offsetof( vertices_t, positions ) ); glEnableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_UV0 ); glVertexAttribPointer( VERTEX_ATTRIBUTE_LOCATION_UV0, 2, GL_FLOAT, false, sizeof( vertices.uvs[0] ), (const GLvoid *)offsetof( vertices_t, uvs ) ); glEnableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_COLOR ); glVertexAttribPointer( VERTEX_ATTRIBUTE_LOCATION_COLOR, 4, GL_FLOAT, false, sizeof( vertices.colors[0] ), (const GLvoid *)offsetof( vertices_t, colors ) ); glBindVertexArrayOES_( 0 ); }
void GlGeometry::Create( const VertexAttribs & attribs, const Array< TriangleIndex > & indices ) { vertexCount = attribs.position.GetSizeI(); indexCount = indices.GetSizeI(); glGenBuffers( 1, &vertexBuffer ); glGenBuffers( 1, &indexBuffer ); glGenVertexArraysOES_( 1, &vertexArrayObject ); glBindVertexArrayOES_( vertexArrayObject ); glBindBuffer( GL_ARRAY_BUFFER, vertexBuffer ); Array< uint8_t > packed; PackVertexAttribute( packed, attribs.position, VERTEX_ATTRIBUTE_LOCATION_POSITION, GL_FLOAT, 3 ); PackVertexAttribute( packed, attribs.normal, VERTEX_ATTRIBUTE_LOCATION_NORMAL, GL_FLOAT, 3 ); PackVertexAttribute( packed, attribs.tangent, VERTEX_ATTRIBUTE_LOCATION_TANGENT, GL_FLOAT, 3 ); PackVertexAttribute( packed, attribs.binormal, VERTEX_ATTRIBUTE_LOCATION_BINORMAL, GL_FLOAT, 3 ); PackVertexAttribute( packed, attribs.color, VERTEX_ATTRIBUTE_LOCATION_COLOR, GL_FLOAT, 4 ); PackVertexAttribute( packed, attribs.uv0, VERTEX_ATTRIBUTE_LOCATION_UV0, GL_FLOAT, 2 ); PackVertexAttribute( packed, attribs.uv1, VERTEX_ATTRIBUTE_LOCATION_UV1, GL_FLOAT, 2 ); PackVertexAttribute( packed, attribs.jointIndices, VERTEX_ATTRIBUTE_LOCATION_JOINT_INDICES, GL_INT, 4 ); PackVertexAttribute( packed, attribs.jointWeights, VERTEX_ATTRIBUTE_LOCATION_JOINT_WEIGHTS, GL_FLOAT, 4 ); glBufferData( GL_ARRAY_BUFFER, packed.GetSize() * sizeof( packed[0] ), packed.GetDataPtr(), GL_STATIC_DRAW ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, indexBuffer ); glBufferData( GL_ELEMENT_ARRAY_BUFFER, indices.GetSizeI() * sizeof( indices[0] ), indices.GetDataPtr(), GL_STATIC_DRAW ); glBindVertexArrayOES_( 0 ); glDisableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_POSITION ); glDisableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_NORMAL ); glDisableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_TANGENT ); glDisableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_BINORMAL ); glDisableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_COLOR ); glDisableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_UV0 ); glDisableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_UV1 ); glDisableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_JOINT_INDICES ); glDisableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_JOINT_WEIGHTS ); }
//============================== // BitmapFontSurfaceLocal::Init // Initializes the surface VBO void BitmapFontSurfaceLocal::Init( const int maxVertices ) { assert( Geo.vertexBuffer == 0 && Geo.indexBuffer == 0 && Geo.vertexArrayObject == 0 ); assert( Vertices == NULL ); if ( Vertices != NULL ) { delete [] Vertices; Vertices = NULL; } assert( maxVertices % 4 == 0 ); MaxVertices = maxVertices; MaxIndices = ( maxVertices / 4 ) * 6; Vertices = new fontVertex_t[ maxVertices ]; const int vertexByteCount = maxVertices * sizeof( fontVertex_t ); // font VAO glGenVertexArraysOES_( 1, &Geo.vertexArrayObject ); glBindVertexArrayOES_( Geo.vertexArrayObject ); // vertex buffer glGenBuffers( 1, &Geo.vertexBuffer ); glBindBuffer( GL_ARRAY_BUFFER, Geo.vertexBuffer ); glBufferData( GL_ARRAY_BUFFER, vertexByteCount, (void*)Vertices, GL_DYNAMIC_DRAW ); glEnableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_POSITION ); // x, y and z glVertexAttribPointer( VERTEX_ATTRIBUTE_LOCATION_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof( fontVertex_t ), (void*)0 ); glEnableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_UV0 ); // s and t glVertexAttribPointer( VERTEX_ATTRIBUTE_LOCATION_UV0, 2, GL_FLOAT, GL_FALSE, sizeof( fontVertex_t ), (void*)offsetof( fontVertex_t, s ) ); glEnableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_COLOR ); // color glVertexAttribPointer( VERTEX_ATTRIBUTE_LOCATION_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof( fontVertex_t ), (void*)offsetof( fontVertex_t, rgba ) ); glDisableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_UV1 ); glEnableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_FONT_PARMS ); // outline parms glVertexAttribPointer( VERTEX_ATTRIBUTE_LOCATION_FONT_PARMS, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof( fontVertex_t ), (void*)offsetof( fontVertex_t, fontParms ) ); fontIndex_t * indices = new fontIndex_t[ MaxIndices ]; const int indexByteCount = MaxIndices * sizeof( fontIndex_t ); // indices never change int numQuads = MaxIndices / 6; int v = 0; for ( int i = 0; i < numQuads; i++ ) { indices[i * 6 + 0] = v + 2; indices[i * 6 + 1] = v + 1; indices[i * 6 + 2] = v + 0; indices[i * 6 + 3] = v + 3; indices[i * 6 + 4] = v + 2; indices[i * 6 + 5] = v + 0; v += 4; } glGenBuffers( 1, &Geo.indexBuffer ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, Geo.indexBuffer ); glBufferData( GL_ELEMENT_ARRAY_BUFFER, indexByteCount, (void*)indices, GL_STATIC_DRAW ); Geo.indexCount = 0; // if there's anything to render this will be modified glBindVertexArrayOES_( 0 ); delete [] indices; CurVertex = 0; CurIndex = 0; LOG( "BitmapFontSurfaceLocal::Init: success" ); }
void Geometry_MakeVertexArrayObject( SGeometry *geometry ) { uint index; GLuint vertexArrayObject; GLuint vertexBuffer; GLuint indexBuffer; uint vertexCount; uint positionSize; uint texCoordSize; uint positionOffset; uint texCoordOffset; uint colorOffset; index = geometry->updateIndex % BUFFER_COUNT; vertexBuffer = geometry->vertexBuffers[index]; indexBuffer = geometry->indexBuffers[index]; assert( vertexBuffer ); assert( indexBuffer ); OVR::GL_CheckErrors( "before Geometry_MakeVertexArrayObject" ); vertexArrayObject = geometry->vertexArrayObjects[index]; if ( !vertexArrayObject ) glGenVertexArraysOES_( 1, &vertexArrayObject ); glBindVertexArrayOES_( vertexArrayObject ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, indexBuffer ); glBindBuffer( GL_ARRAY_BUFFER, vertexBuffer ); glEnableVertexAttribArray( VERTEX_ATTRIBUTE_POSITION ); glEnableVertexAttribArray( VERTEX_ATTRIBUTE_TEXCOORD ); glEnableVertexAttribArray( VERTEX_ATTRIBUTE_COLOR ); vertexCount = geometry->vertexCount; positionSize = sizeof( float ) * 3 * vertexCount; texCoordSize = sizeof( float ) * 2 * vertexCount; positionOffset = 0; texCoordOffset = positionOffset + positionSize; colorOffset = texCoordOffset + texCoordSize; glVertexAttribPointer( VERTEX_ATTRIBUTE_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof( float ) * 3, (void *)( positionOffset ) ); glVertexAttribPointer( VERTEX_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, sizeof( float ) * 2, (void *)( texCoordOffset ) ); glVertexAttribPointer( VERTEX_ATTRIBUTE_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof( byte ) * 4, (void *)( colorOffset ) ); glBindVertexArrayOES_( 0 ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 ); glBindBuffer( GL_ARRAY_BUFFER, 0 ); glDisableVertexAttribArray( VERTEX_ATTRIBUTE_POSITION ); glDisableVertexAttribArray( VERTEX_ATTRIBUTE_TEXCOORD ); glDisableVertexAttribArray( VERTEX_ATTRIBUTE_COLOR ); geometry->vertexArrayObjects[index] = vertexArrayObject; OVR::GL_CheckErrors( "after Geometry_MakeVertexArrayObject" ); }