PDA

View Full Version : the use of glDrawElementsBaseVertex()



shapeare
07-20-2012, 08:16 AM
I am drawing an animated model of several frames. Say the model consists of 1000 vertices, and I want to render 5 frames.

I stored the vertex positions of the five frames in a large buffer, the size of which is sizeof(float) * 1000 * 3 * 5. During rendering I do not want to change the model color, so I stored the vertex color in another buffer which is of the size sizeof(float) * 1000 * 3.

But I have run into the problem of rendering it. I once thought of using glDrawElementsBaseVertex() that accepts an offset so I can render vertices of different frames, but the color array is shorter than the position array, so only the first frame has color associated with it. How can I solve this problem?

Alfonse Reinheart
07-20-2012, 09:44 AM
I stored the vertex positions of the five frames in a large buffer, the size of which is sizeof(float) * 1000 * 3 * 5. During rendering I do not want to change the model color, so I stored the vertex color in another buffer which is of the size sizeof(float) * 1000 * 3.

This situation has nothing to do with base vertex. You can't add a base index to only some of the attribute indices. Just as you can't have different indices for different attributes.

shapeare
07-20-2012, 10:13 AM
Thanks for your reply.
What should I do? Allocate the same size of space as the position buffer for the color buffer and repeat the color value five times?
Is there any better solution for this?

Dark Photon
07-20-2012, 12:51 PM
Could use a diff block or buffer for vtx attribs that chg vs stay the same. Then share those that are the same.

mhagain
07-20-2012, 01:05 PM
Just change the offset in your glVertexAttribPointer calls for position. Color remains the same - offset 0 - but make a glVertexAttribPointer call for position with offset sizeof(float) * 1000 * 3 * framenum. You'd need to separate position and color into different VBOs, and with only 5 frames you could even create 5 separate VAOs, one for each frame.

Alfonse Reinheart
07-20-2012, 02:15 PM
Allocate the same size of space as the position buffer for the color buffer and repeat the color value five times?

It depends: how much does the added performance of base vertex matter to you? It's a memory-for-performance tradeoff.

If this is a real issue, profile it and see what the difference is.

shapeare
07-20-2012, 08:37 PM
Thanks for the replies.



Just change the offset in your glVertexAttribPointer calls for position. Color remains the same - offset 0 - but make a glVertexAttribPointer call for position with offset sizeof(float) * 1000 * 3 * framenum. You'd need to separate position and color into different VBOs, and with only 5 frames you could even create 5 separate VAOs, one for each frame.

Thank you very much. But I did not separate position and color into different VBOs. it works by only changing the offset for glVertexAttribPointer() of the position array before the rendering of each frame.

aqnuep
07-20-2012, 09:28 PM
There is also another alternative:

If you want to keep the color the same but change the rest, you can put your color into another buffer that you bind as a texture buffer and fetch the color separately using texture buffer fetches in your vertex shader.