OpenGL VBO within multiple threads

后端 未结 3 1265
清酒与你
清酒与你 2021-01-05 19:33

I am developing a program in C++/OpenGL which draws terrain of the entire world. I have a database of altitude heights stored as tiles. Every time I start the program, a til

3条回答
  •  清酒与你
    2021-01-05 20:27

    I have already an answer for this kind of tasks.

    In few words, you create two sharing contextes. Then, as suggested by Damon, make the contextes current on their own thread, only once at the beginning of the thread execution. The two contextes will be current at the same time on different threads (one thread, one context).

    Then, the secondary thread won't be used for rendering, but for loading resources (I mean, actually loading terrain data, textures... and create a corresponding OpenGL object on each data, such as textures and buffer objects). This happens while the main context is drawing.

    Essentially, you don't need to worry about bringing a pointer around the application and blocking the rendering thread for uploading data; but at the cost of creating another context. Let the driver to synchronize context states: if it can perform that operations smoothly your application will will benefit of it; at least, you code will be cleaner.

    Other contributions of mine on the subject:

    • Resource design : read about resource sharing
    • Sharing between contextes with different versions

提交回复
热议问题