Different buffers for different objects

Is it possible to have different objects (of the same type) contained in different buffers? That is, can I have one surface saved in one buffer and another surface saved in another buffer?

If so, how can I bind the different buffer attributes to the same variable? That is, if I have two different buffers, both with vertex coordinates, how do I get them both to be interpreted as such in the shader?

I can’t simply call


glBindAttribLocation(Environment.ShaderProgram,OneBuffer,"in_Position");
glBindAttribLocation(Environment.ShaderProgram,OtherBuffer,"in_Position");

can I? Those will obviously clash.

You might notice that glBindAttribLocation does not take a buffer object. That’s because it has nothing to do with buffer objects. It sets the attribute location that the program uses.

Buffer objects don’t have attribute locations. They’re just blocks of memory. That’s why you have to use glVertexAttribPointer to tell OpenGL where in that block of memory to look for a particular attribute.

If you have the position values for one object in one buffer, then you, before rendering, use glBindBuffer, glEnableVertexAttribArray and glVertexAttribPointer to tell OpenGL where the data for that attribute comes from. To render the a different object using the same shader but with a different buffer, you simply repeat the process.

Ah, so I can do something along the lines of

glGenBuffer(); //for one object
glBindBuffer(); 
glBufferData();
glEnableVertexAttribArray(0);
glVertexAttribArray(0,...);

glGenBuffer(); //for another object
glBindBuffer();
glBufferData();
glEnableVertexAttribArray(0); //same attribute
glVertexAttribArray(0,...);

and it will know that the attribute stretches between both buffers? Quite clever, that is.

Do I need to reset glEnableVertexAttribArray for the new buffer or can I just use it once and it will be set for them all?

You’re confusing initialization with what you do when you draw a frame… You should read chapters 1 and 2 of my tutorial, as they explain this stuff with diagrams and everything.