在土壤中的多线程支持opengl [英] multi-threading support in soil for opengl
问题描述
我的问题是,是否是SOIL(简单opengl图像库)线程兼容?
因为当我运行下面的代码:
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
);
(以加载纹理)
外面的线程它工作正常,但是当运行在std ::线程内时,它给我的错误
未处理的异常0x592527FF (msvcr110d.dll)in Project2.exe:
0xC0000005:访问冲突读取位置0x00000000。
线程化它以便它可以在菜单屏幕期间加载,或者启动屏幕或某种类型的东西。所以我的问题是如果SOIL不是线程安全的,那么一个体面的解决方案是运行一个线程来运行菜单/初始屏幕/任何为了允许纹理加载在主线程?
< (感谢datenwolf进行纠正)如果上面提到的方法是一个简单的方法,你可以使用一个单独的线程来调用GL上下文,使用GL方法,我假设它,然后它不会工作,除非你在单独的GL上下文中。如果你想要多线程的方式,你可以创建共享上下文 - 每个在单独的线程。然后你渲染主线程加载纹理在另一个。我不知道它是多少是性能聪明,但你可以尝试无论如何。
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?
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.
这篇关于在土壤中的多线程支持opengl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!