Hi, everyone. I'm not professional in opengl. So I need your help.
So, currently I've started new iteration of game engine(I'm working in game company). We decide to use as base for engine cocos2dx 3.7 and write some wrappers for our script system and etc.
Now I want to add background loading of assets(texture and so on) using multi thread context of glfw.
I added some changes to GLViewImpl::initWithRect. Now I passing callback that should get main context and from that context new one as shared.
if (beforeFinalInitCallback)
{
(*beforeFinalInitCallback)(_mainWindow);
}
glfwMakeContextCurrent(_mainWindow);
and callback looks like this
[](void* glWindow)
{
std::thread thread([glWindow]()
{
auto context = glfwCreateWindow(1, 1, "", 0, static_cast<GLFWwindow*>(glWindow));
glfwMakeContextCurrent(context);
context = glfwGetCurrentContext();
});
};
Even if I remove thread wrapping(it will be the same thread as in initWithRect here), I still can't create context(return null pointer).
But if I move that code to inside of initWithRect and get this
it's start working. Context creating and set as current normaly.
It's frustrating me. I can't get where is error or something like that. I checked all params(getting all pointers valid and right).
Can please someone help me. I fighting with that thing 3 days already. I can't use TextureCache async methods cause I need render my scene with animation while another scene loading in background.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
According to the docs for glfwCreateWindow the context to sare resources with may not be current on any other thread.
So it may be simplest to make your contexts on the main thread (using an invisible window for one), and then make the invisible context current on your loading thread.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
But thats I want to achieve)). I cann't create shared context outside of library class(I wont leave library classes untouched to easy upgrade in future. I just can get what is wrong. shared window(invisble) can not be as current in my loading.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As per my earlier response https://sourceforge.net/p/glfw/discussion/247562/thread/ebbe004d/#980a I think you should first try creating the windows on your current thread, then pass the context for the second window to the loading thread. This isn't what your earlier code appears to be trying to do - have you tried this approach yet?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, everyone. I'm not professional in opengl. So I need your help.
So, currently I've started new iteration of game engine(I'm working in game company). We decide to use as base for engine cocos2dx 3.7 and write some wrappers for our script system and etc.
Now I want to add background loading of assets(texture and so on) using multi thread context of glfw.
I added some changes to GLViewImpl::initWithRect. Now I passing callback that should get main context and from that context new one as shared.
Even if I remove thread wrapping(it will be the same thread as in initWithRect here), I still can't create context(return null pointer).
But if I move that code to inside of initWithRect and get this
it's start working. Context creating and set as current normaly.
It's frustrating me. I can't get where is error or something like that. I checked all params(getting all pointers valid and right).
Can please someone help me. I fighting with that thing 3 days already. I can't use TextureCache async methods cause I need render my scene with animation while another scene loading in background.
According to the docs for glfwCreateWindow the context to sare resources with may not be current on any other thread.
So it may be simplest to make your contexts on the main thread (using an invisible window for one), and then make the invisible context current on your loading thread.
But thats I want to achieve)). I cann't create shared context outside of library class(I wont leave library classes untouched to easy upgrade in future. I just can get what is wrong. shared window(invisble) can not be as current in my loading.
So, any suggestions? or topic is closed?
As per my earlier response https://sourceforge.net/p/glfw/discussion/247562/thread/ebbe004d/#980a I think you should first try creating the windows on your current thread, then pass the context for the second window to the loading thread. This isn't what your earlier code appears to be trying to do - have you tried this approach yet?
Yes, I tried this. But still has error. Context not setting as current for second thread.