I think you missunderstood me which may be due to my bad english (or just me explaining poorly).
I'm perfectly aware that one vao has excatly one vbo and how the binding works. Let me try to explain it a bit more detailed:
Lets assume we have 1 vao with 1 vbo and 1 ibo attached to it. The mode of the vao is GL_TRIANGLES and the attributes are 3 vec4 (float).
Each frame we bind the vao once. We bind our shader program (and upload uniforms) and use glDrawElements to draw the vbo to the screen. Then we unbind the program and the vao and do other stuff waiting for the next frame. Until now everything should be pretty normal indexed vao rendering.
In code:
1 2 3 4 5 6 7 8
| public void render() { vao.glBind(); shaderProgram.glBind(); shaderProgram.uploadUniforms(); glDrawElements(GL_TRIANGLES, vao.size(), GL_UNSIGNED_INT, 0); shaderProgram.glUnbind(); vao.glUnbind(); } |
So here comes my "idea":
The only thing set in stone here is the mode (GL_TRIANGLES) and the vertex attributes. Lets introduce "vao entries" represented by an object with specifies a data-section in the vbo and ibo (upper and lower bound). We render these entries using the offset in glDrawElements. It looks something like:
1 2 3 4 5 6 7 8 9 10
| public void render() { vao.glBind(); shaderProgram.glBind(); shaderProgram.uploadUniforms(); for(VAOEntry e : allVAOEntries) { glDrawElements(GL_TRIANGLES, e.upperBound - e.lowerBound, GL_UNSIGNED_INT, e.lowerBound); } shaderProgram.glUnbind(); vao.glUnbind(); } |
Now we render sections of the vao content separately using the same shader program. The last adjustment I make is giving each entry a separate shader program with the condition all shader programs use
the same vertex attributes.
1 2 3 4 5 6 7 8 9 10
| public void render() { vao.glBind(); for(VAOEntry e : allVAOEntries) { e.glBindShaderProgram(); e.uploadUniforms(); glDrawElements(GL_TRIANGLES, e.upperBound - e.lowerBound, GL_UNSIGNED_INT, e.lowerBound); e.glUnbindShaderProgram(); } vao.glUnbind(); } |
Now I want to create only one VAO for the most common mode / vertex attrib combination and use entries and different shader programs to store completly different graphic-objects in these vao (but all sharing the same mode and vertex attribs).
That minimises the amount of vao drastically as I'm combine "to-draw-objects" in one vao over the "interface" of a common mode and vertex attribs.
Hopefully its more comprehensible now.