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 SetLastError(0xdeadbeef);
719 p
->make_current
= wglMakeCurrent(hdc
, p
->hglrc
);
720 p
->make_current_error
= GetLastError();
721 p
->deleted
= wglDeleteContext(p
->hglrc
);
722 p
->deleted_error
= GetLastError();
723 ReleaseDC( p
->hwnd
, hdc
);
724 SetEvent(p
->test_finished
);
728 static void test_deletecontext(HWND hwnd
, HDC hdc
)
730 struct wgl_thread_param thread_params
;
731 HGLRC hglrc
= wglCreateContext(hdc
);
732 HANDLE thread_handle
;
736 SetLastError(0xdeadbeef);
737 res
= wglDeleteContext(NULL
);
738 ok(res
== FALSE
, "wglDeleteContext succeeded\n");
739 ok(GetLastError() == ERROR_INVALID_HANDLE
, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
743 skip("wglCreateContext failed!\n");
747 res
= wglMakeCurrent(hdc
, hglrc
);
750 skip("wglMakeCurrent failed!\n");
754 /* WGL doesn't allow you to delete a context from a different thread than the one in which it is current.
755 * This differs from GLX which does allow it but it delays actual deletion until the context becomes not current.
757 thread_params
.hglrc
= hglrc
;
758 thread_params
.hwnd
= hwnd
;
759 thread_params
.test_finished
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
760 thread_handle
= CreateThread(NULL
, 0, wgl_thread
, &thread_params
, 0, &tid
);
761 ok(!!thread_handle
, "Failed to create thread, last error %#x.\n", GetLastError());
764 WaitForSingleObject(thread_handle
, INFINITE
);
765 ok(!thread_params
.make_current
, "Attempt to make WGL context from another thread passed\n");
766 ok(thread_params
.make_current_error
== ERROR_BUSY
, "Expected last error to be ERROR_BUSY, got %u\n", thread_params
.make_current_error
);
767 ok(!thread_params
.deleted
, "Attempt to delete WGL context from another thread passed\n");
768 ok(thread_params
.deleted_error
== ERROR_BUSY
, "Expected last error to be ERROR_BUSY, got %u\n", thread_params
.deleted_error
);
770 CloseHandle(thread_params
.test_finished
);
772 res
= wglDeleteContext(hglrc
);
773 ok(res
== TRUE
, "wglDeleteContext failed\n");
775 /* Attempting to delete the same context twice should fail. */
776 SetLastError(0xdeadbeef);
777 res
= wglDeleteContext(hglrc
);
778 ok(res
== FALSE
, "wglDeleteContext succeeded\n");
779 ok(GetLastError() == ERROR_INVALID_HANDLE
, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
781 /* WGL makes a context not current when deleting it. This differs from GLX behavior where
782 * deletion takes place when the thread becomes not current. */
783 hglrc
= wglGetCurrentContext();
784 ok(hglrc
== NULL
, "A WGL context is active while none was expected\n");
788 static void test_getprocaddress(HDC hdc
)
790 const char *extensions
= (const char*)glGetString(GL_EXTENSIONS
);
792 HGLRC ctx
= wglGetCurrentContext();
796 skip("skipping wglGetProcAddress tests because no GL extensions supported\n");
800 /* Core GL 1.0/1.1 functions should not be loadable through wglGetProcAddress.
801 * Try to load the function with and without a context.
803 func
= wglGetProcAddress("glEnable");
804 ok(func
== NULL
, "Lookup of function glEnable with a context passed, expected a failure\n");
805 wglMakeCurrent(hdc
, NULL
);
806 func
= wglGetProcAddress("glEnable");
807 ok(func
== NULL
, "Lookup of function glEnable without a context passed, expected a failure\n");
808 wglMakeCurrent(hdc
, ctx
);
810 /* The goal of the test will be to test behavior of wglGetProcAddress when
811 * no WGL context is active. Before the test we pick an extension (GL_ARB_multitexture)
812 * which any GL >=1.2.1 implementation supports. Unfortunately the GDI renderer doesn't
813 * support it. There aren't any extensions we can use for this test which are supported by
814 * both GDI and real drivers.
815 * Note GDI only has GL_EXT_bgra, GL_EXT_paletted_texture and GL_WIN_swap_hint.
817 if (!gl_extension_supported(extensions
, "GL_ARB_multitexture"))
819 skip("skipping test because lack of GL_ARB_multitexture support\n");
823 func
= wglGetProcAddress("glActiveTextureARB");
824 ok(func
!= NULL
, "Unable to lookup glActiveTextureARB, last error %#x\n", GetLastError());
826 /* Temporarily disable the context, so we can see that we can't retrieve functions now. */
827 wglMakeCurrent(hdc
, NULL
);
828 func
= wglGetProcAddress("glActiveTextureARB");
829 ok(func
== NULL
, "Function lookup without a context passed, expected a failure; last error %#x\n", GetLastError());
830 wglMakeCurrent(hdc
, ctx
);
833 static void test_make_current_read(HDC hdc
)
837 HGLRC hglrc
= wglCreateContext(hdc
);
841 skip("wglCreateContext failed!\n");
845 res
= wglMakeCurrent(hdc
, hglrc
);
848 skip("wglMakeCurrent failed!\n");
852 /* Test what wglGetCurrentReadDCARB does for wglMakeCurrent as the spec doesn't mention it */
853 hread
= pwglGetCurrentReadDCARB();
854 trace("hread %p, hdc %p\n", hread
, hdc
);
855 ok(hread
== hdc
, "wglGetCurrentReadDCARB failed for standard wglMakeCurrent\n");
857 pwglMakeContextCurrentARB(hdc
, hdc
, hglrc
);
858 hread
= pwglGetCurrentReadDCARB();
859 ok(hread
== hdc
, "wglGetCurrentReadDCARB failed for wglMakeContextCurrent\n");
862 static void test_dc(HWND hwnd
, HDC hdc
)
867 /* Get another DC and make sure it has the same pixel format */
871 pf1
= GetPixelFormat(hdc
);
872 pf2
= GetPixelFormat(hdc2
);
873 ok(pf1
== pf2
, "Second DC does not have the same format (%d != %d)\n", pf1
, pf2
);
876 skip("Could not get a different DC for the window\n");
880 ReleaseDC(hwnd
, hdc2
);
885 /* Nvidia converts win32 error codes to (0xc007 << 16) | win32_error_code */
886 #define NVIDIA_HRESULT_FROM_WIN32(x) (HRESULT_FROM_WIN32(x) | 0x40000000)
887 static void test_opengl3(HDC hdc
)
889 /* Try to create a context compatible with OpenGL 1.x; 1.0-2.1 is allowed */
892 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 1, 0};
894 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
895 ok(gl3Ctx
!= 0, "pwglCreateContextAttribsARB for a 1.x context failed!\n");
896 wglDeleteContext(gl3Ctx
);
899 /* Try to pass an invalid HDC */
903 gl3Ctx
= pwglCreateContextAttribsARB((HDC
)0xdeadbeef, 0, 0);
904 ok(gl3Ctx
== 0, "pwglCreateContextAttribsARB using an invalid HDC passed\n");
905 error
= GetLastError();
906 todo_wine
ok(error
== ERROR_DC_NOT_FOUND
||
907 broken(error
== NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_DATA
)), /* Nvidia Vista + Win7 */
908 "Expected ERROR_DC_NOT_FOUND, got error=%x\n", error
);
909 wglDeleteContext(gl3Ctx
);
912 /* Try to pass an invalid shareList */
916 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, (HGLRC
)0xdeadbeef, 0);
917 ok(gl3Ctx
== 0, "pwglCreateContextAttribsARB using an invalid shareList passed\n");
918 error
= GetLastError();
919 /* The Nvidia implementation seems to return hresults instead of win32 error codes */
920 todo_wine
ok(error
== ERROR_INVALID_OPERATION
||
921 error
== NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_OPERATION
), "Expected ERROR_INVALID_OPERATION, got error=%x\n", error
);
922 wglDeleteContext(gl3Ctx
);
925 /* Try to create an OpenGL 3.0 context */
927 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
928 HGLRC gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
932 skip("Skipping the rest of the WGL_ARB_create_context test due to lack of OpenGL 3.0\n");
936 wglDeleteContext(gl3Ctx
);
939 /* 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 */
941 HGLRC glCtx
= wglCreateContext(hdc
);
943 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
944 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};
946 HGLRC gl3Ctx
= pwglCreateContextAttribsARB(hdc
, glCtx
, attribs
);
947 ok(gl3Ctx
!= NULL
, "Sharing of a display list between OpenGL 3.0 and OpenGL 1.x/2.x failed!\n");
949 wglDeleteContext(gl3Ctx
);
951 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, glCtx
, attribs_future
);
952 ok(gl3Ctx
!= NULL
, "Sharing of a display list between a forward compatible OpenGL 3.0 context and OpenGL 1.x/2.x failed!\n");
954 wglDeleteContext(gl3Ctx
);
957 wglDeleteContext(glCtx
);
960 /* Try to create an OpenGL 3.0 context and test windowless rendering */
963 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
966 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
967 ok(gl3Ctx
!= 0, "pwglCreateContextAttribsARB for a 3.0 context failed!\n");
969 /* OpenGL 3.0 allows offscreen rendering WITHOUT a drawable
970 * Neither AMD or Nvidia support it at this point. The WGL_ARB_create_context specs also say that
971 * it is hard because drivers use the HDC to enter the display driver and it sounds like they don't
972 * expect drivers to ever offer it.
974 res
= wglMakeCurrent(0, gl3Ctx
);
975 ok(res
== FALSE
, "Wow, OpenGL 3.0 windowless rendering passed while it was expected not to!\n");
977 wglMakeCurrent(0, 0);
980 wglDeleteContext(gl3Ctx
);
984 static void test_minimized(void)
986 PIXELFORMATDESCRIPTOR pf_desc
=
988 sizeof(PIXELFORMATDESCRIPTOR
),
990 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
992 24, /* 24-bit color depth */
993 0, 0, 0, 0, 0, 0, /* color bits */
994 0, /* alpha buffer */
996 0, /* accumulation buffer */
997 0, 0, 0, 0, /* accum bits */
999 0, /* stencil buffer */
1000 0, /* auxiliary buffer */
1001 PFD_MAIN_PLANE
, /* main layer */
1003 0, 0, 0 /* layer masks */
1012 window
= CreateWindowA("static", "opengl32_test",
1013 WS_POPUP
| WS_MINIMIZE
, 0, 0, 640, 480, 0, 0, 0, 0);
1014 ok(!!window
, "Failed to create window, last error %#x.\n", GetLastError());
1017 ok(!!dc
, "Failed to get DC.\n");
1019 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1022 win_skip("Failed to find pixel format.\n");
1023 ReleaseDC(window
, dc
);
1024 DestroyWindow(window
);
1028 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1029 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1031 style
= GetWindowLongA(window
, GWL_STYLE
);
1032 ok(style
& WS_MINIMIZE
, "Window should be minimized, got style %#x.\n", style
);
1034 ctx
= wglCreateContext(dc
);
1035 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1037 ret
= wglMakeCurrent(dc
, ctx
);
1038 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1040 style
= GetWindowLongA(window
, GWL_STYLE
);
1041 ok(style
& WS_MINIMIZE
, "window should be minimized, got style %#x.\n", style
);
1043 ret
= wglMakeCurrent(NULL
, NULL
);
1044 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1046 ret
= wglDeleteContext(ctx
);
1047 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1049 ReleaseDC(window
, dc
);
1050 DestroyWindow(window
);
1053 static void test_window_dc(void)
1055 PIXELFORMATDESCRIPTOR pf_desc
=
1057 sizeof(PIXELFORMATDESCRIPTOR
),
1059 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1061 24, /* 24-bit color depth */
1062 0, 0, 0, 0, 0, 0, /* color bits */
1063 0, /* alpha buffer */
1065 0, /* accumulation buffer */
1066 0, 0, 0, 0, /* accum bits */
1068 0, /* stencil buffer */
1069 0, /* auxiliary buffer */
1070 PFD_MAIN_PLANE
, /* main layer */
1072 0, 0, 0 /* layer masks */
1081 window
= CreateWindowA("static", "opengl32_test",
1082 WS_OVERLAPPEDWINDOW
, 0, 0, 640, 480, 0, 0, 0, 0);
1083 ok(!!window
, "Failed to create window, last error %#x.\n", GetLastError());
1085 ShowWindow(window
, SW_SHOW
);
1087 dc
= GetWindowDC(window
);
1088 ok(!!dc
, "Failed to get DC.\n");
1090 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1093 win_skip("Failed to find pixel format.\n");
1094 ReleaseDC(window
, dc
);
1095 DestroyWindow(window
);
1099 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1100 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1102 ctx
= wglCreateContext(dc
);
1103 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1105 ret
= wglMakeCurrent(dc
, ctx
);
1106 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1108 GetClientRect(window
, &r
);
1109 glGetIntegerv(GL_VIEWPORT
, (GLint
*)&vp
);
1110 ok(EqualRect(&r
, &vp
), "Viewport not equal to client rect.\n");
1112 ret
= wglMakeCurrent(NULL
, NULL
);
1113 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1115 ret
= wglDeleteContext(ctx
);
1116 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1118 ReleaseDC(window
, dc
);
1119 DestroyWindow(window
);
1122 static void test_message_window(void)
1124 PIXELFORMATDESCRIPTOR pf_desc
=
1126 sizeof(PIXELFORMATDESCRIPTOR
),
1128 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1130 24, /* 24-bit color depth */
1131 0, 0, 0, 0, 0, 0, /* color bits */
1132 0, /* alpha buffer */
1134 0, /* accumulation buffer */
1135 0, 0, 0, 0, /* accum bits */
1137 0, /* stencil buffer */
1138 0, /* auxiliary buffer */
1139 PFD_MAIN_PLANE
, /* main layer */
1141 0, 0, 0 /* layer masks */
1151 window
= CreateWindowA("static", "opengl32_test",
1152 WS_OVERLAPPEDWINDOW
, 0, 0, 100, 100, HWND_MESSAGE
, 0, 0, 0);
1155 win_skip( "HWND_MESSAGE not supported\n" );
1159 ok(!!dc
, "Failed to get DC.\n");
1161 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1164 win_skip("Failed to find pixel format.\n");
1165 ReleaseDC(window
, dc
);
1166 DestroyWindow(window
);
1170 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1171 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1173 ctx
= wglCreateContext(dc
);
1174 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1176 ret
= wglMakeCurrent(dc
, ctx
);
1177 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1179 GetClientRect(window
, &r
);
1180 glGetIntegerv(GL_VIEWPORT
, (GLint
*)&vp
);
1181 ok(EqualRect(&r
, &vp
), "Viewport not equal to client rect.\n");
1183 glClear(GL_COLOR_BUFFER_BIT
);
1185 glerr
= glGetError();
1186 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1187 ret
= SwapBuffers(dc
);
1188 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1190 ret
= wglMakeCurrent(NULL
, NULL
);
1191 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1193 ret
= wglDeleteContext(ctx
);
1194 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1196 ReleaseDC(window
, dc
);
1197 DestroyWindow(window
);
1200 static void test_destroy(HDC oldhdc
)
1202 PIXELFORMATDESCRIPTOR pf_desc
=
1204 sizeof(PIXELFORMATDESCRIPTOR
),
1206 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1208 24, /* 24-bit color depth */
1209 0, 0, 0, 0, 0, 0, /* color bits */
1210 0, /* alpha buffer */
1212 0, /* accumulation buffer */
1213 0, 0, 0, 0, /* accum bits */
1215 0, /* stencil buffer */
1216 0, /* auxiliary buffer */
1217 PFD_MAIN_PLANE
, /* main layer */
1219 0, 0, 0 /* layer masks */
1228 HGLRC oldctx
= wglGetCurrentContext();
1230 ok(!!oldctx
, "Expected to find a valid current context.\n");
1232 window
= CreateWindowA("static", "opengl32_test",
1233 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1234 ok(!!window
, "Failed to create window, last error %#x.\n", GetLastError());
1237 ok(!!dc
, "Failed to get DC.\n");
1239 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1242 win_skip("Failed to find pixel format.\n");
1243 ReleaseDC(window
, dc
);
1244 DestroyWindow(window
);
1248 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1249 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1251 ctx
= wglCreateContext(dc
);
1252 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1254 ret
= wglMakeCurrent(dc
, ctx
);
1255 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1257 glClear(GL_COLOR_BUFFER_BIT
);
1259 glerr
= glGetError();
1260 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1261 ret
= SwapBuffers(dc
);
1262 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1264 ret
= DestroyWindow(window
);
1265 ok(ret
, "Failed to destroy window, last error %#x.\n", GetLastError());
1267 ok(wglGetCurrentContext() == ctx
, "Wrong current context.\n");
1269 SetLastError(0xdeadbeef);
1270 ret
= wglMakeCurrent(dc
, ctx
);
1271 err
= GetLastError();
1272 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1273 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1274 SetLastError(0xdeadbeef);
1275 ret
= SwapBuffers(dc
);
1276 err
= GetLastError();
1277 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1279 ok(wglGetCurrentContext() == ctx
, "Wrong current context.\n");
1281 glClear(GL_COLOR_BUFFER_BIT
);
1283 glerr
= glGetError();
1284 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1285 SetLastError(0xdeadbeef);
1286 ret
= SwapBuffers(dc
);
1287 err
= GetLastError();
1288 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1290 ret
= wglMakeCurrent(NULL
, NULL
);
1291 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1293 glClear(GL_COLOR_BUFFER_BIT
);
1295 glerr
= glGetError();
1296 ok(glerr
== GL_INVALID_OPERATION
, "Failed glClear, error %#x.\n", glerr
);
1297 SetLastError(0xdeadbeef);
1298 ret
= SwapBuffers(dc
);
1299 err
= GetLastError();
1300 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1302 SetLastError(0xdeadbeef);
1303 ret
= wglMakeCurrent(dc
, ctx
);
1304 err
= GetLastError();
1305 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1306 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1308 ok(wglGetCurrentContext() == NULL
, "Wrong current context.\n");
1310 ret
= wglMakeCurrent(oldhdc
, oldctx
);
1311 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1312 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1314 SetLastError(0xdeadbeef);
1315 ret
= wglMakeCurrent(dc
, ctx
);
1316 err
= GetLastError();
1317 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1318 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1320 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1322 ret
= wglDeleteContext(ctx
);
1323 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1325 ReleaseDC(window
, dc
);
1327 ret
= wglMakeCurrent(oldhdc
, oldctx
);
1328 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1331 static void test_destroy_read(HDC oldhdc
)
1333 PIXELFORMATDESCRIPTOR pf_desc
=
1335 sizeof(PIXELFORMATDESCRIPTOR
),
1337 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1339 24, /* 24-bit color depth */
1340 0, 0, 0, 0, 0, 0, /* color bits */
1341 0, /* alpha buffer */
1343 0, /* accumulation buffer */
1344 0, 0, 0, 0, /* accum bits */
1346 0, /* stencil buffer */
1347 0, /* auxiliary buffer */
1348 PFD_MAIN_PLANE
, /* main layer */
1350 0, 0, 0 /* layer masks */
1353 HWND draw_window
, read_window
;
1356 HDC read_dc
, draw_dc
;
1359 HGLRC oldctx
= wglGetCurrentContext();
1361 ok(!!oldctx
, "Expected to find a valid current context\n");
1363 draw_window
= CreateWindowA("static", "opengl32_test",
1364 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1365 ok(!!draw_window
, "Failed to create window, last error %#x.\n", GetLastError());
1367 draw_dc
= GetDC(draw_window
);
1368 ok(!!draw_dc
, "Failed to get DC.\n");
1370 pixel_format
= ChoosePixelFormat(draw_dc
, &pf_desc
);
1373 win_skip("Failed to find pixel format.\n");
1374 ReleaseDC(draw_window
, draw_dc
);
1375 DestroyWindow(draw_window
);
1379 ret
= SetPixelFormat(draw_dc
, pixel_format
, &pf_desc
);
1380 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1382 read_window
= CreateWindowA("static", "opengl32_test",
1383 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1384 ok(!!read_window
, "Failed to create window, last error %#x.\n", GetLastError());
1386 read_dc
= GetDC(read_window
);
1387 ok(!!draw_dc
, "Failed to get DC.\n");
1389 pixel_format
= ChoosePixelFormat(read_dc
, &pf_desc
);
1392 win_skip("Failed to find pixel format.\n");
1393 ReleaseDC(read_window
, read_dc
);
1394 DestroyWindow(read_window
);
1395 ReleaseDC(draw_window
, draw_dc
);
1396 DestroyWindow(draw_window
);
1400 ret
= SetPixelFormat(read_dc
, pixel_format
, &pf_desc
);
1401 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1403 ctx
= wglCreateContext(draw_dc
);
1404 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1406 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1407 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1409 glCopyPixels(0, 0, 640, 480, GL_COLOR
);
1411 glerr
= glGetError();
1412 ok(glerr
== GL_NO_ERROR
, "Failed glCopyPixel, error %#x.\n", glerr
);
1413 ret
= SwapBuffers(draw_dc
);
1414 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1416 ret
= DestroyWindow(read_window
);
1417 ok(ret
, "Failed to destroy window, last error %#x.\n", GetLastError());
1419 ok(wglGetCurrentContext() == ctx
, "Wrong current context.\n");
1421 if (0) /* Crashes on AMD on Windows */
1423 glCopyPixels(0, 0, 640, 480, GL_COLOR
);
1425 glerr
= glGetError();
1426 ok(glerr
== GL_NO_ERROR
, "Failed glCopyPixel, error %#x.\n", glerr
);
1429 glClear(GL_COLOR_BUFFER_BIT
);
1431 glerr
= glGetError();
1432 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1433 ret
= SwapBuffers(draw_dc
);
1434 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1436 ret
= wglMakeCurrent(NULL
, NULL
);
1437 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1439 if (0) /* This crashes with Nvidia drivers on Windows. */
1441 SetLastError(0xdeadbeef);
1442 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1443 err
= GetLastError();
1444 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1445 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1448 ret
= DestroyWindow(draw_window
);
1449 ok(ret
, "Failed to destroy window, last error %#x.\n", GetLastError());
1451 glClear(GL_COLOR_BUFFER_BIT
);
1453 glerr
= glGetError();
1454 ok(glerr
== GL_INVALID_OPERATION
, "Failed glClear, error %#x.\n", glerr
);
1455 SetLastError(0xdeadbeef);
1456 ret
= SwapBuffers(draw_dc
);
1457 err
= GetLastError();
1458 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1460 SetLastError(0xdeadbeef);
1461 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1462 err
= GetLastError();
1463 ok(!ret
&& (err
== ERROR_INVALID_HANDLE
|| err
== 0xc0070006),
1464 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1466 ok(wglGetCurrentContext() == NULL
, "Wrong current context.\n");
1468 wglMakeCurrent(NULL
, NULL
);
1470 wglMakeCurrent(oldhdc
, oldctx
);
1471 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1473 SetLastError(0xdeadbeef);
1474 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1475 err
= GetLastError();
1476 ok(!ret
&& (err
== ERROR_INVALID_HANDLE
|| err
== 0xc0070006),
1477 "Unexpected behavior when making context current, last error %#x.\n", err
);
1479 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1481 ret
= wglDeleteContext(ctx
);
1482 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1484 ReleaseDC(read_window
, read_dc
);
1485 ReleaseDC(draw_window
, draw_dc
);
1487 wglMakeCurrent(oldhdc
, oldctx
);
1490 static void test_swap_control(HDC oldhdc
)
1492 PIXELFORMATDESCRIPTOR pf_desc
=
1494 sizeof(PIXELFORMATDESCRIPTOR
),
1496 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1498 24, /* 24-bit color depth */
1499 0, 0, 0, 0, 0, 0, /* color bits */
1500 0, /* alpha buffer */
1502 0, /* accumulation buffer */
1503 0, 0, 0, 0, /* accum bits */
1505 0, /* stencil buffer */
1506 0, /* auxiliary buffer */
1507 PFD_MAIN_PLANE
, /* main layer */
1509 0, 0, 0 /* layer masks */
1512 HWND window1
, window2
, old_parent
;
1513 HGLRC ctx1
, ctx2
, oldctx
;
1518 oldctx
= wglGetCurrentContext();
1519 ok(!!oldctx
, "Expected to find a valid current context.\n");
1521 window1
= CreateWindowA("static", "opengl32_test",
1522 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1523 ok(!!window1
, "Failed to create window1, last error %#x.\n", GetLastError());
1525 dc1
= GetDC(window1
);
1526 ok(!!dc1
, "Failed to get DC.\n");
1528 pixel_format
= ChoosePixelFormat(dc1
, &pf_desc
);
1531 win_skip("Failed to find pixel format.\n");
1532 ReleaseDC(window1
, dc1
);
1533 DestroyWindow(window1
);
1537 ret
= SetPixelFormat(dc1
, pixel_format
, &pf_desc
);
1538 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1540 ctx1
= wglCreateContext(dc1
);
1541 ok(!!ctx1
, "Failed to create GL context, last error %#x.\n", GetLastError());
1543 ret
= wglMakeCurrent(dc1
, ctx1
);
1544 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1546 interval
= pwglGetSwapIntervalEXT();
1547 ok(interval
== 1, "Expected default swap interval 1, got %d\n", interval
);
1549 ret
= pwglSwapIntervalEXT(0);
1550 ok(ret
, "Failed to set swap interval to 0, last error %#x.\n", GetLastError());
1552 interval
= pwglGetSwapIntervalEXT();
1553 ok(interval
== 0, "Expected swap interval 0, got %d\n", interval
);
1555 /* Check what interval we get on a second context on the same drawable.*/
1556 ctx2
= wglCreateContext(dc1
);
1557 ok(!!ctx2
, "Failed to create GL context, last error %#x.\n", GetLastError());
1559 ret
= wglMakeCurrent(dc1
, ctx2
);
1560 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1562 interval
= pwglGetSwapIntervalEXT();
1563 ok(interval
== 0, "Expected swap interval 0, got %d\n", interval
);
1565 /* A second window is created to see whether its swap interval was affected
1566 * by previous calls.
1568 window2
= CreateWindowA("static", "opengl32_test",
1569 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1570 ok(!!window2
, "Failed to create window2, last error %#x.\n", GetLastError());
1572 dc2
= GetDC(window2
);
1573 ok(!!dc2
, "Failed to get DC.\n");
1575 ret
= SetPixelFormat(dc2
, pixel_format
, &pf_desc
);
1576 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1578 ret
= wglMakeCurrent(dc2
, ctx1
);
1579 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1581 /* Since the second window lacks the swap interval, this proves that the interval
1582 * is not global or shared among contexts.
1584 interval
= pwglGetSwapIntervalEXT();
1585 ok(interval
== 1, "Expected default swap interval 1, got %d\n", interval
);
1587 /* Test if setting the parent of a window resets the swap interval. */
1588 ret
= wglMakeCurrent(dc1
, ctx1
);
1589 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1591 old_parent
= SetParent(window1
, window2
);
1592 ok(!!old_parent
, "Failed to make window1 a child of window2, last error %#x.\n", GetLastError());
1594 interval
= pwglGetSwapIntervalEXT();
1595 ok(interval
== 0, "Expected swap interval 0, got %d\n", interval
);
1597 ret
= wglDeleteContext(ctx1
);
1598 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1599 ret
= wglDeleteContext(ctx2
);
1600 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1602 ReleaseDC(window1
, dc1
);
1603 DestroyWindow(window1
);
1604 ReleaseDC(window2
, dc2
);
1605 DestroyWindow(window2
);
1607 wglMakeCurrent(oldhdc
, oldctx
);
1613 PIXELFORMATDESCRIPTOR pfd
= {
1614 sizeof(PIXELFORMATDESCRIPTOR
),
1616 PFD_DRAW_TO_WINDOW
|
1617 PFD_SUPPORT_OPENGL
|
1620 24, /* 24-bit color depth */
1621 0, 0, 0, 0, 0, 0, /* color bits */
1622 0, /* alpha buffer */
1624 0, /* accumulation buffer */
1625 0, 0, 0, 0, /* accum bits */
1627 0, /* stencil buffer */
1628 0, /* auxiliary buffer */
1629 PFD_MAIN_PLANE
, /* main layer */
1631 0, 0, 0 /* layer masks */
1634 hwnd
= CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW
, 10, 10, 200, 200, NULL
, NULL
,
1636 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
1640 int iPixelFormat
, res
;
1643 ShowWindow(hwnd
, SW_SHOW
);
1647 iPixelFormat
= ChoosePixelFormat(hdc
, &pfd
);
1648 if(iPixelFormat
== 0)
1650 /* This should never happen as ChoosePixelFormat always returns a closest match, but currently this fails in Wine if we don't have glX */
1651 win_skip("Unable to find pixel format.\n");
1655 /* We shouldn't be able to create a context from a hdc which doesn't have a pixel format set */
1656 hglrc
= wglCreateContext(hdc
);
1657 ok(hglrc
== NULL
, "wglCreateContext should fail when no pixel format has been set, but it passed\n");
1658 error
= GetLastError();
1659 ok(error
== ERROR_INVALID_PIXEL_FORMAT
, "expected ERROR_INVALID_PIXEL_FORMAT for wglCreateContext without a pixelformat set, but received %#x\n", error
);
1661 res
= SetPixelFormat(hdc
, iPixelFormat
, &pfd
);
1662 ok(res
, "SetPixelformat failed: %x\n", GetLastError());
1664 test_bitmap_rendering( TRUE
);
1665 test_bitmap_rendering( FALSE
);
1668 test_message_window();
1671 hglrc
= wglCreateContext(hdc
);
1672 res
= wglMakeCurrent(hdc
, hglrc
);
1673 ok(res
, "wglMakeCurrent failed!\n");
1676 trace("OpenGL renderer: %s\n", glGetString(GL_RENDERER
));
1677 trace("OpenGL driver version: %s\n", glGetString(GL_VERSION
));
1678 trace("OpenGL vendor: %s\n", glGetString(GL_VENDOR
));
1682 skip("Skipping OpenGL tests without a current context\n");
1686 /* Initialisation of WGL functions depends on an implicit WGL context. For this reason we can't load them before making
1687 * any WGL call :( On Wine this would work but not on real Windows because there can be different implementations (software, ICD, MCD).
1690 test_getprocaddress(hdc
);
1691 test_deletecontext(hwnd
, hdc
);
1692 test_makecurrent(hdc
);
1694 /* The lack of wglGetExtensionsStringARB in general means broken software rendering or the lack of decent OpenGL support, skip tests in such cases */
1695 if (!pwglGetExtensionsStringARB
)
1697 win_skip("wglGetExtensionsStringARB is not available\n");
1701 test_setpixelformat(hdc
);
1703 test_sharelists(hdc
);
1704 test_colorbits(hdc
);
1706 test_acceleration(hdc
);
1708 wgl_extensions
= pwglGetExtensionsStringARB(hdc
);
1709 if(wgl_extensions
== NULL
) skip("Skipping opengl32 tests because this OpenGL implementation doesn't support WGL extensions!\n");
1711 if(strstr(wgl_extensions
, "WGL_ARB_create_context"))
1714 if(strstr(wgl_extensions
, "WGL_ARB_make_current_read"))
1716 test_make_current_read(hdc
);
1717 test_destroy_read(hdc
);
1720 skip("WGL_ARB_make_current_read not supported, skipping test\n");
1722 if(strstr(wgl_extensions
, "WGL_ARB_pbuffer"))
1725 skip("WGL_ARB_pbuffer not supported, skipping pbuffer test\n");
1727 if(strstr(wgl_extensions
, "WGL_EXT_swap_control"))
1728 test_swap_control(hdc
);
1730 skip("WGL_EXT_swap_control not supported, skipping test\n");
1733 ReleaseDC(hwnd
, hdc
);
1734 DestroyWindow(hwnd
);