projectM-visualizer / projectm

projectM - Cross-platform Music Visualization Library. Open-source and Milkdrop-compatible.
https://discord.gg/mMrxAqaa3W
GNU Lesser General Public License v2.1
3.22k stars 365 forks source link

Improve performance with vertex buffer updates #777

Closed kblaschke closed 4 months ago

kblaschke commented 4 months ago

In wave/shape drawing code, we now preallocate the vertex buffer once for the maximum number of sides and only update the existing buffer instead of reallocating it over and over again. Trades a few KB of additional RAM for a good amount of drawing performance.

In the motion vector grid code, we only reallocate the buffer if we draw more vertices than in the previous draw call.

Also changed the drawing hint to GL_STREAM_DRAW, which is slightly better suited for this kind of usage (update once, draw once, repeat).

These changes should hopefully improve performance, especially when large numbers of custom shapes are drawn.