[FONT=Courier New]=========
Pseudocode
Loadshader ()
SetShaderUniforms();
for (each object in scene)
{
SetShaderModelView();
if (objectNotInCache)
{
glGenVertexArrays( 1, &vao );
glBindVertexArray( vao );
glGenBuffers (1, &bufferID)
glBindBuffer (GL_ARRAY_BUFFER, bufferID);
// Set up buffers for drawing facets. I know interleaved will be faster but want to get
// a simpler buffer layout working first.
glBufferData( GL_ARRAY_BUFFER,
vertexbuffersize + normalbuffersize,
NULL, GL_STATIC_DRAW );
glBufferSubData( GL_ARRAY_BUFFER,
0, vertexBufferSize(), pVertices);
glBufferSubData( GL_ARRAY_BUFFER,
vertexbuffersize , normalbuffersize, pNormals);
// vPosition & vNormal are the shader variables for vertex position & normal
// the positions are retrieved up where I load the shader. I know this is working bcs the
// program works when I use a single buffer or use only one geometry and thus one buffer
glEnableVertexAttribArray( vPosition );
glEnableVertexAttribArray( vNormal );
// set up the vertex arrays for drawing facets
glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0,
BUFFER_OFFSET(0) );
glVertexAttribPointer( vNormal, 3, GL_FLOAT, GL_FALSE, 0,
BUFFER_OFFSET(vertexbuffersize) );
cacheVaoAndBuffer (vao, bufferID);
}
else
{
getVaoAndBufferfromCache (&vao, &bufferID);
glBindVertexArray( vao );
glBindBuffer (GL_ARRAY_BUFFER, bufferID);
// I supect I don't need the following 4 calls but ended up putting them in
// a vain attempt to get some output.
glEnableVertexAttribArray( vPosition );
glEnableVertexAttribArray( vNormal );
glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0,
BUFFER_OFFSET(0) );
glVertexAttribPointer( vNormal, 3, GL_FLOAT, GL_FALSE, 0,
BUFFER_OFFSET(vertexbuffersize) );
}
glDrawArrays( GL_TRIANGLES, 0, vertexCount);
}[/FONT]