Partial merge of condrv_restructure branch r65657.
[reactos.git] / rostests / winetests / opengl32 / opengl.c
1 /*
2 * Some tests for OpenGL functions
3 *
4 * Copyright (C) 2007-2008 Roderick Colenbrander
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include <windows.h>
22 #include <wingdi.h>
23 #include "wine/test.h"
24
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;
29 typedef int GLint;
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
41
42 #define GL_VIEWPORT 0x0ba2
43 void WINAPI glGetIntegerv(GLenum pname, GLint *params);
44
45 #define MAX_FORMATS 256
46 typedef void* HPBUFFERARB;
47
48 /* WGL_ARB_create_context */
49 static HGLRC (WINAPI *pwglCreateContextAttribsARB)(HDC hDC, HGLRC hShareContext, const int *attribList);
50 /* GetLastError */
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
59
60 /* WGL_ARB_extensions_string */
61 static const char* (WINAPI *pwglGetExtensionsStringARB)(HDC);
62 static int (WINAPI *pwglReleasePbufferDCARB)(HPBUFFERARB, HDC);
63
64 /* WGL_ARB_make_current_read */
65 static BOOL (WINAPI *pwglMakeContextCurrentARB)(HDC hdraw, HDC hread, HGLRC hglrc);
66 static HDC (WINAPI *pwglGetCurrentReadDCARB)(void);
67
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
80
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 *);
83
84 /* WGL_ARB_pbuffer */
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);
88
89 /* WGL_EXT_swap_control */
90 static BOOL (WINAPI *pwglSwapIntervalEXT)(int interval);
91 static int (WINAPI *pwglGetSwapIntervalEXT)(void);
92
93 static const char* wgl_extensions = NULL;
94
95 static void init_functions(void)
96 {
97 #define GET_PROC(func) \
98 p ## func = (void*)wglGetProcAddress(#func); \
99 if(!p ## func) \
100 trace("wglGetProcAddress(%s) failed\n", #func);
101
102 /* WGL_ARB_create_context */
103 GET_PROC(wglCreateContextAttribsARB);
104
105 /* WGL_ARB_extensions_string */
106 GET_PROC(wglGetExtensionsStringARB)
107
108 /* WGL_ARB_make_current_read */
109 GET_PROC(wglMakeContextCurrentARB);
110 GET_PROC(wglGetCurrentReadDCARB);
111
112 /* WGL_ARB_pixel_format */
113 GET_PROC(wglChoosePixelFormatARB)
114 GET_PROC(wglGetPixelFormatAttribivARB)
115
116 /* WGL_ARB_pbuffer */
117 GET_PROC(wglCreatePbufferARB)
118 GET_PROC(wglGetPbufferDCARB)
119 GET_PROC(wglReleasePbufferDCARB)
120
121 /* WGL_EXT_swap_control */
122 GET_PROC(wglSwapIntervalEXT)
123 GET_PROC(wglGetSwapIntervalEXT)
124
125 #undef GET_PROC
126 }
127
128 static BOOL gl_extension_supported(const char *extensions, const char *extension_string)
129 {
130 size_t ext_str_len = strlen(extension_string);
131
132 while (*extensions)
133 {
134 const char *start;
135 size_t len;
136
137 while (isspace(*extensions))
138 ++extensions;
139 start = extensions;
140 while (!isspace(*extensions) && *extensions)
141 ++extensions;
142
143 len = extensions - start;
144 if (!len)
145 continue;
146
147 if (len == ext_str_len && !memcmp(start, extension_string, ext_str_len))
148 {
149 return TRUE;
150 }
151 }
152 return FALSE;
153 }
154
155 static void test_pbuffers(HDC hdc)
156 {
157 const int iAttribList[] = { WGL_DRAW_TO_PBUFFER_ARB, 1, /* Request pbuffer support */
158 0 };
159 int iFormats[MAX_FORMATS];
160 unsigned int nOnscreenFormats;
161 unsigned int nFormats;
162 int i, res;
163 int iPixelFormat = 0;
164
165 nOnscreenFormats = DescribePixelFormat(hdc, 0, 0, NULL);
166
167 /* When you want to render to a pbuffer you need to call wglGetPbufferDCARB which
168 * returns a 'magic' HDC which you can then pass to wglMakeCurrent to switch rendering
169 * to the pbuffer. Below some tests are performed on what happens if you use standard WGL calls
170 * on this 'magic' HDC for both a pixelformat that support onscreen and offscreen rendering
171 * and a pixelformat that's only available for offscreen rendering (this means that only
172 * wglChoosePixelFormatARB and friends know about the format.
173 *
174 * The first thing we need are pixelformats with pbuffer capabilities.
175 */
176 res = pwglChoosePixelFormatARB(hdc, iAttribList, NULL, MAX_FORMATS, iFormats, &nFormats);
177 if(res <= 0)
178 {
179 skip("No pbuffer compatible formats found while WGL_ARB_pbuffer is supported\n");
180 return;
181 }
182 trace("nOnscreenFormats: %d\n", nOnscreenFormats);
183 trace("Total number of pbuffer capable pixelformats: %d\n", nFormats);
184
185 /* Try to select an onscreen pixelformat out of the list */
186 for(i=0; i < nFormats; i++)
187 {
188 /* Check if the format is onscreen, if it is choose it */
189 if(iFormats[i] <= nOnscreenFormats)
190 {
191 iPixelFormat = iFormats[i];
192 trace("Selected iPixelFormat=%d\n", iPixelFormat);
193 break;
194 }
195 }
196
197 /* A video driver supports a large number of onscreen and offscreen pixelformats.
198 * The traditional WGL calls only see a subset of the whole pixelformat list. First
199 * of all they only see the onscreen formats (the offscreen formats are at the end of the
200 * pixelformat list) and second extended pixelformat capabilities are hidden from the
201 * standard WGL calls. Only functions that depend on WGL_ARB_pixel_format can see them.
202 *
203 * Below we check if the pixelformat is also supported onscreen.
204 */
205 if(iPixelFormat != 0)
206 {
207 HDC pbuffer_hdc;
208 int attrib = 0;
209 HPBUFFERARB pbuffer = pwglCreatePbufferARB(hdc, iPixelFormat, 640 /* width */, 480 /* height */, &attrib);
210 if(!pbuffer)
211 skip("Pbuffer creation failed!\n");
212
213 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
214 pbuffer_hdc = pwglGetPbufferDCARB(pbuffer);
215 res = GetPixelFormat(pbuffer_hdc);
216 ok(res == iPixelFormat, "Unexpected iPixelFormat=%d returned by GetPixelFormat for format %d\n", res, iPixelFormat);
217 trace("iPixelFormat returned by GetPixelFormat: %d\n", res);
218 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat);
219
220 pwglReleasePbufferDCARB(pbuffer, pbuffer_hdc);
221 }
222 else skip("Pbuffer test for onscreen pixelformat skipped as no onscreen format with pbuffer capabilities have been found\n");
223
224 /* Search for a real offscreen format */
225 for(i=0, iPixelFormat=0; i<nFormats; i++)
226 {
227 if(iFormats[i] > nOnscreenFormats)
228 {
229 iPixelFormat = iFormats[i];
230 trace("Selected iPixelFormat: %d\n", iPixelFormat);
231 break;
232 }
233 }
234
235 if(iPixelFormat != 0)
236 {
237 HDC pbuffer_hdc;
238 HPBUFFERARB pbuffer = pwglCreatePbufferARB(hdc, iPixelFormat, 640 /* width */, 480 /* height */, NULL);
239 if(!pbuffer)
240 skip("Pbuffer creation failed!\n");
241
242 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
243 pbuffer_hdc = pwglGetPbufferDCARB(pbuffer);
244 res = GetPixelFormat(pbuffer_hdc);
245
246 ok(res == 1, "Unexpected iPixelFormat=%d (1 expected) returned by GetPixelFormat for offscreen format %d\n", res, iPixelFormat);
247 trace("iPixelFormat returned by GetPixelFormat: %d\n", res);
248 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat);
249 pwglReleasePbufferDCARB(pbuffer, hdc);
250 }
251 else skip("Pbuffer test for offscreen pixelformat skipped as no offscreen-only format with pbuffer capabilities has been found\n");
252 }
253
254 static void test_setpixelformat(HDC winhdc)
255 {
256 int res = 0;
257 int nCfgs;
258 int pf;
259 int i;
260 HWND hwnd;
261 PIXELFORMATDESCRIPTOR pfd = {
262 sizeof(PIXELFORMATDESCRIPTOR),
263 1, /* version */
264 PFD_DRAW_TO_WINDOW |
265 PFD_SUPPORT_OPENGL |
266 PFD_DOUBLEBUFFER,
267 PFD_TYPE_RGBA,
268 24, /* 24-bit color depth */
269 0, 0, 0, 0, 0, 0, /* color bits */
270 0, /* alpha buffer */
271 0, /* shift bit */
272 0, /* accumulation buffer */
273 0, 0, 0, 0, /* accum bits */
274 32, /* z-buffer */
275 0, /* stencil buffer */
276 0, /* auxiliary buffer */
277 PFD_MAIN_PLANE, /* main layer */
278 0, /* reserved */
279 0, 0, 0 /* layer masks */
280 };
281
282 HDC hdc = GetDC(0);
283 ok(hdc != 0, "GetDC(0) failed!\n");
284
285 /* This should pass even on the main device context */
286 pf = ChoosePixelFormat(hdc, &pfd);
287 ok(pf != 0, "ChoosePixelFormat failed on main device context\n");
288
289 /* SetPixelFormat on the main device context 'X root window' should fail,
290 * but some broken drivers allow it
291 */
292 res = SetPixelFormat(hdc, pf, &pfd);
293 trace("SetPixelFormat on main device context %s\n", res ? "succeeded" : "failed");
294
295 /* Setting the same format that was set on the HDC is allowed; other
296 formats fail */
297 nCfgs = DescribePixelFormat(winhdc, 0, 0, NULL);
298 pf = GetPixelFormat(winhdc);
299 for(i = 1;i <= nCfgs;i++)
300 {
301 int res = SetPixelFormat(winhdc, i, NULL);
302 if(i == pf) ok(res, "Failed to set the same pixel format\n");
303 else ok(!res, "Unexpectedly set an alternate pixel format\n");
304 }
305
306 hwnd = CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW, 10, 10, 200, 200, NULL, NULL,
307 NULL, NULL);
308 ok(hwnd != NULL, "err: %d\n", GetLastError());
309 if (hwnd)
310 {
311 HDC hdc = GetDC( hwnd );
312 pf = ChoosePixelFormat( hdc, &pfd );
313 ok( pf != 0, "ChoosePixelFormat failed\n" );
314 res = SetPixelFormat( hdc, pf, &pfd );
315 ok( res != 0, "SetPixelFormat failed\n" );
316 i = GetPixelFormat( hdc );
317 ok( i == pf, "GetPixelFormat returned wrong format %d/%d\n", i, pf );
318 ReleaseDC( hwnd, hdc );
319 hdc = GetWindowDC( hwnd );
320 i = GetPixelFormat( hdc );
321 ok( i == pf, "GetPixelFormat returned wrong format %d/%d\n", i, pf );
322 ReleaseDC( hwnd, hdc );
323 DestroyWindow( hwnd );
324 }
325
326 hwnd = CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW, 10, 10, 200, 200, NULL, NULL,
327 NULL, NULL);
328 ok(hwnd != NULL, "err: %d\n", GetLastError());
329 if (hwnd)
330 {
331 HDC hdc = GetWindowDC( hwnd );
332 pf = ChoosePixelFormat( hdc, &pfd );
333 ok( pf != 0, "ChoosePixelFormat failed\n" );
334 res = SetPixelFormat( hdc, pf, &pfd );
335 ok( res != 0, "SetPixelFormat failed\n" );
336 i = GetPixelFormat( hdc );
337 ok( i == pf, "GetPixelFormat returned wrong format %d/%d\n", i, pf );
338 ReleaseDC( hwnd, hdc );
339 DestroyWindow( hwnd );
340 }
341 }
342
343 static void test_sharelists(HDC winhdc)
344 {
345 HGLRC hglrc1, hglrc2, hglrc3;
346 BOOL res;
347
348 hglrc1 = wglCreateContext(winhdc);
349 res = wglShareLists(0, 0);
350 ok(res == FALSE, "Sharing display lists for no contexts passed!\n");
351
352 /* Test 1: Create a context and just share lists without doing anything special */
353 hglrc2 = wglCreateContext(winhdc);
354 if(hglrc2)
355 {
356 res = wglShareLists(hglrc1, hglrc2);
357 ok(res, "Sharing of display lists failed\n");
358 wglDeleteContext(hglrc2);
359 }
360
361 /* Test 2: Share display lists with a 'destination' context which has been made current */
362 hglrc2 = wglCreateContext(winhdc);
363 if(hglrc2)
364 {
365 res = wglMakeCurrent(winhdc, hglrc2);
366 ok(res, "Make current failed\n");
367 res = wglShareLists(hglrc1, hglrc2);
368 todo_wine ok(res, "Sharing display lists with a destination context which has been made current failed\n");
369 wglMakeCurrent(0, 0);
370 wglDeleteContext(hglrc2);
371 }
372
373 /* Test 3: Share display lists with a context which already shares display lists with another context.
374 * According to MSDN the second parameter cannot share any display lists but some buggy drivers might allow it */
375 hglrc3 = wglCreateContext(winhdc);
376 if(hglrc3)
377 {
378 res = wglShareLists(hglrc3, hglrc1);
379 ok(res == FALSE, "Sharing of display lists passed for a context which already shared lists before\n");
380 wglDeleteContext(hglrc3);
381 }
382
383 /* Test 4: Share display lists with a 'source' context which has been made current */
384 hglrc2 = wglCreateContext(winhdc);
385 if(hglrc2)
386 {
387 res = wglMakeCurrent(winhdc, hglrc1);
388 ok(res, "Make current failed\n");
389 res = wglShareLists(hglrc1, hglrc2);
390 ok(res, "Sharing display lists with a source context which has been made current failed\n");
391 wglMakeCurrent(0, 0);
392 wglDeleteContext(hglrc2);
393 }
394 }
395
396 static void test_makecurrent(HDC winhdc)
397 {
398 BOOL ret;
399 HGLRC hglrc;
400
401 hglrc = wglCreateContext(winhdc);
402 ok( hglrc != 0, "wglCreateContext failed\n" );
403
404 ret = wglMakeCurrent( winhdc, hglrc );
405 ok( ret, "wglMakeCurrent failed\n" );
406
407 ok( wglGetCurrentContext() == hglrc, "wrong context\n" );
408
409 /* set the same context again */
410 ret = wglMakeCurrent( winhdc, hglrc );
411 ok( ret, "wglMakeCurrent failed\n" );
412
413 /* check wglMakeCurrent(x, y) after another call to wglMakeCurrent(x, y) */
414 ret = wglMakeCurrent( winhdc, NULL );
415 ok( ret, "wglMakeCurrent failed\n" );
416
417 ret = wglMakeCurrent( winhdc, NULL );
418 ok( ret, "wglMakeCurrent failed\n" );
419
420 SetLastError( 0xdeadbeef );
421 ret = wglMakeCurrent( NULL, NULL );
422 ok( !ret || broken(ret) /* nt4 */, "wglMakeCurrent succeeded\n" );
423 if (!ret) ok( GetLastError() == ERROR_INVALID_HANDLE,
424 "Expected ERROR_INVALID_HANDLE, got error=%x\n", GetLastError() );
425
426 ret = wglMakeCurrent( winhdc, NULL );
427 ok( ret, "wglMakeCurrent failed\n" );
428
429 ret = wglMakeCurrent( winhdc, hglrc );
430 ok( ret, "wglMakeCurrent failed\n" );
431
432 ret = wglMakeCurrent( NULL, NULL );
433 ok( ret, "wglMakeCurrent failed\n" );
434
435 ok( wglGetCurrentContext() == NULL, "wrong context\n" );
436
437 SetLastError( 0xdeadbeef );
438 ret = wglMakeCurrent( NULL, NULL );
439 ok( !ret || broken(ret) /* nt4 */, "wglMakeCurrent succeeded\n" );
440 if (!ret) ok( GetLastError() == ERROR_INVALID_HANDLE,
441 "Expected ERROR_INVALID_HANDLE, got error=%x\n", GetLastError() );
442
443 ret = wglMakeCurrent( winhdc, hglrc );
444 ok( ret, "wglMakeCurrent failed\n" );
445 }
446
447 static void test_colorbits(HDC hdc)
448 {
449 const int iAttribList[] = { WGL_COLOR_BITS_ARB, WGL_RED_BITS_ARB, WGL_GREEN_BITS_ARB,
450 WGL_BLUE_BITS_ARB, WGL_ALPHA_BITS_ARB };
451 int iAttribRet[sizeof(iAttribList)/sizeof(iAttribList[0])];
452 const int iAttribs[] = { WGL_ALPHA_BITS_ARB, 1, 0 };
453 unsigned int nFormats;
454 BOOL res;
455 int iPixelFormat = 0;
456
457 if (!pwglChoosePixelFormatARB)
458 {
459 win_skip("wglChoosePixelFormatARB is not available\n");
460 return;
461 }
462
463 /* We need a pixel format with at least one bit of alpha */
464 res = pwglChoosePixelFormatARB(hdc, iAttribs, NULL, 1, &iPixelFormat, &nFormats);
465 if(res == FALSE || nFormats == 0)
466 {
467 skip("No suitable pixel formats found\n");
468 return;
469 }
470
471 res = pwglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0,
472 sizeof(iAttribList)/sizeof(iAttribList[0]), iAttribList, iAttribRet);
473 if(res == FALSE)
474 {
475 skip("wglGetPixelFormatAttribivARB failed\n");
476 return;
477 }
478 iAttribRet[1] += iAttribRet[2]+iAttribRet[3]+iAttribRet[4];
479 ok(iAttribRet[0] == iAttribRet[1], "WGL_COLOR_BITS_ARB (%d) does not equal R+G+B+A (%d)!\n",
480 iAttribRet[0], iAttribRet[1]);
481 }
482
483 static void test_gdi_dbuf(HDC hdc)
484 {
485 const int iAttribList[] = { WGL_SUPPORT_GDI_ARB, WGL_DOUBLE_BUFFER_ARB };
486 int iAttribRet[sizeof(iAttribList)/sizeof(iAttribList[0])];
487 unsigned int nFormats;
488 int iPixelFormat;
489 BOOL res;
490
491 if (!pwglGetPixelFormatAttribivARB)
492 {
493 win_skip("wglGetPixelFormatAttribivARB is not available\n");
494 return;
495 }
496
497 nFormats = DescribePixelFormat(hdc, 0, 0, NULL);
498 for(iPixelFormat = 1;iPixelFormat <= nFormats;iPixelFormat++)
499 {
500 res = pwglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0,
501 sizeof(iAttribList)/sizeof(iAttribList[0]), iAttribList,
502 iAttribRet);
503 ok(res!=FALSE, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat);
504 if(res == FALSE)
505 continue;
506
507 ok(!(iAttribRet[0] && iAttribRet[1]), "GDI support and double buffering on pixel format %d\n", iPixelFormat);
508 }
509 }
510
511 static void test_acceleration(HDC hdc)
512 {
513 const int iAttribList[] = { WGL_ACCELERATION_ARB };
514 int iAttribRet[sizeof(iAttribList)/sizeof(iAttribList[0])];
515 unsigned int nFormats;
516 int iPixelFormat;
517 int res;
518 PIXELFORMATDESCRIPTOR pfd;
519
520 if (!pwglGetPixelFormatAttribivARB)
521 {
522 win_skip("wglGetPixelFormatAttribivARB is not available\n");
523 return;
524 }
525
526 nFormats = DescribePixelFormat(hdc, 0, 0, NULL);
527 for(iPixelFormat = 1; iPixelFormat <= nFormats; iPixelFormat++)
528 {
529 res = pwglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0,
530 sizeof(iAttribList)/sizeof(iAttribList[0]), iAttribList,
531 iAttribRet);
532 ok(res!=FALSE, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat);
533 if(res == FALSE)
534 continue;
535
536 memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
537 DescribePixelFormat(hdc, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
538
539 switch(iAttribRet[0])
540 {
541 case WGL_NO_ACCELERATION_ARB:
542 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);
543 break;
544 case WGL_GENERIC_ACCELERATION_ARB:
545 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);
546 break;
547 case WGL_FULL_ACCELERATION_ARB:
548 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);
549 break;
550 }
551 }
552 }
553
554 static void test_bitmap_rendering( BOOL use_dib )
555 {
556 PIXELFORMATDESCRIPTOR pfd;
557 int i, ret, bpp, iPixelFormat=0;
558 unsigned int nFormats;
559 HGLRC hglrc, hglrc2;
560 BITMAPINFO biDst;
561 HBITMAP bmpDst, oldDst, bmp2;
562 HDC hdcDst, hdcScreen;
563 UINT *dstBuffer = NULL;
564
565 hdcScreen = CreateCompatibleDC(0);
566 hdcDst = CreateCompatibleDC(0);
567
568 if (use_dib)
569 {
570 bpp = 32;
571 memset(&biDst, 0, sizeof(BITMAPINFO));
572 biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
573 biDst.bmiHeader.biWidth = 4;
574 biDst.bmiHeader.biHeight = -4;
575 biDst.bmiHeader.biPlanes = 1;
576 biDst.bmiHeader.biBitCount = 32;
577 biDst.bmiHeader.biCompression = BI_RGB;
578
579 bmpDst = CreateDIBSection(0, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer, NULL, 0);
580
581 biDst.bmiHeader.biWidth = 12;
582 biDst.bmiHeader.biHeight = -12;
583 biDst.bmiHeader.biBitCount = 16;
584 bmp2 = CreateDIBSection(0, &biDst, DIB_RGB_COLORS, NULL, NULL, 0);
585 }
586 else
587 {
588 bpp = GetDeviceCaps( hdcScreen, BITSPIXEL );
589 bmpDst = CreateBitmap( 4, 4, 1, bpp, NULL );
590 bmp2 = CreateBitmap( 12, 12, 1, bpp, NULL );
591 }
592
593 oldDst = SelectObject(hdcDst, bmpDst);
594
595 trace( "testing on %s\n", use_dib ? "DIB" : "DDB" );
596
597 /* Pick a pixel format by hand because ChoosePixelFormat is unreliable */
598 nFormats = DescribePixelFormat(hdcDst, 0, 0, NULL);
599 for(i=1; i<=nFormats; i++)
600 {
601 memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
602 DescribePixelFormat(hdcDst, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
603
604 if((pfd.dwFlags & PFD_DRAW_TO_BITMAP) &&
605 (pfd.dwFlags & PFD_SUPPORT_OPENGL) &&
606 (pfd.cColorBits == bpp) &&
607 (pfd.cAlphaBits == 8) )
608 {
609 iPixelFormat = i;
610 break;
611 }
612 }
613
614 if(!iPixelFormat)
615 {
616 skip("Unable to find a suitable pixel format\n");
617 }
618 else
619 {
620 ret = SetPixelFormat(hdcDst, iPixelFormat, &pfd);
621 ok( ret, "SetPixelFormat failed\n" );
622 ret = GetPixelFormat( hdcDst );
623 ok( ret == iPixelFormat, "GetPixelFormat returned %d/%d\n", ret, iPixelFormat );
624 ret = SetPixelFormat(hdcDst, iPixelFormat + 1, &pfd);
625 ok( !ret, "SetPixelFormat succeeded\n" );
626 hglrc = wglCreateContext(hdcDst);
627 ok(hglrc != NULL, "Unable to create a context\n");
628
629 if(hglrc)
630 {
631 GLint viewport[4];
632 wglMakeCurrent(hdcDst, hglrc);
633 hglrc2 = wglCreateContext(hdcDst);
634 ok(hglrc2 != NULL, "Unable to create a context\n");
635
636 /* Note this is RGBA but we read ARGB back */
637 glClearColor((float)0x22/0xff, (float)0x33/0xff, (float)0x44/0xff, (float)0x11/0xff);
638 glClear(GL_COLOR_BUFFER_BIT);
639 glGetIntegerv( GL_VIEWPORT, viewport );
640 glFinish();
641
642 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 4 && viewport[3] == 4,
643 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
644 /* Note apparently the alpha channel is not supported by the software renderer (bitmap only works using software) */
645 if (dstBuffer)
646 for (i = 0; i < 16; i++)
647 ok(dstBuffer[i] == 0x223344 || dstBuffer[i] == 0x11223344, "Received color=%x at %u\n",
648 dstBuffer[i], i);
649
650 SelectObject(hdcDst, bmp2);
651 ret = GetPixelFormat( hdcDst );
652 ok( ret == iPixelFormat, "GetPixelFormat returned %d/%d\n", ret, iPixelFormat );
653 ret = SetPixelFormat(hdcDst, iPixelFormat + 1, &pfd);
654 ok( !ret, "SetPixelFormat succeeded\n" );
655
656 /* context still uses the old pixel format and viewport */
657 glClearColor((float)0x44/0xff, (float)0x33/0xff, (float)0x22/0xff, (float)0x11/0xff);
658 glClear(GL_COLOR_BUFFER_BIT);
659 glFinish();
660 glGetIntegerv( GL_VIEWPORT, viewport );
661 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 4 && viewport[3] == 4,
662 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
663
664 wglMakeCurrent(NULL, NULL);
665 wglMakeCurrent(hdcDst, hglrc);
666 glClearColor((float)0x44/0xff, (float)0x55/0xff, (float)0x66/0xff, (float)0x11/0xff);
667 glClear(GL_COLOR_BUFFER_BIT);
668 glFinish();
669 glGetIntegerv( GL_VIEWPORT, viewport );
670 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 4 && viewport[3] == 4,
671 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
672
673 wglMakeCurrent(hdcDst, hglrc2);
674 glGetIntegerv( GL_VIEWPORT, viewport );
675 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 12 && viewport[3] == 12,
676 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
677
678 wglMakeCurrent(hdcDst, hglrc);
679 glGetIntegerv( GL_VIEWPORT, viewport );
680 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 4 && viewport[3] == 4,
681 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
682
683 SelectObject(hdcDst, bmpDst);
684 ret = GetPixelFormat( hdcDst );
685 ok( ret == iPixelFormat, "GetPixelFormat returned %d/%d\n", ret, iPixelFormat );
686 ret = SetPixelFormat(hdcDst, iPixelFormat + 1, &pfd);
687 ok( !ret, "SetPixelFormat succeeded\n" );
688 wglMakeCurrent(hdcDst, hglrc2);
689 glGetIntegerv( GL_VIEWPORT, viewport );
690 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 12 && viewport[3] == 12,
691 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
692 }
693 }
694
695 SelectObject(hdcDst, oldDst);
696 DeleteObject(bmp2);
697 DeleteObject(bmpDst);
698 DeleteDC(hdcDst);
699 DeleteDC(hdcScreen);
700 }
701
702 struct wgl_thread_param
703 {
704 HANDLE test_finished;
705 HWND hwnd;
706 HGLRC hglrc;
707 BOOL make_current;
708 BOOL make_current_error;
709 BOOL deleted;
710 DWORD deleted_error;
711 };
712
713 static DWORD WINAPI wgl_thread(void *param)
714 {
715 struct wgl_thread_param *p = param;
716 HDC hdc = GetDC( p->hwnd );
717
718 SetLastError(0xdeadbeef);
719 p->make_current = wglMakeCurrent(hdc, p->hglrc);
720 p->make_current_error = GetLastError();
721 p->deleted = wglDeleteContext(p->hglrc);
722 p->deleted_error = GetLastError();
723 ReleaseDC( p->hwnd, hdc );
724 SetEvent(p->test_finished);
725 return 0;
726 }
727
728 static void test_deletecontext(HWND hwnd, HDC hdc)
729 {
730 struct wgl_thread_param thread_params;
731 HGLRC hglrc = wglCreateContext(hdc);
732 HANDLE thread_handle;
733 BOOL res;
734 DWORD tid;
735
736 SetLastError(0xdeadbeef);
737 res = wglDeleteContext(NULL);
738 ok(res == FALSE, "wglDeleteContext succeeded\n");
739 ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
740
741 if(!hglrc)
742 {
743 skip("wglCreateContext failed!\n");
744 return;
745 }
746
747 res = wglMakeCurrent(hdc, hglrc);
748 if(!res)
749 {
750 skip("wglMakeCurrent failed!\n");
751 return;
752 }
753
754 /* WGL doesn't allow you to delete a context from a different thread than the one in which it is current.
755 * This differs from GLX which does allow it but it delays actual deletion until the context becomes not current.
756 */
757 thread_params.hglrc = hglrc;
758 thread_params.hwnd = hwnd;
759 thread_params.test_finished = CreateEventW(NULL, FALSE, FALSE, NULL);
760 thread_handle = CreateThread(NULL, 0, wgl_thread, &thread_params, 0, &tid);
761 ok(!!thread_handle, "Failed to create thread, last error %#x.\n", GetLastError());
762 if(thread_handle)
763 {
764 WaitForSingleObject(thread_handle, INFINITE);
765 ok(!thread_params.make_current, "Attempt to make WGL context from another thread passed\n");
766 ok(thread_params.make_current_error == ERROR_BUSY, "Expected last error to be ERROR_BUSY, got %u\n", thread_params.make_current_error);
767 ok(!thread_params.deleted, "Attempt to delete WGL context from another thread passed\n");
768 ok(thread_params.deleted_error == ERROR_BUSY, "Expected last error to be ERROR_BUSY, got %u\n", thread_params.deleted_error);
769 }
770 CloseHandle(thread_params.test_finished);
771
772 res = wglDeleteContext(hglrc);
773 ok(res == TRUE, "wglDeleteContext failed\n");
774
775 /* Attempting to delete the same context twice should fail. */
776 SetLastError(0xdeadbeef);
777 res = wglDeleteContext(hglrc);
778 ok(res == FALSE, "wglDeleteContext succeeded\n");
779 ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
780
781 /* WGL makes a context not current when deleting it. This differs from GLX behavior where
782 * deletion takes place when the thread becomes not current. */
783 hglrc = wglGetCurrentContext();
784 ok(hglrc == NULL, "A WGL context is active while none was expected\n");
785 }
786
787
788 static void test_getprocaddress(HDC hdc)
789 {
790 const char *extensions = (const char*)glGetString(GL_EXTENSIONS);
791 PROC func = NULL;
792 HGLRC ctx = wglGetCurrentContext();
793
794 if (!extensions)
795 {
796 skip("skipping wglGetProcAddress tests because no GL extensions supported\n");
797 return;
798 }
799
800 /* Core GL 1.0/1.1 functions should not be loadable through wglGetProcAddress.
801 * Try to load the function with and without a context.
802 */
803 func = wglGetProcAddress("glEnable");
804 ok(func == NULL, "Lookup of function glEnable with a context passed, expected a failure\n");
805 wglMakeCurrent(hdc, NULL);
806 func = wglGetProcAddress("glEnable");
807 ok(func == NULL, "Lookup of function glEnable without a context passed, expected a failure\n");
808 wglMakeCurrent(hdc, ctx);
809
810 /* The goal of the test will be to test behavior of wglGetProcAddress when
811 * no WGL context is active. Before the test we pick an extension (GL_ARB_multitexture)
812 * which any GL >=1.2.1 implementation supports. Unfortunately the GDI renderer doesn't
813 * support it. There aren't any extensions we can use for this test which are supported by
814 * both GDI and real drivers.
815 * Note GDI only has GL_EXT_bgra, GL_EXT_paletted_texture and GL_WIN_swap_hint.
816 */
817 if (!gl_extension_supported(extensions, "GL_ARB_multitexture"))
818 {
819 skip("skipping test because lack of GL_ARB_multitexture support\n");
820 return;
821 }
822
823 func = wglGetProcAddress("glActiveTextureARB");
824 ok(func != NULL, "Unable to lookup glActiveTextureARB, last error %#x\n", GetLastError());
825
826 /* Temporarily disable the context, so we can see that we can't retrieve functions now. */
827 wglMakeCurrent(hdc, NULL);
828 func = wglGetProcAddress("glActiveTextureARB");
829 ok(func == NULL, "Function lookup without a context passed, expected a failure; last error %#x\n", GetLastError());
830 wglMakeCurrent(hdc, ctx);
831 }
832
833 static void test_make_current_read(HDC hdc)
834 {
835 int res;
836 HDC hread;
837 HGLRC hglrc = wglCreateContext(hdc);
838
839 if(!hglrc)
840 {
841 skip("wglCreateContext failed!\n");
842 return;
843 }
844
845 res = wglMakeCurrent(hdc, hglrc);
846 if(!res)
847 {
848 skip("wglMakeCurrent failed!\n");
849 return;
850 }
851
852 /* Test what wglGetCurrentReadDCARB does for wglMakeCurrent as the spec doesn't mention it */
853 hread = pwglGetCurrentReadDCARB();
854 trace("hread %p, hdc %p\n", hread, hdc);
855 ok(hread == hdc, "wglGetCurrentReadDCARB failed for standard wglMakeCurrent\n");
856
857 pwglMakeContextCurrentARB(hdc, hdc, hglrc);
858 hread = pwglGetCurrentReadDCARB();
859 ok(hread == hdc, "wglGetCurrentReadDCARB failed for wglMakeContextCurrent\n");
860 }
861
862 static void test_dc(HWND hwnd, HDC hdc)
863 {
864 int pf1, pf2;
865 HDC hdc2;
866
867 /* Get another DC and make sure it has the same pixel format */
868 hdc2 = GetDC(hwnd);
869 if(hdc != hdc2)
870 {
871 pf1 = GetPixelFormat(hdc);
872 pf2 = GetPixelFormat(hdc2);
873 ok(pf1 == pf2, "Second DC does not have the same format (%d != %d)\n", pf1, pf2);
874 }
875 else
876 skip("Could not get a different DC for the window\n");
877
878 if(hdc2)
879 {
880 ReleaseDC(hwnd, hdc2);
881 hdc2 = NULL;
882 }
883 }
884
885 /* Nvidia converts win32 error codes to (0xc007 << 16) | win32_error_code */
886 #define NVIDIA_HRESULT_FROM_WIN32(x) (HRESULT_FROM_WIN32(x) | 0x40000000)
887 static void test_opengl3(HDC hdc)
888 {
889 /* Try to create a context compatible with OpenGL 1.x; 1.0-2.1 is allowed */
890 {
891 HGLRC gl3Ctx;
892 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 1, 0};
893
894 gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
895 ok(gl3Ctx != 0, "pwglCreateContextAttribsARB for a 1.x context failed!\n");
896 wglDeleteContext(gl3Ctx);
897 }
898
899 /* Try to pass an invalid HDC */
900 {
901 HGLRC gl3Ctx;
902 DWORD error;
903 gl3Ctx = pwglCreateContextAttribsARB((HDC)0xdeadbeef, 0, 0);
904 ok(gl3Ctx == 0, "pwglCreateContextAttribsARB using an invalid HDC passed\n");
905 error = GetLastError();
906 todo_wine ok(error == ERROR_DC_NOT_FOUND ||
907 broken(error == NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_DATA)), /* Nvidia Vista + Win7 */
908 "Expected ERROR_DC_NOT_FOUND, got error=%x\n", error);
909 wglDeleteContext(gl3Ctx);
910 }
911
912 /* Try to pass an invalid shareList */
913 {
914 HGLRC gl3Ctx;
915 DWORD error;
916 gl3Ctx = pwglCreateContextAttribsARB(hdc, (HGLRC)0xdeadbeef, 0);
917 ok(gl3Ctx == 0, "pwglCreateContextAttribsARB using an invalid shareList passed\n");
918 error = GetLastError();
919 /* The Nvidia implementation seems to return hresults instead of win32 error codes */
920 todo_wine ok(error == ERROR_INVALID_OPERATION ||
921 error == NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_OPERATION), "Expected ERROR_INVALID_OPERATION, got error=%x\n", error);
922 wglDeleteContext(gl3Ctx);
923 }
924
925 /* Try to create an OpenGL 3.0 context */
926 {
927 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0};
928 HGLRC gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
929
930 if(gl3Ctx == NULL)
931 {
932 skip("Skipping the rest of the WGL_ARB_create_context test due to lack of OpenGL 3.0\n");
933 return;
934 }
935
936 wglDeleteContext(gl3Ctx);
937 }
938
939 /* 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 */
940 {
941 HGLRC glCtx = wglCreateContext(hdc);
942
943 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0};
944 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};
945
946 HGLRC gl3Ctx = pwglCreateContextAttribsARB(hdc, glCtx, attribs);
947 ok(gl3Ctx != NULL, "Sharing of a display list between OpenGL 3.0 and OpenGL 1.x/2.x failed!\n");
948 if(gl3Ctx)
949 wglDeleteContext(gl3Ctx);
950
951 gl3Ctx = pwglCreateContextAttribsARB(hdc, glCtx, attribs_future);
952 ok(gl3Ctx != NULL, "Sharing of a display list between a forward compatible OpenGL 3.0 context and OpenGL 1.x/2.x failed!\n");
953 if(gl3Ctx)
954 wglDeleteContext(gl3Ctx);
955
956 if(glCtx)
957 wglDeleteContext(glCtx);
958 }
959
960 /* Try to create an OpenGL 3.0 context and test windowless rendering */
961 {
962 HGLRC gl3Ctx;
963 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0};
964 BOOL res;
965
966 gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
967 ok(gl3Ctx != 0, "pwglCreateContextAttribsARB for a 3.0 context failed!\n");
968
969 /* OpenGL 3.0 allows offscreen rendering WITHOUT a drawable
970 * Neither AMD or Nvidia support it at this point. The WGL_ARB_create_context specs also say that
971 * it is hard because drivers use the HDC to enter the display driver and it sounds like they don't
972 * expect drivers to ever offer it.
973 */
974 res = wglMakeCurrent(0, gl3Ctx);
975 ok(res == FALSE, "Wow, OpenGL 3.0 windowless rendering passed while it was expected not to!\n");
976 if(res)
977 wglMakeCurrent(0, 0);
978
979 if(gl3Ctx)
980 wglDeleteContext(gl3Ctx);
981 }
982 }
983
984 static void test_minimized(void)
985 {
986 PIXELFORMATDESCRIPTOR pf_desc =
987 {
988 sizeof(PIXELFORMATDESCRIPTOR),
989 1, /* version */
990 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
991 PFD_TYPE_RGBA,
992 24, /* 24-bit color depth */
993 0, 0, 0, 0, 0, 0, /* color bits */
994 0, /* alpha buffer */
995 0, /* shift bit */
996 0, /* accumulation buffer */
997 0, 0, 0, 0, /* accum bits */
998 32, /* z-buffer */
999 0, /* stencil buffer */
1000 0, /* auxiliary buffer */
1001 PFD_MAIN_PLANE, /* main layer */
1002 0, /* reserved */
1003 0, 0, 0 /* layer masks */
1004 };
1005 int pixel_format;
1006 HWND window;
1007 LONG style;
1008 HGLRC ctx;
1009 BOOL ret;
1010 HDC dc;
1011
1012 window = CreateWindowA("static", "opengl32_test",
1013 WS_POPUP | WS_MINIMIZE, 0, 0, 640, 480, 0, 0, 0, 0);
1014 ok(!!window, "Failed to create window, last error %#x.\n", GetLastError());
1015
1016 dc = GetDC(window);
1017 ok(!!dc, "Failed to get DC.\n");
1018
1019 pixel_format = ChoosePixelFormat(dc, &pf_desc);
1020 if (!pixel_format)
1021 {
1022 win_skip("Failed to find pixel format.\n");
1023 ReleaseDC(window, dc);
1024 DestroyWindow(window);
1025 return;
1026 }
1027
1028 ret = SetPixelFormat(dc, pixel_format, &pf_desc);
1029 ok(ret, "Failed to set pixel format, last error %#x.\n", GetLastError());
1030
1031 style = GetWindowLongA(window, GWL_STYLE);
1032 ok(style & WS_MINIMIZE, "Window should be minimized, got style %#x.\n", style);
1033
1034 ctx = wglCreateContext(dc);
1035 ok(!!ctx, "Failed to create GL context, last error %#x.\n", GetLastError());
1036
1037 ret = wglMakeCurrent(dc, ctx);
1038 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1039
1040 style = GetWindowLongA(window, GWL_STYLE);
1041 ok(style & WS_MINIMIZE, "window should be minimized, got style %#x.\n", style);
1042
1043 ret = wglMakeCurrent(NULL, NULL);
1044 ok(ret, "Failed to clear current context, last error %#x.\n", GetLastError());
1045
1046 ret = wglDeleteContext(ctx);
1047 ok(ret, "Failed to delete GL context, last error %#x.\n", GetLastError());
1048
1049 ReleaseDC(window, dc);
1050 DestroyWindow(window);
1051 }
1052
1053 static void test_window_dc(void)
1054 {
1055 PIXELFORMATDESCRIPTOR pf_desc =
1056 {
1057 sizeof(PIXELFORMATDESCRIPTOR),
1058 1, /* version */
1059 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
1060 PFD_TYPE_RGBA,
1061 24, /* 24-bit color depth */
1062 0, 0, 0, 0, 0, 0, /* color bits */
1063 0, /* alpha buffer */
1064 0, /* shift bit */
1065 0, /* accumulation buffer */
1066 0, 0, 0, 0, /* accum bits */
1067 32, /* z-buffer */
1068 0, /* stencil buffer */
1069 0, /* auxiliary buffer */
1070 PFD_MAIN_PLANE, /* main layer */
1071 0, /* reserved */
1072 0, 0, 0 /* layer masks */
1073 };
1074 int pixel_format;
1075 HWND window;
1076 RECT vp, r;
1077 HGLRC ctx;
1078 BOOL ret;
1079 HDC dc;
1080
1081 window = CreateWindowA("static", "opengl32_test",
1082 WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, 0, 0, 0, 0);
1083 ok(!!window, "Failed to create window, last error %#x.\n", GetLastError());
1084
1085 ShowWindow(window, SW_SHOW);
1086
1087 dc = GetWindowDC(window);
1088 ok(!!dc, "Failed to get DC.\n");
1089
1090 pixel_format = ChoosePixelFormat(dc, &pf_desc);
1091 if (!pixel_format)
1092 {
1093 win_skip("Failed to find pixel format.\n");
1094 ReleaseDC(window, dc);
1095 DestroyWindow(window);
1096 return;
1097 }
1098
1099 ret = SetPixelFormat(dc, pixel_format, &pf_desc);
1100 ok(ret, "Failed to set pixel format, last error %#x.\n", GetLastError());
1101
1102 ctx = wglCreateContext(dc);
1103 ok(!!ctx, "Failed to create GL context, last error %#x.\n", GetLastError());
1104
1105 ret = wglMakeCurrent(dc, ctx);
1106 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1107
1108 GetClientRect(window, &r);
1109 glGetIntegerv(GL_VIEWPORT, (GLint *)&vp);
1110 ok(EqualRect(&r, &vp), "Viewport not equal to client rect.\n");
1111
1112 ret = wglMakeCurrent(NULL, NULL);
1113 ok(ret, "Failed to clear current context, last error %#x.\n", GetLastError());
1114
1115 ret = wglDeleteContext(ctx);
1116 ok(ret, "Failed to delete GL context, last error %#x.\n", GetLastError());
1117
1118 ReleaseDC(window, dc);
1119 DestroyWindow(window);
1120 }
1121
1122 static void test_message_window(void)
1123 {
1124 PIXELFORMATDESCRIPTOR pf_desc =
1125 {
1126 sizeof(PIXELFORMATDESCRIPTOR),
1127 1, /* version */
1128 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
1129 PFD_TYPE_RGBA,
1130 24, /* 24-bit color depth */
1131 0, 0, 0, 0, 0, 0, /* color bits */
1132 0, /* alpha buffer */
1133 0, /* shift bit */
1134 0, /* accumulation buffer */
1135 0, 0, 0, 0, /* accum bits */
1136 32, /* z-buffer */
1137 0, /* stencil buffer */
1138 0, /* auxiliary buffer */
1139 PFD_MAIN_PLANE, /* main layer */
1140 0, /* reserved */
1141 0, 0, 0 /* layer masks */
1142 };
1143 int pixel_format;
1144 HWND window;
1145 RECT vp, r;
1146 HGLRC ctx;
1147 BOOL ret;
1148 HDC dc;
1149 GLenum glerr;
1150
1151 window = CreateWindowA("static", "opengl32_test",
1152 WS_OVERLAPPEDWINDOW, 0, 0, 100, 100, HWND_MESSAGE, 0, 0, 0);
1153 if (!window)
1154 {
1155 win_skip( "HWND_MESSAGE not supported\n" );
1156 return;
1157 }
1158 dc = GetDC(window);
1159 ok(!!dc, "Failed to get DC.\n");
1160
1161 pixel_format = ChoosePixelFormat(dc, &pf_desc);
1162 if (!pixel_format)
1163 {
1164 win_skip("Failed to find pixel format.\n");
1165 ReleaseDC(window, dc);
1166 DestroyWindow(window);
1167 return;
1168 }
1169
1170 ret = SetPixelFormat(dc, pixel_format, &pf_desc);
1171 ok(ret, "Failed to set pixel format, last error %#x.\n", GetLastError());
1172
1173 ctx = wglCreateContext(dc);
1174 ok(!!ctx, "Failed to create GL context, last error %#x.\n", GetLastError());
1175
1176 ret = wglMakeCurrent(dc, ctx);
1177 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1178
1179 GetClientRect(window, &r);
1180 glGetIntegerv(GL_VIEWPORT, (GLint *)&vp);
1181 ok(EqualRect(&r, &vp), "Viewport not equal to client rect.\n");
1182
1183 glClear(GL_COLOR_BUFFER_BIT);
1184 glFinish();
1185 glerr = glGetError();
1186 ok(glerr == GL_NO_ERROR, "Failed glClear, error %#x.\n", glerr);
1187 ret = SwapBuffers(dc);
1188 ok(ret, "Failed SwapBuffers, error %#x.\n", GetLastError());
1189
1190 ret = wglMakeCurrent(NULL, NULL);
1191 ok(ret, "Failed to clear current context, last error %#x.\n", GetLastError());
1192
1193 ret = wglDeleteContext(ctx);
1194 ok(ret, "Failed to delete GL context, last error %#x.\n", GetLastError());
1195
1196 ReleaseDC(window, dc);
1197 DestroyWindow(window);
1198 }
1199
1200 static void test_destroy(HDC oldhdc)
1201 {
1202 PIXELFORMATDESCRIPTOR pf_desc =
1203 {
1204 sizeof(PIXELFORMATDESCRIPTOR),
1205 1, /* version */
1206 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
1207 PFD_TYPE_RGBA,
1208 24, /* 24-bit color depth */
1209 0, 0, 0, 0, 0, 0, /* color bits */
1210 0, /* alpha buffer */
1211 0, /* shift bit */
1212 0, /* accumulation buffer */
1213 0, 0, 0, 0, /* accum bits */
1214 32, /* z-buffer */
1215 0, /* stencil buffer */
1216 0, /* auxiliary buffer */
1217 PFD_MAIN_PLANE, /* main layer */
1218 0, /* reserved */
1219 0, 0, 0 /* layer masks */
1220 };
1221 int pixel_format;
1222 HWND window;
1223 HGLRC ctx;
1224 BOOL ret;
1225 HDC dc;
1226 GLenum glerr;
1227 DWORD err;
1228 HGLRC oldctx = wglGetCurrentContext();
1229
1230 ok(!!oldctx, "Expected to find a valid current context.\n");
1231
1232 window = CreateWindowA("static", "opengl32_test",
1233 WS_POPUP, 0, 0, 640, 480, 0, 0, 0, 0);
1234 ok(!!window, "Failed to create window, last error %#x.\n", GetLastError());
1235
1236 dc = GetDC(window);
1237 ok(!!dc, "Failed to get DC.\n");
1238
1239 pixel_format = ChoosePixelFormat(dc, &pf_desc);
1240 if (!pixel_format)
1241 {
1242 win_skip("Failed to find pixel format.\n");
1243 ReleaseDC(window, dc);
1244 DestroyWindow(window);
1245 return;
1246 }
1247
1248 ret = SetPixelFormat(dc, pixel_format, &pf_desc);
1249 ok(ret, "Failed to set pixel format, last error %#x.\n", GetLastError());
1250
1251 ctx = wglCreateContext(dc);
1252 ok(!!ctx, "Failed to create GL context, last error %#x.\n", GetLastError());
1253
1254 ret = wglMakeCurrent(dc, ctx);
1255 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1256
1257 glClear(GL_COLOR_BUFFER_BIT);
1258 glFinish();
1259 glerr = glGetError();
1260 ok(glerr == GL_NO_ERROR, "Failed glClear, error %#x.\n", glerr);
1261 ret = SwapBuffers(dc);
1262 ok(ret, "Failed SwapBuffers, error %#x.\n", GetLastError());
1263
1264 ret = DestroyWindow(window);
1265 ok(ret, "Failed to destroy window, last error %#x.\n", GetLastError());
1266
1267 ok(wglGetCurrentContext() == ctx, "Wrong current context.\n");
1268
1269 SetLastError(0xdeadbeef);
1270 ret = wglMakeCurrent(dc, ctx);
1271 err = GetLastError();
1272 ok(!ret && err == ERROR_INVALID_HANDLE,
1273 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret, err);
1274 SetLastError(0xdeadbeef);
1275 ret = SwapBuffers(dc);
1276 err = GetLastError();
1277 ok(!ret && err == ERROR_INVALID_HANDLE, "Unexpected behavior with SwapBuffer, last error %#x.\n", err);
1278
1279 ok(wglGetCurrentContext() == ctx, "Wrong current context.\n");
1280
1281 glClear(GL_COLOR_BUFFER_BIT);
1282 glFinish();
1283 glerr = glGetError();
1284 ok(glerr == GL_NO_ERROR, "Failed glClear, error %#x.\n", glerr);
1285 SetLastError(0xdeadbeef);
1286 ret = SwapBuffers(dc);
1287 err = GetLastError();
1288 ok(!ret && err == ERROR_INVALID_HANDLE, "Unexpected behavior with SwapBuffer, last error %#x.\n", err);
1289
1290 ret = wglMakeCurrent(NULL, NULL);
1291 ok(ret, "Failed to clear current context, last error %#x.\n", GetLastError());
1292
1293 glClear(GL_COLOR_BUFFER_BIT);
1294 glFinish();
1295 glerr = glGetError();
1296 ok(glerr == GL_INVALID_OPERATION, "Failed glClear, error %#x.\n", glerr);
1297 SetLastError(0xdeadbeef);
1298 ret = SwapBuffers(dc);
1299 err = GetLastError();
1300 ok(!ret && err == ERROR_INVALID_HANDLE, "Unexpected behavior with SwapBuffer, last error %#x.\n", err);
1301
1302 SetLastError(0xdeadbeef);
1303 ret = wglMakeCurrent(dc, ctx);
1304 err = GetLastError();
1305 ok(!ret && err == ERROR_INVALID_HANDLE,
1306 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret, err);
1307
1308 ok(wglGetCurrentContext() == NULL, "Wrong current context.\n");
1309
1310 ret = wglMakeCurrent(oldhdc, oldctx);
1311 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1312 ok(wglGetCurrentContext() == oldctx, "Wrong current context.\n");
1313
1314 SetLastError(0xdeadbeef);
1315 ret = wglMakeCurrent(dc, ctx);
1316 err = GetLastError();
1317 ok(!ret && err == ERROR_INVALID_HANDLE,
1318 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret, err);
1319
1320 ok(wglGetCurrentContext() == oldctx, "Wrong current context.\n");
1321
1322 ret = wglDeleteContext(ctx);
1323 ok(ret, "Failed to delete GL context, last error %#x.\n", GetLastError());
1324
1325 ReleaseDC(window, dc);
1326
1327 ret = wglMakeCurrent(oldhdc, oldctx);
1328 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1329 }
1330
1331 static void test_destroy_read(HDC oldhdc)
1332 {
1333 PIXELFORMATDESCRIPTOR pf_desc =
1334 {
1335 sizeof(PIXELFORMATDESCRIPTOR),
1336 1, /* version */
1337 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
1338 PFD_TYPE_RGBA,
1339 24, /* 24-bit color depth */
1340 0, 0, 0, 0, 0, 0, /* color bits */
1341 0, /* alpha buffer */
1342 0, /* shift bit */
1343 0, /* accumulation buffer */
1344 0, 0, 0, 0, /* accum bits */
1345 32, /* z-buffer */
1346 0, /* stencil buffer */
1347 0, /* auxiliary buffer */
1348 PFD_MAIN_PLANE, /* main layer */
1349 0, /* reserved */
1350 0, 0, 0 /* layer masks */
1351 };
1352 int pixel_format;
1353 HWND draw_window, read_window;
1354 HGLRC ctx;
1355 BOOL ret;
1356 HDC read_dc, draw_dc;
1357 GLenum glerr;
1358 DWORD err;
1359 HGLRC oldctx = wglGetCurrentContext();
1360
1361 ok(!!oldctx, "Expected to find a valid current context\n");
1362
1363 draw_window = CreateWindowA("static", "opengl32_test",
1364 WS_POPUP, 0, 0, 640, 480, 0, 0, 0, 0);
1365 ok(!!draw_window, "Failed to create window, last error %#x.\n", GetLastError());
1366
1367 draw_dc = GetDC(draw_window);
1368 ok(!!draw_dc, "Failed to get DC.\n");
1369
1370 pixel_format = ChoosePixelFormat(draw_dc, &pf_desc);
1371 if (!pixel_format)
1372 {
1373 win_skip("Failed to find pixel format.\n");
1374 ReleaseDC(draw_window, draw_dc);
1375 DestroyWindow(draw_window);
1376 return;
1377 }
1378
1379 ret = SetPixelFormat(draw_dc, pixel_format, &pf_desc);
1380 ok(ret, "Failed to set pixel format, last error %#x.\n", GetLastError());
1381
1382 read_window = CreateWindowA("static", "opengl32_test",
1383 WS_POPUP, 0, 0, 640, 480, 0, 0, 0, 0);
1384 ok(!!read_window, "Failed to create window, last error %#x.\n", GetLastError());
1385
1386 read_dc = GetDC(read_window);
1387 ok(!!draw_dc, "Failed to get DC.\n");
1388
1389 pixel_format = ChoosePixelFormat(read_dc, &pf_desc);
1390 if (!pixel_format)
1391 {
1392 win_skip("Failed to find pixel format.\n");
1393 ReleaseDC(read_window, read_dc);
1394 DestroyWindow(read_window);
1395 ReleaseDC(draw_window, draw_dc);
1396 DestroyWindow(draw_window);
1397 return;
1398 }
1399
1400 ret = SetPixelFormat(read_dc, pixel_format, &pf_desc);
1401 ok(ret, "Failed to set pixel format, last error %#x.\n", GetLastError());
1402
1403 ctx = wglCreateContext(draw_dc);
1404 ok(!!ctx, "Failed to create GL context, last error %#x.\n", GetLastError());
1405
1406 ret = pwglMakeContextCurrentARB(draw_dc, read_dc, ctx);
1407 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1408
1409 glCopyPixels(0, 0, 640, 480, GL_COLOR);
1410 glFinish();
1411 glerr = glGetError();
1412 ok(glerr == GL_NO_ERROR, "Failed glCopyPixel, error %#x.\n", glerr);
1413 ret = SwapBuffers(draw_dc);
1414 ok(ret, "Failed SwapBuffers, error %#x.\n", GetLastError());
1415
1416 ret = DestroyWindow(read_window);
1417 ok(ret, "Failed to destroy window, last error %#x.\n", GetLastError());
1418
1419 ok(wglGetCurrentContext() == ctx, "Wrong current context.\n");
1420
1421 if (0) /* Crashes on AMD on Windows */
1422 {
1423 glCopyPixels(0, 0, 640, 480, GL_COLOR);
1424 glFinish();
1425 glerr = glGetError();
1426 ok(glerr == GL_NO_ERROR, "Failed glCopyPixel, error %#x.\n", glerr);
1427 }
1428
1429 glClear(GL_COLOR_BUFFER_BIT);
1430 glFinish();
1431 glerr = glGetError();
1432 ok(glerr == GL_NO_ERROR, "Failed glClear, error %#x.\n", glerr);
1433 ret = SwapBuffers(draw_dc);
1434 ok(ret, "Failed SwapBuffers, error %#x.\n", GetLastError());
1435
1436 ret = wglMakeCurrent(NULL, NULL);
1437 ok(ret, "Failed to clear current context, last error %#x.\n", GetLastError());
1438
1439 if (0) /* This crashes with Nvidia drivers on Windows. */
1440 {
1441 SetLastError(0xdeadbeef);
1442 ret = pwglMakeContextCurrentARB(draw_dc, read_dc, ctx);
1443 err = GetLastError();
1444 ok(!ret && err == ERROR_INVALID_HANDLE,
1445 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret, err);
1446 }
1447
1448 ret = DestroyWindow(draw_window);
1449 ok(ret, "Failed to destroy window, last error %#x.\n", GetLastError());
1450
1451 glClear(GL_COLOR_BUFFER_BIT);
1452 glFinish();
1453 glerr = glGetError();
1454 ok(glerr == GL_INVALID_OPERATION, "Failed glClear, error %#x.\n", glerr);
1455 SetLastError(0xdeadbeef);
1456 ret = SwapBuffers(draw_dc);
1457 err = GetLastError();
1458 ok(!ret && err == ERROR_INVALID_HANDLE, "Unexpected behavior with SwapBuffer, last error %#x.\n", err);
1459
1460 SetLastError(0xdeadbeef);
1461 ret = pwglMakeContextCurrentARB(draw_dc, read_dc, ctx);
1462 err = GetLastError();
1463 ok(!ret && (err == ERROR_INVALID_HANDLE || err == 0xc0070006),
1464 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret, err);
1465
1466 ok(wglGetCurrentContext() == NULL, "Wrong current context.\n");
1467
1468 wglMakeCurrent(NULL, NULL);
1469
1470 wglMakeCurrent(oldhdc, oldctx);
1471 ok(wglGetCurrentContext() == oldctx, "Wrong current context.\n");
1472
1473 SetLastError(0xdeadbeef);
1474 ret = pwglMakeContextCurrentARB(draw_dc, read_dc, ctx);
1475 err = GetLastError();
1476 ok(!ret && (err == ERROR_INVALID_HANDLE || err == 0xc0070006),
1477 "Unexpected behavior when making context current, last error %#x.\n", err);
1478
1479 ok(wglGetCurrentContext() == oldctx, "Wrong current context.\n");
1480
1481 ret = wglDeleteContext(ctx);
1482 ok(ret, "Failed to delete GL context, last error %#x.\n", GetLastError());
1483
1484 ReleaseDC(read_window, read_dc);
1485 ReleaseDC(draw_window, draw_dc);
1486
1487 wglMakeCurrent(oldhdc, oldctx);
1488 }
1489
1490 static void test_swap_control(HDC oldhdc)
1491 {
1492 PIXELFORMATDESCRIPTOR pf_desc =
1493 {
1494 sizeof(PIXELFORMATDESCRIPTOR),
1495 1, /* version */
1496 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
1497 PFD_TYPE_RGBA,
1498 24, /* 24-bit color depth */
1499 0, 0, 0, 0, 0, 0, /* color bits */
1500 0, /* alpha buffer */
1501 0, /* shift bit */
1502 0, /* accumulation buffer */
1503 0, 0, 0, 0, /* accum bits */
1504 32, /* z-buffer */
1505 0, /* stencil buffer */
1506 0, /* auxiliary buffer */
1507 PFD_MAIN_PLANE, /* main layer */
1508 0, /* reserved */
1509 0, 0, 0 /* layer masks */
1510 };
1511 int pixel_format;
1512 HWND window1, window2, old_parent;
1513 HGLRC ctx1, ctx2, oldctx;
1514 BOOL ret;
1515 HDC dc1, dc2;
1516 int interval;
1517
1518 oldctx = wglGetCurrentContext();
1519 ok(!!oldctx, "Expected to find a valid current context.\n");
1520
1521 window1 = CreateWindowA("static", "opengl32_test",
1522 WS_POPUP, 0, 0, 640, 480, 0, 0, 0, 0);
1523 ok(!!window1, "Failed to create window1, last error %#x.\n", GetLastError());
1524
1525 dc1 = GetDC(window1);
1526 ok(!!dc1, "Failed to get DC.\n");
1527
1528 pixel_format = ChoosePixelFormat(dc1, &pf_desc);
1529 if (!pixel_format)
1530 {
1531 win_skip("Failed to find pixel format.\n");
1532 ReleaseDC(window1, dc1);
1533 DestroyWindow(window1);
1534 return;
1535 }
1536
1537 ret = SetPixelFormat(dc1, pixel_format, &pf_desc);
1538 ok(ret, "Failed to set pixel format, last error %#x.\n", GetLastError());
1539
1540 ctx1 = wglCreateContext(dc1);
1541 ok(!!ctx1, "Failed to create GL context, last error %#x.\n", GetLastError());
1542
1543 ret = wglMakeCurrent(dc1, ctx1);
1544 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1545
1546 interval = pwglGetSwapIntervalEXT();
1547 ok(interval == 1, "Expected default swap interval 1, got %d\n", interval);
1548
1549 ret = pwglSwapIntervalEXT(0);
1550 ok(ret, "Failed to set swap interval to 0, last error %#x.\n", GetLastError());
1551
1552 interval = pwglGetSwapIntervalEXT();
1553 ok(interval == 0, "Expected swap interval 0, got %d\n", interval);
1554
1555 /* Check what interval we get on a second context on the same drawable.*/
1556 ctx2 = wglCreateContext(dc1);
1557 ok(!!ctx2, "Failed to create GL context, last error %#x.\n", GetLastError());
1558
1559 ret = wglMakeCurrent(dc1, ctx2);
1560 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1561
1562 interval = pwglGetSwapIntervalEXT();
1563 ok(interval == 0, "Expected swap interval 0, got %d\n", interval);
1564
1565 /* A second window is created to see whether its swap interval was affected
1566 * by previous calls.
1567 */
1568 window2 = CreateWindowA("static", "opengl32_test",
1569 WS_POPUP, 0, 0, 640, 480, 0, 0, 0, 0);
1570 ok(!!window2, "Failed to create window2, last error %#x.\n", GetLastError());
1571
1572 dc2 = GetDC(window2);
1573 ok(!!dc2, "Failed to get DC.\n");
1574
1575 ret = SetPixelFormat(dc2, pixel_format, &pf_desc);
1576 ok(ret, "Failed to set pixel format, last error %#x.\n", GetLastError());
1577
1578 ret = wglMakeCurrent(dc2, ctx1);
1579 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1580
1581 /* Since the second window lacks the swap interval, this proves that the interval
1582 * is not global or shared among contexts.
1583 */
1584 interval = pwglGetSwapIntervalEXT();
1585 ok(interval == 1, "Expected default swap interval 1, got %d\n", interval);
1586
1587 /* Test if setting the parent of a window resets the swap interval. */
1588 ret = wglMakeCurrent(dc1, ctx1);
1589 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1590
1591 old_parent = SetParent(window1, window2);
1592 ok(!!old_parent, "Failed to make window1 a child of window2, last error %#x.\n", GetLastError());
1593
1594 interval = pwglGetSwapIntervalEXT();
1595 ok(interval == 0, "Expected swap interval 0, got %d\n", interval);
1596
1597 ret = wglDeleteContext(ctx1);
1598 ok(ret, "Failed to delete GL context, last error %#x.\n", GetLastError());
1599 ret = wglDeleteContext(ctx2);
1600 ok(ret, "Failed to delete GL context, last error %#x.\n", GetLastError());
1601
1602 ReleaseDC(window1, dc1);
1603 DestroyWindow(window1);
1604 ReleaseDC(window2, dc2);
1605 DestroyWindow(window2);
1606
1607 wglMakeCurrent(oldhdc, oldctx);
1608 }
1609
1610 START_TEST(opengl)
1611 {
1612 HWND hwnd;
1613 PIXELFORMATDESCRIPTOR pfd = {
1614 sizeof(PIXELFORMATDESCRIPTOR),
1615 1, /* version */
1616 PFD_DRAW_TO_WINDOW |
1617 PFD_SUPPORT_OPENGL |
1618 PFD_DOUBLEBUFFER,
1619 PFD_TYPE_RGBA,
1620 24, /* 24-bit color depth */
1621 0, 0, 0, 0, 0, 0, /* color bits */
1622 0, /* alpha buffer */
1623 0, /* shift bit */
1624 0, /* accumulation buffer */
1625 0, 0, 0, 0, /* accum bits */
1626 32, /* z-buffer */
1627 0, /* stencil buffer */
1628 0, /* auxiliary buffer */
1629 PFD_MAIN_PLANE, /* main layer */
1630 0, /* reserved */
1631 0, 0, 0 /* layer masks */
1632 };
1633
1634 hwnd = CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW, 10, 10, 200, 200, NULL, NULL,
1635 NULL, NULL);
1636 ok(hwnd != NULL, "err: %d\n", GetLastError());
1637 if (hwnd)
1638 {
1639 HDC hdc;
1640 int iPixelFormat, res;
1641 HGLRC hglrc;
1642 DWORD error;
1643 ShowWindow(hwnd, SW_SHOW);
1644
1645 hdc = GetDC(hwnd);
1646
1647 iPixelFormat = ChoosePixelFormat(hdc, &pfd);
1648 if(iPixelFormat == 0)
1649 {
1650 /* This should never happen as ChoosePixelFormat always returns a closest match, but currently this fails in Wine if we don't have glX */
1651 win_skip("Unable to find pixel format.\n");
1652 goto cleanup;
1653 }
1654
1655 /* We shouldn't be able to create a context from a hdc which doesn't have a pixel format set */
1656 hglrc = wglCreateContext(hdc);
1657 ok(hglrc == NULL, "wglCreateContext should fail when no pixel format has been set, but it passed\n");
1658 error = GetLastError();
1659 ok(error == ERROR_INVALID_PIXEL_FORMAT, "expected ERROR_INVALID_PIXEL_FORMAT for wglCreateContext without a pixelformat set, but received %#x\n", error);
1660
1661 res = SetPixelFormat(hdc, iPixelFormat, &pfd);
1662 ok(res, "SetPixelformat failed: %x\n", GetLastError());
1663
1664 test_bitmap_rendering( TRUE );
1665 test_bitmap_rendering( FALSE );
1666 test_minimized();
1667 test_window_dc();
1668 test_message_window();
1669 test_dc(hwnd, hdc);
1670
1671 hglrc = wglCreateContext(hdc);
1672 res = wglMakeCurrent(hdc, hglrc);
1673 ok(res, "wglMakeCurrent failed!\n");
1674 if(res)
1675 {
1676 trace("OpenGL renderer: %s\n", glGetString(GL_RENDERER));
1677 trace("OpenGL driver version: %s\n", glGetString(GL_VERSION));
1678 trace("OpenGL vendor: %s\n", glGetString(GL_VENDOR));
1679 }
1680 else
1681 {
1682 skip("Skipping OpenGL tests without a current context\n");
1683 return;
1684 }
1685
1686 /* Initialisation of WGL functions depends on an implicit WGL context. For this reason we can't load them before making
1687 * any WGL call :( On Wine this would work but not on real Windows because there can be different implementations (software, ICD, MCD).
1688 */
1689 init_functions();
1690 test_getprocaddress(hdc);
1691 test_deletecontext(hwnd, hdc);
1692 test_makecurrent(hdc);
1693
1694 /* The lack of wglGetExtensionsStringARB in general means broken software rendering or the lack of decent OpenGL support, skip tests in such cases */
1695 if (!pwglGetExtensionsStringARB)
1696 {
1697 win_skip("wglGetExtensionsStringARB is not available\n");
1698 return;
1699 }
1700
1701 test_setpixelformat(hdc);
1702 test_destroy(hdc);
1703 test_sharelists(hdc);
1704 test_colorbits(hdc);
1705 test_gdi_dbuf(hdc);
1706 test_acceleration(hdc);
1707
1708 wgl_extensions = pwglGetExtensionsStringARB(hdc);
1709 if(wgl_extensions == NULL) skip("Skipping opengl32 tests because this OpenGL implementation doesn't support WGL extensions!\n");
1710
1711 if(strstr(wgl_extensions, "WGL_ARB_create_context"))
1712 test_opengl3(hdc);
1713
1714 if(strstr(wgl_extensions, "WGL_ARB_make_current_read"))
1715 {
1716 test_make_current_read(hdc);
1717 test_destroy_read(hdc);
1718 }
1719 else
1720 skip("WGL_ARB_make_current_read not supported, skipping test\n");
1721
1722 if(strstr(wgl_extensions, "WGL_ARB_pbuffer"))
1723 test_pbuffers(hdc);
1724 else
1725 skip("WGL_ARB_pbuffer not supported, skipping pbuffer test\n");
1726
1727 if(strstr(wgl_extensions, "WGL_EXT_swap_control"))
1728 test_swap_control(hdc);
1729 else
1730 skip("WGL_EXT_swap_control not supported, skipping test\n");
1731
1732 cleanup:
1733 ReleaseDC(hwnd, hdc);
1734 DestroyWindow(hwnd);
1735 }
1736 }