From 0793032ece45b35080eddf3f97496a67b94d449a Mon Sep 17 00:00:00 2001 From: offtkp Date: Sat, 10 Aug 2024 20:05:25 +0300 Subject: [PATCH] Update windows createpbuffer implementation to latest from duckstation --- third_party/duckstation/gl/context_wgl.cpp | 31 ++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/third_party/duckstation/gl/context_wgl.cpp b/third_party/duckstation/gl/context_wgl.cpp index 47ec4b1e..b2e0d2e5 100644 --- a/third_party/duckstation/gl/context_wgl.cpp +++ b/third_party/duckstation/gl/context_wgl.cpp @@ -149,8 +149,8 @@ std::unique_ptr ContextWGL::CreateSharedContext(const WindowInfo& wi) } else { - Log_ErrorPrint("PBuffer not implemented"); - return nullptr; + if (!context->CreatePBuffer()) + return nullptr; } if (m_version.profile == Profile::NoProfile) @@ -305,6 +305,32 @@ bool ContextWGL::CreatePBuffer() static constexpr const int pb_attribs[] = {0, 0}; + HGLRC temp_rc = nullptr; + ScopedGuard temp_rc_guard([&temp_rc, hdc]() { + if (temp_rc) + { + wglMakeCurrent(hdc, nullptr); + wglDeleteContext(temp_rc); + } + }); + + if (!GLAD_WGL_ARB_pbuffer) + { + // we're probably running completely surfaceless... need a temporary context. + temp_rc = wglCreateContext(hdc); + if (!temp_rc || !wglMakeCurrent(hdc, temp_rc)) + { + Log_ErrorPrint("Failed to create temporary context to load WGL for pbuffer."); + return false; + } + + if (!ReloadWGL(hdc) || !GLAD_WGL_ARB_pbuffer) + { + Log_ErrorPrint("Missing WGL_ARB_pbuffer"); + return false; + } + } + AssertMsg(m_pixel_format.has_value(), "Has pixel format for pbuffer"); HPBUFFERARB pbuffer = wglCreatePbufferARB(hdc, m_pixel_format.value(), 1, 1, pb_attribs); if (!pbuffer) @@ -326,6 +352,7 @@ bool ContextWGL::CreatePBuffer() m_dummy_dc = hdc; m_pbuffer = pbuffer; + temp_rc_guard.Run(); pbuffer_guard.Cancel(); hdc_guard.Cancel(); hwnd_guard.Cancel();