2 * Some tests for OpenGL functions
4 * Copyright (C) 2007-2008 Roderick Colenbrander
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/test.h"
25 void WINAPI
glClearColor(float red
, float green
, float blue
, float alpha
);
26 void WINAPI
glClear(unsigned int mask
);
27 void WINAPI
glFinish(void);
28 #define GL_COLOR_BUFFER_BIT 0x00004000
29 const unsigned char * WINAPI
glGetString(unsigned int);
30 #define GL_VENDOR 0x1F00
31 #define GL_RENDERER 0x1F01
32 #define GL_VERSION 0x1F02
34 #define MAX_FORMATS 256
35 typedef void* HPBUFFERARB
;
37 /* WGL_ARB_create_context */
38 static HGLRC (WINAPI
*pwglCreateContextAttribsARB
)(HDC hDC
, HGLRC hShareContext
, const int *attribList
);
40 #define ERROR_INVALID_VERSION_ARB 0x2095
41 #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
42 #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
43 #define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
44 #define WGL_CONTEXT_FLAGS_ARB 0x2094
45 /* Flags for WGL_CONTEXT_FLAGS_ARB */
46 #define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
47 #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
49 /* WGL_ARB_extensions_string */
50 static const char* (WINAPI
*pwglGetExtensionsStringARB
)(HDC
);
51 static int (WINAPI
*pwglReleasePbufferDCARB
)(HPBUFFERARB
, HDC
);
53 /* WGL_ARB_make_current_read */
54 static BOOL (WINAPI
*pwglMakeContextCurrentARB
)(HDC hdraw
, HDC hread
, HGLRC hglrc
);
55 static HDC (WINAPI
*pwglGetCurrentReadDCARB
)(void);
57 /* WGL_ARB_pixel_format */
58 #define WGL_ACCELERATION_ARB 0x2003
59 #define WGL_COLOR_BITS_ARB 0x2014
60 #define WGL_RED_BITS_ARB 0x2015
61 #define WGL_GREEN_BITS_ARB 0x2017
62 #define WGL_BLUE_BITS_ARB 0x2019
63 #define WGL_ALPHA_BITS_ARB 0x201B
64 #define WGL_SUPPORT_GDI_ARB 0x200F
65 #define WGL_DOUBLE_BUFFER_ARB 0x2011
66 #define WGL_NO_ACCELERATION_ARB 0x2025
67 #define WGL_GENERIC_ACCELERATION_ARB 0x2026
68 #define WGL_FULL_ACCELERATION_ARB 0x2027
70 static BOOL (WINAPI
*pwglChoosePixelFormatARB
)(HDC
, const int *, const FLOAT
*, UINT
, int *, UINT
*);
71 static BOOL (WINAPI
*pwglGetPixelFormatAttribivARB
)(HDC
, int, int, UINT
, const int *, int *);
74 #define WGL_DRAW_TO_PBUFFER_ARB 0x202D
75 static HPBUFFERARB
* (WINAPI
*pwglCreatePbufferARB
)(HDC
, int, int, int, const int *);
76 static HDC (WINAPI
*pwglGetPbufferDCARB
)(HPBUFFERARB
);
78 static const char* wgl_extensions
= NULL
;
80 static void init_functions(void)
82 #define GET_PROC(func) \
83 p ## func = (void*)wglGetProcAddress(#func); \
85 trace("wglGetProcAddress(%s) failed\n", #func);
87 /* WGL_ARB_create_context */
88 GET_PROC(wglCreateContextAttribsARB
);
90 /* WGL_ARB_extensions_string */
91 GET_PROC(wglGetExtensionsStringARB
)
93 /* WGL_ARB_make_current_read */
94 GET_PROC(wglMakeContextCurrentARB
);
95 GET_PROC(wglGetCurrentReadDCARB
);
97 /* WGL_ARB_pixel_format */
98 GET_PROC(wglChoosePixelFormatARB
)
99 GET_PROC(wglGetPixelFormatAttribivARB
)
101 /* WGL_ARB_pbuffer */
102 GET_PROC(wglCreatePbufferARB
)
103 GET_PROC(wglGetPbufferDCARB
)
104 GET_PROC(wglReleasePbufferDCARB
)
109 static void test_pbuffers(HDC hdc
)
111 const int iAttribList
[] = { WGL_DRAW_TO_PBUFFER_ARB
, 1, /* Request pbuffer support */
113 int iFormats
[MAX_FORMATS
];
114 unsigned int nOnscreenFormats
;
115 unsigned int nFormats
;
117 int iPixelFormat
= 0;
119 nOnscreenFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
121 /* When you want to render to a pbuffer you need to call wglGetPbufferDCARB which
122 * returns a 'magic' HDC which you can then pass to wglMakeCurrent to switch rendering
123 * to the pbuffer. Below some tests are performed on what happens if you use standard WGL calls
124 * on this 'magic' HDC for both a pixelformat that support onscreen and offscreen rendering
125 * and a pixelformat that's only available for offscreen rendering (this means that only
126 * wglChoosePixelFormatARB and friends know about the format.
128 * The first thing we need are pixelformats with pbuffer capabilities.
130 res
= pwglChoosePixelFormatARB(hdc
, iAttribList
, NULL
, MAX_FORMATS
, iFormats
, &nFormats
);
133 skip("No pbuffer compatible formats found while WGL_ARB_pbuffer is supported\n");
136 trace("nOnscreenFormats: %d\n", nOnscreenFormats
);
137 trace("Total number of pbuffer capable pixelformats: %d\n", nFormats
);
139 /* Try to select an onscreen pixelformat out of the list */
140 for(i
=0; i
< nFormats
; i
++)
142 /* Check if the format is onscreen, if it is choose it */
143 if(iFormats
[i
] <= nOnscreenFormats
)
145 iPixelFormat
= iFormats
[i
];
146 trace("Selected iPixelFormat=%d\n", iPixelFormat
);
151 /* A video driver supports a large number of onscreen and offscreen pixelformats.
152 * The traditional WGL calls only see a subset of the whole pixelformat list. First
153 * of all they only see the onscreen formats (the offscreen formats are at the end of the
154 * pixelformat list) and second extended pixelformat capabilities are hidden from the
155 * standard WGL calls. Only functions that depend on WGL_ARB_pixel_format can see them.
157 * Below we check if the pixelformat is also supported onscreen.
159 if(iPixelFormat
!= 0)
162 HPBUFFERARB pbuffer
= pwglCreatePbufferARB(hdc
, iPixelFormat
, 640 /* width */, 480 /* height */, NULL
);
164 skip("Pbuffer creation failed!\n");
166 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
167 pbuffer_hdc
= pwglGetPbufferDCARB(pbuffer
);
168 res
= GetPixelFormat(pbuffer_hdc
);
169 ok(res
== iPixelFormat
, "Unexpected iPixelFormat=%d returned by GetPixelFormat for format %d\n", res
, iPixelFormat
);
170 trace("iPixelFormat returned by GetPixelFormat: %d\n", res
);
171 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat
);
173 pwglReleasePbufferDCARB(pbuffer
, hdc
);
175 else skip("Pbuffer test for onscreen pixelformat skipped as no onscreen format with pbuffer capabilities have been found\n");
177 /* Search for a real offscreen format */
178 for(i
=0, iPixelFormat
=0; i
<nFormats
; i
++)
180 if(iFormats
[i
] > nOnscreenFormats
)
182 iPixelFormat
= iFormats
[i
];
183 trace("Selected iPixelFormat: %d\n", iPixelFormat
);
188 if(iPixelFormat
!= 0)
191 HPBUFFERARB pbuffer
= pwglCreatePbufferARB(hdc
, iPixelFormat
, 640 /* width */, 480 /* height */, NULL
);
193 skip("Pbuffer creation failed!\n");
195 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
196 pbuffer_hdc
= pwglGetPbufferDCARB(pbuffer
);
197 res
= GetPixelFormat(pbuffer_hdc
);
199 ok(res
== 1, "Unexpected iPixelFormat=%d (1 expected) returned by GetPixelFormat for offscreen format %d\n", res
, iPixelFormat
);
200 trace("iPixelFormat returned by GetPixelFormat: %d\n", res
);
201 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat
);
202 pwglReleasePbufferDCARB(pbuffer
, hdc
);
204 else skip("Pbuffer test for offscreen pixelformat skipped as no offscreen-only format with pbuffer capabilities has been found\n");
207 static void test_setpixelformat(HDC winhdc
)
214 PIXELFORMATDESCRIPTOR pfd
= {
215 sizeof(PIXELFORMATDESCRIPTOR
),
221 24, /* 24-bit color depth */
222 0, 0, 0, 0, 0, 0, /* color bits */
223 0, /* alpha buffer */
225 0, /* accumulation buffer */
226 0, 0, 0, 0, /* accum bits */
228 0, /* stencil buffer */
229 0, /* auxiliary buffer */
230 PFD_MAIN_PLANE
, /* main layer */
232 0, 0, 0 /* layer masks */
236 ok(hdc
!= 0, "GetDC(0) failed!\n");
238 /* This should pass even on the main device context */
239 pf
= ChoosePixelFormat(hdc
, &pfd
);
240 ok(pf
!= 0, "ChoosePixelFormat failed on main device context\n");
242 /* SetPixelFormat on the main device context 'X root window' should fail,
243 * but some broken drivers allow it
245 res
= SetPixelFormat(hdc
, pf
, &pfd
);
246 trace("SetPixelFormat on main device context %s\n", res
? "succeeded" : "failed");
248 /* Setting the same format that was set on the HDC is allowed; other
250 nCfgs
= DescribePixelFormat(winhdc
, 0, 0, NULL
);
251 pf
= GetPixelFormat(winhdc
);
252 for(i
= 1;i
<= nCfgs
;i
++)
254 int res
= SetPixelFormat(winhdc
, i
, NULL
);
255 if(i
== pf
) ok(res
, "Failed to set the same pixel format\n");
256 else ok(!res
, "Unexpectedly set an alternate pixel format\n");
259 hwnd
= CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW
,
260 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
261 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
264 HDC hdc
= GetDC( hwnd
);
265 pf
= ChoosePixelFormat( hdc
, &pfd
);
266 ok( pf
!= 0, "ChoosePixelFormat failed\n" );
267 res
= SetPixelFormat( hdc
, pf
, &pfd
);
268 ok( res
!= 0, "SetPixelFormat failed\n" );
269 i
= GetPixelFormat( hdc
);
270 ok( i
== pf
, "GetPixelFormat returned wrong format %d/%d\n", i
, pf
);
271 ReleaseDC( hwnd
, hdc
);
272 hdc
= GetWindowDC( hwnd
);
273 i
= GetPixelFormat( hdc
);
274 ok( i
== pf
, "GetPixelFormat returned wrong format %d/%d\n", i
, pf
);
275 ReleaseDC( hwnd
, hdc
);
276 DestroyWindow( hwnd
);
279 hwnd
= CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW
,
280 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
281 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
284 HDC hdc
= GetWindowDC( hwnd
);
285 pf
= ChoosePixelFormat( hdc
, &pfd
);
286 ok( pf
!= 0, "ChoosePixelFormat failed\n" );
287 res
= SetPixelFormat( hdc
, pf
, &pfd
);
288 ok( res
!= 0, "SetPixelFormat failed\n" );
289 i
= GetPixelFormat( hdc
);
290 ok( i
== pf
, "GetPixelFormat returned wrong format %d/%d\n", i
, pf
);
291 ReleaseDC( hwnd
, hdc
);
292 DestroyWindow( hwnd
);
296 static void test_sharelists(HDC winhdc
)
298 HGLRC hglrc1
, hglrc2
, hglrc3
;
301 hglrc1
= wglCreateContext(winhdc
);
302 res
= wglShareLists(0, 0);
303 ok(res
== FALSE
, "Sharing display lists for no contexts passed!\n");
305 /* Test 1: Create a context and just share lists without doing anything special */
306 hglrc2
= wglCreateContext(winhdc
);
309 res
= wglShareLists(hglrc1
, hglrc2
);
310 ok(res
, "Sharing of display lists failed\n");
311 wglDeleteContext(hglrc2
);
314 /* Test 2: Share display lists with a 'destination' context which has been made current */
315 hglrc2
= wglCreateContext(winhdc
);
318 res
= wglMakeCurrent(winhdc
, hglrc2
);
319 ok(res
, "Make current failed\n");
320 res
= wglShareLists(hglrc1
, hglrc2
);
321 todo_wine
ok(res
, "Sharing display lists with a destination context which has been made current failed\n");
322 wglMakeCurrent(0, 0);
323 wglDeleteContext(hglrc2
);
326 /* Test 3: Share display lists with a context which already shares display lists with another context.
327 * According to MSDN the second parameter cannot share any display lists but some buggy drivers might allow it */
328 hglrc3
= wglCreateContext(winhdc
);
331 res
= wglShareLists(hglrc3
, hglrc1
);
332 ok(res
== FALSE
, "Sharing of display lists passed for a context which already shared lists before\n");
333 wglDeleteContext(hglrc3
);
336 /* Test 4: Share display lists with a 'source' context which has been made current */
337 hglrc2
= wglCreateContext(winhdc
);
340 res
= wglMakeCurrent(winhdc
, hglrc1
);
341 ok(res
, "Make current failed\n");
342 res
= wglShareLists(hglrc1
, hglrc2
);
343 ok(res
, "Sharing display lists with a source context which has been made current failed\n");
344 wglMakeCurrent(0, 0);
345 wglDeleteContext(hglrc2
);
349 static void test_makecurrent(HDC winhdc
)
355 hglrc
= wglCreateContext(winhdc
);
356 ok( hglrc
!= 0, "wglCreateContext failed\n" );
358 ret
= wglMakeCurrent( winhdc
, hglrc
);
359 ok( ret
, "wglMakeCurrent failed\n" );
361 ok( wglGetCurrentContext() == hglrc
, "wrong context\n" );
363 /* set the same context again */
364 ret
= wglMakeCurrent( winhdc
, hglrc
);
365 ok( ret
, "wglMakeCurrent failed\n" );
367 /* check wglMakeCurrent(x, y) after another call to wglMakeCurrent(x, y) */
368 ret
= wglMakeCurrent( winhdc
, NULL
);
369 ok( ret
, "wglMakeCurrent failed\n" );
371 ret
= wglMakeCurrent( winhdc
, NULL
);
372 ok( ret
, "wglMakeCurrent failed\n" );
374 SetLastError( 0xdeadbeef );
375 ret
= wglMakeCurrent( NULL
, NULL
);
376 ok( !ret
, "wglMakeCurrent succeeded\n" );
377 error
= GetLastError();
378 ok( error
== ERROR_INVALID_HANDLE
, "Expected ERROR_INVALID_HANDLE, got error=%x\n", error
);
380 ret
= wglMakeCurrent( winhdc
, NULL
);
381 ok( ret
, "wglMakeCurrent failed\n" );
383 ret
= wglMakeCurrent( winhdc
, hglrc
);
384 ok( ret
, "wglMakeCurrent failed\n" );
386 ret
= wglMakeCurrent( NULL
, NULL
);
387 ok( ret
, "wglMakeCurrent failed\n" );
389 SetLastError( 0xdeadbeef );
390 ret
= wglMakeCurrent( NULL
, NULL
);
391 ok( !ret
, "wglMakeCurrent succeeded\n" );
392 error
= GetLastError();
393 ok( error
== ERROR_INVALID_HANDLE
, "Expected ERROR_INVALID_HANDLE, got error=%x\n", error
);
395 ret
= wglMakeCurrent( winhdc
, hglrc
);
396 ok( ret
, "wglMakeCurrent failed\n" );
399 static void test_colorbits(HDC hdc
)
401 const int iAttribList
[] = { WGL_COLOR_BITS_ARB
, WGL_RED_BITS_ARB
, WGL_GREEN_BITS_ARB
,
402 WGL_BLUE_BITS_ARB
, WGL_ALPHA_BITS_ARB
};
403 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
404 const int iAttribs
[] = { WGL_ALPHA_BITS_ARB
, 1, 0 };
405 unsigned int nFormats
;
407 int iPixelFormat
= 0;
409 if (!pwglChoosePixelFormatARB
)
411 win_skip("wglChoosePixelFormatARB is not available\n");
415 /* We need a pixel format with at least one bit of alpha */
416 res
= pwglChoosePixelFormatARB(hdc
, iAttribs
, NULL
, 1, &iPixelFormat
, &nFormats
);
417 if(res
== FALSE
|| nFormats
== 0)
419 skip("No suitable pixel formats found\n");
423 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
424 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
, iAttribRet
);
427 skip("wglGetPixelFormatAttribivARB failed\n");
430 iAttribRet
[1] += iAttribRet
[2]+iAttribRet
[3]+iAttribRet
[4];
431 ok(iAttribRet
[0] == iAttribRet
[1], "WGL_COLOR_BITS_ARB (%d) does not equal R+G+B+A (%d)!\n",
432 iAttribRet
[0], iAttribRet
[1]);
435 static void test_gdi_dbuf(HDC hdc
)
437 const int iAttribList
[] = { WGL_SUPPORT_GDI_ARB
, WGL_DOUBLE_BUFFER_ARB
};
438 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
439 unsigned int nFormats
;
443 if (!pwglGetPixelFormatAttribivARB
)
445 win_skip("wglGetPixelFormatAttribivARB is not available\n");
449 nFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
450 for(iPixelFormat
= 1;iPixelFormat
<= nFormats
;iPixelFormat
++)
452 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
453 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
,
455 ok(res
!=FALSE
, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat
);
459 ok(!(iAttribRet
[0] && iAttribRet
[1]), "GDI support and double buffering on pixel format %d\n", iPixelFormat
);
463 static void test_acceleration(HDC hdc
)
465 const int iAttribList
[] = { WGL_ACCELERATION_ARB
};
466 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
467 unsigned int nFormats
;
470 PIXELFORMATDESCRIPTOR pfd
;
472 if (!pwglGetPixelFormatAttribivARB
)
474 win_skip("wglGetPixelFormatAttribivARB is not available\n");
478 nFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
479 for(iPixelFormat
= 1; iPixelFormat
<= nFormats
; iPixelFormat
++)
481 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
482 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
,
484 ok(res
!=FALSE
, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat
);
488 memset(&pfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
489 DescribePixelFormat(hdc
, iPixelFormat
, sizeof(PIXELFORMATDESCRIPTOR
), &pfd
);
491 switch(iAttribRet
[0])
493 case WGL_NO_ACCELERATION_ARB
:
494 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
);
496 case WGL_GENERIC_ACCELERATION_ARB
:
497 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
);
499 case WGL_FULL_ACCELERATION_ARB
:
500 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
);
506 static void test_bitmap_rendering(void)
508 PIXELFORMATDESCRIPTOR pfd
;
509 int i
, iPixelFormat
=0;
510 unsigned int nFormats
;
513 HBITMAP bmpDst
, oldDst
;
514 HDC hdcDst
, hdcScreen
;
517 memset(&biDst
, 0, sizeof(BITMAPINFO
));
518 biDst
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
519 biDst
.bmiHeader
.biWidth
= 2;
520 biDst
.bmiHeader
.biHeight
= -2;
521 biDst
.bmiHeader
.biPlanes
= 1;
522 biDst
.bmiHeader
.biBitCount
= 32;
523 biDst
.bmiHeader
.biCompression
= BI_RGB
;
525 hdcScreen
= CreateCompatibleDC(0);
526 if(GetDeviceCaps(hdcScreen
, BITSPIXEL
) != 32)
529 trace("Skipping bitmap rendering test\n");
533 hdcDst
= CreateCompatibleDC(hdcScreen
);
534 bmpDst
= CreateDIBSection(hdcDst
, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
, NULL
, 0);
535 oldDst
= SelectObject(hdcDst
, bmpDst
);
537 /* Pick a pixel format by hand because ChoosePixelFormat is unreliable */
538 nFormats
= DescribePixelFormat(hdcDst
, 0, 0, NULL
);
539 for(i
=1; i
<=nFormats
; i
++)
541 memset(&pfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
542 DescribePixelFormat(hdcDst
, i
, sizeof(PIXELFORMATDESCRIPTOR
), &pfd
);
544 if((pfd
.dwFlags
& PFD_DRAW_TO_BITMAP
) &&
545 (pfd
.dwFlags
& PFD_SUPPORT_OPENGL
) &&
546 (pfd
.cColorBits
== 32) &&
547 (pfd
.cAlphaBits
== 8) )
556 skip("Unable to find a suitable pixel format\n");
560 SetPixelFormat(hdcDst
, iPixelFormat
, &pfd
);
561 hglrc
= wglCreateContext(hdcDst
);
562 todo_wine
ok(hglrc
!= NULL
, "Unable to create a context\n");
566 wglMakeCurrent(hdcDst
, hglrc
);
568 /* Note this is RGBA but we read ARGB back */
569 glClearColor((float)0x22/0xff, (float)0x33/0xff, (float)0x44/0xff, (float)0x11/0xff);
570 glClear(GL_COLOR_BUFFER_BIT
);
573 /* Note apparently the alpha channel is not supported by the software renderer (bitmap only works using software) */
574 ok(dstBuffer
[0] == 0x223344, "Expected color=0x223344, received color=%x\n", dstBuffer
[0]);
576 wglMakeCurrent(NULL
, NULL
);
577 wglDeleteContext(hglrc
);
581 SelectObject(hdcDst
, oldDst
);
582 DeleteObject(bmpDst
);
588 struct wgl_thread_param
590 HANDLE test_finished
;
596 static DWORD WINAPI
wgl_thread(void *param
)
598 struct wgl_thread_param
*p
= param
;
600 SetLastError(0xdeadbeef);
601 p
->hglrc_deleted
= wglDeleteContext(p
->hglrc
);
602 p
->last_error
= GetLastError();
603 SetEvent(p
->test_finished
);
608 static void test_deletecontext(HDC hdc
)
610 struct wgl_thread_param thread_params
;
611 HGLRC hglrc
= wglCreateContext(hdc
);
612 HANDLE thread_handle
;
615 SetLastError(0xdeadbeef);
616 res
= wglDeleteContext(NULL
);
617 ok(res
== FALSE
, "wglDeleteContext succeeded\n");
618 ok(GetLastError() == ERROR_INVALID_HANDLE
, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
622 skip("wglCreateContext failed!\n");
626 res
= wglMakeCurrent(hdc
, hglrc
);
629 skip("wglMakeCurrent failed!\n");
633 /* WGL doesn't allow you to delete a context from a different thread than the one in which it is current.
634 * This differs from GLX which does allow it but it delays actual deletion until the context becomes not current.
636 thread_params
.hglrc
= hglrc
;
637 thread_params
.test_finished
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
638 thread_handle
= CreateThread(NULL
, 0, wgl_thread
, &thread_params
, 0, &tid
);
639 ok(!!thread_handle
, "Failed to create thread, last error %#x.\n", GetLastError());
642 WaitForSingleObject(thread_handle
, INFINITE
);
643 ok(thread_params
.hglrc_deleted
== FALSE
, "Attempt to delete WGL context from another thread passed but should fail!\n");
644 ok(thread_params
.last_error
== ERROR_BUSY
, "Expected last error to be ERROR_BUSY, got %u\n", thread_params
.last_error
);
646 CloseHandle(thread_params
.test_finished
);
648 res
= wglDeleteContext(hglrc
);
649 ok(res
== TRUE
, "wglDeleteContext failed\n");
651 /* Attempting to delete the same context twice should fail. */
652 SetLastError(0xdeadbeef);
653 res
= wglDeleteContext(hglrc
);
654 ok(res
== FALSE
, "wglDeleteContext succeeded\n");
655 ok(GetLastError() == ERROR_INVALID_HANDLE
, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
657 /* WGL makes a context not current when deleting it. This differs from GLX behavior where
658 * deletion takes place when the thread becomes not current. */
659 hglrc
= wglGetCurrentContext();
660 ok(hglrc
== NULL
, "A WGL context is active while none was expected\n");
663 static void test_make_current_read(HDC hdc
)
667 HGLRC hglrc
= wglCreateContext(hdc
);
671 skip("wglCreateContext failed!\n");
675 res
= wglMakeCurrent(hdc
, hglrc
);
678 skip("wglMakeCurrent failed!\n");
682 /* Test what wglGetCurrentReadDCARB does for wglMakeCurrent as the spec doesn't mention it */
683 hread
= pwglGetCurrentReadDCARB();
684 trace("hread %p, hdc %p\n", hread
, hdc
);
685 ok(hread
== hdc
, "wglGetCurrentReadDCARB failed for standard wglMakeCurrent\n");
687 pwglMakeContextCurrentARB(hdc
, hdc
, hglrc
);
688 hread
= pwglGetCurrentReadDCARB();
689 ok(hread
== hdc
, "wglGetCurrentReadDCARB failed for wglMakeContextCurrent\n");
692 static void test_dc(HWND hwnd
, HDC hdc
)
697 /* Get another DC and make sure it has the same pixel format */
701 pf1
= GetPixelFormat(hdc
);
702 pf2
= GetPixelFormat(hdc2
);
703 ok(pf1
== pf2
, "Second DC does not have the same format (%d != %d)\n", pf1
, pf2
);
706 skip("Could not get a different DC for the window\n");
710 ReleaseDC(hwnd
, hdc2
);
715 /* Nvidia converts win32 error codes to (0xc007 << 16) | win32_error_code */
716 #define NVIDIA_HRESULT_FROM_WIN32(x) (HRESULT_FROM_WIN32(x) | 0x40000000)
717 static void test_opengl3(HDC hdc
)
719 /* Try to create a context compatible with OpenGL 1.x; 1.0-2.1 is allowed */
722 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 1, 0};
724 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
725 ok(gl3Ctx
!= 0, "pwglCreateContextAttribsARB for a 1.x context failed!\n");
726 wglDeleteContext(gl3Ctx
);
729 /* Try to pass an invalid HDC */
733 gl3Ctx
= pwglCreateContextAttribsARB((HDC
)0xdeadbeef, 0, 0);
734 ok(gl3Ctx
== 0, "pwglCreateContextAttribsARB using an invalid HDC passed\n");
735 error
= GetLastError();
736 todo_wine
ok(error
== ERROR_DC_NOT_FOUND
||
737 broken(error
== NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_DATA
)), /* Nvidia Vista + Win7 */
738 "Expected ERROR_DC_NOT_FOUND, got error=%x\n", error
);
739 wglDeleteContext(gl3Ctx
);
742 /* Try to pass an invalid shareList */
746 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, (HGLRC
)0xdeadbeef, 0);
747 todo_wine
ok(gl3Ctx
== 0, "pwglCreateContextAttribsARB using an invalid shareList passed\n");
748 error
= GetLastError();
749 /* The Nvidia implementation seems to return hresults instead of win32 error codes */
750 todo_wine
ok(error
== ERROR_INVALID_OPERATION
||
751 error
== NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_OPERATION
), "Expected ERROR_INVALID_OPERATION, got error=%x\n", error
);
752 wglDeleteContext(gl3Ctx
);
755 /* Try to create an OpenGL 3.0 context */
757 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
758 HGLRC gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
762 skip("Skipping the rest of the WGL_ARB_create_context test due to lack of OpenGL 3.0\n");
766 wglDeleteContext(gl3Ctx
);
769 /* 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 */
771 HGLRC glCtx
= wglCreateContext(hdc
);
773 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
774 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};
776 HGLRC gl3Ctx
= pwglCreateContextAttribsARB(hdc
, glCtx
, attribs
);
777 ok(gl3Ctx
!= NULL
, "Sharing of a display list between OpenGL 3.0 and OpenGL 1.x/2.x failed!\n");
779 wglDeleteContext(gl3Ctx
);
781 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, glCtx
, attribs_future
);
782 ok(gl3Ctx
!= NULL
, "Sharing of a display list between a forward compatible OpenGL 3.0 context and OpenGL 1.x/2.x failed!\n");
784 wglDeleteContext(gl3Ctx
);
787 wglDeleteContext(glCtx
);
790 /* Try to create an OpenGL 3.0 context and test windowless rendering */
793 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
796 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
797 ok(gl3Ctx
!= 0, "pwglCreateContextAttribsARB for a 3.0 context failed!\n");
799 /* OpenGL 3.0 allows offscreen rendering WITHOUT a drawable
800 * Neither AMD or Nvidia support it at this point. The WGL_ARB_create_context specs also say that
801 * it is hard because drivers use the HDC to enter the display driver and it sounds like they don't
802 * expect drivers to ever offer it.
804 res
= wglMakeCurrent(0, gl3Ctx
);
805 ok(res
== FALSE
, "Wow, OpenGL 3.0 windowless rendering passed while it was expected not to!\n");
807 wglMakeCurrent(0, 0);
810 wglDeleteContext(gl3Ctx
);
814 static void test_minimized(void)
816 PIXELFORMATDESCRIPTOR pf_desc
=
818 sizeof(PIXELFORMATDESCRIPTOR
),
820 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
822 24, /* 24-bit color depth */
823 0, 0, 0, 0, 0, 0, /* color bits */
824 0, /* alpha buffer */
826 0, /* accumulation buffer */
827 0, 0, 0, 0, /* accum bits */
829 0, /* stencil buffer */
830 0, /* auxiliary buffer */
831 PFD_MAIN_PLANE
, /* main layer */
833 0, 0, 0 /* layer masks */
842 window
= CreateWindowA("static", "opengl32_test",
843 WS_POPUP
| WS_MINIMIZE
, 0, 0, 640, 480, 0, 0, 0, 0);
844 ok(!!window
, "Failed to create window, last error %#x.\n", GetLastError());
847 ok(!!dc
, "Failed to get DC.\n");
849 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
852 win_skip("Failed to find pixel format.\n");
853 ReleaseDC(window
, dc
);
854 DestroyWindow(window
);
858 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
859 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
861 style
= GetWindowLongA(window
, GWL_STYLE
);
862 ok(style
& WS_MINIMIZE
, "Window should be minimized, got style %#x.\n", style
);
864 ctx
= wglCreateContext(dc
);
865 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
867 ret
= wglMakeCurrent(dc
, ctx
);
868 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
870 style
= GetWindowLongA(window
, GWL_STYLE
);
871 ok(style
& WS_MINIMIZE
, "window should be minimized, got style %#x.\n", style
);
873 ret
= wglMakeCurrent(NULL
, NULL
);
874 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
876 ret
= wglDeleteContext(ctx
);
877 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
879 ReleaseDC(window
, dc
);
880 DestroyWindow(window
);
886 PIXELFORMATDESCRIPTOR pfd
= {
887 sizeof(PIXELFORMATDESCRIPTOR
),
893 24, /* 24-bit color depth */
894 0, 0, 0, 0, 0, 0, /* color bits */
895 0, /* alpha buffer */
897 0, /* accumulation buffer */
898 0, 0, 0, 0, /* accum bits */
900 0, /* stencil buffer */
901 0, /* auxiliary buffer */
902 PFD_MAIN_PLANE
, /* main layer */
904 0, 0, 0 /* layer masks */
907 hwnd
= CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW
,
908 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
909 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
913 int iPixelFormat
, res
;
916 ShowWindow(hwnd
, SW_SHOW
);
920 iPixelFormat
= ChoosePixelFormat(hdc
, &pfd
);
921 if(iPixelFormat
== 0)
923 /* This should never happen as ChoosePixelFormat always returns a closest match, but currently this fails in Wine if we don't have glX */
924 win_skip("Unable to find pixel format.\n");
928 /* We shouldn't be able to create a context from a hdc which doesn't have a pixel format set */
929 hglrc
= wglCreateContext(hdc
);
930 ok(hglrc
== NULL
, "wglCreateContext should fail when no pixel format has been set, but it passed\n");
931 error
= GetLastError();
932 ok(error
== ERROR_INVALID_PIXEL_FORMAT
, "expected ERROR_INVALID_PIXEL_FORMAT for wglCreateContext without a pixelformat set, but received %#x\n", error
);
934 res
= SetPixelFormat(hdc
, iPixelFormat
, &pfd
);
935 ok(res
, "SetPixelformat failed: %x\n", GetLastError());
937 test_bitmap_rendering();
941 hglrc
= wglCreateContext(hdc
);
942 res
= wglMakeCurrent(hdc
, hglrc
);
943 ok(res
, "wglMakeCurrent failed!\n");
946 trace("OpenGL renderer: %s\n", glGetString(GL_RENDERER
));
947 trace("OpenGL driver version: %s\n", glGetString(GL_VERSION
));
948 trace("OpenGL vendor: %s\n", glGetString(GL_VENDOR
));
952 skip("Skipping OpenGL tests without a current context\n");
956 /* Initialisation of WGL functions depends on an implicit WGL context. For this reason we can't load them before making
957 * any WGL call :( On Wine this would work but not on real Windows because there can be different implementations (software, ICD, MCD).
960 /* The lack of wglGetExtensionsStringARB in general means broken software rendering or the lack of decent OpenGL support, skip tests in such cases */
961 if (!pwglGetExtensionsStringARB
)
963 win_skip("wglGetExtensionsStringARB is not available\n");
967 test_deletecontext(hdc
);
968 test_makecurrent(hdc
);
969 test_setpixelformat(hdc
);
970 test_sharelists(hdc
);
973 test_acceleration(hdc
);
975 wgl_extensions
= pwglGetExtensionsStringARB(hdc
);
976 if(wgl_extensions
== NULL
) skip("Skipping opengl32 tests because this OpenGL implementation doesn't support WGL extensions!\n");
978 if(strstr(wgl_extensions
, "WGL_ARB_create_context"))
981 if(strstr(wgl_extensions
, "WGL_ARB_make_current_read"))
982 test_make_current_read(hdc
);
984 skip("WGL_ARB_make_current_read not supported, skipping test\n");
986 if(strstr(wgl_extensions
, "WGL_ARB_pbuffer"))
989 skip("WGL_ARB_pbuffer not supported, skipping pbuffer test\n");
992 ReleaseDC(hwnd
, hdc
);