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 /* GL_ARB_debug_output */
75 static void (WINAPI
*pglDebugMessageCallbackARB
)(void *, void *);
76 static void (WINAPI
*pglDebugMessageControlARB
)(GLenum
, GLenum
, GLenum
, GLsizei
, const GLuint
*, GLboolean
);
77 static void (WINAPI
*pglDebugMessageInsertARB
)(GLenum
, GLenum
, GLuint
, GLenum
, GLsizei
, const char *);
79 static const char* wgl_extensions
= NULL
;
81 static void init_functions(void)
83 #define GET_PROC(func) \
84 p ## func = (void*)wglGetProcAddress(#func); \
86 trace("wglGetProcAddress(%s) failed\n", #func);
88 /* WGL_ARB_create_context */
89 GET_PROC(wglCreateContextAttribsARB
);
91 /* WGL_ARB_extensions_string */
92 GET_PROC(wglGetExtensionsStringARB
)
94 /* WGL_ARB_make_current_read */
95 GET_PROC(wglMakeContextCurrentARB
);
96 GET_PROC(wglGetCurrentReadDCARB
);
98 /* WGL_ARB_pixel_format */
99 GET_PROC(wglChoosePixelFormatARB
)
100 GET_PROC(wglGetPixelFormatAttribivARB
)
102 /* WGL_ARB_pbuffer */
103 GET_PROC(wglCreatePbufferARB
)
104 GET_PROC(wglGetPbufferDCARB
)
105 GET_PROC(wglReleasePbufferDCARB
)
107 /* WGL_EXT_swap_control */
108 GET_PROC(wglSwapIntervalEXT
)
109 GET_PROC(wglGetSwapIntervalEXT
)
111 /* GL_ARB_debug_output */
112 GET_PROC(glDebugMessageCallbackARB
)
113 GET_PROC(glDebugMessageControlARB
)
114 GET_PROC(glDebugMessageInsertARB
)
119 static BOOL
gl_extension_supported(const char *extensions
, const char *extension_string
)
121 size_t ext_str_len
= strlen(extension_string
);
128 while (isspace(*extensions
))
131 while (!isspace(*extensions
) && *extensions
)
134 len
= extensions
- start
;
138 if (len
== ext_str_len
&& !memcmp(start
, extension_string
, ext_str_len
))
146 static void test_pbuffers(HDC hdc
)
148 const int iAttribList
[] = { WGL_DRAW_TO_PBUFFER_ARB
, 1, /* Request pbuffer support */
150 int iFormats
[MAX_FORMATS
];
151 unsigned int nOnscreenFormats
;
152 unsigned int nFormats
;
154 int iPixelFormat
= 0;
156 nOnscreenFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
158 /* When you want to render to a pbuffer you need to call wglGetPbufferDCARB which
159 * returns a 'magic' HDC which you can then pass to wglMakeCurrent to switch rendering
160 * to the pbuffer. Below some tests are performed on what happens if you use standard WGL calls
161 * on this 'magic' HDC for both a pixelformat that support onscreen and offscreen rendering
162 * and a pixelformat that's only available for offscreen rendering (this means that only
163 * wglChoosePixelFormatARB and friends know about the format.
165 * The first thing we need are pixelformats with pbuffer capabilities.
167 res
= pwglChoosePixelFormatARB(hdc
, iAttribList
, NULL
, MAX_FORMATS
, iFormats
, &nFormats
);
170 skip("No pbuffer compatible formats found while WGL_ARB_pbuffer is supported\n");
173 trace("nOnscreenFormats: %d\n", nOnscreenFormats
);
174 trace("Total number of pbuffer capable pixelformats: %d\n", nFormats
);
176 /* Try to select an onscreen pixelformat out of the list */
177 for(i
=0; i
< nFormats
; i
++)
179 /* Check if the format is onscreen, if it is choose it */
180 if(iFormats
[i
] <= nOnscreenFormats
)
182 iPixelFormat
= iFormats
[i
];
183 trace("Selected iPixelFormat=%d\n", iPixelFormat
);
188 /* A video driver supports a large number of onscreen and offscreen pixelformats.
189 * The traditional WGL calls only see a subset of the whole pixelformat list. First
190 * of all they only see the onscreen formats (the offscreen formats are at the end of the
191 * pixelformat list) and second extended pixelformat capabilities are hidden from the
192 * standard WGL calls. Only functions that depend on WGL_ARB_pixel_format can see them.
194 * Below we check if the pixelformat is also supported onscreen.
196 if(iPixelFormat
!= 0)
200 HPBUFFERARB pbuffer
= pwglCreatePbufferARB(hdc
, iPixelFormat
, 640 /* width */, 480 /* height */, &attrib
);
202 skip("Pbuffer creation failed!\n");
204 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
205 pbuffer_hdc
= pwglGetPbufferDCARB(pbuffer
);
206 res
= GetPixelFormat(pbuffer_hdc
);
207 ok(res
== iPixelFormat
, "Unexpected iPixelFormat=%d returned by GetPixelFormat for format %d\n", res
, iPixelFormat
);
208 trace("iPixelFormat returned by GetPixelFormat: %d\n", res
);
209 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat
);
211 pwglReleasePbufferDCARB(pbuffer
, pbuffer_hdc
);
213 else skip("Pbuffer test for onscreen pixelformat skipped as no onscreen format with pbuffer capabilities have been found\n");
215 /* Search for a real offscreen format */
216 for(i
=0, iPixelFormat
=0; i
<nFormats
; i
++)
218 if(iFormats
[i
] > nOnscreenFormats
)
220 iPixelFormat
= iFormats
[i
];
221 trace("Selected iPixelFormat: %d\n", iPixelFormat
);
226 if(iPixelFormat
!= 0)
229 HPBUFFERARB pbuffer
= pwglCreatePbufferARB(hdc
, iPixelFormat
, 640 /* width */, 480 /* height */, NULL
);
231 skip("Pbuffer creation failed!\n");
233 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
234 pbuffer_hdc
= pwglGetPbufferDCARB(pbuffer
);
235 res
= GetPixelFormat(pbuffer_hdc
);
237 ok(res
== 1, "Unexpected iPixelFormat=%d (1 expected) returned by GetPixelFormat for offscreen format %d\n", res
, iPixelFormat
);
238 trace("iPixelFormat returned by GetPixelFormat: %d\n", res
);
239 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat
);
240 pwglReleasePbufferDCARB(pbuffer
, hdc
);
242 else skip("Pbuffer test for offscreen pixelformat skipped as no offscreen-only format with pbuffer capabilities has been found\n");
245 static void WINAPI
gl_debug_message_callback(GLenum source
, GLenum type
, GLuint id
, GLenum severity
,
246 GLsizei length
, const GLchar
*message
, const void *userParam
)
248 DWORD
*count
= (DWORD
*)userParam
;
252 static void test_debug_message_callback(void)
254 static const char testmsg
[] = "Hello World";
257 if (!pglDebugMessageCallbackARB
)
259 skip("glDebugMessageCallbackARB not supported\n");
263 glEnable(GL_DEBUG_OUTPUT
);
264 glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS
);
266 pglDebugMessageCallbackARB(gl_debug_message_callback
, &count
);
267 pglDebugMessageControlARB(GL_DONT_CARE
, GL_DONT_CARE
, GL_DONT_CARE
, 0, NULL
, GL_TRUE
);
270 pglDebugMessageInsertARB(GL_DEBUG_SOURCE_APPLICATION
, GL_DEBUG_TYPE_OTHER
, 0x42424242,
271 GL_DEBUG_SEVERITY_LOW
, sizeof(testmsg
), testmsg
);
272 ok(count
== 1, "expected count == 1, got %u\n", count
);
274 glDisable(GL_DEBUG_OUTPUT_SYNCHRONOUS
);
275 glDisable(GL_DEBUG_OUTPUT
);
278 static void test_setpixelformat(HDC winhdc
)
285 PIXELFORMATDESCRIPTOR pfd
= {
286 sizeof(PIXELFORMATDESCRIPTOR
),
292 24, /* 24-bit color depth */
293 0, 0, 0, 0, 0, 0, /* color bits */
294 0, /* alpha buffer */
296 0, /* accumulation buffer */
297 0, 0, 0, 0, /* accum bits */
299 0, /* stencil buffer */
300 0, /* auxiliary buffer */
301 PFD_MAIN_PLANE
, /* main layer */
303 0, 0, 0 /* layer masks */
307 ok(hdc
!= 0, "GetDC(0) failed!\n");
309 /* This should pass even on the main device context */
310 pf
= ChoosePixelFormat(hdc
, &pfd
);
311 ok(pf
!= 0, "ChoosePixelFormat failed on main device context\n");
313 /* SetPixelFormat on the main device context 'X root window' should fail,
314 * but some broken drivers allow it
316 res
= SetPixelFormat(hdc
, pf
, &pfd
);
317 trace("SetPixelFormat on main device context %s\n", res
? "succeeded" : "failed");
319 /* Setting the same format that was set on the HDC is allowed; other
321 nCfgs
= DescribePixelFormat(winhdc
, 0, 0, NULL
);
322 pf
= GetPixelFormat(winhdc
);
323 for(i
= 1;i
<= nCfgs
;i
++)
325 int res
= SetPixelFormat(winhdc
, i
, NULL
);
326 if(i
== pf
) ok(res
, "Failed to set the same pixel format\n");
327 else ok(!res
, "Unexpectedly set an alternate pixel format\n");
330 hwnd
= CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW
, 10, 10, 200, 200, NULL
, NULL
,
332 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
335 HDC hdc
= GetDC( hwnd
);
336 pf
= ChoosePixelFormat( hdc
, &pfd
);
337 ok( pf
!= 0, "ChoosePixelFormat failed\n" );
338 res
= SetPixelFormat( hdc
, pf
, &pfd
);
339 ok( res
!= 0, "SetPixelFormat failed\n" );
340 i
= GetPixelFormat( hdc
);
341 ok( i
== pf
, "GetPixelFormat returned wrong format %d/%d\n", i
, pf
);
342 ReleaseDC( hwnd
, hdc
);
343 hdc
= GetWindowDC( hwnd
);
344 i
= GetPixelFormat( hdc
);
345 ok( i
== pf
, "GetPixelFormat returned wrong format %d/%d\n", i
, pf
);
346 ReleaseDC( hwnd
, hdc
);
347 DestroyWindow( hwnd
);
350 hwnd
= CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW
, 10, 10, 200, 200, NULL
, NULL
,
352 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
355 HDC hdc
= GetWindowDC( hwnd
);
356 pf
= ChoosePixelFormat( hdc
, &pfd
);
357 ok( pf
!= 0, "ChoosePixelFormat failed\n" );
358 res
= SetPixelFormat( hdc
, pf
, &pfd
);
359 ok( res
!= 0, "SetPixelFormat failed\n" );
360 i
= GetPixelFormat( hdc
);
361 ok( i
== pf
, "GetPixelFormat returned wrong format %d/%d\n", i
, pf
);
362 ReleaseDC( hwnd
, hdc
);
363 DestroyWindow( hwnd
);
367 static void test_sharelists(HDC winhdc
)
369 HGLRC hglrc1
, hglrc2
, hglrc3
;
372 hglrc1
= wglCreateContext(winhdc
);
373 res
= wglShareLists(0, 0);
374 ok(res
== FALSE
, "Sharing display lists for no contexts passed!\n");
376 /* Test 1: Create a context and just share lists without doing anything special */
377 hglrc2
= wglCreateContext(winhdc
);
380 res
= wglShareLists(hglrc1
, hglrc2
);
381 ok(res
, "Sharing of display lists failed\n");
382 wglDeleteContext(hglrc2
);
385 /* Test 2: Share display lists with a 'destination' context which has been made current */
386 hglrc2
= wglCreateContext(winhdc
);
389 res
= wglMakeCurrent(winhdc
, hglrc2
);
390 ok(res
, "Make current failed\n");
391 res
= wglShareLists(hglrc1
, hglrc2
);
392 ok(res
, "Sharing display lists with a destination context which has been made current failed\n");
393 wglMakeCurrent(0, 0);
394 wglDeleteContext(hglrc2
);
397 /* Test 3: Share display lists with a context which already shares display lists with another context.
398 * According to MSDN the second parameter cannot share any display lists but some buggy drivers might allow it */
399 hglrc3
= wglCreateContext(winhdc
);
402 res
= wglShareLists(hglrc3
, hglrc1
);
403 ok(res
== FALSE
, "Sharing of display lists passed for a context which already shared lists before\n");
404 wglDeleteContext(hglrc3
);
407 /* Test 4: Share display lists with a 'source' context which has been made current */
408 hglrc2
= wglCreateContext(winhdc
);
411 res
= wglMakeCurrent(winhdc
, hglrc1
);
412 ok(res
, "Make current failed\n");
413 res
= wglShareLists(hglrc1
, hglrc2
);
414 ok(res
, "Sharing display lists with a source context which has been made current failed\n");
415 wglMakeCurrent(0, 0);
416 wglDeleteContext(hglrc2
);
420 static void test_makecurrent(HDC winhdc
)
425 hglrc
= wglCreateContext(winhdc
);
426 ok( hglrc
!= 0, "wglCreateContext failed\n" );
428 ret
= wglMakeCurrent( winhdc
, hglrc
);
429 ok( ret
, "wglMakeCurrent failed\n" );
431 ok( wglGetCurrentContext() == hglrc
, "wrong context\n" );
433 /* set the same context again */
434 ret
= wglMakeCurrent( winhdc
, hglrc
);
435 ok( ret
, "wglMakeCurrent failed\n" );
437 /* check wglMakeCurrent(x, y) after another call to wglMakeCurrent(x, y) */
438 ret
= wglMakeCurrent( winhdc
, NULL
);
439 ok( ret
, "wglMakeCurrent failed\n" );
441 ret
= wglMakeCurrent( winhdc
, NULL
);
442 ok( ret
, "wglMakeCurrent failed\n" );
444 SetLastError( 0xdeadbeef );
445 ret
= wglMakeCurrent( NULL
, NULL
);
446 ok( !ret
|| broken(ret
) /* nt4 */, "wglMakeCurrent succeeded\n" );
447 if (!ret
) ok( GetLastError() == ERROR_INVALID_HANDLE
,
448 "Expected ERROR_INVALID_HANDLE, got error=%x\n", GetLastError() );
450 ret
= wglMakeCurrent( winhdc
, NULL
);
451 ok( ret
, "wglMakeCurrent failed\n" );
453 ret
= wglMakeCurrent( winhdc
, hglrc
);
454 ok( ret
, "wglMakeCurrent failed\n" );
456 ret
= wglMakeCurrent( NULL
, NULL
);
457 ok( ret
, "wglMakeCurrent failed\n" );
459 ok( wglGetCurrentContext() == NULL
, "wrong context\n" );
461 SetLastError( 0xdeadbeef );
462 ret
= wglMakeCurrent( NULL
, NULL
);
463 ok( !ret
|| broken(ret
) /* nt4 */, "wglMakeCurrent succeeded\n" );
464 if (!ret
) ok( GetLastError() == ERROR_INVALID_HANDLE
,
465 "Expected ERROR_INVALID_HANDLE, got error=%x\n", GetLastError() );
467 ret
= wglMakeCurrent( winhdc
, hglrc
);
468 ok( ret
, "wglMakeCurrent failed\n" );
471 static void test_colorbits(HDC hdc
)
473 const int iAttribList
[] = { WGL_COLOR_BITS_ARB
, WGL_RED_BITS_ARB
, WGL_GREEN_BITS_ARB
,
474 WGL_BLUE_BITS_ARB
, WGL_ALPHA_BITS_ARB
};
475 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
476 const int iAttribs
[] = { WGL_ALPHA_BITS_ARB
, 1, 0 };
477 unsigned int nFormats
;
479 int iPixelFormat
= 0;
481 if (!pwglChoosePixelFormatARB
)
483 win_skip("wglChoosePixelFormatARB is not available\n");
487 /* We need a pixel format with at least one bit of alpha */
488 res
= pwglChoosePixelFormatARB(hdc
, iAttribs
, NULL
, 1, &iPixelFormat
, &nFormats
);
489 if(res
== FALSE
|| nFormats
== 0)
491 skip("No suitable pixel formats found\n");
495 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
496 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
, iAttribRet
);
499 skip("wglGetPixelFormatAttribivARB failed\n");
502 iAttribRet
[1] += iAttribRet
[2]+iAttribRet
[3]+iAttribRet
[4];
503 ok(iAttribRet
[0] == iAttribRet
[1], "WGL_COLOR_BITS_ARB (%d) does not equal R+G+B+A (%d)!\n",
504 iAttribRet
[0], iAttribRet
[1]);
507 static void test_gdi_dbuf(HDC hdc
)
509 const int iAttribList
[] = { WGL_SUPPORT_GDI_ARB
, WGL_DOUBLE_BUFFER_ARB
};
510 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
511 unsigned int nFormats
;
515 if (!pwglGetPixelFormatAttribivARB
)
517 win_skip("wglGetPixelFormatAttribivARB is not available\n");
521 nFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
522 for(iPixelFormat
= 1;iPixelFormat
<= nFormats
;iPixelFormat
++)
524 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
525 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
,
527 ok(res
!=FALSE
, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat
);
531 ok(!(iAttribRet
[0] && iAttribRet
[1]), "GDI support and double buffering on pixel format %d\n", iPixelFormat
);
535 static void test_acceleration(HDC hdc
)
537 const int iAttribList
[] = { WGL_ACCELERATION_ARB
};
538 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
539 unsigned int nFormats
;
542 PIXELFORMATDESCRIPTOR pfd
;
544 if (!pwglGetPixelFormatAttribivARB
)
546 win_skip("wglGetPixelFormatAttribivARB is not available\n");
550 nFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
551 for(iPixelFormat
= 1; iPixelFormat
<= nFormats
; iPixelFormat
++)
553 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
554 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
,
556 ok(res
!=FALSE
, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat
);
560 memset(&pfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
561 DescribePixelFormat(hdc
, iPixelFormat
, sizeof(PIXELFORMATDESCRIPTOR
), &pfd
);
563 switch(iAttribRet
[0])
565 case WGL_NO_ACCELERATION_ARB
:
566 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
);
568 case WGL_GENERIC_ACCELERATION_ARB
:
569 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
);
571 case WGL_FULL_ACCELERATION_ARB
:
572 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
);
578 static void test_bitmap_rendering( BOOL use_dib
)
580 PIXELFORMATDESCRIPTOR pfd
;
581 int i
, ret
, bpp
, iPixelFormat
=0;
582 unsigned int nFormats
;
585 HBITMAP bmpDst
, oldDst
, bmp2
;
586 HDC hdcDst
, hdcScreen
;
587 UINT
*dstBuffer
= NULL
;
589 hdcScreen
= CreateCompatibleDC(0);
590 hdcDst
= CreateCompatibleDC(0);
595 memset(&biDst
, 0, sizeof(BITMAPINFO
));
596 biDst
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
597 biDst
.bmiHeader
.biWidth
= 4;
598 biDst
.bmiHeader
.biHeight
= -4;
599 biDst
.bmiHeader
.biPlanes
= 1;
600 biDst
.bmiHeader
.biBitCount
= 32;
601 biDst
.bmiHeader
.biCompression
= BI_RGB
;
603 bmpDst
= CreateDIBSection(0, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
, NULL
, 0);
605 biDst
.bmiHeader
.biWidth
= 12;
606 biDst
.bmiHeader
.biHeight
= -12;
607 biDst
.bmiHeader
.biBitCount
= 16;
608 bmp2
= CreateDIBSection(0, &biDst
, DIB_RGB_COLORS
, NULL
, NULL
, 0);
612 bpp
= GetDeviceCaps( hdcScreen
, BITSPIXEL
);
613 bmpDst
= CreateBitmap( 4, 4, 1, bpp
, NULL
);
614 bmp2
= CreateBitmap( 12, 12, 1, bpp
, NULL
);
617 oldDst
= SelectObject(hdcDst
, bmpDst
);
619 trace( "testing on %s\n", use_dib
? "DIB" : "DDB" );
621 /* Pick a pixel format by hand because ChoosePixelFormat is unreliable */
622 nFormats
= DescribePixelFormat(hdcDst
, 0, 0, NULL
);
623 for(i
=1; i
<=nFormats
; i
++)
625 memset(&pfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
626 DescribePixelFormat(hdcDst
, i
, sizeof(PIXELFORMATDESCRIPTOR
), &pfd
);
628 if((pfd
.dwFlags
& PFD_DRAW_TO_BITMAP
) &&
629 (pfd
.dwFlags
& PFD_SUPPORT_OPENGL
) &&
630 (pfd
.cColorBits
== bpp
) &&
631 (pfd
.cAlphaBits
== 8) )
640 skip("Unable to find a suitable pixel format\n");
644 ret
= SetPixelFormat(hdcDst
, iPixelFormat
, &pfd
);
645 ok( ret
, "SetPixelFormat failed\n" );
646 ret
= GetPixelFormat( hdcDst
);
647 ok( ret
== iPixelFormat
, "GetPixelFormat returned %d/%d\n", ret
, iPixelFormat
);
648 ret
= SetPixelFormat(hdcDst
, iPixelFormat
+ 1, &pfd
);
649 ok( !ret
, "SetPixelFormat succeeded\n" );
650 hglrc
= wglCreateContext(hdcDst
);
651 ok(hglrc
!= NULL
, "Unable to create a context\n");
656 wglMakeCurrent(hdcDst
, hglrc
);
657 hglrc2
= wglCreateContext(hdcDst
);
658 ok(hglrc2
!= NULL
, "Unable to create a context\n");
660 /* Note this is RGBA but we read ARGB back */
661 glClearColor((float)0x22/0xff, (float)0x33/0xff, (float)0x44/0xff, (float)0x11/0xff);
662 glClear(GL_COLOR_BUFFER_BIT
);
663 glGetIntegerv( GL_VIEWPORT
, viewport
);
666 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 4 && viewport
[3] == 4,
667 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
668 /* Note apparently the alpha channel is not supported by the software renderer (bitmap only works using software) */
670 for (i
= 0; i
< 16; i
++)
671 ok(dstBuffer
[i
] == 0x223344 || dstBuffer
[i
] == 0x11223344, "Received color=%x at %u\n",
674 SelectObject(hdcDst
, bmp2
);
675 ret
= GetPixelFormat( hdcDst
);
676 ok( ret
== iPixelFormat
, "GetPixelFormat returned %d/%d\n", ret
, iPixelFormat
);
677 ret
= SetPixelFormat(hdcDst
, iPixelFormat
+ 1, &pfd
);
678 ok( !ret
, "SetPixelFormat succeeded\n" );
680 /* context still uses the old pixel format and viewport */
681 glClearColor((float)0x44/0xff, (float)0x33/0xff, (float)0x22/0xff, (float)0x11/0xff);
682 glClear(GL_COLOR_BUFFER_BIT
);
684 glGetIntegerv( GL_VIEWPORT
, viewport
);
685 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 4 && viewport
[3] == 4,
686 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
688 wglMakeCurrent(NULL
, NULL
);
689 wglMakeCurrent(hdcDst
, hglrc
);
690 glClearColor((float)0x44/0xff, (float)0x55/0xff, (float)0x66/0xff, (float)0x11/0xff);
691 glClear(GL_COLOR_BUFFER_BIT
);
693 glGetIntegerv( GL_VIEWPORT
, viewport
);
694 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 4 && viewport
[3] == 4,
695 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
697 wglMakeCurrent(hdcDst
, hglrc2
);
698 glGetIntegerv( GL_VIEWPORT
, viewport
);
699 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 12 && viewport
[3] == 12,
700 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
702 wglMakeCurrent(hdcDst
, hglrc
);
703 glGetIntegerv( GL_VIEWPORT
, viewport
);
704 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 4 && viewport
[3] == 4,
705 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
707 SelectObject(hdcDst
, bmpDst
);
708 ret
= GetPixelFormat( hdcDst
);
709 ok( ret
== iPixelFormat
, "GetPixelFormat returned %d/%d\n", ret
, iPixelFormat
);
710 ret
= SetPixelFormat(hdcDst
, iPixelFormat
+ 1, &pfd
);
711 ok( !ret
, "SetPixelFormat succeeded\n" );
712 wglMakeCurrent(hdcDst
, hglrc2
);
713 glGetIntegerv( GL_VIEWPORT
, viewport
);
714 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 12 && viewport
[3] == 12,
715 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
719 SelectObject(hdcDst
, oldDst
);
721 DeleteObject(bmpDst
);
726 struct wgl_thread_param
728 HANDLE test_finished
;
732 BOOL make_current_error
;
737 static DWORD WINAPI
wgl_thread(void *param
)
739 struct wgl_thread_param
*p
= param
;
740 HDC hdc
= GetDC( p
->hwnd
);
742 ok(!glGetString(GL_RENDERER
) && !glGetString(GL_VERSION
) && !glGetString(GL_VENDOR
),
743 "Expected NULL string when no active context is set\n");
745 SetLastError(0xdeadbeef);
746 p
->make_current
= wglMakeCurrent(hdc
, p
->hglrc
);
747 p
->make_current_error
= GetLastError();
748 p
->deleted
= wglDeleteContext(p
->hglrc
);
749 p
->deleted_error
= GetLastError();
750 ReleaseDC( p
->hwnd
, hdc
);
751 SetEvent(p
->test_finished
);
755 static void test_deletecontext(HWND hwnd
, HDC hdc
)
757 struct wgl_thread_param thread_params
;
758 HGLRC hglrc
= wglCreateContext(hdc
);
759 HANDLE thread_handle
;
763 SetLastError(0xdeadbeef);
764 res
= wglDeleteContext(NULL
);
765 ok(res
== FALSE
, "wglDeleteContext succeeded\n");
766 ok(GetLastError() == ERROR_INVALID_HANDLE
, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
770 skip("wglCreateContext failed!\n");
774 res
= wglMakeCurrent(hdc
, hglrc
);
777 skip("wglMakeCurrent failed!\n");
781 /* WGL doesn't allow you to delete a context from a different thread than the one in which it is current.
782 * This differs from GLX which does allow it but it delays actual deletion until the context becomes not current.
784 thread_params
.hglrc
= hglrc
;
785 thread_params
.hwnd
= hwnd
;
786 thread_params
.test_finished
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
787 thread_handle
= CreateThread(NULL
, 0, wgl_thread
, &thread_params
, 0, &tid
);
788 ok(!!thread_handle
, "Failed to create thread, last error %#x.\n", GetLastError());
791 WaitForSingleObject(thread_handle
, INFINITE
);
792 ok(!thread_params
.make_current
, "Attempt to make WGL context from another thread passed\n");
793 ok(thread_params
.make_current_error
== ERROR_BUSY
, "Expected last error to be ERROR_BUSY, got %u\n", thread_params
.make_current_error
);
794 ok(!thread_params
.deleted
, "Attempt to delete WGL context from another thread passed\n");
795 ok(thread_params
.deleted_error
== ERROR_BUSY
, "Expected last error to be ERROR_BUSY, got %u\n", thread_params
.deleted_error
);
797 CloseHandle(thread_params
.test_finished
);
799 res
= wglDeleteContext(hglrc
);
800 ok(res
== TRUE
, "wglDeleteContext failed\n");
802 /* Attempting to delete the same context twice should fail. */
803 SetLastError(0xdeadbeef);
804 res
= wglDeleteContext(hglrc
);
805 ok(res
== FALSE
, "wglDeleteContext succeeded\n");
806 ok(GetLastError() == ERROR_INVALID_HANDLE
, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
808 /* WGL makes a context not current when deleting it. This differs from GLX behavior where
809 * deletion takes place when the thread becomes not current. */
810 hglrc
= wglGetCurrentContext();
811 ok(hglrc
== NULL
, "A WGL context is active while none was expected\n");
815 static void test_getprocaddress(HDC hdc
)
817 const char *extensions
= (const char*)glGetString(GL_EXTENSIONS
);
819 HGLRC ctx
= wglGetCurrentContext();
823 skip("skipping wglGetProcAddress tests because no GL extensions supported\n");
827 /* Core GL 1.0/1.1 functions should not be loadable through wglGetProcAddress.
828 * Try to load the function with and without a context.
830 func
= wglGetProcAddress("glEnable");
831 ok(func
== NULL
, "Lookup of function glEnable with a context passed, expected a failure\n");
832 wglMakeCurrent(hdc
, NULL
);
833 func
= wglGetProcAddress("glEnable");
834 ok(func
== NULL
, "Lookup of function glEnable without a context passed, expected a failure\n");
835 wglMakeCurrent(hdc
, ctx
);
837 /* The goal of the test will be to test behavior of wglGetProcAddress when
838 * no WGL context is active. Before the test we pick an extension (GL_ARB_multitexture)
839 * which any GL >=1.2.1 implementation supports. Unfortunately the GDI renderer doesn't
840 * support it. There aren't any extensions we can use for this test which are supported by
841 * both GDI and real drivers.
842 * Note GDI only has GL_EXT_bgra, GL_EXT_paletted_texture and GL_WIN_swap_hint.
844 if (!gl_extension_supported(extensions
, "GL_ARB_multitexture"))
846 skip("skipping test because lack of GL_ARB_multitexture support\n");
850 func
= wglGetProcAddress("glActiveTextureARB");
851 ok(func
!= NULL
, "Unable to lookup glActiveTextureARB, last error %#x\n", GetLastError());
853 /* Temporarily disable the context, so we can see that we can't retrieve functions now. */
854 wglMakeCurrent(hdc
, NULL
);
855 func
= wglGetProcAddress("glActiveTextureARB");
856 ok(func
== NULL
, "Function lookup without a context passed, expected a failure; last error %#x\n", GetLastError());
857 wglMakeCurrent(hdc
, ctx
);
860 static void test_make_current_read(HDC hdc
)
864 HGLRC hglrc
= wglCreateContext(hdc
);
868 skip("wglCreateContext failed!\n");
872 res
= wglMakeCurrent(hdc
, hglrc
);
875 skip("wglMakeCurrent failed!\n");
879 /* Test what wglGetCurrentReadDCARB does for wglMakeCurrent as the spec doesn't mention it */
880 hread
= pwglGetCurrentReadDCARB();
881 trace("hread %p, hdc %p\n", hread
, hdc
);
882 ok(hread
== hdc
, "wglGetCurrentReadDCARB failed for standard wglMakeCurrent\n");
884 pwglMakeContextCurrentARB(hdc
, hdc
, hglrc
);
885 hread
= pwglGetCurrentReadDCARB();
886 ok(hread
== hdc
, "wglGetCurrentReadDCARB failed for wglMakeContextCurrent\n");
889 static void test_dc(HWND hwnd
, HDC hdc
)
894 /* Get another DC and make sure it has the same pixel format */
898 pf1
= GetPixelFormat(hdc
);
899 pf2
= GetPixelFormat(hdc2
);
900 ok(pf1
== pf2
, "Second DC does not have the same format (%d != %d)\n", pf1
, pf2
);
903 skip("Could not get a different DC for the window\n");
907 ReleaseDC(hwnd
, hdc2
);
912 /* Nvidia converts win32 error codes to (0xc007 << 16) | win32_error_code */
913 #define NVIDIA_HRESULT_FROM_WIN32(x) (HRESULT_FROM_WIN32(x) | 0x40000000)
914 static void test_opengl3(HDC hdc
)
916 /* Try to create a context compatible with OpenGL 1.x; 1.0-2.1 is allowed */
919 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 1, 0};
921 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
922 ok(gl3Ctx
!= 0, "pwglCreateContextAttribsARB for a 1.x context failed!\n");
923 wglDeleteContext(gl3Ctx
);
926 /* Try to pass an invalid HDC */
930 gl3Ctx
= pwglCreateContextAttribsARB((HDC
)0xdeadbeef, 0, 0);
931 ok(gl3Ctx
== 0, "pwglCreateContextAttribsARB using an invalid HDC passed\n");
932 error
= GetLastError();
933 todo_wine
ok(error
== ERROR_DC_NOT_FOUND
||
934 broken(error
== NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_DATA
)), /* Nvidia Vista + Win7 */
935 "Expected ERROR_DC_NOT_FOUND, got error=%x\n", error
);
936 wglDeleteContext(gl3Ctx
);
939 /* Try to pass an invalid shareList */
943 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, (HGLRC
)0xdeadbeef, 0);
944 ok(gl3Ctx
== 0, "pwglCreateContextAttribsARB using an invalid shareList passed\n");
945 error
= GetLastError();
946 /* The Nvidia implementation seems to return hresults instead of win32 error codes */
947 todo_wine
ok(error
== ERROR_INVALID_OPERATION
||
948 error
== NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_OPERATION
), "Expected ERROR_INVALID_OPERATION, got error=%x\n", error
);
949 wglDeleteContext(gl3Ctx
);
952 /* Try to create an OpenGL 3.0 context */
954 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
955 HGLRC gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
959 skip("Skipping the rest of the WGL_ARB_create_context test due to lack of OpenGL 3.0\n");
963 wglDeleteContext(gl3Ctx
);
966 /* 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 */
968 HGLRC glCtx
= wglCreateContext(hdc
);
970 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
971 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};
973 HGLRC gl3Ctx
= pwglCreateContextAttribsARB(hdc
, glCtx
, attribs
);
974 ok(gl3Ctx
!= NULL
, "Sharing of a display list between OpenGL 3.0 and OpenGL 1.x/2.x failed!\n");
976 wglDeleteContext(gl3Ctx
);
978 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, glCtx
, attribs_future
);
979 ok(gl3Ctx
!= NULL
, "Sharing of a display list between a forward compatible OpenGL 3.0 context and OpenGL 1.x/2.x failed!\n");
981 wglDeleteContext(gl3Ctx
);
984 wglDeleteContext(glCtx
);
987 /* Try to create an OpenGL 3.0 context and test windowless rendering */
990 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
993 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
994 ok(gl3Ctx
!= 0, "pwglCreateContextAttribsARB for a 3.0 context failed!\n");
996 /* OpenGL 3.0 allows offscreen rendering WITHOUT a drawable
997 * Neither AMD or Nvidia support it at this point. The WGL_ARB_create_context specs also say that
998 * it is hard because drivers use the HDC to enter the display driver and it sounds like they don't
999 * expect drivers to ever offer it.
1001 res
= wglMakeCurrent(0, gl3Ctx
);
1002 ok(res
== FALSE
, "Wow, OpenGL 3.0 windowless rendering passed while it was expected not to!\n");
1004 wglMakeCurrent(0, 0);
1007 wglDeleteContext(gl3Ctx
);
1011 static void test_minimized(void)
1013 PIXELFORMATDESCRIPTOR pf_desc
=
1015 sizeof(PIXELFORMATDESCRIPTOR
),
1017 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1019 24, /* 24-bit color depth */
1020 0, 0, 0, 0, 0, 0, /* color bits */
1021 0, /* alpha buffer */
1023 0, /* accumulation buffer */
1024 0, 0, 0, 0, /* accum bits */
1026 0, /* stencil buffer */
1027 0, /* auxiliary buffer */
1028 PFD_MAIN_PLANE
, /* main layer */
1030 0, 0, 0 /* layer masks */
1039 window
= CreateWindowA("static", "opengl32_test",
1040 WS_POPUP
| WS_MINIMIZE
, 0, 0, 640, 480, 0, 0, 0, 0);
1041 ok(!!window
, "Failed to create window, last error %#x.\n", GetLastError());
1044 ok(!!dc
, "Failed to get DC.\n");
1046 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1049 win_skip("Failed to find pixel format.\n");
1050 ReleaseDC(window
, dc
);
1051 DestroyWindow(window
);
1055 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1056 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1058 style
= GetWindowLongA(window
, GWL_STYLE
);
1059 ok(style
& WS_MINIMIZE
, "Window should be minimized, got style %#x.\n", style
);
1061 ctx
= wglCreateContext(dc
);
1062 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1064 ret
= wglMakeCurrent(dc
, ctx
);
1065 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1067 style
= GetWindowLongA(window
, GWL_STYLE
);
1068 ok(style
& WS_MINIMIZE
, "window should be minimized, got style %#x.\n", style
);
1070 ret
= wglMakeCurrent(NULL
, NULL
);
1071 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1073 ret
= wglDeleteContext(ctx
);
1074 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1076 ReleaseDC(window
, dc
);
1077 DestroyWindow(window
);
1080 static void test_window_dc(void)
1082 PIXELFORMATDESCRIPTOR pf_desc
=
1084 sizeof(PIXELFORMATDESCRIPTOR
),
1086 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1088 24, /* 24-bit color depth */
1089 0, 0, 0, 0, 0, 0, /* color bits */
1090 0, /* alpha buffer */
1092 0, /* accumulation buffer */
1093 0, 0, 0, 0, /* accum bits */
1095 0, /* stencil buffer */
1096 0, /* auxiliary buffer */
1097 PFD_MAIN_PLANE
, /* main layer */
1099 0, 0, 0 /* layer masks */
1108 window
= CreateWindowA("static", "opengl32_test",
1109 WS_OVERLAPPEDWINDOW
, 0, 0, 640, 480, 0, 0, 0, 0);
1110 ok(!!window
, "Failed to create window, last error %#x.\n", GetLastError());
1112 ShowWindow(window
, SW_SHOW
);
1114 dc
= GetWindowDC(window
);
1115 ok(!!dc
, "Failed to get DC.\n");
1117 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1120 win_skip("Failed to find pixel format.\n");
1121 ReleaseDC(window
, dc
);
1122 DestroyWindow(window
);
1126 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1127 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1129 ctx
= wglCreateContext(dc
);
1130 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1132 ret
= wglMakeCurrent(dc
, ctx
);
1133 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1135 GetClientRect(window
, &r
);
1136 glGetIntegerv(GL_VIEWPORT
, (GLint
*)&vp
);
1137 ok(EqualRect(&r
, &vp
), "Viewport not equal to client rect.\n");
1139 ret
= wglMakeCurrent(NULL
, NULL
);
1140 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1142 ret
= wglDeleteContext(ctx
);
1143 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1145 ReleaseDC(window
, dc
);
1146 DestroyWindow(window
);
1149 static void test_message_window(void)
1151 PIXELFORMATDESCRIPTOR pf_desc
=
1153 sizeof(PIXELFORMATDESCRIPTOR
),
1155 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1157 24, /* 24-bit color depth */
1158 0, 0, 0, 0, 0, 0, /* color bits */
1159 0, /* alpha buffer */
1161 0, /* accumulation buffer */
1162 0, 0, 0, 0, /* accum bits */
1164 0, /* stencil buffer */
1165 0, /* auxiliary buffer */
1166 PFD_MAIN_PLANE
, /* main layer */
1168 0, 0, 0 /* layer masks */
1178 window
= CreateWindowA("static", "opengl32_test",
1179 WS_OVERLAPPEDWINDOW
, 0, 0, 100, 100, HWND_MESSAGE
, 0, 0, 0);
1182 win_skip( "HWND_MESSAGE not supported\n" );
1186 ok(!!dc
, "Failed to get DC.\n");
1188 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1191 win_skip("Failed to find pixel format.\n");
1192 ReleaseDC(window
, dc
);
1193 DestroyWindow(window
);
1197 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1198 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1200 ctx
= wglCreateContext(dc
);
1201 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1203 ret
= wglMakeCurrent(dc
, ctx
);
1204 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1206 GetClientRect(window
, &r
);
1207 glGetIntegerv(GL_VIEWPORT
, (GLint
*)&vp
);
1208 ok(EqualRect(&r
, &vp
), "Viewport not equal to client rect.\n");
1210 glClear(GL_COLOR_BUFFER_BIT
);
1212 glerr
= glGetError();
1213 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1214 ret
= SwapBuffers(dc
);
1215 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1217 ret
= wglMakeCurrent(NULL
, NULL
);
1218 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1220 ret
= wglDeleteContext(ctx
);
1221 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1223 ReleaseDC(window
, dc
);
1224 DestroyWindow(window
);
1227 static void test_destroy(HDC oldhdc
)
1229 PIXELFORMATDESCRIPTOR pf_desc
=
1231 sizeof(PIXELFORMATDESCRIPTOR
),
1233 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1235 24, /* 24-bit color depth */
1236 0, 0, 0, 0, 0, 0, /* color bits */
1237 0, /* alpha buffer */
1239 0, /* accumulation buffer */
1240 0, 0, 0, 0, /* accum bits */
1242 0, /* stencil buffer */
1243 0, /* auxiliary buffer */
1244 PFD_MAIN_PLANE
, /* main layer */
1246 0, 0, 0 /* layer masks */
1255 HGLRC oldctx
= wglGetCurrentContext();
1257 ok(!!oldctx
, "Expected to find a valid current context.\n");
1259 window
= CreateWindowA("static", "opengl32_test",
1260 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1261 ok(!!window
, "Failed to create window, last error %#x.\n", GetLastError());
1264 ok(!!dc
, "Failed to get DC.\n");
1266 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1269 win_skip("Failed to find pixel format.\n");
1270 ReleaseDC(window
, dc
);
1271 DestroyWindow(window
);
1275 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1276 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1278 ctx
= wglCreateContext(dc
);
1279 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1281 ret
= wglMakeCurrent(dc
, ctx
);
1282 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1284 glClear(GL_COLOR_BUFFER_BIT
);
1286 glerr
= glGetError();
1287 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1288 ret
= SwapBuffers(dc
);
1289 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1291 ret
= DestroyWindow(window
);
1292 ok(ret
, "Failed to destroy window, last error %#x.\n", GetLastError());
1294 ok(wglGetCurrentContext() == ctx
, "Wrong current context.\n");
1296 SetLastError(0xdeadbeef);
1297 ret
= wglMakeCurrent(dc
, ctx
);
1298 err
= GetLastError();
1299 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1300 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1301 SetLastError(0xdeadbeef);
1302 ret
= SwapBuffers(dc
);
1303 err
= GetLastError();
1304 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1306 ok(wglGetCurrentContext() == ctx
, "Wrong current context.\n");
1308 glClear(GL_COLOR_BUFFER_BIT
);
1310 glerr
= glGetError();
1311 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1312 SetLastError(0xdeadbeef);
1313 ret
= SwapBuffers(dc
);
1314 err
= GetLastError();
1315 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1317 ret
= wglMakeCurrent(NULL
, NULL
);
1318 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1320 glClear(GL_COLOR_BUFFER_BIT
);
1322 glerr
= glGetError();
1323 ok(glerr
== GL_INVALID_OPERATION
, "Failed glClear, error %#x.\n", glerr
);
1324 SetLastError(0xdeadbeef);
1325 ret
= SwapBuffers(dc
);
1326 err
= GetLastError();
1327 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1329 SetLastError(0xdeadbeef);
1330 ret
= wglMakeCurrent(dc
, ctx
);
1331 err
= GetLastError();
1332 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1333 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1335 ok(wglGetCurrentContext() == NULL
, "Wrong current context.\n");
1337 ret
= wglMakeCurrent(oldhdc
, oldctx
);
1338 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1339 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1341 SetLastError(0xdeadbeef);
1342 ret
= wglMakeCurrent(dc
, ctx
);
1343 err
= GetLastError();
1344 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1345 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1347 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1349 ret
= wglDeleteContext(ctx
);
1350 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1352 ReleaseDC(window
, dc
);
1354 ret
= wglMakeCurrent(oldhdc
, oldctx
);
1355 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1358 static void test_destroy_read(HDC oldhdc
)
1360 PIXELFORMATDESCRIPTOR pf_desc
=
1362 sizeof(PIXELFORMATDESCRIPTOR
),
1364 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1366 24, /* 24-bit color depth */
1367 0, 0, 0, 0, 0, 0, /* color bits */
1368 0, /* alpha buffer */
1370 0, /* accumulation buffer */
1371 0, 0, 0, 0, /* accum bits */
1373 0, /* stencil buffer */
1374 0, /* auxiliary buffer */
1375 PFD_MAIN_PLANE
, /* main layer */
1377 0, 0, 0 /* layer masks */
1380 HWND draw_window
, read_window
;
1383 HDC read_dc
, draw_dc
;
1386 HGLRC oldctx
= wglGetCurrentContext();
1388 ok(!!oldctx
, "Expected to find a valid current context\n");
1390 draw_window
= CreateWindowA("static", "opengl32_test",
1391 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1392 ok(!!draw_window
, "Failed to create window, last error %#x.\n", GetLastError());
1394 draw_dc
= GetDC(draw_window
);
1395 ok(!!draw_dc
, "Failed to get DC.\n");
1397 pixel_format
= ChoosePixelFormat(draw_dc
, &pf_desc
);
1400 win_skip("Failed to find pixel format.\n");
1401 ReleaseDC(draw_window
, draw_dc
);
1402 DestroyWindow(draw_window
);
1406 ret
= SetPixelFormat(draw_dc
, pixel_format
, &pf_desc
);
1407 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1409 read_window
= CreateWindowA("static", "opengl32_test",
1410 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1411 ok(!!read_window
, "Failed to create window, last error %#x.\n", GetLastError());
1413 read_dc
= GetDC(read_window
);
1414 ok(!!draw_dc
, "Failed to get DC.\n");
1416 pixel_format
= ChoosePixelFormat(read_dc
, &pf_desc
);
1419 win_skip("Failed to find pixel format.\n");
1420 ReleaseDC(read_window
, read_dc
);
1421 DestroyWindow(read_window
);
1422 ReleaseDC(draw_window
, draw_dc
);
1423 DestroyWindow(draw_window
);
1427 ret
= SetPixelFormat(read_dc
, pixel_format
, &pf_desc
);
1428 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1430 ctx
= wglCreateContext(draw_dc
);
1431 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1433 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1434 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1436 glCopyPixels(0, 0, 640, 480, GL_COLOR
);
1438 glerr
= glGetError();
1439 ok(glerr
== GL_NO_ERROR
, "Failed glCopyPixel, error %#x.\n", glerr
);
1440 ret
= SwapBuffers(draw_dc
);
1441 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1443 ret
= DestroyWindow(read_window
);
1444 ok(ret
, "Failed to destroy window, last error %#x.\n", GetLastError());
1446 ok(wglGetCurrentContext() == ctx
, "Wrong current context.\n");
1448 if (0) /* Crashes on AMD on Windows */
1450 glCopyPixels(0, 0, 640, 480, GL_COLOR
);
1452 glerr
= glGetError();
1453 ok(glerr
== GL_NO_ERROR
, "Failed glCopyPixel, error %#x.\n", glerr
);
1456 glClear(GL_COLOR_BUFFER_BIT
);
1458 glerr
= glGetError();
1459 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1460 ret
= SwapBuffers(draw_dc
);
1461 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1463 ret
= wglMakeCurrent(NULL
, NULL
);
1464 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1466 if (0) /* This crashes with Nvidia drivers on Windows. */
1468 SetLastError(0xdeadbeef);
1469 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1470 err
= GetLastError();
1471 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1472 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1475 ret
= DestroyWindow(draw_window
);
1476 ok(ret
, "Failed to destroy window, last error %#x.\n", GetLastError());
1478 glClear(GL_COLOR_BUFFER_BIT
);
1480 glerr
= glGetError();
1481 ok(glerr
== GL_INVALID_OPERATION
, "Failed glClear, error %#x.\n", glerr
);
1482 SetLastError(0xdeadbeef);
1483 ret
= SwapBuffers(draw_dc
);
1484 err
= GetLastError();
1485 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1487 SetLastError(0xdeadbeef);
1488 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1489 err
= GetLastError();
1490 ok(!ret
&& (err
== ERROR_INVALID_HANDLE
|| err
== 0xc0070006),
1491 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1493 ok(wglGetCurrentContext() == NULL
, "Wrong current context.\n");
1495 wglMakeCurrent(NULL
, NULL
);
1497 wglMakeCurrent(oldhdc
, oldctx
);
1498 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1500 SetLastError(0xdeadbeef);
1501 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1502 err
= GetLastError();
1503 ok(!ret
&& (err
== ERROR_INVALID_HANDLE
|| err
== 0xc0070006),
1504 "Unexpected behavior when making context current, last error %#x.\n", err
);
1506 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1508 ret
= wglDeleteContext(ctx
);
1509 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1511 ReleaseDC(read_window
, read_dc
);
1512 ReleaseDC(draw_window
, draw_dc
);
1514 wglMakeCurrent(oldhdc
, oldctx
);
1517 static void test_swap_control(HDC oldhdc
)
1519 PIXELFORMATDESCRIPTOR pf_desc
=
1521 sizeof(PIXELFORMATDESCRIPTOR
),
1523 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1525 24, /* 24-bit color depth */
1526 0, 0, 0, 0, 0, 0, /* color bits */
1527 0, /* alpha buffer */
1529 0, /* accumulation buffer */
1530 0, 0, 0, 0, /* accum bits */
1532 0, /* stencil buffer */
1533 0, /* auxiliary buffer */
1534 PFD_MAIN_PLANE
, /* main layer */
1536 0, 0, 0 /* layer masks */
1539 HWND window1
, window2
, old_parent
;
1540 HGLRC ctx1
, ctx2
, oldctx
;
1545 oldctx
= wglGetCurrentContext();
1546 ok(!!oldctx
, "Expected to find a valid current context.\n");
1548 window1
= CreateWindowA("static", "opengl32_test",
1549 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1550 ok(!!window1
, "Failed to create window1, last error %#x.\n", GetLastError());
1552 dc1
= GetDC(window1
);
1553 ok(!!dc1
, "Failed to get DC.\n");
1555 pixel_format
= ChoosePixelFormat(dc1
, &pf_desc
);
1558 win_skip("Failed to find pixel format.\n");
1559 ReleaseDC(window1
, dc1
);
1560 DestroyWindow(window1
);
1564 ret
= SetPixelFormat(dc1
, pixel_format
, &pf_desc
);
1565 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1567 ctx1
= wglCreateContext(dc1
);
1568 ok(!!ctx1
, "Failed to create GL context, last error %#x.\n", GetLastError());
1570 ret
= wglMakeCurrent(dc1
, ctx1
);
1571 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1573 interval
= pwglGetSwapIntervalEXT();
1574 ok(interval
== 1, "Expected default swap interval 1, got %d\n", interval
);
1576 ret
= pwglSwapIntervalEXT(0);
1577 ok(ret
, "Failed to set swap interval to 0, last error %#x.\n", GetLastError());
1579 interval
= pwglGetSwapIntervalEXT();
1580 ok(interval
== 0, "Expected swap interval 0, got %d\n", interval
);
1582 /* Check what interval we get on a second context on the same drawable.*/
1583 ctx2
= wglCreateContext(dc1
);
1584 ok(!!ctx2
, "Failed to create GL context, last error %#x.\n", GetLastError());
1586 ret
= wglMakeCurrent(dc1
, ctx2
);
1587 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1589 interval
= pwglGetSwapIntervalEXT();
1590 ok(interval
== 0, "Expected swap interval 0, got %d\n", interval
);
1592 /* A second window is created to see whether its swap interval was affected
1593 * by previous calls.
1595 window2
= CreateWindowA("static", "opengl32_test",
1596 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1597 ok(!!window2
, "Failed to create window2, last error %#x.\n", GetLastError());
1599 dc2
= GetDC(window2
);
1600 ok(!!dc2
, "Failed to get DC.\n");
1602 ret
= SetPixelFormat(dc2
, pixel_format
, &pf_desc
);
1603 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1605 ret
= wglMakeCurrent(dc2
, ctx1
);
1606 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1608 /* Since the second window lacks the swap interval, this proves that the interval
1609 * is not global or shared among contexts.
1611 interval
= pwglGetSwapIntervalEXT();
1612 ok(interval
== 1, "Expected default swap interval 1, got %d\n", interval
);
1614 /* Test if setting the parent of a window resets the swap interval. */
1615 ret
= wglMakeCurrent(dc1
, ctx1
);
1616 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1618 old_parent
= SetParent(window1
, window2
);
1619 ok(!!old_parent
, "Failed to make window1 a child of window2, last error %#x.\n", GetLastError());
1621 interval
= pwglGetSwapIntervalEXT();
1622 ok(interval
== 0, "Expected swap interval 0, got %d\n", interval
);
1624 ret
= wglDeleteContext(ctx1
);
1625 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1626 ret
= wglDeleteContext(ctx2
);
1627 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1629 ReleaseDC(window1
, dc1
);
1630 DestroyWindow(window1
);
1631 ReleaseDC(window2
, dc2
);
1632 DestroyWindow(window2
);
1634 wglMakeCurrent(oldhdc
, oldctx
);
1640 PIXELFORMATDESCRIPTOR pfd
= {
1641 sizeof(PIXELFORMATDESCRIPTOR
),
1643 PFD_DRAW_TO_WINDOW
|
1644 PFD_SUPPORT_OPENGL
|
1647 24, /* 24-bit color depth */
1648 0, 0, 0, 0, 0, 0, /* color bits */
1649 0, /* alpha buffer */
1651 0, /* accumulation buffer */
1652 0, 0, 0, 0, /* accum bits */
1654 0, /* stencil buffer */
1655 0, /* auxiliary buffer */
1656 PFD_MAIN_PLANE
, /* main layer */
1658 0, 0, 0 /* layer masks */
1661 hwnd
= CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW
, 10, 10, 200, 200, NULL
, NULL
,
1663 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
1667 int iPixelFormat
, res
;
1670 ShowWindow(hwnd
, SW_SHOW
);
1674 iPixelFormat
= ChoosePixelFormat(hdc
, &pfd
);
1675 if(iPixelFormat
== 0)
1677 /* This should never happen as ChoosePixelFormat always returns a closest match, but currently this fails in Wine if we don't have glX */
1678 win_skip("Unable to find pixel format.\n");
1682 /* We shouldn't be able to create a context from a hdc which doesn't have a pixel format set */
1683 hglrc
= wglCreateContext(hdc
);
1684 ok(hglrc
== NULL
, "wglCreateContext should fail when no pixel format has been set, but it passed\n");
1685 error
= GetLastError();
1686 ok(error
== ERROR_INVALID_PIXEL_FORMAT
, "expected ERROR_INVALID_PIXEL_FORMAT for wglCreateContext without a pixelformat set, but received %#x\n", error
);
1688 res
= SetPixelFormat(hdc
, iPixelFormat
, &pfd
);
1689 ok(res
, "SetPixelformat failed: %x\n", GetLastError());
1691 test_bitmap_rendering( TRUE
);
1692 test_bitmap_rendering( FALSE
);
1695 test_message_window();
1698 ok(!glGetString(GL_RENDERER
) && !glGetString(GL_VERSION
) && !glGetString(GL_VENDOR
),
1699 "Expected NULL string when no active context is set\n");
1700 hglrc
= wglCreateContext(hdc
);
1701 res
= wglMakeCurrent(hdc
, hglrc
);
1702 ok(res
, "wglMakeCurrent failed!\n");
1705 trace("OpenGL renderer: %s\n", glGetString(GL_RENDERER
));
1706 trace("OpenGL driver version: %s\n", glGetString(GL_VERSION
));
1707 trace("OpenGL vendor: %s\n", glGetString(GL_VENDOR
));
1711 skip("Skipping OpenGL tests without a current context\n");
1715 /* Initialisation of WGL functions depends on an implicit WGL context. For this reason we can't load them before making
1716 * any WGL call :( On Wine this would work but not on real Windows because there can be different implementations (software, ICD, MCD).
1719 test_getprocaddress(hdc
);
1720 test_deletecontext(hwnd
, hdc
);
1721 test_makecurrent(hdc
);
1723 /* The lack of wglGetExtensionsStringARB in general means broken software rendering or the lack of decent OpenGL support, skip tests in such cases */
1724 if (!pwglGetExtensionsStringARB
)
1726 win_skip("wglGetExtensionsStringARB is not available\n");
1730 test_debug_message_callback();
1731 test_setpixelformat(hdc
);
1733 test_sharelists(hdc
);
1734 test_colorbits(hdc
);
1736 test_acceleration(hdc
);
1738 wgl_extensions
= pwglGetExtensionsStringARB(hdc
);
1739 if(wgl_extensions
== NULL
) skip("Skipping opengl32 tests because this OpenGL implementation doesn't support WGL extensions!\n");
1741 if(strstr(wgl_extensions
, "WGL_ARB_create_context"))
1744 if(strstr(wgl_extensions
, "WGL_ARB_make_current_read"))
1746 test_make_current_read(hdc
);
1747 test_destroy_read(hdc
);
1750 skip("WGL_ARB_make_current_read not supported, skipping test\n");
1752 if(strstr(wgl_extensions
, "WGL_ARB_pbuffer"))
1755 skip("WGL_ARB_pbuffer not supported, skipping pbuffer test\n");
1757 if(strstr(wgl_extensions
, "WGL_EXT_swap_control"))
1758 test_swap_control(hdc
);
1760 skip("WGL_EXT_swap_control not supported, skipping test\n");
1763 ReleaseDC(hwnd
, hdc
);
1764 DestroyWindow(hwnd
);