mirror of https://github.com/PCSX2/pcsx2.git
gsdx wgl: drop GL2.0 context and avoid a context leak
Namely detach/delete context before throwing
This commit is contained in:
parent
cdb71101a1
commit
674d22321a
|
@ -47,12 +47,14 @@ LRESULT CALLBACK GSWndWGL::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA
|
||||||
|
|
||||||
void GSWndWGL::CreateContext(int major, int minor)
|
void GSWndWGL::CreateContext(int major, int minor)
|
||||||
{
|
{
|
||||||
if ( !m_NativeDisplay || !m_NativeWindow )
|
if (!m_NativeDisplay || !m_NativeWindow)
|
||||||
{
|
{
|
||||||
fprintf( stderr, "Wrong display/window\n" );
|
fprintf( stderr, "Wrong display/window\n" );
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ASSERT(major >= 3);
|
||||||
|
|
||||||
// GL2 context are quite easy but we need GL3 which is another painful story...
|
// GL2 context are quite easy but we need GL3 which is another painful story...
|
||||||
m_context = wglCreateContext(m_NativeDisplay);
|
m_context = wglCreateContext(m_NativeDisplay);
|
||||||
if (!m_context) {
|
if (!m_context) {
|
||||||
|
@ -63,53 +65,52 @@ void GSWndWGL::CreateContext(int major, int minor)
|
||||||
// FIXME test it
|
// FIXME test it
|
||||||
// Note: albeit every tutorial said that we need an opengl context to use the GL function wglCreateContextAttribsARB
|
// Note: albeit every tutorial said that we need an opengl context to use the GL function wglCreateContextAttribsARB
|
||||||
// On linux it works without the extra temporary context, not sure the limitation still applied
|
// On linux it works without the extra temporary context, not sure the limitation still applied
|
||||||
if (major >= 3) {
|
AttachContext();
|
||||||
AttachContext();
|
|
||||||
|
|
||||||
// Create a context
|
// Create a context
|
||||||
int context_attribs[] =
|
int context_attribs[] =
|
||||||
{
|
{
|
||||||
WGL_CONTEXT_MAJOR_VERSION_ARB, major,
|
WGL_CONTEXT_MAJOR_VERSION_ARB, major,
|
||||||
WGL_CONTEXT_MINOR_VERSION_ARB, minor,
|
WGL_CONTEXT_MINOR_VERSION_ARB, minor,
|
||||||
// FIXME : Request a debug context to ease opengl development
|
// FIXME : Request a debug context to ease opengl development
|
||||||
// Note: don't support deprecated feature (pre openg 3.1)
|
// Note: don't support deprecated feature (pre openg 3.1)
|
||||||
//GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB | GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
|
//GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB | GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
|
||||||
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
|
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
|
||||||
#ifdef ENABLE_OGL_DEBUG
|
#ifdef ENABLE_OGL_DEBUG
|
||||||
| WGL_CONTEXT_DEBUG_BIT_ARB
|
| WGL_CONTEXT_DEBUG_BIT_ARB
|
||||||
#else
|
#else
|
||||||
| GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR
|
| GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR
|
||||||
#endif
|
#endif
|
||||||
,
|
,
|
||||||
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
|
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
|
||||||
if (!wglCreateContextAttribsARB) {
|
if (!wglCreateContextAttribsARB) {
|
||||||
fprintf(stderr, "Failed to init wglCreateContextAttribsARB function pointer\n");
|
fprintf(stderr, "Failed to init wglCreateContextAttribsARB function pointer\n");
|
||||||
throw GSDXRecoverableError();
|
throw GSDXRecoverableError();
|
||||||
}
|
|
||||||
|
|
||||||
HGLRC context30 = wglCreateContextAttribsARB(m_NativeDisplay, NULL, context_attribs);
|
|
||||||
if (!context30) {
|
|
||||||
fprintf(stderr, "Failed to create a 3.x context with standard flags\n");
|
|
||||||
// retry with more compatible option for (Mesa on Windows, OpenGL on WINE)
|
|
||||||
context_attribs[2*2+1] = 0;
|
|
||||||
|
|
||||||
context30 = wglCreateContextAttribsARB(m_NativeDisplay, NULL, context_attribs);
|
|
||||||
if (!context30) {
|
|
||||||
fprintf(stderr, "Failed to create a 3.x context with compatible flags\n");
|
|
||||||
throw GSDXRecoverableError();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DetachContext();
|
|
||||||
wglDeleteContext(m_context);
|
|
||||||
|
|
||||||
m_context = context30;
|
|
||||||
fprintf(stderr, "3.x GL context successfully created\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HGLRC context30 = wglCreateContextAttribsARB(m_NativeDisplay, NULL, context_attribs);
|
||||||
|
if (!context30) {
|
||||||
|
fprintf(stderr, "Failed to create a 3.x context with standard flags\n");
|
||||||
|
// retry with more compatible option for (Mesa on Windows, OpenGL on WINE)
|
||||||
|
context_attribs[2*2+1] = 0;
|
||||||
|
|
||||||
|
context30 = wglCreateContextAttribsARB(m_NativeDisplay, NULL, context_attribs);
|
||||||
|
}
|
||||||
|
|
||||||
|
DetachContext();
|
||||||
|
wglDeleteContext(m_context);
|
||||||
|
|
||||||
|
if (!context30) {
|
||||||
|
fprintf(stderr, "Failed to create a 3.x context with compatible flags\n");
|
||||||
|
throw GSDXRecoverableError();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_context = context30;
|
||||||
|
fprintf(stderr, "3.x GL context successfully created\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GSWndWGL::AttachContext()
|
void GSWndWGL::AttachContext()
|
||||||
|
|
Loading…
Reference in New Issue