opengl32: No display driver supports windowless opengl3 rendering and likely no drive...
[wine/multimedia.git] / dlls / opengl32 / tests / opengl.c
blob4137eea54a00a77e4e4a60d42c83f5cda9e479ca
1 /*
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
21 #include <windows.h>
22 #include <wingdi.h>
23 #include "wine/test.h"
25 const unsigned char * WINAPI glGetString(unsigned int);
26 #define GL_VENDOR 0x1F00
27 #define GL_RENDERER 0x1F01
28 #define GL_VERSION 0x1F02
30 #define MAX_FORMATS 256
31 typedef void* HPBUFFERARB;
33 /* WGL_ARB_create_context */
34 HGLRC (WINAPI *pwglCreateContextAttribsARB)(HDC hDC, HGLRC hShareContext, const int *attribList);
35 /* GetLastError */
36 #define ERROR_INVALID_VERSION_ARB 0x2095
37 #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
38 #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
39 #define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
40 #define WGL_CONTEXT_FLAGS_ARB 0x2094
41 /* Flags for WGL_CONTEXT_FLAGS_ARB */
42 #define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
43 #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
45 /* WGL_ARB_extensions_string */
46 static const char* (WINAPI *pwglGetExtensionsStringARB)(HDC);
47 static int (WINAPI *pwglReleasePbufferDCARB)(HPBUFFERARB, HDC);
49 /* WGL_ARB_make_current_read */
50 static BOOL (WINAPI *pwglMakeContextCurrentARB)(HDC hdraw, HDC hread, HGLRC hglrc);
51 static HDC (WINAPI *pwglGetCurrentReadDCARB)(void);
53 /* WGL_ARB_pixel_format */
54 #define WGL_ACCELERATION_ARB 0x2003
55 #define WGL_COLOR_BITS_ARB 0x2014
56 #define WGL_RED_BITS_ARB 0x2015
57 #define WGL_GREEN_BITS_ARB 0x2017
58 #define WGL_BLUE_BITS_ARB 0x2019
59 #define WGL_ALPHA_BITS_ARB 0x201B
60 #define WGL_SUPPORT_GDI_ARB 0x200F
61 #define WGL_DOUBLE_BUFFER_ARB 0x2011
62 #define WGL_NO_ACCELERATION_ARB 0x2025
63 #define WGL_GENERIC_ACCELERATION_ARB 0x2026
64 #define WGL_FULL_ACCELERATION_ARB 0x2027
66 static BOOL (WINAPI *pwglChoosePixelFormatARB)(HDC, const int *, const FLOAT *, UINT, int *, UINT *);
67 static BOOL (WINAPI *pwglGetPixelFormatAttribivARB)(HDC, int, int, UINT, const int *, int *);
69 /* WGL_ARB_pbuffer */
70 #define WGL_DRAW_TO_PBUFFER_ARB 0x202D
71 static HPBUFFERARB* (WINAPI *pwglCreatePbufferARB)(HDC, int, int, int, const int *);
72 static HDC (WINAPI *pwglGetPbufferDCARB)(HPBUFFERARB);
74 static const char* wgl_extensions = NULL;
76 static void init_functions(void)
78 #define GET_PROC(func) \
79 p ## func = (void*)wglGetProcAddress(#func); \
80 if(!p ## func) \
81 trace("wglGetProcAddress(%s) failed\n", #func);
83 /* WGL_ARB_create_context */
84 GET_PROC(wglCreateContextAttribsARB);
86 /* WGL_ARB_extensions_string */
87 GET_PROC(wglGetExtensionsStringARB)
89 /* WGL_ARB_make_current_read */
90 GET_PROC(wglMakeContextCurrentARB);
91 GET_PROC(wglGetCurrentReadDCARB);
93 /* WGL_ARB_pixel_format */
94 GET_PROC(wglChoosePixelFormatARB)
95 GET_PROC(wglGetPixelFormatAttribivARB)
97 /* WGL_ARB_pbuffer */
98 GET_PROC(wglCreatePbufferARB)
99 GET_PROC(wglGetPbufferDCARB)
100 GET_PROC(wglReleasePbufferDCARB)
102 #undef GET_PROC
105 static void test_pbuffers(HDC hdc)
107 const int iAttribList[] = { WGL_DRAW_TO_PBUFFER_ARB, 1, /* Request pbuffer support */
108 0 };
109 int iFormats[MAX_FORMATS];
110 unsigned int nOnscreenFormats;
111 unsigned int nFormats;
112 int i, res;
113 int iPixelFormat = 0;
115 nOnscreenFormats = DescribePixelFormat(hdc, 0, 0, NULL);
117 /* When you want to render to a pbuffer you need to call wglGetPbufferDCARB which
118 * returns a 'magic' HDC which you can then pass to wglMakeCurrent to switch rendering
119 * to the pbuffer. Below some tests are performed on what happens if you use standard WGL calls
120 * on this 'magic' HDC for both a pixelformat that support onscreen and offscreen rendering
121 * and a pixelformat that's only available for offscreen rendering (this means that only
122 * wglChoosePixelFormatARB and friends know about the format.
124 * The first thing we need are pixelformats with pbuffer capabilities.
126 res = pwglChoosePixelFormatARB(hdc, iAttribList, NULL, MAX_FORMATS, iFormats, &nFormats);
127 if(res <= 0)
129 skip("No pbuffer compatible formats found while WGL_ARB_pbuffer is supported\n");
130 return;
132 trace("nOnscreenFormats: %d\n", nOnscreenFormats);
133 trace("Total number of pbuffer capable pixelformats: %d\n", nFormats);
135 /* Try to select an onscreen pixelformat out of the list */
136 for(i=0; i < nFormats; i++)
138 /* Check if the format is onscreen, if it is choose it */
139 if(iFormats[i] <= nOnscreenFormats)
141 iPixelFormat = iFormats[i];
142 trace("Selected iPixelFormat=%d\n", iPixelFormat);
143 break;
147 /* A video driver supports a large number of onscreen and offscreen pixelformats.
148 * The traditional WGL calls only see a subset of the whole pixelformat list. First
149 * of all they only see the onscreen formats (the offscreen formats are at the end of the
150 * pixelformat list) and second extended pixelformat capabilities are hidden from the
151 * standard WGL calls. Only functions that depend on WGL_ARB_pixel_format can see them.
153 * Below we check if the pixelformat is also supported onscreen.
155 if(iPixelFormat != 0)
157 HDC pbuffer_hdc;
158 HPBUFFERARB pbuffer = pwglCreatePbufferARB(hdc, iPixelFormat, 640 /* width */, 480 /* height */, NULL);
159 if(!pbuffer)
160 skip("Pbuffer creation failed!\n");
162 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
163 pbuffer_hdc = pwglGetPbufferDCARB(pbuffer);
164 res = GetPixelFormat(pbuffer_hdc);
165 ok(res == iPixelFormat, "Unexpected iPixelFormat=%d returned by GetPixelFormat for format %d\n", res, iPixelFormat);
166 trace("iPixelFormat returned by GetPixelFormat: %d\n", res);
167 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat);
169 pwglReleasePbufferDCARB(pbuffer, hdc);
171 else skip("Pbuffer test for onscreen pixelformat skipped as no onscreen format with pbuffer capabilities have been found\n");
173 /* Search for a real offscreen format */
174 for(i=0, iPixelFormat=0; i<nFormats; i++)
176 if(iFormats[i] > nOnscreenFormats)
178 iPixelFormat = iFormats[i];
179 trace("Selected iPixelFormat: %d\n", iPixelFormat);
180 break;
184 if(iPixelFormat != 0)
186 HDC pbuffer_hdc;
187 HPBUFFERARB pbuffer = pwglCreatePbufferARB(hdc, iPixelFormat, 640 /* width */, 480 /* height */, NULL);
188 if(!pbuffer)
189 skip("Pbuffer creation failed!\n");
191 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
192 pbuffer_hdc = pwglGetPbufferDCARB(pbuffer);
193 res = GetPixelFormat(pbuffer_hdc);
195 ok(res == 1, "Unexpected iPixelFormat=%d (1 expected) returned by GetPixelFormat for offscreen format %d\n", res, iPixelFormat);
196 trace("iPixelFormat returned by GetPixelFormat: %d\n", res);
197 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat);
198 pwglReleasePbufferDCARB(pbuffer, hdc);
200 else skip("Pbuffer test for offscreen pixelformat skipped as no offscreen-only format with pbuffer capabilities has been found\n");
203 static void test_setpixelformat(HDC winhdc)
205 int res = 0;
206 int nCfgs;
207 int pf;
208 int i;
209 HWND hwnd;
210 PIXELFORMATDESCRIPTOR pfd = {
211 sizeof(PIXELFORMATDESCRIPTOR),
212 1, /* version */
213 PFD_DRAW_TO_WINDOW |
214 PFD_SUPPORT_OPENGL |
215 PFD_DOUBLEBUFFER,
216 PFD_TYPE_RGBA,
217 24, /* 24-bit color depth */
218 0, 0, 0, 0, 0, 0, /* color bits */
219 0, /* alpha buffer */
220 0, /* shift bit */
221 0, /* accumulation buffer */
222 0, 0, 0, 0, /* accum bits */
223 32, /* z-buffer */
224 0, /* stencil buffer */
225 0, /* auxiliary buffer */
226 PFD_MAIN_PLANE, /* main layer */
227 0, /* reserved */
228 0, 0, 0 /* layer masks */
231 HDC hdc = GetDC(0);
232 ok(hdc != 0, "GetDC(0) failed!\n");
234 /* This should pass even on the main device context */
235 pf = ChoosePixelFormat(hdc, &pfd);
236 ok(pf != 0, "ChoosePixelFormat failed on main device context\n");
238 /* SetPixelFormat on the main device context 'X root window' should fail,
239 * but some broken drivers allow it
241 res = SetPixelFormat(hdc, pf, &pfd);
242 trace("SetPixelFormat on main device context %s\n", res ? "succeeded" : "failed");
244 /* Setting the same format that was set on the HDC is allowed; other
245 formats fail */
246 nCfgs = DescribePixelFormat(winhdc, 0, 0, NULL);
247 pf = GetPixelFormat(winhdc);
248 for(i = 1;i <= nCfgs;i++)
250 int res = SetPixelFormat(winhdc, i, NULL);
251 if(i == pf) ok(res, "Failed to set the same pixel format\n");
252 else ok(!res, "Unexpectedly set an alternate pixel format\n");
255 hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW,
256 10, 10, 200, 200, NULL, NULL, NULL, NULL);
257 ok(hwnd != NULL, "err: %d\n", GetLastError());
258 if (hwnd)
260 HDC hdc = GetDC( hwnd );
261 pf = ChoosePixelFormat( hdc, &pfd );
262 ok( pf != 0, "ChoosePixelFormat failed\n" );
263 res = SetPixelFormat( hdc, pf, &pfd );
264 ok( res != 0, "SetPixelFormat failed\n" );
265 i = GetPixelFormat( hdc );
266 ok( i == pf, "GetPixelFormat returned wrong format %d/%d\n", i, pf );
267 ReleaseDC( hwnd, hdc );
268 hdc = GetWindowDC( hwnd );
269 i = GetPixelFormat( hdc );
270 ok( i == pf, "GetPixelFormat returned wrong format %d/%d\n", i, pf );
271 ReleaseDC( hwnd, hdc );
272 DestroyWindow( hwnd );
275 hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW,
276 10, 10, 200, 200, NULL, NULL, NULL, NULL);
277 ok(hwnd != NULL, "err: %d\n", GetLastError());
278 if (hwnd)
280 HDC hdc = GetWindowDC( hwnd );
281 pf = ChoosePixelFormat( hdc, &pfd );
282 ok( pf != 0, "ChoosePixelFormat failed\n" );
283 res = SetPixelFormat( hdc, pf, &pfd );
284 ok( res != 0, "SetPixelFormat failed\n" );
285 i = GetPixelFormat( hdc );
286 ok( i == pf, "GetPixelFormat returned wrong format %d/%d\n", i, pf );
287 ReleaseDC( hwnd, hdc );
288 DestroyWindow( hwnd );
292 static void test_sharelists(HDC winhdc)
294 HGLRC hglrc1, hglrc2, hglrc3;
295 int res;
297 hglrc1 = wglCreateContext(winhdc);
298 res = wglShareLists(0, 0);
299 ok(res == FALSE, "Sharing display lists for no contexts passed!\n");
301 /* Test 1: Create a context and just share lists without doing anything special */
302 hglrc2 = wglCreateContext(winhdc);
303 if(hglrc2)
305 res = wglShareLists(hglrc1, hglrc2);
306 ok(res, "Sharing of display lists failed\n");
307 wglDeleteContext(hglrc2);
310 /* Test 2: Share display lists with a 'destination' context which has been made current */
311 hglrc2 = wglCreateContext(winhdc);
312 if(hglrc2)
314 res = wglMakeCurrent(winhdc, hglrc2);
315 ok(res, "Make current failed\n");
316 res = wglShareLists(hglrc1, hglrc2);
317 todo_wine ok(res, "Sharing display lists with a destination context which has been made current failed\n");
318 wglMakeCurrent(0, 0);
319 wglDeleteContext(hglrc2);
322 /* Test 3: Share display lists with a context which already shares display lists with another context.
323 * According to MSDN the second parameter cannot share any display lists but some buggy drivers might allow it */
324 hglrc3 = wglCreateContext(winhdc);
325 if(hglrc3)
327 res = wglShareLists(hglrc3, hglrc1);
328 ok(res == FALSE, "Sharing of display lists passed for a context which already shared lists before\n");
329 wglDeleteContext(hglrc3);
332 /* Test 4: Share display lists with a 'source' context which has been made current */
333 hglrc2 = wglCreateContext(winhdc);
334 if(hglrc2)
336 res = wglMakeCurrent(winhdc, hglrc1);
337 ok(res, "Make current failed\n");
338 res = wglShareLists(hglrc1, hglrc2);
339 ok(res, "Sharing display lists with a source context which has been made current failed\n");
340 wglMakeCurrent(0, 0);
341 wglDeleteContext(hglrc2);
345 static void test_makecurrent(HDC winhdc)
347 BOOL ret;
348 HGLRC hglrc;
349 DWORD error;
351 hglrc = wglCreateContext(winhdc);
352 ok( hglrc != 0, "wglCreateContext failed\n" );
354 ret = wglMakeCurrent( winhdc, hglrc );
355 ok( ret, "wglMakeCurrent failed\n" );
357 ok( wglGetCurrentContext() == hglrc, "wrong context\n" );
359 /* set the same context again */
360 ret = wglMakeCurrent( winhdc, hglrc );
361 ok( ret, "wglMakeCurrent failed\n" );
363 /* check wglMakeCurrent(x, y) after another call to wglMakeCurrent(x, y) */
364 ret = wglMakeCurrent( winhdc, NULL );
365 ok( ret, "wglMakeCurrent failed\n" );
367 ret = wglMakeCurrent( winhdc, NULL );
368 ok( ret, "wglMakeCurrent failed\n" );
370 SetLastError( 0xdeadbeef );
371 ret = wglMakeCurrent( NULL, NULL );
372 ok( !ret, "wglMakeCurrent succeeded\n" );
373 error = GetLastError();
374 ok( error == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got error=%x\n", error);
376 ret = wglMakeCurrent( winhdc, NULL );
377 ok( ret, "wglMakeCurrent failed\n" );
379 ret = wglMakeCurrent( winhdc, hglrc );
380 ok( ret, "wglMakeCurrent failed\n" );
382 ret = wglMakeCurrent( NULL, NULL );
383 ok( ret, "wglMakeCurrent failed\n" );
385 SetLastError( 0xdeadbeef );
386 ret = wglMakeCurrent( NULL, NULL );
387 ok( !ret, "wglMakeCurrent succeeded\n" );
388 error = GetLastError();
389 ok( error == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got error=%x\n", error);
391 ret = wglMakeCurrent( winhdc, hglrc );
392 ok( ret, "wglMakeCurrent failed\n" );
395 static void test_colorbits(HDC hdc)
397 const int iAttribList[] = { WGL_COLOR_BITS_ARB, WGL_RED_BITS_ARB, WGL_GREEN_BITS_ARB,
398 WGL_BLUE_BITS_ARB, WGL_ALPHA_BITS_ARB };
399 int iAttribRet[sizeof(iAttribList)/sizeof(iAttribList[0])];
400 const int iAttribs[] = { WGL_ALPHA_BITS_ARB, 1, 0 };
401 unsigned int nFormats;
402 int res;
403 int iPixelFormat = 0;
405 if (!pwglChoosePixelFormatARB)
407 win_skip("wglChoosePixelFormatARB is not available\n");
408 return;
411 /* We need a pixel format with at least one bit of alpha */
412 res = pwglChoosePixelFormatARB(hdc, iAttribs, NULL, 1, &iPixelFormat, &nFormats);
413 if(res == FALSE || nFormats == 0)
415 skip("No suitable pixel formats found\n");
416 return;
419 res = pwglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0,
420 sizeof(iAttribList)/sizeof(iAttribList[0]), iAttribList, iAttribRet);
421 if(res == FALSE)
423 skip("wglGetPixelFormatAttribivARB failed\n");
424 return;
426 iAttribRet[1] += iAttribRet[2]+iAttribRet[3]+iAttribRet[4];
427 ok(iAttribRet[0] == iAttribRet[1], "WGL_COLOR_BITS_ARB (%d) does not equal R+G+B+A (%d)!\n",
428 iAttribRet[0], iAttribRet[1]);
431 static void test_gdi_dbuf(HDC hdc)
433 const int iAttribList[] = { WGL_SUPPORT_GDI_ARB, WGL_DOUBLE_BUFFER_ARB };
434 int iAttribRet[sizeof(iAttribList)/sizeof(iAttribList[0])];
435 unsigned int nFormats;
436 int iPixelFormat;
437 int res;
439 if (!pwglGetPixelFormatAttribivARB)
441 win_skip("wglGetPixelFormatAttribivARB is not available\n");
442 return;
445 nFormats = DescribePixelFormat(hdc, 0, 0, NULL);
446 for(iPixelFormat = 1;iPixelFormat <= nFormats;iPixelFormat++)
448 res = pwglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0,
449 sizeof(iAttribList)/sizeof(iAttribList[0]), iAttribList,
450 iAttribRet);
451 ok(res!=FALSE, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat);
452 if(res == FALSE)
453 continue;
455 ok(!(iAttribRet[0] && iAttribRet[1]), "GDI support and double buffering on pixel format %d\n", iPixelFormat);
459 static void test_acceleration(HDC hdc)
461 const int iAttribList[] = { WGL_ACCELERATION_ARB };
462 int iAttribRet[sizeof(iAttribList)/sizeof(iAttribList[0])];
463 unsigned int nFormats;
464 int iPixelFormat;
465 int res;
466 PIXELFORMATDESCRIPTOR pfd;
468 if (!pwglGetPixelFormatAttribivARB)
470 win_skip("wglGetPixelFormatAttribivARB is not available\n");
471 return;
474 nFormats = DescribePixelFormat(hdc, 0, 0, NULL);
475 for(iPixelFormat = 1; iPixelFormat <= nFormats; iPixelFormat++)
477 res = pwglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0,
478 sizeof(iAttribList)/sizeof(iAttribList[0]), iAttribList,
479 iAttribRet);
480 ok(res!=FALSE, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat);
481 if(res == FALSE)
482 continue;
484 memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
485 DescribePixelFormat(hdc, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
487 switch(iAttribRet[0])
489 case WGL_NO_ACCELERATION_ARB:
490 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);
491 break;
492 case WGL_GENERIC_ACCELERATION_ARB:
493 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);
494 break;
495 case WGL_FULL_ACCELERATION_ARB:
496 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);
497 break;
502 static void test_make_current_read(HDC hdc)
504 int res;
505 HDC hread;
506 HGLRC hglrc = wglCreateContext(hdc);
508 if(!hglrc)
510 skip("wglCreateContext failed!\n");
511 return;
514 res = wglMakeCurrent(hdc, hglrc);
515 if(!res)
517 skip("wglMakeCurrent failed!\n");
518 return;
521 /* Test what wglGetCurrentReadDCARB does for wglMakeCurrent as the spec doesn't mention it */
522 hread = pwglGetCurrentReadDCARB();
523 trace("hread %p, hdc %p\n", hread, hdc);
524 ok(hread == hdc, "wglGetCurrentReadDCARB failed for standard wglMakeCurrent\n");
526 pwglMakeContextCurrentARB(hdc, hdc, hglrc);
527 hread = pwglGetCurrentReadDCARB();
528 ok(hread == hdc, "wglGetCurrentReadDCARB failed for wglMakeContextCurrent\n");
531 static void test_dc(HWND hwnd, HDC hdc)
533 int pf1, pf2;
534 HDC hdc2;
536 /* Get another DC and make sure it has the same pixel format */
537 hdc2 = GetDC(hwnd);
538 if(hdc != hdc2)
540 pf1 = GetPixelFormat(hdc);
541 pf2 = GetPixelFormat(hdc2);
542 ok(pf1 == pf2, "Second DC does not have the same format (%d != %d)\n", pf1, pf2);
544 else
545 skip("Could not get a different DC for the window\n");
547 if(hdc2)
549 ReleaseDC(hwnd, hdc2);
550 hdc2 = NULL;
554 static void test_opengl3(HDC hdc)
556 /* Try to create a context using an invalid OpenGL version namely 0.x */
558 HGLRC gl3Ctx;
559 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 0, 0};
561 gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
562 ok(gl3Ctx == 0, "wglCreateContextAttribs with major version=0 should fail!\n");
564 if(gl3Ctx)
565 wglDeleteContext(gl3Ctx);
568 /* Try to create a context compatible with OpenGL 1.x; 1.0-2.1 is allowed */
570 HGLRC gl3Ctx;
571 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 1, 0};
573 gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
574 ok(gl3Ctx != 0, "pwglCreateContextAttribsARB for a 1.x context failed!\n");
575 wglDeleteContext(gl3Ctx);
578 /* Try to pass an invalid HDC */
580 HGLRC gl3Ctx;
581 DWORD error;
582 gl3Ctx = pwglCreateContextAttribsARB((HDC)0xdeadbeef, 0, 0);
583 ok(gl3Ctx == 0, "pwglCreateContextAttribsARB using an invalid HDC passed\n");
584 error = GetLastError();
585 todo_wine ok(error == ERROR_DC_NOT_FOUND, "Expected ERROR_DC_NOT_FOUND, got error=%x\n", error);
586 wglDeleteContext(gl3Ctx);
589 /* Try to pass an invalid shareList */
591 HGLRC gl3Ctx;
592 DWORD error;
593 gl3Ctx = pwglCreateContextAttribsARB(hdc, (HGLRC)0xdeadbeef, 0);
594 todo_wine ok(gl3Ctx == 0, "pwglCreateContextAttribsARB using an invalid shareList passed\n");
595 error = GetLastError();
596 todo_wine ok(error == ERROR_INVALID_OPERATION, "Expected ERROR_INVALID_OPERATION, got error=%x\n", error);
597 wglDeleteContext(gl3Ctx);
600 /* Try to create an OpenGL 3.0 context */
602 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0};
603 HGLRC gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
605 if(gl3Ctx == NULL)
607 skip("Skipping the rest of the WGL_ARB_create_context test due to lack of OpenGL 3.0\n");
608 return;
611 wglDeleteContext(gl3Ctx);
614 /* 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 */
616 HGLRC glCtx = wglCreateContext(hdc);
618 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0};
619 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};
621 HGLRC gl3Ctx = pwglCreateContextAttribsARB(hdc, glCtx, attribs);
622 ok(gl3Ctx != NULL, "Sharing of a display list between OpenGL 3.0 and OpenGL 1.x/2.x failed!\n");
623 if(gl3Ctx)
624 wglDeleteContext(gl3Ctx);
626 gl3Ctx = pwglCreateContextAttribsARB(hdc, glCtx, attribs_future);
627 ok(gl3Ctx != NULL, "Sharing of a display list between a forward compatible OpenGL 3.0 context and OpenGL 1.x/2.x failed!\n");
628 if(gl3Ctx)
629 wglDeleteContext(gl3Ctx);
631 if(glCtx)
632 wglDeleteContext(glCtx);
635 /* Try to create an OpenGL 3.0 context and test windowless rendering */
637 HGLRC gl3Ctx;
638 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0};
639 BOOL res;
641 gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
642 ok(gl3Ctx != 0, "pwglCreateContextAttribsARB for a 3.0 context failed!\n");
644 /* OpenGL 3.0 allows offscreen rendering WITHOUT a drawable
645 * Neither AMD or Nvidia support it at this point. The WGL_ARB_create_context specs also say that
646 * it is hard because drivers use the HDC to enter the display driver and it sounds like they don't
647 * expect drivers to ever offer it.
649 res = wglMakeCurrent(0, gl3Ctx);
650 ok(res == FALSE, "Wow, OpenGL 3.0 windowless rendering passed while it was expected not to!\n");
651 if(res)
652 wglMakeCurrent(0, 0);
654 if(gl3Ctx)
655 wglDeleteContext(gl3Ctx);
659 START_TEST(opengl)
661 HWND hwnd;
662 PIXELFORMATDESCRIPTOR pfd = {
663 sizeof(PIXELFORMATDESCRIPTOR),
664 1, /* version */
665 PFD_DRAW_TO_WINDOW |
666 PFD_SUPPORT_OPENGL |
667 PFD_DOUBLEBUFFER,
668 PFD_TYPE_RGBA,
669 24, /* 24-bit color depth */
670 0, 0, 0, 0, 0, 0, /* color bits */
671 0, /* alpha buffer */
672 0, /* shift bit */
673 0, /* accumulation buffer */
674 0, 0, 0, 0, /* accum bits */
675 32, /* z-buffer */
676 0, /* stencil buffer */
677 0, /* auxiliary buffer */
678 PFD_MAIN_PLANE, /* main layer */
679 0, /* reserved */
680 0, 0, 0 /* layer masks */
683 hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW,
684 10, 10, 200, 200, NULL, NULL, NULL, NULL);
685 ok(hwnd != NULL, "err: %d\n", GetLastError());
686 if (hwnd)
688 HDC hdc;
689 int iPixelFormat, res;
690 HGLRC hglrc;
691 DWORD error;
692 ShowWindow(hwnd, SW_SHOW);
694 hdc = GetDC(hwnd);
696 iPixelFormat = ChoosePixelFormat(hdc, &pfd);
697 if(iPixelFormat == 0)
699 /* This should never happen as ChoosePixelFormat always returns a closest match, but currently this fails in Wine if we don't have glX */
700 win_skip("Unable to find pixel format.\n");
701 goto cleanup;
704 /* We shouldn't be able to create a context from a hdc which doesn't have a pixel format set */
705 hglrc = wglCreateContext(hdc);
706 ok(hglrc == NULL, "wglCreateContext should fail when no pixel format has been set, but it passed\n");
707 error = GetLastError();
708 ok(error == ERROR_INVALID_PIXEL_FORMAT, "expected ERROR_INVALID_PIXEL_FORMAT for wglCreateContext without a pixelformat set, but received %#x\n", error);
710 res = SetPixelFormat(hdc, iPixelFormat, &pfd);
711 ok(res, "SetPixelformat failed: %x\n", GetLastError());
713 test_dc(hwnd, hdc);
715 hglrc = wglCreateContext(hdc);
716 res = wglMakeCurrent(hdc, hglrc);
717 ok(res, "wglMakeCurrent failed!\n");
718 if(res)
720 trace("OpenGL renderer: %s\n", glGetString(GL_RENDERER));
721 trace("OpenGL driver version: %s\n", glGetString(GL_VERSION));
722 trace("OpenGL vendor: %s\n", glGetString(GL_VENDOR));
724 else
726 skip("Skipping OpenGL tests without a current context\n");
727 return;
730 /* Initialisation of WGL functions depends on an implicit WGL context. For this reason we can't load them before making
731 * any WGL call :( On Wine this would work but not on real Windows because there can be different implementations (software, ICD, MCD).
733 init_functions();
734 /* The lack of wglGetExtensionsStringARB in general means broken software rendering or the lack of decent OpenGL support, skip tests in such cases */
735 if (!pwglGetExtensionsStringARB)
737 win_skip("wglGetExtensionsStringARB is not available\n");
738 return;
741 test_makecurrent(hdc);
742 test_setpixelformat(hdc);
743 test_sharelists(hdc);
744 test_colorbits(hdc);
745 test_gdi_dbuf(hdc);
746 test_acceleration(hdc);
748 wgl_extensions = pwglGetExtensionsStringARB(hdc);
749 if(wgl_extensions == NULL) skip("Skipping opengl32 tests because this OpenGL implementation doesn't support WGL extensions!\n");
751 if(strstr(wgl_extensions, "WGL_ARB_create_context"))
752 test_opengl3(hdc);
754 if(strstr(wgl_extensions, "WGL_ARB_make_current_read"))
755 test_make_current_read(hdc);
756 else
757 skip("WGL_ARB_make_current_read not supported, skipping test\n");
759 if(strstr(wgl_extensions, "WGL_ARB_pbuffer"))
760 test_pbuffers(hdc);
761 else
762 skip("WGL_ARB_pbuffer not supported, skipping pbuffer test\n");
764 cleanup:
765 ReleaseDC(hwnd, hdc);
766 DestroyWindow(hwnd);