Manage VBO for multiple objects

Started by
9 comments, last by owl 12 years, 10 months ago
I want to render an undefined amount of objects on my scene

if I create one large VBO to hold all the data how do I deal with geometry changes that may occur to some of those objects

I was thinking of having many vbo's but Ive been told that would cause problems


please help
Advertisement
if I create one large VBO to hold all the data how do I deal with geometry changes that may occur to some of those objects[/quote]

I'm not sure what you mean by geometry changes, if you mean actually changing the vertices of an individual object that can be done by replacing the vertices with glBufferSubData. If you mean just moving objects around in space then you'll just draw a subset of the VBO each time you change the transformation.



I was thinking of having many vbo's but Ive been told that would cause problems
[/quote]

I think you've either been told incorrectly or misunderstood.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Could you provide more details on how to use glBufferSubData?

how do I keep track of which subset corresponds to each object
For usage specifics, see http://www.opengl.org/sdk/docs/man/xhtml/glBufferSubData.xml

Where different objects start and end is up to you to keep track of. You could just store values called 'start' and 'end' inside your object class, and a pointer to a opengl buffer. Then when you draw a particular object you just render the VBO from 'start' to 'end'.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
I think Im still confused...

since probably most of my vertex data will change why I dont just refill the buffer with new data each frame?
You can either do double buffering, which means having 2 VBOs. This does improve performance.
The other way is to call glBufferData with a NULL pointer. This tells the driver you prefer to have a newly allocated VBO. Then call glBufferSubData to refresh the entire VBO.
http://www.opengl.org/wiki/VBO_-_more#Dynamic_VBO
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
good stuff , Im going to try that
I still havent made a decision on how to handle the rendering of my objects..

I was thinking of doing this

- send the following data to the vertex shader

vec2 translation_vector
float rotation_degrees
vec3 vertex[4]
vec4 color

(send as uniforms the projection and the current camera matrices)


this way I can just create my matrices at the vertex shader and transform the quads instead of calculating/creating matrices at the CPU

to avoid keeping tabs on where each quad is stored in the buffer I will just refill the current buffer with fresh data each frame.

comments?

thank you guys
For my animated models I just have a dynamic vbo which I map each frame and fill with the updated data. I have one VBO per model. I guess I could have a big one for many but as I wasn't sure the number of models was gonna be constant I firstly implemented it this way. For my old video card, the bottleneck is in texturing more than in transfering.
[size="2"]I like the Walrus best.
oh well that sounds MUCH more simpler

so where u handle the transformations? at the cpu or at the shader

This topic is closed to new replies.

Advertisement