View Full Version : Different buffers for different objects
08-22-2011, 10:40 AM
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
can I? Those will obviously clash.
08-22-2011, 01:55 PM
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.
08-22-2011, 05:04 PM
Ah, so I can do something along the lines of
glGenBuffer(); //for one object
glGenBuffer(); //for another object
glEnableVertexAttribArray(0); //same attribute
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?
08-22-2011, 05:37 PM
You're confusing initialization with what you do when you draw a frame.. You should read chapters 1 (http://www.arcsynthesis.org/gltut/Basics/Tutorial%2001.html) and 2 (http://www.arcsynthesis.org/gltut/Basics/Tutorial%2002.html) of my tutorial, as they explain this stuff with diagrams and everything.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.