SDL / OpenGL: Implementing a “Loading thread”

不打扰是莪最后的温柔 提交于 2019-12-03 03:29:40

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!