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
= CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW
,
307 10, 10, 200, 200, NULL
, NULL
, 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
= CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW
,
327 10, 10, 200, 200, NULL
, NULL
, 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
;
735 SetLastError(0xdeadbeef);
736 res
= wglDeleteContext(NULL
);
737 ok(res
== FALSE
, "wglDeleteContext succeeded\n");
738 ok(GetLastError() == ERROR_INVALID_HANDLE
, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
742 skip("wglCreateContext failed!\n");
746 res
= wglMakeCurrent(hdc
, hglrc
);
749 skip("wglMakeCurrent failed!\n");
753 /* WGL doesn't allow you to delete a context from a different thread than the one in which it is current.
754 * This differs from GLX which does allow it but it delays actual deletion until the context becomes not current.
756 thread_params
.hglrc
= hglrc
;
757 thread_params
.hwnd
= hwnd
;
758 thread_params
.test_finished
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
759 thread_handle
= CreateThread(NULL
, 0, wgl_thread
, &thread_params
, 0, &tid
);
760 ok(!!thread_handle
, "Failed to create thread, last error %#x.\n", GetLastError());
763 WaitForSingleObject(thread_handle
, INFINITE
);
764 ok(!thread_params
.make_current
, "Attempt to make WGL context from another thread passed\n");
765 ok(thread_params
.make_current_error
== ERROR_BUSY
, "Expected last error to be ERROR_BUSY, got %u\n", thread_params
.make_current_error
);
766 ok(!thread_params
.deleted
, "Attempt to delete WGL context from another thread passed\n");
767 ok(thread_params
.deleted_error
== ERROR_BUSY
, "Expected last error to be ERROR_BUSY, got %u\n", thread_params
.deleted_error
);
769 CloseHandle(thread_params
.test_finished
);
771 res
= wglDeleteContext(hglrc
);
772 ok(res
== TRUE
, "wglDeleteContext failed\n");
774 /* Attempting to delete the same context twice should fail. */
775 SetLastError(0xdeadbeef);
776 res
= wglDeleteContext(hglrc
);
777 ok(res
== FALSE
, "wglDeleteContext succeeded\n");
778 ok(GetLastError() == ERROR_INVALID_HANDLE
, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
780 /* WGL makes a context not current when deleting it. This differs from GLX behavior where
781 * deletion takes place when the thread becomes not current. */
782 hglrc
= wglGetCurrentContext();
783 ok(hglrc
== NULL
, "A WGL context is active while none was expected\n");
787 static void test_getprocaddress(HDC hdc
)
789 const char *extensions
= (const char*)glGetString(GL_EXTENSIONS
);
791 HGLRC ctx
= wglGetCurrentContext();
795 skip("skipping wglGetProcAddress tests because no GL extensions supported\n");
799 /* Core GL 1.0/1.1 functions should not be loadable through wglGetProcAddress.
800 * Try to load the function with and without a context.
802 func
= wglGetProcAddress("glEnable");
803 ok(func
== NULL
, "Lookup of function glEnable with a context passed, expected a failure\n");
804 wglMakeCurrent(hdc
, NULL
);
805 func
= wglGetProcAddress("glEnable");
806 ok(func
== NULL
, "Lookup of function glEnable without a context passed, expected a failure\n");
807 wglMakeCurrent(hdc
, ctx
);
809 /* The goal of the test will be to test behavior of wglGetProcAddress when
810 * no WGL context is active. Before the test we pick an extension (GL_ARB_multitexture)
811 * which any GL >=1.2.1 implementation supports. Unfortunately the GDI renderer doesn't
812 * support it. There aren't any extensions we can use for this test which are supported by
813 * both GDI and real drivers.
814 * Note GDI only has GL_EXT_bgra, GL_EXT_paletted_texture and GL_WIN_swap_hint.
816 if (!gl_extension_supported(extensions
, "GL_ARB_multitexture"))
818 skip("skipping test because lack of GL_ARB_multitexture support\n");
822 func
= wglGetProcAddress("glActiveTextureARB");
823 ok(func
!= NULL
, "Unable to lookup glActiveTextureARB, last error %#x\n", GetLastError());
825 /* Temporarily disable the context, so we can see that we can't retrieve functions now. */
826 wglMakeCurrent(hdc
, NULL
);
827 func
= wglGetProcAddress("glActiveTextureARB");
828 ok(func
== NULL
, "Function lookup without a context passed, expected a failure; last error %#x\n", GetLastError());
829 wglMakeCurrent(hdc
, ctx
);
832 static void test_make_current_read(HDC hdc
)
836 HGLRC hglrc
= wglCreateContext(hdc
);
840 skip("wglCreateContext failed!\n");
844 res
= wglMakeCurrent(hdc
, hglrc
);
847 skip("wglMakeCurrent failed!\n");
851 /* Test what wglGetCurrentReadDCARB does for wglMakeCurrent as the spec doesn't mention it */
852 hread
= pwglGetCurrentReadDCARB();
853 trace("hread %p, hdc %p\n", hread
, hdc
);
854 ok(hread
== hdc
, "wglGetCurrentReadDCARB failed for standard wglMakeCurrent\n");
856 pwglMakeContextCurrentARB(hdc
, hdc
, hglrc
);
857 hread
= pwglGetCurrentReadDCARB();
858 ok(hread
== hdc
, "wglGetCurrentReadDCARB failed for wglMakeContextCurrent\n");
861 static void test_dc(HWND hwnd
, HDC hdc
)
866 /* Get another DC and make sure it has the same pixel format */
870 pf1
= GetPixelFormat(hdc
);
871 pf2
= GetPixelFormat(hdc2
);
872 ok(pf1
== pf2
, "Second DC does not have the same format (%d != %d)\n", pf1
, pf2
);
875 skip("Could not get a different DC for the window\n");
879 ReleaseDC(hwnd
, hdc2
);
884 /* Nvidia converts win32 error codes to (0xc007 << 16) | win32_error_code */
885 #define NVIDIA_HRESULT_FROM_WIN32(x) (HRESULT_FROM_WIN32(x) | 0x40000000)
886 static void test_opengl3(HDC hdc
)
888 /* Try to create a context compatible with OpenGL 1.x; 1.0-2.1 is allowed */
891 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 1, 0};
893 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
894 ok(gl3Ctx
!= 0, "pwglCreateContextAttribsARB for a 1.x context failed!\n");
895 wglDeleteContext(gl3Ctx
);
898 /* Try to pass an invalid HDC */
902 gl3Ctx
= pwglCreateContextAttribsARB((HDC
)0xdeadbeef, 0, 0);
903 ok(gl3Ctx
== 0, "pwglCreateContextAttribsARB using an invalid HDC passed\n");
904 error
= GetLastError();
905 todo_wine
ok(error
== ERROR_DC_NOT_FOUND
||
906 broken(error
== NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_DATA
)), /* Nvidia Vista + Win7 */
907 "Expected ERROR_DC_NOT_FOUND, got error=%x\n", error
);
908 wglDeleteContext(gl3Ctx
);
911 /* Try to pass an invalid shareList */
915 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, (HGLRC
)0xdeadbeef, 0);
916 ok(gl3Ctx
== 0, "pwglCreateContextAttribsARB using an invalid shareList passed\n");
917 error
= GetLastError();
918 /* The Nvidia implementation seems to return hresults instead of win32 error codes */
919 todo_wine
ok(error
== ERROR_INVALID_OPERATION
||
920 error
== NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_OPERATION
), "Expected ERROR_INVALID_OPERATION, got error=%x\n", error
);
921 wglDeleteContext(gl3Ctx
);
924 /* Try to create an OpenGL 3.0 context */
926 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
927 HGLRC gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
931 skip("Skipping the rest of the WGL_ARB_create_context test due to lack of OpenGL 3.0\n");
935 wglDeleteContext(gl3Ctx
);
938 /* 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 */
940 HGLRC glCtx
= wglCreateContext(hdc
);
942 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
943 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};
945 HGLRC gl3Ctx
= pwglCreateContextAttribsARB(hdc
, glCtx
, attribs
);
946 ok(gl3Ctx
!= NULL
, "Sharing of a display list between OpenGL 3.0 and OpenGL 1.x/2.x failed!\n");
948 wglDeleteContext(gl3Ctx
);
950 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, glCtx
, attribs_future
);
951 ok(gl3Ctx
!= NULL
, "Sharing of a display list between a forward compatible OpenGL 3.0 context and OpenGL 1.x/2.x failed!\n");
953 wglDeleteContext(gl3Ctx
);
956 wglDeleteContext(glCtx
);
959 /* Try to create an OpenGL 3.0 context and test windowless rendering */
962 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
965 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
966 ok(gl3Ctx
!= 0, "pwglCreateContextAttribsARB for a 3.0 context failed!\n");
968 /* OpenGL 3.0 allows offscreen rendering WITHOUT a drawable
969 * Neither AMD or Nvidia support it at this point. The WGL_ARB_create_context specs also say that
970 * it is hard because drivers use the HDC to enter the display driver and it sounds like they don't
971 * expect drivers to ever offer it.
973 res
= wglMakeCurrent(0, gl3Ctx
);
974 ok(res
== FALSE
, "Wow, OpenGL 3.0 windowless rendering passed while it was expected not to!\n");
976 wglMakeCurrent(0, 0);
979 wglDeleteContext(gl3Ctx
);
983 static void test_minimized(void)
985 PIXELFORMATDESCRIPTOR pf_desc
=
987 sizeof(PIXELFORMATDESCRIPTOR
),
989 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
991 24, /* 24-bit color depth */
992 0, 0, 0, 0, 0, 0, /* color bits */
993 0, /* alpha buffer */
995 0, /* accumulation buffer */
996 0, 0, 0, 0, /* accum bits */
998 0, /* stencil buffer */
999 0, /* auxiliary buffer */
1000 PFD_MAIN_PLANE
, /* main layer */
1002 0, 0, 0 /* layer masks */
1011 window
= CreateWindowA("static", "opengl32_test",
1012 WS_POPUP
| WS_MINIMIZE
, 0, 0, 640, 480, 0, 0, 0, 0);
1013 ok(!!window
, "Failed to create window, last error %#x.\n", GetLastError());
1016 ok(!!dc
, "Failed to get DC.\n");
1018 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1021 win_skip("Failed to find pixel format.\n");
1022 ReleaseDC(window
, dc
);
1023 DestroyWindow(window
);
1027 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1028 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1030 style
= GetWindowLongA(window
, GWL_STYLE
);
1031 ok(style
& WS_MINIMIZE
, "Window should be minimized, got style %#x.\n", style
);
1033 ctx
= wglCreateContext(dc
);
1034 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1036 ret
= wglMakeCurrent(dc
, ctx
);
1037 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1039 style
= GetWindowLongA(window
, GWL_STYLE
);
1040 ok(style
& WS_MINIMIZE
, "window should be minimized, got style %#x.\n", style
);
1042 ret
= wglMakeCurrent(NULL
, NULL
);
1043 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1045 ret
= wglDeleteContext(ctx
);
1046 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1048 ReleaseDC(window
, dc
);
1049 DestroyWindow(window
);
1052 static void test_window_dc(void)
1054 PIXELFORMATDESCRIPTOR pf_desc
=
1056 sizeof(PIXELFORMATDESCRIPTOR
),
1058 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1060 24, /* 24-bit color depth */
1061 0, 0, 0, 0, 0, 0, /* color bits */
1062 0, /* alpha buffer */
1064 0, /* accumulation buffer */
1065 0, 0, 0, 0, /* accum bits */
1067 0, /* stencil buffer */
1068 0, /* auxiliary buffer */
1069 PFD_MAIN_PLANE
, /* main layer */
1071 0, 0, 0 /* layer masks */
1080 window
= CreateWindowA("static", "opengl32_test",
1081 WS_OVERLAPPEDWINDOW
, 0, 0, 640, 480, 0, 0, 0, 0);
1082 ok(!!window
, "Failed to create window, last error %#x.\n", GetLastError());
1084 ShowWindow(window
, SW_SHOW
);
1086 dc
= GetWindowDC(window
);
1087 ok(!!dc
, "Failed to get DC.\n");
1089 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1092 win_skip("Failed to find pixel format.\n");
1093 ReleaseDC(window
, dc
);
1094 DestroyWindow(window
);
1098 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1099 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1101 ctx
= wglCreateContext(dc
);
1102 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1104 ret
= wglMakeCurrent(dc
, ctx
);
1105 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1107 GetClientRect(window
, &r
);
1108 glGetIntegerv(GL_VIEWPORT
, (GLint
*)&vp
);
1109 ok(EqualRect(&r
, &vp
), "Viewport not equal to client rect.\n");
1111 ret
= wglMakeCurrent(NULL
, NULL
);
1112 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1114 ret
= wglDeleteContext(ctx
);
1115 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1117 ReleaseDC(window
, dc
);
1118 DestroyWindow(window
);
1121 static void test_message_window(void)
1123 PIXELFORMATDESCRIPTOR pf_desc
=
1125 sizeof(PIXELFORMATDESCRIPTOR
),
1127 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1129 24, /* 24-bit color depth */
1130 0, 0, 0, 0, 0, 0, /* color bits */
1131 0, /* alpha buffer */
1133 0, /* accumulation buffer */
1134 0, 0, 0, 0, /* accum bits */
1136 0, /* stencil buffer */
1137 0, /* auxiliary buffer */
1138 PFD_MAIN_PLANE
, /* main layer */
1140 0, 0, 0 /* layer masks */
1150 window
= CreateWindowA("static", "opengl32_test",
1151 WS_OVERLAPPEDWINDOW
, 0, 0, 100, 100, HWND_MESSAGE
, 0, 0, 0);
1154 win_skip( "HWND_MESSAGE not supported\n" );
1158 ok(!!dc
, "Failed to get DC.\n");
1160 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1163 win_skip("Failed to find pixel format.\n");
1164 ReleaseDC(window
, dc
);
1165 DestroyWindow(window
);
1169 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1170 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1172 ctx
= wglCreateContext(dc
);
1173 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1175 ret
= wglMakeCurrent(dc
, ctx
);
1176 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1178 GetClientRect(window
, &r
);
1179 glGetIntegerv(GL_VIEWPORT
, (GLint
*)&vp
);
1180 ok(EqualRect(&r
, &vp
), "Viewport not equal to client rect.\n");
1182 glClear(GL_COLOR_BUFFER_BIT
);
1184 glerr
= glGetError();
1185 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1186 ret
= SwapBuffers(dc
);
1187 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1189 ret
= wglMakeCurrent(NULL
, NULL
);
1190 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1192 ret
= wglDeleteContext(ctx
);
1193 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1195 ReleaseDC(window
, dc
);
1196 DestroyWindow(window
);
1199 static void test_destroy(HDC oldhdc
)
1201 PIXELFORMATDESCRIPTOR pf_desc
=
1203 sizeof(PIXELFORMATDESCRIPTOR
),
1205 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1207 24, /* 24-bit color depth */
1208 0, 0, 0, 0, 0, 0, /* color bits */
1209 0, /* alpha buffer */
1211 0, /* accumulation buffer */
1212 0, 0, 0, 0, /* accum bits */
1214 0, /* stencil buffer */
1215 0, /* auxiliary buffer */
1216 PFD_MAIN_PLANE
, /* main layer */
1218 0, 0, 0 /* layer masks */
1227 HGLRC oldctx
= wglGetCurrentContext();
1229 ok(!!oldctx
, "Expected to find a valid current context.\n");
1231 window
= CreateWindowA("static", "opengl32_test",
1232 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1233 ok(!!window
, "Failed to create window, last error %#x.\n", GetLastError());
1236 ok(!!dc
, "Failed to get DC.\n");
1238 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1241 win_skip("Failed to find pixel format.\n");
1242 ReleaseDC(window
, dc
);
1243 DestroyWindow(window
);
1247 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1248 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1250 ctx
= wglCreateContext(dc
);
1251 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1253 ret
= wglMakeCurrent(dc
, ctx
);
1254 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1256 glClear(GL_COLOR_BUFFER_BIT
);
1258 glerr
= glGetError();
1259 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1260 ret
= SwapBuffers(dc
);
1261 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1263 ret
= DestroyWindow(window
);
1264 ok(ret
, "Failed to destroy window, last error %#x.\n", GetLastError());
1266 ok(wglGetCurrentContext() == ctx
, "Wrong current context.\n");
1268 SetLastError(0xdeadbeef);
1269 ret
= wglMakeCurrent(dc
, ctx
);
1270 err
= GetLastError();
1271 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1272 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1273 SetLastError(0xdeadbeef);
1274 ret
= SwapBuffers(dc
);
1275 err
= GetLastError();
1276 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1278 ok(wglGetCurrentContext() == ctx
, "Wrong current context.\n");
1280 glClear(GL_COLOR_BUFFER_BIT
);
1282 glerr
= glGetError();
1283 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1284 SetLastError(0xdeadbeef);
1285 ret
= SwapBuffers(dc
);
1286 err
= GetLastError();
1287 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1289 ret
= wglMakeCurrent(NULL
, NULL
);
1290 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1292 glClear(GL_COLOR_BUFFER_BIT
);
1294 glerr
= glGetError();
1295 ok(glerr
== GL_INVALID_OPERATION
, "Failed glClear, error %#x.\n", glerr
);
1296 SetLastError(0xdeadbeef);
1297 ret
= SwapBuffers(dc
);
1298 err
= GetLastError();
1299 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1301 SetLastError(0xdeadbeef);
1302 ret
= wglMakeCurrent(dc
, ctx
);
1303 err
= GetLastError();
1304 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1305 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1307 ok(wglGetCurrentContext() == NULL
, "Wrong current context.\n");
1309 ret
= wglMakeCurrent(oldhdc
, oldctx
);
1310 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1311 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1313 SetLastError(0xdeadbeef);
1314 ret
= wglMakeCurrent(dc
, ctx
);
1315 err
= GetLastError();
1316 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1317 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1319 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1321 ret
= wglDeleteContext(ctx
);
1322 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1324 ReleaseDC(window
, dc
);
1326 ret
= wglMakeCurrent(oldhdc
, oldctx
);
1327 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1330 static void test_destroy_read(HDC oldhdc
)
1332 PIXELFORMATDESCRIPTOR pf_desc
=
1334 sizeof(PIXELFORMATDESCRIPTOR
),
1336 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1338 24, /* 24-bit color depth */
1339 0, 0, 0, 0, 0, 0, /* color bits */
1340 0, /* alpha buffer */
1342 0, /* accumulation buffer */
1343 0, 0, 0, 0, /* accum bits */
1345 0, /* stencil buffer */
1346 0, /* auxiliary buffer */
1347 PFD_MAIN_PLANE
, /* main layer */
1349 0, 0, 0 /* layer masks */
1352 HWND draw_window
, read_window
;
1355 HDC read_dc
, draw_dc
;
1358 HGLRC oldctx
= wglGetCurrentContext();
1360 ok(!!oldctx
, "Expected to find a valid current context\n");
1362 draw_window
= CreateWindowA("static", "opengl32_test",
1363 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1364 ok(!!draw_window
, "Failed to create window, last error %#x.\n", GetLastError());
1366 draw_dc
= GetDC(draw_window
);
1367 ok(!!draw_dc
, "Failed to get DC.\n");
1369 pixel_format
= ChoosePixelFormat(draw_dc
, &pf_desc
);
1372 win_skip("Failed to find pixel format.\n");
1373 ReleaseDC(draw_window
, draw_dc
);
1374 DestroyWindow(draw_window
);
1378 ret
= SetPixelFormat(draw_dc
, pixel_format
, &pf_desc
);
1379 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1381 read_window
= CreateWindowA("static", "opengl32_test",
1382 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1383 ok(!!read_window
, "Failed to create window, last error %#x.\n", GetLastError());
1385 read_dc
= GetDC(read_window
);
1386 ok(!!draw_dc
, "Failed to get DC.\n");
1388 pixel_format
= ChoosePixelFormat(read_dc
, &pf_desc
);
1391 win_skip("Failed to find pixel format.\n");
1392 ReleaseDC(read_window
, read_dc
);
1393 DestroyWindow(read_window
);
1394 ReleaseDC(draw_window
, draw_dc
);
1395 DestroyWindow(draw_window
);
1399 ret
= SetPixelFormat(read_dc
, pixel_format
, &pf_desc
);
1400 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1402 ctx
= wglCreateContext(draw_dc
);
1403 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1405 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1406 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1408 glCopyPixels(0, 0, 640, 480, GL_COLOR
);
1410 glerr
= glGetError();
1411 ok(glerr
== GL_NO_ERROR
, "Failed glCopyPixel, error %#x.\n", glerr
);
1412 ret
= SwapBuffers(draw_dc
);
1413 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1415 ret
= DestroyWindow(read_window
);
1416 ok(ret
, "Failed to destroy window, last error %#x.\n", GetLastError());
1418 ok(wglGetCurrentContext() == ctx
, "Wrong current context.\n");
1420 if (0) /* Crashes on AMD on Windows */
1422 glCopyPixels(0, 0, 640, 480, GL_COLOR
);
1424 glerr
= glGetError();
1425 ok(glerr
== GL_NO_ERROR
, "Failed glCopyPixel, error %#x.\n", glerr
);
1428 glClear(GL_COLOR_BUFFER_BIT
);
1430 glerr
= glGetError();
1431 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1432 ret
= SwapBuffers(draw_dc
);
1433 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1435 ret
= wglMakeCurrent(NULL
, NULL
);
1436 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1438 if (0) /* This crashes with Nvidia drivers on Windows. */
1440 SetLastError(0xdeadbeef);
1441 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1442 err
= GetLastError();
1443 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1444 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1447 ret
= DestroyWindow(draw_window
);
1448 ok(ret
, "Failed to destroy window, last error %#x.\n", GetLastError());
1450 glClear(GL_COLOR_BUFFER_BIT
);
1452 glerr
= glGetError();
1453 ok(glerr
== GL_INVALID_OPERATION
, "Failed glClear, error %#x.\n", glerr
);
1454 SetLastError(0xdeadbeef);
1455 ret
= SwapBuffers(draw_dc
);
1456 err
= GetLastError();
1457 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1459 SetLastError(0xdeadbeef);
1460 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1461 err
= GetLastError();
1462 ok(!ret
&& (err
== ERROR_INVALID_HANDLE
|| err
== 0xc0070006),
1463 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1465 ok(wglGetCurrentContext() == NULL
, "Wrong current context.\n");
1467 wglMakeCurrent(NULL
, NULL
);
1469 wglMakeCurrent(oldhdc
, oldctx
);
1470 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1472 SetLastError(0xdeadbeef);
1473 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1474 err
= GetLastError();
1475 ok(!ret
&& (err
== ERROR_INVALID_HANDLE
|| err
== 0xc0070006),
1476 "Unexpected behavior when making context current, last error %#x.\n", err
);
1478 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1480 ret
= wglDeleteContext(ctx
);
1481 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1483 ReleaseDC(read_window
, read_dc
);
1484 ReleaseDC(draw_window
, draw_dc
);
1486 wglMakeCurrent(oldhdc
, oldctx
);
1489 static void test_swap_control(HDC oldhdc
)
1491 PIXELFORMATDESCRIPTOR pf_desc
=
1493 sizeof(PIXELFORMATDESCRIPTOR
),
1495 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1497 24, /* 24-bit color depth */
1498 0, 0, 0, 0, 0, 0, /* color bits */
1499 0, /* alpha buffer */
1501 0, /* accumulation buffer */
1502 0, 0, 0, 0, /* accum bits */
1504 0, /* stencil buffer */
1505 0, /* auxiliary buffer */
1506 PFD_MAIN_PLANE
, /* main layer */
1508 0, 0, 0 /* layer masks */
1511 HWND window1
, window2
;
1512 HGLRC ctx1
, ctx2
, oldctx
;
1517 oldctx
= wglGetCurrentContext();
1518 ok(!!oldctx
, "Expected to find a valid current context.\n");
1520 window1
= CreateWindowA("static", "opengl32_test",
1521 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1522 ok(!!window1
, "Failed to create window1, last error %#x.\n", GetLastError());
1524 dc1
= GetDC(window1
);
1525 ok(!!dc1
, "Failed to get DC.\n");
1527 pixel_format
= ChoosePixelFormat(dc1
, &pf_desc
);
1530 win_skip("Failed to find pixel format.\n");
1531 ReleaseDC(window1
, dc1
);
1532 DestroyWindow(window1
);
1536 ret
= SetPixelFormat(dc1
, pixel_format
, &pf_desc
);
1537 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1539 ctx1
= wglCreateContext(dc1
);
1540 ok(!!ctx1
, "Failed to create GL context, last error %#x.\n", GetLastError());
1542 ret
= wglMakeCurrent(dc1
, ctx1
);
1543 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1545 interval
= pwglGetSwapIntervalEXT();
1546 ok(interval
== 1, "Expected default swap interval 1, got %d\n", interval
);
1548 ret
= pwglSwapIntervalEXT(0);
1549 ok(ret
, "Failed to set swap interval to 0, last error %#x.\n", GetLastError());
1551 interval
= pwglGetSwapIntervalEXT();
1552 ok(interval
== 0, "Expected default swap interval 0, got %d\n", interval
);
1554 /* Check what interval we get on a second context on the same drawable.*/
1555 ctx2
= wglCreateContext(dc1
);
1556 ok(!!ctx2
, "Failed to create GL context, last error %#x.\n", GetLastError());
1558 ret
= wglMakeCurrent(dc1
, ctx2
);
1559 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1561 interval
= pwglGetSwapIntervalEXT();
1562 ok(interval
== 0, "Expected swap interval 0, got %d\n", interval
);
1564 /* A second window is created to see whether its swap interval was affected
1565 * by previous calls.
1567 window2
= CreateWindowA("static", "opengl32_test",
1568 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1569 ok(!!window2
, "Failed to create window2, last error %#x.\n", GetLastError());
1571 dc2
= GetDC(window2
);
1572 ok(!!dc2
, "Failed to get DC.\n");
1574 ret
= SetPixelFormat(dc2
, pixel_format
, &pf_desc
);
1575 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1577 ret
= wglMakeCurrent(dc2
, ctx1
);
1578 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1580 /* Since the second window lacks the swap interval, this proves that the interval
1581 * is not global or shared among contexts.
1583 interval
= pwglGetSwapIntervalEXT();
1584 ok(interval
== 1, "Expected swap interval 1, got %d\n", interval
);
1586 ret
= wglDeleteContext(ctx1
);
1587 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1588 ret
= wglDeleteContext(ctx2
);
1589 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1591 ReleaseDC(window1
, dc1
);
1592 DestroyWindow(window1
);
1593 ReleaseDC(window2
, dc2
);
1594 DestroyWindow(window2
);
1596 wglMakeCurrent(oldhdc
, oldctx
);
1602 PIXELFORMATDESCRIPTOR pfd
= {
1603 sizeof(PIXELFORMATDESCRIPTOR
),
1605 PFD_DRAW_TO_WINDOW
|
1606 PFD_SUPPORT_OPENGL
|
1609 24, /* 24-bit color depth */
1610 0, 0, 0, 0, 0, 0, /* color bits */
1611 0, /* alpha buffer */
1613 0, /* accumulation buffer */
1614 0, 0, 0, 0, /* accum bits */
1616 0, /* stencil buffer */
1617 0, /* auxiliary buffer */
1618 PFD_MAIN_PLANE
, /* main layer */
1620 0, 0, 0 /* layer masks */
1623 hwnd
= CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW
,
1624 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
1625 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
1629 int iPixelFormat
, res
;
1632 ShowWindow(hwnd
, SW_SHOW
);
1636 iPixelFormat
= ChoosePixelFormat(hdc
, &pfd
);
1637 if(iPixelFormat
== 0)
1639 /* This should never happen as ChoosePixelFormat always returns a closest match, but currently this fails in Wine if we don't have glX */
1640 win_skip("Unable to find pixel format.\n");
1644 /* We shouldn't be able to create a context from a hdc which doesn't have a pixel format set */
1645 hglrc
= wglCreateContext(hdc
);
1646 ok(hglrc
== NULL
, "wglCreateContext should fail when no pixel format has been set, but it passed\n");
1647 error
= GetLastError();
1648 ok(error
== ERROR_INVALID_PIXEL_FORMAT
, "expected ERROR_INVALID_PIXEL_FORMAT for wglCreateContext without a pixelformat set, but received %#x\n", error
);
1650 res
= SetPixelFormat(hdc
, iPixelFormat
, &pfd
);
1651 ok(res
, "SetPixelformat failed: %x\n", GetLastError());
1653 test_bitmap_rendering( TRUE
);
1654 test_bitmap_rendering( FALSE
);
1657 test_message_window();
1660 hglrc
= wglCreateContext(hdc
);
1661 res
= wglMakeCurrent(hdc
, hglrc
);
1662 ok(res
, "wglMakeCurrent failed!\n");
1665 trace("OpenGL renderer: %s\n", glGetString(GL_RENDERER
));
1666 trace("OpenGL driver version: %s\n", glGetString(GL_VERSION
));
1667 trace("OpenGL vendor: %s\n", glGetString(GL_VENDOR
));
1671 skip("Skipping OpenGL tests without a current context\n");
1675 /* Initialisation of WGL functions depends on an implicit WGL context. For this reason we can't load them before making
1676 * any WGL call :( On Wine this would work but not on real Windows because there can be different implementations (software, ICD, MCD).
1679 test_getprocaddress(hdc
);
1680 test_deletecontext(hwnd
, hdc
);
1681 test_makecurrent(hdc
);
1683 /* The lack of wglGetExtensionsStringARB in general means broken software rendering or the lack of decent OpenGL support, skip tests in such cases */
1684 if (!pwglGetExtensionsStringARB
)
1686 win_skip("wglGetExtensionsStringARB is not available\n");
1690 test_setpixelformat(hdc
);
1692 test_sharelists(hdc
);
1693 test_colorbits(hdc
);
1695 test_acceleration(hdc
);
1697 wgl_extensions
= pwglGetExtensionsStringARB(hdc
);
1698 if(wgl_extensions
== NULL
) skip("Skipping opengl32 tests because this OpenGL implementation doesn't support WGL extensions!\n");
1700 if(strstr(wgl_extensions
, "WGL_ARB_create_context"))
1703 if(strstr(wgl_extensions
, "WGL_ARB_make_current_read"))
1705 test_make_current_read(hdc
);
1706 test_destroy_read(hdc
);
1709 skip("WGL_ARB_make_current_read not supported, skipping test\n");
1711 if(strstr(wgl_extensions
, "WGL_ARB_pbuffer"))
1714 skip("WGL_ARB_pbuffer not supported, skipping pbuffer test\n");
1716 if(strstr(wgl_extensions
, "WGL_EXT_swap_control"))
1717 test_swap_control(hdc
);
1719 skip("WGL_EXT_swap_control not supported, skipping test\n");
1722 ReleaseDC(hwnd
, hdc
);
1723 DestroyWindow(hwnd
);