Efficient VBO Distribution in WebGL

I am writing a WebGL application that algorithmically generates geometry. The geometry will consist of 4-150 objects, each of which consists somewhere between 16 and 2048 points, drawn as TRIANGLE_STRIP through drawElements. The geometry will be static with most frames, but it will need to be animated in response to user input. In these frames, when the geometry is updated, points / tris can be added or removed. Objects must also be added / removed throughout the entire program life cycle.

What is the most efficient way to host / update VBOs in this context? I'm sure I should use DYNAMIC_DRAW and bufferSubData to update each object, but do I want to redistribute some huge VBOs (assuming the worst case in terms of points to an object) and define each object as an offset (object number * maximum size per object), and then there is a lot of allocated unused VBO memory at best? Or is there another approach I should try? Or is it small enough in terms of the amount of memory that I think too much?

+6
source share
1 answer

What is the most efficient way to host / update VBOs in this context? I am sure that I should use DYNAMIC_DRAW and bufferSubData to update each object.

This is really the way to go. In fact, you want to use double or even triple buffering for your objects, i.e. have one binding to VBO for drawing, while you are updating the contents of another with new data. After glMapBuffer, the memory card can be accessed from all threads in the process, so you can have a worker thread updating the "correct" vertex buffer, while the rendering thread is busy drawing the current frame.

Or is it small enough in terms of the amount of memory that I think too much?

Did you rate the worst memory you are dealing with? Given your numbers, I bet it will be below 16MiB (150 objects * 2048 points * 3 double-precision floats per point * 8 bytes per double = 7.4 MiB, only 3.7MiB if single precision floats are used). Compare this with several hundred modern MiB RAM graphics cards (my GeForce 8800GTX had 768MiB RAM in 2006, and my Radeon HD6570 has 1024 megabytes (= 1 Gb).

+8
source

Source: https://habr.com/ru/post/897334/


All Articles