I’m designing a pipeline that needs to be able to draw thousands of 2D polygons per frame, some of which may be generated on the fly. OpenGL offers several strategies for loading this data into buffer objects, and I’m wondering what’s the best one.
Should I define a separate buffer object for each polygon I want to render, or just define one buffer object and keep overwriting it’s data? With the former strategy, I would be potentially be doing one glGenBuffers/glBindBuffers/glBufferData/glDeleteBuffer per object per frame (although I might be able to cache and reuse some of them for multiple frames). With the latter strategy, would it be efficient to keep overwriting the same buffer with different data for every object? If so, should I call glBufferData with GL_STREAM_DRAW, GL_DYNAMIC_DRAW or GL_STATIC_DRAW? (From the docs, I’m having trouble telling the difference between the STREAM and DYNAMIC versions).
If you determine that you need to regenerate the vertex/index data on the CPU (or at least, not on the GPU), then carefully read and use the techniques described here:
If OTOH you find that you can generate (or even better, just reuse) the vertex/index data on the GPU, then I’d suggest doing that instead.
On the usage flags, I wouldn’t sweat those. Many drivers just ignore them and try to choose the ideal memory space for your buffer object to live in based on what operations you perform on them.
glDeleteBuffers … After startup, I would avoid like the plague creating, deleting, and/or reallocating the storage for buffer objects. (Note here that I differentiate between reallocating the storage and orpaning [aka re-specifying] the storage; see the above wiki page link for details). Pre-allocate everything on startup if you require realtime rendering performance.
This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.