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"
26 #define MAX_FORMATS 256
27 typedef void* HPBUFFERARB
;
29 /* WGL_ARB_create_context */
30 static HGLRC (WINAPI
*pwglCreateContextAttribsARB
)(HDC hDC
, HGLRC hShareContext
, const int *attribList
);
32 #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
33 #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
34 #define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
35 #define WGL_CONTEXT_FLAGS_ARB 0x2094
37 /* Flags for WGL_CONTEXT_FLAGS_ARB */
38 #define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
39 #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
41 /* WGL_ARB_extensions_string */
42 static const char* (WINAPI
*pwglGetExtensionsStringARB
)(HDC
);
43 static int (WINAPI
*pwglReleasePbufferDCARB
)(HPBUFFERARB
, HDC
);
45 /* WGL_ARB_make_current_read */
46 static BOOL (WINAPI
*pwglMakeContextCurrentARB
)(HDC hdraw
, HDC hread
, HGLRC hglrc
);
47 static HDC (WINAPI
*pwglGetCurrentReadDCARB
)(void);
49 /* WGL_ARB_pixel_format */
50 #define WGL_ACCELERATION_ARB 0x2003
51 #define WGL_COLOR_BITS_ARB 0x2014
52 #define WGL_RED_BITS_ARB 0x2015
53 #define WGL_GREEN_BITS_ARB 0x2017
54 #define WGL_BLUE_BITS_ARB 0x2019
55 #define WGL_ALPHA_BITS_ARB 0x201B
56 #define WGL_SUPPORT_GDI_ARB 0x200F
57 #define WGL_DOUBLE_BUFFER_ARB 0x2011
58 #define WGL_NO_ACCELERATION_ARB 0x2025
59 #define WGL_GENERIC_ACCELERATION_ARB 0x2026
60 #define WGL_FULL_ACCELERATION_ARB 0x2027
62 static BOOL (WINAPI
*pwglChoosePixelFormatARB
)(HDC
, const int *, const FLOAT
*, UINT
, int *, UINT
*);
63 static BOOL (WINAPI
*pwglGetPixelFormatAttribivARB
)(HDC
, int, int, UINT
, const int *, int *);
66 #define WGL_DRAW_TO_PBUFFER_ARB 0x202D
67 static HPBUFFERARB
* (WINAPI
*pwglCreatePbufferARB
)(HDC
, int, int, int, const int *);
68 static HDC (WINAPI
*pwglGetPbufferDCARB
)(HPBUFFERARB
);
70 /* WGL_EXT_swap_control */
71 static BOOL (WINAPI
*pwglSwapIntervalEXT
)(int interval
);
72 static int (WINAPI
*pwglGetSwapIntervalEXT
)(void);
74 static const char* wgl_extensions
= NULL
;
76 static void init_functions(void)
78 #define GET_PROC(func) \
79 p ## func = (void*)wglGetProcAddress(#func); \
81 trace("wglGetProcAddress(%s) failed\n", #func);
83 /* WGL_ARB_create_context */
84 GET_PROC(wglCreateContextAttribsARB
);
86 /* WGL_ARB_extensions_string */
87 GET_PROC(wglGetExtensionsStringARB
)
89 /* WGL_ARB_make_current_read */
90 GET_PROC(wglMakeContextCurrentARB
);
91 GET_PROC(wglGetCurrentReadDCARB
);
93 /* WGL_ARB_pixel_format */
94 GET_PROC(wglChoosePixelFormatARB
)
95 GET_PROC(wglGetPixelFormatAttribivARB
)
98 GET_PROC(wglCreatePbufferARB
)
99 GET_PROC(wglGetPbufferDCARB
)
100 GET_PROC(wglReleasePbufferDCARB
)
102 /* WGL_EXT_swap_control */
103 GET_PROC(wglSwapIntervalEXT
)
104 GET_PROC(wglGetSwapIntervalEXT
)
109 static BOOL
gl_extension_supported(const char *extensions
, const char *extension_string
)
111 size_t ext_str_len
= strlen(extension_string
);
118 while (isspace(*extensions
))
121 while (!isspace(*extensions
) && *extensions
)
124 len
= extensions
- start
;
128 if (len
== ext_str_len
&& !memcmp(start
, extension_string
, ext_str_len
))
136 static void test_pbuffers(HDC hdc
)
138 const int iAttribList
[] = { WGL_DRAW_TO_PBUFFER_ARB
, 1, /* Request pbuffer support */
140 int iFormats
[MAX_FORMATS
];
141 unsigned int nOnscreenFormats
;
142 unsigned int nFormats
;
144 int iPixelFormat
= 0;
146 nOnscreenFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
148 /* When you want to render to a pbuffer you need to call wglGetPbufferDCARB which
149 * returns a 'magic' HDC which you can then pass to wglMakeCurrent to switch rendering
150 * to the pbuffer. Below some tests are performed on what happens if you use standard WGL calls
151 * on this 'magic' HDC for both a pixelformat that support onscreen and offscreen rendering
152 * and a pixelformat that's only available for offscreen rendering (this means that only
153 * wglChoosePixelFormatARB and friends know about the format.
155 * The first thing we need are pixelformats with pbuffer capabilities.
157 res
= pwglChoosePixelFormatARB(hdc
, iAttribList
, NULL
, MAX_FORMATS
, iFormats
, &nFormats
);
160 skip("No pbuffer compatible formats found while WGL_ARB_pbuffer is supported\n");
163 trace("nOnscreenFormats: %d\n", nOnscreenFormats
);
164 trace("Total number of pbuffer capable pixelformats: %d\n", nFormats
);
166 /* Try to select an onscreen pixelformat out of the list */
167 for(i
=0; i
< nFormats
; i
++)
169 /* Check if the format is onscreen, if it is choose it */
170 if(iFormats
[i
] <= nOnscreenFormats
)
172 iPixelFormat
= iFormats
[i
];
173 trace("Selected iPixelFormat=%d\n", iPixelFormat
);
178 /* A video driver supports a large number of onscreen and offscreen pixelformats.
179 * The traditional WGL calls only see a subset of the whole pixelformat list. First
180 * of all they only see the onscreen formats (the offscreen formats are at the end of the
181 * pixelformat list) and second extended pixelformat capabilities are hidden from the
182 * standard WGL calls. Only functions that depend on WGL_ARB_pixel_format can see them.
184 * Below we check if the pixelformat is also supported onscreen.
186 if(iPixelFormat
!= 0)
190 HPBUFFERARB pbuffer
= pwglCreatePbufferARB(hdc
, iPixelFormat
, 640 /* width */, 480 /* height */, &attrib
);
192 skip("Pbuffer creation failed!\n");
194 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
195 pbuffer_hdc
= pwglGetPbufferDCARB(pbuffer
);
196 res
= GetPixelFormat(pbuffer_hdc
);
197 ok(res
== iPixelFormat
, "Unexpected iPixelFormat=%d returned by GetPixelFormat for format %d\n", res
, iPixelFormat
);
198 trace("iPixelFormat returned by GetPixelFormat: %d\n", res
);
199 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat
);
201 pwglReleasePbufferDCARB(pbuffer
, pbuffer_hdc
);
203 else skip("Pbuffer test for onscreen pixelformat skipped as no onscreen format with pbuffer capabilities have been found\n");
205 /* Search for a real offscreen format */
206 for(i
=0, iPixelFormat
=0; i
<nFormats
; i
++)
208 if(iFormats
[i
] > nOnscreenFormats
)
210 iPixelFormat
= iFormats
[i
];
211 trace("Selected iPixelFormat: %d\n", iPixelFormat
);
216 if(iPixelFormat
!= 0)
219 HPBUFFERARB pbuffer
= pwglCreatePbufferARB(hdc
, iPixelFormat
, 640 /* width */, 480 /* height */, NULL
);
221 skip("Pbuffer creation failed!\n");
223 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
224 pbuffer_hdc
= pwglGetPbufferDCARB(pbuffer
);
225 res
= GetPixelFormat(pbuffer_hdc
);
227 ok(res
== 1, "Unexpected iPixelFormat=%d (1 expected) returned by GetPixelFormat for offscreen format %d\n", res
, iPixelFormat
);
228 trace("iPixelFormat returned by GetPixelFormat: %d\n", res
);
229 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat
);
230 pwglReleasePbufferDCARB(pbuffer
, hdc
);
232 else skip("Pbuffer test for offscreen pixelformat skipped as no offscreen-only format with pbuffer capabilities has been found\n");
235 static int test_pfd(const PIXELFORMATDESCRIPTOR
*pfd
)
241 hwnd
= CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW
, 10, 10, 200, 200, NULL
, NULL
,
247 pf
= ChoosePixelFormat( hdc
, pfd
);
248 ReleaseDC( hwnd
, hdc
);
249 DestroyWindow( hwnd
);
254 static void test_choosepixelformat(void)
256 PIXELFORMATDESCRIPTOR pfd
= {
257 sizeof(PIXELFORMATDESCRIPTOR
),
263 0, 0, 0, 0, 0, 0, /* color bits */
264 0, /* alpha buffer */
266 0, /* accumulation buffer */
267 0, 0, 0, 0, /* accum bits */
269 0, /* stencil buffer */
270 0, /* auxiliary buffer */
271 PFD_MAIN_PLANE
, /* main layer */
273 0, 0, 0 /* layer masks */
276 ok( test_pfd(&pfd
), "Simple pfd failed\n" );
277 pfd
.dwFlags
|= PFD_DOUBLEBUFFER_DONTCARE
;
278 ok( test_pfd(&pfd
), "PFD_DOUBLEBUFFER_DONTCARE failed\n" );
279 pfd
.dwFlags
|= PFD_STEREO_DONTCARE
;
280 ok( test_pfd(&pfd
), "PFD_DOUBLEBUFFER_DONTCARE|PFD_STEREO_DONTCARE failed\n" );
281 pfd
.dwFlags
&= ~PFD_DOUBLEBUFFER_DONTCARE
;
282 ok( test_pfd(&pfd
), "PFD_STEREO_DONTCARE failed\n" );
283 pfd
.dwFlags
&= ~PFD_STEREO_DONTCARE
;
286 ok( test_pfd(&pfd
), "Simple pfd failed\n" );
287 pfd
.dwFlags
|= PFD_DOUBLEBUFFER_DONTCARE
;
288 ok( test_pfd(&pfd
), "PFD_DOUBLEBUFFER_DONTCARE failed\n" );
289 pfd
.dwFlags
|= PFD_STEREO_DONTCARE
;
290 ok( test_pfd(&pfd
), "PFD_DOUBLEBUFFER_DONTCARE|PFD_STEREO_DONTCARE failed\n" );
291 pfd
.dwFlags
&= ~PFD_DOUBLEBUFFER_DONTCARE
;
292 ok( test_pfd(&pfd
), "PFD_STEREO_DONTCARE failed\n" );
293 pfd
.dwFlags
&= ~PFD_STEREO_DONTCARE
;
297 ok( test_pfd(&pfd
), "Simple pfd failed\n" );
298 pfd
.dwFlags
|= PFD_DOUBLEBUFFER_DONTCARE
;
299 ok( test_pfd(&pfd
), "PFD_DOUBLEBUFFER_DONTCARE failed\n" );
300 pfd
.dwFlags
|= PFD_STEREO_DONTCARE
;
301 ok( test_pfd(&pfd
), "PFD_DOUBLEBUFFER_DONTCARE|PFD_STEREO_DONTCARE failed\n" );
302 pfd
.dwFlags
&= ~PFD_DOUBLEBUFFER_DONTCARE
;
303 ok( test_pfd(&pfd
), "PFD_STEREO_DONTCARE failed\n" );
304 pfd
.dwFlags
&= ~PFD_STEREO_DONTCARE
;
307 pfd
.cStencilBits
= 8;
308 ok( test_pfd(&pfd
), "Simple pfd failed\n" );
309 pfd
.dwFlags
|= PFD_DOUBLEBUFFER_DONTCARE
;
310 ok( test_pfd(&pfd
), "PFD_DOUBLEBUFFER_DONTCARE failed\n" );
311 pfd
.dwFlags
|= PFD_STEREO_DONTCARE
;
312 ok( test_pfd(&pfd
), "PFD_DOUBLEBUFFER_DONTCARE|PFD_STEREO_DONTCARE failed\n" );
313 pfd
.dwFlags
&= ~PFD_DOUBLEBUFFER_DONTCARE
;
314 ok( test_pfd(&pfd
), "PFD_STEREO_DONTCARE failed\n" );
315 pfd
.dwFlags
&= ~PFD_STEREO_DONTCARE
;
316 pfd
.cStencilBits
= 0;
319 ok( test_pfd(&pfd
), "Simple pfd failed\n" );
320 pfd
.dwFlags
|= PFD_DOUBLEBUFFER_DONTCARE
;
321 ok( test_pfd(&pfd
), "PFD_DOUBLEBUFFER_DONTCARE failed\n" );
322 pfd
.dwFlags
|= PFD_STEREO_DONTCARE
;
323 ok( test_pfd(&pfd
), "PFD_DOUBLEBUFFER_DONTCARE|PFD_STEREO_DONTCARE failed\n" );
324 pfd
.dwFlags
&= ~PFD_DOUBLEBUFFER_DONTCARE
;
325 ok( test_pfd(&pfd
), "PFD_STEREO_DONTCARE failed\n" );
326 pfd
.dwFlags
&= ~PFD_STEREO_DONTCARE
;
330 static void test_setpixelformat(HDC winhdc
)
337 PIXELFORMATDESCRIPTOR pfd
= {
338 sizeof(PIXELFORMATDESCRIPTOR
),
344 24, /* 24-bit color depth */
345 0, 0, 0, 0, 0, 0, /* color bits */
346 0, /* alpha buffer */
348 0, /* accumulation buffer */
349 0, 0, 0, 0, /* accum bits */
351 0, /* stencil buffer */
352 0, /* auxiliary buffer */
353 PFD_MAIN_PLANE
, /* main layer */
355 0, 0, 0 /* layer masks */
359 ok(hdc
!= 0, "GetDC(0) failed!\n");
361 /* This should pass even on the main device context */
362 pf
= ChoosePixelFormat(hdc
, &pfd
);
363 ok(pf
!= 0, "ChoosePixelFormat failed on main device context\n");
365 /* SetPixelFormat on the main device context 'X root window' should fail,
366 * but some broken drivers allow it
368 res
= SetPixelFormat(hdc
, pf
, &pfd
);
369 trace("SetPixelFormat on main device context %s\n", res
? "succeeded" : "failed");
371 /* Setting the same format that was set on the HDC is allowed; other
373 nCfgs
= DescribePixelFormat(winhdc
, 0, 0, NULL
);
374 pf
= GetPixelFormat(winhdc
);
375 for(i
= 1;i
<= nCfgs
;i
++)
377 int res
= SetPixelFormat(winhdc
, i
, NULL
);
378 if(i
== pf
) ok(res
, "Failed to set the same pixel format\n");
379 else ok(!res
, "Unexpectedly set an alternate pixel format\n");
382 hwnd
= CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW
, 10, 10, 200, 200, NULL
, NULL
,
384 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
387 HDC hdc
= GetDC( hwnd
);
388 pf
= ChoosePixelFormat( hdc
, &pfd
);
389 ok( pf
!= 0, "ChoosePixelFormat failed\n" );
390 res
= SetPixelFormat( hdc
, pf
, &pfd
);
391 ok( res
!= 0, "SetPixelFormat failed\n" );
392 i
= GetPixelFormat( hdc
);
393 ok( i
== pf
, "GetPixelFormat returned wrong format %d/%d\n", i
, pf
);
394 ReleaseDC( hwnd
, hdc
);
395 hdc
= GetWindowDC( hwnd
);
396 i
= GetPixelFormat( hdc
);
397 ok( i
== pf
, "GetPixelFormat returned wrong format %d/%d\n", i
, pf
);
398 ReleaseDC( hwnd
, hdc
);
399 DestroyWindow( hwnd
);
400 /* check various calls with invalid hdc */
401 SetLastError( 0xdeadbeef );
402 i
= GetPixelFormat( hdc
);
403 ok( i
== 0, "GetPixelFormat succeeded\n" );
404 ok( GetLastError() == ERROR_INVALID_PIXEL_FORMAT
, "wrong error %u\n", GetLastError() );
405 SetLastError( 0xdeadbeef );
406 res
= SetPixelFormat( hdc
, pf
, &pfd
);
407 ok( !res
, "SetPixelFormat succeeded\n" );
408 ok( GetLastError() == ERROR_INVALID_HANDLE
, "wrong error %u\n", GetLastError() );
409 SetLastError( 0xdeadbeef );
410 res
= DescribePixelFormat( hdc
, 0, 0, NULL
);
411 ok( !res
, "DescribePixelFormat succeeded\n" );
412 ok( GetLastError() == ERROR_INVALID_HANDLE
, "wrong error %u\n", GetLastError() );
413 SetLastError( 0xdeadbeef );
414 pf
= ChoosePixelFormat( hdc
, &pfd
);
415 ok( !pf
, "ChoosePixelFormat succeeded\n" );
416 ok( GetLastError() == ERROR_INVALID_HANDLE
, "wrong error %u\n", GetLastError() );
417 SetLastError( 0xdeadbeef );
418 res
= SwapBuffers( hdc
);
419 ok( !res
, "SwapBuffers succeeded\n" );
420 ok( GetLastError() == ERROR_INVALID_HANDLE
, "wrong error %u\n", GetLastError() );
421 SetLastError( 0xdeadbeef );
422 ok( !wglCreateContext( hdc
), "CreateContext succeeded\n" );
423 ok( GetLastError() == ERROR_INVALID_HANDLE
, "wrong error %u\n", GetLastError() );
426 hwnd
= CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW
, 10, 10, 200, 200, NULL
, NULL
,
428 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
431 HDC hdc
= GetWindowDC( hwnd
);
432 pf
= ChoosePixelFormat( hdc
, &pfd
);
433 ok( pf
!= 0, "ChoosePixelFormat failed\n" );
434 res
= SetPixelFormat( hdc
, pf
, &pfd
);
435 ok( res
!= 0, "SetPixelFormat failed\n" );
436 i
= GetPixelFormat( hdc
);
437 ok( i
== pf
, "GetPixelFormat returned wrong format %d/%d\n", i
, pf
);
438 ReleaseDC( hwnd
, hdc
);
439 DestroyWindow( hwnd
);
443 static void test_sharelists(HDC winhdc
)
445 HGLRC hglrc1
, hglrc2
, hglrc3
;
448 hglrc1
= wglCreateContext(winhdc
);
449 res
= wglShareLists(0, 0);
450 ok(res
== FALSE
, "Sharing display lists for no contexts passed!\n");
452 /* Test 1: Create a context and just share lists without doing anything special */
453 hglrc2
= wglCreateContext(winhdc
);
456 res
= wglShareLists(hglrc1
, hglrc2
);
457 ok(res
, "Sharing of display lists failed\n");
458 wglDeleteContext(hglrc2
);
461 /* Test 2: Share display lists with a 'destination' context which has been made current */
462 hglrc2
= wglCreateContext(winhdc
);
465 res
= wglMakeCurrent(winhdc
, hglrc2
);
466 ok(res
, "Make current failed\n");
467 res
= wglShareLists(hglrc1
, hglrc2
);
468 todo_wine
ok(res
, "Sharing display lists with a destination context which has been made current failed\n");
469 wglMakeCurrent(0, 0);
470 wglDeleteContext(hglrc2
);
473 /* Test 3: Share display lists with a context which already shares display lists with another context.
474 * According to MSDN the second parameter cannot share any display lists but some buggy drivers might allow it */
475 hglrc3
= wglCreateContext(winhdc
);
478 res
= wglShareLists(hglrc3
, hglrc1
);
479 ok(res
== FALSE
, "Sharing of display lists passed for a context which already shared lists before\n");
480 wglDeleteContext(hglrc3
);
483 /* Test 4: Share display lists with a 'source' context which has been made current */
484 hglrc2
= wglCreateContext(winhdc
);
487 res
= wglMakeCurrent(winhdc
, hglrc1
);
488 ok(res
, "Make current failed\n");
489 res
= wglShareLists(hglrc1
, hglrc2
);
490 ok(res
, "Sharing display lists with a source context which has been made current failed\n");
491 wglMakeCurrent(0, 0);
492 wglDeleteContext(hglrc2
);
496 static void test_makecurrent(HDC winhdc
)
501 hglrc
= wglCreateContext(winhdc
);
502 ok( hglrc
!= 0, "wglCreateContext failed\n" );
504 ret
= wglMakeCurrent( winhdc
, hglrc
);
505 ok( ret
, "wglMakeCurrent failed\n" );
507 ok( wglGetCurrentContext() == hglrc
, "wrong context\n" );
509 /* set the same context again */
510 ret
= wglMakeCurrent( winhdc
, hglrc
);
511 ok( ret
, "wglMakeCurrent failed\n" );
513 /* check wglMakeCurrent(x, y) after another call to wglMakeCurrent(x, y) */
514 ret
= wglMakeCurrent( winhdc
, NULL
);
515 ok( ret
, "wglMakeCurrent failed\n" );
517 ret
= wglMakeCurrent( winhdc
, NULL
);
518 ok( ret
, "wglMakeCurrent failed\n" );
520 SetLastError( 0xdeadbeef );
521 ret
= wglMakeCurrent( NULL
, NULL
);
522 ok( !ret
|| broken(ret
) /* nt4 */, "wglMakeCurrent succeeded\n" );
523 if (!ret
) ok( GetLastError() == ERROR_INVALID_HANDLE
,
524 "Expected ERROR_INVALID_HANDLE, got error=%x\n", GetLastError() );
526 ret
= wglMakeCurrent( winhdc
, NULL
);
527 ok( ret
, "wglMakeCurrent failed\n" );
529 ret
= wglMakeCurrent( winhdc
, hglrc
);
530 ok( ret
, "wglMakeCurrent failed\n" );
532 ret
= wglMakeCurrent( NULL
, NULL
);
533 ok( ret
, "wglMakeCurrent failed\n" );
535 ok( wglGetCurrentContext() == NULL
, "wrong context\n" );
537 SetLastError( 0xdeadbeef );
538 ret
= wglMakeCurrent( NULL
, NULL
);
539 ok( !ret
|| broken(ret
) /* nt4 */, "wglMakeCurrent succeeded\n" );
540 if (!ret
) ok( GetLastError() == ERROR_INVALID_HANDLE
,
541 "Expected ERROR_INVALID_HANDLE, got error=%x\n", GetLastError() );
543 ret
= wglMakeCurrent( winhdc
, hglrc
);
544 ok( ret
, "wglMakeCurrent failed\n" );
547 static void test_colorbits(HDC hdc
)
549 const int iAttribList
[] = { WGL_COLOR_BITS_ARB
, WGL_RED_BITS_ARB
, WGL_GREEN_BITS_ARB
,
550 WGL_BLUE_BITS_ARB
, WGL_ALPHA_BITS_ARB
};
551 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
552 const int iAttribs
[] = { WGL_ALPHA_BITS_ARB
, 1, 0 };
553 unsigned int nFormats
;
555 int iPixelFormat
= 0;
557 if (!pwglChoosePixelFormatARB
)
559 win_skip("wglChoosePixelFormatARB is not available\n");
563 /* We need a pixel format with at least one bit of alpha */
564 res
= pwglChoosePixelFormatARB(hdc
, iAttribs
, NULL
, 1, &iPixelFormat
, &nFormats
);
565 if(res
== FALSE
|| nFormats
== 0)
567 skip("No suitable pixel formats found\n");
571 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
572 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
, iAttribRet
);
575 skip("wglGetPixelFormatAttribivARB failed\n");
578 iAttribRet
[1] += iAttribRet
[2]+iAttribRet
[3]+iAttribRet
[4];
579 ok(iAttribRet
[0] == iAttribRet
[1], "WGL_COLOR_BITS_ARB (%d) does not equal R+G+B+A (%d)!\n",
580 iAttribRet
[0], iAttribRet
[1]);
583 static void test_gdi_dbuf(HDC hdc
)
585 const int iAttribList
[] = { WGL_SUPPORT_GDI_ARB
, WGL_DOUBLE_BUFFER_ARB
};
586 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
587 unsigned int nFormats
;
591 if (!pwglGetPixelFormatAttribivARB
)
593 win_skip("wglGetPixelFormatAttribivARB is not available\n");
597 nFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
598 for(iPixelFormat
= 1;iPixelFormat
<= nFormats
;iPixelFormat
++)
600 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
601 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
,
603 ok(res
!=FALSE
, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat
);
607 ok(!(iAttribRet
[0] && iAttribRet
[1]), "GDI support and double buffering on pixel format %d\n", iPixelFormat
);
611 static void test_acceleration(HDC hdc
)
613 const int iAttribList
[] = { WGL_ACCELERATION_ARB
};
614 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
615 unsigned int nFormats
;
618 PIXELFORMATDESCRIPTOR pfd
;
620 if (!pwglGetPixelFormatAttribivARB
)
622 win_skip("wglGetPixelFormatAttribivARB is not available\n");
626 nFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
627 for(iPixelFormat
= 1; iPixelFormat
<= nFormats
; iPixelFormat
++)
629 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
630 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
,
632 ok(res
!=FALSE
, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat
);
636 memset(&pfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
637 DescribePixelFormat(hdc
, iPixelFormat
, sizeof(PIXELFORMATDESCRIPTOR
), &pfd
);
639 switch(iAttribRet
[0])
641 case WGL_NO_ACCELERATION_ARB
:
642 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
);
644 case WGL_GENERIC_ACCELERATION_ARB
:
645 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
);
647 case WGL_FULL_ACCELERATION_ARB
:
648 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
);
654 static void test_bitmap_rendering( BOOL use_dib
)
656 PIXELFORMATDESCRIPTOR pfd
;
657 int i
, ret
, bpp
, iPixelFormat
=0;
658 unsigned int nFormats
;
661 HBITMAP bmpDst
, oldDst
, bmp2
;
662 HDC hdcDst
, hdcScreen
;
663 UINT
*dstBuffer
= NULL
;
665 hdcScreen
= CreateCompatibleDC(0);
666 hdcDst
= CreateCompatibleDC(0);
671 memset(&biDst
, 0, sizeof(BITMAPINFO
));
672 biDst
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
673 biDst
.bmiHeader
.biWidth
= 4;
674 biDst
.bmiHeader
.biHeight
= -4;
675 biDst
.bmiHeader
.biPlanes
= 1;
676 biDst
.bmiHeader
.biBitCount
= 32;
677 biDst
.bmiHeader
.biCompression
= BI_RGB
;
679 bmpDst
= CreateDIBSection(0, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
, NULL
, 0);
681 biDst
.bmiHeader
.biWidth
= 12;
682 biDst
.bmiHeader
.biHeight
= -12;
683 biDst
.bmiHeader
.biBitCount
= 16;
684 bmp2
= CreateDIBSection(0, &biDst
, DIB_RGB_COLORS
, NULL
, NULL
, 0);
688 bpp
= GetDeviceCaps( hdcScreen
, BITSPIXEL
);
689 bmpDst
= CreateBitmap( 4, 4, 1, bpp
, NULL
);
690 bmp2
= CreateBitmap( 12, 12, 1, bpp
, NULL
);
693 oldDst
= SelectObject(hdcDst
, bmpDst
);
695 trace( "testing on %s\n", use_dib
? "DIB" : "DDB" );
697 /* Pick a pixel format by hand because ChoosePixelFormat is unreliable */
698 nFormats
= DescribePixelFormat(hdcDst
, 0, 0, NULL
);
699 for(i
=1; i
<=nFormats
; i
++)
701 memset(&pfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
702 DescribePixelFormat(hdcDst
, i
, sizeof(PIXELFORMATDESCRIPTOR
), &pfd
);
704 if((pfd
.dwFlags
& PFD_DRAW_TO_BITMAP
) &&
705 (pfd
.dwFlags
& PFD_SUPPORT_OPENGL
) &&
706 (pfd
.cColorBits
== bpp
) &&
707 (pfd
.cAlphaBits
== 8) )
716 skip("Unable to find a suitable pixel format\n");
720 ret
= SetPixelFormat(hdcDst
, iPixelFormat
, &pfd
);
721 ok( ret
, "SetPixelFormat failed\n" );
722 ret
= GetPixelFormat( hdcDst
);
723 ok( ret
== iPixelFormat
, "GetPixelFormat returned %d/%d\n", ret
, iPixelFormat
);
724 ret
= SetPixelFormat(hdcDst
, iPixelFormat
+ 1, &pfd
);
725 ok( !ret
, "SetPixelFormat succeeded\n" );
726 hglrc
= wglCreateContext(hdcDst
);
727 ok(hglrc
!= NULL
, "Unable to create a context\n");
732 wglMakeCurrent(hdcDst
, hglrc
);
733 hglrc2
= wglCreateContext(hdcDst
);
734 ok(hglrc2
!= NULL
, "Unable to create a context\n");
736 /* Note this is RGBA but we read ARGB back */
737 glClearColor((float)0x22/0xff, (float)0x33/0xff, (float)0x44/0xff, (float)0x11/0xff);
738 glClear(GL_COLOR_BUFFER_BIT
);
739 glGetIntegerv( GL_VIEWPORT
, viewport
);
742 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 4 && viewport
[3] == 4,
743 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
744 /* Note apparently the alpha channel is not supported by the software renderer (bitmap only works using software) */
746 for (i
= 0; i
< 16; i
++)
747 ok(dstBuffer
[i
] == 0x223344 || dstBuffer
[i
] == 0x11223344, "Received color=%x at %u\n",
750 SelectObject(hdcDst
, bmp2
);
751 ret
= GetPixelFormat( hdcDst
);
752 ok( ret
== iPixelFormat
, "GetPixelFormat returned %d/%d\n", ret
, iPixelFormat
);
753 ret
= SetPixelFormat(hdcDst
, iPixelFormat
+ 1, &pfd
);
754 ok( !ret
, "SetPixelFormat succeeded\n" );
756 /* context still uses the old pixel format and viewport */
757 glClearColor((float)0x44/0xff, (float)0x33/0xff, (float)0x22/0xff, (float)0x11/0xff);
758 glClear(GL_COLOR_BUFFER_BIT
);
760 glGetIntegerv( GL_VIEWPORT
, viewport
);
761 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 4 && viewport
[3] == 4,
762 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
764 wglMakeCurrent(NULL
, NULL
);
765 wglMakeCurrent(hdcDst
, hglrc
);
766 glClearColor((float)0x44/0xff, (float)0x55/0xff, (float)0x66/0xff, (float)0x11/0xff);
767 glClear(GL_COLOR_BUFFER_BIT
);
769 glGetIntegerv( GL_VIEWPORT
, viewport
);
770 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 4 && viewport
[3] == 4,
771 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
773 wglMakeCurrent(hdcDst
, hglrc2
);
774 glGetIntegerv( GL_VIEWPORT
, viewport
);
775 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 12 && viewport
[3] == 12,
776 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
778 wglMakeCurrent(hdcDst
, hglrc
);
779 glGetIntegerv( GL_VIEWPORT
, viewport
);
780 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 4 && viewport
[3] == 4,
781 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
783 SelectObject(hdcDst
, bmpDst
);
784 ret
= GetPixelFormat( hdcDst
);
785 ok( ret
== iPixelFormat
, "GetPixelFormat returned %d/%d\n", ret
, iPixelFormat
);
786 ret
= SetPixelFormat(hdcDst
, iPixelFormat
+ 1, &pfd
);
787 ok( !ret
, "SetPixelFormat succeeded\n" );
788 wglMakeCurrent(hdcDst
, hglrc2
);
789 glGetIntegerv( GL_VIEWPORT
, viewport
);
790 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 12 && viewport
[3] == 12,
791 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
793 wglDeleteContext(hglrc2
);
794 wglDeleteContext(hglrc
);
798 SelectObject(hdcDst
, oldDst
);
800 DeleteObject(bmpDst
);
805 struct wgl_thread_param
807 HANDLE test_finished
;
811 BOOL make_current_error
;
816 static DWORD WINAPI
wgl_thread(void *param
)
818 struct wgl_thread_param
*p
= param
;
819 HDC hdc
= GetDC( p
->hwnd
);
821 ok(!glGetString(GL_RENDERER
) && !glGetString(GL_VERSION
) && !glGetString(GL_VENDOR
),
822 "Expected NULL string when no active context is set\n");
824 SetLastError(0xdeadbeef);
825 p
->make_current
= wglMakeCurrent(hdc
, p
->hglrc
);
826 p
->make_current_error
= GetLastError();
827 p
->deleted
= wglDeleteContext(p
->hglrc
);
828 p
->deleted_error
= GetLastError();
829 ReleaseDC( p
->hwnd
, hdc
);
830 SetEvent(p
->test_finished
);
834 static void test_deletecontext(HWND hwnd
, HDC hdc
)
836 struct wgl_thread_param thread_params
;
837 HGLRC hglrc
= wglCreateContext(hdc
);
838 HANDLE thread_handle
;
842 SetLastError(0xdeadbeef);
843 res
= wglDeleteContext(NULL
);
844 ok(res
== FALSE
, "wglDeleteContext succeeded\n");
845 ok(GetLastError() == ERROR_INVALID_HANDLE
, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
849 skip("wglCreateContext failed!\n");
853 res
= wglMakeCurrent(hdc
, hglrc
);
856 skip("wglMakeCurrent failed!\n");
860 /* WGL doesn't allow you to delete a context from a different thread than the one in which it is current.
861 * This differs from GLX which does allow it but it delays actual deletion until the context becomes not current.
863 thread_params
.hglrc
= hglrc
;
864 thread_params
.hwnd
= hwnd
;
865 thread_params
.test_finished
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
866 thread_handle
= CreateThread(NULL
, 0, wgl_thread
, &thread_params
, 0, &tid
);
867 ok(!!thread_handle
, "Failed to create thread, last error %#x.\n", GetLastError());
870 WaitForSingleObject(thread_handle
, INFINITE
);
871 ok(!thread_params
.make_current
, "Attempt to make WGL context from another thread passed\n");
872 ok(thread_params
.make_current_error
== ERROR_BUSY
, "Expected last error to be ERROR_BUSY, got %u\n", thread_params
.make_current_error
);
873 ok(!thread_params
.deleted
, "Attempt to delete WGL context from another thread passed\n");
874 ok(thread_params
.deleted_error
== ERROR_BUSY
, "Expected last error to be ERROR_BUSY, got %u\n", thread_params
.deleted_error
);
876 CloseHandle(thread_params
.test_finished
);
878 res
= wglDeleteContext(hglrc
);
879 ok(res
== TRUE
, "wglDeleteContext failed\n");
881 /* Attempting to delete the same context twice should fail. */
882 SetLastError(0xdeadbeef);
883 res
= wglDeleteContext(hglrc
);
884 ok(res
== FALSE
, "wglDeleteContext succeeded\n");
885 ok(GetLastError() == ERROR_INVALID_HANDLE
, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
887 /* WGL makes a context not current when deleting it. This differs from GLX behavior where
888 * deletion takes place when the thread becomes not current. */
889 hglrc
= wglGetCurrentContext();
890 ok(hglrc
== NULL
, "A WGL context is active while none was expected\n");
894 static void test_getprocaddress(HDC hdc
)
896 const char *extensions
= (const char*)glGetString(GL_EXTENSIONS
);
898 HGLRC ctx
= wglGetCurrentContext();
902 skip("skipping wglGetProcAddress tests because no GL extensions supported\n");
906 /* Core GL 1.0/1.1 functions should not be loadable through wglGetProcAddress.
907 * Try to load the function with and without a context.
909 func
= wglGetProcAddress("glEnable");
910 ok(func
== NULL
, "Lookup of function glEnable with a context passed, expected a failure\n");
911 wglMakeCurrent(hdc
, NULL
);
912 func
= wglGetProcAddress("glEnable");
913 ok(func
== NULL
, "Lookup of function glEnable without a context passed, expected a failure\n");
914 wglMakeCurrent(hdc
, ctx
);
916 /* The goal of the test will be to test behavior of wglGetProcAddress when
917 * no WGL context is active. Before the test we pick an extension (GL_ARB_multitexture)
918 * which any GL >=1.2.1 implementation supports. Unfortunately the GDI renderer doesn't
919 * support it. There aren't any extensions we can use for this test which are supported by
920 * both GDI and real drivers.
921 * Note GDI only has GL_EXT_bgra, GL_EXT_paletted_texture and GL_WIN_swap_hint.
923 if (!gl_extension_supported(extensions
, "GL_ARB_multitexture"))
925 skip("skipping test because lack of GL_ARB_multitexture support\n");
929 func
= wglGetProcAddress("glActiveTextureARB");
930 ok(func
!= NULL
, "Unable to lookup glActiveTextureARB, last error %#x\n", GetLastError());
932 /* Temporarily disable the context, so we can see that we can't retrieve functions now. */
933 wglMakeCurrent(hdc
, NULL
);
934 func
= wglGetProcAddress("glActiveTextureARB");
935 ok(func
== NULL
, "Function lookup without a context passed, expected a failure; last error %#x\n", GetLastError());
936 wglMakeCurrent(hdc
, ctx
);
939 static void test_make_current_read(HDC hdc
)
943 HGLRC hglrc
= wglCreateContext(hdc
);
947 skip("wglCreateContext failed!\n");
951 res
= wglMakeCurrent(hdc
, hglrc
);
954 skip("wglMakeCurrent failed!\n");
958 /* Test what wglGetCurrentReadDCARB does for wglMakeCurrent as the spec doesn't mention it */
959 hread
= pwglGetCurrentReadDCARB();
960 trace("hread %p, hdc %p\n", hread
, hdc
);
961 ok(hread
== hdc
, "wglGetCurrentReadDCARB failed for standard wglMakeCurrent\n");
963 pwglMakeContextCurrentARB(hdc
, hdc
, hglrc
);
964 hread
= pwglGetCurrentReadDCARB();
965 ok(hread
== hdc
, "wglGetCurrentReadDCARB failed for wglMakeContextCurrent\n");
968 static void test_dc(HWND hwnd
, HDC hdc
)
973 /* Get another DC and make sure it has the same pixel format */
977 pf1
= GetPixelFormat(hdc
);
978 pf2
= GetPixelFormat(hdc2
);
979 ok(pf1
== pf2
, "Second DC does not have the same format (%d != %d)\n", pf1
, pf2
);
982 skip("Could not get a different DC for the window\n");
986 ReleaseDC(hwnd
, hdc2
);
991 /* Nvidia converts win32 error codes to (0xc007 << 16) | win32_error_code */
992 #define NVIDIA_HRESULT_FROM_WIN32(x) (HRESULT_FROM_WIN32(x) | 0x40000000)
993 static void test_opengl3(HDC hdc
)
995 /* Try to create a context compatible with OpenGL 1.x; 1.0-2.1 is allowed */
998 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 1, 0};
1000 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
1001 ok(gl3Ctx
!= 0, "pwglCreateContextAttribsARB for a 1.x context failed!\n");
1002 wglDeleteContext(gl3Ctx
);
1005 /* Try to pass an invalid HDC */
1009 SetLastError(0xdeadbeef);
1010 gl3Ctx
= pwglCreateContextAttribsARB((HDC
)0xdeadbeef, 0, 0);
1011 ok(gl3Ctx
== 0, "pwglCreateContextAttribsARB using an invalid HDC passed\n");
1012 error
= GetLastError();
1013 ok(error
== ERROR_DC_NOT_FOUND
|| error
== ERROR_INVALID_HANDLE
||
1014 broken(error
== ERROR_DS_GENERIC_ERROR
) ||
1015 broken(error
== NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_DATA
)), /* Nvidia Vista + Win7 */
1016 "Expected ERROR_DC_NOT_FOUND, got error=%x\n", error
);
1017 wglDeleteContext(gl3Ctx
);
1020 /* Try to pass an invalid shareList */
1024 SetLastError(0xdeadbeef);
1025 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, (HGLRC
)0xdeadbeef, 0);
1026 ok(gl3Ctx
== 0, "pwglCreateContextAttribsARB using an invalid shareList passed\n");
1027 error
= GetLastError();
1028 /* The Nvidia implementation seems to return hresults instead of win32 error codes */
1029 ok(error
== ERROR_INVALID_OPERATION
|| error
== ERROR_INVALID_DATA
||
1030 error
== NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_OPERATION
), "Expected ERROR_INVALID_OPERATION, got error=%x\n", error
);
1031 wglDeleteContext(gl3Ctx
);
1034 /* Try to create an OpenGL 3.0 context */
1036 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
1037 HGLRC gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
1041 skip("Skipping the rest of the WGL_ARB_create_context test due to lack of OpenGL 3.0\n");
1045 wglDeleteContext(gl3Ctx
);
1048 /* 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 */
1050 HGLRC glCtx
= wglCreateContext(hdc
);
1052 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
1053 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};
1055 HGLRC gl3Ctx
= pwglCreateContextAttribsARB(hdc
, glCtx
, attribs
);
1056 ok(gl3Ctx
!= NULL
, "Sharing of a display list between OpenGL 3.0 and OpenGL 1.x/2.x failed!\n");
1058 wglDeleteContext(gl3Ctx
);
1060 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, glCtx
, attribs_future
);
1061 ok(gl3Ctx
!= NULL
, "Sharing of a display list between a forward compatible OpenGL 3.0 context and OpenGL 1.x/2.x failed!\n");
1063 wglDeleteContext(gl3Ctx
);
1066 wglDeleteContext(glCtx
);
1069 /* Try to create an OpenGL 3.0 context and test windowless rendering */
1072 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
1075 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
1076 ok(gl3Ctx
!= 0, "pwglCreateContextAttribsARB for a 3.0 context failed!\n");
1078 /* OpenGL 3.0 allows offscreen rendering WITHOUT a drawable
1079 * Neither AMD or Nvidia support it at this point. The WGL_ARB_create_context specs also say that
1080 * it is hard because drivers use the HDC to enter the display driver and it sounds like they don't
1081 * expect drivers to ever offer it.
1083 res
= wglMakeCurrent(0, gl3Ctx
);
1084 ok(res
== FALSE
, "Wow, OpenGL 3.0 windowless rendering passed while it was expected not to!\n");
1086 wglMakeCurrent(0, 0);
1089 wglDeleteContext(gl3Ctx
);
1093 static void test_minimized(void)
1095 PIXELFORMATDESCRIPTOR pf_desc
=
1097 sizeof(PIXELFORMATDESCRIPTOR
),
1099 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1101 24, /* 24-bit color depth */
1102 0, 0, 0, 0, 0, 0, /* color bits */
1103 0, /* alpha buffer */
1105 0, /* accumulation buffer */
1106 0, 0, 0, 0, /* accum bits */
1108 0, /* stencil buffer */
1109 0, /* auxiliary buffer */
1110 PFD_MAIN_PLANE
, /* main layer */
1112 0, 0, 0 /* layer masks */
1121 window
= CreateWindowA("static", "opengl32_test",
1122 WS_POPUP
| WS_MINIMIZE
, 0, 0, 640, 480, 0, 0, 0, 0);
1123 ok(!!window
, "Failed to create window, last error %#x.\n", GetLastError());
1126 ok(!!dc
, "Failed to get DC.\n");
1128 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1131 win_skip("Failed to find pixel format.\n");
1132 ReleaseDC(window
, dc
);
1133 DestroyWindow(window
);
1137 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1138 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1140 style
= GetWindowLongA(window
, GWL_STYLE
);
1141 ok(style
& WS_MINIMIZE
, "Window should be minimized, got style %#x.\n", style
);
1143 ctx
= wglCreateContext(dc
);
1144 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1146 ret
= wglMakeCurrent(dc
, ctx
);
1147 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1149 style
= GetWindowLongA(window
, GWL_STYLE
);
1150 ok(style
& WS_MINIMIZE
, "window should be minimized, got style %#x.\n", style
);
1152 ret
= wglMakeCurrent(NULL
, NULL
);
1153 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1155 ret
= wglDeleteContext(ctx
);
1156 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1158 ReleaseDC(window
, dc
);
1159 DestroyWindow(window
);
1162 static void test_window_dc(void)
1164 PIXELFORMATDESCRIPTOR pf_desc
=
1166 sizeof(PIXELFORMATDESCRIPTOR
),
1168 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1170 24, /* 24-bit color depth */
1171 0, 0, 0, 0, 0, 0, /* color bits */
1172 0, /* alpha buffer */
1174 0, /* accumulation buffer */
1175 0, 0, 0, 0, /* accum bits */
1177 0, /* stencil buffer */
1178 0, /* auxiliary buffer */
1179 PFD_MAIN_PLANE
, /* main layer */
1181 0, 0, 0 /* layer masks */
1190 window
= CreateWindowA("static", "opengl32_test",
1191 WS_OVERLAPPEDWINDOW
, 0, 0, 640, 480, 0, 0, 0, 0);
1192 ok(!!window
, "Failed to create window, last error %#x.\n", GetLastError());
1194 ShowWindow(window
, SW_SHOW
);
1196 dc
= GetWindowDC(window
);
1197 ok(!!dc
, "Failed to get DC.\n");
1199 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1202 win_skip("Failed to find pixel format.\n");
1203 ReleaseDC(window
, dc
);
1204 DestroyWindow(window
);
1208 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1209 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1211 ctx
= wglCreateContext(dc
);
1212 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1214 ret
= wglMakeCurrent(dc
, ctx
);
1215 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1217 GetClientRect(window
, &r
);
1218 glGetIntegerv(GL_VIEWPORT
, (GLint
*)&vp
);
1219 ok(EqualRect(&r
, &vp
), "Viewport not equal to client rect.\n");
1221 ret
= wglMakeCurrent(NULL
, NULL
);
1222 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1224 ret
= wglDeleteContext(ctx
);
1225 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1227 ReleaseDC(window
, dc
);
1228 DestroyWindow(window
);
1231 static void test_message_window(void)
1233 PIXELFORMATDESCRIPTOR pf_desc
=
1235 sizeof(PIXELFORMATDESCRIPTOR
),
1237 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1239 24, /* 24-bit color depth */
1240 0, 0, 0, 0, 0, 0, /* color bits */
1241 0, /* alpha buffer */
1243 0, /* accumulation buffer */
1244 0, 0, 0, 0, /* accum bits */
1246 0, /* stencil buffer */
1247 0, /* auxiliary buffer */
1248 PFD_MAIN_PLANE
, /* main layer */
1250 0, 0, 0 /* layer masks */
1260 window
= CreateWindowA("static", "opengl32_test",
1261 WS_OVERLAPPEDWINDOW
, 0, 0, 100, 100, HWND_MESSAGE
, 0, 0, 0);
1264 win_skip( "HWND_MESSAGE not supported\n" );
1268 ok(!!dc
, "Failed to get DC.\n");
1270 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1273 win_skip("Failed to find pixel format.\n");
1274 ReleaseDC(window
, dc
);
1275 DestroyWindow(window
);
1279 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1280 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1282 ctx
= wglCreateContext(dc
);
1283 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1285 ret
= wglMakeCurrent(dc
, ctx
);
1286 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1288 GetClientRect(window
, &r
);
1289 glGetIntegerv(GL_VIEWPORT
, (GLint
*)&vp
);
1290 ok(EqualRect(&r
, &vp
), "Viewport not equal to client rect.\n");
1292 glClear(GL_COLOR_BUFFER_BIT
);
1294 glerr
= glGetError();
1295 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1296 ret
= SwapBuffers(dc
);
1297 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1299 ret
= wglMakeCurrent(NULL
, NULL
);
1300 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1302 ret
= wglDeleteContext(ctx
);
1303 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1305 ReleaseDC(window
, dc
);
1306 DestroyWindow(window
);
1309 static void test_destroy(HDC oldhdc
)
1311 PIXELFORMATDESCRIPTOR pf_desc
=
1313 sizeof(PIXELFORMATDESCRIPTOR
),
1315 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1317 24, /* 24-bit color depth */
1318 0, 0, 0, 0, 0, 0, /* color bits */
1319 0, /* alpha buffer */
1321 0, /* accumulation buffer */
1322 0, 0, 0, 0, /* accum bits */
1324 0, /* stencil buffer */
1325 0, /* auxiliary buffer */
1326 PFD_MAIN_PLANE
, /* main layer */
1328 0, 0, 0 /* layer masks */
1337 HGLRC oldctx
= wglGetCurrentContext();
1339 ok(!!oldctx
, "Expected to find a valid current context.\n");
1341 window
= CreateWindowA("static", "opengl32_test",
1342 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1343 ok(!!window
, "Failed to create window, last error %#x.\n", GetLastError());
1346 ok(!!dc
, "Failed to get DC.\n");
1348 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1351 win_skip("Failed to find pixel format.\n");
1352 ReleaseDC(window
, dc
);
1353 DestroyWindow(window
);
1357 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1358 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1360 ctx
= wglCreateContext(dc
);
1361 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1363 ret
= wglMakeCurrent(dc
, ctx
);
1364 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1366 glClear(GL_COLOR_BUFFER_BIT
);
1368 glerr
= glGetError();
1369 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1370 ret
= SwapBuffers(dc
);
1371 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1373 ret
= DestroyWindow(window
);
1374 ok(ret
, "Failed to destroy window, last error %#x.\n", GetLastError());
1376 ok(wglGetCurrentContext() == ctx
, "Wrong current context.\n");
1378 SetLastError(0xdeadbeef);
1379 ret
= wglMakeCurrent(dc
, ctx
);
1380 err
= GetLastError();
1381 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1382 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1383 SetLastError(0xdeadbeef);
1384 ret
= SwapBuffers(dc
);
1385 err
= GetLastError();
1386 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1388 ok(wglGetCurrentContext() == ctx
, "Wrong current context.\n");
1390 glClear(GL_COLOR_BUFFER_BIT
);
1392 glerr
= glGetError();
1393 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1394 SetLastError(0xdeadbeef);
1395 ret
= SwapBuffers(dc
);
1396 err
= GetLastError();
1397 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1399 ret
= wglMakeCurrent(NULL
, NULL
);
1400 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1402 glClear(GL_COLOR_BUFFER_BIT
);
1404 glerr
= glGetError();
1405 ok(glerr
== GL_INVALID_OPERATION
, "Failed glClear, error %#x.\n", glerr
);
1406 SetLastError(0xdeadbeef);
1407 ret
= SwapBuffers(dc
);
1408 err
= GetLastError();
1409 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1411 SetLastError(0xdeadbeef);
1412 ret
= wglMakeCurrent(dc
, ctx
);
1413 err
= GetLastError();
1414 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1415 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1417 ok(wglGetCurrentContext() == NULL
, "Wrong current context.\n");
1419 ret
= wglMakeCurrent(oldhdc
, oldctx
);
1420 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1421 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1423 SetLastError(0xdeadbeef);
1424 ret
= wglMakeCurrent(dc
, ctx
);
1425 err
= GetLastError();
1426 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1427 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1429 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1431 ret
= wglDeleteContext(ctx
);
1432 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1434 ReleaseDC(window
, dc
);
1436 ret
= wglMakeCurrent(oldhdc
, oldctx
);
1437 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1440 static void test_destroy_read(HDC oldhdc
)
1442 PIXELFORMATDESCRIPTOR pf_desc
=
1444 sizeof(PIXELFORMATDESCRIPTOR
),
1446 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1448 24, /* 24-bit color depth */
1449 0, 0, 0, 0, 0, 0, /* color bits */
1450 0, /* alpha buffer */
1452 0, /* accumulation buffer */
1453 0, 0, 0, 0, /* accum bits */
1455 0, /* stencil buffer */
1456 0, /* auxiliary buffer */
1457 PFD_MAIN_PLANE
, /* main layer */
1459 0, 0, 0 /* layer masks */
1462 HWND draw_window
, read_window
;
1465 HDC read_dc
, draw_dc
;
1468 HGLRC oldctx
= wglGetCurrentContext();
1470 ok(!!oldctx
, "Expected to find a valid current context\n");
1472 draw_window
= CreateWindowA("static", "opengl32_test",
1473 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1474 ok(!!draw_window
, "Failed to create window, last error %#x.\n", GetLastError());
1476 draw_dc
= GetDC(draw_window
);
1477 ok(!!draw_dc
, "Failed to get DC.\n");
1479 pixel_format
= ChoosePixelFormat(draw_dc
, &pf_desc
);
1482 win_skip("Failed to find pixel format.\n");
1483 ReleaseDC(draw_window
, draw_dc
);
1484 DestroyWindow(draw_window
);
1488 ret
= SetPixelFormat(draw_dc
, pixel_format
, &pf_desc
);
1489 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1491 read_window
= CreateWindowA("static", "opengl32_test",
1492 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1493 ok(!!read_window
, "Failed to create window, last error %#x.\n", GetLastError());
1495 read_dc
= GetDC(read_window
);
1496 ok(!!draw_dc
, "Failed to get DC.\n");
1498 pixel_format
= ChoosePixelFormat(read_dc
, &pf_desc
);
1501 win_skip("Failed to find pixel format.\n");
1502 ReleaseDC(read_window
, read_dc
);
1503 DestroyWindow(read_window
);
1504 ReleaseDC(draw_window
, draw_dc
);
1505 DestroyWindow(draw_window
);
1509 ret
= SetPixelFormat(read_dc
, pixel_format
, &pf_desc
);
1510 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1512 ctx
= wglCreateContext(draw_dc
);
1513 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1515 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1516 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1518 glCopyPixels(0, 0, 640, 480, GL_COLOR
);
1520 glerr
= glGetError();
1521 ok(glerr
== GL_NO_ERROR
, "Failed glCopyPixel, error %#x.\n", glerr
);
1522 ret
= SwapBuffers(draw_dc
);
1523 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1525 ret
= DestroyWindow(read_window
);
1526 ok(ret
, "Failed to destroy window, last error %#x.\n", GetLastError());
1528 ok(wglGetCurrentContext() == ctx
, "Wrong current context.\n");
1530 if (0) /* Crashes on AMD on Windows */
1532 glCopyPixels(0, 0, 640, 480, GL_COLOR
);
1534 glerr
= glGetError();
1535 ok(glerr
== GL_NO_ERROR
, "Failed glCopyPixel, error %#x.\n", glerr
);
1538 glClear(GL_COLOR_BUFFER_BIT
);
1540 glerr
= glGetError();
1541 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1542 ret
= SwapBuffers(draw_dc
);
1543 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1545 ret
= wglMakeCurrent(NULL
, NULL
);
1546 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1548 if (0) /* This crashes with Nvidia drivers on Windows. */
1550 SetLastError(0xdeadbeef);
1551 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1552 err
= GetLastError();
1553 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1554 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1557 ret
= DestroyWindow(draw_window
);
1558 ok(ret
, "Failed to destroy window, last error %#x.\n", GetLastError());
1560 glClear(GL_COLOR_BUFFER_BIT
);
1562 glerr
= glGetError();
1563 ok(glerr
== GL_INVALID_OPERATION
, "Failed glClear, error %#x.\n", glerr
);
1564 SetLastError(0xdeadbeef);
1565 ret
= SwapBuffers(draw_dc
);
1566 err
= GetLastError();
1567 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1569 SetLastError(0xdeadbeef);
1570 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1571 err
= GetLastError();
1572 ok(!ret
&& (err
== ERROR_INVALID_HANDLE
|| err
== 0xc0070006),
1573 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1575 ok(wglGetCurrentContext() == NULL
, "Wrong current context.\n");
1577 wglMakeCurrent(NULL
, NULL
);
1579 wglMakeCurrent(oldhdc
, oldctx
);
1580 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1582 SetLastError(0xdeadbeef);
1583 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1584 err
= GetLastError();
1585 ok(!ret
&& (err
== ERROR_INVALID_HANDLE
|| err
== 0xc0070006),
1586 "Unexpected behavior when making context current, last error %#x.\n", err
);
1588 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1590 ret
= wglDeleteContext(ctx
);
1591 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1593 ReleaseDC(read_window
, read_dc
);
1594 ReleaseDC(draw_window
, draw_dc
);
1596 wglMakeCurrent(oldhdc
, oldctx
);
1599 static void test_swap_control(HDC oldhdc
)
1601 PIXELFORMATDESCRIPTOR pf_desc
=
1603 sizeof(PIXELFORMATDESCRIPTOR
),
1605 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1607 24, /* 24-bit color depth */
1608 0, 0, 0, 0, 0, 0, /* color bits */
1609 0, /* alpha buffer */
1611 0, /* accumulation buffer */
1612 0, 0, 0, 0, /* accum bits */
1614 0, /* stencil buffer */
1615 0, /* auxiliary buffer */
1616 PFD_MAIN_PLANE
, /* main layer */
1618 0, 0, 0 /* layer masks */
1621 HWND window1
, window2
, old_parent
;
1622 HGLRC ctx1
, ctx2
, oldctx
;
1627 oldctx
= wglGetCurrentContext();
1628 ok(!!oldctx
, "Expected to find a valid current context.\n");
1630 window1
= CreateWindowA("static", "opengl32_test",
1631 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1632 ok(!!window1
, "Failed to create window1, last error %#x.\n", GetLastError());
1634 dc1
= GetDC(window1
);
1635 ok(!!dc1
, "Failed to get DC.\n");
1637 pixel_format
= ChoosePixelFormat(dc1
, &pf_desc
);
1640 win_skip("Failed to find pixel format.\n");
1641 ReleaseDC(window1
, dc1
);
1642 DestroyWindow(window1
);
1646 ret
= SetPixelFormat(dc1
, pixel_format
, &pf_desc
);
1647 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1649 ctx1
= wglCreateContext(dc1
);
1650 ok(!!ctx1
, "Failed to create GL context, last error %#x.\n", GetLastError());
1652 ret
= wglMakeCurrent(dc1
, ctx1
);
1653 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1655 interval
= pwglGetSwapIntervalEXT();
1656 ok(interval
== 1, "Expected default swap interval 1, got %d\n", interval
);
1658 ret
= pwglSwapIntervalEXT(0);
1659 ok(ret
, "Failed to set swap interval to 0, last error %#x.\n", GetLastError());
1661 interval
= pwglGetSwapIntervalEXT();
1662 ok(interval
== 0, "Expected swap interval 0, got %d\n", interval
);
1664 /* Check what interval we get on a second context on the same drawable.*/
1665 ctx2
= wglCreateContext(dc1
);
1666 ok(!!ctx2
, "Failed to create GL context, last error %#x.\n", GetLastError());
1668 ret
= wglMakeCurrent(dc1
, ctx2
);
1669 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1671 interval
= pwglGetSwapIntervalEXT();
1672 ok(interval
== 0, "Expected swap interval 0, got %d\n", interval
);
1674 /* A second window is created to see whether its swap interval was affected
1675 * by previous calls.
1677 window2
= CreateWindowA("static", "opengl32_test",
1678 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1679 ok(!!window2
, "Failed to create window2, last error %#x.\n", GetLastError());
1681 dc2
= GetDC(window2
);
1682 ok(!!dc2
, "Failed to get DC.\n");
1684 ret
= SetPixelFormat(dc2
, pixel_format
, &pf_desc
);
1685 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1687 ret
= wglMakeCurrent(dc2
, ctx1
);
1688 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1690 /* Since the second window lacks the swap interval, this proves that the interval
1691 * is not global or shared among contexts.
1693 interval
= pwglGetSwapIntervalEXT();
1694 ok(interval
== 1, "Expected default swap interval 1, got %d\n", interval
);
1696 /* Test if setting the parent of a window resets the swap interval. */
1697 ret
= wglMakeCurrent(dc1
, ctx1
);
1698 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1700 old_parent
= SetParent(window1
, window2
);
1701 ok(!!old_parent
, "Failed to make window1 a child of window2, last error %#x.\n", GetLastError());
1703 interval
= pwglGetSwapIntervalEXT();
1704 ok(interval
== 0, "Expected swap interval 0, got %d\n", interval
);
1706 ret
= wglDeleteContext(ctx1
);
1707 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1708 ret
= wglDeleteContext(ctx2
);
1709 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1711 ReleaseDC(window1
, dc1
);
1712 DestroyWindow(window1
);
1713 ReleaseDC(window2
, dc2
);
1714 DestroyWindow(window2
);
1716 wglMakeCurrent(oldhdc
, oldctx
);
1722 PIXELFORMATDESCRIPTOR pfd
= {
1723 sizeof(PIXELFORMATDESCRIPTOR
),
1725 PFD_DRAW_TO_WINDOW
|
1726 PFD_SUPPORT_OPENGL
|
1729 24, /* 24-bit color depth */
1730 0, 0, 0, 0, 0, 0, /* color bits */
1731 0, /* alpha buffer */
1733 0, /* accumulation buffer */
1734 0, 0, 0, 0, /* accum bits */
1736 0, /* stencil buffer */
1737 0, /* auxiliary buffer */
1738 PFD_MAIN_PLANE
, /* main layer */
1740 0, 0, 0 /* layer masks */
1743 hwnd
= CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW
, 10, 10, 200, 200, NULL
, NULL
,
1745 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
1749 int iPixelFormat
, res
;
1752 ShowWindow(hwnd
, SW_SHOW
);
1756 iPixelFormat
= ChoosePixelFormat(hdc
, &pfd
);
1757 if(iPixelFormat
== 0)
1759 /* This should never happen as ChoosePixelFormat always returns a closest match, but currently this fails in Wine if we don't have glX */
1760 win_skip("Unable to find pixel format.\n");
1764 /* We shouldn't be able to create a context from a hdc which doesn't have a pixel format set */
1765 hglrc
= wglCreateContext(hdc
);
1766 ok(hglrc
== NULL
, "wglCreateContext should fail when no pixel format has been set, but it passed\n");
1767 error
= GetLastError();
1768 ok(error
== ERROR_INVALID_PIXEL_FORMAT
, "expected ERROR_INVALID_PIXEL_FORMAT for wglCreateContext without a pixelformat set, but received %#x\n", error
);
1770 res
= SetPixelFormat(hdc
, iPixelFormat
, &pfd
);
1771 ok(res
, "SetPixelformat failed: %x\n", GetLastError());
1773 test_bitmap_rendering( TRUE
);
1774 test_bitmap_rendering( FALSE
);
1777 test_message_window();
1780 ok(!glGetString(GL_RENDERER
) && !glGetString(GL_VERSION
) && !glGetString(GL_VENDOR
),
1781 "Expected NULL string when no active context is set\n");
1782 hglrc
= wglCreateContext(hdc
);
1783 res
= wglMakeCurrent(hdc
, hglrc
);
1784 ok(res
, "wglMakeCurrent failed!\n");
1787 trace("OpenGL renderer: %s\n", glGetString(GL_RENDERER
));
1788 trace("OpenGL driver version: %s\n", glGetString(GL_VERSION
));
1789 trace("OpenGL vendor: %s\n", glGetString(GL_VENDOR
));
1793 skip("Skipping OpenGL tests without a current context\n");
1797 /* Initialisation of WGL functions depends on an implicit WGL context. For this reason we can't load them before making
1798 * any WGL call :( On Wine this would work but not on real Windows because there can be different implementations (software, ICD, MCD).
1801 test_getprocaddress(hdc
);
1802 test_deletecontext(hwnd
, hdc
);
1803 test_makecurrent(hdc
);
1805 /* The lack of wglGetExtensionsStringARB in general means broken software rendering or the lack of decent OpenGL support, skip tests in such cases */
1806 if (!pwglGetExtensionsStringARB
)
1808 win_skip("wglGetExtensionsStringARB is not available\n");
1812 test_choosepixelformat();
1813 test_setpixelformat(hdc
);
1815 test_sharelists(hdc
);
1816 test_colorbits(hdc
);
1818 test_acceleration(hdc
);
1820 wgl_extensions
= pwglGetExtensionsStringARB(hdc
);
1821 if(wgl_extensions
== NULL
) skip("Skipping opengl32 tests because this OpenGL implementation doesn't support WGL extensions!\n");
1823 if(strstr(wgl_extensions
, "WGL_ARB_create_context"))
1826 if(strstr(wgl_extensions
, "WGL_ARB_make_current_read"))
1828 test_make_current_read(hdc
);
1829 test_destroy_read(hdc
);
1832 skip("WGL_ARB_make_current_read not supported, skipping test\n");
1834 if(strstr(wgl_extensions
, "WGL_ARB_pbuffer"))
1837 skip("WGL_ARB_pbuffer not supported, skipping pbuffer test\n");
1839 if(strstr(wgl_extensions
, "WGL_EXT_swap_control"))
1840 test_swap_control(hdc
);
1842 skip("WGL_EXT_swap_control not supported, skipping test\n");
1845 ReleaseDC(hwnd
, hdc
);
1846 DestroyWindow(hwnd
);