From 61aeff13c922bdc3a4147d71829e36528e6b121f Mon Sep 17 00:00:00 2001 From: binary1248 Date: Thu, 6 Apr 2023 04:00:01 +0200 Subject: [PATCH] Fixed wglGetProcAddress not providing OpenGL 1.1 functions when the context is provided by an Nvidia ICD. --- src/SFML/Window/Win32/WglContext.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/SFML/Window/Win32/WglContext.cpp b/src/SFML/Window/Win32/WglContext.cpp index 7d6016e3a..57618553f 100644 --- a/src/SFML/Window/Win32/WglContext.cpp +++ b/src/SFML/Window/Win32/WglContext.cpp @@ -86,7 +86,7 @@ void ensureExtensionsInit(HDC deviceContext) // We don't check the return value since the extension // flags are cleared even if loading fails - gladLoadWGL(deviceContext, getOpenGl32Function); + gladLoadWGL(deviceContext, sf::priv::WglContext::getFunction); } } } // namespace WglContextImpl @@ -200,22 +200,22 @@ GlFunctionPointer WglContext::getFunction(const char* name) { assert(WglContextImpl::currentContext != nullptr); - auto address = reinterpret_cast(wglGetProcAddress(reinterpret_cast(name))); - - if (address) + // If we are using the generic GDI implementation, skip to loading directly from OpenGL32.dll since it doesn't support extensions + if (!WglContextImpl::currentContext->m_isGeneric) { - // Test whether the returned value is a valid error code - auto errorCode = reinterpret_cast(address); + auto address = reinterpret_cast(wglGetProcAddress(reinterpret_cast(name))); - if ((errorCode != -1) && (errorCode != 1) && (errorCode != 2) && (errorCode != 3)) - return address; + if (address) + { + // Test whether the returned value is a valid error code + auto errorCode = reinterpret_cast(address); + + if ((errorCode != -1) && (errorCode != 1) && (errorCode != 2) && (errorCode != 3)) + return address; + } } - // If we are using the generic GDI implementation, try loading directly from OpenGL32.dll as well - if (WglContextImpl::currentContext->m_isGeneric) - return WglContextImpl::getOpenGl32Function(name); - - return nullptr; + return WglContextImpl::getOpenGl32Function(name); }