From 39149998d11df61d0f0e6363cbd7feb117705eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 16 Dec 2015 22:20:36 +0100 Subject: [PATCH] Platform: actually properly implement WindowlessWglApplication. That was unprofessional from me, sorry, because it didn't even compile. When I got it to compile, it crashed right away, because I was querying GLX function instead of WGL function. But even after that it was still crashing BECAUSE APPARENTLY YOU HAVE TO CREATE CONTEXT TO BE ABLE TO CREATE CONTEXT, YO DAWG. Fuck all this GL shit. Gimme something sane already. Ugh. --- .../Platform/WindowlessWglApplication.cpp | 21 ++++++++++++++++--- .../Platform/WindowlessWglApplication.h | 6 +++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/Magnum/Platform/WindowlessWglApplication.cpp b/src/Magnum/Platform/WindowlessWglApplication.cpp index 6466607df..eb10cb980 100644 --- a/src/Magnum/Platform/WindowlessWglApplication.cpp +++ b/src/Magnum/Platform/WindowlessWglApplication.cpp @@ -104,14 +104,29 @@ bool WindowlessWglApplication::tryCreateContext(const Configuration& configurati const int pixelFormat = ChoosePixelFormat(_deviceContext, &pfd); SetPixelFormat(_deviceContext, pixelFormat, &pfd); - const int attributes = { + const int attributes[] = { WGL_CONTEXT_FLAGS_ARB, int(configuration.flags()), 0 }; - /* Create context and make it current */ - const PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = reinterpret_cast( wglGetProcAddress(reinterpret_cast("glXCreateContextAttribsARB"))); + /* Create temporary context so we are able to get the pointer to + wglCreateContextAttribsARB() */ + HGLRC temporaryContext = wglCreateContext(_deviceContext); + if(!wglMakeCurrent(_deviceContext, temporaryContext)) { + Error() << "Platform::WindowlessWglApplication::tryCreateContext(): cannot make temporary context current:" << GetLastError(); + return false; + } + + /* Get pointer to proper context creation function and create real context + with it */ + typedef HGLRC(WINAPI*PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC, HGLRC, const int*); + const PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = reinterpret_cast( wglGetProcAddress(reinterpret_cast("wglCreateContextAttribsARB"))); _renderingContext = wglCreateContextAttribsARB(_deviceContext, 0, attributes); + + /* Delete the temporary context */ + wglMakeCurrent(_deviceContext, nullptr); + wglDeleteContext(temporaryContext); + if(!_renderingContext) { Error() << "Platform::WindowlessWglApplication::tryCreateContext(): cannot create context:" << GetLastError(); return false; diff --git a/src/Magnum/Platform/WindowlessWglApplication.h b/src/Magnum/Platform/WindowlessWglApplication.h index 544879ed6..fbcd5a962 100644 --- a/src/Magnum/Platform/WindowlessWglApplication.h +++ b/src/Magnum/Platform/WindowlessWglApplication.h @@ -41,6 +41,11 @@ #include "Magnum/OpenGL.h" #include "Magnum/Platform/Platform.h" +/* Define stuff that we need because I can't be bothered with creating a new + header just for two defines */ +#define WGL_CONTEXT_FLAGS_ARB 0x2094 +#define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001 + namespace Magnum { namespace Platform { /** @@ -199,7 +204,6 @@ class WindowlessWglApplication::Configuration { #endif constexpr /*implicit*/ Configuration() {} - ~Configuration(); /** @brief Context flags */ Flags flags() const { return _flags; }