PDA

View Full Version : Change VBO offset while drawing instances



Aliii
10-27-2013, 02:19 AM
I want to do something like instanced rendering ...but sort of the opposite. With vertexAttribDivisor I can set something like "after every 5 instances it jumps to the next index in the VBO". But what I need is like "after every instance it jumps 5 indices in the VBO".

The only thing I can think of right now is that after every instance I change the buffer offset in the VBO with vertexAttribPointer, ...but I dont want to do that state change that often.
Any ideas? Thanks!

GClements
10-27-2013, 02:59 AM
I want to do something like instanced rendering ...but sort of the opposite. With vertexAttribDivisor I can set something like "after every 5 instances it jumps to the next index in the VBO". But what I need is like "after every instance it jumps 5 indices in the VBO".
Unless you've omitted something in your description, you just need to use the appropriate value for the stride parameter in the glVertexAttribPointer() call.

Aliii
10-27-2013, 03:23 AM
Unless you've omitted something in your description, you just need to use the appropriate value for the stride parameter in the glVertexAttribPointer() call.

I mean ...skip indices logically ...not skip them physically in the memory. Thats what stride does.

To give an example:
I have 2 VBOs. In one there are the positions of the vertices, in the other one there are the colors. But the second one has twice as many elements in it, because I want to draw the same object twice ...but with different colors. So I draw 2 instances of the object, and after the first instance I want to skip the colors of the first object and use the colors of the second object.

...and without changing VBO-s, or calling vertexAttribPointer to change the offset.