Jump to content
  • Advertisement
Sign in to follow this  
X Abstract X

Can I do Something Like This?

This topic is 2972 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to do some basic keyframe animation using .obj files to load models, using a separate file for each frame. Is it possible to set up a VBO to store all the vertices and normals for all 10 frames BUT use a separate VBO to store the texture coords and colors for a single frame since the texture coords and colors are going to be the same for every frame? Or, am I thinking about this all wrong? Is this too inefficient?

Share this post


Link to post
Share on other sites
Advertisement
I think this should be possible. Just generate 22 buffers (10x vertex and normal, 1x texture and color). You can change the vertex and normal buffers as needed for each frame while still pointing the texcoord and color pointer to the same buffer.

Share this post


Link to post
Share on other sites
I'm sorry but I don't understand what you mean by set the attribute pointers to a different buffer. How exactly do you do that? Right now my code, without animation implemented, looks something like this:


unsigned int vboID = 0;
glGenBuffers(1, &vboID);
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBufferData(GL_ARRAY_BUFFER, numVertices * sizeof(Vertexf), vertices, GL_DYNAMIC_DRAW);

//Setup attributes
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertexf), 0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertexf), (void*)sizeof(Vector3f));
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertexf), (void*)(sizeof(Vector3f) + sizeof(Vector3f)));
glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(Vertexf), (void*)(sizeof(Vector3f) + sizeof(Vector3f) + sizeof(TexCoord2f)));


Share this post


Link to post
Share on other sites
What you have is called an "interleaved" buffer format. You are packing all of your information into a single buffer like the following (I'm guessing):

Buffer 1: VNCTVNCTVNCT

(V= vertex, N = normal, C = color, T = texcoord)

You don't have to do it this way. You can draw from as many different buffers as you want. Instead of packing all of your information into one buffer, you can do it into four buffers:

Buffer 1: VVVVV
Buffer 2: NNNNN
Buffer 3: CCCCC
Buffer 4: TTTTT

Then when setting up your Attrib pointers you just bind the proper buffer first:

glBindBuffer(Buffer 1);
glAttribPointer(...verts...);
glBindBuffer(Buffer 2);
glAttribPointer(...normals...);
glBindBuffer(Buffer 3);
glAttribPointer(...colors...);
glBindBuffer(Buffer 4);
glAttribPointer(...texcoords...);
...
glDrawElements()

For your case you can create a buffer of VVVVV for each of your keyframes, while using the same texcoord buffer every time.

Share this post


Link to post
Share on other sites
Ah, I really appreciate the detail in your post. I didn't know you could bind a buffer, set a pointer and then bind another buffer like that. You seem to emphasize using a single buffer for each attribute but would performance be better if I made 2 buffers? One for pos and normals and another for tex coords and colors?

I've also heard that filling each VBO with ~4 megabytes of data is the 'prime' amount of data to pack into it. Do you know if theres any truth to that?

Then it seems like there's going to be an issue with my index buffer. The indices into the different attribute buffers are going to be different... (assuming I try to pack all animation frames into the same vertex/normal buffers)

Share this post


Link to post
Share on other sites
Quote:

but would performance be better if I made 2 buffers?


You can try it for yourself and see, although my guess is that it will be negligible difference.

Quote:
I've also heard that filling each VBO with ~4 megabytes of data is the 'prime' amount of data to pack into it. Do you know if theres any truth to that?


I wouldn't stress over this. I don't know if there's some magic number, but it is probably dependent on the OpenGL implementation, and again it would probably be negligible.

Quote:

Then it seems like there's going to be an issue with my index buffer. The indices into the different attribute buffers are going to be different...(assuming I try to pack all animation frames into the same vertex/normal buffers)


This shouldn't be a problem. You can either create a unique buffer for the vertices in each frame (the 22 buffers idea from my original post). You can even pack all of the frames into a single buffer if you want (again shouldn't make any difference). Remember that index zero doesn't equal the start of the buffer, but where you put the pointer. So if you have two frames and 500 vertices, then you can make a buffer of 1000 vertices. Then if you set the pointer to element zero the index count starts from there, or if you set the pointer to element 500 then the index starts counting from there.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!