SDL / OpenGL: Implementing a “Loading thread”

后端 未结 1 997
夕颜
夕颜 2021-02-06 11:51

I currently try to implement a \"Loading thread\" for a very basic gaming engine, which takes care of loading e.g. textures or audio while the main thread keeps rendering a prop

相关标签:
1条回答
  • 2021-02-06 12:42

    Is there any way to share contexts with SDL

    No.

    Yes!

    You have to get the current context, using platform-specific calls. From there, you can create a new context and make it shared, also with platform-specific calls.

    Is there any other more "elegant" way to load my data in the background that I may have missed or didn't think about?

    Not really. You enumerated the options quite well: hack SDL to get the data you need, or load data inefficiently.

    However, you can load the data into mapped buffer objects and transfer the data to OpenGL. You can only do the mapping/unmapping on the OpenGL thread, but the pointer you get when you map can be used on any thread. So map a buffer, pass it to the worker thread. It loads data into the mapped memory, and flips a switch. The GL thread unmaps the pointer (the worker thread should forget about the pointer now) and uploads the texture data.

    Can my intention of going with approach B considered to be a good choice?

    Define "good"? There's no way to answer this without knowing more about your problem domain.

    0 讨论(0)
提交回复
热议问题