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
40 #define GL_EXTENSIONS 0x1F03
42 #define GL_VIEWPORT 0x0ba2
43 void WINAPI
glGetIntegerv(GLenum pname
, GLint
*params
);
45 #define MAX_FORMATS 256
46 typedef void* HPBUFFERARB
;
48 /* WGL_ARB_create_context */
49 static HGLRC (WINAPI
*pwglCreateContextAttribsARB
)(HDC hDC
, HGLRC hShareContext
, const int *attribList
);
51 #define ERROR_INVALID_VERSION_ARB 0x2095
52 #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
53 #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
54 #define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
55 #define WGL_CONTEXT_FLAGS_ARB 0x2094
56 /* Flags for WGL_CONTEXT_FLAGS_ARB */
57 #define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
58 #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
60 /* WGL_ARB_extensions_string */
61 static const char* (WINAPI
*pwglGetExtensionsStringARB
)(HDC
);
62 static int (WINAPI
*pwglReleasePbufferDCARB
)(HPBUFFERARB
, HDC
);
64 /* WGL_ARB_make_current_read */
65 static BOOL (WINAPI
*pwglMakeContextCurrentARB
)(HDC hdraw
, HDC hread
, HGLRC hglrc
);
66 static HDC (WINAPI
*pwglGetCurrentReadDCARB
)(void);
68 /* WGL_ARB_pixel_format */
69 #define WGL_ACCELERATION_ARB 0x2003
70 #define WGL_COLOR_BITS_ARB 0x2014
71 #define WGL_RED_BITS_ARB 0x2015
72 #define WGL_GREEN_BITS_ARB 0x2017
73 #define WGL_BLUE_BITS_ARB 0x2019
74 #define WGL_ALPHA_BITS_ARB 0x201B
75 #define WGL_SUPPORT_GDI_ARB 0x200F
76 #define WGL_DOUBLE_BUFFER_ARB 0x2011
77 #define WGL_NO_ACCELERATION_ARB 0x2025
78 #define WGL_GENERIC_ACCELERATION_ARB 0x2026
79 #define WGL_FULL_ACCELERATION_ARB 0x2027
81 static BOOL (WINAPI
*pwglChoosePixelFormatARB
)(HDC
, const int *, const FLOAT
*, UINT
, int *, UINT
*);
82 static BOOL (WINAPI
*pwglGetPixelFormatAttribivARB
)(HDC
, int, int, UINT
, const int *, int *);
85 #define WGL_DRAW_TO_PBUFFER_ARB 0x202D
86 static HPBUFFERARB
* (WINAPI
*pwglCreatePbufferARB
)(HDC
, int, int, int, const int *);
87 static HDC (WINAPI
*pwglGetPbufferDCARB
)(HPBUFFERARB
);
89 /* WGL_EXT_swap_control */
90 static BOOL (WINAPI
*pwglSwapIntervalEXT
)(int interval
);
91 static int (WINAPI
*pwglGetSwapIntervalEXT
)(void);
93 static const char* wgl_extensions
= NULL
;
95 static void init_functions(void)
97 #define GET_PROC(func) \
98 p ## func = (void*)wglGetProcAddress(#func); \
100 trace("wglGetProcAddress(%s) failed\n", #func);
102 /* WGL_ARB_create_context */
103 GET_PROC(wglCreateContextAttribsARB
);
105 /* WGL_ARB_extensions_string */
106 GET_PROC(wglGetExtensionsStringARB
)
108 /* WGL_ARB_make_current_read */
109 GET_PROC(wglMakeContextCurrentARB
);
110 GET_PROC(wglGetCurrentReadDCARB
);
112 /* WGL_ARB_pixel_format */
113 GET_PROC(wglChoosePixelFormatARB
)
114 GET_PROC(wglGetPixelFormatAttribivARB
)
116 /* WGL_ARB_pbuffer */
117 GET_PROC(wglCreatePbufferARB
)
118 GET_PROC(wglGetPbufferDCARB
)
119 GET_PROC(wglReleasePbufferDCARB
)
121 /* WGL_EXT_swap_control */
122 GET_PROC(wglSwapIntervalEXT
)
123 GET_PROC(wglGetSwapIntervalEXT
)
128 static BOOL
gl_extension_supported(const char *extensions
, const char *extension_string
)
130 size_t ext_str_len
= strlen(extension_string
);
137 while (isspace(*extensions
))
140 while (!isspace(*extensions
) && *extensions
)
143 len
= extensions
- start
;
147 if (len
== ext_str_len
&& !memcmp(start
, extension_string
, ext_str_len
))
155 static void test_pbuffers(HDC hdc
)
157 const int iAttribList
[] = { WGL_DRAW_TO_PBUFFER_ARB
, 1, /* Request pbuffer support */
159 int iFormats
[MAX_FORMATS
];
160 unsigned int nOnscreenFormats
;
161 unsigned int nFormats
;
163 int iPixelFormat
= 0;
165 nOnscreenFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
167 /* When you want to render to a pbuffer you need to call wglGetPbufferDCARB which
168 * returns a 'magic' HDC which you can then pass to wglMakeCurrent to switch rendering
169 * to the pbuffer. Below some tests are performed on what happens if you use standard WGL calls
170 * on this 'magic' HDC for both a pixelformat that support onscreen and offscreen rendering
171 * and a pixelformat that's only available for offscreen rendering (this means that only
172 * wglChoosePixelFormatARB and friends know about the format.
174 * The first thing we need are pixelformats with pbuffer capabilities.
176 res
= pwglChoosePixelFormatARB(hdc
, iAttribList
, NULL
, MAX_FORMATS
, iFormats
, &nFormats
);
179 skip("No pbuffer compatible formats found while WGL_ARB_pbuffer is supported\n");
182 trace("nOnscreenFormats: %d\n", nOnscreenFormats
);
183 trace("Total number of pbuffer capable pixelformats: %d\n", nFormats
);
185 /* Try to select an onscreen pixelformat out of the list */
186 for(i
=0; i
< nFormats
; i
++)
188 /* Check if the format is onscreen, if it is choose it */
189 if(iFormats
[i
] <= nOnscreenFormats
)
191 iPixelFormat
= iFormats
[i
];
192 trace("Selected iPixelFormat=%d\n", iPixelFormat
);
197 /* A video driver supports a large number of onscreen and offscreen pixelformats.
198 * The traditional WGL calls only see a subset of the whole pixelformat list. First
199 * of all they only see the onscreen formats (the offscreen formats are at the end of the
200 * pixelformat list) and second extended pixelformat capabilities are hidden from the
201 * standard WGL calls. Only functions that depend on WGL_ARB_pixel_format can see them.
203 * Below we check if the pixelformat is also supported onscreen.
205 if(iPixelFormat
!= 0)
209 HPBUFFERARB pbuffer
= pwglCreatePbufferARB(hdc
, iPixelFormat
, 640 /* width */, 480 /* height */, &attrib
);
211 skip("Pbuffer creation failed!\n");
213 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
214 pbuffer_hdc
= pwglGetPbufferDCARB(pbuffer
);
215 res
= GetPixelFormat(pbuffer_hdc
);
216 ok(res
== iPixelFormat
, "Unexpected iPixelFormat=%d returned by GetPixelFormat for format %d\n", res
, iPixelFormat
);
217 trace("iPixelFormat returned by GetPixelFormat: %d\n", res
);
218 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat
);
220 pwglReleasePbufferDCARB(pbuffer
, pbuffer_hdc
);
222 else skip("Pbuffer test for onscreen pixelformat skipped as no onscreen format with pbuffer capabilities have been found\n");
224 /* Search for a real offscreen format */
225 for(i
=0, iPixelFormat
=0; i
<nFormats
; i
++)
227 if(iFormats
[i
] > nOnscreenFormats
)
229 iPixelFormat
= iFormats
[i
];
230 trace("Selected iPixelFormat: %d\n", iPixelFormat
);
235 if(iPixelFormat
!= 0)
238 HPBUFFERARB pbuffer
= pwglCreatePbufferARB(hdc
, iPixelFormat
, 640 /* width */, 480 /* height */, NULL
);
240 skip("Pbuffer creation failed!\n");
242 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
243 pbuffer_hdc
= pwglGetPbufferDCARB(pbuffer
);
244 res
= GetPixelFormat(pbuffer_hdc
);
246 ok(res
== 1, "Unexpected iPixelFormat=%d (1 expected) returned by GetPixelFormat for offscreen format %d\n", res
, iPixelFormat
);
247 trace("iPixelFormat returned by GetPixelFormat: %d\n", res
);
248 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat
);
249 pwglReleasePbufferDCARB(pbuffer
, hdc
);
251 else skip("Pbuffer test for offscreen pixelformat skipped as no offscreen-only format with pbuffer capabilities has been found\n");
254 static void test_setpixelformat(HDC winhdc
)
261 PIXELFORMATDESCRIPTOR pfd
= {
262 sizeof(PIXELFORMATDESCRIPTOR
),
268 24, /* 24-bit color depth */
269 0, 0, 0, 0, 0, 0, /* color bits */
270 0, /* alpha buffer */
272 0, /* accumulation buffer */
273 0, 0, 0, 0, /* accum bits */
275 0, /* stencil buffer */
276 0, /* auxiliary buffer */
277 PFD_MAIN_PLANE
, /* main layer */
279 0, 0, 0 /* layer masks */
283 ok(hdc
!= 0, "GetDC(0) failed!\n");
285 /* This should pass even on the main device context */
286 pf
= ChoosePixelFormat(hdc
, &pfd
);
287 ok(pf
!= 0, "ChoosePixelFormat failed on main device context\n");
289 /* SetPixelFormat on the main device context 'X root window' should fail,
290 * but some broken drivers allow it
292 res
= SetPixelFormat(hdc
, pf
, &pfd
);
293 trace("SetPixelFormat on main device context %s\n", res
? "succeeded" : "failed");
295 /* Setting the same format that was set on the HDC is allowed; other
297 nCfgs
= DescribePixelFormat(winhdc
, 0, 0, NULL
);
298 pf
= GetPixelFormat(winhdc
);
299 for(i
= 1;i
<= nCfgs
;i
++)
301 int res
= SetPixelFormat(winhdc
, i
, NULL
);
302 if(i
== pf
) ok(res
, "Failed to set the same pixel format\n");
303 else ok(!res
, "Unexpectedly set an alternate pixel format\n");
306 hwnd
= CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW
, 10, 10, 200, 200, NULL
, NULL
,
308 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
311 HDC hdc
= GetDC( hwnd
);
312 pf
= ChoosePixelFormat( hdc
, &pfd
);
313 ok( pf
!= 0, "ChoosePixelFormat failed\n" );
314 res
= SetPixelFormat( hdc
, pf
, &pfd
);
315 ok( res
!= 0, "SetPixelFormat failed\n" );
316 i
= GetPixelFormat( hdc
);
317 ok( i
== pf
, "GetPixelFormat returned wrong format %d/%d\n", i
, pf
);
318 ReleaseDC( hwnd
, hdc
);
319 hdc
= GetWindowDC( hwnd
);
320 i
= GetPixelFormat( hdc
);
321 ok( i
== pf
, "GetPixelFormat returned wrong format %d/%d\n", i
, pf
);
322 ReleaseDC( hwnd
, hdc
);
323 DestroyWindow( hwnd
);
326 hwnd
= CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW
, 10, 10, 200, 200, NULL
, NULL
,
328 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
331 HDC hdc
= GetWindowDC( hwnd
);
332 pf
= ChoosePixelFormat( hdc
, &pfd
);
333 ok( pf
!= 0, "ChoosePixelFormat failed\n" );
334 res
= SetPixelFormat( hdc
, pf
, &pfd
);
335 ok( res
!= 0, "SetPixelFormat failed\n" );
336 i
= GetPixelFormat( hdc
);
337 ok( i
== pf
, "GetPixelFormat returned wrong format %d/%d\n", i
, pf
);
338 ReleaseDC( hwnd
, hdc
);
339 DestroyWindow( hwnd
);
343 static void test_sharelists(HDC winhdc
)
345 HGLRC hglrc1
, hglrc2
, hglrc3
;
348 hglrc1
= wglCreateContext(winhdc
);
349 res
= wglShareLists(0, 0);
350 ok(res
== FALSE
, "Sharing display lists for no contexts passed!\n");
352 /* Test 1: Create a context and just share lists without doing anything special */
353 hglrc2
= wglCreateContext(winhdc
);
356 res
= wglShareLists(hglrc1
, hglrc2
);
357 ok(res
, "Sharing of display lists failed\n");
358 wglDeleteContext(hglrc2
);
361 /* Test 2: Share display lists with a 'destination' context which has been made current */
362 hglrc2
= wglCreateContext(winhdc
);
365 res
= wglMakeCurrent(winhdc
, hglrc2
);
366 ok(res
, "Make current failed\n");
367 res
= wglShareLists(hglrc1
, hglrc2
);
368 todo_wine
ok(res
, "Sharing display lists with a destination context which has been made current failed\n");
369 wglMakeCurrent(0, 0);
370 wglDeleteContext(hglrc2
);
373 /* Test 3: Share display lists with a context which already shares display lists with another context.
374 * According to MSDN the second parameter cannot share any display lists but some buggy drivers might allow it */
375 hglrc3
= wglCreateContext(winhdc
);
378 res
= wglShareLists(hglrc3
, hglrc1
);
379 ok(res
== FALSE
, "Sharing of display lists passed for a context which already shared lists before\n");
380 wglDeleteContext(hglrc3
);
383 /* Test 4: Share display lists with a 'source' context which has been made current */
384 hglrc2
= wglCreateContext(winhdc
);
387 res
= wglMakeCurrent(winhdc
, hglrc1
);
388 ok(res
, "Make current failed\n");
389 res
= wglShareLists(hglrc1
, hglrc2
);
390 ok(res
, "Sharing display lists with a source context which has been made current failed\n");
391 wglMakeCurrent(0, 0);
392 wglDeleteContext(hglrc2
);
396 static void test_makecurrent(HDC winhdc
)
401 hglrc
= wglCreateContext(winhdc
);
402 ok( hglrc
!= 0, "wglCreateContext failed\n" );
404 ret
= wglMakeCurrent( winhdc
, hglrc
);
405 ok( ret
, "wglMakeCurrent failed\n" );
407 ok( wglGetCurrentContext() == hglrc
, "wrong context\n" );
409 /* set the same context again */
410 ret
= wglMakeCurrent( winhdc
, hglrc
);
411 ok( ret
, "wglMakeCurrent failed\n" );
413 /* check wglMakeCurrent(x, y) after another call to wglMakeCurrent(x, y) */
414 ret
= wglMakeCurrent( winhdc
, NULL
);
415 ok( ret
, "wglMakeCurrent failed\n" );
417 ret
= wglMakeCurrent( winhdc
, NULL
);
418 ok( ret
, "wglMakeCurrent failed\n" );
420 SetLastError( 0xdeadbeef );
421 ret
= wglMakeCurrent( NULL
, NULL
);
422 ok( !ret
|| broken(ret
) /* nt4 */, "wglMakeCurrent succeeded\n" );
423 if (!ret
) ok( GetLastError() == ERROR_INVALID_HANDLE
,
424 "Expected ERROR_INVALID_HANDLE, got error=%x\n", GetLastError() );
426 ret
= wglMakeCurrent( winhdc
, NULL
);
427 ok( ret
, "wglMakeCurrent failed\n" );
429 ret
= wglMakeCurrent( winhdc
, hglrc
);
430 ok( ret
, "wglMakeCurrent failed\n" );
432 ret
= wglMakeCurrent( NULL
, NULL
);
433 ok( ret
, "wglMakeCurrent failed\n" );
435 ok( wglGetCurrentContext() == NULL
, "wrong context\n" );
437 SetLastError( 0xdeadbeef );
438 ret
= wglMakeCurrent( NULL
, NULL
);
439 ok( !ret
|| broken(ret
) /* nt4 */, "wglMakeCurrent succeeded\n" );
440 if (!ret
) ok( GetLastError() == ERROR_INVALID_HANDLE
,
441 "Expected ERROR_INVALID_HANDLE, got error=%x\n", GetLastError() );
443 ret
= wglMakeCurrent( winhdc
, hglrc
);
444 ok( ret
, "wglMakeCurrent failed\n" );
447 static void test_colorbits(HDC hdc
)
449 const int iAttribList
[] = { WGL_COLOR_BITS_ARB
, WGL_RED_BITS_ARB
, WGL_GREEN_BITS_ARB
,
450 WGL_BLUE_BITS_ARB
, WGL_ALPHA_BITS_ARB
};
451 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
452 const int iAttribs
[] = { WGL_ALPHA_BITS_ARB
, 1, 0 };
453 unsigned int nFormats
;
455 int iPixelFormat
= 0;
457 if (!pwglChoosePixelFormatARB
)
459 win_skip("wglChoosePixelFormatARB is not available\n");
463 /* We need a pixel format with at least one bit of alpha */
464 res
= pwglChoosePixelFormatARB(hdc
, iAttribs
, NULL
, 1, &iPixelFormat
, &nFormats
);
465 if(res
== FALSE
|| nFormats
== 0)
467 skip("No suitable pixel formats found\n");
471 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
472 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
, iAttribRet
);
475 skip("wglGetPixelFormatAttribivARB failed\n");
478 iAttribRet
[1] += iAttribRet
[2]+iAttribRet
[3]+iAttribRet
[4];
479 ok(iAttribRet
[0] == iAttribRet
[1], "WGL_COLOR_BITS_ARB (%d) does not equal R+G+B+A (%d)!\n",
480 iAttribRet
[0], iAttribRet
[1]);
483 static void test_gdi_dbuf(HDC hdc
)
485 const int iAttribList
[] = { WGL_SUPPORT_GDI_ARB
, WGL_DOUBLE_BUFFER_ARB
};
486 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
487 unsigned int nFormats
;
491 if (!pwglGetPixelFormatAttribivARB
)
493 win_skip("wglGetPixelFormatAttribivARB is not available\n");
497 nFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
498 for(iPixelFormat
= 1;iPixelFormat
<= nFormats
;iPixelFormat
++)
500 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
501 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
,
503 ok(res
!=FALSE
, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat
);
507 ok(!(iAttribRet
[0] && iAttribRet
[1]), "GDI support and double buffering on pixel format %d\n", iPixelFormat
);
511 static void test_acceleration(HDC hdc
)
513 const int iAttribList
[] = { WGL_ACCELERATION_ARB
};
514 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
515 unsigned int nFormats
;
518 PIXELFORMATDESCRIPTOR pfd
;
520 if (!pwglGetPixelFormatAttribivARB
)
522 win_skip("wglGetPixelFormatAttribivARB is not available\n");
526 nFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
527 for(iPixelFormat
= 1; iPixelFormat
<= nFormats
; iPixelFormat
++)
529 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
530 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
,
532 ok(res
!=FALSE
, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat
);
536 memset(&pfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
537 DescribePixelFormat(hdc
, iPixelFormat
, sizeof(PIXELFORMATDESCRIPTOR
), &pfd
);
539 switch(iAttribRet
[0])
541 case WGL_NO_ACCELERATION_ARB
:
542 ok( (pfd
.dwFlags
& (PFD_GENERIC_FORMAT
| PFD_GENERIC_ACCELERATED
)) == PFD_GENERIC_FORMAT
, "Expected only PFD_GENERIC_FORMAT to be set for WGL_NO_ACCELERATION_ARB!: iPixelFormat=%d, dwFlags=%x!\n", iPixelFormat
, pfd
.dwFlags
);
544 case WGL_GENERIC_ACCELERATION_ARB
:
545 ok( (pfd
.dwFlags
& (PFD_GENERIC_FORMAT
| PFD_GENERIC_ACCELERATED
)) == (PFD_GENERIC_FORMAT
| PFD_GENERIC_ACCELERATED
), "Expected both PFD_GENERIC_FORMAT and PFD_GENERIC_ACCELERATION to be set for WGL_GENERIC_ACCELERATION_ARB: iPixelFormat=%d, dwFlags=%x!\n", iPixelFormat
, pfd
.dwFlags
);
547 case WGL_FULL_ACCELERATION_ARB
:
548 ok( (pfd
.dwFlags
& (PFD_GENERIC_FORMAT
| PFD_GENERIC_ACCELERATED
)) == 0, "Expected no PFD_GENERIC_FORMAT/_ACCELERATION to be set for WGL_FULL_ACCELERATION_ARB: iPixelFormat=%d, dwFlags=%x!\n", iPixelFormat
, pfd
.dwFlags
);
554 static void test_bitmap_rendering( BOOL use_dib
)
556 PIXELFORMATDESCRIPTOR pfd
;
557 int i
, ret
, bpp
, iPixelFormat
=0;
558 unsigned int nFormats
;
561 HBITMAP bmpDst
, oldDst
, bmp2
;
562 HDC hdcDst
, hdcScreen
;
563 UINT
*dstBuffer
= NULL
;
565 hdcScreen
= CreateCompatibleDC(0);
566 hdcDst
= CreateCompatibleDC(0);
571 memset(&biDst
, 0, sizeof(BITMAPINFO
));
572 biDst
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
573 biDst
.bmiHeader
.biWidth
= 4;
574 biDst
.bmiHeader
.biHeight
= -4;
575 biDst
.bmiHeader
.biPlanes
= 1;
576 biDst
.bmiHeader
.biBitCount
= 32;
577 biDst
.bmiHeader
.biCompression
= BI_RGB
;
579 bmpDst
= CreateDIBSection(0, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
, NULL
, 0);
581 biDst
.bmiHeader
.biWidth
= 12;
582 biDst
.bmiHeader
.biHeight
= -12;
583 biDst
.bmiHeader
.biBitCount
= 16;
584 bmp2
= CreateDIBSection(0, &biDst
, DIB_RGB_COLORS
, NULL
, NULL
, 0);
588 bpp
= GetDeviceCaps( hdcScreen
, BITSPIXEL
);
589 bmpDst
= CreateBitmap( 4, 4, 1, bpp
, NULL
);
590 bmp2
= CreateBitmap( 12, 12, 1, bpp
, NULL
);
593 oldDst
= SelectObject(hdcDst
, bmpDst
);
595 trace( "testing on %s\n", use_dib
? "DIB" : "DDB" );
597 /* Pick a pixel format by hand because ChoosePixelFormat is unreliable */
598 nFormats
= DescribePixelFormat(hdcDst
, 0, 0, NULL
);
599 for(i
=1; i
<=nFormats
; i
++)
601 memset(&pfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
602 DescribePixelFormat(hdcDst
, i
, sizeof(PIXELFORMATDESCRIPTOR
), &pfd
);
604 if((pfd
.dwFlags
& PFD_DRAW_TO_BITMAP
) &&
605 (pfd
.dwFlags
& PFD_SUPPORT_OPENGL
) &&
606 (pfd
.cColorBits
== bpp
) &&
607 (pfd
.cAlphaBits
== 8) )
616 skip("Unable to find a suitable pixel format\n");
620 ret
= SetPixelFormat(hdcDst
, iPixelFormat
, &pfd
);
621 ok( ret
, "SetPixelFormat failed\n" );
622 ret
= GetPixelFormat( hdcDst
);
623 ok( ret
== iPixelFormat
, "GetPixelFormat returned %d/%d\n", ret
, iPixelFormat
);
624 ret
= SetPixelFormat(hdcDst
, iPixelFormat
+ 1, &pfd
);
625 ok( !ret
, "SetPixelFormat succeeded\n" );
626 hglrc
= wglCreateContext(hdcDst
);
627 ok(hglrc
!= NULL
, "Unable to create a context\n");
632 wglMakeCurrent(hdcDst
, hglrc
);
633 hglrc2
= wglCreateContext(hdcDst
);
634 ok(hglrc2
!= NULL
, "Unable to create a context\n");
636 /* Note this is RGBA but we read ARGB back */
637 glClearColor((float)0x22/0xff, (float)0x33/0xff, (float)0x44/0xff, (float)0x11/0xff);
638 glClear(GL_COLOR_BUFFER_BIT
);
639 glGetIntegerv( GL_VIEWPORT
, viewport
);
642 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 4 && viewport
[3] == 4,
643 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
644 /* Note apparently the alpha channel is not supported by the software renderer (bitmap only works using software) */
646 for (i
= 0; i
< 16; i
++)
647 ok(dstBuffer
[i
] == 0x223344 || dstBuffer
[i
] == 0x11223344, "Received color=%x at %u\n",
650 SelectObject(hdcDst
, bmp2
);
651 ret
= GetPixelFormat( hdcDst
);
652 ok( ret
== iPixelFormat
, "GetPixelFormat returned %d/%d\n", ret
, iPixelFormat
);
653 ret
= SetPixelFormat(hdcDst
, iPixelFormat
+ 1, &pfd
);
654 ok( !ret
, "SetPixelFormat succeeded\n" );
656 /* context still uses the old pixel format and viewport */
657 glClearColor((float)0x44/0xff, (float)0x33/0xff, (float)0x22/0xff, (float)0x11/0xff);
658 glClear(GL_COLOR_BUFFER_BIT
);
660 glGetIntegerv( GL_VIEWPORT
, viewport
);
661 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 4 && viewport
[3] == 4,
662 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
664 wglMakeCurrent(NULL
, NULL
);
665 wglMakeCurrent(hdcDst
, hglrc
);
666 glClearColor((float)0x44/0xff, (float)0x55/0xff, (float)0x66/0xff, (float)0x11/0xff);
667 glClear(GL_COLOR_BUFFER_BIT
);
669 glGetIntegerv( GL_VIEWPORT
, viewport
);
670 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 4 && viewport
[3] == 4,
671 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
673 wglMakeCurrent(hdcDst
, hglrc2
);
674 glGetIntegerv( GL_VIEWPORT
, viewport
);
675 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 12 && viewport
[3] == 12,
676 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
678 wglMakeCurrent(hdcDst
, hglrc
);
679 glGetIntegerv( GL_VIEWPORT
, viewport
);
680 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 4 && viewport
[3] == 4,
681 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
683 SelectObject(hdcDst
, bmpDst
);
684 ret
= GetPixelFormat( hdcDst
);
685 ok( ret
== iPixelFormat
, "GetPixelFormat returned %d/%d\n", ret
, iPixelFormat
);
686 ret
= SetPixelFormat(hdcDst
, iPixelFormat
+ 1, &pfd
);
687 ok( !ret
, "SetPixelFormat succeeded\n" );
688 wglMakeCurrent(hdcDst
, hglrc2
);
689 glGetIntegerv( GL_VIEWPORT
, viewport
);
690 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 12 && viewport
[3] == 12,
691 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
695 SelectObject(hdcDst
, oldDst
);
697 DeleteObject(bmpDst
);
702 struct wgl_thread_param
704 HANDLE test_finished
;
708 BOOL make_current_error
;
713 static DWORD WINAPI
wgl_thread(void *param
)
715 struct wgl_thread_param
*p
= param
;
716 HDC hdc
= GetDC( p
->hwnd
);
718 ok(!glGetString(GL_RENDERER
) && !glGetString(GL_VERSION
) && !glGetString(GL_VENDOR
),
719 "Expected NULL string when no active context is set\n");
721 SetLastError(0xdeadbeef);
722 p
->make_current
= wglMakeCurrent(hdc
, p
->hglrc
);
723 p
->make_current_error
= GetLastError();
724 p
->deleted
= wglDeleteContext(p
->hglrc
);
725 p
->deleted_error
= GetLastError();
726 ReleaseDC( p
->hwnd
, hdc
);
727 SetEvent(p
->test_finished
);
731 static void test_deletecontext(HWND hwnd
, HDC hdc
)
733 struct wgl_thread_param thread_params
;
734 HGLRC hglrc
= wglCreateContext(hdc
);
735 HANDLE thread_handle
;
739 SetLastError(0xdeadbeef);
740 res
= wglDeleteContext(NULL
);
741 ok(res
== FALSE
, "wglDeleteContext succeeded\n");
742 ok(GetLastError() == ERROR_INVALID_HANDLE
, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
746 skip("wglCreateContext failed!\n");
750 res
= wglMakeCurrent(hdc
, hglrc
);
753 skip("wglMakeCurrent failed!\n");
757 /* WGL doesn't allow you to delete a context from a different thread than the one in which it is current.
758 * This differs from GLX which does allow it but it delays actual deletion until the context becomes not current.
760 thread_params
.hglrc
= hglrc
;
761 thread_params
.hwnd
= hwnd
;
762 thread_params
.test_finished
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
763 thread_handle
= CreateThread(NULL
, 0, wgl_thread
, &thread_params
, 0, &tid
);
764 ok(!!thread_handle
, "Failed to create thread, last error %#x.\n", GetLastError());
767 WaitForSingleObject(thread_handle
, INFINITE
);
768 ok(!thread_params
.make_current
, "Attempt to make WGL context from another thread passed\n");
769 ok(thread_params
.make_current_error
== ERROR_BUSY
, "Expected last error to be ERROR_BUSY, got %u\n", thread_params
.make_current_error
);
770 ok(!thread_params
.deleted
, "Attempt to delete WGL context from another thread passed\n");
771 ok(thread_params
.deleted_error
== ERROR_BUSY
, "Expected last error to be ERROR_BUSY, got %u\n", thread_params
.deleted_error
);
773 CloseHandle(thread_params
.test_finished
);
775 res
= wglDeleteContext(hglrc
);
776 ok(res
== TRUE
, "wglDeleteContext failed\n");
778 /* Attempting to delete the same context twice should fail. */
779 SetLastError(0xdeadbeef);
780 res
= wglDeleteContext(hglrc
);
781 ok(res
== FALSE
, "wglDeleteContext succeeded\n");
782 ok(GetLastError() == ERROR_INVALID_HANDLE
, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
784 /* WGL makes a context not current when deleting it. This differs from GLX behavior where
785 * deletion takes place when the thread becomes not current. */
786 hglrc
= wglGetCurrentContext();
787 ok(hglrc
== NULL
, "A WGL context is active while none was expected\n");
791 static void test_getprocaddress(HDC hdc
)
793 const char *extensions
= (const char*)glGetString(GL_EXTENSIONS
);
795 HGLRC ctx
= wglGetCurrentContext();
799 skip("skipping wglGetProcAddress tests because no GL extensions supported\n");
803 /* Core GL 1.0/1.1 functions should not be loadable through wglGetProcAddress.
804 * Try to load the function with and without a context.
806 func
= wglGetProcAddress("glEnable");
807 ok(func
== NULL
, "Lookup of function glEnable with a context passed, expected a failure\n");
808 wglMakeCurrent(hdc
, NULL
);
809 func
= wglGetProcAddress("glEnable");
810 ok(func
== NULL
, "Lookup of function glEnable without a context passed, expected a failure\n");
811 wglMakeCurrent(hdc
, ctx
);
813 /* The goal of the test will be to test behavior of wglGetProcAddress when
814 * no WGL context is active. Before the test we pick an extension (GL_ARB_multitexture)
815 * which any GL >=1.2.1 implementation supports. Unfortunately the GDI renderer doesn't
816 * support it. There aren't any extensions we can use for this test which are supported by
817 * both GDI and real drivers.
818 * Note GDI only has GL_EXT_bgra, GL_EXT_paletted_texture and GL_WIN_swap_hint.
820 if (!gl_extension_supported(extensions
, "GL_ARB_multitexture"))
822 skip("skipping test because lack of GL_ARB_multitexture support\n");
826 func
= wglGetProcAddress("glActiveTextureARB");
827 ok(func
!= NULL
, "Unable to lookup glActiveTextureARB, last error %#x\n", GetLastError());
829 /* Temporarily disable the context, so we can see that we can't retrieve functions now. */
830 wglMakeCurrent(hdc
, NULL
);
831 func
= wglGetProcAddress("glActiveTextureARB");
832 ok(func
== NULL
, "Function lookup without a context passed, expected a failure; last error %#x\n", GetLastError());
833 wglMakeCurrent(hdc
, ctx
);
836 static void test_make_current_read(HDC hdc
)
840 HGLRC hglrc
= wglCreateContext(hdc
);
844 skip("wglCreateContext failed!\n");
848 res
= wglMakeCurrent(hdc
, hglrc
);
851 skip("wglMakeCurrent failed!\n");
855 /* Test what wglGetCurrentReadDCARB does for wglMakeCurrent as the spec doesn't mention it */
856 hread
= pwglGetCurrentReadDCARB();
857 trace("hread %p, hdc %p\n", hread
, hdc
);
858 ok(hread
== hdc
, "wglGetCurrentReadDCARB failed for standard wglMakeCurrent\n");
860 pwglMakeContextCurrentARB(hdc
, hdc
, hglrc
);
861 hread
= pwglGetCurrentReadDCARB();
862 ok(hread
== hdc
, "wglGetCurrentReadDCARB failed for wglMakeContextCurrent\n");
865 static void test_dc(HWND hwnd
, HDC hdc
)
870 /* Get another DC and make sure it has the same pixel format */
874 pf1
= GetPixelFormat(hdc
);
875 pf2
= GetPixelFormat(hdc2
);
876 ok(pf1
== pf2
, "Second DC does not have the same format (%d != %d)\n", pf1
, pf2
);
879 skip("Could not get a different DC for the window\n");
883 ReleaseDC(hwnd
, hdc2
);
888 /* Nvidia converts win32 error codes to (0xc007 << 16) | win32_error_code */
889 #define NVIDIA_HRESULT_FROM_WIN32(x) (HRESULT_FROM_WIN32(x) | 0x40000000)
890 static void test_opengl3(HDC hdc
)
892 /* Try to create a context compatible with OpenGL 1.x; 1.0-2.1 is allowed */
895 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 1, 0};
897 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
898 ok(gl3Ctx
!= 0, "pwglCreateContextAttribsARB for a 1.x context failed!\n");
899 wglDeleteContext(gl3Ctx
);
902 /* Try to pass an invalid HDC */
906 gl3Ctx
= pwglCreateContextAttribsARB((HDC
)0xdeadbeef, 0, 0);
907 ok(gl3Ctx
== 0, "pwglCreateContextAttribsARB using an invalid HDC passed\n");
908 error
= GetLastError();
909 todo_wine
ok(error
== ERROR_DC_NOT_FOUND
||
910 broken(error
== NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_DATA
)), /* Nvidia Vista + Win7 */
911 "Expected ERROR_DC_NOT_FOUND, got error=%x\n", error
);
912 wglDeleteContext(gl3Ctx
);
915 /* Try to pass an invalid shareList */
919 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, (HGLRC
)0xdeadbeef, 0);
920 ok(gl3Ctx
== 0, "pwglCreateContextAttribsARB using an invalid shareList passed\n");
921 error
= GetLastError();
922 /* The Nvidia implementation seems to return hresults instead of win32 error codes */
923 todo_wine
ok(error
== ERROR_INVALID_OPERATION
||
924 error
== NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_OPERATION
), "Expected ERROR_INVALID_OPERATION, got error=%x\n", error
);
925 wglDeleteContext(gl3Ctx
);
928 /* Try to create an OpenGL 3.0 context */
930 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
931 HGLRC gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
935 skip("Skipping the rest of the WGL_ARB_create_context test due to lack of OpenGL 3.0\n");
939 wglDeleteContext(gl3Ctx
);
942 /* 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 */
944 HGLRC glCtx
= wglCreateContext(hdc
);
946 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
947 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};
949 HGLRC gl3Ctx
= pwglCreateContextAttribsARB(hdc
, glCtx
, attribs
);
950 ok(gl3Ctx
!= NULL
, "Sharing of a display list between OpenGL 3.0 and OpenGL 1.x/2.x failed!\n");
952 wglDeleteContext(gl3Ctx
);
954 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, glCtx
, attribs_future
);
955 ok(gl3Ctx
!= NULL
, "Sharing of a display list between a forward compatible OpenGL 3.0 context and OpenGL 1.x/2.x failed!\n");
957 wglDeleteContext(gl3Ctx
);
960 wglDeleteContext(glCtx
);
963 /* Try to create an OpenGL 3.0 context and test windowless rendering */
966 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
969 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
970 ok(gl3Ctx
!= 0, "pwglCreateContextAttribsARB for a 3.0 context failed!\n");
972 /* OpenGL 3.0 allows offscreen rendering WITHOUT a drawable
973 * Neither AMD or Nvidia support it at this point. The WGL_ARB_create_context specs also say that
974 * it is hard because drivers use the HDC to enter the display driver and it sounds like they don't
975 * expect drivers to ever offer it.
977 res
= wglMakeCurrent(0, gl3Ctx
);
978 ok(res
== FALSE
, "Wow, OpenGL 3.0 windowless rendering passed while it was expected not to!\n");
980 wglMakeCurrent(0, 0);
983 wglDeleteContext(gl3Ctx
);
987 static void test_minimized(void)
989 PIXELFORMATDESCRIPTOR pf_desc
=
991 sizeof(PIXELFORMATDESCRIPTOR
),
993 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
995 24, /* 24-bit color depth */
996 0, 0, 0, 0, 0, 0, /* color bits */
997 0, /* alpha buffer */
999 0, /* accumulation buffer */
1000 0, 0, 0, 0, /* accum bits */
1002 0, /* stencil buffer */
1003 0, /* auxiliary buffer */
1004 PFD_MAIN_PLANE
, /* main layer */
1006 0, 0, 0 /* layer masks */
1015 window
= CreateWindowA("static", "opengl32_test",
1016 WS_POPUP
| WS_MINIMIZE
, 0, 0, 640, 480, 0, 0, 0, 0);
1017 ok(!!window
, "Failed to create window, last error %#x.\n", GetLastError());
1020 ok(!!dc
, "Failed to get DC.\n");
1022 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1025 win_skip("Failed to find pixel format.\n");
1026 ReleaseDC(window
, dc
);
1027 DestroyWindow(window
);
1031 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1032 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1034 style
= GetWindowLongA(window
, GWL_STYLE
);
1035 ok(style
& WS_MINIMIZE
, "Window should be minimized, got style %#x.\n", style
);
1037 ctx
= wglCreateContext(dc
);
1038 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1040 ret
= wglMakeCurrent(dc
, ctx
);
1041 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1043 style
= GetWindowLongA(window
, GWL_STYLE
);
1044 ok(style
& WS_MINIMIZE
, "window should be minimized, got style %#x.\n", style
);
1046 ret
= wglMakeCurrent(NULL
, NULL
);
1047 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1049 ret
= wglDeleteContext(ctx
);
1050 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1052 ReleaseDC(window
, dc
);
1053 DestroyWindow(window
);
1056 static void test_window_dc(void)
1058 PIXELFORMATDESCRIPTOR pf_desc
=
1060 sizeof(PIXELFORMATDESCRIPTOR
),
1062 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1064 24, /* 24-bit color depth */
1065 0, 0, 0, 0, 0, 0, /* color bits */
1066 0, /* alpha buffer */
1068 0, /* accumulation buffer */
1069 0, 0, 0, 0, /* accum bits */
1071 0, /* stencil buffer */
1072 0, /* auxiliary buffer */
1073 PFD_MAIN_PLANE
, /* main layer */
1075 0, 0, 0 /* layer masks */
1084 window
= CreateWindowA("static", "opengl32_test",
1085 WS_OVERLAPPEDWINDOW
, 0, 0, 640, 480, 0, 0, 0, 0);
1086 ok(!!window
, "Failed to create window, last error %#x.\n", GetLastError());
1088 ShowWindow(window
, SW_SHOW
);
1090 dc
= GetWindowDC(window
);
1091 ok(!!dc
, "Failed to get DC.\n");
1093 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1096 win_skip("Failed to find pixel format.\n");
1097 ReleaseDC(window
, dc
);
1098 DestroyWindow(window
);
1102 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1103 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1105 ctx
= wglCreateContext(dc
);
1106 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1108 ret
= wglMakeCurrent(dc
, ctx
);
1109 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1111 GetClientRect(window
, &r
);
1112 glGetIntegerv(GL_VIEWPORT
, (GLint
*)&vp
);
1113 ok(EqualRect(&r
, &vp
), "Viewport not equal to client rect.\n");
1115 ret
= wglMakeCurrent(NULL
, NULL
);
1116 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1118 ret
= wglDeleteContext(ctx
);
1119 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1121 ReleaseDC(window
, dc
);
1122 DestroyWindow(window
);
1125 static void test_message_window(void)
1127 PIXELFORMATDESCRIPTOR pf_desc
=
1129 sizeof(PIXELFORMATDESCRIPTOR
),
1131 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1133 24, /* 24-bit color depth */
1134 0, 0, 0, 0, 0, 0, /* color bits */
1135 0, /* alpha buffer */
1137 0, /* accumulation buffer */
1138 0, 0, 0, 0, /* accum bits */
1140 0, /* stencil buffer */
1141 0, /* auxiliary buffer */
1142 PFD_MAIN_PLANE
, /* main layer */
1144 0, 0, 0 /* layer masks */
1154 window
= CreateWindowA("static", "opengl32_test",
1155 WS_OVERLAPPEDWINDOW
, 0, 0, 100, 100, HWND_MESSAGE
, 0, 0, 0);
1158 win_skip( "HWND_MESSAGE not supported\n" );
1162 ok(!!dc
, "Failed to get DC.\n");
1164 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1167 win_skip("Failed to find pixel format.\n");
1168 ReleaseDC(window
, dc
);
1169 DestroyWindow(window
);
1173 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1174 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1176 ctx
= wglCreateContext(dc
);
1177 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1179 ret
= wglMakeCurrent(dc
, ctx
);
1180 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1182 GetClientRect(window
, &r
);
1183 glGetIntegerv(GL_VIEWPORT
, (GLint
*)&vp
);
1184 ok(EqualRect(&r
, &vp
), "Viewport not equal to client rect.\n");
1186 glClear(GL_COLOR_BUFFER_BIT
);
1188 glerr
= glGetError();
1189 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1190 ret
= SwapBuffers(dc
);
1191 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1193 ret
= wglMakeCurrent(NULL
, NULL
);
1194 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1196 ret
= wglDeleteContext(ctx
);
1197 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1199 ReleaseDC(window
, dc
);
1200 DestroyWindow(window
);
1203 static void test_destroy(HDC oldhdc
)
1205 PIXELFORMATDESCRIPTOR pf_desc
=
1207 sizeof(PIXELFORMATDESCRIPTOR
),
1209 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1211 24, /* 24-bit color depth */
1212 0, 0, 0, 0, 0, 0, /* color bits */
1213 0, /* alpha buffer */
1215 0, /* accumulation buffer */
1216 0, 0, 0, 0, /* accum bits */
1218 0, /* stencil buffer */
1219 0, /* auxiliary buffer */
1220 PFD_MAIN_PLANE
, /* main layer */
1222 0, 0, 0 /* layer masks */
1231 HGLRC oldctx
= wglGetCurrentContext();
1233 ok(!!oldctx
, "Expected to find a valid current context.\n");
1235 window
= CreateWindowA("static", "opengl32_test",
1236 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1237 ok(!!window
, "Failed to create window, last error %#x.\n", GetLastError());
1240 ok(!!dc
, "Failed to get DC.\n");
1242 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1245 win_skip("Failed to find pixel format.\n");
1246 ReleaseDC(window
, dc
);
1247 DestroyWindow(window
);
1251 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1252 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1254 ctx
= wglCreateContext(dc
);
1255 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1257 ret
= wglMakeCurrent(dc
, ctx
);
1258 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1260 glClear(GL_COLOR_BUFFER_BIT
);
1262 glerr
= glGetError();
1263 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1264 ret
= SwapBuffers(dc
);
1265 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1267 ret
= DestroyWindow(window
);
1268 ok(ret
, "Failed to destroy window, last error %#x.\n", GetLastError());
1270 ok(wglGetCurrentContext() == ctx
, "Wrong current context.\n");
1272 SetLastError(0xdeadbeef);
1273 ret
= wglMakeCurrent(dc
, ctx
);
1274 err
= GetLastError();
1275 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1276 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1277 SetLastError(0xdeadbeef);
1278 ret
= SwapBuffers(dc
);
1279 err
= GetLastError();
1280 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1282 ok(wglGetCurrentContext() == ctx
, "Wrong current context.\n");
1284 glClear(GL_COLOR_BUFFER_BIT
);
1286 glerr
= glGetError();
1287 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1288 SetLastError(0xdeadbeef);
1289 ret
= SwapBuffers(dc
);
1290 err
= GetLastError();
1291 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1293 ret
= wglMakeCurrent(NULL
, NULL
);
1294 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1296 glClear(GL_COLOR_BUFFER_BIT
);
1298 glerr
= glGetError();
1299 ok(glerr
== GL_INVALID_OPERATION
, "Failed glClear, error %#x.\n", glerr
);
1300 SetLastError(0xdeadbeef);
1301 ret
= SwapBuffers(dc
);
1302 err
= GetLastError();
1303 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1305 SetLastError(0xdeadbeef);
1306 ret
= wglMakeCurrent(dc
, ctx
);
1307 err
= GetLastError();
1308 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1309 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1311 ok(wglGetCurrentContext() == NULL
, "Wrong current context.\n");
1313 ret
= wglMakeCurrent(oldhdc
, oldctx
);
1314 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1315 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1317 SetLastError(0xdeadbeef);
1318 ret
= wglMakeCurrent(dc
, ctx
);
1319 err
= GetLastError();
1320 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1321 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1323 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1325 ret
= wglDeleteContext(ctx
);
1326 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1328 ReleaseDC(window
, dc
);
1330 ret
= wglMakeCurrent(oldhdc
, oldctx
);
1331 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1334 static void test_destroy_read(HDC oldhdc
)
1336 PIXELFORMATDESCRIPTOR pf_desc
=
1338 sizeof(PIXELFORMATDESCRIPTOR
),
1340 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1342 24, /* 24-bit color depth */
1343 0, 0, 0, 0, 0, 0, /* color bits */
1344 0, /* alpha buffer */
1346 0, /* accumulation buffer */
1347 0, 0, 0, 0, /* accum bits */
1349 0, /* stencil buffer */
1350 0, /* auxiliary buffer */
1351 PFD_MAIN_PLANE
, /* main layer */
1353 0, 0, 0 /* layer masks */
1356 HWND draw_window
, read_window
;
1359 HDC read_dc
, draw_dc
;
1362 HGLRC oldctx
= wglGetCurrentContext();
1364 ok(!!oldctx
, "Expected to find a valid current context\n");
1366 draw_window
= CreateWindowA("static", "opengl32_test",
1367 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1368 ok(!!draw_window
, "Failed to create window, last error %#x.\n", GetLastError());
1370 draw_dc
= GetDC(draw_window
);
1371 ok(!!draw_dc
, "Failed to get DC.\n");
1373 pixel_format
= ChoosePixelFormat(draw_dc
, &pf_desc
);
1376 win_skip("Failed to find pixel format.\n");
1377 ReleaseDC(draw_window
, draw_dc
);
1378 DestroyWindow(draw_window
);
1382 ret
= SetPixelFormat(draw_dc
, pixel_format
, &pf_desc
);
1383 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1385 read_window
= CreateWindowA("static", "opengl32_test",
1386 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1387 ok(!!read_window
, "Failed to create window, last error %#x.\n", GetLastError());
1389 read_dc
= GetDC(read_window
);
1390 ok(!!draw_dc
, "Failed to get DC.\n");
1392 pixel_format
= ChoosePixelFormat(read_dc
, &pf_desc
);
1395 win_skip("Failed to find pixel format.\n");
1396 ReleaseDC(read_window
, read_dc
);
1397 DestroyWindow(read_window
);
1398 ReleaseDC(draw_window
, draw_dc
);
1399 DestroyWindow(draw_window
);
1403 ret
= SetPixelFormat(read_dc
, pixel_format
, &pf_desc
);
1404 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1406 ctx
= wglCreateContext(draw_dc
);
1407 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1409 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1410 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1412 glCopyPixels(0, 0, 640, 480, GL_COLOR
);
1414 glerr
= glGetError();
1415 ok(glerr
== GL_NO_ERROR
, "Failed glCopyPixel, error %#x.\n", glerr
);
1416 ret
= SwapBuffers(draw_dc
);
1417 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1419 ret
= DestroyWindow(read_window
);
1420 ok(ret
, "Failed to destroy window, last error %#x.\n", GetLastError());
1422 ok(wglGetCurrentContext() == ctx
, "Wrong current context.\n");
1424 if (0) /* Crashes on AMD on Windows */
1426 glCopyPixels(0, 0, 640, 480, GL_COLOR
);
1428 glerr
= glGetError();
1429 ok(glerr
== GL_NO_ERROR
, "Failed glCopyPixel, error %#x.\n", glerr
);
1432 glClear(GL_COLOR_BUFFER_BIT
);
1434 glerr
= glGetError();
1435 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1436 ret
= SwapBuffers(draw_dc
);
1437 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1439 ret
= wglMakeCurrent(NULL
, NULL
);
1440 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1442 if (0) /* This crashes with Nvidia drivers on Windows. */
1444 SetLastError(0xdeadbeef);
1445 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1446 err
= GetLastError();
1447 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1448 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1451 ret
= DestroyWindow(draw_window
);
1452 ok(ret
, "Failed to destroy window, last error %#x.\n", GetLastError());
1454 glClear(GL_COLOR_BUFFER_BIT
);
1456 glerr
= glGetError();
1457 ok(glerr
== GL_INVALID_OPERATION
, "Failed glClear, error %#x.\n", glerr
);
1458 SetLastError(0xdeadbeef);
1459 ret
= SwapBuffers(draw_dc
);
1460 err
= GetLastError();
1461 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1463 SetLastError(0xdeadbeef);
1464 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1465 err
= GetLastError();
1466 ok(!ret
&& (err
== ERROR_INVALID_HANDLE
|| err
== 0xc0070006),
1467 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1469 ok(wglGetCurrentContext() == NULL
, "Wrong current context.\n");
1471 wglMakeCurrent(NULL
, NULL
);
1473 wglMakeCurrent(oldhdc
, oldctx
);
1474 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1476 SetLastError(0xdeadbeef);
1477 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1478 err
= GetLastError();
1479 ok(!ret
&& (err
== ERROR_INVALID_HANDLE
|| err
== 0xc0070006),
1480 "Unexpected behavior when making context current, last error %#x.\n", err
);
1482 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1484 ret
= wglDeleteContext(ctx
);
1485 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1487 ReleaseDC(read_window
, read_dc
);
1488 ReleaseDC(draw_window
, draw_dc
);
1490 wglMakeCurrent(oldhdc
, oldctx
);
1493 static void test_swap_control(HDC oldhdc
)
1495 PIXELFORMATDESCRIPTOR pf_desc
=
1497 sizeof(PIXELFORMATDESCRIPTOR
),
1499 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1501 24, /* 24-bit color depth */
1502 0, 0, 0, 0, 0, 0, /* color bits */
1503 0, /* alpha buffer */
1505 0, /* accumulation buffer */
1506 0, 0, 0, 0, /* accum bits */
1508 0, /* stencil buffer */
1509 0, /* auxiliary buffer */
1510 PFD_MAIN_PLANE
, /* main layer */
1512 0, 0, 0 /* layer masks */
1515 HWND window1
, window2
, old_parent
;
1516 HGLRC ctx1
, ctx2
, oldctx
;
1521 oldctx
= wglGetCurrentContext();
1522 ok(!!oldctx
, "Expected to find a valid current context.\n");
1524 window1
= CreateWindowA("static", "opengl32_test",
1525 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1526 ok(!!window1
, "Failed to create window1, last error %#x.\n", GetLastError());
1528 dc1
= GetDC(window1
);
1529 ok(!!dc1
, "Failed to get DC.\n");
1531 pixel_format
= ChoosePixelFormat(dc1
, &pf_desc
);
1534 win_skip("Failed to find pixel format.\n");
1535 ReleaseDC(window1
, dc1
);
1536 DestroyWindow(window1
);
1540 ret
= SetPixelFormat(dc1
, pixel_format
, &pf_desc
);
1541 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1543 ctx1
= wglCreateContext(dc1
);
1544 ok(!!ctx1
, "Failed to create GL context, last error %#x.\n", GetLastError());
1546 ret
= wglMakeCurrent(dc1
, ctx1
);
1547 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1549 interval
= pwglGetSwapIntervalEXT();
1550 ok(interval
== 1, "Expected default swap interval 1, got %d\n", interval
);
1552 ret
= pwglSwapIntervalEXT(0);
1553 ok(ret
, "Failed to set swap interval to 0, last error %#x.\n", GetLastError());
1555 interval
= pwglGetSwapIntervalEXT();
1556 ok(interval
== 0, "Expected swap interval 0, got %d\n", interval
);
1558 /* Check what interval we get on a second context on the same drawable.*/
1559 ctx2
= wglCreateContext(dc1
);
1560 ok(!!ctx2
, "Failed to create GL context, last error %#x.\n", GetLastError());
1562 ret
= wglMakeCurrent(dc1
, ctx2
);
1563 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1565 interval
= pwglGetSwapIntervalEXT();
1566 ok(interval
== 0, "Expected swap interval 0, got %d\n", interval
);
1568 /* A second window is created to see whether its swap interval was affected
1569 * by previous calls.
1571 window2
= CreateWindowA("static", "opengl32_test",
1572 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1573 ok(!!window2
, "Failed to create window2, last error %#x.\n", GetLastError());
1575 dc2
= GetDC(window2
);
1576 ok(!!dc2
, "Failed to get DC.\n");
1578 ret
= SetPixelFormat(dc2
, pixel_format
, &pf_desc
);
1579 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1581 ret
= wglMakeCurrent(dc2
, ctx1
);
1582 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1584 /* Since the second window lacks the swap interval, this proves that the interval
1585 * is not global or shared among contexts.
1587 interval
= pwglGetSwapIntervalEXT();
1588 ok(interval
== 1, "Expected default swap interval 1, got %d\n", interval
);
1590 /* Test if setting the parent of a window resets the swap interval. */
1591 ret
= wglMakeCurrent(dc1
, ctx1
);
1592 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1594 old_parent
= SetParent(window1
, window2
);
1595 ok(!!old_parent
, "Failed to make window1 a child of window2, last error %#x.\n", GetLastError());
1597 interval
= pwglGetSwapIntervalEXT();
1598 ok(interval
== 0, "Expected swap interval 0, got %d\n", interval
);
1600 ret
= wglDeleteContext(ctx1
);
1601 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1602 ret
= wglDeleteContext(ctx2
);
1603 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1605 ReleaseDC(window1
, dc1
);
1606 DestroyWindow(window1
);
1607 ReleaseDC(window2
, dc2
);
1608 DestroyWindow(window2
);
1610 wglMakeCurrent(oldhdc
, oldctx
);
1616 PIXELFORMATDESCRIPTOR pfd
= {
1617 sizeof(PIXELFORMATDESCRIPTOR
),
1619 PFD_DRAW_TO_WINDOW
|
1620 PFD_SUPPORT_OPENGL
|
1623 24, /* 24-bit color depth */
1624 0, 0, 0, 0, 0, 0, /* color bits */
1625 0, /* alpha buffer */
1627 0, /* accumulation buffer */
1628 0, 0, 0, 0, /* accum bits */
1630 0, /* stencil buffer */
1631 0, /* auxiliary buffer */
1632 PFD_MAIN_PLANE
, /* main layer */
1634 0, 0, 0 /* layer masks */
1637 hwnd
= CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW
, 10, 10, 200, 200, NULL
, NULL
,
1639 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
1643 int iPixelFormat
, res
;
1646 ShowWindow(hwnd
, SW_SHOW
);
1650 iPixelFormat
= ChoosePixelFormat(hdc
, &pfd
);
1651 if(iPixelFormat
== 0)
1653 /* This should never happen as ChoosePixelFormat always returns a closest match, but currently this fails in Wine if we don't have glX */
1654 win_skip("Unable to find pixel format.\n");
1658 /* We shouldn't be able to create a context from a hdc which doesn't have a pixel format set */
1659 hglrc
= wglCreateContext(hdc
);
1660 ok(hglrc
== NULL
, "wglCreateContext should fail when no pixel format has been set, but it passed\n");
1661 error
= GetLastError();
1662 ok(error
== ERROR_INVALID_PIXEL_FORMAT
, "expected ERROR_INVALID_PIXEL_FORMAT for wglCreateContext without a pixelformat set, but received %#x\n", error
);
1664 res
= SetPixelFormat(hdc
, iPixelFormat
, &pfd
);
1665 ok(res
, "SetPixelformat failed: %x\n", GetLastError());
1667 test_bitmap_rendering( TRUE
);
1668 test_bitmap_rendering( FALSE
);
1671 test_message_window();
1674 ok(!glGetString(GL_RENDERER
) && !glGetString(GL_VERSION
) && !glGetString(GL_VENDOR
),
1675 "Expected NULL string when no active context is set\n");
1676 hglrc
= wglCreateContext(hdc
);
1677 res
= wglMakeCurrent(hdc
, hglrc
);
1678 ok(res
, "wglMakeCurrent failed!\n");
1681 trace("OpenGL renderer: %s\n", glGetString(GL_RENDERER
));
1682 trace("OpenGL driver version: %s\n", glGetString(GL_VERSION
));
1683 trace("OpenGL vendor: %s\n", glGetString(GL_VENDOR
));
1687 skip("Skipping OpenGL tests without a current context\n");
1691 /* Initialisation of WGL functions depends on an implicit WGL context. For this reason we can't load them before making
1692 * any WGL call :( On Wine this would work but not on real Windows because there can be different implementations (software, ICD, MCD).
1695 test_getprocaddress(hdc
);
1696 test_deletecontext(hwnd
, hdc
);
1697 test_makecurrent(hdc
);
1699 /* The lack of wglGetExtensionsStringARB in general means broken software rendering or the lack of decent OpenGL support, skip tests in such cases */
1700 if (!pwglGetExtensionsStringARB
)
1702 win_skip("wglGetExtensionsStringARB is not available\n");
1706 test_setpixelformat(hdc
);
1708 test_sharelists(hdc
);
1709 test_colorbits(hdc
);
1711 test_acceleration(hdc
);
1713 wgl_extensions
= pwglGetExtensionsStringARB(hdc
);
1714 if(wgl_extensions
== NULL
) skip("Skipping opengl32 tests because this OpenGL implementation doesn't support WGL extensions!\n");
1716 if(strstr(wgl_extensions
, "WGL_ARB_create_context"))
1719 if(strstr(wgl_extensions
, "WGL_ARB_make_current_read"))
1721 test_make_current_read(hdc
);
1722 test_destroy_read(hdc
);
1725 skip("WGL_ARB_make_current_read not supported, skipping test\n");
1727 if(strstr(wgl_extensions
, "WGL_ARB_pbuffer"))
1730 skip("WGL_ARB_pbuffer not supported, skipping pbuffer test\n");
1732 if(strstr(wgl_extensions
, "WGL_EXT_swap_control"))
1733 test_swap_control(hdc
);
1735 skip("WGL_EXT_swap_control not supported, skipping test\n");
1738 ReleaseDC(hwnd
, hdc
);
1739 DestroyWindow(hwnd
);