wininet: Fix a number of problems with InternetGetCookie.
[wine.git] / dlls / opengl32 / tests / opengl.c
blobc244bb804fd2e9557cc8b8f2758e42de53c70103
1 /*
2 * Some tests for OpenGL functions
4 * Copyright (C) 2007 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 #define MAX_FORMATS 256
26 typedef void* HPBUFFERARB;
28 /* WGL_ARB_extensions_string */
29 static const char* (WINAPI *pwglGetExtensionsStringARB)(HDC);
30 static int (WINAPI *pwglReleasePbufferDCARB)(HPBUFFERARB, HDC);
32 /* WGL_ARB_make_current_read */
33 static BOOL (WINAPI *pwglMakeContextCurrentARB)(HDC hdraw, HDC hread, HGLRC hglrc);
34 static HDC (WINAPI *pwglGetCurrentReadDCARB)();
36 /* WGL_ARB_pixel_format */
37 #define WGL_COLOR_BITS_ARB 0x2014
38 #define WGL_RED_BITS_ARB 0x2015
39 #define WGL_GREEN_BITS_ARB 0x2017
40 #define WGL_BLUE_BITS_ARB 0x2019
41 #define WGL_ALPHA_BITS_ARB 0x201B
42 #define WGL_SUPPORT_GDI_ARB 0x200F
43 #define WGL_DOUBLE_BUFFER_ARB 0x2011
45 static BOOL (WINAPI *pwglChoosePixelFormatARB)(HDC, const int *, const FLOAT *, UINT, int *, UINT *);
46 static BOOL (WINAPI *pwglGetPixelFormatAttribivARB)(HDC, int, int, UINT, const int *, int *);
48 /* WGL_ARB_pbuffer */
49 #define WGL_DRAW_TO_PBUFFER_ARB 0x202D
50 static HPBUFFERARB* (WINAPI *pwglCreatePbufferARB)(HDC, int, int, int, const int *);
51 static HDC (WINAPI *pwglGetPbufferDCARB)(HPBUFFERARB);
53 static const char* wgl_extensions = NULL;
55 static void init_functions(void)
57 #define GET_PROC(func) \
58 p ## func = (void*)wglGetProcAddress(#func); \
59 if(!p ## func) \
60 trace("wglGetProcAddress(%s) failed\n", #func);
62 /* WGL_ARB_extensions_string */
63 GET_PROC(wglGetExtensionsStringARB)
65 /* WGL_ARB_make_current_read */
66 GET_PROC(wglMakeContextCurrentARB);
67 GET_PROC(wglGetCurrentReadDCARB);
69 /* WGL_ARB_pixel_format */
70 GET_PROC(wglChoosePixelFormatARB)
71 GET_PROC(wglGetPixelFormatAttribivARB)
73 /* WGL_ARB_pbuffer */
74 GET_PROC(wglCreatePbufferARB)
75 GET_PROC(wglGetPbufferDCARB)
76 GET_PROC(wglReleasePbufferDCARB)
78 #undef GET_PROC
81 static void test_pbuffers(HDC hdc)
83 const int iAttribList[] = { WGL_DRAW_TO_PBUFFER_ARB, 1, /* Request pbuffer support */
84 0 };
85 int iFormats[MAX_FORMATS];
86 unsigned int nOnscreenFormats;
87 unsigned int nFormats;
88 int i, res;
89 int iPixelFormat = 0;
91 nOnscreenFormats = DescribePixelFormat(hdc, 0, 0, NULL);
93 /* When you want to render to a pbuffer you need to call wglGetPbufferDCARB which
94 * returns a 'magic' HDC which you can then pass to wglMakeCurrent to switch rendering
95 * to the pbuffer. Below some tests are performed on what happens if you use standard WGL calls
96 * on this 'magic' HDC for both a pixelformat that support onscreen and offscreen rendering
97 * and a pixelformat that's only available for offscreen rendering (this means that only
98 * wglChoosePixelFormatARB and friends know about the format.
100 * The first thing we need are pixelformats with pbuffer capabilites.
102 res = pwglChoosePixelFormatARB(hdc, iAttribList, NULL, MAX_FORMATS, iFormats, &nFormats);
103 if(res <= 0)
105 skip("No pbuffer compatible formats found while WGL_ARB_pbuffer is supported\n");
106 return;
108 trace("nOnscreenFormats: %d\n", nOnscreenFormats);
109 trace("Total number of pbuffer capable pixelformats: %d\n", nFormats);
111 /* Try to select an onscreen pixelformat out of the list */
112 for(i=0; i < nFormats; i++)
114 /* Check if the format is onscreen, if it is choose it */
115 if(iFormats[i] <= nOnscreenFormats)
117 iPixelFormat = iFormats[i];
118 trace("Selected iPixelFormat=%d\n", iPixelFormat);
119 break;
123 /* A video driver supports a large number of onscreen and offscreen pixelformats.
124 * The traditional WGL calls only see a subset of the whole pixelformat list. First
125 * of all they only see the onscreen formats (the offscreen formats are at the end of the
126 * pixelformat list) and second extended pixelformat capabilities are hidden from the
127 * standard WGL calls. Only functions that depend on WGL_ARB_pixel_format can see them.
129 * Below we check if the pixelformat is also supported onscreen.
131 if(iPixelFormat != 0)
133 HDC pbuffer_hdc;
134 HPBUFFERARB pbuffer = pwglCreatePbufferARB(hdc, iPixelFormat, 640 /* width */, 480 /* height */, NULL);
135 if(!pbuffer)
136 skip("Pbuffer creation failed!\n");
138 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
139 pbuffer_hdc = pwglGetPbufferDCARB(pbuffer);
140 res = GetPixelFormat(pbuffer_hdc);
141 ok(res == iPixelFormat, "Unexpected iPixelFormat=%d returned by GetPixelFormat for format %d\n", res, iPixelFormat);
142 trace("iPixelFormat returned by GetPixelFormat: %d\n", res);
143 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat);
145 pwglReleasePbufferDCARB(pbuffer, hdc);
147 else skip("Pbuffer test for onscreen pixelformat skipped as no onscreen format with pbuffer capabilities have been found\n");
149 /* Search for a real offscreen format */
150 for(i=0, iPixelFormat=0; i<nFormats; i++)
152 if(iFormats[i] > nOnscreenFormats)
154 iPixelFormat = iFormats[i];
155 trace("Selected iPixelFormat: %d\n", iPixelFormat);
156 break;
160 if(iPixelFormat != 0)
162 HDC pbuffer_hdc;
163 HPBUFFERARB pbuffer = pwglCreatePbufferARB(hdc, iPixelFormat, 640 /* width */, 480 /* height */, NULL);
164 if(!pbuffer)
165 skip("Pbuffer creation failed!\n");
167 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
168 pbuffer_hdc = pwglGetPbufferDCARB(pbuffer);
169 res = GetPixelFormat(pbuffer_hdc);
171 ok(res == 1, "Unexpected iPixelFormat=%d (1 expected) returned by GetPixelFormat for offscreen format %d\n", res, iPixelFormat);
172 trace("iPixelFormat returned by GetPixelFormat: %d\n", res);
173 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat);
174 pwglReleasePbufferDCARB(pbuffer, hdc);
176 else skip("Pbuffer test for offscreen pixelformat skipped as no offscreen-only format with pbuffer capabilities has been found\n");
179 static void test_setpixelformat(HDC winhdc)
181 int res = 0;
182 int nCfgs;
183 int pf;
184 int i;
185 PIXELFORMATDESCRIPTOR pfd = {
186 sizeof(PIXELFORMATDESCRIPTOR),
187 1, /* version */
188 PFD_DRAW_TO_WINDOW |
189 PFD_SUPPORT_OPENGL |
190 PFD_DOUBLEBUFFER,
191 PFD_TYPE_RGBA,
192 24, /* 24-bit color depth */
193 0, 0, 0, 0, 0, 0, /* color bits */
194 0, /* alpha buffer */
195 0, /* shift bit */
196 0, /* accumulation buffer */
197 0, 0, 0, 0, /* accum bits */
198 32, /* z-buffer */
199 0, /* stencil buffer */
200 0, /* auxiliary buffer */
201 PFD_MAIN_PLANE, /* main layer */
202 0, /* reserved */
203 0, 0, 0 /* layer masks */
206 HDC hdc = GetDC(0);
207 ok(hdc != 0, "GetDC(0) failed!\n");
209 /* This should pass even on the main device context */
210 pf = ChoosePixelFormat(hdc, &pfd);
211 ok(pf != 0, "ChoosePixelFormat failed on main device context\n");
213 /* SetPixelFormat on the main device context 'X root window' should fail */
214 res = SetPixelFormat(hdc, pf, &pfd);
215 ok(res == 0, "SetPixelFormat on main device context should fail\n");
217 /* Setting the same format that was set on the HDC is allowed; other
218 formats fail */
219 nCfgs = DescribePixelFormat(winhdc, 0, 0, NULL);
220 pf = GetPixelFormat(winhdc);
221 for(i = 1;i <= nCfgs;i++)
223 int res = SetPixelFormat(winhdc, i, NULL);
224 if(i == pf) ok(res, "Failed to set the same pixel format\n");
225 else ok(!res, "Unexpectedly set an alternate pixel format\n");
229 static void test_colorbits(HDC hdc)
231 const int iAttribList[] = { WGL_COLOR_BITS_ARB, WGL_RED_BITS_ARB, WGL_GREEN_BITS_ARB,
232 WGL_BLUE_BITS_ARB, WGL_ALPHA_BITS_ARB };
233 int iAttribRet[sizeof(iAttribList)/sizeof(iAttribList[0])];
234 const int iAttribs[] = { WGL_ALPHA_BITS_ARB, 1, 0 };
235 unsigned int nFormats;
236 int res;
237 int iPixelFormat = 0;
239 /* We need a pixel format with at least one bit of alpha */
240 res = pwglChoosePixelFormatARB(hdc, iAttribs, NULL, 1, &iPixelFormat, &nFormats);
241 if(res == FALSE || nFormats == 0)
243 skip("No suitable pixel formats found\n");
244 return;
247 res = pwglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0,
248 sizeof(iAttribList)/sizeof(iAttribList[0]), iAttribList, iAttribRet);
249 if(res == FALSE)
251 skip("wglGetPixelFormatAttribivARB failed\n");
252 return;
254 iAttribRet[1] += iAttribRet[2]+iAttribRet[3]+iAttribRet[4];
255 ok(iAttribRet[0] == iAttribRet[1], "WGL_COLOR_BITS_ARB (%d) does not equal R+G+B+A (%d)!\n",
256 iAttribRet[0], iAttribRet[1]);
259 static void test_gdi_dbuf(HDC hdc)
261 const int iAttribList[] = { WGL_SUPPORT_GDI_ARB, WGL_DOUBLE_BUFFER_ARB };
262 int iAttribRet[sizeof(iAttribList)/sizeof(iAttribList[0])];
263 unsigned int nFormats;
264 int iPixelFormat;
265 int res;
267 nFormats = DescribePixelFormat(hdc, 0, 0, NULL);
268 for(iPixelFormat = 1;iPixelFormat <= nFormats;iPixelFormat++)
270 res = pwglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0,
271 sizeof(iAttribList)/sizeof(iAttribList[0]), iAttribList,
272 iAttribRet);
273 ok(res!=FALSE, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat);
274 if(res == FALSE)
275 continue;
277 ok(!(iAttribRet[0] && iAttribRet[1]), "GDI support and double buffering on pixel format %d\n", iPixelFormat);
281 static void test_make_current_read(HDC hdc)
283 int res;
284 HDC hread;
285 HGLRC hglrc = wglCreateContext(hdc);
287 if(!hglrc)
289 skip("wglCreateContext failed!\n");
290 return;
293 res = wglMakeCurrent(hdc, hglrc);
294 if(!res)
296 skip("wglMakeCurrent failed!\n");
297 return;
300 /* Test what wglGetCurrentReadDCARB does for wglMakeCurrent as the spec doesn't mention it */
301 hread = pwglGetCurrentReadDCARB();
302 trace("hread %p, hdc %p\n", hread, hdc);
303 ok(hread == hdc, "wglGetCurrentReadDCARB failed for standard wglMakeCurrent\n");
305 pwglMakeContextCurrentARB(hdc, hdc, hglrc);
306 hread = pwglGetCurrentReadDCARB();
307 ok(hread == hdc, "wglGetCurrentReadDCARB failed for wglMakeContextCurrent\n");
310 static void test_dc(HWND hwnd, HDC hdc)
312 int pf1, pf2;
313 HDC hdc2;
315 /* Get another DC and make sure it has the same pixel format */
316 hdc2 = GetDC(hwnd);
317 if(hdc != hdc2)
319 pf1 = GetPixelFormat(hdc);
320 pf2 = GetPixelFormat(hdc2);
321 ok(pf1 == pf2, "Second DC does not have the same format (%d != %d)\n", pf1, pf2);
323 else
324 skip("Could not get a different DC for the window\n");
326 if(hdc2)
328 ReleaseDC(hwnd, hdc2);
329 hdc2 = NULL;
333 START_TEST(opengl)
335 HWND hwnd;
336 PIXELFORMATDESCRIPTOR pfd = {
337 sizeof(PIXELFORMATDESCRIPTOR),
338 1, /* version */
339 PFD_DRAW_TO_WINDOW |
340 PFD_SUPPORT_OPENGL |
341 PFD_DOUBLEBUFFER,
342 PFD_TYPE_RGBA,
343 24, /* 24-bit color depth */
344 0, 0, 0, 0, 0, 0, /* color bits */
345 0, /* alpha buffer */
346 0, /* shift bit */
347 0, /* accumulation buffer */
348 0, 0, 0, 0, /* accum bits */
349 32, /* z-buffer */
350 0, /* stencil buffer */
351 0, /* auxiliary buffer */
352 PFD_MAIN_PLANE, /* main layer */
353 0, /* reserved */
354 0, 0, 0 /* layer masks */
357 hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW,
358 10, 10, 200, 200, NULL, NULL, NULL, NULL);
359 ok(hwnd != NULL, "err: %d\n", GetLastError());
360 if (hwnd)
362 HDC hdc;
363 int iPixelFormat, res;
364 HGLRC hglrc;
365 ShowWindow(hwnd, SW_SHOW);
367 hdc = GetDC(hwnd);
369 iPixelFormat = ChoosePixelFormat(hdc, &pfd);
370 ok(iPixelFormat > 0, "No pixelformat found!\n"); /* This should never happen as ChoosePixelFormat always returns a closest match */
372 res = SetPixelFormat(hdc, iPixelFormat, &pfd);
373 ok(res, "SetPixelformat failed: %x\n", GetLastError());
375 test_dc(hwnd, hdc);
377 hglrc = wglCreateContext(hdc);
378 res = wglMakeCurrent(hdc, hglrc);
379 ok(res, "wglMakeCurrent failed!\n");
380 init_functions();
382 test_setpixelformat(hdc);
383 test_colorbits(hdc);
384 test_gdi_dbuf(hdc);
386 wgl_extensions = pwglGetExtensionsStringARB(hdc);
387 if(wgl_extensions == NULL) skip("Skipping opengl32 tests because this OpenGL implementation doesn't support WGL extensions!\n");
389 if(strstr(wgl_extensions, "WGL_ARB_make_current_read"))
390 test_make_current_read(hdc);
391 else
392 trace("WGL_ARB_make_current_read not supported, skipping test\n");
394 if(strstr(wgl_extensions, "WGL_ARB_pbuffer"))
395 test_pbuffers(hdc);
396 else
397 trace("WGL_ARB_pbuffer not supported, skipping pbuffer test\n");
399 DestroyWindow(hwnd);