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 #define GL_COLOR 0x1800
28 typedef unsigned int GLenum
;
30 void WINAPI
glCopyPixels(int x
, int y
, int width
, int height
, GLenum type
);
31 void WINAPI
glFinish(void);
32 #define GL_NO_ERROR 0x0
33 #define GL_INVALID_OPERATION 0x502
34 GLenum WINAPI
glGetError(void);
35 #define GL_COLOR_BUFFER_BIT 0x00004000
36 const unsigned char * WINAPI
glGetString(unsigned int);
37 #define GL_VENDOR 0x1F00
38 #define GL_RENDERER 0x1F01
39 #define GL_VERSION 0x1F02
41 #define GL_VIEWPORT 0x0ba2
42 void WINAPI
glGetIntegerv(GLenum pname
, GLint
*params
);
44 #define MAX_FORMATS 256
45 typedef void* HPBUFFERARB
;
47 /* WGL_ARB_create_context */
48 static HGLRC (WINAPI
*pwglCreateContextAttribsARB
)(HDC hDC
, HGLRC hShareContext
, const int *attribList
);
50 #define ERROR_INVALID_VERSION_ARB 0x2095
51 #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
52 #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
53 #define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
54 #define WGL_CONTEXT_FLAGS_ARB 0x2094
55 /* Flags for WGL_CONTEXT_FLAGS_ARB */
56 #define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
57 #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
59 /* WGL_ARB_extensions_string */
60 static const char* (WINAPI
*pwglGetExtensionsStringARB
)(HDC
);
61 static int (WINAPI
*pwglReleasePbufferDCARB
)(HPBUFFERARB
, HDC
);
63 /* WGL_ARB_make_current_read */
64 static BOOL (WINAPI
*pwglMakeContextCurrentARB
)(HDC hdraw
, HDC hread
, HGLRC hglrc
);
65 static HDC (WINAPI
*pwglGetCurrentReadDCARB
)(void);
67 /* WGL_ARB_pixel_format */
68 #define WGL_ACCELERATION_ARB 0x2003
69 #define WGL_COLOR_BITS_ARB 0x2014
70 #define WGL_RED_BITS_ARB 0x2015
71 #define WGL_GREEN_BITS_ARB 0x2017
72 #define WGL_BLUE_BITS_ARB 0x2019
73 #define WGL_ALPHA_BITS_ARB 0x201B
74 #define WGL_SUPPORT_GDI_ARB 0x200F
75 #define WGL_DOUBLE_BUFFER_ARB 0x2011
76 #define WGL_NO_ACCELERATION_ARB 0x2025
77 #define WGL_GENERIC_ACCELERATION_ARB 0x2026
78 #define WGL_FULL_ACCELERATION_ARB 0x2027
80 static BOOL (WINAPI
*pwglChoosePixelFormatARB
)(HDC
, const int *, const FLOAT
*, UINT
, int *, UINT
*);
81 static BOOL (WINAPI
*pwglGetPixelFormatAttribivARB
)(HDC
, int, int, UINT
, const int *, int *);
84 #define WGL_DRAW_TO_PBUFFER_ARB 0x202D
85 static HPBUFFERARB
* (WINAPI
*pwglCreatePbufferARB
)(HDC
, int, int, int, const int *);
86 static HDC (WINAPI
*pwglGetPbufferDCARB
)(HPBUFFERARB
);
88 static const char* wgl_extensions
= NULL
;
90 static void init_functions(void)
92 #define GET_PROC(func) \
93 p ## func = (void*)wglGetProcAddress(#func); \
95 trace("wglGetProcAddress(%s) failed\n", #func);
97 /* WGL_ARB_create_context */
98 GET_PROC(wglCreateContextAttribsARB
);
100 /* WGL_ARB_extensions_string */
101 GET_PROC(wglGetExtensionsStringARB
)
103 /* WGL_ARB_make_current_read */
104 GET_PROC(wglMakeContextCurrentARB
);
105 GET_PROC(wglGetCurrentReadDCARB
);
107 /* WGL_ARB_pixel_format */
108 GET_PROC(wglChoosePixelFormatARB
)
109 GET_PROC(wglGetPixelFormatAttribivARB
)
111 /* WGL_ARB_pbuffer */
112 GET_PROC(wglCreatePbufferARB
)
113 GET_PROC(wglGetPbufferDCARB
)
114 GET_PROC(wglReleasePbufferDCARB
)
119 static void test_pbuffers(HDC hdc
)
121 const int iAttribList
[] = { WGL_DRAW_TO_PBUFFER_ARB
, 1, /* Request pbuffer support */
123 int iFormats
[MAX_FORMATS
];
124 unsigned int nOnscreenFormats
;
125 unsigned int nFormats
;
127 int iPixelFormat
= 0;
129 nOnscreenFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
131 /* When you want to render to a pbuffer you need to call wglGetPbufferDCARB which
132 * returns a 'magic' HDC which you can then pass to wglMakeCurrent to switch rendering
133 * to the pbuffer. Below some tests are performed on what happens if you use standard WGL calls
134 * on this 'magic' HDC for both a pixelformat that support onscreen and offscreen rendering
135 * and a pixelformat that's only available for offscreen rendering (this means that only
136 * wglChoosePixelFormatARB and friends know about the format.
138 * The first thing we need are pixelformats with pbuffer capabilities.
140 res
= pwglChoosePixelFormatARB(hdc
, iAttribList
, NULL
, MAX_FORMATS
, iFormats
, &nFormats
);
143 skip("No pbuffer compatible formats found while WGL_ARB_pbuffer is supported\n");
146 trace("nOnscreenFormats: %d\n", nOnscreenFormats
);
147 trace("Total number of pbuffer capable pixelformats: %d\n", nFormats
);
149 /* Try to select an onscreen pixelformat out of the list */
150 for(i
=0; i
< nFormats
; i
++)
152 /* Check if the format is onscreen, if it is choose it */
153 if(iFormats
[i
] <= nOnscreenFormats
)
155 iPixelFormat
= iFormats
[i
];
156 trace("Selected iPixelFormat=%d\n", iPixelFormat
);
161 /* A video driver supports a large number of onscreen and offscreen pixelformats.
162 * The traditional WGL calls only see a subset of the whole pixelformat list. First
163 * of all they only see the onscreen formats (the offscreen formats are at the end of the
164 * pixelformat list) and second extended pixelformat capabilities are hidden from the
165 * standard WGL calls. Only functions that depend on WGL_ARB_pixel_format can see them.
167 * Below we check if the pixelformat is also supported onscreen.
169 if(iPixelFormat
!= 0)
172 HPBUFFERARB pbuffer
= pwglCreatePbufferARB(hdc
, iPixelFormat
, 640 /* width */, 480 /* height */, NULL
);
174 skip("Pbuffer creation failed!\n");
176 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
177 pbuffer_hdc
= pwglGetPbufferDCARB(pbuffer
);
178 res
= GetPixelFormat(pbuffer_hdc
);
179 ok(res
== iPixelFormat
, "Unexpected iPixelFormat=%d returned by GetPixelFormat for format %d\n", res
, iPixelFormat
);
180 trace("iPixelFormat returned by GetPixelFormat: %d\n", res
);
181 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat
);
183 pwglReleasePbufferDCARB(pbuffer
, hdc
);
185 else skip("Pbuffer test for onscreen pixelformat skipped as no onscreen format with pbuffer capabilities have been found\n");
187 /* Search for a real offscreen format */
188 for(i
=0, iPixelFormat
=0; i
<nFormats
; i
++)
190 if(iFormats
[i
] > nOnscreenFormats
)
192 iPixelFormat
= iFormats
[i
];
193 trace("Selected iPixelFormat: %d\n", iPixelFormat
);
198 if(iPixelFormat
!= 0)
201 HPBUFFERARB pbuffer
= pwglCreatePbufferARB(hdc
, iPixelFormat
, 640 /* width */, 480 /* height */, NULL
);
203 skip("Pbuffer creation failed!\n");
205 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
206 pbuffer_hdc
= pwglGetPbufferDCARB(pbuffer
);
207 res
= GetPixelFormat(pbuffer_hdc
);
209 ok(res
== 1, "Unexpected iPixelFormat=%d (1 expected) returned by GetPixelFormat for offscreen format %d\n", res
, iPixelFormat
);
210 trace("iPixelFormat returned by GetPixelFormat: %d\n", res
);
211 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat
);
212 pwglReleasePbufferDCARB(pbuffer
, hdc
);
214 else skip("Pbuffer test for offscreen pixelformat skipped as no offscreen-only format with pbuffer capabilities has been found\n");
217 static void test_setpixelformat(HDC winhdc
)
224 PIXELFORMATDESCRIPTOR pfd
= {
225 sizeof(PIXELFORMATDESCRIPTOR
),
231 24, /* 24-bit color depth */
232 0, 0, 0, 0, 0, 0, /* color bits */
233 0, /* alpha buffer */
235 0, /* accumulation buffer */
236 0, 0, 0, 0, /* accum bits */
238 0, /* stencil buffer */
239 0, /* auxiliary buffer */
240 PFD_MAIN_PLANE
, /* main layer */
242 0, 0, 0 /* layer masks */
246 ok(hdc
!= 0, "GetDC(0) failed!\n");
248 /* This should pass even on the main device context */
249 pf
= ChoosePixelFormat(hdc
, &pfd
);
250 ok(pf
!= 0, "ChoosePixelFormat failed on main device context\n");
252 /* SetPixelFormat on the main device context 'X root window' should fail,
253 * but some broken drivers allow it
255 res
= SetPixelFormat(hdc
, pf
, &pfd
);
256 trace("SetPixelFormat on main device context %s\n", res
? "succeeded" : "failed");
258 /* Setting the same format that was set on the HDC is allowed; other
260 nCfgs
= DescribePixelFormat(winhdc
, 0, 0, NULL
);
261 pf
= GetPixelFormat(winhdc
);
262 for(i
= 1;i
<= nCfgs
;i
++)
264 int res
= SetPixelFormat(winhdc
, i
, NULL
);
265 if(i
== pf
) ok(res
, "Failed to set the same pixel format\n");
266 else ok(!res
, "Unexpectedly set an alternate pixel format\n");
269 hwnd
= CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW
,
270 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
271 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
274 HDC hdc
= GetDC( hwnd
);
275 pf
= ChoosePixelFormat( hdc
, &pfd
);
276 ok( pf
!= 0, "ChoosePixelFormat failed\n" );
277 res
= SetPixelFormat( hdc
, pf
, &pfd
);
278 ok( res
!= 0, "SetPixelFormat failed\n" );
279 i
= GetPixelFormat( hdc
);
280 ok( i
== pf
, "GetPixelFormat returned wrong format %d/%d\n", i
, pf
);
281 ReleaseDC( hwnd
, hdc
);
282 hdc
= GetWindowDC( hwnd
);
283 i
= GetPixelFormat( hdc
);
284 ok( i
== pf
, "GetPixelFormat returned wrong format %d/%d\n", i
, pf
);
285 ReleaseDC( hwnd
, hdc
);
286 DestroyWindow( hwnd
);
289 hwnd
= CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW
,
290 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
291 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
294 HDC hdc
= GetWindowDC( hwnd
);
295 pf
= ChoosePixelFormat( hdc
, &pfd
);
296 ok( pf
!= 0, "ChoosePixelFormat failed\n" );
297 res
= SetPixelFormat( hdc
, pf
, &pfd
);
298 ok( res
!= 0, "SetPixelFormat failed\n" );
299 i
= GetPixelFormat( hdc
);
300 ok( i
== pf
, "GetPixelFormat returned wrong format %d/%d\n", i
, pf
);
301 ReleaseDC( hwnd
, hdc
);
302 DestroyWindow( hwnd
);
306 static void test_sharelists(HDC winhdc
)
308 HGLRC hglrc1
, hglrc2
, hglrc3
;
311 hglrc1
= wglCreateContext(winhdc
);
312 res
= wglShareLists(0, 0);
313 ok(res
== FALSE
, "Sharing display lists for no contexts passed!\n");
315 /* Test 1: Create a context and just share lists without doing anything special */
316 hglrc2
= wglCreateContext(winhdc
);
319 res
= wglShareLists(hglrc1
, hglrc2
);
320 ok(res
, "Sharing of display lists failed\n");
321 wglDeleteContext(hglrc2
);
324 /* Test 2: Share display lists with a 'destination' context which has been made current */
325 hglrc2
= wglCreateContext(winhdc
);
328 res
= wglMakeCurrent(winhdc
, hglrc2
);
329 ok(res
, "Make current failed\n");
330 res
= wglShareLists(hglrc1
, hglrc2
);
331 todo_wine
ok(res
, "Sharing display lists with a destination context which has been made current failed\n");
332 wglMakeCurrent(0, 0);
333 wglDeleteContext(hglrc2
);
336 /* Test 3: Share display lists with a context which already shares display lists with another context.
337 * According to MSDN the second parameter cannot share any display lists but some buggy drivers might allow it */
338 hglrc3
= wglCreateContext(winhdc
);
341 res
= wglShareLists(hglrc3
, hglrc1
);
342 ok(res
== FALSE
, "Sharing of display lists passed for a context which already shared lists before\n");
343 wglDeleteContext(hglrc3
);
346 /* Test 4: Share display lists with a 'source' context which has been made current */
347 hglrc2
= wglCreateContext(winhdc
);
350 res
= wglMakeCurrent(winhdc
, hglrc1
);
351 ok(res
, "Make current failed\n");
352 res
= wglShareLists(hglrc1
, hglrc2
);
353 ok(res
, "Sharing display lists with a source context which has been made current failed\n");
354 wglMakeCurrent(0, 0);
355 wglDeleteContext(hglrc2
);
359 static void test_makecurrent(HDC winhdc
)
365 hglrc
= wglCreateContext(winhdc
);
366 ok( hglrc
!= 0, "wglCreateContext failed\n" );
368 ret
= wglMakeCurrent( winhdc
, hglrc
);
369 ok( ret
, "wglMakeCurrent failed\n" );
371 ok( wglGetCurrentContext() == hglrc
, "wrong context\n" );
373 /* set the same context again */
374 ret
= wglMakeCurrent( winhdc
, hglrc
);
375 ok( ret
, "wglMakeCurrent failed\n" );
377 /* check wglMakeCurrent(x, y) after another call to wglMakeCurrent(x, y) */
378 ret
= wglMakeCurrent( winhdc
, NULL
);
379 ok( ret
, "wglMakeCurrent failed\n" );
381 ret
= wglMakeCurrent( winhdc
, NULL
);
382 ok( ret
, "wglMakeCurrent failed\n" );
384 SetLastError( 0xdeadbeef );
385 ret
= wglMakeCurrent( NULL
, NULL
);
386 ok( !ret
, "wglMakeCurrent succeeded\n" );
387 error
= GetLastError();
388 ok( error
== ERROR_INVALID_HANDLE
, "Expected ERROR_INVALID_HANDLE, got error=%x\n", error
);
390 ret
= wglMakeCurrent( winhdc
, NULL
);
391 ok( ret
, "wglMakeCurrent failed\n" );
393 ret
= wglMakeCurrent( winhdc
, hglrc
);
394 ok( ret
, "wglMakeCurrent failed\n" );
396 ret
= wglMakeCurrent( NULL
, NULL
);
397 ok( ret
, "wglMakeCurrent failed\n" );
399 ok( wglGetCurrentContext() == NULL
, "wrong context\n" );
401 SetLastError( 0xdeadbeef );
402 ret
= wglMakeCurrent( NULL
, NULL
);
403 ok( !ret
, "wglMakeCurrent succeeded\n" );
404 error
= GetLastError();
405 ok( error
== ERROR_INVALID_HANDLE
, "Expected ERROR_INVALID_HANDLE, got error=%x\n", error
);
407 ret
= wglMakeCurrent( winhdc
, hglrc
);
408 ok( ret
, "wglMakeCurrent failed\n" );
411 static void test_colorbits(HDC hdc
)
413 const int iAttribList
[] = { WGL_COLOR_BITS_ARB
, WGL_RED_BITS_ARB
, WGL_GREEN_BITS_ARB
,
414 WGL_BLUE_BITS_ARB
, WGL_ALPHA_BITS_ARB
};
415 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
416 const int iAttribs
[] = { WGL_ALPHA_BITS_ARB
, 1, 0 };
417 unsigned int nFormats
;
419 int iPixelFormat
= 0;
421 if (!pwglChoosePixelFormatARB
)
423 win_skip("wglChoosePixelFormatARB is not available\n");
427 /* We need a pixel format with at least one bit of alpha */
428 res
= pwglChoosePixelFormatARB(hdc
, iAttribs
, NULL
, 1, &iPixelFormat
, &nFormats
);
429 if(res
== FALSE
|| nFormats
== 0)
431 skip("No suitable pixel formats found\n");
435 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
436 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
, iAttribRet
);
439 skip("wglGetPixelFormatAttribivARB failed\n");
442 iAttribRet
[1] += iAttribRet
[2]+iAttribRet
[3]+iAttribRet
[4];
443 ok(iAttribRet
[0] == iAttribRet
[1], "WGL_COLOR_BITS_ARB (%d) does not equal R+G+B+A (%d)!\n",
444 iAttribRet
[0], iAttribRet
[1]);
447 static void test_gdi_dbuf(HDC hdc
)
449 const int iAttribList
[] = { WGL_SUPPORT_GDI_ARB
, WGL_DOUBLE_BUFFER_ARB
};
450 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
451 unsigned int nFormats
;
455 if (!pwglGetPixelFormatAttribivARB
)
457 win_skip("wglGetPixelFormatAttribivARB is not available\n");
461 nFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
462 for(iPixelFormat
= 1;iPixelFormat
<= nFormats
;iPixelFormat
++)
464 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
465 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
,
467 ok(res
!=FALSE
, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat
);
471 ok(!(iAttribRet
[0] && iAttribRet
[1]), "GDI support and double buffering on pixel format %d\n", iPixelFormat
);
475 static void test_acceleration(HDC hdc
)
477 const int iAttribList
[] = { WGL_ACCELERATION_ARB
};
478 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
479 unsigned int nFormats
;
482 PIXELFORMATDESCRIPTOR pfd
;
484 if (!pwglGetPixelFormatAttribivARB
)
486 win_skip("wglGetPixelFormatAttribivARB is not available\n");
490 nFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
491 for(iPixelFormat
= 1; iPixelFormat
<= nFormats
; iPixelFormat
++)
493 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
494 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
,
496 ok(res
!=FALSE
, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat
);
500 memset(&pfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
501 DescribePixelFormat(hdc
, iPixelFormat
, sizeof(PIXELFORMATDESCRIPTOR
), &pfd
);
503 switch(iAttribRet
[0])
505 case WGL_NO_ACCELERATION_ARB
:
506 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
);
508 case WGL_GENERIC_ACCELERATION_ARB
:
509 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
);
511 case WGL_FULL_ACCELERATION_ARB
:
512 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
);
518 static void test_bitmap_rendering(void)
520 PIXELFORMATDESCRIPTOR pfd
;
521 int i
, iPixelFormat
=0;
522 unsigned int nFormats
;
525 HBITMAP bmpDst
, oldDst
;
526 HDC hdcDst
, hdcScreen
;
529 memset(&biDst
, 0, sizeof(BITMAPINFO
));
530 biDst
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
531 biDst
.bmiHeader
.biWidth
= 2;
532 biDst
.bmiHeader
.biHeight
= -2;
533 biDst
.bmiHeader
.biPlanes
= 1;
534 biDst
.bmiHeader
.biBitCount
= 32;
535 biDst
.bmiHeader
.biCompression
= BI_RGB
;
537 hdcScreen
= CreateCompatibleDC(0);
538 if(GetDeviceCaps(hdcScreen
, BITSPIXEL
) != 32)
541 trace("Skipping bitmap rendering test\n");
545 hdcDst
= CreateCompatibleDC(hdcScreen
);
546 bmpDst
= CreateDIBSection(hdcDst
, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
, NULL
, 0);
547 oldDst
= SelectObject(hdcDst
, bmpDst
);
549 /* Pick a pixel format by hand because ChoosePixelFormat is unreliable */
550 nFormats
= DescribePixelFormat(hdcDst
, 0, 0, NULL
);
551 for(i
=1; i
<=nFormats
; i
++)
553 memset(&pfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
554 DescribePixelFormat(hdcDst
, i
, sizeof(PIXELFORMATDESCRIPTOR
), &pfd
);
556 if((pfd
.dwFlags
& PFD_DRAW_TO_BITMAP
) &&
557 (pfd
.dwFlags
& PFD_SUPPORT_OPENGL
) &&
558 (pfd
.cColorBits
== 32) &&
559 (pfd
.cAlphaBits
== 8) )
568 skip("Unable to find a suitable pixel format\n");
572 SetPixelFormat(hdcDst
, iPixelFormat
, &pfd
);
573 hglrc
= wglCreateContext(hdcDst
);
574 todo_wine
ok(hglrc
!= NULL
, "Unable to create a context\n");
578 wglMakeCurrent(hdcDst
, hglrc
);
580 /* Note this is RGBA but we read ARGB back */
581 glClearColor((float)0x22/0xff, (float)0x33/0xff, (float)0x44/0xff, (float)0x11/0xff);
582 glClear(GL_COLOR_BUFFER_BIT
);
585 /* Note apparently the alpha channel is not supported by the software renderer (bitmap only works using software) */
586 ok(dstBuffer
[0] == 0x223344, "Expected color=0x223344, received color=%x\n", dstBuffer
[0]);
588 wglMakeCurrent(NULL
, NULL
);
589 wglDeleteContext(hglrc
);
593 SelectObject(hdcDst
, oldDst
);
594 DeleteObject(bmpDst
);
600 struct wgl_thread_param
602 HANDLE test_finished
;
608 static DWORD WINAPI
wgl_thread(void *param
)
610 struct wgl_thread_param
*p
= param
;
612 SetLastError(0xdeadbeef);
613 p
->hglrc_deleted
= wglDeleteContext(p
->hglrc
);
614 p
->last_error
= GetLastError();
615 SetEvent(p
->test_finished
);
620 static void test_deletecontext(HDC hdc
)
622 struct wgl_thread_param thread_params
;
623 HGLRC hglrc
= wglCreateContext(hdc
);
624 HANDLE thread_handle
;
627 SetLastError(0xdeadbeef);
628 res
= wglDeleteContext(NULL
);
629 ok(res
== FALSE
, "wglDeleteContext succeeded\n");
630 ok(GetLastError() == ERROR_INVALID_HANDLE
, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
634 skip("wglCreateContext failed!\n");
638 res
= wglMakeCurrent(hdc
, hglrc
);
641 skip("wglMakeCurrent failed!\n");
645 /* WGL doesn't allow you to delete a context from a different thread than the one in which it is current.
646 * This differs from GLX which does allow it but it delays actual deletion until the context becomes not current.
648 thread_params
.hglrc
= hglrc
;
649 thread_params
.test_finished
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
650 thread_handle
= CreateThread(NULL
, 0, wgl_thread
, &thread_params
, 0, &tid
);
651 ok(!!thread_handle
, "Failed to create thread, last error %#x.\n", GetLastError());
654 WaitForSingleObject(thread_handle
, INFINITE
);
655 ok(thread_params
.hglrc_deleted
== FALSE
, "Attempt to delete WGL context from another thread passed but should fail!\n");
656 ok(thread_params
.last_error
== ERROR_BUSY
, "Expected last error to be ERROR_BUSY, got %u\n", thread_params
.last_error
);
658 CloseHandle(thread_params
.test_finished
);
660 res
= wglDeleteContext(hglrc
);
661 ok(res
== TRUE
, "wglDeleteContext failed\n");
663 /* Attempting to delete the same context twice should fail. */
664 SetLastError(0xdeadbeef);
665 res
= wglDeleteContext(hglrc
);
666 ok(res
== FALSE
, "wglDeleteContext succeeded\n");
667 ok(GetLastError() == ERROR_INVALID_HANDLE
, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
669 /* WGL makes a context not current when deleting it. This differs from GLX behavior where
670 * deletion takes place when the thread becomes not current. */
671 hglrc
= wglGetCurrentContext();
672 ok(hglrc
== NULL
, "A WGL context is active while none was expected\n");
675 static void test_make_current_read(HDC hdc
)
679 HGLRC hglrc
= wglCreateContext(hdc
);
683 skip("wglCreateContext failed!\n");
687 res
= wglMakeCurrent(hdc
, hglrc
);
690 skip("wglMakeCurrent failed!\n");
694 /* Test what wglGetCurrentReadDCARB does for wglMakeCurrent as the spec doesn't mention it */
695 hread
= pwglGetCurrentReadDCARB();
696 trace("hread %p, hdc %p\n", hread
, hdc
);
697 ok(hread
== hdc
, "wglGetCurrentReadDCARB failed for standard wglMakeCurrent\n");
699 pwglMakeContextCurrentARB(hdc
, hdc
, hglrc
);
700 hread
= pwglGetCurrentReadDCARB();
701 ok(hread
== hdc
, "wglGetCurrentReadDCARB failed for wglMakeContextCurrent\n");
704 static void test_dc(HWND hwnd
, HDC hdc
)
709 /* Get another DC and make sure it has the same pixel format */
713 pf1
= GetPixelFormat(hdc
);
714 pf2
= GetPixelFormat(hdc2
);
715 ok(pf1
== pf2
, "Second DC does not have the same format (%d != %d)\n", pf1
, pf2
);
718 skip("Could not get a different DC for the window\n");
722 ReleaseDC(hwnd
, hdc2
);
727 /* Nvidia converts win32 error codes to (0xc007 << 16) | win32_error_code */
728 #define NVIDIA_HRESULT_FROM_WIN32(x) (HRESULT_FROM_WIN32(x) | 0x40000000)
729 static void test_opengl3(HDC hdc
)
731 /* Try to create a context compatible with OpenGL 1.x; 1.0-2.1 is allowed */
734 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 1, 0};
736 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
737 ok(gl3Ctx
!= 0, "pwglCreateContextAttribsARB for a 1.x context failed!\n");
738 wglDeleteContext(gl3Ctx
);
741 /* Try to pass an invalid HDC */
745 gl3Ctx
= pwglCreateContextAttribsARB((HDC
)0xdeadbeef, 0, 0);
746 ok(gl3Ctx
== 0, "pwglCreateContextAttribsARB using an invalid HDC passed\n");
747 error
= GetLastError();
748 todo_wine
ok(error
== ERROR_DC_NOT_FOUND
||
749 broken(error
== NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_DATA
)), /* Nvidia Vista + Win7 */
750 "Expected ERROR_DC_NOT_FOUND, got error=%x\n", error
);
751 wglDeleteContext(gl3Ctx
);
754 /* Try to pass an invalid shareList */
758 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, (HGLRC
)0xdeadbeef, 0);
759 todo_wine
ok(gl3Ctx
== 0, "pwglCreateContextAttribsARB using an invalid shareList passed\n");
760 error
= GetLastError();
761 /* The Nvidia implementation seems to return hresults instead of win32 error codes */
762 todo_wine
ok(error
== ERROR_INVALID_OPERATION
||
763 error
== NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_OPERATION
), "Expected ERROR_INVALID_OPERATION, got error=%x\n", error
);
764 wglDeleteContext(gl3Ctx
);
767 /* Try to create an OpenGL 3.0 context */
769 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
770 HGLRC gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
774 skip("Skipping the rest of the WGL_ARB_create_context test due to lack of OpenGL 3.0\n");
778 wglDeleteContext(gl3Ctx
);
781 /* 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 */
783 HGLRC glCtx
= wglCreateContext(hdc
);
785 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
786 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};
788 HGLRC gl3Ctx
= pwglCreateContextAttribsARB(hdc
, glCtx
, attribs
);
789 ok(gl3Ctx
!= NULL
, "Sharing of a display list between OpenGL 3.0 and OpenGL 1.x/2.x failed!\n");
791 wglDeleteContext(gl3Ctx
);
793 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, glCtx
, attribs_future
);
794 ok(gl3Ctx
!= NULL
, "Sharing of a display list between a forward compatible OpenGL 3.0 context and OpenGL 1.x/2.x failed!\n");
796 wglDeleteContext(gl3Ctx
);
799 wglDeleteContext(glCtx
);
802 /* Try to create an OpenGL 3.0 context and test windowless rendering */
805 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
808 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
809 ok(gl3Ctx
!= 0, "pwglCreateContextAttribsARB for a 3.0 context failed!\n");
811 /* OpenGL 3.0 allows offscreen rendering WITHOUT a drawable
812 * Neither AMD or Nvidia support it at this point. The WGL_ARB_create_context specs also say that
813 * it is hard because drivers use the HDC to enter the display driver and it sounds like they don't
814 * expect drivers to ever offer it.
816 res
= wglMakeCurrent(0, gl3Ctx
);
817 ok(res
== FALSE
, "Wow, OpenGL 3.0 windowless rendering passed while it was expected not to!\n");
819 wglMakeCurrent(0, 0);
822 wglDeleteContext(gl3Ctx
);
826 static void test_minimized(void)
828 PIXELFORMATDESCRIPTOR pf_desc
=
830 sizeof(PIXELFORMATDESCRIPTOR
),
832 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
834 24, /* 24-bit color depth */
835 0, 0, 0, 0, 0, 0, /* color bits */
836 0, /* alpha buffer */
838 0, /* accumulation buffer */
839 0, 0, 0, 0, /* accum bits */
841 0, /* stencil buffer */
842 0, /* auxiliary buffer */
843 PFD_MAIN_PLANE
, /* main layer */
845 0, 0, 0 /* layer masks */
854 window
= CreateWindowA("static", "opengl32_test",
855 WS_POPUP
| WS_MINIMIZE
, 0, 0, 640, 480, 0, 0, 0, 0);
856 ok(!!window
, "Failed to create window, last error %#x.\n", GetLastError());
859 ok(!!dc
, "Failed to get DC.\n");
861 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
864 win_skip("Failed to find pixel format.\n");
865 ReleaseDC(window
, dc
);
866 DestroyWindow(window
);
870 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
871 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
873 style
= GetWindowLongA(window
, GWL_STYLE
);
874 ok(style
& WS_MINIMIZE
, "Window should be minimized, got style %#x.\n", style
);
876 ctx
= wglCreateContext(dc
);
877 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
879 ret
= wglMakeCurrent(dc
, ctx
);
880 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
882 style
= GetWindowLongA(window
, GWL_STYLE
);
883 ok(style
& WS_MINIMIZE
, "window should be minimized, got style %#x.\n", style
);
885 ret
= wglMakeCurrent(NULL
, NULL
);
886 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
888 ret
= wglDeleteContext(ctx
);
889 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
891 ReleaseDC(window
, dc
);
892 DestroyWindow(window
);
895 static void test_window_dc(void)
897 PIXELFORMATDESCRIPTOR pf_desc
=
899 sizeof(PIXELFORMATDESCRIPTOR
),
901 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
903 24, /* 24-bit color depth */
904 0, 0, 0, 0, 0, 0, /* color bits */
905 0, /* alpha buffer */
907 0, /* accumulation buffer */
908 0, 0, 0, 0, /* accum bits */
910 0, /* stencil buffer */
911 0, /* auxiliary buffer */
912 PFD_MAIN_PLANE
, /* main layer */
914 0, 0, 0 /* layer masks */
923 window
= CreateWindowA("static", "opengl32_test",
924 WS_OVERLAPPEDWINDOW
, 0, 0, 640, 480, 0, 0, 0, 0);
925 ok(!!window
, "Failed to create window, last error %#x.\n", GetLastError());
927 ShowWindow(window
, SW_SHOW
);
929 dc
= GetWindowDC(window
);
930 ok(!!dc
, "Failed to get DC.\n");
932 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
935 win_skip("Failed to find pixel format.\n");
936 ReleaseDC(window
, dc
);
937 DestroyWindow(window
);
941 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
942 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
944 ctx
= wglCreateContext(dc
);
945 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
947 ret
= wglMakeCurrent(dc
, ctx
);
948 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
950 GetClientRect(window
, &r
);
951 glGetIntegerv(GL_VIEWPORT
, (GLint
*)&vp
);
952 ok(EqualRect(&r
, &vp
), "Viewport not equal to client rect.\n");
954 ret
= wglMakeCurrent(NULL
, NULL
);
955 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
957 ret
= wglDeleteContext(ctx
);
958 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
960 ReleaseDC(window
, dc
);
961 DestroyWindow(window
);
964 static void test_destroy(HDC oldhdc
)
966 PIXELFORMATDESCRIPTOR pf_desc
=
968 sizeof(PIXELFORMATDESCRIPTOR
),
970 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
972 24, /* 24-bit color depth */
973 0, 0, 0, 0, 0, 0, /* color bits */
974 0, /* alpha buffer */
976 0, /* accumulation buffer */
977 0, 0, 0, 0, /* accum bits */
979 0, /* stencil buffer */
980 0, /* auxiliary buffer */
981 PFD_MAIN_PLANE
, /* main layer */
983 0, 0, 0 /* layer masks */
992 HGLRC oldctx
= wglGetCurrentContext();
994 ok(!!oldctx
, "Expected to find a valid current context.\n");
996 window
= CreateWindowA("static", "opengl32_test",
997 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
998 ok(!!window
, "Failed to create window, last error %#x.\n", GetLastError());
1001 ok(!!dc
, "Failed to get DC.\n");
1003 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1006 win_skip("Failed to find pixel format.\n");
1007 ReleaseDC(window
, dc
);
1008 DestroyWindow(window
);
1012 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1013 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1015 ctx
= wglCreateContext(dc
);
1016 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1018 ret
= wglMakeCurrent(dc
, ctx
);
1019 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1021 glClear(GL_COLOR_BUFFER_BIT
);
1023 glerr
= glGetError();
1024 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1025 ret
= SwapBuffers(dc
);
1026 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1028 ret
= DestroyWindow(window
);
1029 ok(ret
, "Failed to destroy window, last error %#x.\n", GetLastError());
1031 ok(wglGetCurrentContext() == ctx
, "Wrong current context.\n");
1033 SetLastError(0xdeadbeef);
1034 ret
= wglMakeCurrent(dc
, ctx
);
1035 err
= GetLastError();
1036 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1037 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1038 SetLastError(0xdeadbeef);
1039 ret
= SwapBuffers(dc
);
1040 err
= GetLastError();
1041 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1043 ok(wglGetCurrentContext() == ctx
, "Wrong current context.\n");
1045 glClear(GL_COLOR_BUFFER_BIT
);
1047 glerr
= glGetError();
1048 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1049 SetLastError(0xdeadbeef);
1050 ret
= SwapBuffers(dc
);
1051 err
= GetLastError();
1052 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1054 ret
= wglMakeCurrent(NULL
, NULL
);
1055 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1057 glClear(GL_COLOR_BUFFER_BIT
);
1059 glerr
= glGetError();
1060 todo_wine
ok(glerr
== GL_INVALID_OPERATION
, "Failed glClear, error %#x.\n", glerr
);
1061 SetLastError(0xdeadbeef);
1062 ret
= SwapBuffers(dc
);
1063 err
= GetLastError();
1064 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1066 SetLastError(0xdeadbeef);
1067 ret
= wglMakeCurrent(dc
, ctx
);
1068 err
= GetLastError();
1069 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1070 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1072 ok(wglGetCurrentContext() == NULL
, "Wrong current context.\n");
1074 ret
= wglMakeCurrent(oldhdc
, oldctx
);
1075 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1076 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1078 SetLastError(0xdeadbeef);
1079 ret
= wglMakeCurrent(dc
, ctx
);
1080 err
= GetLastError();
1081 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1082 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1084 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1086 ret
= wglDeleteContext(ctx
);
1087 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1089 ReleaseDC(window
, dc
);
1091 ret
= wglMakeCurrent(oldhdc
, oldctx
);
1092 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1095 static void test_destroy_read(HDC oldhdc
)
1097 PIXELFORMATDESCRIPTOR pf_desc
=
1099 sizeof(PIXELFORMATDESCRIPTOR
),
1101 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1103 24, /* 24-bit color depth */
1104 0, 0, 0, 0, 0, 0, /* color bits */
1105 0, /* alpha buffer */
1107 0, /* accumulation buffer */
1108 0, 0, 0, 0, /* accum bits */
1110 0, /* stencil buffer */
1111 0, /* auxiliary buffer */
1112 PFD_MAIN_PLANE
, /* main layer */
1114 0, 0, 0 /* layer masks */
1117 HWND draw_window
, read_window
;
1120 HDC read_dc
, draw_dc
;
1123 HGLRC oldctx
= wglGetCurrentContext();
1125 ok(!!oldctx
, "Expected to find a valid current context\n");
1127 draw_window
= CreateWindowA("static", "opengl32_test",
1128 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1129 ok(!!draw_window
, "Failed to create window, last error %#x.\n", GetLastError());
1131 draw_dc
= GetDC(draw_window
);
1132 ok(!!draw_dc
, "Failed to get DC.\n");
1134 pixel_format
= ChoosePixelFormat(draw_dc
, &pf_desc
);
1137 win_skip("Failed to find pixel format.\n");
1138 ReleaseDC(draw_window
, draw_dc
);
1139 DestroyWindow(draw_window
);
1143 ret
= SetPixelFormat(draw_dc
, pixel_format
, &pf_desc
);
1144 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1146 read_window
= CreateWindowA("static", "opengl32_test",
1147 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1148 ok(!!read_window
, "Failed to create window, last error %#x.\n", GetLastError());
1150 read_dc
= GetDC(read_window
);
1151 ok(!!draw_dc
, "Failed to get DC.\n");
1153 pixel_format
= ChoosePixelFormat(read_dc
, &pf_desc
);
1156 win_skip("Failed to find pixel format.\n");
1157 ReleaseDC(read_window
, read_dc
);
1158 DestroyWindow(read_window
);
1159 ReleaseDC(draw_window
, draw_dc
);
1160 DestroyWindow(draw_window
);
1164 ret
= SetPixelFormat(read_dc
, pixel_format
, &pf_desc
);
1165 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1167 ctx
= wglCreateContext(draw_dc
);
1168 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1170 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1171 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1173 glCopyPixels(0, 0, 640, 480, GL_COLOR
);
1175 glerr
= glGetError();
1176 ok(glerr
== GL_NO_ERROR
, "Failed glCopyPixel, error %#x.\n", glerr
);
1177 ret
= SwapBuffers(draw_dc
);
1178 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1180 ret
= DestroyWindow(read_window
);
1181 ok(ret
, "Failed to destroy window, last error %#x.\n", GetLastError());
1183 ok(wglGetCurrentContext() == ctx
, "Wrong current context.\n");
1185 if (0) /* Crashes on AMD on Windows */
1187 glCopyPixels(0, 0, 640, 480, GL_COLOR
);
1189 glerr
= glGetError();
1190 ok(glerr
== GL_NO_ERROR
, "Failed glCopyPixel, error %#x.\n", glerr
);
1193 glClear(GL_COLOR_BUFFER_BIT
);
1195 glerr
= glGetError();
1196 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1197 ret
= SwapBuffers(draw_dc
);
1198 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1200 ret
= wglMakeCurrent(NULL
, NULL
);
1201 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1203 if (0) /* This crashes with Nvidia drivers on Windows. */
1205 SetLastError(0xdeadbeef);
1206 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1207 err
= GetLastError();
1208 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1209 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1212 ret
= DestroyWindow(draw_window
);
1213 ok(ret
, "Failed to destroy window, last error %#x.\n", GetLastError());
1215 glClear(GL_COLOR_BUFFER_BIT
);
1217 glerr
= glGetError();
1218 todo_wine
ok(glerr
== GL_INVALID_OPERATION
, "Failed glClear, error %#x.\n", glerr
);
1219 SetLastError(0xdeadbeef);
1220 ret
= SwapBuffers(draw_dc
);
1221 err
= GetLastError();
1222 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1224 SetLastError(0xdeadbeef);
1225 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1226 err
= GetLastError();
1227 ok(!ret
&& (err
== ERROR_INVALID_HANDLE
|| err
== 0xc0070006),
1228 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1230 ok(wglGetCurrentContext() == NULL
, "Wrong current context.\n");
1232 wglMakeCurrent(NULL
, NULL
);
1234 wglMakeCurrent(oldhdc
, oldctx
);
1235 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1237 SetLastError(0xdeadbeef);
1238 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1239 err
= GetLastError();
1240 ok(!ret
&& (err
== ERROR_INVALID_HANDLE
|| err
== 0xc0070006),
1241 "Unexpected behavior when making context current, last error %#x.\n", err
);
1243 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1245 ret
= wglDeleteContext(ctx
);
1246 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1248 ReleaseDC(read_window
, read_dc
);
1249 ReleaseDC(draw_window
, draw_dc
);
1251 wglMakeCurrent(oldhdc
, oldctx
);
1257 PIXELFORMATDESCRIPTOR pfd
= {
1258 sizeof(PIXELFORMATDESCRIPTOR
),
1260 PFD_DRAW_TO_WINDOW
|
1261 PFD_SUPPORT_OPENGL
|
1264 24, /* 24-bit color depth */
1265 0, 0, 0, 0, 0, 0, /* color bits */
1266 0, /* alpha buffer */
1268 0, /* accumulation buffer */
1269 0, 0, 0, 0, /* accum bits */
1271 0, /* stencil buffer */
1272 0, /* auxiliary buffer */
1273 PFD_MAIN_PLANE
, /* main layer */
1275 0, 0, 0 /* layer masks */
1278 hwnd
= CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW
,
1279 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
1280 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
1284 int iPixelFormat
, res
;
1287 ShowWindow(hwnd
, SW_SHOW
);
1291 iPixelFormat
= ChoosePixelFormat(hdc
, &pfd
);
1292 if(iPixelFormat
== 0)
1294 /* This should never happen as ChoosePixelFormat always returns a closest match, but currently this fails in Wine if we don't have glX */
1295 win_skip("Unable to find pixel format.\n");
1299 /* We shouldn't be able to create a context from a hdc which doesn't have a pixel format set */
1300 hglrc
= wglCreateContext(hdc
);
1301 ok(hglrc
== NULL
, "wglCreateContext should fail when no pixel format has been set, but it passed\n");
1302 error
= GetLastError();
1303 ok(error
== ERROR_INVALID_PIXEL_FORMAT
, "expected ERROR_INVALID_PIXEL_FORMAT for wglCreateContext without a pixelformat set, but received %#x\n", error
);
1305 res
= SetPixelFormat(hdc
, iPixelFormat
, &pfd
);
1306 ok(res
, "SetPixelformat failed: %x\n", GetLastError());
1308 test_bitmap_rendering();
1313 hglrc
= wglCreateContext(hdc
);
1314 res
= wglMakeCurrent(hdc
, hglrc
);
1315 ok(res
, "wglMakeCurrent failed!\n");
1318 trace("OpenGL renderer: %s\n", glGetString(GL_RENDERER
));
1319 trace("OpenGL driver version: %s\n", glGetString(GL_VERSION
));
1320 trace("OpenGL vendor: %s\n", glGetString(GL_VENDOR
));
1324 skip("Skipping OpenGL tests without a current context\n");
1328 /* Initialisation of WGL functions depends on an implicit WGL context. For this reason we can't load them before making
1329 * any WGL call :( On Wine this would work but not on real Windows because there can be different implementations (software, ICD, MCD).
1332 /* The lack of wglGetExtensionsStringARB in general means broken software rendering or the lack of decent OpenGL support, skip tests in such cases */
1333 if (!pwglGetExtensionsStringARB
)
1335 win_skip("wglGetExtensionsStringARB is not available\n");
1339 test_deletecontext(hdc
);
1340 test_makecurrent(hdc
);
1341 test_setpixelformat(hdc
);
1343 test_sharelists(hdc
);
1344 test_colorbits(hdc
);
1346 test_acceleration(hdc
);
1348 wgl_extensions
= pwglGetExtensionsStringARB(hdc
);
1349 if(wgl_extensions
== NULL
) skip("Skipping opengl32 tests because this OpenGL implementation doesn't support WGL extensions!\n");
1351 if(strstr(wgl_extensions
, "WGL_ARB_create_context"))
1354 if(strstr(wgl_extensions
, "WGL_ARB_make_current_read"))
1356 test_make_current_read(hdc
);
1357 test_destroy_read(hdc
);
1360 skip("WGL_ARB_make_current_read not supported, skipping test\n");
1362 if(strstr(wgl_extensions
, "WGL_ARB_pbuffer"))
1365 skip("WGL_ARB_pbuffer not supported, skipping pbuffer test\n");
1368 ReleaseDC(hwnd
, hdc
);
1369 DestroyWindow(hwnd
);