From 815baba090b79cab4a3ceff5fa248bda1f7c8e8c Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 18 Jun 2008 20:10:47 +0200 Subject: [PATCH] winex11: Check for matching pixel format in wglMakeCurrent. --- dlls/opengl32/tests/opengl.c | 28 ++++++++++++++++++++++++++++ dlls/winex11.drv/opengl.c | 7 ++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/dlls/opengl32/tests/opengl.c b/dlls/opengl32/tests/opengl.c index 46ded06c4c3..e72d1a07624 100644 --- a/dlls/opengl32/tests/opengl.c +++ b/dlls/opengl32/tests/opengl.c @@ -265,6 +265,33 @@ static void test_setpixelformat(HDC winhdc) } } +static void test_makecurrent(HDC winhdc) +{ + BOOL ret; + HGLRC hglrc; + HDC hdc; + + hdc = GetDC(0); + ok( hdc != 0, "GetDC(0) failed\n" ); + + hglrc = wglCreateContext(winhdc); + ok( hglrc != 0, "wglCreateContext failed\n" ); + + ret = wglMakeCurrent( winhdc, hglrc ); + ok( ret, "wglMakeCurrent failed\n" ); + + ok( wglGetCurrentContext() == hglrc, "wrong context\n" ); + + SetLastError( 0xdeadbeef ); + ret = wglMakeCurrent( hdc, hglrc ); + ok( !ret, "wglMakeCurrent succeeded\n" ); + ok( GetLastError() == ERROR_INVALID_PIXEL_FORMAT, "last error %u\n", GetLastError() ); + + ok( wglGetCurrentContext() == hglrc, "wrong context\n" ); + + ReleaseDC( 0, hdc ); +} + static void test_colorbits(HDC hdc) { const int iAttribList[] = { WGL_COLOR_BITS_ARB, WGL_RED_BITS_ARB, WGL_GREEN_BITS_ARB, @@ -437,6 +464,7 @@ START_TEST(opengl) ok(res, "wglMakeCurrent failed!\n"); init_functions(); + test_makecurrent(hdc); test_setpixelformat(hdc); test_colorbits(hdc); test_gdi_dbuf(hdc); diff --git a/dlls/winex11.drv/opengl.c b/dlls/winex11.drv/opengl.c index 393c11a2f0f..b6e88ea1db6 100644 --- a/dlls/winex11.drv/opengl.c +++ b/dlls/winex11.drv/opengl.c @@ -1754,6 +1754,7 @@ BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) { BOOL ret; HDC hdc = physDev->hdc; DWORD type = GetObjectType(hdc); + Wine_GLContext *ctx = (Wine_GLContext *) hglrc; TRACE("(%p,%p)\n", hdc, hglrc); @@ -1766,8 +1767,12 @@ BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) { if (hglrc == NULL) { ret = pglXMakeCurrent(gdi_display, None, NULL); NtCurrentTeb()->glContext = NULL; + } else if (ctx->fmt->iPixelFormat != physDev->current_pf) { + WARN( "mismatched pixel format hdc %p %u ctx %p %u\n", + hdc, physDev->current_pf, ctx, ctx->fmt->iPixelFormat ); + SetLastError( ERROR_INVALID_PIXEL_FORMAT ); + ret = FALSE; } else { - Wine_GLContext *ctx = (Wine_GLContext *) hglrc; Drawable drawable = get_glxdrawable(physDev); if (ctx->ctx == NULL) { /* The describe lines below are for debugging purposes only */