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 /* WGL_ARB_extensions_string */
54 pwglGetExtensionsStringARB
= (void*)wglGetProcAddress("wglGetExtensionsStringARB");
56 /* WGL_ARB_pixel_format */
57 pwglChoosePixelFormatARB
= (void*)wglGetProcAddress("wglChoosePixelFormatARB");
58 pwglGetPixelFormatAttribivARB
= (void*)wglGetProcAddress("wglGetPixelFormatAttribivARB");
61 pwglCreatePbufferARB
= (void*)wglGetProcAddress("wglCreatePbufferARB");
62 pwglGetPbufferDCARB
= (void*)wglGetProcAddress("wglGetPbufferDCARB");
63 pwglReleasePbufferDCARB
= (void*)wglGetProcAddress("wglReleasePbufferDCARB");
66 static void test_pbuffers(HDC hdc
)
68 const int iAttribList
[] = { WGL_DRAW_TO_PBUFFER_ARB
, 1, /* Request pbuffer support */
70 int iFormats
[MAX_FORMATS
];
71 unsigned int nOnscreenFormats
;
72 unsigned int nFormats
;
76 nOnscreenFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
78 /* When you want to render to a pbuffer you need to call wglGetPbufferDCARB which
79 * returns a 'magic' HDC which you can then pass to wglMakeCurrent to switch rendering
80 * to the pbuffer. Below some tests are performed on what happens if you use standard WGL calls
81 * on this 'magic' HDC for both a pixelformat that support onscreen and offscreen rendering
82 * and a pixelformat that's only available for offscreen rendering (this means that only
83 * wglChoosePixelFormatARB and friends know about the format.
85 * The first thing we need are pixelformats with pbuffer capabilites.
87 res
= pwglChoosePixelFormatARB(hdc
, iAttribList
, NULL
, MAX_FORMATS
, iFormats
, &nFormats
);
90 skip("No pbuffer compatible formats found while WGL_ARB_pbuffer is supported\n");
93 trace("nOnscreenFormats: %d\n", nOnscreenFormats
);
94 trace("Total number of pbuffer capable pixelformats: %d\n", nFormats
);
96 /* Try to select an onscreen pixelformat out of the list */
97 for(i
=0; i
< nFormats
; i
++)
99 /* Check if the format is onscreen, if it is choose it */
100 if(iFormats
[i
] <= nOnscreenFormats
)
102 iPixelFormat
= iFormats
[i
];
103 trace("Selected iPixelFormat=%d\n", iPixelFormat
);
108 /* A video driver supports a large number of onscreen and offscreen pixelformats.
109 * The traditional WGL calls only see a subset of the whole pixelformat list. First
110 * of all they only see the onscreen formats (the offscreen formats are at the end of the
111 * pixelformat list) and second extended pixelformat capabilities are hidden from the
112 * standard WGL calls. Only functions that depend on WGL_ARB_pixel_format can see them.
114 * Below we check if the pixelformat is also supported onscreen.
116 if(iPixelFormat
!= 0)
119 HPBUFFERARB pbuffer
= pwglCreatePbufferARB(hdc
, iPixelFormat
, 640 /* width */, 480 /* height */, NULL
);
121 skip("Pbuffer creation failed!\n");
123 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
124 pbuffer_hdc
= pwglGetPbufferDCARB(pbuffer
);
125 res
= GetPixelFormat(pbuffer_hdc
);
126 ok(res
== iPixelFormat
, "Unexpected iPixelFormat=%d returned by GetPixelFormat for format %d\n", res
, iPixelFormat
);
127 trace("iPixelFormat returned by GetPixelFormat: %d\n", res
);
128 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat
);
130 pwglReleasePbufferDCARB(pbuffer
, hdc
);
132 else skip("Pbuffer test for onscreen pixelformat skipped as no onscreen format with pbuffer capabilities have been found\n");
134 /* Search for a real offscreen format */
135 for(i
=0, iPixelFormat
=0; i
<nFormats
; i
++)
137 if(iFormats
[i
] > nOnscreenFormats
)
139 iPixelFormat
= iFormats
[i
];
140 trace("Selected iPixelFormat: %d\n", iPixelFormat
);
145 if(iPixelFormat
!= 0)
148 HPBUFFERARB pbuffer
= pwglCreatePbufferARB(hdc
, iPixelFormat
, 640 /* width */, 480 /* height */, NULL
);
150 skip("Pbuffer creation failed!\n");
152 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
153 pbuffer_hdc
= pwglGetPbufferDCARB(pbuffer
);
154 res
= GetPixelFormat(pbuffer_hdc
);
156 ok(res
== 1, "Unexpected iPixelFormat=%d (1 expected) returned by GetPixelFormat for offscreen format %d\n", res
, iPixelFormat
);
157 trace("iPixelFormat returned by GetPixelFormat: %d\n", res
);
158 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat
);
159 pwglReleasePbufferDCARB(pbuffer
, hdc
);
161 else skip("Pbuffer test for offscreen pixelformat skipped as no offscreen-only format with pbuffer capabilities has been found\n");
164 static void test_setpixelformat(void)
168 PIXELFORMATDESCRIPTOR pfd
= {
169 sizeof(PIXELFORMATDESCRIPTOR
),
175 24, /* 24-bit color depth */
176 0, 0, 0, 0, 0, 0, /* color bits */
177 0, /* alpha buffer */
179 0, /* accumulation buffer */
180 0, 0, 0, 0, /* accum bits */
182 0, /* stencil buffer */
183 0, /* auxiliary buffer */
184 PFD_MAIN_PLANE
, /* main layer */
186 0, 0, 0 /* layer masks */
190 ok(hdc
!= 0, "GetDC(0) failed!\n");
192 /* This should pass even on the main device context */
193 pf
= ChoosePixelFormat(hdc
, &pfd
);
194 ok(pf
!= 0, "ChoosePixelFormat failed on main device context\n");
196 /* SetPixelFormat on the main device context 'X root window' should fail */
197 res
= SetPixelFormat(hdc
, pf
, &pfd
);
198 ok(res
== 0, "SetPixelFormat on main device context should fail\n");
201 static void test_colorbits(HDC hdc
)
203 const int iAttribList
[] = { WGL_COLOR_BITS_ARB
, WGL_RED_BITS_ARB
, WGL_GREEN_BITS_ARB
,
204 WGL_BLUE_BITS_ARB
, WGL_ALPHA_BITS_ARB
};
205 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
206 const int iAttribs
[] = { WGL_ALPHA_BITS_ARB
, 1, 0 };
207 unsigned int nFormats
;
209 int iPixelFormat
= 0;
211 /* We need a pixel format with at least one bit of alpha */
212 res
= pwglChoosePixelFormatARB(hdc
, iAttribs
, NULL
, 1, &iPixelFormat
, &nFormats
);
213 if(res
== FALSE
|| nFormats
== 0)
215 skip("No suitable pixel formats found\n");
219 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
220 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
, iAttribRet
);
223 skip("wglGetPixelFormatAttribivARB failed\n");
226 iAttribRet
[1] += iAttribRet
[2]+iAttribRet
[3]+iAttribRet
[4];
227 ok(iAttribRet
[0] == iAttribRet
[1], "WGL_COLOR_BITS_ARB (%d) does not equal R+G+B+A (%d)!\n",
228 iAttribRet
[0], iAttribRet
[1]);
231 static void test_gdi_dbuf(HDC hdc
)
233 const int iAttribList
[] = { WGL_SUPPORT_GDI_ARB
, WGL_DOUBLE_BUFFER_ARB
};
234 int iAttribRet
[sizeof(iAttribList
)/sizeof(iAttribList
[0])];
235 unsigned int nFormats
;
239 nFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
240 for(iPixelFormat
= 1;iPixelFormat
<= nFormats
;iPixelFormat
++)
242 res
= pwglGetPixelFormatAttribivARB(hdc
, iPixelFormat
, 0,
243 sizeof(iAttribList
)/sizeof(iAttribList
[0]), iAttribList
,
245 ok(res
!=FALSE
, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat
);
249 ok(!(iAttribRet
[0] && iAttribRet
[1]), "GDI support and double buffering on pixel format %d\n", iPixelFormat
);
256 PIXELFORMATDESCRIPTOR pfd
= {
257 sizeof(PIXELFORMATDESCRIPTOR
),
263 24, /* 24-bit color depth */
264 0, 0, 0, 0, 0, 0, /* color bits */
265 0, /* alpha buffer */
267 0, /* accumulation buffer */
268 0, 0, 0, 0, /* accum bits */
270 0, /* stencil buffer */
271 0, /* auxiliary buffer */
272 PFD_MAIN_PLANE
, /* main layer */
274 0, 0, 0 /* layer masks */
277 hwnd
= CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW
,
278 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
279 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
283 int iPixelFormat
, res
;
285 ShowWindow(hwnd
, SW_SHOW
);
289 iPixelFormat
= ChoosePixelFormat(hdc
, &pfd
);
290 ok(iPixelFormat
> 0, "No pixelformat found!\n"); /* This should never happen as ChoosePixelFormat always returns a closest match */
292 res
= SetPixelFormat(hdc
, iPixelFormat
, &pfd
);
293 ok(res
, "SetPixelformat failed: %x\n", GetLastError());
295 hglrc
= wglCreateContext(hdc
);
296 res
= wglMakeCurrent(hdc
, hglrc
);
297 ok(res
, "wglMakeCurrent failed!\n");
300 test_setpixelformat();
304 wgl_extensions
= pwglGetExtensionsStringARB(hdc
);
305 if(wgl_extensions
== NULL
) skip("Skipping opengl32 tests because this OpenGL implementation doesn't support WGL extensions!\n");
307 if(strstr(wgl_extensions
, "WGL_ARB_pbuffer"))
310 trace("WGL_ARB_pbuffer not supported, skipping pbuffer test\n");