multi-threading support in soil for opengl

瘦欲@ 提交于 2019-12-11 13:56:48

问题


My question is, is SOIL (simple opengl image library) thread compatible?

Because when I run the following code:

Texture = SOIL_load_OGL_texture (
                 loc.c_str(),
                 SOIL_LOAD_AUTO,
                 SOIL_CREATE_NEW_ID,
                 SOIL_FLAG_POWER_OF_TWO
                 | SOIL_FLAG_MIPMAPS
                 | SOIL_FLAG_MULTIPLY_ALPHA
                 | SOIL_FLAG_COMPRESS_TO_DXT
                 | SOIL_FLAG_DDS_LOAD_DIRECT
                 | SOIL_FLAG_INVERT_Y
             );

(in order to load a texture)

outside of a thread it works fine, however when run inside an std::thread it gives me the error

Unhandled exception at 0x592527FF (msvcr110d.dll) in Project2.exe: 0xC0000005: Access violation reading location 0x00000000.

I want to be able to thread it so that it can load during a menu screen, or a splash screen or something of the sort. So my question is if SOIL is not thread safe then would a decent solution be to run a thread to run the menu/ splash screen/ whatever in order to allow textures to load in the main thread?


回答1:


OpenGL isTHREAD BOUND!Which means you can make calls on your GL context from a single thread at a time.(Thanks to datenwolf for correction)If the above mentioned method uses GL methods ,which I suppose it does, then it won't work unless you do it in separate GL context.If you want to go multi -threaded way,you can create shared context - each in separate thread.Then you render in the main thread while loading the textures in another one.I am not sure how much it is performance wise,but you can give it a try anyway.



来源:https://stackoverflow.com/questions/19341704/multi-threading-support-in-soil-for-opengl

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