mirror of
https://github.com/SFML/SFML.git
synced 2025-01-19 15:55:13 +08:00
Fixed OpenGL entry points being loaded from OpenGL32.dll instead of failing to load if they are not provided by the vendor provided library on Windows.
This commit is contained in:
parent
2c99b3343a
commit
21af6fecf1
@ -945,29 +945,6 @@ void GlContext::initialize(const ContextSettings& requestedSettings)
|
|||||||
void GlContext::checkSettings(const ContextSettings& requestedSettings) const
|
void GlContext::checkSettings(const ContextSettings& requestedSettings) const
|
||||||
{
|
{
|
||||||
// Perform checks to inform the user if they are getting a context they might not have expected
|
// Perform checks to inform the user if they are getting a context they might not have expected
|
||||||
|
|
||||||
auto glGetStringFunc = reinterpret_cast<glGetStringFuncType>(getFunction("glGetString"));
|
|
||||||
|
|
||||||
if (!glGetStringFunc)
|
|
||||||
{
|
|
||||||
err() << "Could not load glGetString function" << std::endl;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Detect any known non-accelerated implementations and warn
|
|
||||||
const char* vendorName = reinterpret_cast<const char*>(glGetStringFunc(GL_VENDOR));
|
|
||||||
const char* rendererName = reinterpret_cast<const char*>(glGetStringFunc(GL_RENDERER));
|
|
||||||
|
|
||||||
if (vendorName && rendererName)
|
|
||||||
{
|
|
||||||
if (std::string_view(vendorName) == "Microsoft Corporation" && std::string_view(rendererName) == "GDI Generic")
|
|
||||||
{
|
|
||||||
err() << "Warning: Detected \"Microsoft Corporation GDI Generic\" OpenGL implementation" << '\n'
|
|
||||||
<< "The current OpenGL implementation is not hardware-accelerated" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int version = static_cast<int>(m_settings.majorVersion * 10u + m_settings.minorVersion);
|
int version = static_cast<int>(m_settings.majorVersion * 10u + m_settings.minorVersion);
|
||||||
int requestedVersion = static_cast<int>(requestedSettings.majorVersion * 10u + requestedSettings.minorVersion);
|
int requestedVersion = static_cast<int>(requestedSettings.majorVersion * 10u + requestedSettings.minorVersion);
|
||||||
|
|
||||||
|
@ -51,6 +51,18 @@ namespace WglContextImpl
|
|||||||
thread_local sf::priv::WglContext* currentContext(nullptr);
|
thread_local sf::priv::WglContext* currentContext(nullptr);
|
||||||
|
|
||||||
|
|
||||||
|
// We use a different loader for wgl functions since we load them directly from OpenGL32.dll
|
||||||
|
sf::GlFunctionPointer getOpenGl32Function(const char* name)
|
||||||
|
{
|
||||||
|
static const HMODULE module = GetModuleHandleA("OpenGL32.dll");
|
||||||
|
|
||||||
|
if (module)
|
||||||
|
return reinterpret_cast<sf::GlFunctionPointer>(GetProcAddress(module, reinterpret_cast<LPCSTR>(name)));
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void ensureInit()
|
void ensureInit()
|
||||||
{
|
{
|
||||||
@ -59,7 +71,7 @@ void ensureInit()
|
|||||||
{
|
{
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
|
||||||
gladLoadWGL(nullptr, sf::priv::WglContext::getFunction);
|
gladLoadWGL(nullptr, getOpenGl32Function);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +86,7 @@ void ensureExtensionsInit(HDC deviceContext)
|
|||||||
|
|
||||||
// We don't check the return value since the extension
|
// We don't check the return value since the extension
|
||||||
// flags are cleared even if loading fails
|
// flags are cleared even if loading fails
|
||||||
gladLoadWGL(deviceContext, sf::priv::WglContext::getFunction);
|
gladLoadWGL(deviceContext, getOpenGl32Function);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace WglContextImpl
|
} // namespace WglContextImpl
|
||||||
@ -186,6 +198,8 @@ WglContext::~WglContext()
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
GlFunctionPointer WglContext::getFunction(const char* name)
|
GlFunctionPointer WglContext::getFunction(const char* name)
|
||||||
{
|
{
|
||||||
|
assert(WglContextImpl::currentContext != nullptr);
|
||||||
|
|
||||||
auto address = reinterpret_cast<GlFunctionPointer>(wglGetProcAddress(reinterpret_cast<LPCSTR>(name)));
|
auto address = reinterpret_cast<GlFunctionPointer>(wglGetProcAddress(reinterpret_cast<LPCSTR>(name)));
|
||||||
|
|
||||||
if (address)
|
if (address)
|
||||||
@ -197,13 +211,9 @@ GlFunctionPointer WglContext::getFunction(const char* name)
|
|||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HMODULE module = nullptr;
|
// If we are using the generic GDI implementation, try loading directly from OpenGL32.dll as well
|
||||||
|
if (WglContextImpl::currentContext->m_isGeneric)
|
||||||
if (!module)
|
return WglContextImpl::getOpenGl32Function(name);
|
||||||
module = GetModuleHandleA("OpenGL32.dll");
|
|
||||||
|
|
||||||
if (module)
|
|
||||||
return reinterpret_cast<GlFunctionPointer>(GetProcAddress(module, reinterpret_cast<LPCSTR>(name)));
|
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -460,6 +470,20 @@ void WglContext::updateSettingsFromPixelFormat()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Detect if we are running using the generic GDI implementation and warn
|
||||||
|
if (actualFormat.dwFlags & PFD_GENERIC_FORMAT)
|
||||||
|
{
|
||||||
|
m_isGeneric = true;
|
||||||
|
|
||||||
|
err() << "Warning: Detected \"Microsoft Corporation GDI Generic\" OpenGL implementation" << std::endl;
|
||||||
|
|
||||||
|
// Detect if the generic GDI implementation is not accelerated
|
||||||
|
if (!(actualFormat.dwFlags & PFD_GENERIC_ACCELERATED))
|
||||||
|
err() << "Warning: The \"Microsoft Corporation GDI Generic\" OpenGL implementation is not "
|
||||||
|
"hardware-accelerated"
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
if (SF_GLAD_WGL_ARB_pixel_format)
|
if (SF_GLAD_WGL_ARB_pixel_format)
|
||||||
{
|
{
|
||||||
const int attributes[] = {WGL_DEPTH_BITS_ARB, WGL_STENCIL_BITS_ARB};
|
const int attributes[] = {WGL_DEPTH_BITS_ARB, WGL_STENCIL_BITS_ARB};
|
||||||
|
@ -181,6 +181,7 @@ private:
|
|||||||
HDC m_deviceContext{}; //!< Device context associated to the context
|
HDC m_deviceContext{}; //!< Device context associated to the context
|
||||||
HGLRC m_context{}; //!< OpenGL context
|
HGLRC m_context{}; //!< OpenGL context
|
||||||
bool m_ownsWindow{}; //!< Do we own the target window?
|
bool m_ownsWindow{}; //!< Do we own the target window?
|
||||||
|
bool m_isGeneric{}; //!< Is this context provided by the generic GDI implementation?
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sf::priv
|
} // namespace sf::priv
|
||||||
|
Loading…
Reference in New Issue
Block a user