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 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)
163 HPBUFFERARB pbuffer
= pwglCreatePbufferARB(hdc
, iPixelFormat
, 640 /* width */, 480 /* height */, &attrib
);
165 skip("Pbuffer creation failed!\n");
167 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
168 pbuffer_hdc
= pwglGetPbufferDCARB(pbuffer
);
169 res
= GetPixelFormat(pbuffer_hdc
);
170 ok(res
== iPixelFormat
, "Unexpected iPixelFormat=%d returned by GetPixelFormat for format %d\n", res
, iPixelFormat
);
171 trace("iPixelFormat returned by GetPixelFormat: %d\n", res
);
172 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat
);
174 pwglReleasePbufferDCARB(pbuffer
, hdc
);
176 else skip("Pbuffer test for onscreen pixelformat skipped as no onscreen format with pbuffer capabilities have been found\n");
178 /* Search for a real offscreen format */
179 for(i
=0, iPixelFormat
=0; i
<nFormats
; i
++)
181 if(iFormats
[i
] > nOnscreenFormats
)
183 iPixelFormat
= iFormats
[i
];
184 trace("Selected iPixelFormat: %d\n", iPixelFormat
);
189 if(iPixelFormat
!= 0)
192 HPBUFFERARB pbuffer
= pwglCreatePbufferARB(hdc
, iPixelFormat
, 640 /* width */, 480 /* height */, NULL
);
194 skip("Pbuffer creation failed!\n");
196 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
197 pbuffer_hdc
= pwglGetPbufferDCARB(pbuffer
);
198 res
= GetPixelFormat(pbuffer_hdc
);
200 ok(res
== 1, "Unexpected iPixelFormat=%d (1 expected) returned by GetPixelFormat for offscreen format %d\n", res
, iPixelFormat
);
201 trace("iPixelFormat returned by GetPixelFormat: %d\n", res
);
202 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat
);
203 pwglReleasePbufferDCARB(pbuffer
, hdc
);
205 else skip("Pbuffer test for offscreen pixelformat skipped as no offscreen-only format with pbuffer capabilities has been found\n");
208 static void test_setpixelformat(HDC winhdc
)
215 PIXELFORMATDESCRIPTOR pfd
= {
216 sizeof(PIXELFORMATDESCRIPTOR
),
222 24, /* 24-bit color depth */
223 0, 0, 0, 0, 0, 0, /* color bits */
224 0, /* alpha buffer */
226 0, /* accumulation buffer */
227 0, 0, 0, 0, /* accum bits */
229 0, /* stencil buffer */
230 0, /* auxiliary buffer */
231 PFD_MAIN_PLANE
, /* main layer */
233 0, 0, 0 /* layer masks */
237 ok(hdc
!= 0, "GetDC(0) failed!\n");
239 /* This should pass even on the main device context */
240 pf
= ChoosePixelFormat(hdc
, &pfd
);
241 ok(pf
!= 0, "ChoosePixelFormat failed on main device context\n");
243 /* SetPixelFormat on the main device context 'X root window' should fail,
244 * but some broken drivers allow it
246 res
= SetPixelFormat(hdc
, pf
, &pfd
);
247 trace("SetPixelFormat on main device context %s\n", res
? "succeeded" : "failed");
249 /* Setting the same format that was set on the HDC is allowed; other
251 nCfgs
= DescribePixelFormat(winhdc
, 0, 0, NULL
);
252 pf
= GetPixelFormat(winhdc
);
253 for(i
= 1;i
<= nCfgs
;i
++)
255 int res
= SetPixelFormat(winhdc
, i
, NULL
);
256 if(i
== pf
) ok(res
, "Failed to set the same pixel format\n");
257 else ok(!res
, "Unexpectedly set an alternate pixel format\n");
260 hwnd
= CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW
,
261 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
262 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
265 HDC hdc
= GetDC( hwnd
);
266 pf
= ChoosePixelFormat( hdc
, &pfd
);
267 ok( pf
!= 0, "ChoosePixelFormat failed\n" );
268 res
= SetPixelFormat( hdc
, pf
, &pfd
);
269 ok( res
!= 0, "SetPixelFormat failed\n" );
270 i
= GetPixelFormat( hdc
);
271 ok( i
== pf
, "GetPixelFormat returned wrong format %d/%d\n", i
, pf
);
272 ReleaseDC( hwnd
, hdc
);
273 hdc
= GetWindowDC( hwnd
);
274 i
= GetPixelFormat( hdc
);
275 ok( i
== pf
, "GetPixelFormat returned wrong format %d/%d\n", i
, pf
);
276 ReleaseDC( hwnd
, hdc
);
277 DestroyWindow( hwnd
);
280 hwnd
= CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW
,
281 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
282 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
285 HDC hdc
= GetWindowDC( hwnd
);
286 pf
= ChoosePixelFormat( hdc
, &pfd
);
287 ok( pf
!= 0, "ChoosePixelFormat failed\n" );
288 res
= SetPixelFormat( hdc
, pf
, &pfd
);
289 ok( res
!= 0, "SetPixelFormat failed\n" );
290 i
= GetPixelFormat( hdc
);
291 ok( i
== pf
, "GetPixelFormat returned wrong format %d/%d\n", i
, pf
);
292 ReleaseDC( hwnd
, hdc
);
293 DestroyWindow( hwnd
);
297 static void test_sharelists(HDC winhdc
)
299 HGLRC hglrc1
, hglrc2
, hglrc3
;
302 hglrc1
= wglCreateContext(winhdc
);
303 res
= wglShareLists(0, 0);
304 ok(res
== FALSE
, "Sharing display lists for no contexts passed!\n");
306 /* Test 1: Create a context and just share lists without doing anything special */
307 hglrc2
= wglCreateContext(winhdc
);
310 res
= wglShareLists(hglrc1
, hglrc2
);
311 ok(res
, "Sharing of display lists failed\n");
312 wglDeleteContext(hglrc2
);
315 /* Test 2: Share display lists with a 'destination' context which has been made current */
316 hglrc2
= wglCreateContext(winhdc
);
319 res
= wglMakeCurrent(winhdc
, hglrc2
);
320 ok(res
, "Make current failed\n");
321 res
= wglShareLists(hglrc1
, hglrc2
);
322 todo_wine
ok(res
, "Sharing display lists with a destination context which has been made current failed\n");
323 wglMakeCurrent(0, 0);
324 wglDeleteContext(hglrc2
);
327 /* Test 3: Share display lists with a context which already shares display lists with another context.
328 * According to MSDN the second parameter cannot share any display lists but some buggy drivers might allow it */
329 hglrc3
= wglCreateContext(winhdc
);
332 res
= wglShareLists(hglrc3
, hglrc1
);
333 ok(res
== FALSE
, "Sharing of display lists passed for a context which already shared lists before\n");
334 wglDeleteContext(hglrc3
);
337 /* Test 4: Share display lists with a 'source' context which has been made current */
338 hglrc2
= wglCreateContext(winhdc
);
341 res
= wglMakeCurrent(winhdc
, hglrc1
);
342 ok(res
, "Make current failed\n");
343 res
= wglShareLists(hglrc1
, hglrc2
);
344 ok(res
, "Sharing display lists with a source context which has been made current failed\n");
345 wglMakeCurrent(0, 0);
346 wglDeleteContext(hglrc2
);
350 static void test_makecurrent(HDC winhdc
)
356 hglrc
= wglCreateContext(winhdc
);
357 ok( hglrc
!= 0, "wglCreateContext failed\n" );
359 ret
= wglMakeCurrent( winhdc
, hglrc
);
360 ok( ret
, "wglMakeCurrent failed\n" );
362 ok( wglGetCurrentContext() == hglrc
, "wrong context\n" );
364 /* set the same context again */
365 ret
= wglMakeCurrent( winhdc
, hglrc
);
366 ok( ret
, "wglMakeCurrent failed\n" );
368 /* check wglMakeCurrent(x, y) after another call to wglMakeCurrent(x, y) */
369 ret
= wglMakeCurrent( winhdc
, NULL
);
370 ok( ret
, "wglMakeCurrent failed\n" );
372 ret
= wglMakeCurrent( winhdc
, NULL
);
373 ok( ret
, "wglMakeCurrent failed\n" );
375 SetLastError( 0xdeadbeef );
376 ret
= wglMakeCurrent( NULL
, NULL
);
377 ok( !ret
, "wglMakeCurrent succeeded\n" );
378 error
= GetLastError();
379 ok( error
== ERROR_INVALID_HANDLE
, "Expected ERROR_INVALID_HANDLE, got error=%x\n", error
);
381 ret
= wglMakeCurrent( winhdc
, NULL
);
382 ok( ret
, "wglMakeCurrent failed\n" );
384 ret
= wglMakeCurrent( winhdc
, hglrc
);
385 ok( ret
, "wglMakeCurrent failed\n" );
387 ret
= wglMakeCurrent( NULL
, NULL
);
388 ok( ret
, "wglMakeCurrent failed\n" );
390 SetLastError( 0xdeadbeef );
391 ret
= wglMakeCurrent( NULL
, NULL
);
392 ok( !ret
, "wglMakeCurrent succeeded\n" );
393 error
= GetLastError();
394 ok( error
== ERROR_INVALID_HANDLE
, "Expected ERROR_INVALID_HANDLE, got error=%x\n", error
);
396 ret
= wglMakeCurrent( winhdc
, hglrc
);
397 ok( ret
, "wglMakeCurrent failed\n" );
400 static void test_colorbits(HDC hdc
)
402 const int iAttribList
[] = { WGL_COLOR_BITS_ARB
, WGL_RED_BITS_ARB
, WGL_GREEN_BITS_ARB
,
403 WGL_BLUE_BITS_ARB
, WGL_ALPHA_BITS_ARB
};
404 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
405 const int iAttribs
[] = { WGL_ALPHA_BITS_ARB
, 1, 0 };
406 unsigned int nFormats
;
408 int iPixelFormat
= 0;
410 if (!pwglChoosePixelFormatARB
)
412 win_skip("wglChoosePixelFormatARB is not available\n");
416 /* We need a pixel format with at least one bit of alpha */
417 res
= pwglChoosePixelFormatARB(hdc
, iAttribs
, NULL
, 1, &iPixelFormat
, &nFormats
);
418 if(res
== FALSE
|| nFormats
== 0)
420 skip("No suitable pixel formats found\n");
424 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
425 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
, iAttribRet
);
428 skip("wglGetPixelFormatAttribivARB failed\n");
431 iAttribRet
[1] += iAttribRet
[2]+iAttribRet
[3]+iAttribRet
[4];
432 ok(iAttribRet
[0] == iAttribRet
[1], "WGL_COLOR_BITS_ARB (%d) does not equal R+G+B+A (%d)!\n",
433 iAttribRet
[0], iAttribRet
[1]);
436 static void test_gdi_dbuf(HDC hdc
)
438 const int iAttribList
[] = { WGL_SUPPORT_GDI_ARB
, WGL_DOUBLE_BUFFER_ARB
};
439 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
440 unsigned int nFormats
;
444 if (!pwglGetPixelFormatAttribivARB
)
446 win_skip("wglGetPixelFormatAttribivARB is not available\n");
450 nFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
451 for(iPixelFormat
= 1;iPixelFormat
<= nFormats
;iPixelFormat
++)
453 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
454 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
,
456 ok(res
!=FALSE
, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat
);
460 ok(!(iAttribRet
[0] && iAttribRet
[1]), "GDI support and double buffering on pixel format %d\n", iPixelFormat
);
464 static void test_acceleration(HDC hdc
)
466 const int iAttribList
[] = { WGL_ACCELERATION_ARB
};
467 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
468 unsigned int nFormats
;
471 PIXELFORMATDESCRIPTOR pfd
;
473 if (!pwglGetPixelFormatAttribivARB
)
475 win_skip("wglGetPixelFormatAttribivARB is not available\n");
479 nFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
480 for(iPixelFormat
= 1; iPixelFormat
<= nFormats
; iPixelFormat
++)
482 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
483 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
,
485 ok(res
!=FALSE
, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat
);
489 memset(&pfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
490 DescribePixelFormat(hdc
, iPixelFormat
, sizeof(PIXELFORMATDESCRIPTOR
), &pfd
);
492 switch(iAttribRet
[0])
494 case WGL_NO_ACCELERATION_ARB
:
495 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
);
497 case WGL_GENERIC_ACCELERATION_ARB
:
498 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
);
500 case WGL_FULL_ACCELERATION_ARB
:
501 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
);
507 static void test_bitmap_rendering(void)
509 PIXELFORMATDESCRIPTOR pfd
;
510 int i
, iPixelFormat
=0;
511 unsigned int nFormats
;
514 HBITMAP bmpDst
, oldDst
;
515 HDC hdcDst
, hdcScreen
;
518 memset(&biDst
, 0, sizeof(BITMAPINFO
));
519 biDst
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
520 biDst
.bmiHeader
.biWidth
= 2;
521 biDst
.bmiHeader
.biHeight
= -2;
522 biDst
.bmiHeader
.biPlanes
= 1;
523 biDst
.bmiHeader
.biBitCount
= 32;
524 biDst
.bmiHeader
.biCompression
= BI_RGB
;
526 hdcScreen
= CreateCompatibleDC(0);
527 if(GetDeviceCaps(hdcScreen
, BITSPIXEL
) != 32)
530 trace("Skipping bitmap rendering test\n");
534 hdcDst
= CreateCompatibleDC(hdcScreen
);
535 bmpDst
= CreateDIBSection(hdcDst
, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
, NULL
, 0);
536 oldDst
= SelectObject(hdcDst
, bmpDst
);
538 /* Pick a pixel format by hand because ChoosePixelFormat is unreliable */
539 nFormats
= DescribePixelFormat(hdcDst
, 0, 0, NULL
);
540 for(i
=1; i
<=nFormats
; i
++)
542 memset(&pfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
543 DescribePixelFormat(hdcDst
, i
, sizeof(PIXELFORMATDESCRIPTOR
), &pfd
);
545 if((pfd
.dwFlags
& PFD_DRAW_TO_BITMAP
) &&
546 (pfd
.dwFlags
& PFD_SUPPORT_OPENGL
) &&
547 (pfd
.cColorBits
== 32) &&
548 (pfd
.cAlphaBits
== 8) )
557 skip("Unable to find a suitable pixel format\n");
561 SetPixelFormat(hdcDst
, iPixelFormat
, &pfd
);
562 hglrc
= wglCreateContext(hdcDst
);
563 todo_wine
ok(hglrc
!= NULL
, "Unable to create a context\n");
567 wglMakeCurrent(hdcDst
, hglrc
);
569 /* Note this is RGBA but we read ARGB back */
570 glClearColor((float)0x22/0xff, (float)0x33/0xff, (float)0x44/0xff, (float)0x11/0xff);
571 glClear(GL_COLOR_BUFFER_BIT
);
574 /* Note apparently the alpha channel is not supported by the software renderer (bitmap only works using software) */
575 ok(dstBuffer
[0] == 0x223344, "Expected color=0x223344, received color=%x\n", dstBuffer
[0]);
577 wglMakeCurrent(NULL
, NULL
);
578 wglDeleteContext(hglrc
);
582 SelectObject(hdcDst
, oldDst
);
583 DeleteObject(bmpDst
);
589 struct wgl_thread_param
591 HANDLE test_finished
;
596 static DWORD WINAPI
wgl_thread(void *param
)
598 struct wgl_thread_param
*p
= param
;
600 p
->hglrc_deleted
= wglDeleteContext(p
->hglrc
);
601 SetEvent(p
->test_finished
);
606 static void test_deletecontext(HDC hdc
)
608 struct wgl_thread_param thread_params
;
609 HGLRC hglrc
= wglCreateContext(hdc
);
610 HANDLE thread_handle
;
615 skip("wglCreateContext failed!\n");
619 res
= wglMakeCurrent(hdc
, hglrc
);
622 skip("wglMakeCurrent failed!\n");
626 /* WGL doesn't allow you to delete a context from a different thread than the one in which it is current.
627 * This differs from GLX which does allow it but it delays actual deletion until the context becomes not current.
629 thread_params
.hglrc
= hglrc
;
630 thread_params
.test_finished
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
631 thread_handle
= CreateThread(NULL
, 0, wgl_thread
, &thread_params
, 0, &tid
);
632 ok(!!thread_handle
, "Failed to create thread, last error %#x.\n", GetLastError());
635 WaitForSingleObject(thread_handle
, INFINITE
);
636 ok(thread_params
.hglrc_deleted
== FALSE
, "Attempt to delete WGL context from another thread passed but should fail!\n");
638 CloseHandle(thread_params
.test_finished
);
640 res
= wglDeleteContext(hglrc
);
641 ok(res
== TRUE
, "wglDeleteContext failed\n");
643 /* WGL makes a context not current when deleting it. This differs from GLX behavior where
644 * deletion takes place when the thread becomes not current. */
645 hglrc
= wglGetCurrentContext();
646 ok(hglrc
== NULL
, "A WGL context is active while none was expected\n");
649 static void test_make_current_read(HDC hdc
)
653 HGLRC hglrc
= wglCreateContext(hdc
);
657 skip("wglCreateContext failed!\n");
661 res
= wglMakeCurrent(hdc
, hglrc
);
664 skip("wglMakeCurrent failed!\n");
668 /* Test what wglGetCurrentReadDCARB does for wglMakeCurrent as the spec doesn't mention it */
669 hread
= pwglGetCurrentReadDCARB();
670 trace("hread %p, hdc %p\n", hread
, hdc
);
671 ok(hread
== hdc
, "wglGetCurrentReadDCARB failed for standard wglMakeCurrent\n");
673 pwglMakeContextCurrentARB(hdc
, hdc
, hglrc
);
674 hread
= pwglGetCurrentReadDCARB();
675 ok(hread
== hdc
, "wglGetCurrentReadDCARB failed for wglMakeContextCurrent\n");
678 static void test_dc(HWND hwnd
, HDC hdc
)
683 /* Get another DC and make sure it has the same pixel format */
687 pf1
= GetPixelFormat(hdc
);
688 pf2
= GetPixelFormat(hdc2
);
689 ok(pf1
== pf2
, "Second DC does not have the same format (%d != %d)\n", pf1
, pf2
);
692 skip("Could not get a different DC for the window\n");
696 ReleaseDC(hwnd
, hdc2
);
701 /* Nvidia converts win32 error codes to (0xc007 << 16) | win32_error_code */
702 #define NVIDIA_HRESULT_FROM_WIN32(x) (HRESULT_FROM_WIN32(x) | 0x40000000)
703 static void test_opengl3(HDC hdc
)
705 /* Try to create a context compatible with OpenGL 1.x; 1.0-2.1 is allowed */
708 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 1, 0};
710 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
711 ok(gl3Ctx
!= 0, "pwglCreateContextAttribsARB for a 1.x context failed!\n");
712 wglDeleteContext(gl3Ctx
);
715 /* Try to pass an invalid HDC */
719 gl3Ctx
= pwglCreateContextAttribsARB((HDC
)0xdeadbeef, 0, 0);
720 ok(gl3Ctx
== 0, "pwglCreateContextAttribsARB using an invalid HDC passed\n");
721 error
= GetLastError();
722 todo_wine
ok(error
== ERROR_DC_NOT_FOUND
||
723 broken(error
== NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_DATA
)), /* Nvidia Vista + Win7 */
724 "Expected ERROR_DC_NOT_FOUND, got error=%x\n", error
);
725 wglDeleteContext(gl3Ctx
);
728 /* Try to pass an invalid shareList */
732 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, (HGLRC
)0xdeadbeef, 0);
733 todo_wine
ok(gl3Ctx
== 0, "pwglCreateContextAttribsARB using an invalid shareList passed\n");
734 error
= GetLastError();
735 /* The Nvidia implementation seems to return hresults instead of win32 error codes */
736 todo_wine
ok(error
== ERROR_INVALID_OPERATION
||
737 error
== NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_OPERATION
), "Expected ERROR_INVALID_OPERATION, got error=%x\n", error
);
738 wglDeleteContext(gl3Ctx
);
741 /* Try to create an OpenGL 3.0 context */
743 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
744 HGLRC gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
748 skip("Skipping the rest of the WGL_ARB_create_context test due to lack of OpenGL 3.0\n");
752 wglDeleteContext(gl3Ctx
);
755 /* 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 */
757 HGLRC glCtx
= wglCreateContext(hdc
);
759 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
760 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};
762 HGLRC gl3Ctx
= pwglCreateContextAttribsARB(hdc
, glCtx
, attribs
);
763 ok(gl3Ctx
!= NULL
, "Sharing of a display list between OpenGL 3.0 and OpenGL 1.x/2.x failed!\n");
765 wglDeleteContext(gl3Ctx
);
767 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, glCtx
, attribs_future
);
768 ok(gl3Ctx
!= NULL
, "Sharing of a display list between a forward compatible OpenGL 3.0 context and OpenGL 1.x/2.x failed!\n");
770 wglDeleteContext(gl3Ctx
);
773 wglDeleteContext(glCtx
);
776 /* Try to create an OpenGL 3.0 context and test windowless rendering */
779 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
782 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
783 ok(gl3Ctx
!= 0, "pwglCreateContextAttribsARB for a 3.0 context failed!\n");
785 /* OpenGL 3.0 allows offscreen rendering WITHOUT a drawable
786 * Neither AMD or Nvidia support it at this point. The WGL_ARB_create_context specs also say that
787 * it is hard because drivers use the HDC to enter the display driver and it sounds like they don't
788 * expect drivers to ever offer it.
790 res
= wglMakeCurrent(0, gl3Ctx
);
791 ok(res
== FALSE
, "Wow, OpenGL 3.0 windowless rendering passed while it was expected not to!\n");
793 wglMakeCurrent(0, 0);
796 wglDeleteContext(gl3Ctx
);
800 static void test_minimized(void)
802 PIXELFORMATDESCRIPTOR pf_desc
=
804 sizeof(PIXELFORMATDESCRIPTOR
),
806 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
808 24, /* 24-bit color depth */
809 0, 0, 0, 0, 0, 0, /* color bits */
810 0, /* alpha buffer */
812 0, /* accumulation buffer */
813 0, 0, 0, 0, /* accum bits */
815 0, /* stencil buffer */
816 0, /* auxiliary buffer */
817 PFD_MAIN_PLANE
, /* main layer */
819 0, 0, 0 /* layer masks */
828 window
= CreateWindowA("static", "opengl32_test",
829 WS_POPUP
| WS_MINIMIZE
, 0, 0, 640, 480, 0, 0, 0, 0);
830 ok(!!window
, "Failed to create window, last error %#x.\n", GetLastError());
833 ok(!!dc
, "Failed to get DC.\n");
835 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
838 win_skip("Failed to find pixel format.\n");
839 ReleaseDC(window
, dc
);
840 DestroyWindow(window
);
844 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
845 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
847 style
= GetWindowLongA(window
, GWL_STYLE
);
848 ok(style
& WS_MINIMIZE
, "Window should be minimized, got style %#x.\n", style
);
850 ctx
= wglCreateContext(dc
);
851 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
853 ret
= wglMakeCurrent(dc
, ctx
);
854 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
856 style
= GetWindowLongA(window
, GWL_STYLE
);
857 ok(style
& WS_MINIMIZE
, "window should be minimized, got style %#x.\n", style
);
859 ret
= wglMakeCurrent(NULL
, NULL
);
860 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
862 ret
= wglDeleteContext(ctx
);
863 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
865 ReleaseDC(window
, dc
);
866 DestroyWindow(window
);
872 PIXELFORMATDESCRIPTOR pfd
= {
873 sizeof(PIXELFORMATDESCRIPTOR
),
879 24, /* 24-bit color depth */
880 0, 0, 0, 0, 0, 0, /* color bits */
881 0, /* alpha buffer */
883 0, /* accumulation buffer */
884 0, 0, 0, 0, /* accum bits */
886 0, /* stencil buffer */
887 0, /* auxiliary buffer */
888 PFD_MAIN_PLANE
, /* main layer */
890 0, 0, 0 /* layer masks */
893 hwnd
= CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW
,
894 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
895 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
899 int iPixelFormat
, res
;
902 ShowWindow(hwnd
, SW_SHOW
);
906 iPixelFormat
= ChoosePixelFormat(hdc
, &pfd
);
907 if(iPixelFormat
== 0)
909 /* This should never happen as ChoosePixelFormat always returns a closest match, but currently this fails in Wine if we don't have glX */
910 win_skip("Unable to find pixel format.\n");
914 /* We shouldn't be able to create a context from a hdc which doesn't have a pixel format set */
915 hglrc
= wglCreateContext(hdc
);
916 ok(hglrc
== NULL
, "wglCreateContext should fail when no pixel format has been set, but it passed\n");
917 error
= GetLastError();
918 ok(error
== ERROR_INVALID_PIXEL_FORMAT
, "expected ERROR_INVALID_PIXEL_FORMAT for wglCreateContext without a pixelformat set, but received %#x\n", error
);
920 res
= SetPixelFormat(hdc
, iPixelFormat
, &pfd
);
921 ok(res
, "SetPixelformat failed: %x\n", GetLastError());
923 test_bitmap_rendering();
927 hglrc
= wglCreateContext(hdc
);
928 res
= wglMakeCurrent(hdc
, hglrc
);
929 ok(res
, "wglMakeCurrent failed!\n");
932 trace("OpenGL renderer: %s\n", glGetString(GL_RENDERER
));
933 trace("OpenGL driver version: %s\n", glGetString(GL_VERSION
));
934 trace("OpenGL vendor: %s\n", glGetString(GL_VENDOR
));
938 skip("Skipping OpenGL tests without a current context\n");
942 /* Initialisation of WGL functions depends on an implicit WGL context. For this reason we can't load them before making
943 * any WGL call :( On Wine this would work but not on real Windows because there can be different implementations (software, ICD, MCD).
946 /* The lack of wglGetExtensionsStringARB in general means broken software rendering or the lack of decent OpenGL support, skip tests in such cases */
947 if (!pwglGetExtensionsStringARB
)
949 win_skip("wglGetExtensionsStringARB is not available\n");
953 test_deletecontext(hdc
);
954 test_makecurrent(hdc
);
955 test_setpixelformat(hdc
);
956 test_sharelists(hdc
);
959 test_acceleration(hdc
);
961 wgl_extensions
= pwglGetExtensionsStringARB(hdc
);
962 if(wgl_extensions
== NULL
) skip("Skipping opengl32 tests because this OpenGL implementation doesn't support WGL extensions!\n");
964 if(strstr(wgl_extensions
, "WGL_ARB_create_context"))
967 if(strstr(wgl_extensions
, "WGL_ARB_make_current_read"))
968 test_make_current_read(hdc
);
970 skip("WGL_ARB_make_current_read not supported, skipping test\n");
972 if(strstr(wgl_extensions
, "WGL_ARB_pbuffer"))
975 skip("WGL_ARB_pbuffer not supported, skipping pbuffer test\n");
978 ReleaseDC(hwnd
, hdc
);