Hi
I have been trying to get VAO’s to work with my engine using 4.1 compatability context on nvidia 270.61 drivers.
It seems to run ok except that I get 1282 invalid operation
inside my draw method when I try to bind the VAO.
Other than that it renders it ok. Could someone please have a quick look at my code to see if I got something wrong?
void Terrain::GenVAO(std::shared_ptr<TILE>tile)
{
//VBOs//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Generate VBOs
glGenBuffers(2, tile->VBOIBO);
//Vertex buffer
glBindBuffer(GL_ARRAY_BUFFER, tile->VBOIBO[0]);
glBufferData(GL_ARRAY_BUFFER, tile->Vertices.size() * sizeof(VortexVertex), &tile->Vertices[0].pos.x, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
//Index buffer
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tile->VBOIBO[1]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, tile->Indices.size() * sizeof(unsigned int), &tile->Indices[0], GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//tile->Vertices.clear(); //Why cant I uncommend this? I dont understand why the buffer needs to store its own memory + point to my own memory
//tile->Indices.clear();
//VAOs//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Generate VAOs
glGenVertexArrays(1, &tile->VAO);
glBindVertexArray(tile->VAO);
glBindBuffer(GL_ARRAY_BUFFER, tile->VBOIBO[0]);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(VortexVertex), BUFFER_OFFSET(0));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tile->VBOIBO[1]);
glBindVertexArray(0);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
void Terrain::Draw(std::shared_ptr<TILE>tile)
{
glBindVertexArray(tile->VAO);
glDrawElements(GL_TRIANGLES, tile->Indices.size(), GL_UNSIGNED_INT, BUFFER_OFFSET(0));
glBindVertexArray(0);
}