Henlo,
I honestly still have no clue how to make it work, there is nothing too intuitive about it and I've tried a ton of combinations.
For instance, instead of doing this (generating VBO once and storing)
glGenBuffers( 1, &m_VBO.points );
glBindBuffer( GL_ARRAY_BUFFER, m_VBO.points );
glBufferData( GL_ARRAY_BUFFER, points.size()*sizeof(points[0]), points.data(), GL_STATIC_DRAW );
glGenBuffers( 1, &m_VBO.texcoords );
glBindBuffer( GL_ARRAY_BUFFER, m_VBO.texcoords );
glBufferData( GL_ARRAY_BUFFER, texcoords.size()*sizeof(texcoords[0]), texcoords.data(), GL_STATIC_DRAW );
glGenBuffers( 1, &m_VBO.indexes );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_VBO.indexes );
glBufferData( GL_ELEMENT_ARRAY_BUFFER, indexes.size()*sizeof(indexes[0]), indexes.data(), GL_STATIC_DRAW );
glGenBuffers( 1, &m_VBO.normals );
glBindBuffer( GL_ARRAY_BUFFER, m_VBO.normals );
glBufferData( GL_ARRAY_BUFFER, normals.size()*sizeof(normals[0]), normals.data(), GL_STATIC_DRAW );
... and then calling on EACH DRAW this:
void Model::generate_VAO()
{
#if 1
glGenVertexArrays( 1, &m_VAO );
glBindVertexArray( m_VAO );
glBindBuffer( GL_ARRAY_BUFFER, m_VBO.points );
glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, NULL );
glBindBuffer( GL_ARRAY_BUFFER, m_VBO.texcoords );
glVertexAttribPointer( 1, 2, GL_FLOAT, GL_FALSE, 0, NULL );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_VBO.indexes );
glVertexAttribPointer( 2, 1, GL_BYTE, GL_FALSE, 0, NULL );
glBindBuffer( GL_ARRAY_BUFFER, m_VBO.normals );
glVertexAttribPointer( 3, 3, GL_FLOAT, GL_FALSE, 0, NULL );
/// points and texture coords have to match the layout (location = x) in the shader
/// programms, i.e. if the index for points is 0, it will be passed to the shader for
/// the location = 0
enable_ArrayAttrib();
#endif
}
... and right after drawing deleting the VAO or it piles up in the mem:
void Model::delete_VAO()
{
glDeleteVertexArrays(1, &m_VAO);
}
... all of which works fine but surely has some performance penalty, I'm trying to use the new API and doing one or another variation of the code below, which is creating all at once, only once (which is the intended result), and then trying to just bind VAO before drawing.
(I'm assuming bindingindex
-- where I'm passing model_count -- would do the trick of separating the different model's VAOs, but does it? Is it supposed to do this? What is wrong there? I get errors)
void foo()
{
static int model_count;
glGenBuffers( 1, &m_VBO.points );
glBindBuffer( GL_ARRAY_BUFFER, m_VBO.points );
glBufferData( GL_ARRAY_BUFFER, points.size()*sizeof(points[0]), points.data(), GL_STATIC_DRAW );
glGenBuffers( 1, &m_VBO.texcoords );
glBindBuffer( GL_ARRAY_BUFFER, m_VBO.texcoords );
glBufferData( GL_ARRAY_BUFFER, texcoords.size()*sizeof(texcoords[0]), texcoords.data(), GL_STATIC_DRAW );
glGenBuffers( 1, &m_VBO.indexes );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_VBO.indexes );
glBufferData( GL_ELEMENT_ARRAY_BUFFER, indexes.size()*sizeof(indexes[0]), indexes.data(), GL_STATIC_DRAW );
glGenBuffers( 1, &m_VBO.normals );
glBindBuffer( GL_ARRAY_BUFFER, m_VBO.normals );
glBufferData( GL_ARRAY_BUFFER, normals.size()*sizeof(normals[0]), normals.data(), GL_STATIC_DRAW );
#if 1
glGenVertexArrays( 1, &m_VAO );
glBindVertexArray( m_VAO );
glVertexArrayVertexBuffer(m_VAO, model_count, m_VBO.points, 0, points.size()*sizeof(points[0]));
glEnableVertexAttribArray(0);
glVertexAttribFormat(0, 3, GL_FLOAT, GL_FALSE, 0);
glVertexAttribBinding(0, model_count);
glVertexArrayVertexBuffer(m_VAO, model_count, m_VBO.texcoords, 0, texcoords.size()*sizeof(texcoords[0]));
glEnableVertexAttribArray(1);
glVertexAttribFormat(1, 2, GL_FLOAT, GL_FALSE, 0);
glVertexAttribBinding(1, model_count);
glVertexArrayVertexBuffer(m_VAO, model_count, m_VBO.indexes, 0, indexes.size()*sizeof(indexes[0]));
glEnableVertexAttribArray(2);
glVertexAttribFormat(2, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0);
glVertexAttribBinding(2, model_count);
glVertexArrayVertexBuffer(m_VAO, model_count, m_VBO.normals, 0, normals.size()*sizeof(normals[0]));
glEnableVertexAttribArray(3);
glVertexAttribFormat(3, 3, GL_FLOAT, GL_FALSE, 0);
glVertexAttribBinding(3, model_count);
++model_count;
#endif
}
Would you be so kind as to provide some code example?
Help :)