Hello
Here is the code I use to setup the VAO shown in the above code. (Code is posted as is).
glGenVertexArrays( 1, &details_.vertexArrayObject );
[b]
// The resource freeing assumes we correctly pass this point, so
// test that this assumption is upheld here:
if( details_.vertexArrayObject != 0 )
{
glGenBuffers( 2, buffers_ );
// Create the IBO, 16 bit indices
details_.indicesCount = geom->index_count();
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, buffers_[0] );
glBufferData( GL_ELEMENT_ARRAY_BUFFER, details_.indicesCount * sizeof(GLushort), geom->indices(), GL_STATIC_DRAW );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
// Create VBO
const GLsizeiptr vertexSize = geom->vertex_count() * 3 * sizeof(GLfloat);
const GLsizeiptr texCoordSize = geom->vertex_count() * 2 * sizeof(GLfloat);
const GLsizeiptr bufferSize = texCoordSize + vertexSize;
const GLsizei instanceDataBlockStride = sizeof(modelinstancedata);
const size_t rowSize = sizeof(float) * 4;
glBindBuffer( GL_ARRAY_BUFFER, buffers_[1] );
glBufferData( GL_ARRAY_BUFFER, bufferSize, nullptr, GL_STATIC_DRAW );
glBufferSubData( GL_ARRAY_BUFFER, 0, vertexSize, geom->vertices() );
glBufferSubData( GL_ARRAY_BUFFER, vertexSize, texCoordSize, texs->texture_coords() );
glBindBuffer( GL_ARRAY_BUFFER, 0 );
// VAO for the model
glBindVertexArray( details_.vertexArrayObject );
// Bind the IBO for the VAO
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, buffers_[0] );
// Bind the VBO and setup pointers for the VAO
glBindBuffer( GL_ARRAY_BUFFER, buffers_[1] );
glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) );
glVertexAttribPointer( 1, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(vertexSize) );
// Bind the VBO for the incoming instance data:
glBindBuffer( GL_ARRAY_BUFFER, [b]instanceMatrixVBO[/b] ); << This is the VBO being updated in the code shown in my 1st post...
// First matrix:
glVertexAttribPointer( 2, 4, GL_FLOAT, GL_FALSE, instanceDataBlockStride, BUFFER_OFFSET(0) );
glVertexAttribPointer( 3, 4, GL_FLOAT, GL_FALSE, instanceDataBlockStride, BUFFER_OFFSET(rowSize * 1) );
glVertexAttribPointer( 4, 4, GL_FLOAT, GL_FALSE, instanceDataBlockStride, BUFFER_OFFSET(rowSize * 2) );
glVertexAttribPointer( 5, 4, GL_FLOAT, GL_FALSE, instanceDataBlockStride, BUFFER_OFFSET(rowSize * 3) );
// Team colour:
glVertexAttribPointer( 6, 4, GL_UNSIGNED_BYTE, GL_TRUE, instanceDataBlockStride, BUFFER_OFFSET(rowSize * 4) );
// Finished with this models VAO:
glBindVertexArray( 0 );
glBindBuffer( GL_ARRAY_BUFFER, 0 );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
[/b]
This is the setup for the VAO, one per model, for use in instance rendering. The matrices are passed in via a VBO shared by one or more VAOs. The VBO is created beforehand like this:
glGenBuffers( 1, &instanceMatrixVBO_ );
glBindBuffer( GL_ARRAY_BUFFER, instanceMatrixVBO_ );
glBufferData( GL_ARRAY_BUFFER, MAX_INSTANCES_PER_BATCH * sizeof(modelinstancedata), nullptr, GL_STREAM_DRAW );
glBindBuffer( GL_ARRAY_BUFFER, 0 );
Thanks for your time and input, its really appreciated.
At no time during the running does OpenGL generate any errors. I am very frequently checking for this.
Also, I tested the above suggestion to reorder the calls, it does not fix my issue.