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)
393 hglrc = wglCreateContext(winhdc);
394 ok( hglrc != 0, "wglCreateContext failed\n" );
396 ret = wglMakeCurrent( winhdc, hglrc );
397 ok( ret, "wglMakeCurrent failed\n" );
399 ok( wglGetCurrentContext() == hglrc, "wrong context\n" );
401 /* set the same context again */
402 ret = wglMakeCurrent( winhdc, hglrc );
403 ok( ret, "wglMakeCurrent failed\n" );
405 /* check wglMakeCurrent(x, y) after another call to wglMakeCurrent(x, y) */
406 ret = wglMakeCurrent( winhdc, NULL );
407 ok( ret, "wglMakeCurrent failed\n" );
409 ret = wglMakeCurrent( winhdc, NULL );
410 ok( ret, "wglMakeCurrent failed\n" );
412 SetLastError( 0xdeadbeef );
413 ret = wglMakeCurrent( NULL, NULL );
414 ok( !ret, "wglMakeCurrent succeeded\n" );
415 error = GetLastError();
416 ok( error == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got error=%x\n", error);
418 ret = wglMakeCurrent( winhdc, NULL );
419 ok( ret, "wglMakeCurrent failed\n" );
421 ret = wglMakeCurrent( winhdc, hglrc );
422 ok( ret, "wglMakeCurrent failed\n" );
424 ret = wglMakeCurrent( NULL, NULL );
425 ok( ret, "wglMakeCurrent failed\n" );
427 ok( wglGetCurrentContext() == NULL, "wrong context\n" );
429 SetLastError( 0xdeadbeef );
430 ret = wglMakeCurrent( NULL, NULL );
431 ok( !ret, "wglMakeCurrent succeeded\n" );
432 error = GetLastError();
433 ok( error == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got error=%x\n", error);
435 ret = wglMakeCurrent( winhdc, hglrc );
436 ok( ret, "wglMakeCurrent failed\n" );
439 static void test_colorbits(HDC hdc)
441 const int iAttribList[] = { WGL_COLOR_BITS_ARB, WGL_RED_BITS_ARB, WGL_GREEN_BITS_ARB,
442 WGL_BLUE_BITS_ARB, WGL_ALPHA_BITS_ARB };
443 int iAttribRet[sizeof(iAttribList)/sizeof(iAttribList[0])];
444 const int iAttribs[] = { WGL_ALPHA_BITS_ARB, 1, 0 };
445 unsigned int nFormats;
447 int iPixelFormat = 0;
449 if (!pwglChoosePixelFormatARB)
451 win_skip("wglChoosePixelFormatARB is not available\n");
455 /* We need a pixel format with at least one bit of alpha */
456 res = pwglChoosePixelFormatARB(hdc, iAttribs, NULL, 1, &iPixelFormat, &nFormats);
457 if(res == FALSE || nFormats == 0)
459 skip("No suitable pixel formats found\n");
463 res = pwglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0,
464 sizeof(iAttribList)/sizeof(iAttribList[0]), iAttribList, iAttribRet);
467 skip("wglGetPixelFormatAttribivARB failed\n");
470 iAttribRet[1] += iAttribRet[2]+iAttribRet[3]+iAttribRet[4];
471 ok(iAttribRet[0] == iAttribRet[1], "WGL_COLOR_BITS_ARB (%d) does not equal R+G+B+A (%d)!\n",
472 iAttribRet[0], iAttribRet[1]);
475 static void test_gdi_dbuf(HDC hdc)
477 const int iAttribList[] = { WGL_SUPPORT_GDI_ARB, WGL_DOUBLE_BUFFER_ARB };
478 int iAttribRet[sizeof(iAttribList)/sizeof(iAttribList[0])];
479 unsigned int nFormats;
483 if (!pwglGetPixelFormatAttribivARB)
485 win_skip("wglGetPixelFormatAttribivARB is not available\n");
489 nFormats = DescribePixelFormat(hdc, 0, 0, NULL);
490 for(iPixelFormat = 1;iPixelFormat <= nFormats;iPixelFormat++)
492 res = pwglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0,
493 sizeof(iAttribList)/sizeof(iAttribList[0]), iAttribList,
495 ok(res!=FALSE, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat);
499 ok(!(iAttribRet[0] && iAttribRet[1]), "GDI support and double buffering on pixel format %d\n", iPixelFormat);
503 static void test_acceleration(HDC hdc)
505 const int iAttribList[] = { WGL_ACCELERATION_ARB };
506 int iAttribRet[sizeof(iAttribList)/sizeof(iAttribList[0])];
507 unsigned int nFormats;
510 PIXELFORMATDESCRIPTOR pfd;
512 if (!pwglGetPixelFormatAttribivARB)
514 win_skip("wglGetPixelFormatAttribivARB is not available\n");
518 nFormats = DescribePixelFormat(hdc, 0, 0, NULL);
519 for(iPixelFormat = 1; iPixelFormat <= nFormats; iPixelFormat++)
521 res = pwglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0,
522 sizeof(iAttribList)/sizeof(iAttribList[0]), iAttribList,
524 ok(res!=FALSE, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat);
528 memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
529 DescribePixelFormat(hdc, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
531 switch(iAttribRet[0])
533 case WGL_NO_ACCELERATION_ARB:
534 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);
536 case WGL_GENERIC_ACCELERATION_ARB:
537 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);
539 case WGL_FULL_ACCELERATION_ARB:
540 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);
546 static void test_bitmap_rendering( BOOL use_dib )
548 PIXELFORMATDESCRIPTOR pfd;
549 int i, ret, bpp, iPixelFormat=0;
550 unsigned int nFormats;
553 HBITMAP bmpDst, oldDst, bmp2;
554 HDC hdcDst, hdcScreen;
555 UINT *dstBuffer = NULL;
557 hdcScreen = CreateCompatibleDC(0);
558 hdcDst = CreateCompatibleDC(0);
563 memset(&biDst, 0, sizeof(BITMAPINFO));
564 biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
565 biDst.bmiHeader.biWidth = 4;
566 biDst.bmiHeader.biHeight = -4;
567 biDst.bmiHeader.biPlanes = 1;
568 biDst.bmiHeader.biBitCount = 32;
569 biDst.bmiHeader.biCompression = BI_RGB;
571 bmpDst = CreateDIBSection(0, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer, NULL, 0);
573 biDst.bmiHeader.biWidth = 12;
574 biDst.bmiHeader.biHeight = -12;
575 biDst.bmiHeader.biBitCount = 16;
576 bmp2 = CreateDIBSection(0, &biDst, DIB_RGB_COLORS, NULL, NULL, 0);
580 bpp = GetDeviceCaps( hdcScreen, BITSPIXEL );
581 bmpDst = CreateBitmap( 4, 4, 1, bpp, NULL );
582 bmp2 = CreateBitmap( 12, 12, 1, bpp, NULL );
585 oldDst = SelectObject(hdcDst, bmpDst);
587 trace( "testing on %s\n", use_dib ? "DIB" : "DDB" );
589 /* Pick a pixel format by hand because ChoosePixelFormat is unreliable */
590 nFormats = DescribePixelFormat(hdcDst, 0, 0, NULL);
591 for(i=1; i<=nFormats; i++)
593 memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
594 DescribePixelFormat(hdcDst, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
596 if((pfd.dwFlags & PFD_DRAW_TO_BITMAP) &&
597 (pfd.dwFlags & PFD_SUPPORT_OPENGL) &&
598 (pfd.cColorBits == bpp) &&
599 (pfd.cAlphaBits == 8) )
608 skip("Unable to find a suitable pixel format\n");
612 ret = SetPixelFormat(hdcDst, iPixelFormat, &pfd);
613 ok( ret, "SetPixelFormat failed\n" );
614 ret = GetPixelFormat( hdcDst );
615 ok( ret == iPixelFormat, "GetPixelFormat returned %d/%d\n", ret, iPixelFormat );
616 ret = SetPixelFormat(hdcDst, iPixelFormat + 1, &pfd);
617 ok( !ret, "SetPixelFormat succeeded\n" );
618 hglrc = wglCreateContext(hdcDst);
619 ok(hglrc != NULL, "Unable to create a context\n");
624 wglMakeCurrent(hdcDst, hglrc);
625 hglrc2 = wglCreateContext(hdcDst);
626 ok(hglrc2 != NULL, "Unable to create a context\n");
628 /* Note this is RGBA but we read ARGB back */
629 glClearColor((float)0x22/0xff, (float)0x33/0xff, (float)0x44/0xff, (float)0x11/0xff);
630 glClear(GL_COLOR_BUFFER_BIT);
631 glGetIntegerv( GL_VIEWPORT, viewport );
634 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 4 && viewport[3] == 4,
635 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
636 /* Note apparently the alpha channel is not supported by the software renderer (bitmap only works using software) */
638 for (i = 0; i < 16; i++)
639 ok(dstBuffer[i] == 0x223344 || dstBuffer[i] == 0x11223344, "Received color=%x at %u\n",
642 SelectObject(hdcDst, bmp2);
643 ret = GetPixelFormat( hdcDst );
644 ok( ret == iPixelFormat, "GetPixelFormat returned %d/%d\n", ret, iPixelFormat );
645 ret = SetPixelFormat(hdcDst, iPixelFormat + 1, &pfd);
646 ok( !ret, "SetPixelFormat succeeded\n" );
648 /* context still uses the old pixel format and viewport */
649 glClearColor((float)0x44/0xff, (float)0x33/0xff, (float)0x22/0xff, (float)0x11/0xff);
650 glClear(GL_COLOR_BUFFER_BIT);
652 glGetIntegerv( GL_VIEWPORT, viewport );
653 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 4 && viewport[3] == 4,
654 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
656 wglMakeCurrent(NULL, NULL);
657 wglMakeCurrent(hdcDst, hglrc);
658 glClearColor((float)0x44/0xff, (float)0x55/0xff, (float)0x66/0xff, (float)0x11/0xff);
659 glClear(GL_COLOR_BUFFER_BIT);
661 glGetIntegerv( GL_VIEWPORT, viewport );
662 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 4 && viewport[3] == 4,
663 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
665 wglMakeCurrent(hdcDst, hglrc2);
666 glGetIntegerv( GL_VIEWPORT, viewport );
667 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 12 && viewport[3] == 12,
668 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
670 wglMakeCurrent(hdcDst, hglrc);
671 glGetIntegerv( GL_VIEWPORT, viewport );
672 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 4 && viewport[3] == 4,
673 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
675 SelectObject(hdcDst, bmpDst);
676 ret = GetPixelFormat( hdcDst );
677 ok( ret == iPixelFormat, "GetPixelFormat returned %d/%d\n", ret, iPixelFormat );
678 ret = SetPixelFormat(hdcDst, iPixelFormat + 1, &pfd);
679 ok( !ret, "SetPixelFormat succeeded\n" );
680 wglMakeCurrent(hdcDst, hglrc2);
681 glGetIntegerv( GL_VIEWPORT, viewport );
682 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 12 && viewport[3] == 12,
683 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
687 SelectObject(hdcDst, oldDst);
689 DeleteObject(bmpDst);
694 struct wgl_thread_param
696 HANDLE test_finished;
702 static DWORD WINAPI wgl_thread(void *param)
704 struct wgl_thread_param *p = param;
706 SetLastError(0xdeadbeef);
707 p->hglrc_deleted = wglDeleteContext(p->hglrc);
708 p->last_error = GetLastError();
709 SetEvent(p->test_finished);
714 static void test_deletecontext(HDC hdc)
716 struct wgl_thread_param thread_params;
717 HGLRC hglrc = wglCreateContext(hdc);
718 HANDLE thread_handle;
721 SetLastError(0xdeadbeef);
722 res = wglDeleteContext(NULL);
723 ok(res == FALSE, "wglDeleteContext succeeded\n");
724 ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
728 skip("wglCreateContext failed!\n");
732 res = wglMakeCurrent(hdc, hglrc);
735 skip("wglMakeCurrent failed!\n");
739 /* WGL doesn't allow you to delete a context from a different thread than the one in which it is current.
740 * This differs from GLX which does allow it but it delays actual deletion until the context becomes not current.
742 thread_params.hglrc = hglrc;
743 thread_params.test_finished = CreateEvent(NULL, FALSE, FALSE, NULL);
744 thread_handle = CreateThread(NULL, 0, wgl_thread, &thread_params, 0, &tid);
745 ok(!!thread_handle, "Failed to create thread, last error %#x.\n", GetLastError());
748 WaitForSingleObject(thread_handle, INFINITE);
749 ok(thread_params.hglrc_deleted == FALSE, "Attempt to delete WGL context from another thread passed but should fail!\n");
750 ok(thread_params.last_error == ERROR_BUSY, "Expected last error to be ERROR_BUSY, got %u\n", thread_params.last_error);
752 CloseHandle(thread_params.test_finished);
754 res = wglDeleteContext(hglrc);
755 ok(res == TRUE, "wglDeleteContext failed\n");
757 /* Attempting to delete the same context twice should fail. */
758 SetLastError(0xdeadbeef);
759 res = wglDeleteContext(hglrc);
760 ok(res == FALSE, "wglDeleteContext succeeded\n");
761 ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
763 /* WGL makes a context not current when deleting it. This differs from GLX behavior where
764 * deletion takes place when the thread becomes not current. */
765 hglrc = wglGetCurrentContext();
766 ok(hglrc == NULL, "A WGL context is active while none was expected\n");
770 static void test_getprocaddress(HDC hdc)
772 const char *extensions = (const char*)glGetString(GL_EXTENSIONS);
774 HGLRC ctx = wglGetCurrentContext();
778 skip("skipping wglGetProcAddress tests because no GL extensions supported\n");
782 /* Core GL 1.0/1.1 functions should not be loadable through wglGetProcAddress.
783 * Try to load the function with and without a context.
785 func = wglGetProcAddress("glEnable");
786 ok(func == NULL, "Lookup of function glEnable with a context passed, expected a failure\n");
787 wglMakeCurrent(hdc, NULL);
788 func = wglGetProcAddress("glEnable");
789 ok(func == NULL, "Lookup of function glEnable without a context passed, expected a failure\n");
790 wglMakeCurrent(hdc, ctx);
792 /* The goal of the test will be to test behavior of wglGetProcAddress when
793 * no WGL context is active. Before the test we pick an extension (GL_ARB_multitexture)
794 * which any GL >=1.2.1 implementation supports. Unfortunately the GDI renderer doesn't
795 * support it. There aren't any extensions we can use for this test which are supported by
796 * both GDI and real drivers.
797 * Note GDI only has GL_EXT_bgra, GL_EXT_paletted_texture and GL_WIN_swap_hint.
799 if (!gl_extension_supported(extensions, "GL_ARB_multitexture"))
801 skip("skipping test because lack of GL_ARB_multitexture support\n");
804 func = wglGetProcAddress("glActiveTextureARB");
805 ok(func != NULL, "Unable to lookup glActiveTextureARB, last error %#x\n", GetLastError());
807 /* Temporarily disable the context, so we can see that we can't retrieve functions now. */
808 wglMakeCurrent(hdc, NULL);
809 func = wglGetProcAddress("glActiveTextureARB");
810 ok(func == NULL, "Function lookup without a context passed, expected a failure; last error %#x\n", GetLastError());
811 wglMakeCurrent(hdc, ctx);
814 static void test_make_current_read(HDC hdc)
818 HGLRC hglrc = wglCreateContext(hdc);
822 skip("wglCreateContext failed!\n");
826 res = wglMakeCurrent(hdc, hglrc);
829 skip("wglMakeCurrent failed!\n");
833 /* Test what wglGetCurrentReadDCARB does for wglMakeCurrent as the spec doesn't mention it */
834 hread = pwglGetCurrentReadDCARB();
835 trace("hread %p, hdc %p\n", hread, hdc);
836 ok(hread == hdc, "wglGetCurrentReadDCARB failed for standard wglMakeCurrent\n");
838 pwglMakeContextCurrentARB(hdc, hdc, hglrc);
839 hread = pwglGetCurrentReadDCARB();
840 ok(hread == hdc, "wglGetCurrentReadDCARB failed for wglMakeContextCurrent\n");
843 static void test_dc(HWND hwnd, HDC hdc)
848 /* Get another DC and make sure it has the same pixel format */
852 pf1 = GetPixelFormat(hdc);
853 pf2 = GetPixelFormat(hdc2);
854 ok(pf1 == pf2, "Second DC does not have the same format (%d != %d)\n", pf1, pf2);
857 skip("Could not get a different DC for the window\n");
861 ReleaseDC(hwnd, hdc2);
866 /* Nvidia converts win32 error codes to (0xc007 << 16) | win32_error_code */
867 #define NVIDIA_HRESULT_FROM_WIN32(x) (HRESULT_FROM_WIN32(x) | 0x40000000)
868 static void test_opengl3(HDC hdc)
870 /* Try to create a context compatible with OpenGL 1.x; 1.0-2.1 is allowed */
873 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 1, 0};
875 gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
876 ok(gl3Ctx != 0, "pwglCreateContextAttribsARB for a 1.x context failed!\n");
877 wglDeleteContext(gl3Ctx);
880 /* Try to pass an invalid HDC */
884 gl3Ctx = pwglCreateContextAttribsARB((HDC)0xdeadbeef, 0, 0);
885 ok(gl3Ctx == 0, "pwglCreateContextAttribsARB using an invalid HDC passed\n");
886 error = GetLastError();
887 todo_wine ok(error == ERROR_DC_NOT_FOUND ||
888 broken(error == NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_DATA)), /* Nvidia Vista + Win7 */
889 "Expected ERROR_DC_NOT_FOUND, got error=%x\n", error);
890 wglDeleteContext(gl3Ctx);
893 /* Try to pass an invalid shareList */
897 gl3Ctx = pwglCreateContextAttribsARB(hdc, (HGLRC)0xdeadbeef, 0);
898 todo_wine ok(gl3Ctx == 0, "pwglCreateContextAttribsARB using an invalid shareList passed\n");
899 error = GetLastError();
900 /* The Nvidia implementation seems to return hresults instead of win32 error codes */
901 todo_wine ok(error == ERROR_INVALID_OPERATION ||
902 error == NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_OPERATION), "Expected ERROR_INVALID_OPERATION, got error=%x\n", error);
903 wglDeleteContext(gl3Ctx);
906 /* Try to create an OpenGL 3.0 context */
908 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0};
909 HGLRC gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
913 skip("Skipping the rest of the WGL_ARB_create_context test due to lack of OpenGL 3.0\n");
917 wglDeleteContext(gl3Ctx);
920 /* 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 */
922 HGLRC glCtx = wglCreateContext(hdc);
924 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0};
925 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};
927 HGLRC gl3Ctx = pwglCreateContextAttribsARB(hdc, glCtx, attribs);
928 ok(gl3Ctx != NULL, "Sharing of a display list between OpenGL 3.0 and OpenGL 1.x/2.x failed!\n");
930 wglDeleteContext(gl3Ctx);
932 gl3Ctx = pwglCreateContextAttribsARB(hdc, glCtx, attribs_future);
933 ok(gl3Ctx != NULL, "Sharing of a display list between a forward compatible OpenGL 3.0 context and OpenGL 1.x/2.x failed!\n");
935 wglDeleteContext(gl3Ctx);
938 wglDeleteContext(glCtx);
941 /* Try to create an OpenGL 3.0 context and test windowless rendering */
944 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0};
947 gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
948 ok(gl3Ctx != 0, "pwglCreateContextAttribsARB for a 3.0 context failed!\n");
950 /* OpenGL 3.0 allows offscreen rendering WITHOUT a drawable
951 * Neither AMD or Nvidia support it at this point. The WGL_ARB_create_context specs also say that
952 * it is hard because drivers use the HDC to enter the display driver and it sounds like they don't
953 * expect drivers to ever offer it.
955 res = wglMakeCurrent(0, gl3Ctx);
956 ok(res == FALSE, "Wow, OpenGL 3.0 windowless rendering passed while it was expected not to!\n");
958 wglMakeCurrent(0, 0);
961 wglDeleteContext(gl3Ctx);
965 static void test_minimized(void)
967 PIXELFORMATDESCRIPTOR pf_desc =
969 sizeof(PIXELFORMATDESCRIPTOR),
971 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
973 24, /* 24-bit color depth */
974 0, 0, 0, 0, 0, 0, /* color bits */
975 0, /* alpha buffer */
977 0, /* accumulation buffer */
978 0, 0, 0, 0, /* accum bits */
980 0, /* stencil buffer */
981 0, /* auxiliary buffer */
982 PFD_MAIN_PLANE, /* main layer */
984 0, 0, 0 /* layer masks */
993 window = CreateWindowA("static", "opengl32_test",
994 WS_POPUP | WS_MINIMIZE, 0, 0, 640, 480, 0, 0, 0, 0);
995 ok(!!window, "Failed to create window, last error %#x.\n", GetLastError());
998 ok(!!dc, "Failed to get DC.\n");
1000 pixel_format = ChoosePixelFormat(dc, &pf_desc);
1003 win_skip("Failed to find pixel format.\n");
1004 ReleaseDC(window, dc);
1005 DestroyWindow(window);
1009 ret = SetPixelFormat(dc, pixel_format, &pf_desc);
1010 ok(ret, "Failed to set pixel format, last error %#x.\n", GetLastError());
1012 style = GetWindowLongA(window, GWL_STYLE);
1013 ok(style & WS_MINIMIZE, "Window should be minimized, got style %#x.\n", style);
1015 ctx = wglCreateContext(dc);
1016 ok(!!ctx, "Failed to create GL context, last error %#x.\n", GetLastError());
1018 ret = wglMakeCurrent(dc, ctx);
1019 ok(ret, "Failed to make context current, 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 ret = wglMakeCurrent(NULL, NULL);
1025 ok(ret, "Failed to clear current context, last error %#x.\n", GetLastError());
1027 ret = wglDeleteContext(ctx);
1028 ok(ret, "Failed to delete GL context, last error %#x.\n", GetLastError());
1030 ReleaseDC(window, dc);
1031 DestroyWindow(window);
1034 static void test_window_dc(void)
1036 PIXELFORMATDESCRIPTOR pf_desc =
1038 sizeof(PIXELFORMATDESCRIPTOR),
1040 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
1042 24, /* 24-bit color depth */
1043 0, 0, 0, 0, 0, 0, /* color bits */
1044 0, /* alpha buffer */
1046 0, /* accumulation buffer */
1047 0, 0, 0, 0, /* accum bits */
1049 0, /* stencil buffer */
1050 0, /* auxiliary buffer */
1051 PFD_MAIN_PLANE, /* main layer */
1053 0, 0, 0 /* layer masks */
1062 window = CreateWindowA("static", "opengl32_test",
1063 WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, 0, 0, 0, 0);
1064 ok(!!window, "Failed to create window, last error %#x.\n", GetLastError());
1066 ShowWindow(window, SW_SHOW);
1068 dc = GetWindowDC(window);
1069 ok(!!dc, "Failed to get DC.\n");
1071 pixel_format = ChoosePixelFormat(dc, &pf_desc);
1074 win_skip("Failed to find pixel format.\n");
1075 ReleaseDC(window, dc);
1076 DestroyWindow(window);
1080 ret = SetPixelFormat(dc, pixel_format, &pf_desc);
1081 ok(ret, "Failed to set pixel format, last error %#x.\n", GetLastError());
1083 ctx = wglCreateContext(dc);
1084 ok(!!ctx, "Failed to create GL context, last error %#x.\n", GetLastError());
1086 ret = wglMakeCurrent(dc, ctx);
1087 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1089 GetClientRect(window, &r);
1090 glGetIntegerv(GL_VIEWPORT, (GLint *)&vp);
1091 ok(EqualRect(&r, &vp), "Viewport not equal to client rect.\n");
1093 ret = wglMakeCurrent(NULL, NULL);
1094 ok(ret, "Failed to clear current context, last error %#x.\n", GetLastError());
1096 ret = wglDeleteContext(ctx);
1097 ok(ret, "Failed to delete GL context, last error %#x.\n", GetLastError());
1099 ReleaseDC(window, dc);
1100 DestroyWindow(window);
1103 static void test_destroy(HDC oldhdc)
1105 PIXELFORMATDESCRIPTOR pf_desc =
1107 sizeof(PIXELFORMATDESCRIPTOR),
1109 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
1111 24, /* 24-bit color depth */
1112 0, 0, 0, 0, 0, 0, /* color bits */
1113 0, /* alpha buffer */
1115 0, /* accumulation buffer */
1116 0, 0, 0, 0, /* accum bits */
1118 0, /* stencil buffer */
1119 0, /* auxiliary buffer */
1120 PFD_MAIN_PLANE, /* main layer */
1122 0, 0, 0 /* layer masks */
1131 HGLRC oldctx = wglGetCurrentContext();
1133 ok(!!oldctx, "Expected to find a valid current context.\n");
1135 window = CreateWindowA("static", "opengl32_test",
1136 WS_POPUP, 0, 0, 640, 480, 0, 0, 0, 0);
1137 ok(!!window, "Failed to create window, last error %#x.\n", GetLastError());
1140 ok(!!dc, "Failed to get DC.\n");
1142 pixel_format = ChoosePixelFormat(dc, &pf_desc);
1145 win_skip("Failed to find pixel format.\n");
1146 ReleaseDC(window, dc);
1147 DestroyWindow(window);
1151 ret = SetPixelFormat(dc, pixel_format, &pf_desc);
1152 ok(ret, "Failed to set pixel format, last error %#x.\n", GetLastError());
1154 ctx = wglCreateContext(dc);
1155 ok(!!ctx, "Failed to create GL context, last error %#x.\n", GetLastError());
1157 ret = wglMakeCurrent(dc, ctx);
1158 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1160 glClear(GL_COLOR_BUFFER_BIT);
1162 glerr = glGetError();
1163 ok(glerr == GL_NO_ERROR, "Failed glClear, error %#x.\n", glerr);
1164 ret = SwapBuffers(dc);
1165 ok(ret, "Failed SwapBuffers, error %#x.\n", GetLastError());
1167 ret = DestroyWindow(window);
1168 ok(ret, "Failed to destroy window, last error %#x.\n", GetLastError());
1170 ok(wglGetCurrentContext() == ctx, "Wrong current context.\n");
1172 SetLastError(0xdeadbeef);
1173 ret = wglMakeCurrent(dc, ctx);
1174 err = GetLastError();
1175 ok(!ret && err == ERROR_INVALID_HANDLE,
1176 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret, err);
1177 SetLastError(0xdeadbeef);
1178 ret = SwapBuffers(dc);
1179 err = GetLastError();
1180 ok(!ret && err == ERROR_INVALID_HANDLE, "Unexpected behavior with SwapBuffer, last error %#x.\n", err);
1182 ok(wglGetCurrentContext() == ctx, "Wrong current context.\n");
1184 glClear(GL_COLOR_BUFFER_BIT);
1186 glerr = glGetError();
1187 ok(glerr == GL_NO_ERROR, "Failed glClear, error %#x.\n", glerr);
1188 SetLastError(0xdeadbeef);
1189 ret = SwapBuffers(dc);
1190 err = GetLastError();
1191 ok(!ret && err == ERROR_INVALID_HANDLE, "Unexpected behavior with SwapBuffer, last error %#x.\n", err);
1193 ret = wglMakeCurrent(NULL, NULL);
1194 ok(ret, "Failed to clear current context, last error %#x.\n", GetLastError());
1196 glClear(GL_COLOR_BUFFER_BIT);
1198 glerr = glGetError();
1199 todo_wine ok(glerr == GL_INVALID_OPERATION, "Failed glClear, error %#x.\n", glerr);
1200 SetLastError(0xdeadbeef);
1201 ret = SwapBuffers(dc);
1202 err = GetLastError();
1203 ok(!ret && err == ERROR_INVALID_HANDLE, "Unexpected behavior with SwapBuffer, last error %#x.\n", err);
1205 SetLastError(0xdeadbeef);
1206 ret = wglMakeCurrent(dc, ctx);
1207 err = GetLastError();
1208 ok(!ret && err == ERROR_INVALID_HANDLE,
1209 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret, err);
1211 ok(wglGetCurrentContext() == NULL, "Wrong current context.\n");
1213 ret = wglMakeCurrent(oldhdc, oldctx);
1214 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1215 ok(wglGetCurrentContext() == oldctx, "Wrong current context.\n");
1217 SetLastError(0xdeadbeef);
1218 ret = wglMakeCurrent(dc, ctx);
1219 err = GetLastError();
1220 ok(!ret && err == ERROR_INVALID_HANDLE,
1221 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret, err);
1223 ok(wglGetCurrentContext() == oldctx, "Wrong current context.\n");
1225 ret = wglDeleteContext(ctx);
1226 ok(ret, "Failed to delete GL context, last error %#x.\n", GetLastError());
1228 ReleaseDC(window, dc);
1230 ret = wglMakeCurrent(oldhdc, oldctx);
1231 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1234 static void test_destroy_read(HDC oldhdc)
1236 PIXELFORMATDESCRIPTOR pf_desc =
1238 sizeof(PIXELFORMATDESCRIPTOR),
1240 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
1242 24, /* 24-bit color depth */
1243 0, 0, 0, 0, 0, 0, /* color bits */
1244 0, /* alpha buffer */
1246 0, /* accumulation buffer */
1247 0, 0, 0, 0, /* accum bits */
1249 0, /* stencil buffer */
1250 0, /* auxiliary buffer */
1251 PFD_MAIN_PLANE, /* main layer */
1253 0, 0, 0 /* layer masks */
1256 HWND draw_window, read_window;
1259 HDC read_dc, draw_dc;
1262 HGLRC oldctx = wglGetCurrentContext();
1264 ok(!!oldctx, "Expected to find a valid current context\n");
1266 draw_window = CreateWindowA("static", "opengl32_test",
1267 WS_POPUP, 0, 0, 640, 480, 0, 0, 0, 0);
1268 ok(!!draw_window, "Failed to create window, last error %#x.\n", GetLastError());
1270 draw_dc = GetDC(draw_window);
1271 ok(!!draw_dc, "Failed to get DC.\n");
1273 pixel_format = ChoosePixelFormat(draw_dc, &pf_desc);
1276 win_skip("Failed to find pixel format.\n");
1277 ReleaseDC(draw_window, draw_dc);
1278 DestroyWindow(draw_window);
1282 ret = SetPixelFormat(draw_dc, pixel_format, &pf_desc);
1283 ok(ret, "Failed to set pixel format, last error %#x.\n", GetLastError());
1285 read_window = CreateWindowA("static", "opengl32_test",
1286 WS_POPUP, 0, 0, 640, 480, 0, 0, 0, 0);
1287 ok(!!read_window, "Failed to create window, last error %#x.\n", GetLastError());
1289 read_dc = GetDC(read_window);
1290 ok(!!draw_dc, "Failed to get DC.\n");
1292 pixel_format = ChoosePixelFormat(read_dc, &pf_desc);
1295 win_skip("Failed to find pixel format.\n");
1296 ReleaseDC(read_window, read_dc);
1297 DestroyWindow(read_window);
1298 ReleaseDC(draw_window, draw_dc);
1299 DestroyWindow(draw_window);
1303 ret = SetPixelFormat(read_dc, pixel_format, &pf_desc);
1304 ok(ret, "Failed to set pixel format, last error %#x.\n", GetLastError());
1306 ctx = wglCreateContext(draw_dc);
1307 ok(!!ctx, "Failed to create GL context, last error %#x.\n", GetLastError());
1309 ret = pwglMakeContextCurrentARB(draw_dc, read_dc, ctx);
1310 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1312 glCopyPixels(0, 0, 640, 480, GL_COLOR);
1314 glerr = glGetError();
1315 ok(glerr == GL_NO_ERROR, "Failed glCopyPixel, error %#x.\n", glerr);
1316 ret = SwapBuffers(draw_dc);
1317 ok(ret, "Failed SwapBuffers, error %#x.\n", GetLastError());
1319 ret = DestroyWindow(read_window);
1320 ok(ret, "Failed to destroy window, last error %#x.\n", GetLastError());
1322 ok(wglGetCurrentContext() == ctx, "Wrong current context.\n");
1324 if (0) /* Crashes on AMD on Windows */
1326 glCopyPixels(0, 0, 640, 480, GL_COLOR);
1328 glerr = glGetError();
1329 ok(glerr == GL_NO_ERROR, "Failed glCopyPixel, error %#x.\n", glerr);
1332 glClear(GL_COLOR_BUFFER_BIT);
1334 glerr = glGetError();
1335 ok(glerr == GL_NO_ERROR, "Failed glClear, error %#x.\n", glerr);
1336 ret = SwapBuffers(draw_dc);
1337 ok(ret, "Failed SwapBuffers, error %#x.\n", GetLastError());
1339 ret = wglMakeCurrent(NULL, NULL);
1340 ok(ret, "Failed to clear current context, last error %#x.\n", GetLastError());
1342 if (0) /* This crashes with Nvidia drivers on Windows. */
1344 SetLastError(0xdeadbeef);
1345 ret = pwglMakeContextCurrentARB(draw_dc, read_dc, ctx);
1346 err = GetLastError();
1347 ok(!ret && err == ERROR_INVALID_HANDLE,
1348 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret, err);
1351 ret = DestroyWindow(draw_window);
1352 ok(ret, "Failed to destroy window, last error %#x.\n", GetLastError());
1354 glClear(GL_COLOR_BUFFER_BIT);
1356 glerr = glGetError();
1357 todo_wine ok(glerr == GL_INVALID_OPERATION, "Failed glClear, error %#x.\n", glerr);
1358 SetLastError(0xdeadbeef);
1359 ret = SwapBuffers(draw_dc);
1360 err = GetLastError();
1361 ok(!ret && err == ERROR_INVALID_HANDLE, "Unexpected behavior with SwapBuffer, last error %#x.\n", err);
1363 SetLastError(0xdeadbeef);
1364 ret = pwglMakeContextCurrentARB(draw_dc, read_dc, ctx);
1365 err = GetLastError();
1366 ok(!ret && (err == ERROR_INVALID_HANDLE || err == 0xc0070006),
1367 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret, err);
1369 ok(wglGetCurrentContext() == NULL, "Wrong current context.\n");
1371 wglMakeCurrent(NULL, NULL);
1373 wglMakeCurrent(oldhdc, oldctx);
1374 ok(wglGetCurrentContext() == oldctx, "Wrong current context.\n");
1376 SetLastError(0xdeadbeef);
1377 ret = pwglMakeContextCurrentARB(draw_dc, read_dc, ctx);
1378 err = GetLastError();
1379 ok(!ret && (err == ERROR_INVALID_HANDLE || err == 0xc0070006),
1380 "Unexpected behavior when making context current, last error %#x.\n", err);
1382 ok(wglGetCurrentContext() == oldctx, "Wrong current context.\n");
1384 ret = wglDeleteContext(ctx);
1385 ok(ret, "Failed to delete GL context, last error %#x.\n", GetLastError());
1387 ReleaseDC(read_window, read_dc);
1388 ReleaseDC(draw_window, draw_dc);
1390 wglMakeCurrent(oldhdc, oldctx);
1396 PIXELFORMATDESCRIPTOR pfd = {
1397 sizeof(PIXELFORMATDESCRIPTOR),
1399 PFD_DRAW_TO_WINDOW |
1400 PFD_SUPPORT_OPENGL |
1403 24, /* 24-bit color depth */
1404 0, 0, 0, 0, 0, 0, /* color bits */
1405 0, /* alpha buffer */
1407 0, /* accumulation buffer */
1408 0, 0, 0, 0, /* accum bits */
1410 0, /* stencil buffer */
1411 0, /* auxiliary buffer */
1412 PFD_MAIN_PLANE, /* main layer */
1414 0, 0, 0 /* layer masks */
1417 hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW,
1418 10, 10, 200, 200, NULL, NULL, NULL, NULL);
1419 ok(hwnd != NULL, "err: %d\n", GetLastError());
1423 int iPixelFormat, res;
1426 ShowWindow(hwnd, SW_SHOW);
1430 iPixelFormat = ChoosePixelFormat(hdc, &pfd);
1431 if(iPixelFormat == 0)
1433 /* This should never happen as ChoosePixelFormat always returns a closest match, but currently this fails in Wine if we don't have glX */
1434 win_skip("Unable to find pixel format.\n");
1438 /* We shouldn't be able to create a context from a hdc which doesn't have a pixel format set */
1439 hglrc = wglCreateContext(hdc);
1440 ok(hglrc == NULL, "wglCreateContext should fail when no pixel format has been set, but it passed\n");
1441 error = GetLastError();
1442 ok(error == ERROR_INVALID_PIXEL_FORMAT, "expected ERROR_INVALID_PIXEL_FORMAT for wglCreateContext without a pixelformat set, but received %#x\n", error);
1444 res = SetPixelFormat(hdc, iPixelFormat, &pfd);
1445 ok(res, "SetPixelformat failed: %x\n", GetLastError());
1447 test_bitmap_rendering( TRUE );
1448 test_bitmap_rendering( FALSE );
1453 hglrc = wglCreateContext(hdc);
1454 res = wglMakeCurrent(hdc, hglrc);
1455 ok(res, "wglMakeCurrent failed!\n");
1458 trace("OpenGL renderer: %s\n", glGetString(GL_RENDERER));
1459 trace("OpenGL driver version: %s\n", glGetString(GL_VERSION));
1460 trace("OpenGL vendor: %s\n", glGetString(GL_VENDOR));
1464 skip("Skipping OpenGL tests without a current context\n");
1468 /* Initialisation of WGL functions depends on an implicit WGL context. For this reason we can't load them before making
1469 * any WGL call :( On Wine this would work but not on real Windows because there can be different implementations (software, ICD, MCD).
1472 /* The lack of wglGetExtensionsStringARB in general means broken software rendering or the lack of decent OpenGL support, skip tests in such cases */
1473 if (!pwglGetExtensionsStringARB)
1475 win_skip("wglGetExtensionsStringARB is not available\n");
1479 test_getprocaddress(hdc);
1480 test_deletecontext(hdc);
1481 test_makecurrent(hdc);
1482 test_setpixelformat(hdc);
1484 test_sharelists(hdc);
1485 test_colorbits(hdc);
1487 test_acceleration(hdc);
1489 wgl_extensions = pwglGetExtensionsStringARB(hdc);
1490 if(wgl_extensions == NULL) skip("Skipping opengl32 tests because this OpenGL implementation doesn't support WGL extensions!\n");
1492 if(strstr(wgl_extensions, "WGL_ARB_create_context"))
1495 if(strstr(wgl_extensions, "WGL_ARB_make_current_read"))
1497 test_make_current_read(hdc);
1498 test_destroy_read(hdc);
1501 skip("WGL_ARB_make_current_read not supported, skipping test\n");
1503 if(strstr(wgl_extensions, "WGL_ARB_pbuffer"))
1506 skip("WGL_ARB_pbuffer not supported, skipping pbuffer test\n");
1509 ReleaseDC(hwnd, hdc);
1510 DestroyWindow(hwnd);