push 8724397e7ede0f147b6e05994a72142d44d4fecc
[wine/hacks.git] / dlls / opengl32 / tests / opengl.c
blob49659eb8b4d5b01450b10a0162b1f6f86e0fa516
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_COLOR_BITS_ARB 0x2014
55 #define WGL_RED_BITS_ARB 0x2015
56 #define WGL_GREEN_BITS_ARB 0x2017
57 #define WGL_BLUE_BITS_ARB 0x2019
58 #define WGL_ALPHA_BITS_ARB 0x201B
59 #define WGL_SUPPORT_GDI_ARB 0x200F
60 #define WGL_DOUBLE_BUFFER_ARB 0x2011
62 static BOOL (WINAPI *pwglChoosePixelFormatARB)(HDC, const int *, const FLOAT *, UINT, int *, UINT *);
63 static BOOL (WINAPI *pwglGetPixelFormatAttribivARB)(HDC, int, int, UINT, const int *, int *);
65 /* WGL_ARB_pbuffer */
66 #define WGL_DRAW_TO_PBUFFER_ARB 0x202D
67 static HPBUFFERARB* (WINAPI *pwglCreatePbufferARB)(HDC, int, int, int, const int *);
68 static HDC (WINAPI *pwglGetPbufferDCARB)(HPBUFFERARB);
70 static const char* wgl_extensions = NULL;
72 static void init_functions(void)
74 #define GET_PROC(func) \
75 p ## func = (void*)wglGetProcAddress(#func); \
76 if(!p ## func) \
77 trace("wglGetProcAddress(%s) failed\n", #func);
79 /* WGL_ARB_create_context */
80 GET_PROC(wglCreateContextAttribsARB);
82 /* WGL_ARB_extensions_string */
83 GET_PROC(wglGetExtensionsStringARB)
85 /* WGL_ARB_make_current_read */
86 GET_PROC(wglMakeContextCurrentARB);
87 GET_PROC(wglGetCurrentReadDCARB);
89 /* WGL_ARB_pixel_format */
90 GET_PROC(wglChoosePixelFormatARB)
91 GET_PROC(wglGetPixelFormatAttribivARB)
93 /* WGL_ARB_pbuffer */
94 GET_PROC(wglCreatePbufferARB)
95 GET_PROC(wglGetPbufferDCARB)
96 GET_PROC(wglReleasePbufferDCARB)
98 #undef GET_PROC
101 static void test_pbuffers(HDC hdc)
103 const int iAttribList[] = { WGL_DRAW_TO_PBUFFER_ARB, 1, /* Request pbuffer support */
104 0 };
105 int iFormats[MAX_FORMATS];
106 unsigned int nOnscreenFormats;
107 unsigned int nFormats;
108 int i, res;
109 int iPixelFormat = 0;
111 nOnscreenFormats = DescribePixelFormat(hdc, 0, 0, NULL);
113 /* When you want to render to a pbuffer you need to call wglGetPbufferDCARB which
114 * returns a 'magic' HDC which you can then pass to wglMakeCurrent to switch rendering
115 * to the pbuffer. Below some tests are performed on what happens if you use standard WGL calls
116 * on this 'magic' HDC for both a pixelformat that support onscreen and offscreen rendering
117 * and a pixelformat that's only available for offscreen rendering (this means that only
118 * wglChoosePixelFormatARB and friends know about the format.
120 * The first thing we need are pixelformats with pbuffer capabilities.
122 res = pwglChoosePixelFormatARB(hdc, iAttribList, NULL, MAX_FORMATS, iFormats, &nFormats);
123 if(res <= 0)
125 skip("No pbuffer compatible formats found while WGL_ARB_pbuffer is supported\n");
126 return;
128 trace("nOnscreenFormats: %d\n", nOnscreenFormats);
129 trace("Total number of pbuffer capable pixelformats: %d\n", nFormats);
131 /* Try to select an onscreen pixelformat out of the list */
132 for(i=0; i < nFormats; i++)
134 /* Check if the format is onscreen, if it is choose it */
135 if(iFormats[i] <= nOnscreenFormats)
137 iPixelFormat = iFormats[i];
138 trace("Selected iPixelFormat=%d\n", iPixelFormat);
139 break;
143 /* A video driver supports a large number of onscreen and offscreen pixelformats.
144 * The traditional WGL calls only see a subset of the whole pixelformat list. First
145 * of all they only see the onscreen formats (the offscreen formats are at the end of the
146 * pixelformat list) and second extended pixelformat capabilities are hidden from the
147 * standard WGL calls. Only functions that depend on WGL_ARB_pixel_format can see them.
149 * Below we check if the pixelformat is also supported onscreen.
151 if(iPixelFormat != 0)
153 HDC pbuffer_hdc;
154 HPBUFFERARB pbuffer = pwglCreatePbufferARB(hdc, iPixelFormat, 640 /* width */, 480 /* height */, NULL);
155 if(!pbuffer)
156 skip("Pbuffer creation failed!\n");
158 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
159 pbuffer_hdc = pwglGetPbufferDCARB(pbuffer);
160 res = GetPixelFormat(pbuffer_hdc);
161 ok(res == iPixelFormat, "Unexpected iPixelFormat=%d returned by GetPixelFormat for format %d\n", res, iPixelFormat);
162 trace("iPixelFormat returned by GetPixelFormat: %d\n", res);
163 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat);
165 pwglReleasePbufferDCARB(pbuffer, hdc);
167 else skip("Pbuffer test for onscreen pixelformat skipped as no onscreen format with pbuffer capabilities have been found\n");
169 /* Search for a real offscreen format */
170 for(i=0, iPixelFormat=0; i<nFormats; i++)
172 if(iFormats[i] > nOnscreenFormats)
174 iPixelFormat = iFormats[i];
175 trace("Selected iPixelFormat: %d\n", iPixelFormat);
176 break;
180 if(iPixelFormat != 0)
182 HDC pbuffer_hdc;
183 HPBUFFERARB pbuffer = pwglCreatePbufferARB(hdc, iPixelFormat, 640 /* width */, 480 /* height */, NULL);
184 if(!pbuffer)
185 skip("Pbuffer creation failed!\n");
187 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
188 pbuffer_hdc = pwglGetPbufferDCARB(pbuffer);
189 res = GetPixelFormat(pbuffer_hdc);
191 ok(res == 1, "Unexpected iPixelFormat=%d (1 expected) returned by GetPixelFormat for offscreen format %d\n", res, iPixelFormat);
192 trace("iPixelFormat returned by GetPixelFormat: %d\n", res);
193 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat);
194 pwglReleasePbufferDCARB(pbuffer, hdc);
196 else skip("Pbuffer test for offscreen pixelformat skipped as no offscreen-only format with pbuffer capabilities has been found\n");
199 static void test_setpixelformat(HDC winhdc)
201 int res = 0;
202 int nCfgs;
203 int pf;
204 int i;
205 HWND hwnd;
206 PIXELFORMATDESCRIPTOR pfd = {
207 sizeof(PIXELFORMATDESCRIPTOR),
208 1, /* version */
209 PFD_DRAW_TO_WINDOW |
210 PFD_SUPPORT_OPENGL |
211 PFD_DOUBLEBUFFER,
212 PFD_TYPE_RGBA,
213 24, /* 24-bit color depth */
214 0, 0, 0, 0, 0, 0, /* color bits */
215 0, /* alpha buffer */
216 0, /* shift bit */
217 0, /* accumulation buffer */
218 0, 0, 0, 0, /* accum bits */
219 32, /* z-buffer */
220 0, /* stencil buffer */
221 0, /* auxiliary buffer */
222 PFD_MAIN_PLANE, /* main layer */
223 0, /* reserved */
224 0, 0, 0 /* layer masks */
227 HDC hdc = GetDC(0);
228 ok(hdc != 0, "GetDC(0) failed!\n");
230 /* This should pass even on the main device context */
231 pf = ChoosePixelFormat(hdc, &pfd);
232 ok(pf != 0, "ChoosePixelFormat failed on main device context\n");
234 /* SetPixelFormat on the main device context 'X root window' should fail,
235 * but some broken drivers allow it
237 res = SetPixelFormat(hdc, pf, &pfd);
238 trace("SetPixelFormat on main device context %s\n", res ? "succeeded" : "failed");
240 /* Setting the same format that was set on the HDC is allowed; other
241 formats fail */
242 nCfgs = DescribePixelFormat(winhdc, 0, 0, NULL);
243 pf = GetPixelFormat(winhdc);
244 for(i = 1;i <= nCfgs;i++)
246 int res = SetPixelFormat(winhdc, i, NULL);
247 if(i == pf) ok(res, "Failed to set the same pixel format\n");
248 else ok(!res, "Unexpectedly set an alternate pixel format\n");
251 hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW,
252 10, 10, 200, 200, NULL, NULL, NULL, NULL);
253 ok(hwnd != NULL, "err: %d\n", GetLastError());
254 if (hwnd)
256 HDC hdc = GetDC( hwnd );
257 pf = ChoosePixelFormat( hdc, &pfd );
258 ok( pf != 0, "ChoosePixelFormat failed\n" );
259 res = SetPixelFormat( hdc, pf, &pfd );
260 ok( res != 0, "SetPixelFormat failed\n" );
261 i = GetPixelFormat( hdc );
262 ok( i == pf, "GetPixelFormat returned wrong format %d/%d\n", i, pf );
263 ReleaseDC( hwnd, hdc );
264 hdc = GetWindowDC( hwnd );
265 i = GetPixelFormat( hdc );
266 ok( i == pf, "GetPixelFormat returned wrong format %d/%d\n", i, pf );
267 ReleaseDC( hwnd, hdc );
268 DestroyWindow( hwnd );
271 hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW,
272 10, 10, 200, 200, NULL, NULL, NULL, NULL);
273 ok(hwnd != NULL, "err: %d\n", GetLastError());
274 if (hwnd)
276 HDC hdc = GetWindowDC( hwnd );
277 pf = ChoosePixelFormat( hdc, &pfd );
278 ok( pf != 0, "ChoosePixelFormat failed\n" );
279 res = SetPixelFormat( hdc, pf, &pfd );
280 ok( res != 0, "SetPixelFormat failed\n" );
281 i = GetPixelFormat( hdc );
282 ok( i == pf, "GetPixelFormat returned wrong format %d/%d\n", i, pf );
283 ReleaseDC( hwnd, hdc );
284 DestroyWindow( hwnd );
288 static void test_makecurrent(HDC winhdc)
290 BOOL ret;
291 HGLRC hglrc;
293 hglrc = wglCreateContext(winhdc);
294 ok( hglrc != 0, "wglCreateContext failed\n" );
296 ret = wglMakeCurrent( winhdc, hglrc );
297 ok( ret, "wglMakeCurrent failed\n" );
299 ok( wglGetCurrentContext() == hglrc, "wrong context\n" );
302 static void test_colorbits(HDC hdc)
304 const int iAttribList[] = { WGL_COLOR_BITS_ARB, WGL_RED_BITS_ARB, WGL_GREEN_BITS_ARB,
305 WGL_BLUE_BITS_ARB, WGL_ALPHA_BITS_ARB };
306 int iAttribRet[sizeof(iAttribList)/sizeof(iAttribList[0])];
307 const int iAttribs[] = { WGL_ALPHA_BITS_ARB, 1, 0 };
308 unsigned int nFormats;
309 int res;
310 int iPixelFormat = 0;
312 if (!pwglChoosePixelFormatARB)
314 win_skip("wglChoosePixelFormatARB is not available\n");
315 return;
318 /* We need a pixel format with at least one bit of alpha */
319 res = pwglChoosePixelFormatARB(hdc, iAttribs, NULL, 1, &iPixelFormat, &nFormats);
320 if(res == FALSE || nFormats == 0)
322 skip("No suitable pixel formats found\n");
323 return;
326 res = pwglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0,
327 sizeof(iAttribList)/sizeof(iAttribList[0]), iAttribList, iAttribRet);
328 if(res == FALSE)
330 skip("wglGetPixelFormatAttribivARB failed\n");
331 return;
333 iAttribRet[1] += iAttribRet[2]+iAttribRet[3]+iAttribRet[4];
334 ok(iAttribRet[0] == iAttribRet[1], "WGL_COLOR_BITS_ARB (%d) does not equal R+G+B+A (%d)!\n",
335 iAttribRet[0], iAttribRet[1]);
338 static void test_gdi_dbuf(HDC hdc)
340 const int iAttribList[] = { WGL_SUPPORT_GDI_ARB, WGL_DOUBLE_BUFFER_ARB };
341 int iAttribRet[sizeof(iAttribList)/sizeof(iAttribList[0])];
342 unsigned int nFormats;
343 int iPixelFormat;
344 int res;
346 if (!pwglGetPixelFormatAttribivARB)
348 win_skip("wglGetPixelFormatAttribivARB is not available\n");
349 return;
352 nFormats = DescribePixelFormat(hdc, 0, 0, NULL);
353 for(iPixelFormat = 1;iPixelFormat <= nFormats;iPixelFormat++)
355 res = pwglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0,
356 sizeof(iAttribList)/sizeof(iAttribList[0]), iAttribList,
357 iAttribRet);
358 ok(res!=FALSE, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat);
359 if(res == FALSE)
360 continue;
362 ok(!(iAttribRet[0] && iAttribRet[1]), "GDI support and double buffering on pixel format %d\n", iPixelFormat);
366 static void test_make_current_read(HDC hdc)
368 int res;
369 HDC hread;
370 HGLRC hglrc = wglCreateContext(hdc);
372 if(!hglrc)
374 skip("wglCreateContext failed!\n");
375 return;
378 res = wglMakeCurrent(hdc, hglrc);
379 if(!res)
381 skip("wglMakeCurrent failed!\n");
382 return;
385 /* Test what wglGetCurrentReadDCARB does for wglMakeCurrent as the spec doesn't mention it */
386 hread = pwglGetCurrentReadDCARB();
387 trace("hread %p, hdc %p\n", hread, hdc);
388 ok(hread == hdc, "wglGetCurrentReadDCARB failed for standard wglMakeCurrent\n");
390 pwglMakeContextCurrentARB(hdc, hdc, hglrc);
391 hread = pwglGetCurrentReadDCARB();
392 ok(hread == hdc, "wglGetCurrentReadDCARB failed for wglMakeContextCurrent\n");
395 static void test_dc(HWND hwnd, HDC hdc)
397 int pf1, pf2;
398 HDC hdc2;
400 /* Get another DC and make sure it has the same pixel format */
401 hdc2 = GetDC(hwnd);
402 if(hdc != hdc2)
404 pf1 = GetPixelFormat(hdc);
405 pf2 = GetPixelFormat(hdc2);
406 ok(pf1 == pf2, "Second DC does not have the same format (%d != %d)\n", pf1, pf2);
408 else
409 skip("Could not get a different DC for the window\n");
411 if(hdc2)
413 ReleaseDC(hwnd, hdc2);
414 hdc2 = NULL;
418 static void test_opengl3(HDC hdc)
420 /* Try to create a context using an invalid OpenGL version namely 0.x */
422 HGLRC gl3Ctx;
423 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 0, 0};
425 gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
426 ok(gl3Ctx == 0, "wglCreateContextAttribs with major version=0 should fail!\n");
428 if(gl3Ctx)
429 wglDeleteContext(gl3Ctx);
432 /* Try to create a context compatible with OpenGL 1.x; 1.0-2.1 is allowed */
434 HGLRC gl3Ctx;
435 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 1, 0};
437 gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
438 ok(gl3Ctx != 0, "pwglCreateContextAttribsARB for a 1.x context failed!\n");
439 wglDeleteContext(gl3Ctx);
442 /* Try to pass an invalid HDC */
444 HGLRC gl3Ctx;
445 DWORD error;
446 gl3Ctx = pwglCreateContextAttribsARB((HDC)0xdeadbeef, 0, 0);
447 ok(gl3Ctx == 0, "pwglCreateContextAttribsARB using an invalid HDC passed\n");
448 error = GetLastError();
449 todo_wine ok(error == ERROR_DC_NOT_FOUND, "Expected ERROR_DC_NOT_FOUND, got error=%x\n", error);
450 wglDeleteContext(gl3Ctx);
453 /* Try to pass an invalid shareList */
455 HGLRC gl3Ctx;
456 DWORD error;
457 gl3Ctx = pwglCreateContextAttribsARB(hdc, (HGLRC)0xdeadbeef, 0);
458 ok(gl3Ctx == 0, "pwglCreateContextAttribsARB using an invalid shareList passed\n");
459 error = GetLastError();
460 todo_wine ok(error == ERROR_INVALID_OPERATION, "Expected ERROR_INVALID_OPERATION, got error=%x\n", error);
461 wglDeleteContext(gl3Ctx);
464 /* Try to create an OpenGL 3.0 context */
466 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0};
467 HGLRC gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
469 if(gl3Ctx == NULL)
471 skip("Skipping the rest of the WGL_ARB_create_context test due to lack of OpenGL 3.0\n");
472 return;
475 wglDeleteContext(gl3Ctx);
478 /* 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 */
480 HGLRC glCtx = wglCreateContext(hdc);
482 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0};
483 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};
485 HGLRC gl3Ctx = pwglCreateContextAttribsARB(hdc, glCtx, attribs);
486 ok(gl3Ctx != NULL, "Sharing of a display list between OpenGL 3.0 and OpenGL 1.x/2.x failed!\n");
487 if(gl3Ctx)
488 wglDeleteContext(gl3Ctx);
490 gl3Ctx = pwglCreateContextAttribsARB(hdc, glCtx, attribs_future);
491 ok(gl3Ctx != NULL, "Sharing of a display list between a forward compatible OpenGL 3.0 context and OpenGL 1.x/2.x failed!\n");
492 if(gl3Ctx)
493 wglDeleteContext(gl3Ctx);
495 if(glCtx)
496 wglDeleteContext(glCtx);
499 /* Try to create an OpenGL 3.0 context and test windowless rendering */
501 HGLRC gl3Ctx;
502 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0};
503 BOOL res;
505 gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
506 ok(gl3Ctx != 0, "pwglCreateContextAttribsARB for a 3.0 context failed!\n");
508 /* OpenGL 3.0 allows offscreen rendering WITHOUT a drawable */
509 /* NOTE: Nvidia's 177.89 beta drivers don't allow this yet */
510 res = wglMakeCurrent(0, gl3Ctx);
511 todo_wine ok(res == TRUE, "OpenGL 3.0 should allow windowless rendering, but the test failed!\n");
512 if(res)
513 wglMakeCurrent(0, 0);
515 if(gl3Ctx)
516 wglDeleteContext(gl3Ctx);
520 START_TEST(opengl)
522 HWND hwnd;
523 PIXELFORMATDESCRIPTOR pfd = {
524 sizeof(PIXELFORMATDESCRIPTOR),
525 1, /* version */
526 PFD_DRAW_TO_WINDOW |
527 PFD_SUPPORT_OPENGL |
528 PFD_DOUBLEBUFFER,
529 PFD_TYPE_RGBA,
530 24, /* 24-bit color depth */
531 0, 0, 0, 0, 0, 0, /* color bits */
532 0, /* alpha buffer */
533 0, /* shift bit */
534 0, /* accumulation buffer */
535 0, 0, 0, 0, /* accum bits */
536 32, /* z-buffer */
537 0, /* stencil buffer */
538 0, /* auxiliary buffer */
539 PFD_MAIN_PLANE, /* main layer */
540 0, /* reserved */
541 0, 0, 0 /* layer masks */
544 hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW,
545 10, 10, 200, 200, NULL, NULL, NULL, NULL);
546 ok(hwnd != NULL, "err: %d\n", GetLastError());
547 if (hwnd)
549 HDC hdc;
550 int iPixelFormat, res;
551 HGLRC hglrc;
552 DWORD error;
553 ShowWindow(hwnd, SW_SHOW);
555 hdc = GetDC(hwnd);
557 iPixelFormat = ChoosePixelFormat(hdc, &pfd);
558 if(iPixelFormat == 0)
560 /* This should never happen as ChoosePixelFormat always returns a closest match, but currently this fails in Wine if we don't have glX */
561 win_skip("Unable to find pixel format.\n");
562 goto cleanup;
565 /* We shouldn't be able to create a context from a hdc which doesn't have a pixel format set */
566 hglrc = wglCreateContext(hdc);
567 ok(hglrc == NULL, "wglCreateContext should fail when no pixel format has been set, but it passed\n");
568 error = GetLastError();
569 ok(error == ERROR_INVALID_PIXEL_FORMAT, "expected ERROR_INVALID_PIXEL_FORMAT for wglCreateContext without a pixelformat set, but received %#x\n", error);
571 res = SetPixelFormat(hdc, iPixelFormat, &pfd);
572 ok(res, "SetPixelformat failed: %x\n", GetLastError());
574 test_dc(hwnd, hdc);
576 hglrc = wglCreateContext(hdc);
577 res = wglMakeCurrent(hdc, hglrc);
578 ok(res, "wglMakeCurrent failed!\n");
579 if(res)
581 trace("OpenGL renderer: %s\n", glGetString(GL_RENDERER));
582 trace("OpenGL driver version: %s\n", glGetString(GL_VERSION));
583 trace("OpenGL vendor: %s\n", glGetString(GL_VENDOR));
585 else
587 skip("Skipping OpenGL tests without a current context\n");
588 return;
591 /* Initialisation of WGL functions depends on an implicit WGL context. For this reason we can't load them before making
592 * any WGL call :( On Wine this would work but not on real Windows because there can be different implementations (software, ICD, MCD).
594 init_functions();
595 /* The lack of wglGetExtensionsStringARB in general means broken software rendering or the lack of decent OpenGL support, skip tests in such cases */
596 if (!pwglGetExtensionsStringARB)
598 win_skip("wglGetExtensionsStringARB is not available\n");
599 return;
602 test_makecurrent(hdc);
603 test_setpixelformat(hdc);
604 test_colorbits(hdc);
605 test_gdi_dbuf(hdc);
607 wgl_extensions = pwglGetExtensionsStringARB(hdc);
608 if(wgl_extensions == NULL) skip("Skipping opengl32 tests because this OpenGL implementation doesn't support WGL extensions!\n");
610 if(strstr(wgl_extensions, "WGL_ARB_create_context"))
611 test_opengl3(hdc);
613 if(strstr(wgl_extensions, "WGL_ARB_make_current_read"))
614 test_make_current_read(hdc);
615 else
616 skip("WGL_ARB_make_current_read not supported, skipping test\n");
618 if(strstr(wgl_extensions, "WGL_ARB_pbuffer"))
619 test_pbuffers(hdc);
620 else
621 skip("WGL_ARB_pbuffer not supported, skipping pbuffer test\n");
623 cleanup:
624 ReleaseDC(hwnd, hdc);
625 DestroyWindow(hwnd);