PDA

View Full Version : Real-time 3D measurements: should I use an index buffer or not?



samvdj
02-04-2014, 05:33 AM
Dear all,

I have a rectangular grid at fixed (X,Y) coordinates, for which the Z variable changes with each 3D measurement. Such a measurement updates this Z variable several 10 times per second, and obviously I would like my code to handle this in real-time.

My question is: should I use standard vertex buffer arrays and create new triangles with each go, or should I find a way to use the predefined (X,Y) grid in some sort of index buffer (as these never change, only the Z variable does)? I imagine the index buffer array would be fastest, but then how should I incorporate the changing heights in the vertex rendering? Only modify every third vertex coordinate somehow?

Thanks in advance for any pointers in the right direction,

Sam

nenad*
02-04-2014, 08:03 AM
Using an array and modifying every third coordinate is ok approach. If you need more speed you could use a vertex shader and keep the constant x/y array in a fast static read only VBO and send corresponding z coordinates as a separate attribute from a dynamic buffer.

samvdj
02-04-2014, 08:15 AM
Great thanks!

Some follow-up questions come to mind:

- So updating a "heightBuffer" and sending this as an attribute to the vertex shader should work faster than modifying third coordinates?
- Which of glDrawArrays / glDrawElements would I be using?
- Should I store the fixed x/y array VBO's in indexBuffers or vertexBuffers?
- I would still like wireFrame functionality, can this be achieved by your suggested approach?

nenad*
02-04-2014, 09:30 AM
- So updating a "heightBuffer" and sending this as an attribute to the vertex shader should work faster than modifying third coordinates?

It depends where the data is stored and what gpu/driver you run on. As a rule of thumb if the data is in video ram (VBO) - it will be faster. If it's in system ram - it will be slower. And again, if the data is hinted to gl as being static (e.g. GL_STATIC_DRAW) it might be faster, otherwise might be slower etc.



- Which of glDrawArrays / glDrawElements would I be using?

I'm assuming you're drawing a standard heightfield in which case each vertex is used in up to 8 triangles. So if storage is the concern using indices can save you some space and you need to update every Z coordinate only once.



- Should I store the fixed x/y array VBO's in indexBuffers or vertexBuffers?

If you decide to use indexed arrays then you'll need both, otherwise only the latter.




- I would still like wireFrame functionality, can this be achieved by your suggested approach?
Why not. Just set the polygon mode to lines.


I'd suggest you make the simplest possible implementation first. Draw from an indexed array stored in system ram using fixed functionality (so no shaders, no VBOs). Everything else is more or less just speed or storage optimization.

samvdj
02-06-2014, 06:41 AM
Great, thanks this has helped me a lot!