I'm confused on the concept of buffers. I understand the very basics with glBufferData and glBufferSubData. Using glBufferSubData before a render function in your main loop you can use a offset and size parameter to store multiple model objects in a vertex buffer and a index buffer. Then at render you bind the single vertex buffer and call glDrawElements with the correct offsets and sizes to render multiple objects.
Is this the case with glMapBuffer? Or am I suppose to call glMapBuffer to link vertex and index data at render, then draw?
GLuint vertexArrayId;
GLuint verticesBufferId;
GLuint indicesBufferId;
void setupBuffers() {
glGenVertexArrays(1, &vertexArrayId);
glBindVertexArray(vertexArrayId);
glGenBuffers(1, &verticesBufferId);
glGenBuffers(1, &indicesBufferId);
glBindBuffer(GL_ARRAY_BUFFER, verticesBufferId);
glBufferData(GL_ARRAY_BUFFER, VERTICES_SIZE, NULL, GL_STATIC_DRAW);
// glMapBuffer stuff here
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indicesBufferId);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, INDICES_SIZE, NULL, GL_STATIC_DRAW);
// glMapBuffer stuff here
}
void render() {
glBindBuffer(GL_ARRAY_BUFFER, verticesBufferId);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)((sizeof(GLfloat) * 0)));
glEnableVertexAttribArray(0);
// glDrawElements stuff here
glDisableVertexAttribArray(0);
// Model, View, Projection transformations here
// glUniformMatrix4fv
}