Currently I am working on a project in which I generate geometry based on the players movement. A glorified very long trail, composed of quads.
I am doing this by storing a STD::Vector, and removing the oldest verticies once enough exist, and then calling glDrawArrays.
I am interested in switching to a shader based model, usually examples I see the VBO is generated at start and then that's basically it. What is the best route to go about creating geometry in real time, using shader / VBO approach
Answer
Even though this can be application bound and depends on how much you generate geometry and how dynamic your application is, there are general rules you can follow when using VBOs.
-Specify how your VBOs will be used.
- "Static" means the data in VBO will not be changed (specified once and used many times),
"Dynamic" means the data will be changed frequently (specified and used repeatedly)
"Stream" means the data will be changed every frame (specified once and used once). "Draw"
so in your case they should be dynamic.
- Update (reuse) your existing VBOs using
glBufferSubData
,glMapBuffer()
,glUnMapBuffer()
, instead of creating and allocating new VBOs.
About using std::vector I think this can hurt performance if you add and remove a lot of objects, try to specify a vector with predefined size to minimize memory copy.
As for shaders, I don't think this makes any difference as long as you track transformation matrices (player position, rotation).
for more on VBOs refer to http://www.songho.ca/opengl/gl_vbo.html
No comments:
Post a Comment