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 static const char* wgl_extensions
= NULL
;
91 static void init_functions(void)
93 #define GET_PROC(func) \
94 p ## func = (void*)wglGetProcAddress(#func); \
96 trace("wglGetProcAddress(%s) failed\n", #func);
98 /* WGL_ARB_create_context */
99 GET_PROC(wglCreateContextAttribsARB
);
101 /* WGL_ARB_extensions_string */
102 GET_PROC(wglGetExtensionsStringARB
)
104 /* WGL_ARB_make_current_read */
105 GET_PROC(wglMakeContextCurrentARB
);
106 GET_PROC(wglGetCurrentReadDCARB
);
108 /* WGL_ARB_pixel_format */
109 GET_PROC(wglChoosePixelFormatARB
)
110 GET_PROC(wglGetPixelFormatAttribivARB
)
112 /* WGL_ARB_pbuffer */
113 GET_PROC(wglCreatePbufferARB
)
114 GET_PROC(wglGetPbufferDCARB
)
115 GET_PROC(wglReleasePbufferDCARB
)
120 static BOOL
gl_extension_supported(const char *extensions
, const char *extension_string
)
122 size_t ext_str_len
= strlen(extension_string
);
129 while (isspace(*extensions
))
132 while (!isspace(*extensions
) && *extensions
)
135 len
= extensions
- start
;
139 if (len
== ext_str_len
&& !memcmp(start
, extension_string
, ext_str_len
))
147 static void test_pbuffers(HDC hdc
)
149 const int iAttribList
[] = { WGL_DRAW_TO_PBUFFER_ARB
, 1, /* Request pbuffer support */
151 int iFormats
[MAX_FORMATS
];
152 unsigned int nOnscreenFormats
;
153 unsigned int nFormats
;
155 int iPixelFormat
= 0;
157 nOnscreenFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
159 /* When you want to render to a pbuffer you need to call wglGetPbufferDCARB which
160 * returns a 'magic' HDC which you can then pass to wglMakeCurrent to switch rendering
161 * to the pbuffer. Below some tests are performed on what happens if you use standard WGL calls
162 * on this 'magic' HDC for both a pixelformat that support onscreen and offscreen rendering
163 * and a pixelformat that's only available for offscreen rendering (this means that only
164 * wglChoosePixelFormatARB and friends know about the format.
166 * The first thing we need are pixelformats with pbuffer capabilities.
168 res
= pwglChoosePixelFormatARB(hdc
, iAttribList
, NULL
, MAX_FORMATS
, iFormats
, &nFormats
);
171 skip("No pbuffer compatible formats found while WGL_ARB_pbuffer is supported\n");
174 trace("nOnscreenFormats: %d\n", nOnscreenFormats
);
175 trace("Total number of pbuffer capable pixelformats: %d\n", nFormats
);
177 /* Try to select an onscreen pixelformat out of the list */
178 for(i
=0; i
< nFormats
; i
++)
180 /* Check if the format is onscreen, if it is choose it */
181 if(iFormats
[i
] <= nOnscreenFormats
)
183 iPixelFormat
= iFormats
[i
];
184 trace("Selected iPixelFormat=%d\n", iPixelFormat
);
189 /* A video driver supports a large number of onscreen and offscreen pixelformats.
190 * The traditional WGL calls only see a subset of the whole pixelformat list. First
191 * of all they only see the onscreen formats (the offscreen formats are at the end of the
192 * pixelformat list) and second extended pixelformat capabilities are hidden from the
193 * standard WGL calls. Only functions that depend on WGL_ARB_pixel_format can see them.
195 * Below we check if the pixelformat is also supported onscreen.
197 if(iPixelFormat
!= 0)
201 HPBUFFERARB pbuffer
= pwglCreatePbufferARB(hdc
, iPixelFormat
, 640 /* width */, 480 /* height */, &attrib
);
203 skip("Pbuffer creation failed!\n");
205 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
206 pbuffer_hdc
= pwglGetPbufferDCARB(pbuffer
);
207 res
= GetPixelFormat(pbuffer_hdc
);
208 ok(res
== iPixelFormat
, "Unexpected iPixelFormat=%d returned by GetPixelFormat for format %d\n", res
, iPixelFormat
);
209 trace("iPixelFormat returned by GetPixelFormat: %d\n", res
);
210 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat
);
212 pwglReleasePbufferDCARB(pbuffer
, pbuffer_hdc
);
214 else skip("Pbuffer test for onscreen pixelformat skipped as no onscreen format with pbuffer capabilities have been found\n");
216 /* Search for a real offscreen format */
217 for(i
=0, iPixelFormat
=0; i
<nFormats
; i
++)
219 if(iFormats
[i
] > nOnscreenFormats
)
221 iPixelFormat
= iFormats
[i
];
222 trace("Selected iPixelFormat: %d\n", iPixelFormat
);
227 if(iPixelFormat
!= 0)
230 HPBUFFERARB pbuffer
= pwglCreatePbufferARB(hdc
, iPixelFormat
, 640 /* width */, 480 /* height */, NULL
);
232 skip("Pbuffer creation failed!\n");
234 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
235 pbuffer_hdc
= pwglGetPbufferDCARB(pbuffer
);
236 res
= GetPixelFormat(pbuffer_hdc
);
238 ok(res
== 1, "Unexpected iPixelFormat=%d (1 expected) returned by GetPixelFormat for offscreen format %d\n", res
, iPixelFormat
);
239 trace("iPixelFormat returned by GetPixelFormat: %d\n", res
);
240 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat
);
241 pwglReleasePbufferDCARB(pbuffer
, hdc
);
243 else skip("Pbuffer test for offscreen pixelformat skipped as no offscreen-only format with pbuffer capabilities has been found\n");
246 static void test_setpixelformat(HDC winhdc
)
253 PIXELFORMATDESCRIPTOR pfd
= {
254 sizeof(PIXELFORMATDESCRIPTOR
),
260 24, /* 24-bit color depth */
261 0, 0, 0, 0, 0, 0, /* color bits */
262 0, /* alpha buffer */
264 0, /* accumulation buffer */
265 0, 0, 0, 0, /* accum bits */
267 0, /* stencil buffer */
268 0, /* auxiliary buffer */
269 PFD_MAIN_PLANE
, /* main layer */
271 0, 0, 0 /* layer masks */
275 ok(hdc
!= 0, "GetDC(0) failed!\n");
277 /* This should pass even on the main device context */
278 pf
= ChoosePixelFormat(hdc
, &pfd
);
279 ok(pf
!= 0, "ChoosePixelFormat failed on main device context\n");
281 /* SetPixelFormat on the main device context 'X root window' should fail,
282 * but some broken drivers allow it
284 res
= SetPixelFormat(hdc
, pf
, &pfd
);
285 trace("SetPixelFormat on main device context %s\n", res
? "succeeded" : "failed");
287 /* Setting the same format that was set on the HDC is allowed; other
289 nCfgs
= DescribePixelFormat(winhdc
, 0, 0, NULL
);
290 pf
= GetPixelFormat(winhdc
);
291 for(i
= 1;i
<= nCfgs
;i
++)
293 int res
= SetPixelFormat(winhdc
, i
, NULL
);
294 if(i
== pf
) ok(res
, "Failed to set the same pixel format\n");
295 else ok(!res
, "Unexpectedly set an alternate pixel format\n");
298 hwnd
= CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW
,
299 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
300 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
303 HDC hdc
= GetDC( hwnd
);
304 pf
= ChoosePixelFormat( hdc
, &pfd
);
305 ok( pf
!= 0, "ChoosePixelFormat failed\n" );
306 res
= SetPixelFormat( hdc
, pf
, &pfd
);
307 ok( res
!= 0, "SetPixelFormat failed\n" );
308 i
= GetPixelFormat( hdc
);
309 ok( i
== pf
, "GetPixelFormat returned wrong format %d/%d\n", i
, pf
);
310 ReleaseDC( hwnd
, hdc
);
311 hdc
= GetWindowDC( hwnd
);
312 i
= GetPixelFormat( hdc
);
313 ok( i
== pf
, "GetPixelFormat returned wrong format %d/%d\n", i
, pf
);
314 ReleaseDC( hwnd
, hdc
);
315 DestroyWindow( hwnd
);
318 hwnd
= CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW
,
319 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
320 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
323 HDC hdc
= GetWindowDC( hwnd
);
324 pf
= ChoosePixelFormat( hdc
, &pfd
);
325 ok( pf
!= 0, "ChoosePixelFormat failed\n" );
326 res
= SetPixelFormat( hdc
, pf
, &pfd
);
327 ok( res
!= 0, "SetPixelFormat failed\n" );
328 i
= GetPixelFormat( hdc
);
329 ok( i
== pf
, "GetPixelFormat returned wrong format %d/%d\n", i
, pf
);
330 ReleaseDC( hwnd
, hdc
);
331 DestroyWindow( hwnd
);
335 static void test_sharelists(HDC winhdc
)
337 HGLRC hglrc1
, hglrc2
, hglrc3
;
340 hglrc1
= wglCreateContext(winhdc
);
341 res
= wglShareLists(0, 0);
342 ok(res
== FALSE
, "Sharing display lists for no contexts passed!\n");
344 /* Test 1: Create a context and just share lists without doing anything special */
345 hglrc2
= wglCreateContext(winhdc
);
348 res
= wglShareLists(hglrc1
, hglrc2
);
349 ok(res
, "Sharing of display lists failed\n");
350 wglDeleteContext(hglrc2
);
353 /* Test 2: Share display lists with a 'destination' context which has been made current */
354 hglrc2
= wglCreateContext(winhdc
);
357 res
= wglMakeCurrent(winhdc
, hglrc2
);
358 ok(res
, "Make current failed\n");
359 res
= wglShareLists(hglrc1
, hglrc2
);
360 todo_wine
ok(res
, "Sharing display lists with a destination context which has been made current failed\n");
361 wglMakeCurrent(0, 0);
362 wglDeleteContext(hglrc2
);
365 /* Test 3: Share display lists with a context which already shares display lists with another context.
366 * According to MSDN the second parameter cannot share any display lists but some buggy drivers might allow it */
367 hglrc3
= wglCreateContext(winhdc
);
370 res
= wglShareLists(hglrc3
, hglrc1
);
371 ok(res
== FALSE
, "Sharing of display lists passed for a context which already shared lists before\n");
372 wglDeleteContext(hglrc3
);
375 /* Test 4: Share display lists with a 'source' context which has been made current */
376 hglrc2
= wglCreateContext(winhdc
);
379 res
= wglMakeCurrent(winhdc
, hglrc1
);
380 ok(res
, "Make current failed\n");
381 res
= wglShareLists(hglrc1
, hglrc2
);
382 ok(res
, "Sharing display lists with a source context which has been made current failed\n");
383 wglMakeCurrent(0, 0);
384 wglDeleteContext(hglrc2
);
388 static void test_makecurrent(HDC winhdc
)
393 hglrc
= wglCreateContext(winhdc
);
394 ok( hglrc
!= 0, "wglCreateContext failed\n" );
396 ret
= wglMakeCurrent( winhdc
, hglrc
);
397 ok( ret
, "wglMakeCurrent failed\n" );
399 ok( wglGetCurrentContext() == hglrc
, "wrong context\n" );
401 /* set the same context again */
402 ret
= wglMakeCurrent( winhdc
, hglrc
);
403 ok( ret
, "wglMakeCurrent failed\n" );
405 /* check wglMakeCurrent(x, y) after another call to wglMakeCurrent(x, y) */
406 ret
= wglMakeCurrent( winhdc
, NULL
);
407 ok( ret
, "wglMakeCurrent failed\n" );
409 ret
= wglMakeCurrent( winhdc
, NULL
);
410 ok( ret
, "wglMakeCurrent failed\n" );
412 SetLastError( 0xdeadbeef );
413 ret
= wglMakeCurrent( NULL
, NULL
);
414 ok( !ret
|| broken(ret
) /* nt4 */, "wglMakeCurrent succeeded\n" );
415 if (!ret
) ok( GetLastError() == ERROR_INVALID_HANDLE
,
416 "Expected ERROR_INVALID_HANDLE, got error=%x\n", GetLastError() );
418 ret
= wglMakeCurrent( winhdc
, NULL
);
419 ok( ret
, "wglMakeCurrent failed\n" );
421 ret
= wglMakeCurrent( winhdc
, hglrc
);
422 ok( ret
, "wglMakeCurrent failed\n" );
424 ret
= wglMakeCurrent( NULL
, NULL
);
425 ok( ret
, "wglMakeCurrent failed\n" );
427 ok( wglGetCurrentContext() == NULL
, "wrong context\n" );
429 SetLastError( 0xdeadbeef );
430 ret
= wglMakeCurrent( NULL
, NULL
);
431 ok( !ret
|| broken(ret
) /* nt4 */, "wglMakeCurrent succeeded\n" );
432 if (!ret
) ok( GetLastError() == ERROR_INVALID_HANDLE
,
433 "Expected ERROR_INVALID_HANDLE, got error=%x\n", GetLastError() );
435 ret
= wglMakeCurrent( winhdc
, hglrc
);
436 ok( ret
, "wglMakeCurrent failed\n" );
439 static void test_colorbits(HDC hdc
)
441 const int iAttribList
[] = { WGL_COLOR_BITS_ARB
, WGL_RED_BITS_ARB
, WGL_GREEN_BITS_ARB
,
442 WGL_BLUE_BITS_ARB
, WGL_ALPHA_BITS_ARB
};
443 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
444 const int iAttribs
[] = { WGL_ALPHA_BITS_ARB
, 1, 0 };
445 unsigned int nFormats
;
447 int iPixelFormat
= 0;
449 if (!pwglChoosePixelFormatARB
)
451 win_skip("wglChoosePixelFormatARB is not available\n");
455 /* We need a pixel format with at least one bit of alpha */
456 res
= pwglChoosePixelFormatARB(hdc
, iAttribs
, NULL
, 1, &iPixelFormat
, &nFormats
);
457 if(res
== FALSE
|| nFormats
== 0)
459 skip("No suitable pixel formats found\n");
463 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
464 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
, iAttribRet
);
467 skip("wglGetPixelFormatAttribivARB failed\n");
470 iAttribRet
[1] += iAttribRet
[2]+iAttribRet
[3]+iAttribRet
[4];
471 ok(iAttribRet
[0] == iAttribRet
[1], "WGL_COLOR_BITS_ARB (%d) does not equal R+G+B+A (%d)!\n",
472 iAttribRet
[0], iAttribRet
[1]);
475 static void test_gdi_dbuf(HDC hdc
)
477 const int iAttribList
[] = { WGL_SUPPORT_GDI_ARB
, WGL_DOUBLE_BUFFER_ARB
};
478 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
479 unsigned int nFormats
;
483 if (!pwglGetPixelFormatAttribivARB
)
485 win_skip("wglGetPixelFormatAttribivARB is not available\n");
489 nFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
490 for(iPixelFormat
= 1;iPixelFormat
<= nFormats
;iPixelFormat
++)
492 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
493 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
,
495 ok(res
!=FALSE
, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat
);
499 ok(!(iAttribRet
[0] && iAttribRet
[1]), "GDI support and double buffering on pixel format %d\n", iPixelFormat
);
503 static void test_acceleration(HDC hdc
)
505 const int iAttribList
[] = { WGL_ACCELERATION_ARB
};
506 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
507 unsigned int nFormats
;
510 PIXELFORMATDESCRIPTOR pfd
;
512 if (!pwglGetPixelFormatAttribivARB
)
514 win_skip("wglGetPixelFormatAttribivARB is not available\n");
518 nFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
519 for(iPixelFormat
= 1; iPixelFormat
<= nFormats
; iPixelFormat
++)
521 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
522 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
,
524 ok(res
!=FALSE
, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat
);
528 memset(&pfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
529 DescribePixelFormat(hdc
, iPixelFormat
, sizeof(PIXELFORMATDESCRIPTOR
), &pfd
);
531 switch(iAttribRet
[0])
533 case WGL_NO_ACCELERATION_ARB
:
534 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
);
536 case WGL_GENERIC_ACCELERATION_ARB
:
537 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
);
539 case WGL_FULL_ACCELERATION_ARB
:
540 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
);
546 static void test_bitmap_rendering( BOOL use_dib
)
548 PIXELFORMATDESCRIPTOR pfd
;
549 int i
, ret
, bpp
, iPixelFormat
=0;
550 unsigned int nFormats
;
553 HBITMAP bmpDst
, oldDst
, bmp2
;
554 HDC hdcDst
, hdcScreen
;
555 UINT
*dstBuffer
= NULL
;
557 hdcScreen
= CreateCompatibleDC(0);
558 hdcDst
= CreateCompatibleDC(0);
563 memset(&biDst
, 0, sizeof(BITMAPINFO
));
564 biDst
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
565 biDst
.bmiHeader
.biWidth
= 4;
566 biDst
.bmiHeader
.biHeight
= -4;
567 biDst
.bmiHeader
.biPlanes
= 1;
568 biDst
.bmiHeader
.biBitCount
= 32;
569 biDst
.bmiHeader
.biCompression
= BI_RGB
;
571 bmpDst
= CreateDIBSection(0, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
, NULL
, 0);
573 biDst
.bmiHeader
.biWidth
= 12;
574 biDst
.bmiHeader
.biHeight
= -12;
575 biDst
.bmiHeader
.biBitCount
= 16;
576 bmp2
= CreateDIBSection(0, &biDst
, DIB_RGB_COLORS
, NULL
, NULL
, 0);
580 bpp
= GetDeviceCaps( hdcScreen
, BITSPIXEL
);
581 bmpDst
= CreateBitmap( 4, 4, 1, bpp
, NULL
);
582 bmp2
= CreateBitmap( 12, 12, 1, bpp
, NULL
);
585 oldDst
= SelectObject(hdcDst
, bmpDst
);
587 trace( "testing on %s\n", use_dib
? "DIB" : "DDB" );
589 /* Pick a pixel format by hand because ChoosePixelFormat is unreliable */
590 nFormats
= DescribePixelFormat(hdcDst
, 0, 0, NULL
);
591 for(i
=1; i
<=nFormats
; i
++)
593 memset(&pfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
594 DescribePixelFormat(hdcDst
, i
, sizeof(PIXELFORMATDESCRIPTOR
), &pfd
);
596 if((pfd
.dwFlags
& PFD_DRAW_TO_BITMAP
) &&
597 (pfd
.dwFlags
& PFD_SUPPORT_OPENGL
) &&
598 (pfd
.cColorBits
== bpp
) &&
599 (pfd
.cAlphaBits
== 8) )
608 skip("Unable to find a suitable pixel format\n");
612 ret
= SetPixelFormat(hdcDst
, iPixelFormat
, &pfd
);
613 ok( ret
, "SetPixelFormat failed\n" );
614 ret
= GetPixelFormat( hdcDst
);
615 ok( ret
== iPixelFormat
, "GetPixelFormat returned %d/%d\n", ret
, iPixelFormat
);
616 ret
= SetPixelFormat(hdcDst
, iPixelFormat
+ 1, &pfd
);
617 ok( !ret
, "SetPixelFormat succeeded\n" );
618 hglrc
= wglCreateContext(hdcDst
);
619 ok(hglrc
!= NULL
, "Unable to create a context\n");
624 wglMakeCurrent(hdcDst
, hglrc
);
625 hglrc2
= wglCreateContext(hdcDst
);
626 ok(hglrc2
!= NULL
, "Unable to create a context\n");
628 /* Note this is RGBA but we read ARGB back */
629 glClearColor((float)0x22/0xff, (float)0x33/0xff, (float)0x44/0xff, (float)0x11/0xff);
630 glClear(GL_COLOR_BUFFER_BIT
);
631 glGetIntegerv( GL_VIEWPORT
, viewport
);
634 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 4 && viewport
[3] == 4,
635 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
636 /* Note apparently the alpha channel is not supported by the software renderer (bitmap only works using software) */
638 for (i
= 0; i
< 16; i
++)
639 ok(dstBuffer
[i
] == 0x223344 || dstBuffer
[i
] == 0x11223344, "Received color=%x at %u\n",
642 SelectObject(hdcDst
, bmp2
);
643 ret
= GetPixelFormat( hdcDst
);
644 ok( ret
== iPixelFormat
, "GetPixelFormat returned %d/%d\n", ret
, iPixelFormat
);
645 ret
= SetPixelFormat(hdcDst
, iPixelFormat
+ 1, &pfd
);
646 ok( !ret
, "SetPixelFormat succeeded\n" );
648 /* context still uses the old pixel format and viewport */
649 glClearColor((float)0x44/0xff, (float)0x33/0xff, (float)0x22/0xff, (float)0x11/0xff);
650 glClear(GL_COLOR_BUFFER_BIT
);
652 glGetIntegerv( GL_VIEWPORT
, viewport
);
653 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 4 && viewport
[3] == 4,
654 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
656 wglMakeCurrent(NULL
, NULL
);
657 wglMakeCurrent(hdcDst
, hglrc
);
658 glClearColor((float)0x44/0xff, (float)0x55/0xff, (float)0x66/0xff, (float)0x11/0xff);
659 glClear(GL_COLOR_BUFFER_BIT
);
661 glGetIntegerv( GL_VIEWPORT
, viewport
);
662 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 4 && viewport
[3] == 4,
663 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
665 wglMakeCurrent(hdcDst
, hglrc2
);
666 glGetIntegerv( GL_VIEWPORT
, viewport
);
667 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 12 && viewport
[3] == 12,
668 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
670 wglMakeCurrent(hdcDst
, hglrc
);
671 glGetIntegerv( GL_VIEWPORT
, viewport
);
672 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 4 && viewport
[3] == 4,
673 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
675 SelectObject(hdcDst
, bmpDst
);
676 ret
= GetPixelFormat( hdcDst
);
677 ok( ret
== iPixelFormat
, "GetPixelFormat returned %d/%d\n", ret
, iPixelFormat
);
678 ret
= SetPixelFormat(hdcDst
, iPixelFormat
+ 1, &pfd
);
679 ok( !ret
, "SetPixelFormat succeeded\n" );
680 wglMakeCurrent(hdcDst
, hglrc2
);
681 glGetIntegerv( GL_VIEWPORT
, viewport
);
682 ok( viewport
[0] == 0 && viewport
[1] == 0 && viewport
[2] == 12 && viewport
[3] == 12,
683 "wrong viewport %d,%d,%d,%d\n", viewport
[0], viewport
[1], viewport
[2], viewport
[3] );
687 SelectObject(hdcDst
, oldDst
);
689 DeleteObject(bmpDst
);
694 struct wgl_thread_param
696 HANDLE test_finished
;
700 BOOL make_current_error
;
705 static DWORD WINAPI
wgl_thread(void *param
)
707 struct wgl_thread_param
*p
= param
;
708 HDC hdc
= GetDC( p
->hwnd
);
710 SetLastError(0xdeadbeef);
711 p
->make_current
= wglMakeCurrent(hdc
, p
->hglrc
);
712 p
->make_current_error
= GetLastError();
713 p
->deleted
= wglDeleteContext(p
->hglrc
);
714 p
->deleted_error
= GetLastError();
715 ReleaseDC( p
->hwnd
, hdc
);
716 SetEvent(p
->test_finished
);
720 static void test_deletecontext(HWND hwnd
, HDC hdc
)
722 struct wgl_thread_param thread_params
;
723 HGLRC hglrc
= wglCreateContext(hdc
);
724 HANDLE thread_handle
;
727 SetLastError(0xdeadbeef);
728 res
= wglDeleteContext(NULL
);
729 ok(res
== FALSE
, "wglDeleteContext succeeded\n");
730 ok(GetLastError() == ERROR_INVALID_HANDLE
, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
734 skip("wglCreateContext failed!\n");
738 res
= wglMakeCurrent(hdc
, hglrc
);
741 skip("wglMakeCurrent failed!\n");
745 /* WGL doesn't allow you to delete a context from a different thread than the one in which it is current.
746 * This differs from GLX which does allow it but it delays actual deletion until the context becomes not current.
748 thread_params
.hglrc
= hglrc
;
749 thread_params
.hwnd
= hwnd
;
750 thread_params
.test_finished
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
751 thread_handle
= CreateThread(NULL
, 0, wgl_thread
, &thread_params
, 0, &tid
);
752 ok(!!thread_handle
, "Failed to create thread, last error %#x.\n", GetLastError());
755 WaitForSingleObject(thread_handle
, INFINITE
);
756 ok(!thread_params
.make_current
, "Attempt to make WGL context from another thread passed\n");
757 ok(thread_params
.make_current_error
== ERROR_BUSY
, "Expected last error to be ERROR_BUSY, got %u\n", thread_params
.make_current_error
);
758 ok(!thread_params
.deleted
, "Attempt to delete WGL context from another thread passed\n");
759 ok(thread_params
.deleted_error
== ERROR_BUSY
, "Expected last error to be ERROR_BUSY, got %u\n", thread_params
.deleted_error
);
761 CloseHandle(thread_params
.test_finished
);
763 res
= wglDeleteContext(hglrc
);
764 ok(res
== TRUE
, "wglDeleteContext failed\n");
766 /* Attempting to delete the same context twice should fail. */
767 SetLastError(0xdeadbeef);
768 res
= wglDeleteContext(hglrc
);
769 ok(res
== FALSE
, "wglDeleteContext succeeded\n");
770 ok(GetLastError() == ERROR_INVALID_HANDLE
, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
772 /* WGL makes a context not current when deleting it. This differs from GLX behavior where
773 * deletion takes place when the thread becomes not current. */
774 hglrc
= wglGetCurrentContext();
775 ok(hglrc
== NULL
, "A WGL context is active while none was expected\n");
779 static void test_getprocaddress(HDC hdc
)
781 const char *extensions
= (const char*)glGetString(GL_EXTENSIONS
);
783 HGLRC ctx
= wglGetCurrentContext();
787 skip("skipping wglGetProcAddress tests because no GL extensions supported\n");
791 /* Core GL 1.0/1.1 functions should not be loadable through wglGetProcAddress.
792 * Try to load the function with and without a context.
794 func
= wglGetProcAddress("glEnable");
795 ok(func
== NULL
, "Lookup of function glEnable with a context passed, expected a failure\n");
796 wglMakeCurrent(hdc
, NULL
);
797 func
= wglGetProcAddress("glEnable");
798 ok(func
== NULL
, "Lookup of function glEnable without a context passed, expected a failure\n");
799 wglMakeCurrent(hdc
, ctx
);
801 /* The goal of the test will be to test behavior of wglGetProcAddress when
802 * no WGL context is active. Before the test we pick an extension (GL_ARB_multitexture)
803 * which any GL >=1.2.1 implementation supports. Unfortunately the GDI renderer doesn't
804 * support it. There aren't any extensions we can use for this test which are supported by
805 * both GDI and real drivers.
806 * Note GDI only has GL_EXT_bgra, GL_EXT_paletted_texture and GL_WIN_swap_hint.
808 if (!gl_extension_supported(extensions
, "GL_ARB_multitexture"))
810 skip("skipping test because lack of GL_ARB_multitexture support\n");
814 func
= wglGetProcAddress("glActiveTextureARB");
815 ok(func
!= NULL
, "Unable to lookup glActiveTextureARB, last error %#x\n", GetLastError());
817 /* Temporarily disable the context, so we can see that we can't retrieve functions now. */
818 wglMakeCurrent(hdc
, NULL
);
819 func
= wglGetProcAddress("glActiveTextureARB");
820 ok(func
== NULL
, "Function lookup without a context passed, expected a failure; last error %#x\n", GetLastError());
821 wglMakeCurrent(hdc
, ctx
);
824 static void test_make_current_read(HDC hdc
)
828 HGLRC hglrc
= wglCreateContext(hdc
);
832 skip("wglCreateContext failed!\n");
836 res
= wglMakeCurrent(hdc
, hglrc
);
839 skip("wglMakeCurrent failed!\n");
843 /* Test what wglGetCurrentReadDCARB does for wglMakeCurrent as the spec doesn't mention it */
844 hread
= pwglGetCurrentReadDCARB();
845 trace("hread %p, hdc %p\n", hread
, hdc
);
846 ok(hread
== hdc
, "wglGetCurrentReadDCARB failed for standard wglMakeCurrent\n");
848 pwglMakeContextCurrentARB(hdc
, hdc
, hglrc
);
849 hread
= pwglGetCurrentReadDCARB();
850 ok(hread
== hdc
, "wglGetCurrentReadDCARB failed for wglMakeContextCurrent\n");
853 static void test_dc(HWND hwnd
, HDC hdc
)
858 /* Get another DC and make sure it has the same pixel format */
862 pf1
= GetPixelFormat(hdc
);
863 pf2
= GetPixelFormat(hdc2
);
864 ok(pf1
== pf2
, "Second DC does not have the same format (%d != %d)\n", pf1
, pf2
);
867 skip("Could not get a different DC for the window\n");
871 ReleaseDC(hwnd
, hdc2
);
876 /* Nvidia converts win32 error codes to (0xc007 << 16) | win32_error_code */
877 #define NVIDIA_HRESULT_FROM_WIN32(x) (HRESULT_FROM_WIN32(x) | 0x40000000)
878 static void test_opengl3(HDC hdc
)
880 /* Try to create a context compatible with OpenGL 1.x; 1.0-2.1 is allowed */
883 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 1, 0};
885 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
886 ok(gl3Ctx
!= 0, "pwglCreateContextAttribsARB for a 1.x context failed!\n");
887 wglDeleteContext(gl3Ctx
);
890 /* Try to pass an invalid HDC */
894 gl3Ctx
= pwglCreateContextAttribsARB((HDC
)0xdeadbeef, 0, 0);
895 ok(gl3Ctx
== 0, "pwglCreateContextAttribsARB using an invalid HDC passed\n");
896 error
= GetLastError();
897 todo_wine
ok(error
== ERROR_DC_NOT_FOUND
||
898 broken(error
== NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_DATA
)), /* Nvidia Vista + Win7 */
899 "Expected ERROR_DC_NOT_FOUND, got error=%x\n", error
);
900 wglDeleteContext(gl3Ctx
);
903 /* Try to pass an invalid shareList */
907 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, (HGLRC
)0xdeadbeef, 0);
908 ok(gl3Ctx
== 0, "pwglCreateContextAttribsARB using an invalid shareList passed\n");
909 error
= GetLastError();
910 /* The Nvidia implementation seems to return hresults instead of win32 error codes */
911 todo_wine
ok(error
== ERROR_INVALID_OPERATION
||
912 error
== NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_OPERATION
), "Expected ERROR_INVALID_OPERATION, got error=%x\n", error
);
913 wglDeleteContext(gl3Ctx
);
916 /* Try to create an OpenGL 3.0 context */
918 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
919 HGLRC gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
923 skip("Skipping the rest of the WGL_ARB_create_context test due to lack of OpenGL 3.0\n");
927 wglDeleteContext(gl3Ctx
);
930 /* 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 */
932 HGLRC glCtx
= wglCreateContext(hdc
);
934 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
935 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};
937 HGLRC gl3Ctx
= pwglCreateContextAttribsARB(hdc
, glCtx
, attribs
);
938 ok(gl3Ctx
!= NULL
, "Sharing of a display list between OpenGL 3.0 and OpenGL 1.x/2.x failed!\n");
940 wglDeleteContext(gl3Ctx
);
942 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, glCtx
, attribs_future
);
943 ok(gl3Ctx
!= NULL
, "Sharing of a display list between a forward compatible OpenGL 3.0 context and OpenGL 1.x/2.x failed!\n");
945 wglDeleteContext(gl3Ctx
);
948 wglDeleteContext(glCtx
);
951 /* Try to create an OpenGL 3.0 context and test windowless rendering */
954 int attribs
[] = {WGL_CONTEXT_MAJOR_VERSION_ARB
, 3, WGL_CONTEXT_MINOR_VERSION_ARB
, 0, 0};
957 gl3Ctx
= pwglCreateContextAttribsARB(hdc
, 0, attribs
);
958 ok(gl3Ctx
!= 0, "pwglCreateContextAttribsARB for a 3.0 context failed!\n");
960 /* OpenGL 3.0 allows offscreen rendering WITHOUT a drawable
961 * Neither AMD or Nvidia support it at this point. The WGL_ARB_create_context specs also say that
962 * it is hard because drivers use the HDC to enter the display driver and it sounds like they don't
963 * expect drivers to ever offer it.
965 res
= wglMakeCurrent(0, gl3Ctx
);
966 ok(res
== FALSE
, "Wow, OpenGL 3.0 windowless rendering passed while it was expected not to!\n");
968 wglMakeCurrent(0, 0);
971 wglDeleteContext(gl3Ctx
);
975 static void test_minimized(void)
977 PIXELFORMATDESCRIPTOR pf_desc
=
979 sizeof(PIXELFORMATDESCRIPTOR
),
981 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
983 24, /* 24-bit color depth */
984 0, 0, 0, 0, 0, 0, /* color bits */
985 0, /* alpha buffer */
987 0, /* accumulation buffer */
988 0, 0, 0, 0, /* accum bits */
990 0, /* stencil buffer */
991 0, /* auxiliary buffer */
992 PFD_MAIN_PLANE
, /* main layer */
994 0, 0, 0 /* layer masks */
1003 window
= CreateWindowA("static", "opengl32_test",
1004 WS_POPUP
| WS_MINIMIZE
, 0, 0, 640, 480, 0, 0, 0, 0);
1005 ok(!!window
, "Failed to create window, last error %#x.\n", GetLastError());
1008 ok(!!dc
, "Failed to get DC.\n");
1010 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1013 win_skip("Failed to find pixel format.\n");
1014 ReleaseDC(window
, dc
);
1015 DestroyWindow(window
);
1019 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1020 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1022 style
= GetWindowLongA(window
, GWL_STYLE
);
1023 ok(style
& WS_MINIMIZE
, "Window should be minimized, got style %#x.\n", style
);
1025 ctx
= wglCreateContext(dc
);
1026 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1028 ret
= wglMakeCurrent(dc
, ctx
);
1029 ok(ret
, "Failed to make context current, 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 ret
= wglMakeCurrent(NULL
, NULL
);
1035 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1037 ret
= wglDeleteContext(ctx
);
1038 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1040 ReleaseDC(window
, dc
);
1041 DestroyWindow(window
);
1044 static void test_window_dc(void)
1046 PIXELFORMATDESCRIPTOR pf_desc
=
1048 sizeof(PIXELFORMATDESCRIPTOR
),
1050 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1052 24, /* 24-bit color depth */
1053 0, 0, 0, 0, 0, 0, /* color bits */
1054 0, /* alpha buffer */
1056 0, /* accumulation buffer */
1057 0, 0, 0, 0, /* accum bits */
1059 0, /* stencil buffer */
1060 0, /* auxiliary buffer */
1061 PFD_MAIN_PLANE
, /* main layer */
1063 0, 0, 0 /* layer masks */
1072 window
= CreateWindowA("static", "opengl32_test",
1073 WS_OVERLAPPEDWINDOW
, 0, 0, 640, 480, 0, 0, 0, 0);
1074 ok(!!window
, "Failed to create window, last error %#x.\n", GetLastError());
1076 ShowWindow(window
, SW_SHOW
);
1078 dc
= GetWindowDC(window
);
1079 ok(!!dc
, "Failed to get DC.\n");
1081 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1084 win_skip("Failed to find pixel format.\n");
1085 ReleaseDC(window
, dc
);
1086 DestroyWindow(window
);
1090 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1091 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1093 ctx
= wglCreateContext(dc
);
1094 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1096 ret
= wglMakeCurrent(dc
, ctx
);
1097 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1099 GetClientRect(window
, &r
);
1100 glGetIntegerv(GL_VIEWPORT
, (GLint
*)&vp
);
1101 ok(EqualRect(&r
, &vp
), "Viewport not equal to client rect.\n");
1103 ret
= wglMakeCurrent(NULL
, NULL
);
1104 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1106 ret
= wglDeleteContext(ctx
);
1107 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1109 ReleaseDC(window
, dc
);
1110 DestroyWindow(window
);
1113 static void test_message_window(void)
1115 PIXELFORMATDESCRIPTOR pf_desc
=
1117 sizeof(PIXELFORMATDESCRIPTOR
),
1119 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1121 24, /* 24-bit color depth */
1122 0, 0, 0, 0, 0, 0, /* color bits */
1123 0, /* alpha buffer */
1125 0, /* accumulation buffer */
1126 0, 0, 0, 0, /* accum bits */
1128 0, /* stencil buffer */
1129 0, /* auxiliary buffer */
1130 PFD_MAIN_PLANE
, /* main layer */
1132 0, 0, 0 /* layer masks */
1142 window
= CreateWindowA("static", "opengl32_test",
1143 WS_OVERLAPPEDWINDOW
, 0, 0, 100, 100, HWND_MESSAGE
, 0, 0, 0);
1146 win_skip( "HWND_MESSAGE not supported\n" );
1150 ok(!!dc
, "Failed to get DC.\n");
1152 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1155 win_skip("Failed to find pixel format.\n");
1156 ReleaseDC(window
, dc
);
1157 DestroyWindow(window
);
1161 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1162 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1164 ctx
= wglCreateContext(dc
);
1165 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1167 ret
= wglMakeCurrent(dc
, ctx
);
1168 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1170 GetClientRect(window
, &r
);
1171 glGetIntegerv(GL_VIEWPORT
, (GLint
*)&vp
);
1172 ok(EqualRect(&r
, &vp
), "Viewport not equal to client rect.\n");
1174 glClear(GL_COLOR_BUFFER_BIT
);
1176 glerr
= glGetError();
1177 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1178 ret
= SwapBuffers(dc
);
1179 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1181 ret
= wglMakeCurrent(NULL
, NULL
);
1182 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1184 ret
= wglDeleteContext(ctx
);
1185 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1187 ReleaseDC(window
, dc
);
1188 DestroyWindow(window
);
1191 static void test_destroy(HDC oldhdc
)
1193 PIXELFORMATDESCRIPTOR pf_desc
=
1195 sizeof(PIXELFORMATDESCRIPTOR
),
1197 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1199 24, /* 24-bit color depth */
1200 0, 0, 0, 0, 0, 0, /* color bits */
1201 0, /* alpha buffer */
1203 0, /* accumulation buffer */
1204 0, 0, 0, 0, /* accum bits */
1206 0, /* stencil buffer */
1207 0, /* auxiliary buffer */
1208 PFD_MAIN_PLANE
, /* main layer */
1210 0, 0, 0 /* layer masks */
1219 HGLRC oldctx
= wglGetCurrentContext();
1221 ok(!!oldctx
, "Expected to find a valid current context.\n");
1223 window
= CreateWindowA("static", "opengl32_test",
1224 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1225 ok(!!window
, "Failed to create window, last error %#x.\n", GetLastError());
1228 ok(!!dc
, "Failed to get DC.\n");
1230 pixel_format
= ChoosePixelFormat(dc
, &pf_desc
);
1233 win_skip("Failed to find pixel format.\n");
1234 ReleaseDC(window
, dc
);
1235 DestroyWindow(window
);
1239 ret
= SetPixelFormat(dc
, pixel_format
, &pf_desc
);
1240 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1242 ctx
= wglCreateContext(dc
);
1243 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1245 ret
= wglMakeCurrent(dc
, ctx
);
1246 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1248 glClear(GL_COLOR_BUFFER_BIT
);
1250 glerr
= glGetError();
1251 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1252 ret
= SwapBuffers(dc
);
1253 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1255 ret
= DestroyWindow(window
);
1256 ok(ret
, "Failed to destroy window, last error %#x.\n", GetLastError());
1258 ok(wglGetCurrentContext() == ctx
, "Wrong current context.\n");
1260 SetLastError(0xdeadbeef);
1261 ret
= wglMakeCurrent(dc
, ctx
);
1262 err
= GetLastError();
1263 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1264 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1265 SetLastError(0xdeadbeef);
1266 ret
= SwapBuffers(dc
);
1267 err
= GetLastError();
1268 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1270 ok(wglGetCurrentContext() == ctx
, "Wrong current context.\n");
1272 glClear(GL_COLOR_BUFFER_BIT
);
1274 glerr
= glGetError();
1275 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1276 SetLastError(0xdeadbeef);
1277 ret
= SwapBuffers(dc
);
1278 err
= GetLastError();
1279 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1281 ret
= wglMakeCurrent(NULL
, NULL
);
1282 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1284 glClear(GL_COLOR_BUFFER_BIT
);
1286 glerr
= glGetError();
1287 ok(glerr
== GL_INVALID_OPERATION
, "Failed glClear, error %#x.\n", glerr
);
1288 SetLastError(0xdeadbeef);
1289 ret
= SwapBuffers(dc
);
1290 err
= GetLastError();
1291 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1293 SetLastError(0xdeadbeef);
1294 ret
= wglMakeCurrent(dc
, ctx
);
1295 err
= GetLastError();
1296 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1297 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1299 ok(wglGetCurrentContext() == NULL
, "Wrong current context.\n");
1301 ret
= wglMakeCurrent(oldhdc
, oldctx
);
1302 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1303 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1305 SetLastError(0xdeadbeef);
1306 ret
= wglMakeCurrent(dc
, ctx
);
1307 err
= GetLastError();
1308 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1309 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1311 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1313 ret
= wglDeleteContext(ctx
);
1314 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1316 ReleaseDC(window
, dc
);
1318 ret
= wglMakeCurrent(oldhdc
, oldctx
);
1319 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1322 static void test_destroy_read(HDC oldhdc
)
1324 PIXELFORMATDESCRIPTOR pf_desc
=
1326 sizeof(PIXELFORMATDESCRIPTOR
),
1328 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
1330 24, /* 24-bit color depth */
1331 0, 0, 0, 0, 0, 0, /* color bits */
1332 0, /* alpha buffer */
1334 0, /* accumulation buffer */
1335 0, 0, 0, 0, /* accum bits */
1337 0, /* stencil buffer */
1338 0, /* auxiliary buffer */
1339 PFD_MAIN_PLANE
, /* main layer */
1341 0, 0, 0 /* layer masks */
1344 HWND draw_window
, read_window
;
1347 HDC read_dc
, draw_dc
;
1350 HGLRC oldctx
= wglGetCurrentContext();
1352 ok(!!oldctx
, "Expected to find a valid current context\n");
1354 draw_window
= CreateWindowA("static", "opengl32_test",
1355 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1356 ok(!!draw_window
, "Failed to create window, last error %#x.\n", GetLastError());
1358 draw_dc
= GetDC(draw_window
);
1359 ok(!!draw_dc
, "Failed to get DC.\n");
1361 pixel_format
= ChoosePixelFormat(draw_dc
, &pf_desc
);
1364 win_skip("Failed to find pixel format.\n");
1365 ReleaseDC(draw_window
, draw_dc
);
1366 DestroyWindow(draw_window
);
1370 ret
= SetPixelFormat(draw_dc
, pixel_format
, &pf_desc
);
1371 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1373 read_window
= CreateWindowA("static", "opengl32_test",
1374 WS_POPUP
, 0, 0, 640, 480, 0, 0, 0, 0);
1375 ok(!!read_window
, "Failed to create window, last error %#x.\n", GetLastError());
1377 read_dc
= GetDC(read_window
);
1378 ok(!!draw_dc
, "Failed to get DC.\n");
1380 pixel_format
= ChoosePixelFormat(read_dc
, &pf_desc
);
1383 win_skip("Failed to find pixel format.\n");
1384 ReleaseDC(read_window
, read_dc
);
1385 DestroyWindow(read_window
);
1386 ReleaseDC(draw_window
, draw_dc
);
1387 DestroyWindow(draw_window
);
1391 ret
= SetPixelFormat(read_dc
, pixel_format
, &pf_desc
);
1392 ok(ret
, "Failed to set pixel format, last error %#x.\n", GetLastError());
1394 ctx
= wglCreateContext(draw_dc
);
1395 ok(!!ctx
, "Failed to create GL context, last error %#x.\n", GetLastError());
1397 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1398 ok(ret
, "Failed to make context current, last error %#x.\n", GetLastError());
1400 glCopyPixels(0, 0, 640, 480, GL_COLOR
);
1402 glerr
= glGetError();
1403 ok(glerr
== GL_NO_ERROR
, "Failed glCopyPixel, error %#x.\n", glerr
);
1404 ret
= SwapBuffers(draw_dc
);
1405 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1407 ret
= DestroyWindow(read_window
);
1408 ok(ret
, "Failed to destroy window, last error %#x.\n", GetLastError());
1410 ok(wglGetCurrentContext() == ctx
, "Wrong current context.\n");
1412 if (0) /* Crashes on AMD on Windows */
1414 glCopyPixels(0, 0, 640, 480, GL_COLOR
);
1416 glerr
= glGetError();
1417 ok(glerr
== GL_NO_ERROR
, "Failed glCopyPixel, error %#x.\n", glerr
);
1420 glClear(GL_COLOR_BUFFER_BIT
);
1422 glerr
= glGetError();
1423 ok(glerr
== GL_NO_ERROR
, "Failed glClear, error %#x.\n", glerr
);
1424 ret
= SwapBuffers(draw_dc
);
1425 ok(ret
, "Failed SwapBuffers, error %#x.\n", GetLastError());
1427 ret
= wglMakeCurrent(NULL
, NULL
);
1428 ok(ret
, "Failed to clear current context, last error %#x.\n", GetLastError());
1430 if (0) /* This crashes with Nvidia drivers on Windows. */
1432 SetLastError(0xdeadbeef);
1433 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1434 err
= GetLastError();
1435 ok(!ret
&& err
== ERROR_INVALID_HANDLE
,
1436 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1439 ret
= DestroyWindow(draw_window
);
1440 ok(ret
, "Failed to destroy window, last error %#x.\n", GetLastError());
1442 glClear(GL_COLOR_BUFFER_BIT
);
1444 glerr
= glGetError();
1445 ok(glerr
== GL_INVALID_OPERATION
, "Failed glClear, error %#x.\n", glerr
);
1446 SetLastError(0xdeadbeef);
1447 ret
= SwapBuffers(draw_dc
);
1448 err
= GetLastError();
1449 ok(!ret
&& err
== ERROR_INVALID_HANDLE
, "Unexpected behavior with SwapBuffer, last error %#x.\n", err
);
1451 SetLastError(0xdeadbeef);
1452 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1453 err
= GetLastError();
1454 ok(!ret
&& (err
== ERROR_INVALID_HANDLE
|| err
== 0xc0070006),
1455 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret
, err
);
1457 ok(wglGetCurrentContext() == NULL
, "Wrong current context.\n");
1459 wglMakeCurrent(NULL
, NULL
);
1461 wglMakeCurrent(oldhdc
, oldctx
);
1462 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1464 SetLastError(0xdeadbeef);
1465 ret
= pwglMakeContextCurrentARB(draw_dc
, read_dc
, ctx
);
1466 err
= GetLastError();
1467 ok(!ret
&& (err
== ERROR_INVALID_HANDLE
|| err
== 0xc0070006),
1468 "Unexpected behavior when making context current, last error %#x.\n", err
);
1470 ok(wglGetCurrentContext() == oldctx
, "Wrong current context.\n");
1472 ret
= wglDeleteContext(ctx
);
1473 ok(ret
, "Failed to delete GL context, last error %#x.\n", GetLastError());
1475 ReleaseDC(read_window
, read_dc
);
1476 ReleaseDC(draw_window
, draw_dc
);
1478 wglMakeCurrent(oldhdc
, oldctx
);
1484 PIXELFORMATDESCRIPTOR pfd
= {
1485 sizeof(PIXELFORMATDESCRIPTOR
),
1487 PFD_DRAW_TO_WINDOW
|
1488 PFD_SUPPORT_OPENGL
|
1491 24, /* 24-bit color depth */
1492 0, 0, 0, 0, 0, 0, /* color bits */
1493 0, /* alpha buffer */
1495 0, /* accumulation buffer */
1496 0, 0, 0, 0, /* accum bits */
1498 0, /* stencil buffer */
1499 0, /* auxiliary buffer */
1500 PFD_MAIN_PLANE
, /* main layer */
1502 0, 0, 0 /* layer masks */
1505 hwnd
= CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW
,
1506 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
1507 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
1511 int iPixelFormat
, res
;
1514 ShowWindow(hwnd
, SW_SHOW
);
1518 iPixelFormat
= ChoosePixelFormat(hdc
, &pfd
);
1519 if(iPixelFormat
== 0)
1521 /* This should never happen as ChoosePixelFormat always returns a closest match, but currently this fails in Wine if we don't have glX */
1522 win_skip("Unable to find pixel format.\n");
1526 /* We shouldn't be able to create a context from a hdc which doesn't have a pixel format set */
1527 hglrc
= wglCreateContext(hdc
);
1528 ok(hglrc
== NULL
, "wglCreateContext should fail when no pixel format has been set, but it passed\n");
1529 error
= GetLastError();
1530 ok(error
== ERROR_INVALID_PIXEL_FORMAT
, "expected ERROR_INVALID_PIXEL_FORMAT for wglCreateContext without a pixelformat set, but received %#x\n", error
);
1532 res
= SetPixelFormat(hdc
, iPixelFormat
, &pfd
);
1533 ok(res
, "SetPixelformat failed: %x\n", GetLastError());
1535 test_bitmap_rendering( TRUE
);
1536 test_bitmap_rendering( FALSE
);
1539 test_message_window();
1542 hglrc
= wglCreateContext(hdc
);
1543 res
= wglMakeCurrent(hdc
, hglrc
);
1544 ok(res
, "wglMakeCurrent failed!\n");
1547 trace("OpenGL renderer: %s\n", glGetString(GL_RENDERER
));
1548 trace("OpenGL driver version: %s\n", glGetString(GL_VERSION
));
1549 trace("OpenGL vendor: %s\n", glGetString(GL_VENDOR
));
1553 skip("Skipping OpenGL tests without a current context\n");
1557 /* Initialisation of WGL functions depends on an implicit WGL context. For this reason we can't load them before making
1558 * any WGL call :( On Wine this would work but not on real Windows because there can be different implementations (software, ICD, MCD).
1561 test_getprocaddress(hdc
);
1562 test_deletecontext(hwnd
, hdc
);
1563 test_makecurrent(hdc
);
1565 /* The lack of wglGetExtensionsStringARB in general means broken software rendering or the lack of decent OpenGL support, skip tests in such cases */
1566 if (!pwglGetExtensionsStringARB
)
1568 win_skip("wglGetExtensionsStringARB is not available\n");
1572 test_setpixelformat(hdc
);
1574 test_sharelists(hdc
);
1575 test_colorbits(hdc
);
1577 test_acceleration(hdc
);
1579 wgl_extensions
= pwglGetExtensionsStringARB(hdc
);
1580 if(wgl_extensions
== NULL
) skip("Skipping opengl32 tests because this OpenGL implementation doesn't support WGL extensions!\n");
1582 if(strstr(wgl_extensions
, "WGL_ARB_create_context"))
1585 if(strstr(wgl_extensions
, "WGL_ARB_make_current_read"))
1587 test_make_current_read(hdc
);
1588 test_destroy_read(hdc
);
1591 skip("WGL_ARB_make_current_read not supported, skipping test\n");
1593 if(strstr(wgl_extensions
, "WGL_ARB_pbuffer"))
1596 skip("WGL_ARB_pbuffer not supported, skipping pbuffer test\n");
1599 ReleaseDC(hwnd
, hdc
);
1600 DestroyWindow(hwnd
);