Hello everyone. Need your help, because I'm already out of ideas.
While rendering my 3D scene, I'm getting the following error within my logging system:
OpenGL error in 'glDrawElements ( GL_TRIANGLES, numIndices, GL_UNSIGNED_INT, 0 )' - 'Mesh.cpp:27' - invalid operation
Where Mesh.cpp:27 is the call to glDrawElements:
void Mesh::Draw() {
GL_CHECK ( glBindVertexArray ( vao ) );
GL_CHECK ( glDrawElements ( GL_TRIANGLES, numIndices, GL_UNSIGNED_INT, 0 ) );
GL_CHECK ( glBindVertexArray ( 0 ) );
}
GL_CHECK is a macro for digging all the OpenGL errors ( if any ).
VAO, VBO and IBO are created like that:
void Mesh::PopulateBuffers () {
// --- create buffers
if ( vao )
GL_CHECK ( glDeleteVertexArrays ( 1, &vao ) );
if ( vbo )
GL_CHECK ( glDeleteBuffers ( 1, &vbo ) );
if ( ibo )
GL_CHECK ( glDeleteBuffers ( 1, & ibo ) );
GL_CHECK ( glGenVertexArrays ( 1, &vao ) );
GL_CHECK ( glBindVertexArray ( vao ) );
GL_CHECK ( glGenBuffers ( 1, &vbo ) );
GL_CHECK ( glGenBuffers ( 1, &ibo ) );
// --- layout setup BEGIN
GL_CHECK ( glEnableVertexAttribArray ( 0 ) ); // vertices
GL_CHECK ( glEnableVertexAttribArray ( 1 ) ); // texture coords
GL_CHECK ( glEnableVertexAttribArray ( 2 ) ); // normals
GL_CHECK ( glEnableVertexAttribArray ( 3 ) ); // tangents
GL_CHECK ( glEnableVertexAttribArray ( 4 ) ); // bitangents
// --- layout setup END
GL_CHECK ( glBindBuffer ( GL_ARRAY_BUFFER, vbo ) );
GL_CHECK ( glVertexAttribPointer ( 0, 3, GL_FLOAT, GL_FALSE,
VERTEX_ELEMENTS_COUNT * sizeof ( float ), 0 ) ); // vert coords
GL_CHECK ( glVertexAttribPointer ( 1, 2, GL_FLOAT, GL_FALSE,
VERTEX_ELEMENTS_COUNT * sizeof ( float ), ( GLvoid* ) ( 3 * sizeof ( float ) ) ) ); // tex coords
GL_CHECK ( glVertexAttribPointer ( 2, 3, GL_FLOAT, GL_FALSE,
VERTEX_ELEMENTS_COUNT * sizeof ( float ), ( GLvoid* ) ( ( 3 + 2 ) * sizeof ( float ) ) ) ); // normals
GL_CHECK ( glVertexAttribPointer ( 3, 3, GL_FLOAT, GL_FALSE,
VERTEX_ELEMENTS_COUNT * sizeof ( float ), ( GLvoid* ) ( ( 3 + 2 + 3 ) * sizeof ( float ) ) ) ); // tangents
GL_CHECK ( glVertexAttribPointer ( 4, 3, GL_FLOAT, GL_FALSE,
VERTEX_ELEMENTS_COUNT * sizeof ( float ), ( GLvoid* ) ( ( 3 + 2 + 3 + 3 ) * sizeof ( float ) ) ) ); // bitangents
// ---- populate buffer with vertices
GL_CHECK ( glBufferData ( GL_ARRAY_BUFFER,
core::VERTEX_ELEMENTS_COUNT * vertices.size() * sizeof ( float ),
&bufferData[ 0 ],
GL_STATIC_DRAW ) );
// ---- populate another buffer with indices
GL_CHECK ( glBindBuffer ( GL_ELEMENT_ARRAY_BUFFER, ibo ) );
GL_CHECK ( glBufferData ( GL_ELEMENT_ARRAY_BUFFER,
indices.size() * sizeof ( GLuint ),
&indices[ 0 ],
GL_STATIC_DRAW ) );
// ---- unbind VAO
GL_CHECK ( glBindVertexArray ( 0 ) );
// ---- recalculate box
RecalcAABB();
}
I'm working with 3.3 core profile, all shaders are OK ( as for it could be one of the reasons for such errors ).
Must mention that everything is being rendered just fine, but in the same time I'm getting the storm of errors, and each one is pointing to the code above ( the glDrawElements call ).
Could anybody help? Or should I just ignore these error messages ?