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
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_pixel_format */
33 #define WGL_COLOR_BITS_ARB 0x2014
34 #define WGL_RED_BITS_ARB 0x2015
35 #define WGL_GREEN_BITS_ARB 0x2017
36 #define WGL_BLUE_BITS_ARB 0x2019
37 #define WGL_ALPHA_BITS_ARB 0x201B
38 #define WGL_SUPPORT_GDI_ARB 0x200F
39 #define WGL_DOUBLE_BUFFER_ARB 0x2011
41 static BOOL (WINAPI
*pwglChoosePixelFormatARB
)(HDC
, const int *, const FLOAT
*, UINT
, int *, UINT
*);
42 static BOOL (WINAPI
*pwglGetPixelFormatAttribivARB
)(HDC
, int, int, UINT
, const int *, int *);
45 #define WGL_DRAW_TO_PBUFFER_ARB 0x202D
46 static HPBUFFERARB
* (WINAPI
*pwglCreatePbufferARB
)(HDC
, int, int, int, const int *);
47 static HDC (WINAPI
*pwglGetPbufferDCARB
)(HPBUFFERARB
);
49 static const char* wgl_extensions
= NULL
;
51 static void init_functions(void)
53 #define GET_PROC(func) \
54 p ## func = (void*)wglGetProcAddress(#func); \
56 trace("wglGetProcAddress(%s) failed\n", #func);
58 /* WGL_ARB_extensions_string */
59 GET_PROC(wglGetExtensionsStringARB
)
61 /* WGL_ARB_pixel_format */
62 GET_PROC(wglChoosePixelFormatARB
)
63 GET_PROC(wglGetPixelFormatAttribivARB
)
66 GET_PROC(wglCreatePbufferARB
)
67 GET_PROC(wglGetPbufferDCARB
)
68 GET_PROC(wglReleasePbufferDCARB
)
73 static void test_pbuffers(HDC hdc
)
75 const int iAttribList
[] = { WGL_DRAW_TO_PBUFFER_ARB
, 1, /* Request pbuffer support */
77 int iFormats
[MAX_FORMATS
];
78 unsigned int nOnscreenFormats
;
79 unsigned int nFormats
;
83 nOnscreenFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
85 /* When you want to render to a pbuffer you need to call wglGetPbufferDCARB which
86 * returns a 'magic' HDC which you can then pass to wglMakeCurrent to switch rendering
87 * to the pbuffer. Below some tests are performed on what happens if you use standard WGL calls
88 * on this 'magic' HDC for both a pixelformat that support onscreen and offscreen rendering
89 * and a pixelformat that's only available for offscreen rendering (this means that only
90 * wglChoosePixelFormatARB and friends know about the format.
92 * The first thing we need are pixelformats with pbuffer capabilites.
94 res
= pwglChoosePixelFormatARB(hdc
, iAttribList
, NULL
, MAX_FORMATS
, iFormats
, &nFormats
);
97 skip("No pbuffer compatible formats found while WGL_ARB_pbuffer is supported\n");
100 trace("nOnscreenFormats: %d\n", nOnscreenFormats
);
101 trace("Total number of pbuffer capable pixelformats: %d\n", nFormats
);
103 /* Try to select an onscreen pixelformat out of the list */
104 for(i
=0; i
< nFormats
; i
++)
106 /* Check if the format is onscreen, if it is choose it */
107 if(iFormats
[i
] <= nOnscreenFormats
)
109 iPixelFormat
= iFormats
[i
];
110 trace("Selected iPixelFormat=%d\n", iPixelFormat
);
115 /* A video driver supports a large number of onscreen and offscreen pixelformats.
116 * The traditional WGL calls only see a subset of the whole pixelformat list. First
117 * of all they only see the onscreen formats (the offscreen formats are at the end of the
118 * pixelformat list) and second extended pixelformat capabilities are hidden from the
119 * standard WGL calls. Only functions that depend on WGL_ARB_pixel_format can see them.
121 * Below we check if the pixelformat is also supported onscreen.
123 if(iPixelFormat
!= 0)
126 HPBUFFERARB pbuffer
= pwglCreatePbufferARB(hdc
, iPixelFormat
, 640 /* width */, 480 /* height */, NULL
);
128 skip("Pbuffer creation failed!\n");
130 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
131 pbuffer_hdc
= pwglGetPbufferDCARB(pbuffer
);
132 res
= GetPixelFormat(pbuffer_hdc
);
133 ok(res
== iPixelFormat
, "Unexpected iPixelFormat=%d returned by GetPixelFormat for format %d\n", res
, iPixelFormat
);
134 trace("iPixelFormat returned by GetPixelFormat: %d\n", res
);
135 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat
);
137 pwglReleasePbufferDCARB(pbuffer
, hdc
);
139 else skip("Pbuffer test for onscreen pixelformat skipped as no onscreen format with pbuffer capabilities have been found\n");
141 /* Search for a real offscreen format */
142 for(i
=0, iPixelFormat
=0; i
<nFormats
; i
++)
144 if(iFormats
[i
] > nOnscreenFormats
)
146 iPixelFormat
= iFormats
[i
];
147 trace("Selected iPixelFormat: %d\n", iPixelFormat
);
152 if(iPixelFormat
!= 0)
155 HPBUFFERARB pbuffer
= pwglCreatePbufferARB(hdc
, iPixelFormat
, 640 /* width */, 480 /* height */, NULL
);
157 skip("Pbuffer creation failed!\n");
159 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
160 pbuffer_hdc
= pwglGetPbufferDCARB(pbuffer
);
161 res
= GetPixelFormat(pbuffer_hdc
);
163 ok(res
== 1, "Unexpected iPixelFormat=%d (1 expected) returned by GetPixelFormat for offscreen format %d\n", res
, iPixelFormat
);
164 trace("iPixelFormat returned by GetPixelFormat: %d\n", res
);
165 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat
);
166 pwglReleasePbufferDCARB(pbuffer
, hdc
);
168 else skip("Pbuffer test for offscreen pixelformat skipped as no offscreen-only format with pbuffer capabilities has been found\n");
171 static void test_setpixelformat(void)
175 PIXELFORMATDESCRIPTOR pfd
= {
176 sizeof(PIXELFORMATDESCRIPTOR
),
182 24, /* 24-bit color depth */
183 0, 0, 0, 0, 0, 0, /* color bits */
184 0, /* alpha buffer */
186 0, /* accumulation buffer */
187 0, 0, 0, 0, /* accum bits */
189 0, /* stencil buffer */
190 0, /* auxiliary buffer */
191 PFD_MAIN_PLANE
, /* main layer */
193 0, 0, 0 /* layer masks */
197 ok(hdc
!= 0, "GetDC(0) failed!\n");
199 /* This should pass even on the main device context */
200 pf
= ChoosePixelFormat(hdc
, &pfd
);
201 ok(pf
!= 0, "ChoosePixelFormat failed on main device context\n");
203 /* SetPixelFormat on the main device context 'X root window' should fail */
204 res
= SetPixelFormat(hdc
, pf
, &pfd
);
205 ok(res
== 0, "SetPixelFormat on main device context should fail\n");
208 static void test_colorbits(HDC hdc
)
210 const int iAttribList
[] = { WGL_COLOR_BITS_ARB
, WGL_RED_BITS_ARB
, WGL_GREEN_BITS_ARB
,
211 WGL_BLUE_BITS_ARB
, WGL_ALPHA_BITS_ARB
};
212 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
213 const int iAttribs
[] = { WGL_ALPHA_BITS_ARB
, 1, 0 };
214 unsigned int nFormats
;
216 int iPixelFormat
= 0;
218 /* We need a pixel format with at least one bit of alpha */
219 res
= pwglChoosePixelFormatARB(hdc
, iAttribs
, NULL
, 1, &iPixelFormat
, &nFormats
);
220 if(res
== FALSE
|| nFormats
== 0)
222 skip("No suitable pixel formats found\n");
226 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
227 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
, iAttribRet
);
230 skip("wglGetPixelFormatAttribivARB failed\n");
233 iAttribRet
[1] += iAttribRet
[2]+iAttribRet
[3]+iAttribRet
[4];
234 ok(iAttribRet
[0] == iAttribRet
[1], "WGL_COLOR_BITS_ARB (%d) does not equal R+G+B+A (%d)!\n",
235 iAttribRet
[0], iAttribRet
[1]);
238 static void test_gdi_dbuf(HDC hdc
)
240 const int iAttribList
[] = { WGL_SUPPORT_GDI_ARB
, WGL_DOUBLE_BUFFER_ARB
};
241 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
242 unsigned int nFormats
;
246 nFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
247 for(iPixelFormat
= 1;iPixelFormat
<= nFormats
;iPixelFormat
++)
249 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
250 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
,
252 ok(res
!=FALSE
, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat
);
256 ok(!(iAttribRet
[0] && iAttribRet
[1]), "GDI support and double buffering on pixel format %d\n", iPixelFormat
);
263 PIXELFORMATDESCRIPTOR pfd
= {
264 sizeof(PIXELFORMATDESCRIPTOR
),
270 24, /* 24-bit color depth */
271 0, 0, 0, 0, 0, 0, /* color bits */
272 0, /* alpha buffer */
274 0, /* accumulation buffer */
275 0, 0, 0, 0, /* accum bits */
277 0, /* stencil buffer */
278 0, /* auxiliary buffer */
279 PFD_MAIN_PLANE
, /* main layer */
281 0, 0, 0 /* layer masks */
284 hwnd
= CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW
,
285 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
286 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
290 int iPixelFormat
, res
;
292 ShowWindow(hwnd
, SW_SHOW
);
296 iPixelFormat
= ChoosePixelFormat(hdc
, &pfd
);
297 ok(iPixelFormat
> 0, "No pixelformat found!\n"); /* This should never happen as ChoosePixelFormat always returns a closest match */
299 res
= SetPixelFormat(hdc
, iPixelFormat
, &pfd
);
300 ok(res
, "SetPixelformat failed: %x\n", GetLastError());
302 hglrc
= wglCreateContext(hdc
);
303 res
= wglMakeCurrent(hdc
, hglrc
);
304 ok(res
, "wglMakeCurrent failed!\n");
307 test_setpixelformat();
311 wgl_extensions
= pwglGetExtensionsStringARB(hdc
);
312 if(wgl_extensions
== NULL
) skip("Skipping opengl32 tests because this OpenGL implementation doesn't support WGL extensions!\n");
314 if(strstr(wgl_extensions
, "WGL_ARB_pbuffer"))
317 trace("WGL_ARB_pbuffer not supported, skipping pbuffer test\n");