2 * Some tests for OpenGL functions
4 * Copyright (C) 2007-2008 Roderick Colenbrander
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/test.h"
25 void WINAPI glClearColor(float red, float green, float blue, float alpha);
26 void WINAPI glClear(unsigned int mask);
27 #define GL_COLOR 0x1800
28 typedef unsigned int GLenum;
30 void WINAPI glCopyPixels(int x, int y, int width, int height, GLenum type);
31 void WINAPI glFinish(void);
32 #define GL_NO_ERROR 0x0
33 #define GL_INVALID_OPERATION 0x502
34 GLenum WINAPI glGetError(void);
35 #define GL_COLOR_BUFFER_BIT 0x00004000
36 const unsigned char * WINAPI glGetString(unsigned int);
37 #define GL_VENDOR 0x1F00
38 #define GL_RENDERER 0x1F01
39 #define GL_VERSION 0x1F02
40 #define GL_EXTENSIONS 0x1F03
42 #define GL_VIEWPORT 0x0ba2
43 void WINAPI glGetIntegerv(GLenum pname, GLint *params);
45 #define MAX_FORMATS 256
46 typedef void* HPBUFFERARB;
48 /* WGL_ARB_create_context */
49 static HGLRC (WINAPI *pwglCreateContextAttribsARB)(HDC hDC, HGLRC hShareContext, const int *attribList);
51 #define ERROR_INVALID_VERSION_ARB 0x2095
52 #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
53 #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
54 #define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
55 #define WGL_CONTEXT_FLAGS_ARB 0x2094
56 /* Flags for WGL_CONTEXT_FLAGS_ARB */
57 #define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
58 #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
60 /* WGL_ARB_extensions_string */
61 static const char* (WINAPI *pwglGetExtensionsStringARB)(HDC);
62 static int (WINAPI *pwglReleasePbufferDCARB)(HPBUFFERARB, HDC);
64 /* WGL_ARB_make_current_read */
65 static BOOL (WINAPI *pwglMakeContextCurrentARB)(HDC hdraw, HDC hread, HGLRC hglrc);
66 static HDC (WINAPI *pwglGetCurrentReadDCARB)(void);
68 /* WGL_ARB_pixel_format */
69 #define WGL_ACCELERATION_ARB 0x2003
70 #define WGL_COLOR_BITS_ARB 0x2014
71 #define WGL_RED_BITS_ARB 0x2015
72 #define WGL_GREEN_BITS_ARB 0x2017
73 #define WGL_BLUE_BITS_ARB 0x2019
74 #define WGL_ALPHA_BITS_ARB 0x201B
75 #define WGL_SUPPORT_GDI_ARB 0x200F
76 #define WGL_DOUBLE_BUFFER_ARB 0x2011
77 #define WGL_NO_ACCELERATION_ARB 0x2025
78 #define WGL_GENERIC_ACCELERATION_ARB 0x2026
79 #define WGL_FULL_ACCELERATION_ARB 0x2027
81 static BOOL (WINAPI *pwglChoosePixelFormatARB)(HDC, const int *, const FLOAT *, UINT, int *, UINT *);
82 static BOOL (WINAPI *pwglGetPixelFormatAttribivARB)(HDC, int, int, UINT, const int *, int *);
85 #define WGL_DRAW_TO_PBUFFER_ARB 0x202D
86 static HPBUFFERARB* (WINAPI *pwglCreatePbufferARB)(HDC, int, int, int, const int *);
87 static HDC (WINAPI *pwglGetPbufferDCARB)(HPBUFFERARB);
89 static const char* wgl_extensions = NULL;
91 static void init_functions(void)
93 #define GET_PROC(func) \
94 p ## func = (void*)wglGetProcAddress(#func); \
96 trace("wglGetProcAddress(%s) failed\n", #func);
98 /* WGL_ARB_create_context */
99 GET_PROC(wglCreateContextAttribsARB);
101 /* WGL_ARB_extensions_string */
102 GET_PROC(wglGetExtensionsStringARB)
104 /* WGL_ARB_make_current_read */
105 GET_PROC(wglMakeContextCurrentARB);
106 GET_PROC(wglGetCurrentReadDCARB);
108 /* WGL_ARB_pixel_format */
109 GET_PROC(wglChoosePixelFormatARB)
110 GET_PROC(wglGetPixelFormatAttribivARB)
112 /* WGL_ARB_pbuffer */
113 GET_PROC(wglCreatePbufferARB)
114 GET_PROC(wglGetPbufferDCARB)
115 GET_PROC(wglReleasePbufferDCARB)
120 static BOOL gl_extension_supported(const char *extensions, const char *extension_string)
122 size_t ext_str_len = strlen(extension_string);
129 while (isspace(*extensions))
132 while (!isspace(*extensions) && *extensions)
135 len = extensions - start;
139 if (len == ext_str_len && !memcmp(start, extension_string, ext_str_len))
147 static void test_pbuffers(HDC hdc)
149 const int iAttribList[] = { WGL_DRAW_TO_PBUFFER_ARB, 1, /* Request pbuffer support */
151 int iFormats[MAX_FORMATS];
152 unsigned int nOnscreenFormats;
153 unsigned int nFormats;
155 int iPixelFormat = 0;
157 nOnscreenFormats = DescribePixelFormat(hdc, 0, 0, NULL);
159 /* When you want to render to a pbuffer you need to call wglGetPbufferDCARB which
160 * returns a 'magic' HDC which you can then pass to wglMakeCurrent to switch rendering
161 * to the pbuffer. Below some tests are performed on what happens if you use standard WGL calls
162 * on this 'magic' HDC for both a pixelformat that support onscreen and offscreen rendering
163 * and a pixelformat that's only available for offscreen rendering (this means that only
164 * wglChoosePixelFormatARB and friends know about the format.
166 * The first thing we need are pixelformats with pbuffer capabilities.
168 res = pwglChoosePixelFormatARB(hdc, iAttribList, NULL, MAX_FORMATS, iFormats, &nFormats);
171 skip("No pbuffer compatible formats found while WGL_ARB_pbuffer is supported\n");
174 trace("nOnscreenFormats: %d\n", nOnscreenFormats);
175 trace("Total number of pbuffer capable pixelformats: %d\n", nFormats);
177 /* Try to select an onscreen pixelformat out of the list */
178 for(i=0; i < nFormats; i++)
180 /* Check if the format is onscreen, if it is choose it */
181 if(iFormats[i] <= nOnscreenFormats)
183 iPixelFormat = iFormats[i];
184 trace("Selected iPixelFormat=%d\n", iPixelFormat);
189 /* A video driver supports a large number of onscreen and offscreen pixelformats.
190 * The traditional WGL calls only see a subset of the whole pixelformat list. First
191 * of all they only see the onscreen formats (the offscreen formats are at the end of the
192 * pixelformat list) and second extended pixelformat capabilities are hidden from the
193 * standard WGL calls. Only functions that depend on WGL_ARB_pixel_format can see them.
195 * Below we check if the pixelformat is also supported onscreen.
197 if(iPixelFormat != 0)
200 HPBUFFERARB pbuffer = pwglCreatePbufferARB(hdc, iPixelFormat, 640 /* width */, 480 /* height */, NULL);
202 skip("Pbuffer creation failed!\n");
204 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
205 pbuffer_hdc = pwglGetPbufferDCARB(pbuffer);
206 res = GetPixelFormat(pbuffer_hdc);
207 ok(res == iPixelFormat, "Unexpected iPixelFormat=%d returned by GetPixelFormat for format %d\n", res, iPixelFormat);
208 trace("iPixelFormat returned by GetPixelFormat: %d\n", res);
209 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat);
211 pwglReleasePbufferDCARB(pbuffer, hdc);
213 else skip("Pbuffer test for onscreen pixelformat skipped as no onscreen format with pbuffer capabilities have been found\n");
215 /* Search for a real offscreen format */
216 for(i=0, iPixelFormat=0; i<nFormats; i++)
218 if(iFormats[i] > nOnscreenFormats)
220 iPixelFormat = iFormats[i];
221 trace("Selected iPixelFormat: %d\n", iPixelFormat);
226 if(iPixelFormat != 0)
229 HPBUFFERARB pbuffer = pwglCreatePbufferARB(hdc, iPixelFormat, 640 /* width */, 480 /* height */, NULL);
231 skip("Pbuffer creation failed!\n");
233 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
234 pbuffer_hdc = pwglGetPbufferDCARB(pbuffer);
235 res = GetPixelFormat(pbuffer_hdc);
237 ok(res == 1, "Unexpected iPixelFormat=%d (1 expected) returned by GetPixelFormat for offscreen format %d\n", res, iPixelFormat);
238 trace("iPixelFormat returned by GetPixelFormat: %d\n", res);
239 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat);
240 pwglReleasePbufferDCARB(pbuffer, hdc);
242 else skip("Pbuffer test for offscreen pixelformat skipped as no offscreen-only format with pbuffer capabilities has been found\n");
245 static void test_setpixelformat(HDC winhdc)
252 PIXELFORMATDESCRIPTOR pfd = {
253 sizeof(PIXELFORMATDESCRIPTOR),
259 24, /* 24-bit color depth */
260 0, 0, 0, 0, 0, 0, /* color bits */
261 0, /* alpha buffer */
263 0, /* accumulation buffer */
264 0, 0, 0, 0, /* accum bits */
266 0, /* stencil buffer */
267 0, /* auxiliary buffer */
268 PFD_MAIN_PLANE, /* main layer */
270 0, 0, 0 /* layer masks */
274 ok(hdc != 0, "GetDC(0) failed!\n");
276 /* This should pass even on the main device context */
277 pf = ChoosePixelFormat(hdc, &pfd);
278 ok(pf != 0, "ChoosePixelFormat failed on main device context\n");
280 /* SetPixelFormat on the main device context 'X root window' should fail,
281 * but some broken drivers allow it
283 res = SetPixelFormat(hdc, pf, &pfd);
284 trace("SetPixelFormat on main device context %s\n", res ? "succeeded" : "failed");
286 /* Setting the same format that was set on the HDC is allowed; other
288 nCfgs = DescribePixelFormat(winhdc, 0, 0, NULL);
289 pf = GetPixelFormat(winhdc);
290 for(i = 1;i <= nCfgs;i++)
292 int res = SetPixelFormat(winhdc, i, NULL);
293 if(i == pf) ok(res, "Failed to set the same pixel format\n");
294 else ok(!res, "Unexpectedly set an alternate pixel format\n");
297 hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW,
298 10, 10, 200, 200, NULL, NULL, NULL, NULL);
299 ok(hwnd != NULL, "err: %d\n", GetLastError());
302 HDC hdc = GetDC( hwnd );
303 pf = ChoosePixelFormat( hdc, &pfd );
304 ok( pf != 0, "ChoosePixelFormat failed\n" );
305 res = SetPixelFormat( hdc, pf, &pfd );
306 ok( res != 0, "SetPixelFormat failed\n" );
307 i = GetPixelFormat( hdc );
308 ok( i == pf, "GetPixelFormat returned wrong format %d/%d\n", i, pf );
309 ReleaseDC( hwnd, hdc );
310 hdc = GetWindowDC( hwnd );
311 i = GetPixelFormat( hdc );
312 ok( i == pf, "GetPixelFormat returned wrong format %d/%d\n", i, pf );
313 ReleaseDC( hwnd, hdc );
314 DestroyWindow( hwnd );
317 hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW,
318 10, 10, 200, 200, NULL, NULL, NULL, NULL);
319 ok(hwnd != NULL, "err: %d\n", GetLastError());
322 HDC hdc = GetWindowDC( hwnd );
323 pf = ChoosePixelFormat( hdc, &pfd );
324 ok( pf != 0, "ChoosePixelFormat failed\n" );
325 res = SetPixelFormat( hdc, pf, &pfd );
326 ok( res != 0, "SetPixelFormat failed\n" );
327 i = GetPixelFormat( hdc );
328 ok( i == pf, "GetPixelFormat returned wrong format %d/%d\n", i, pf );
329 ReleaseDC( hwnd, hdc );
330 DestroyWindow( hwnd );
334 static void test_sharelists(HDC winhdc)
336 HGLRC hglrc1, hglrc2, hglrc3;
339 hglrc1 = wglCreateContext(winhdc);
340 res = wglShareLists(0, 0);
341 ok(res == FALSE, "Sharing display lists for no contexts passed!\n");
343 /* Test 1: Create a context and just share lists without doing anything special */
344 hglrc2 = wglCreateContext(winhdc);
347 res = wglShareLists(hglrc1, hglrc2);
348 ok(res, "Sharing of display lists failed\n");
349 wglDeleteContext(hglrc2);
352 /* Test 2: Share display lists with a 'destination' context which has been made current */
353 hglrc2 = wglCreateContext(winhdc);
356 res = wglMakeCurrent(winhdc, hglrc2);
357 ok(res, "Make current failed\n");
358 res = wglShareLists(hglrc1, hglrc2);
359 todo_wine ok(res, "Sharing display lists with a destination context which has been made current failed\n");
360 wglMakeCurrent(0, 0);
361 wglDeleteContext(hglrc2);
364 /* Test 3: Share display lists with a context which already shares display lists with another context.
365 * According to MSDN the second parameter cannot share any display lists but some buggy drivers might allow it */
366 hglrc3 = wglCreateContext(winhdc);
369 res = wglShareLists(hglrc3, hglrc1);
370 ok(res == FALSE, "Sharing of display lists passed for a context which already shared lists before\n");
371 wglDeleteContext(hglrc3);
374 /* Test 4: Share display lists with a 'source' context which has been made current */
375 hglrc2 = wglCreateContext(winhdc);
378 res = wglMakeCurrent(winhdc, hglrc1);
379 ok(res, "Make current failed\n");
380 res = wglShareLists(hglrc1, hglrc2);
381 ok(res, "Sharing display lists with a source context which has been made current failed\n");
382 wglMakeCurrent(0, 0);
383 wglDeleteContext(hglrc2);
387 static void test_makecurrent(HDC winhdc)
392 hglrc = wglCreateContext(winhdc);
393 ok( hglrc != 0, "wglCreateContext failed\n" );
395 ret = wglMakeCurrent( winhdc, hglrc );
396 ok( ret, "wglMakeCurrent failed\n" );
398 ok( wglGetCurrentContext() == hglrc, "wrong context\n" );
400 /* set the same context again */
401 ret = wglMakeCurrent( winhdc, hglrc );
402 ok( ret, "wglMakeCurrent failed\n" );
404 /* check wglMakeCurrent(x, y) after another call to wglMakeCurrent(x, y) */
405 ret = wglMakeCurrent( winhdc, NULL );
406 ok( ret, "wglMakeCurrent failed\n" );
408 ret = wglMakeCurrent( winhdc, NULL );
409 ok( ret, "wglMakeCurrent failed\n" );
411 SetLastError( 0xdeadbeef );
412 ret = wglMakeCurrent( NULL, NULL );
413 ok( !ret || broken(ret) /* nt4 */, "wglMakeCurrent succeeded\n" );
414 if (!ret) ok( GetLastError() == ERROR_INVALID_HANDLE,
415 "Expected ERROR_INVALID_HANDLE, got error=%x\n", GetLastError() );
417 ret = wglMakeCurrent( winhdc, NULL );
418 ok( ret, "wglMakeCurrent failed\n" );
420 ret = wglMakeCurrent( winhdc, hglrc );
421 ok( ret, "wglMakeCurrent failed\n" );
423 ret = wglMakeCurrent( NULL, NULL );
424 ok( ret, "wglMakeCurrent failed\n" );
426 ok( wglGetCurrentContext() == NULL, "wrong context\n" );
428 SetLastError( 0xdeadbeef );
429 ret = wglMakeCurrent( NULL, NULL );
430 ok( !ret || broken(ret) /* nt4 */, "wglMakeCurrent succeeded\n" );
431 if (!ret) ok( GetLastError() == ERROR_INVALID_HANDLE,
432 "Expected ERROR_INVALID_HANDLE, got error=%x\n", GetLastError() );
434 ret = wglMakeCurrent( winhdc, hglrc );
435 ok( ret, "wglMakeCurrent failed\n" );
438 static void test_colorbits(HDC hdc)
440 const int iAttribList[] = { WGL_COLOR_BITS_ARB, WGL_RED_BITS_ARB, WGL_GREEN_BITS_ARB,
441 WGL_BLUE_BITS_ARB, WGL_ALPHA_BITS_ARB };
442 int iAttribRet[sizeof(iAttribList)/sizeof(iAttribList[0])];
443 const int iAttribs[] = { WGL_ALPHA_BITS_ARB, 1, 0 };
444 unsigned int nFormats;
446 int iPixelFormat = 0;
448 if (!pwglChoosePixelFormatARB)
450 win_skip("wglChoosePixelFormatARB is not available\n");
454 /* We need a pixel format with at least one bit of alpha */
455 res = pwglChoosePixelFormatARB(hdc, iAttribs, NULL, 1, &iPixelFormat, &nFormats);
456 if(res == FALSE || nFormats == 0)
458 skip("No suitable pixel formats found\n");
462 res = pwglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0,
463 sizeof(iAttribList)/sizeof(iAttribList[0]), iAttribList, iAttribRet);
466 skip("wglGetPixelFormatAttribivARB failed\n");
469 iAttribRet[1] += iAttribRet[2]+iAttribRet[3]+iAttribRet[4];
470 ok(iAttribRet[0] == iAttribRet[1], "WGL_COLOR_BITS_ARB (%d) does not equal R+G+B+A (%d)!\n",
471 iAttribRet[0], iAttribRet[1]);
474 static void test_gdi_dbuf(HDC hdc)
476 const int iAttribList[] = { WGL_SUPPORT_GDI_ARB, WGL_DOUBLE_BUFFER_ARB };
477 int iAttribRet[sizeof(iAttribList)/sizeof(iAttribList[0])];
478 unsigned int nFormats;
482 if (!pwglGetPixelFormatAttribivARB)
484 win_skip("wglGetPixelFormatAttribivARB is not available\n");
488 nFormats = DescribePixelFormat(hdc, 0, 0, NULL);
489 for(iPixelFormat = 1;iPixelFormat <= nFormats;iPixelFormat++)
491 res = pwglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0,
492 sizeof(iAttribList)/sizeof(iAttribList[0]), iAttribList,
494 ok(res!=FALSE, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat);
498 ok(!(iAttribRet[0] && iAttribRet[1]), "GDI support and double buffering on pixel format %d\n", iPixelFormat);
502 static void test_acceleration(HDC hdc)
504 const int iAttribList[] = { WGL_ACCELERATION_ARB };
505 int iAttribRet[sizeof(iAttribList)/sizeof(iAttribList[0])];
506 unsigned int nFormats;
509 PIXELFORMATDESCRIPTOR pfd;
511 if (!pwglGetPixelFormatAttribivARB)
513 win_skip("wglGetPixelFormatAttribivARB is not available\n");
517 nFormats = DescribePixelFormat(hdc, 0, 0, NULL);
518 for(iPixelFormat = 1; iPixelFormat <= nFormats; iPixelFormat++)
520 res = pwglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0,
521 sizeof(iAttribList)/sizeof(iAttribList[0]), iAttribList,
523 ok(res!=FALSE, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat);
527 memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
528 DescribePixelFormat(hdc, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
530 switch(iAttribRet[0])
532 case WGL_NO_ACCELERATION_ARB:
533 ok( (pfd.dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED)) == PFD_GENERIC_FORMAT , "Expected only PFD_GENERIC_FORMAT to be set for WGL_NO_ACCELERATION_ARB!: iPixelFormat=%d, dwFlags=%x!\n", iPixelFormat, pfd.dwFlags);
535 case WGL_GENERIC_ACCELERATION_ARB:
536 ok( (pfd.dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED)) == (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED), "Expected both PFD_GENERIC_FORMAT and PFD_GENERIC_ACCELERATION to be set for WGL_GENERIC_ACCELERATION_ARB: iPixelFormat=%d, dwFlags=%x!\n", iPixelFormat, pfd.dwFlags);
538 case WGL_FULL_ACCELERATION_ARB:
539 ok( (pfd.dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED)) == 0, "Expected no PFD_GENERIC_FORMAT/_ACCELERATION to be set for WGL_FULL_ACCELERATION_ARB: iPixelFormat=%d, dwFlags=%x!\n", iPixelFormat, pfd.dwFlags);
545 static void test_bitmap_rendering( BOOL use_dib )
547 PIXELFORMATDESCRIPTOR pfd;
548 int i, ret, bpp, iPixelFormat=0;
549 unsigned int nFormats;
552 HBITMAP bmpDst, oldDst, bmp2;
553 HDC hdcDst, hdcScreen;
554 UINT *dstBuffer = NULL;
556 hdcScreen = CreateCompatibleDC(0);
557 hdcDst = CreateCompatibleDC(0);
562 memset(&biDst, 0, sizeof(BITMAPINFO));
563 biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
564 biDst.bmiHeader.biWidth = 4;
565 biDst.bmiHeader.biHeight = -4;
566 biDst.bmiHeader.biPlanes = 1;
567 biDst.bmiHeader.biBitCount = 32;
568 biDst.bmiHeader.biCompression = BI_RGB;
570 bmpDst = CreateDIBSection(0, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer, NULL, 0);
572 biDst.bmiHeader.biWidth = 12;
573 biDst.bmiHeader.biHeight = -12;
574 biDst.bmiHeader.biBitCount = 16;
575 bmp2 = CreateDIBSection(0, &biDst, DIB_RGB_COLORS, NULL, NULL, 0);
579 bpp = GetDeviceCaps( hdcScreen, BITSPIXEL );
580 bmpDst = CreateBitmap( 4, 4, 1, bpp, NULL );
581 bmp2 = CreateBitmap( 12, 12, 1, bpp, NULL );
584 oldDst = SelectObject(hdcDst, bmpDst);
586 trace( "testing on %s\n", use_dib ? "DIB" : "DDB" );
588 /* Pick a pixel format by hand because ChoosePixelFormat is unreliable */
589 nFormats = DescribePixelFormat(hdcDst, 0, 0, NULL);
590 for(i=1; i<=nFormats; i++)
592 memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
593 DescribePixelFormat(hdcDst, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
595 if((pfd.dwFlags & PFD_DRAW_TO_BITMAP) &&
596 (pfd.dwFlags & PFD_SUPPORT_OPENGL) &&
597 (pfd.cColorBits == bpp) &&
598 (pfd.cAlphaBits == 8) )
607 skip("Unable to find a suitable pixel format\n");
611 ret = SetPixelFormat(hdcDst, iPixelFormat, &pfd);
612 ok( ret, "SetPixelFormat failed\n" );
613 ret = GetPixelFormat( hdcDst );
614 ok( ret == iPixelFormat, "GetPixelFormat returned %d/%d\n", ret, iPixelFormat );
615 ret = SetPixelFormat(hdcDst, iPixelFormat + 1, &pfd);
616 ok( !ret, "SetPixelFormat succeeded\n" );
617 hglrc = wglCreateContext(hdcDst);
618 ok(hglrc != NULL, "Unable to create a context\n");
623 wglMakeCurrent(hdcDst, hglrc);
624 hglrc2 = wglCreateContext(hdcDst);
625 ok(hglrc2 != NULL, "Unable to create a context\n");
627 /* Note this is RGBA but we read ARGB back */
628 glClearColor((float)0x22/0xff, (float)0x33/0xff, (float)0x44/0xff, (float)0x11/0xff);
629 glClear(GL_COLOR_BUFFER_BIT);
630 glGetIntegerv( GL_VIEWPORT, viewport );
633 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 4 && viewport[3] == 4,
634 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
635 /* Note apparently the alpha channel is not supported by the software renderer (bitmap only works using software) */
637 for (i = 0; i < 16; i++)
638 ok(dstBuffer[i] == 0x223344 || dstBuffer[i] == 0x11223344, "Received color=%x at %u\n",
641 SelectObject(hdcDst, bmp2);
642 ret = GetPixelFormat( hdcDst );
643 ok( ret == iPixelFormat, "GetPixelFormat returned %d/%d\n", ret, iPixelFormat );
644 ret = SetPixelFormat(hdcDst, iPixelFormat + 1, &pfd);
645 ok( !ret, "SetPixelFormat succeeded\n" );
647 /* context still uses the old pixel format and viewport */
648 glClearColor((float)0x44/0xff, (float)0x33/0xff, (float)0x22/0xff, (float)0x11/0xff);
649 glClear(GL_COLOR_BUFFER_BIT);
651 glGetIntegerv( GL_VIEWPORT, viewport );
652 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 4 && viewport[3] == 4,
653 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
655 wglMakeCurrent(NULL, NULL);
656 wglMakeCurrent(hdcDst, hglrc);
657 glClearColor((float)0x44/0xff, (float)0x55/0xff, (float)0x66/0xff, (float)0x11/0xff);
658 glClear(GL_COLOR_BUFFER_BIT);
660 glGetIntegerv( GL_VIEWPORT, viewport );
661 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 4 && viewport[3] == 4,
662 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
664 wglMakeCurrent(hdcDst, hglrc2);
665 glGetIntegerv( GL_VIEWPORT, viewport );
666 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 12 && viewport[3] == 12,
667 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
669 wglMakeCurrent(hdcDst, hglrc);
670 glGetIntegerv( GL_VIEWPORT, viewport );
671 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 4 && viewport[3] == 4,
672 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
674 SelectObject(hdcDst, bmpDst);
675 ret = GetPixelFormat( hdcDst );
676 ok( ret == iPixelFormat, "GetPixelFormat returned %d/%d\n", ret, iPixelFormat );
677 ret = SetPixelFormat(hdcDst, iPixelFormat + 1, &pfd);
678 ok( !ret, "SetPixelFormat succeeded\n" );
679 wglMakeCurrent(hdcDst, hglrc2);
680 glGetIntegerv( GL_VIEWPORT, viewport );
681 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 12 && viewport[3] == 12,
682 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
686 SelectObject(hdcDst, oldDst);
688 DeleteObject(bmpDst);
693 struct wgl_thread_param
695 HANDLE test_finished;
699 BOOL make_current_error;
704 static DWORD WINAPI wgl_thread(void *param)
706 struct wgl_thread_param *p = param;
707 HDC hdc = GetDC( p->hwnd );
709 SetLastError(0xdeadbeef);
710 p->make_current = wglMakeCurrent(hdc, p->hglrc);
711 p->make_current_error = GetLastError();
712 p->deleted = wglDeleteContext(p->hglrc);
713 p->deleted_error = GetLastError();
714 ReleaseDC( p->hwnd, hdc );
715 SetEvent(p->test_finished);
719 static void test_deletecontext(HWND hwnd, HDC hdc)
721 struct wgl_thread_param thread_params;
722 HGLRC hglrc = wglCreateContext(hdc);
723 HANDLE thread_handle;
726 SetLastError(0xdeadbeef);
727 res = wglDeleteContext(NULL);
728 ok(res == FALSE, "wglDeleteContext succeeded\n");
729 ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
733 skip("wglCreateContext failed!\n");
737 res = wglMakeCurrent(hdc, hglrc);
740 skip("wglMakeCurrent failed!\n");
744 /* WGL doesn't allow you to delete a context from a different thread than the one in which it is current.
745 * This differs from GLX which does allow it but it delays actual deletion until the context becomes not current.
747 thread_params.hglrc = hglrc;
748 thread_params.hwnd = hwnd;
749 thread_params.test_finished = CreateEvent(NULL, FALSE, FALSE, NULL);
750 thread_handle = CreateThread(NULL, 0, wgl_thread, &thread_params, 0, &tid);
751 ok(!!thread_handle, "Failed to create thread, last error %#x.\n", GetLastError());
754 WaitForSingleObject(thread_handle, INFINITE);
755 ok(!thread_params.make_current, "Attempt to make WGL context from another thread passed\n");
756 ok(thread_params.make_current_error == ERROR_BUSY, "Expected last error to be ERROR_BUSY, got %u\n", thread_params.make_current_error);
757 ok(!thread_params.deleted, "Attempt to delete WGL context from another thread passed\n");
758 ok(thread_params.deleted_error == ERROR_BUSY, "Expected last error to be ERROR_BUSY, got %u\n", thread_params.deleted_error);
760 CloseHandle(thread_params.test_finished);
762 res = wglDeleteContext(hglrc);
763 ok(res == TRUE, "wglDeleteContext failed\n");
765 /* Attempting to delete the same context twice should fail. */
766 SetLastError(0xdeadbeef);
767 res = wglDeleteContext(hglrc);
768 ok(res == FALSE, "wglDeleteContext succeeded\n");
769 ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
771 /* WGL makes a context not current when deleting it. This differs from GLX behavior where
772 * deletion takes place when the thread becomes not current. */
773 hglrc = wglGetCurrentContext();
774 ok(hglrc == NULL, "A WGL context is active while none was expected\n");
778 static void test_getprocaddress(HDC hdc)
780 const char *extensions = (const char*)glGetString(GL_EXTENSIONS);
782 HGLRC ctx = wglGetCurrentContext();
786 skip("skipping wglGetProcAddress tests because no GL extensions supported\n");
790 /* Core GL 1.0/1.1 functions should not be loadable through wglGetProcAddress.
791 * Try to load the function with and without a context.
793 func = wglGetProcAddress("glEnable");
794 ok(func == NULL, "Lookup of function glEnable with a context passed, expected a failure\n");
795 wglMakeCurrent(hdc, NULL);
796 func = wglGetProcAddress("glEnable");
797 ok(func == NULL, "Lookup of function glEnable without a context passed, expected a failure\n");
798 wglMakeCurrent(hdc, ctx);
800 /* The goal of the test will be to test behavior of wglGetProcAddress when
801 * no WGL context is active. Before the test we pick an extension (GL_ARB_multitexture)
802 * which any GL >=1.2.1 implementation supports. Unfortunately the GDI renderer doesn't
803 * support it. There aren't any extensions we can use for this test which are supported by
804 * both GDI and real drivers.
805 * Note GDI only has GL_EXT_bgra, GL_EXT_paletted_texture and GL_WIN_swap_hint.
807 if (!gl_extension_supported(extensions, "GL_ARB_multitexture"))
809 skip("skipping test because lack of GL_ARB_multitexture support\n");
813 func = wglGetProcAddress("glActiveTextureARB");
814 ok(func != NULL, "Unable to lookup glActiveTextureARB, last error %#x\n", GetLastError());
816 /* Temporarily disable the context, so we can see that we can't retrieve functions now. */
817 wglMakeCurrent(hdc, NULL);
818 func = wglGetProcAddress("glActiveTextureARB");
819 ok(func == NULL, "Function lookup without a context passed, expected a failure; last error %#x\n", GetLastError());
820 wglMakeCurrent(hdc, ctx);
823 static void test_make_current_read(HDC hdc)
827 HGLRC hglrc = wglCreateContext(hdc);
831 skip("wglCreateContext failed!\n");
835 res = wglMakeCurrent(hdc, hglrc);
838 skip("wglMakeCurrent failed!\n");
842 /* Test what wglGetCurrentReadDCARB does for wglMakeCurrent as the spec doesn't mention it */
843 hread = pwglGetCurrentReadDCARB();
844 trace("hread %p, hdc %p\n", hread, hdc);
845 ok(hread == hdc, "wglGetCurrentReadDCARB failed for standard wglMakeCurrent\n");
847 pwglMakeContextCurrentARB(hdc, hdc, hglrc);
848 hread = pwglGetCurrentReadDCARB();
849 ok(hread == hdc, "wglGetCurrentReadDCARB failed for wglMakeContextCurrent\n");
852 static void test_dc(HWND hwnd, HDC hdc)
857 /* Get another DC and make sure it has the same pixel format */
861 pf1 = GetPixelFormat(hdc);
862 pf2 = GetPixelFormat(hdc2);
863 ok(pf1 == pf2, "Second DC does not have the same format (%d != %d)\n", pf1, pf2);
866 skip("Could not get a different DC for the window\n");
870 ReleaseDC(hwnd, hdc2);
875 /* Nvidia converts win32 error codes to (0xc007 << 16) | win32_error_code */
876 #define NVIDIA_HRESULT_FROM_WIN32(x) (HRESULT_FROM_WIN32(x) | 0x40000000)
877 static void test_opengl3(HDC hdc)
879 /* Try to create a context compatible with OpenGL 1.x; 1.0-2.1 is allowed */
882 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 1, 0};
884 gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
885 ok(gl3Ctx != 0, "pwglCreateContextAttribsARB for a 1.x context failed!\n");
886 wglDeleteContext(gl3Ctx);
889 /* Try to pass an invalid HDC */
893 gl3Ctx = pwglCreateContextAttribsARB((HDC)0xdeadbeef, 0, 0);
894 ok(gl3Ctx == 0, "pwglCreateContextAttribsARB using an invalid HDC passed\n");
895 error = GetLastError();
896 todo_wine ok(error == ERROR_DC_NOT_FOUND ||
897 broken(error == NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_DATA)), /* Nvidia Vista + Win7 */
898 "Expected ERROR_DC_NOT_FOUND, got error=%x\n", error);
899 wglDeleteContext(gl3Ctx);
902 /* Try to pass an invalid shareList */
906 gl3Ctx = pwglCreateContextAttribsARB(hdc, (HGLRC)0xdeadbeef, 0);
907 ok(gl3Ctx == 0, "pwglCreateContextAttribsARB using an invalid shareList passed\n");
908 error = GetLastError();
909 /* The Nvidia implementation seems to return hresults instead of win32 error codes */
910 todo_wine ok(error == ERROR_INVALID_OPERATION ||
911 error == NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_OPERATION), "Expected ERROR_INVALID_OPERATION, got error=%x\n", error);
912 wglDeleteContext(gl3Ctx);
915 /* Try to create an OpenGL 3.0 context */
917 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0};
918 HGLRC gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
922 skip("Skipping the rest of the WGL_ARB_create_context test due to lack of OpenGL 3.0\n");
926 wglDeleteContext(gl3Ctx);
929 /* Test matching an OpenGL 3.0 context with an older one, OpenGL 3.0 should allow it until the new object model is introduced in a future revision */
931 HGLRC glCtx = wglCreateContext(hdc);
933 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0};
934 int attribs_future[] = {WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0};
936 HGLRC gl3Ctx = pwglCreateContextAttribsARB(hdc, glCtx, attribs);
937 ok(gl3Ctx != NULL, "Sharing of a display list between OpenGL 3.0 and OpenGL 1.x/2.x failed!\n");
939 wglDeleteContext(gl3Ctx);
941 gl3Ctx = pwglCreateContextAttribsARB(hdc, glCtx, attribs_future);
942 ok(gl3Ctx != NULL, "Sharing of a display list between a forward compatible OpenGL 3.0 context and OpenGL 1.x/2.x failed!\n");
944 wglDeleteContext(gl3Ctx);
947 wglDeleteContext(glCtx);
950 /* Try to create an OpenGL 3.0 context and test windowless rendering */
953 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0};
956 gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
957 ok(gl3Ctx != 0, "pwglCreateContextAttribsARB for a 3.0 context failed!\n");
959 /* OpenGL 3.0 allows offscreen rendering WITHOUT a drawable
960 * Neither AMD or Nvidia support it at this point. The WGL_ARB_create_context specs also say that
961 * it is hard because drivers use the HDC to enter the display driver and it sounds like they don't
962 * expect drivers to ever offer it.
964 res = wglMakeCurrent(0, gl3Ctx);
965 ok(res == FALSE, "Wow, OpenGL 3.0 windowless rendering passed while it was expected not to!\n");
967 wglMakeCurrent(0, 0);
970 wglDeleteContext(gl3Ctx);
974 static void test_minimized(void)
976 PIXELFORMATDESCRIPTOR pf_desc =
978 sizeof(PIXELFORMATDESCRIPTOR),
980 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
982 24, /* 24-bit color depth */
983 0, 0, 0, 0, 0, 0, /* color bits */
984 0, /* alpha buffer */
986 0, /* accumulation buffer */
987 0, 0, 0, 0, /* accum bits */
989 0, /* stencil buffer */
990 0, /* auxiliary buffer */
991 PFD_MAIN_PLANE, /* main layer */
993 0, 0, 0 /* layer masks */
1002 window = CreateWindowA("static", "opengl32_test",
1003 WS_POPUP | WS_MINIMIZE, 0, 0, 640, 480, 0, 0, 0, 0);
1004 ok(!!window, "Failed to create window, last error %#x.\n", GetLastError());
1007 ok(!!dc, "Failed to get DC.\n");
1009 pixel_format = ChoosePixelFormat(dc, &pf_desc);
1012 win_skip("Failed to find pixel format.\n");
1013 ReleaseDC(window, dc);
1014 DestroyWindow(window);
1018 ret = SetPixelFormat(dc, pixel_format, &pf_desc);
1019 ok(ret, "Failed to set pixel format, last error %#x.\n", GetLastError());
1021 style = GetWindowLongA(window, GWL_STYLE);
1022 ok(style & WS_MINIMIZE, "Window should be minimized, got style %#x.\n", style);
1024 ctx = wglCreateContext(dc);
1025 ok(!!ctx, "Failed to create GL context, last error %#x.\n", GetLastError());
1027 ret = wglMakeCurrent(dc, ctx);
1028 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1030 style = GetWindowLongA(window, GWL_STYLE);
1031 ok(style & WS_MINIMIZE, "window should be minimized, got style %#x.\n", style);
1033 ret = wglMakeCurrent(NULL, NULL);
1034 ok(ret, "Failed to clear current context, last error %#x.\n", GetLastError());
1036 ret = wglDeleteContext(ctx);
1037 ok(ret, "Failed to delete GL context, last error %#x.\n", GetLastError());
1039 ReleaseDC(window, dc);
1040 DestroyWindow(window);
1043 static void test_window_dc(void)
1045 PIXELFORMATDESCRIPTOR pf_desc =
1047 sizeof(PIXELFORMATDESCRIPTOR),
1049 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
1051 24, /* 24-bit color depth */
1052 0, 0, 0, 0, 0, 0, /* color bits */
1053 0, /* alpha buffer */
1055 0, /* accumulation buffer */
1056 0, 0, 0, 0, /* accum bits */
1058 0, /* stencil buffer */
1059 0, /* auxiliary buffer */
1060 PFD_MAIN_PLANE, /* main layer */
1062 0, 0, 0 /* layer masks */
1071 window = CreateWindowA("static", "opengl32_test",
1072 WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, 0, 0, 0, 0);
1073 ok(!!window, "Failed to create window, last error %#x.\n", GetLastError());
1075 ShowWindow(window, SW_SHOW);
1077 dc = GetWindowDC(window);
1078 ok(!!dc, "Failed to get DC.\n");
1080 pixel_format = ChoosePixelFormat(dc, &pf_desc);
1083 win_skip("Failed to find pixel format.\n");
1084 ReleaseDC(window, dc);
1085 DestroyWindow(window);
1089 ret = SetPixelFormat(dc, pixel_format, &pf_desc);
1090 ok(ret, "Failed to set pixel format, last error %#x.\n", GetLastError());
1092 ctx = wglCreateContext(dc);
1093 ok(!!ctx, "Failed to create GL context, last error %#x.\n", GetLastError());
1095 ret = wglMakeCurrent(dc, ctx);
1096 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1098 GetClientRect(window, &r);
1099 glGetIntegerv(GL_VIEWPORT, (GLint *)&vp);
1100 ok(EqualRect(&r, &vp), "Viewport not equal to client rect.\n");
1102 ret = wglMakeCurrent(NULL, NULL);
1103 ok(ret, "Failed to clear current context, last error %#x.\n", GetLastError());
1105 ret = wglDeleteContext(ctx);
1106 ok(ret, "Failed to delete GL context, last error %#x.\n", GetLastError());
1108 ReleaseDC(window, dc);
1109 DestroyWindow(window);
1112 static void test_destroy(HDC oldhdc)
1114 PIXELFORMATDESCRIPTOR pf_desc =
1116 sizeof(PIXELFORMATDESCRIPTOR),
1118 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
1120 24, /* 24-bit color depth */
1121 0, 0, 0, 0, 0, 0, /* color bits */
1122 0, /* alpha buffer */
1124 0, /* accumulation buffer */
1125 0, 0, 0, 0, /* accum bits */
1127 0, /* stencil buffer */
1128 0, /* auxiliary buffer */
1129 PFD_MAIN_PLANE, /* main layer */
1131 0, 0, 0 /* layer masks */
1140 HGLRC oldctx = wglGetCurrentContext();
1142 ok(!!oldctx, "Expected to find a valid current context.\n");
1144 window = CreateWindowA("static", "opengl32_test",
1145 WS_POPUP, 0, 0, 640, 480, 0, 0, 0, 0);
1146 ok(!!window, "Failed to create window, last error %#x.\n", GetLastError());
1149 ok(!!dc, "Failed to get DC.\n");
1151 pixel_format = ChoosePixelFormat(dc, &pf_desc);
1154 win_skip("Failed to find pixel format.\n");
1155 ReleaseDC(window, dc);
1156 DestroyWindow(window);
1160 ret = SetPixelFormat(dc, pixel_format, &pf_desc);
1161 ok(ret, "Failed to set pixel format, last error %#x.\n", GetLastError());
1163 ctx = wglCreateContext(dc);
1164 ok(!!ctx, "Failed to create GL context, last error %#x.\n", GetLastError());
1166 ret = wglMakeCurrent(dc, ctx);
1167 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1169 glClear(GL_COLOR_BUFFER_BIT);
1171 glerr = glGetError();
1172 ok(glerr == GL_NO_ERROR, "Failed glClear, error %#x.\n", glerr);
1173 ret = SwapBuffers(dc);
1174 ok(ret, "Failed SwapBuffers, error %#x.\n", GetLastError());
1176 ret = DestroyWindow(window);
1177 ok(ret, "Failed to destroy window, last error %#x.\n", GetLastError());
1179 ok(wglGetCurrentContext() == ctx, "Wrong current context.\n");
1181 SetLastError(0xdeadbeef);
1182 ret = wglMakeCurrent(dc, ctx);
1183 err = GetLastError();
1184 ok(!ret && err == ERROR_INVALID_HANDLE,
1185 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret, err);
1186 SetLastError(0xdeadbeef);
1187 ret = SwapBuffers(dc);
1188 err = GetLastError();
1189 ok(!ret && err == ERROR_INVALID_HANDLE, "Unexpected behavior with SwapBuffer, last error %#x.\n", err);
1191 ok(wglGetCurrentContext() == ctx, "Wrong current context.\n");
1193 glClear(GL_COLOR_BUFFER_BIT);
1195 glerr = glGetError();
1196 ok(glerr == GL_NO_ERROR, "Failed glClear, error %#x.\n", glerr);
1197 SetLastError(0xdeadbeef);
1198 ret = SwapBuffers(dc);
1199 err = GetLastError();
1200 ok(!ret && err == ERROR_INVALID_HANDLE, "Unexpected behavior with SwapBuffer, last error %#x.\n", err);
1202 ret = wglMakeCurrent(NULL, NULL);
1203 ok(ret, "Failed to clear current context, last error %#x.\n", GetLastError());
1205 glClear(GL_COLOR_BUFFER_BIT);
1207 glerr = glGetError();
1208 ok(glerr == GL_INVALID_OPERATION, "Failed glClear, error %#x.\n", glerr);
1209 SetLastError(0xdeadbeef);
1210 ret = SwapBuffers(dc);
1211 err = GetLastError();
1212 ok(!ret && err == ERROR_INVALID_HANDLE, "Unexpected behavior with SwapBuffer, last error %#x.\n", err);
1214 SetLastError(0xdeadbeef);
1215 ret = wglMakeCurrent(dc, ctx);
1216 err = GetLastError();
1217 ok(!ret && err == ERROR_INVALID_HANDLE,
1218 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret, err);
1220 ok(wglGetCurrentContext() == NULL, "Wrong current context.\n");
1222 ret = wglMakeCurrent(oldhdc, oldctx);
1223 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1224 ok(wglGetCurrentContext() == oldctx, "Wrong current context.\n");
1226 SetLastError(0xdeadbeef);
1227 ret = wglMakeCurrent(dc, ctx);
1228 err = GetLastError();
1229 ok(!ret && err == ERROR_INVALID_HANDLE,
1230 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret, err);
1232 ok(wglGetCurrentContext() == oldctx, "Wrong current context.\n");
1234 ret = wglDeleteContext(ctx);
1235 ok(ret, "Failed to delete GL context, last error %#x.\n", GetLastError());
1237 ReleaseDC(window, dc);
1239 ret = wglMakeCurrent(oldhdc, oldctx);
1240 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1243 static void test_destroy_read(HDC oldhdc)
1245 PIXELFORMATDESCRIPTOR pf_desc =
1247 sizeof(PIXELFORMATDESCRIPTOR),
1249 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
1251 24, /* 24-bit color depth */
1252 0, 0, 0, 0, 0, 0, /* color bits */
1253 0, /* alpha buffer */
1255 0, /* accumulation buffer */
1256 0, 0, 0, 0, /* accum bits */
1258 0, /* stencil buffer */
1259 0, /* auxiliary buffer */
1260 PFD_MAIN_PLANE, /* main layer */
1262 0, 0, 0 /* layer masks */
1265 HWND draw_window, read_window;
1268 HDC read_dc, draw_dc;
1271 HGLRC oldctx = wglGetCurrentContext();
1273 ok(!!oldctx, "Expected to find a valid current context\n");
1275 draw_window = CreateWindowA("static", "opengl32_test",
1276 WS_POPUP, 0, 0, 640, 480, 0, 0, 0, 0);
1277 ok(!!draw_window, "Failed to create window, last error %#x.\n", GetLastError());
1279 draw_dc = GetDC(draw_window);
1280 ok(!!draw_dc, "Failed to get DC.\n");
1282 pixel_format = ChoosePixelFormat(draw_dc, &pf_desc);
1285 win_skip("Failed to find pixel format.\n");
1286 ReleaseDC(draw_window, draw_dc);
1287 DestroyWindow(draw_window);
1291 ret = SetPixelFormat(draw_dc, pixel_format, &pf_desc);
1292 ok(ret, "Failed to set pixel format, last error %#x.\n", GetLastError());
1294 read_window = CreateWindowA("static", "opengl32_test",
1295 WS_POPUP, 0, 0, 640, 480, 0, 0, 0, 0);
1296 ok(!!read_window, "Failed to create window, last error %#x.\n", GetLastError());
1298 read_dc = GetDC(read_window);
1299 ok(!!draw_dc, "Failed to get DC.\n");
1301 pixel_format = ChoosePixelFormat(read_dc, &pf_desc);
1304 win_skip("Failed to find pixel format.\n");
1305 ReleaseDC(read_window, read_dc);
1306 DestroyWindow(read_window);
1307 ReleaseDC(draw_window, draw_dc);
1308 DestroyWindow(draw_window);
1312 ret = SetPixelFormat(read_dc, pixel_format, &pf_desc);
1313 ok(ret, "Failed to set pixel format, last error %#x.\n", GetLastError());
1315 ctx = wglCreateContext(draw_dc);
1316 ok(!!ctx, "Failed to create GL context, last error %#x.\n", GetLastError());
1318 ret = pwglMakeContextCurrentARB(draw_dc, read_dc, ctx);
1319 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1321 glCopyPixels(0, 0, 640, 480, GL_COLOR);
1323 glerr = glGetError();
1324 ok(glerr == GL_NO_ERROR, "Failed glCopyPixel, error %#x.\n", glerr);
1325 ret = SwapBuffers(draw_dc);
1326 ok(ret, "Failed SwapBuffers, error %#x.\n", GetLastError());
1328 ret = DestroyWindow(read_window);
1329 ok(ret, "Failed to destroy window, last error %#x.\n", GetLastError());
1331 ok(wglGetCurrentContext() == ctx, "Wrong current context.\n");
1333 if (0) /* Crashes on AMD on Windows */
1335 glCopyPixels(0, 0, 640, 480, GL_COLOR);
1337 glerr = glGetError();
1338 ok(glerr == GL_NO_ERROR, "Failed glCopyPixel, error %#x.\n", glerr);
1341 glClear(GL_COLOR_BUFFER_BIT);
1343 glerr = glGetError();
1344 ok(glerr == GL_NO_ERROR, "Failed glClear, error %#x.\n", glerr);
1345 ret = SwapBuffers(draw_dc);
1346 ok(ret, "Failed SwapBuffers, error %#x.\n", GetLastError());
1348 ret = wglMakeCurrent(NULL, NULL);
1349 ok(ret, "Failed to clear current context, last error %#x.\n", GetLastError());
1351 if (0) /* This crashes with Nvidia drivers on Windows. */
1353 SetLastError(0xdeadbeef);
1354 ret = pwglMakeContextCurrentARB(draw_dc, read_dc, ctx);
1355 err = GetLastError();
1356 ok(!ret && err == ERROR_INVALID_HANDLE,
1357 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret, err);
1360 ret = DestroyWindow(draw_window);
1361 ok(ret, "Failed to destroy window, last error %#x.\n", GetLastError());
1363 glClear(GL_COLOR_BUFFER_BIT);
1365 glerr = glGetError();
1366 ok(glerr == GL_INVALID_OPERATION, "Failed glClear, error %#x.\n", glerr);
1367 SetLastError(0xdeadbeef);
1368 ret = SwapBuffers(draw_dc);
1369 err = GetLastError();
1370 ok(!ret && err == ERROR_INVALID_HANDLE, "Unexpected behavior with SwapBuffer, last error %#x.\n", err);
1372 SetLastError(0xdeadbeef);
1373 ret = pwglMakeContextCurrentARB(draw_dc, read_dc, ctx);
1374 err = GetLastError();
1375 ok(!ret && (err == ERROR_INVALID_HANDLE || err == 0xc0070006),
1376 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret, err);
1378 ok(wglGetCurrentContext() == NULL, "Wrong current context.\n");
1380 wglMakeCurrent(NULL, NULL);
1382 wglMakeCurrent(oldhdc, oldctx);
1383 ok(wglGetCurrentContext() == oldctx, "Wrong current context.\n");
1385 SetLastError(0xdeadbeef);
1386 ret = pwglMakeContextCurrentARB(draw_dc, read_dc, ctx);
1387 err = GetLastError();
1388 ok(!ret && (err == ERROR_INVALID_HANDLE || err == 0xc0070006),
1389 "Unexpected behavior when making context current, last error %#x.\n", err);
1391 ok(wglGetCurrentContext() == oldctx, "Wrong current context.\n");
1393 ret = wglDeleteContext(ctx);
1394 ok(ret, "Failed to delete GL context, last error %#x.\n", GetLastError());
1396 ReleaseDC(read_window, read_dc);
1397 ReleaseDC(draw_window, draw_dc);
1399 wglMakeCurrent(oldhdc, oldctx);
1405 PIXELFORMATDESCRIPTOR pfd = {
1406 sizeof(PIXELFORMATDESCRIPTOR),
1408 PFD_DRAW_TO_WINDOW |
1409 PFD_SUPPORT_OPENGL |
1412 24, /* 24-bit color depth */
1413 0, 0, 0, 0, 0, 0, /* color bits */
1414 0, /* alpha buffer */
1416 0, /* accumulation buffer */
1417 0, 0, 0, 0, /* accum bits */
1419 0, /* stencil buffer */
1420 0, /* auxiliary buffer */
1421 PFD_MAIN_PLANE, /* main layer */
1423 0, 0, 0 /* layer masks */
1426 hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW,
1427 10, 10, 200, 200, NULL, NULL, NULL, NULL);
1428 ok(hwnd != NULL, "err: %d\n", GetLastError());
1432 int iPixelFormat, res;
1435 ShowWindow(hwnd, SW_SHOW);
1439 iPixelFormat = ChoosePixelFormat(hdc, &pfd);
1440 if(iPixelFormat == 0)
1442 /* This should never happen as ChoosePixelFormat always returns a closest match, but currently this fails in Wine if we don't have glX */
1443 win_skip("Unable to find pixel format.\n");
1447 /* We shouldn't be able to create a context from a hdc which doesn't have a pixel format set */
1448 hglrc = wglCreateContext(hdc);
1449 ok(hglrc == NULL, "wglCreateContext should fail when no pixel format has been set, but it passed\n");
1450 error = GetLastError();
1451 ok(error == ERROR_INVALID_PIXEL_FORMAT, "expected ERROR_INVALID_PIXEL_FORMAT for wglCreateContext without a pixelformat set, but received %#x\n", error);
1453 res = SetPixelFormat(hdc, iPixelFormat, &pfd);
1454 ok(res, "SetPixelformat failed: %x\n", GetLastError());
1456 test_bitmap_rendering( TRUE );
1457 test_bitmap_rendering( FALSE );
1462 hglrc = wglCreateContext(hdc);
1463 res = wglMakeCurrent(hdc, hglrc);
1464 ok(res, "wglMakeCurrent failed!\n");
1467 trace("OpenGL renderer: %s\n", glGetString(GL_RENDERER));
1468 trace("OpenGL driver version: %s\n", glGetString(GL_VERSION));
1469 trace("OpenGL vendor: %s\n", glGetString(GL_VENDOR));
1473 skip("Skipping OpenGL tests without a current context\n");
1477 /* Initialisation of WGL functions depends on an implicit WGL context. For this reason we can't load them before making
1478 * any WGL call :( On Wine this would work but not on real Windows because there can be different implementations (software, ICD, MCD).
1481 test_getprocaddress(hdc);
1482 test_deletecontext(hwnd, hdc);
1483 test_makecurrent(hdc);
1485 /* The lack of wglGetExtensionsStringARB in general means broken software rendering or the lack of decent OpenGL support, skip tests in such cases */
1486 if (!pwglGetExtensionsStringARB)
1488 win_skip("wglGetExtensionsStringARB is not available\n");
1492 test_setpixelformat(hdc);
1494 test_sharelists(hdc);
1495 test_colorbits(hdc);
1497 test_acceleration(hdc);
1499 wgl_extensions = pwglGetExtensionsStringARB(hdc);
1500 if(wgl_extensions == NULL) skip("Skipping opengl32 tests because this OpenGL implementation doesn't support WGL extensions!\n");
1502 if(strstr(wgl_extensions, "WGL_ARB_create_context"))
1505 if(strstr(wgl_extensions, "WGL_ARB_make_current_read"))
1507 test_make_current_read(hdc);
1508 test_destroy_read(hdc);
1511 skip("WGL_ARB_make_current_read not supported, skipping test\n");
1513 if(strstr(wgl_extensions, "WGL_ARB_pbuffer"))
1516 skip("WGL_ARB_pbuffer not supported, skipping pbuffer test\n");
1519 ReleaseDC(hwnd, hdc);
1520 DestroyWindow(hwnd);