diff --git a/src/cocoa_init.m b/src/cocoa_init.m index d3aec5e7..59943211 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -325,9 +325,6 @@ int _glfwPlatformInit(void) if (!_glfwInitThreadLocalStoragePOSIX()) return GLFW_FALSE; - if (!_glfwInitNSGL()) - return GLFW_FALSE; - _glfwInitTimerNS(); _glfwInitJoysticksNS(); diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 5643061f..09d2ca22 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -1034,6 +1034,8 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, { if (ctxconfig->source == GLFW_NATIVE_CONTEXT_API) { + if (!_glfwInitNSGL()) + return GLFW_FALSE; if (!_glfwCreateContextNSGL(window, ctxconfig, fbconfig)) return GLFW_FALSE; } diff --git a/src/egl_context.c b/src/egl_context.c index 7b75d127..7583fac9 100644 --- a/src/egl_context.c +++ b/src/egl_context.c @@ -296,6 +296,9 @@ GLFWbool _glfwInitEGL(void) NULL }; + if (_glfw.egl.handle) + return GLFW_TRUE; + for (i = 0; sonames[i]; i++) { _glfw.egl.handle = _glfw_dlopen(sonames[i]); @@ -358,6 +361,8 @@ GLFWbool _glfwInitEGL(void) { _glfwInputError(GLFW_PLATFORM_ERROR, "EGL: Failed to load required entry points"); + + _glfwTerminateEGL(); return GLFW_FALSE; } diff --git a/src/glx_context.c b/src/glx_context.c index a3deefcf..251b7fc4 100644 --- a/src/glx_context.c +++ b/src/glx_context.c @@ -253,6 +253,9 @@ GLFWbool _glfwInitGLX(void) NULL }; + if (_glfw.glx.handle) + return GLFW_TRUE; + for (i = 0; sonames[i]; i++) { _glfw.glx.handle = dlopen(sonames[i], RTLD_LAZY | RTLD_GLOBAL); diff --git a/src/mir_init.c b/src/mir_init.c index 3f649670..3076f5f3 100644 --- a/src/mir_init.c +++ b/src/mir_init.c @@ -183,9 +183,6 @@ int _glfwPlatformInit(void) if (!_glfwInitThreadLocalStoragePOSIX()) return GLFW_FALSE; - if (!_glfwInitEGL()) - return GLFW_FALSE; - if (!_glfwInitJoysticksLinux()) return GLFW_FALSE; diff --git a/src/mir_window.c b/src/mir_window.c index b9b5752b..5380a884 100644 --- a/src/mir_window.c +++ b/src/mir_window.c @@ -379,6 +379,8 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, if (ctxconfig->client != GLFW_NO_API) { + if (!_glfwInitEGL()) + return GLFW_FALSE; if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig)) return GLFW_FALSE; } diff --git a/src/nsgl_context.m b/src/nsgl_context.m index 64729009..22ebdba9 100644 --- a/src/nsgl_context.m +++ b/src/nsgl_context.m @@ -92,6 +92,9 @@ static void destroyContextNSGL(_GLFWwindow* window) // GLFWbool _glfwInitNSGL(void) { + if (_glfw.nsgl.framework) + return GLFW_TRUE; + _glfw.nsgl.framework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl")); if (_glfw.nsgl.framework == NULL) diff --git a/src/wgl_context.c b/src/wgl_context.c index 6f7ee85e..c3af4675 100644 --- a/src/wgl_context.c +++ b/src/wgl_context.c @@ -424,6 +424,9 @@ static void loadWGLExtensions(void) // GLFWbool _glfwInitWGL(void) { + if (_glfw.wgl.instance) + return GLFW_TRUE; + _glfw.wgl.instance = LoadLibraryA("opengl32.dll"); if (!_glfw.wgl.instance) { diff --git a/src/win32_init.c b/src/win32_init.c index 681954cb..e7dcb04e 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -425,10 +425,6 @@ int _glfwPlatformInit(void) _glfwPlatformPollEvents(); - if (!_glfwInitWGL()) - return GLFW_FALSE; - - _glfwInitEGL(); _glfwInitTimerWin32(); _glfwInitJoysticksWin32(); diff --git a/src/win32_window.c b/src/win32_window.c index b9bb6899..b2503823 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -993,11 +993,15 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, { if (ctxconfig->source == GLFW_NATIVE_CONTEXT_API) { + if (!_glfwInitWGL()) + return GLFW_FALSE; if (!_glfwCreateContextWGL(window, ctxconfig, fbconfig)) return GLFW_FALSE; } else { + if (!_glfwInitEGL()) + return GLFW_FALSE; if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig)) return GLFW_FALSE; } diff --git a/src/wl_init.c b/src/wl_init.c index 5f6a2e99..44f7d0c8 100644 --- a/src/wl_init.c +++ b/src/wl_init.c @@ -600,9 +600,6 @@ int _glfwPlatformInit(void) if (!_glfwInitThreadLocalStoragePOSIX()) return GLFW_FALSE; - if (!_glfwInitEGL()) - return GLFW_FALSE; - if (!_glfwInitJoysticksLinux()) return GLFW_FALSE; diff --git a/src/wl_window.c b/src/wl_window.c index 04cbd997..dc6e0db3 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -393,6 +393,8 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, if (ctxconfig->client != GLFW_NO_API) { + if (!_glfwInitEGL()) + return GLFW_FALSE; if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig)) return GLFW_FALSE; } diff --git a/src/x11_init.c b/src/x11_init.c index c488dc3e..f7a06c1d 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -765,13 +765,9 @@ int _glfwPlatformInit(void) if (!_glfwInitThreadLocalStoragePOSIX()) return GLFW_FALSE; - if (!_glfwInitGLX()) - return GLFW_FALSE; - if (!_glfwInitJoysticksLinux()) return GLFW_FALSE; - _glfwInitEGL(); _glfwInitTimerPOSIX(); return GLFW_TRUE; diff --git a/src/x11_window.c b/src/x11_window.c index 1bcab263..6e89eb11 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1514,11 +1514,15 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, { if (ctxconfig->source == GLFW_NATIVE_CONTEXT_API) { + if (!_glfwInitGLX()) + return GLFW_FALSE; if (!_glfwChooseVisualGLX(ctxconfig, fbconfig, &visual, &depth)) return GLFW_FALSE; } else { + if (!_glfwInitEGL()) + return GLFW_FALSE; if (!_glfwChooseVisualEGL(ctxconfig, fbconfig, &visual, &depth)) return GLFW_FALSE; }