push cc8bc80451cc24f4d7cf75168b569f0ebfe19547
[wine/hacks.git] / dlls / opengl32 / tests / opengl.c
blob3078b79415197ed16a90f147313d52b540429e24
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)();
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 passed\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 paramater can't 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 failed 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 passed\n");
340 wglMakeCurrent(0, 0);
341 wglDeleteContext(hglrc2);
345 static void test_makecurrent(HDC winhdc)
347 BOOL ret;
348 HGLRC hglrc;
350 hglrc = wglCreateContext(winhdc);
351 ok( hglrc != 0, "wglCreateContext failed\n" );
353 ret = wglMakeCurrent( winhdc, hglrc );
354 ok( ret, "wglMakeCurrent failed\n" );
356 ok( wglGetCurrentContext() == hglrc, "wrong context\n" );
359 static void test_colorbits(HDC hdc)
361 const int iAttribList[] = { WGL_COLOR_BITS_ARB, WGL_RED_BITS_ARB, WGL_GREEN_BITS_ARB,
362 WGL_BLUE_BITS_ARB, WGL_ALPHA_BITS_ARB };
363 int iAttribRet[sizeof(iAttribList)/sizeof(iAttribList[0])];
364 const int iAttribs[] = { WGL_ALPHA_BITS_ARB, 1, 0 };
365 unsigned int nFormats;
366 int res;
367 int iPixelFormat = 0;
369 if (!pwglChoosePixelFormatARB)
371 win_skip("wglChoosePixelFormatARB is not available\n");
372 return;
375 /* We need a pixel format with at least one bit of alpha */
376 res = pwglChoosePixelFormatARB(hdc, iAttribs, NULL, 1, &iPixelFormat, &nFormats);
377 if(res == FALSE || nFormats == 0)
379 skip("No suitable pixel formats found\n");
380 return;
383 res = pwglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0,
384 sizeof(iAttribList)/sizeof(iAttribList[0]), iAttribList, iAttribRet);
385 if(res == FALSE)
387 skip("wglGetPixelFormatAttribivARB failed\n");
388 return;
390 iAttribRet[1] += iAttribRet[2]+iAttribRet[3]+iAttribRet[4];
391 ok(iAttribRet[0] == iAttribRet[1], "WGL_COLOR_BITS_ARB (%d) does not equal R+G+B+A (%d)!\n",
392 iAttribRet[0], iAttribRet[1]);
395 static void test_gdi_dbuf(HDC hdc)
397 const int iAttribList[] = { WGL_SUPPORT_GDI_ARB, WGL_DOUBLE_BUFFER_ARB };
398 int iAttribRet[sizeof(iAttribList)/sizeof(iAttribList[0])];
399 unsigned int nFormats;
400 int iPixelFormat;
401 int res;
403 if (!pwglGetPixelFormatAttribivARB)
405 win_skip("wglGetPixelFormatAttribivARB is not available\n");
406 return;
409 nFormats = DescribePixelFormat(hdc, 0, 0, NULL);
410 for(iPixelFormat = 1;iPixelFormat <= nFormats;iPixelFormat++)
412 res = pwglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0,
413 sizeof(iAttribList)/sizeof(iAttribList[0]), iAttribList,
414 iAttribRet);
415 ok(res!=FALSE, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat);
416 if(res == FALSE)
417 continue;
419 ok(!(iAttribRet[0] && iAttribRet[1]), "GDI support and double buffering on pixel format %d\n", iPixelFormat);
423 static void test_acceleration(HDC hdc)
425 const int iAttribList[] = { WGL_ACCELERATION_ARB };
426 int iAttribRet[sizeof(iAttribList)/sizeof(iAttribList[0])];
427 unsigned int nFormats;
428 int iPixelFormat;
429 int res;
430 PIXELFORMATDESCRIPTOR pfd;
432 if (!pwglGetPixelFormatAttribivARB)
434 win_skip("wglGetPixelFormatAttribivARB is not available\n");
435 return;
438 nFormats = DescribePixelFormat(hdc, 0, 0, NULL);
439 for(iPixelFormat = 1; iPixelFormat <= nFormats; iPixelFormat++)
441 res = pwglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0,
442 sizeof(iAttribList)/sizeof(iAttribList[0]), iAttribList,
443 iAttribRet);
444 ok(res!=FALSE, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat);
445 if(res == FALSE)
446 continue;
448 memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
449 DescribePixelFormat(hdc, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
451 switch(iAttribRet[0])
453 case WGL_NO_ACCELERATION_ARB:
454 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);
455 break;
456 case WGL_GENERIC_ACCELERATION_ARB:
457 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);
458 break;
459 case WGL_FULL_ACCELERATION_ARB:
460 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);
461 break;
466 static void test_make_current_read(HDC hdc)
468 int res;
469 HDC hread;
470 HGLRC hglrc = wglCreateContext(hdc);
472 if(!hglrc)
474 skip("wglCreateContext failed!\n");
475 return;
478 res = wglMakeCurrent(hdc, hglrc);
479 if(!res)
481 skip("wglMakeCurrent failed!\n");
482 return;
485 /* Test what wglGetCurrentReadDCARB does for wglMakeCurrent as the spec doesn't mention it */
486 hread = pwglGetCurrentReadDCARB();
487 trace("hread %p, hdc %p\n", hread, hdc);
488 ok(hread == hdc, "wglGetCurrentReadDCARB failed for standard wglMakeCurrent\n");
490 pwglMakeContextCurrentARB(hdc, hdc, hglrc);
491 hread = pwglGetCurrentReadDCARB();
492 ok(hread == hdc, "wglGetCurrentReadDCARB failed for wglMakeContextCurrent\n");
495 static void test_dc(HWND hwnd, HDC hdc)
497 int pf1, pf2;
498 HDC hdc2;
500 /* Get another DC and make sure it has the same pixel format */
501 hdc2 = GetDC(hwnd);
502 if(hdc != hdc2)
504 pf1 = GetPixelFormat(hdc);
505 pf2 = GetPixelFormat(hdc2);
506 ok(pf1 == pf2, "Second DC does not have the same format (%d != %d)\n", pf1, pf2);
508 else
509 skip("Could not get a different DC for the window\n");
511 if(hdc2)
513 ReleaseDC(hwnd, hdc2);
514 hdc2 = NULL;
518 static void test_opengl3(HDC hdc)
520 /* Try to create a context using an invalid OpenGL version namely 0.x */
522 HGLRC gl3Ctx;
523 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 0, 0};
525 gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
526 ok(gl3Ctx == 0, "wglCreateContextAttribs with major version=0 should fail!\n");
528 if(gl3Ctx)
529 wglDeleteContext(gl3Ctx);
532 /* Try to create a context compatible with OpenGL 1.x; 1.0-2.1 is allowed */
534 HGLRC gl3Ctx;
535 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 1, 0};
537 gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
538 ok(gl3Ctx != 0, "pwglCreateContextAttribsARB for a 1.x context failed!\n");
539 wglDeleteContext(gl3Ctx);
542 /* Try to pass an invalid HDC */
544 HGLRC gl3Ctx;
545 DWORD error;
546 gl3Ctx = pwglCreateContextAttribsARB((HDC)0xdeadbeef, 0, 0);
547 ok(gl3Ctx == 0, "pwglCreateContextAttribsARB using an invalid HDC passed\n");
548 error = GetLastError();
549 todo_wine ok(error == ERROR_DC_NOT_FOUND, "Expected ERROR_DC_NOT_FOUND, got error=%x\n", error);
550 wglDeleteContext(gl3Ctx);
553 /* Try to pass an invalid shareList */
555 HGLRC gl3Ctx;
556 DWORD error;
557 gl3Ctx = pwglCreateContextAttribsARB(hdc, (HGLRC)0xdeadbeef, 0);
558 ok(gl3Ctx == 0, "pwglCreateContextAttribsARB using an invalid shareList passed\n");
559 error = GetLastError();
560 todo_wine ok(error == ERROR_INVALID_OPERATION, "Expected ERROR_INVALID_OPERATION, got error=%x\n", error);
561 wglDeleteContext(gl3Ctx);
564 /* Try to create an OpenGL 3.0 context */
566 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0};
567 HGLRC gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
569 if(gl3Ctx == NULL)
571 skip("Skipping the rest of the WGL_ARB_create_context test due to lack of OpenGL 3.0\n");
572 return;
575 wglDeleteContext(gl3Ctx);
578 /* 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 */
580 HGLRC glCtx = wglCreateContext(hdc);
582 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0};
583 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};
585 HGLRC gl3Ctx = pwglCreateContextAttribsARB(hdc, glCtx, attribs);
586 ok(gl3Ctx != NULL, "Sharing of a display list between OpenGL 3.0 and OpenGL 1.x/2.x failed!\n");
587 if(gl3Ctx)
588 wglDeleteContext(gl3Ctx);
590 gl3Ctx = pwglCreateContextAttribsARB(hdc, glCtx, attribs_future);
591 ok(gl3Ctx != NULL, "Sharing of a display list between a forward compatible OpenGL 3.0 context and OpenGL 1.x/2.x failed!\n");
592 if(gl3Ctx)
593 wglDeleteContext(gl3Ctx);
595 if(glCtx)
596 wglDeleteContext(glCtx);
599 /* Try to create an OpenGL 3.0 context and test windowless rendering */
601 HGLRC gl3Ctx;
602 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0};
603 BOOL res;
605 gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
606 ok(gl3Ctx != 0, "pwglCreateContextAttribsARB for a 3.0 context failed!\n");
608 /* OpenGL 3.0 allows offscreen rendering WITHOUT a drawable */
609 /* NOTE: Nvidia's 177.89 beta drivers don't allow this yet */
610 res = wglMakeCurrent(0, gl3Ctx);
611 todo_wine ok(res == TRUE, "OpenGL 3.0 should allow windowless rendering, but the test failed!\n");
612 if(res)
613 wglMakeCurrent(0, 0);
615 if(gl3Ctx)
616 wglDeleteContext(gl3Ctx);
620 START_TEST(opengl)
622 HWND hwnd;
623 PIXELFORMATDESCRIPTOR pfd = {
624 sizeof(PIXELFORMATDESCRIPTOR),
625 1, /* version */
626 PFD_DRAW_TO_WINDOW |
627 PFD_SUPPORT_OPENGL |
628 PFD_DOUBLEBUFFER,
629 PFD_TYPE_RGBA,
630 24, /* 24-bit color depth */
631 0, 0, 0, 0, 0, 0, /* color bits */
632 0, /* alpha buffer */
633 0, /* shift bit */
634 0, /* accumulation buffer */
635 0, 0, 0, 0, /* accum bits */
636 32, /* z-buffer */
637 0, /* stencil buffer */
638 0, /* auxiliary buffer */
639 PFD_MAIN_PLANE, /* main layer */
640 0, /* reserved */
641 0, 0, 0 /* layer masks */
644 hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW,
645 10, 10, 200, 200, NULL, NULL, NULL, NULL);
646 ok(hwnd != NULL, "err: %d\n", GetLastError());
647 if (hwnd)
649 HDC hdc;
650 int iPixelFormat, res;
651 HGLRC hglrc;
652 DWORD error;
653 ShowWindow(hwnd, SW_SHOW);
655 hdc = GetDC(hwnd);
657 iPixelFormat = ChoosePixelFormat(hdc, &pfd);
658 if(iPixelFormat == 0)
660 /* This should never happen as ChoosePixelFormat always returns a closest match, but currently this fails in Wine if we don't have glX */
661 win_skip("Unable to find pixel format.\n");
662 goto cleanup;
665 /* We shouldn't be able to create a context from a hdc which doesn't have a pixel format set */
666 hglrc = wglCreateContext(hdc);
667 ok(hglrc == NULL, "wglCreateContext should fail when no pixel format has been set, but it passed\n");
668 error = GetLastError();
669 ok(error == ERROR_INVALID_PIXEL_FORMAT, "expected ERROR_INVALID_PIXEL_FORMAT for wglCreateContext without a pixelformat set, but received %#x\n", error);
671 res = SetPixelFormat(hdc, iPixelFormat, &pfd);
672 ok(res, "SetPixelformat failed: %x\n", GetLastError());
674 test_dc(hwnd, hdc);
676 hglrc = wglCreateContext(hdc);
677 res = wglMakeCurrent(hdc, hglrc);
678 ok(res, "wglMakeCurrent failed!\n");
679 if(res)
681 trace("OpenGL renderer: %s\n", glGetString(GL_RENDERER));
682 trace("OpenGL driver version: %s\n", glGetString(GL_VERSION));
683 trace("OpenGL vendor: %s\n", glGetString(GL_VENDOR));
685 else
687 skip("Skipping OpenGL tests without a current context\n");
688 return;
691 /* Initialisation of WGL functions depends on an implicit WGL context. For this reason we can't load them before making
692 * any WGL call :( On Wine this would work but not on real Windows because there can be different implementations (software, ICD, MCD).
694 init_functions();
695 /* The lack of wglGetExtensionsStringARB in general means broken software rendering or the lack of decent OpenGL support, skip tests in such cases */
696 if (!pwglGetExtensionsStringARB)
698 win_skip("wglGetExtensionsStringARB is not available\n");
699 return;
702 test_makecurrent(hdc);
703 test_setpixelformat(hdc);
704 test_sharelists(hdc);
705 test_colorbits(hdc);
706 test_gdi_dbuf(hdc);
707 test_acceleration(hdc);
709 wgl_extensions = pwglGetExtensionsStringARB(hdc);
710 if(wgl_extensions == NULL) skip("Skipping opengl32 tests because this OpenGL implementation doesn't support WGL extensions!\n");
712 if(strstr(wgl_extensions, "WGL_ARB_create_context"))
713 test_opengl3(hdc);
715 if(strstr(wgl_extensions, "WGL_ARB_make_current_read"))
716 test_make_current_read(hdc);
717 else
718 skip("WGL_ARB_make_current_read not supported, skipping test\n");
720 if(strstr(wgl_extensions, "WGL_ARB_pbuffer"))
721 test_pbuffers(hdc);
722 else
723 skip("WGL_ARB_pbuffer not supported, skipping pbuffer test\n");
725 cleanup:
726 ReleaseDC(hwnd, hdc);
727 DestroyWindow(hwnd);