mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-08-23 15:23:44 +02:00
Only create GL context in main thread on macOS
This commit is contained in:
parent
74f62e26d4
commit
2432aec97f
2 changed files with 61 additions and 44 deletions
104
src/main.cpp
104
src/main.cpp
|
@ -70,10 +70,18 @@ printGLInfo()
|
||||||
Debug() << "GLSL Version :" << glGetStringInt(GL_SHADING_LANGUAGE_VERSION);
|
Debug() << "GLSL Version :" << glGetStringInt(GL_SHADING_LANGUAGE_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SDL_GLContext initGL(SDL_Window* win, Config& conf);
|
||||||
|
|
||||||
int rgssThreadFun(void *userdata)
|
int rgssThreadFun(void *userdata)
|
||||||
{
|
{
|
||||||
RGSSThreadData *threadData = static_cast<RGSSThreadData*>(userdata);
|
RGSSThreadData *threadData = static_cast<RGSSThreadData*>(userdata);
|
||||||
|
|
||||||
|
#ifndef __APPLE__
|
||||||
|
threadData->glContext = initGL(threadData->window, threadData->glContext);
|
||||||
|
#else
|
||||||
|
SDL_GL_MakeCurrent(threadData->window, threadData->glContext);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Setup AL context */
|
/* Setup AL context */
|
||||||
ALCcontext *alcCtx = alcCreateContext(threadData->alcDev, 0);
|
ALCcontext *alcCtx = alcCreateContext(threadData->alcDev, 0);
|
||||||
|
|
||||||
|
@ -310,48 +318,11 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
EventThread eventThread;
|
EventThread eventThread;
|
||||||
|
|
||||||
SDL_GLContext glCtx{};
|
#ifdef __APPLE__
|
||||||
|
SDL_GLContext glCtx = initGL(win, conf);
|
||||||
/* Setup GL context. Must be done in main thread since macOS 10.15 */
|
#else
|
||||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
SDL_GLContext glCtx = NULL;
|
||||||
|
#endif
|
||||||
if (conf.debugMode)
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
|
|
||||||
|
|
||||||
glCtx = SDL_GL_CreateContext(win);
|
|
||||||
|
|
||||||
if (!glCtx)
|
|
||||||
{
|
|
||||||
showInitError(std::string("Error creating context: ") + SDL_GetError());
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
initGLFunctions();
|
|
||||||
}
|
|
||||||
catch (const Exception &exc)
|
|
||||||
{
|
|
||||||
showInitError(exc.msg);
|
|
||||||
SDL_GL_DeleteContext(glCtx);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!conf.enableBlitting)
|
|
||||||
gl.BlitFramebuffer = 0;
|
|
||||||
|
|
||||||
gl.ClearColor(0, 0, 0, 1);
|
|
||||||
gl.Clear(GL_COLOR_BUFFER_BIT);
|
|
||||||
SDL_GL_SwapWindow(win);
|
|
||||||
|
|
||||||
printGLInfo();
|
|
||||||
|
|
||||||
bool vsync = conf.vsync || conf.syncToRefreshrate;
|
|
||||||
SDL_GL_SetSwapInterval(vsync ? 1 : 0);
|
|
||||||
|
|
||||||
GLDebugLogger dLogger;
|
|
||||||
|
|
||||||
|
|
||||||
RGSSThreadData rtData(&eventThread, argv[0], win,
|
RGSSThreadData rtData(&eventThread, argv[0], win,
|
||||||
alcDev, mode.refresh_rate, conf, glCtx);
|
alcDev, mode.refresh_rate, conf, glCtx);
|
||||||
|
@ -402,12 +373,13 @@ int main(int argc, char *argv[])
|
||||||
rtData.rgssErrorMsg.c_str(), win);
|
rtData.rgssErrorMsg.c_str(), win);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_GL_DeleteContext(rtData.glContext);
|
||||||
|
|
||||||
/* Clean up any remainin events */
|
/* Clean up any remainin events */
|
||||||
eventThread.cleanup();
|
eventThread.cleanup();
|
||||||
|
|
||||||
Debug() << "Shutting down.";
|
Debug() << "Shutting down.";
|
||||||
|
|
||||||
SDL_GL_DeleteContext(glCtx);
|
|
||||||
alcCloseDevice(alcDev);
|
alcCloseDevice(alcDev);
|
||||||
SDL_DestroyWindow(win);
|
SDL_DestroyWindow(win);
|
||||||
|
|
||||||
|
@ -421,3 +393,49 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SDL_GLContext initGL(SDL_Window* win, Config& conf)
|
||||||
|
{
|
||||||
|
SDL_GLContext glCtx{};
|
||||||
|
|
||||||
|
/* Setup GL context. Must be done in main thread since macOS 10.15 */
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||||
|
|
||||||
|
if (conf.debugMode)
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
|
||||||
|
|
||||||
|
glCtx = SDL_GL_CreateContext(win);
|
||||||
|
|
||||||
|
if (!glCtx)
|
||||||
|
{
|
||||||
|
showInitError(std::string("Error creating context: ") + SDL_GetError());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
initGLFunctions();
|
||||||
|
}
|
||||||
|
catch (const Exception &exc)
|
||||||
|
{
|
||||||
|
showInitError(exc.msg);
|
||||||
|
SDL_GL_DeleteContext(glCtx);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!conf.enableBlitting)
|
||||||
|
gl.BlitFramebuffer = 0;
|
||||||
|
|
||||||
|
gl.ClearColor(0, 0, 0, 1);
|
||||||
|
gl.Clear(GL_COLOR_BUFFER_BIT);
|
||||||
|
SDL_GL_SwapWindow(win);
|
||||||
|
|
||||||
|
printGLInfo();
|
||||||
|
|
||||||
|
bool vsync = conf.vsync || conf.syncToRefreshrate;
|
||||||
|
SDL_GL_SetSwapInterval(vsync ? 1 : 0);
|
||||||
|
|
||||||
|
//GLDebugLogger dLogger;
|
||||||
|
return glCtx;
|
||||||
|
}
|
||||||
|
|
|
@ -184,7 +184,6 @@ void SharedState::initInstance(RGSSThreadData *threadData)
|
||||||
* Font depends on SharedState existing */
|
* Font depends on SharedState existing */
|
||||||
|
|
||||||
rgssVersion = threadData->config.rgssVersion;
|
rgssVersion = threadData->config.rgssVersion;
|
||||||
SDL_GL_MakeCurrent(threadData->window, threadData->glContext);
|
|
||||||
|
|
||||||
_globalIBO = new GlobalIBO();
|
_globalIBO = new GlobalIBO();
|
||||||
_globalIBO->ensureSize(1);
|
_globalIBO->ensureSize(1);
|
||||||
|
|
Loading…
Add table
Reference in a new issue