Something is slightly confusing me about some of my rendering code. My understanding is that a VAO retains all of the glVertexAttribPointer and glEnableVertexAttribArray calls so that when it comes time to render I don't have to explicitly do that again but my program crashes if I don't repeat those calls every draw. Otherwise the program runs fine.
Here is where I set up the VAO initially:
void Render_Engine::Generate_VAOs(){
std::cout << "Generating a vao" << std::endl;
glGenVertexArrays(1, &position_color_vao);
glBindVertexArray(position_color_vao);
uint8_t position_color_vertex_stride = (3 * sizeof(GLfloat)) + (4 * sizeof(GLfloat)) + (3 * sizeof(GLfloat));
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, position_color_vertex_stride, (GLvoid*)0);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, position_color_vertex_stride, (GLvoid*)(3 * sizeof(GLfloat)));
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, position_color_vertex_stride, (GLvoid*)(7 * sizeof(GLfloat)));
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glBindVertexArray(0);
}
And here is my rendering call for each mesh:
Shader* shader = mesh->Get_Shader();
shader->Bind();
glBindVertexArray(position_color_vao);
glBindBuffer(GL_ARRAY_BUFFER, vbos[mesh]);
glUniformMatrix4fv(shader->Get_Model_Transform_Location(), 1, GL_FALSE, glm::value_ptr(parent_transformation.transformation));
glUniformMatrix4fv(shader->Get_View_Transform_Location(), 1, GL_FALSE, glm::value_ptr(view_mat));
glUniformMatrix4fv(shader->Get_Projection_Transform_Location(), 1, GL_FALSE, glm::value_ptr(projection));
uint8_t position_color_vertex_stride = (3 * sizeof(GLfloat)) + (4 * sizeof(GLfloat)) + (3 * sizeof(GLfloat));
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, position_color_vertex_stride, (GLvoid*)0);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, position_color_vertex_stride, (GLvoid*)(3 * sizeof(GLfloat)));
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, position_color_vertex_stride, (GLvoid*)(7 * sizeof(GLfloat)));
glDrawArrays(GL_TRIANGLES, 0, mesh->Get_Vertex_Count());
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
If I remove the indented lines the program will crash. If I leave them in it runs just fine. So why do I have to recall those? I thought the rebinding of the vao would do that for me?