tristam92 wrote on Wednesday, February 10, 2016:
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
std::function<void(void*)> pFunc = [](void* glWindow)
{
std::thread thread([glWindow]()
{
auto context = glfwCreateWindow(1, 1, "", 0, static_cast<GLFWwindow*>(glWindow));
glfwMakeContextCurrent(context);
context = glfwGetCurrentContext();
});
};
pFunc(_mainWindow);
glfwMakeContextCurrent(_mainWindow);
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.