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 static BOOL (WINAPI
*pwglChoosePixelFormatARB
)(HDC
, const int *, const FLOAT
*, UINT
, int *, UINT
*);
36 #define WGL_DRAW_TO_PBUFFER_ARB 0x202D
37 static HPBUFFERARB
* (WINAPI
*pwglCreatePbufferARB
)(HDC
, int, int, int, const int *);
38 static HDC (WINAPI
*pwglGetPbufferDCARB
)(HPBUFFERARB
);
40 static const char* wgl_extensions
= NULL
;
42 static void init_functions(void)
44 /* WGL_ARB_extensions_string */
45 pwglGetExtensionsStringARB
= (void*)wglGetProcAddress("wglGetExtensionsStringARB");
47 /* WGL_ARB_pixel_format */
48 pwglChoosePixelFormatARB
= (void*)wglGetProcAddress("wglChoosePixelFormatARB");
51 pwglCreatePbufferARB
= (void*)wglGetProcAddress("wglCreatePbufferARB");
52 pwglGetPbufferDCARB
= (void*)wglGetProcAddress("wglGetPbufferDCARB");
53 pwglReleasePbufferDCARB
= (void*)wglGetProcAddress("wglReleasePbufferDCARB");
56 static void test_pbuffers(HDC hdc
)
58 const int iAttribList
[] = { WGL_DRAW_TO_PBUFFER_ARB
, 1, /* Request pbuffer support */
60 int iFormats
[MAX_FORMATS
];
61 unsigned int nOnscreenFormats
;
62 unsigned int nFormats
;
66 nOnscreenFormats
= DescribePixelFormat(hdc
, 0, 0, NULL
);
68 /* When you want to render to a pbuffer you need to call wglGetPbufferDCARB which
69 * returns a 'magic' HDC which you can then pass to wglMakeCurrent to switch rendering
70 * to the pbuffer. Below some tests are performed on what happens if you use standard WGL calls
71 * on this 'magic' HDC for both a pixelformat that support onscreen and offscreen rendering
72 * and a pixelformat that's only available for offscreen rendering (this means that only
73 * wglChoosePixelFormatARB and friends know about the format.
75 * The first thing we need are pixelformats with pbuffer capabilites.
77 res
= pwglChoosePixelFormatARB(hdc
, iAttribList
, NULL
, MAX_FORMATS
, iFormats
, &nFormats
);
80 skip("No pbuffer compatible formats found while WGL_ARB_pbuffer is supported\n");
83 trace("nOnscreenFormats: %d\n", nOnscreenFormats
);
84 trace("Total number of pbuffer capable pixelformats: %d\n", nFormats
);
86 /* Try to select an onscreen pixelformat out of the list */
87 for(i
=0; i
< nFormats
; i
++)
89 /* Check if the format is onscreen, if it is choose it */
90 if(iFormats
[i
] <= nOnscreenFormats
)
92 iPixelFormat
= iFormats
[i
];
93 trace("Selected iPixelFormat=%d\n", iPixelFormat
);
98 /* A video driver supports a large number of onscreen and offscreen pixelformats.
99 * The traditional WGL calls only see a subset of the whole pixelformat list. First
100 * of all they only see the onscreen formats (the offscreen formats are at the end of the
101 * pixelformat list) and second extended pixelformat capabilities are hidden from the
102 * standard WGL calls. Only functions that depend on WGL_ARB_pixel_format can see them.
104 * Below we check if the pixelformat is also supported onscreen.
106 if(iPixelFormat
!= 0)
109 HPBUFFERARB pbuffer
= pwglCreatePbufferARB(hdc
, iPixelFormat
, 640 /* width */, 480 /* height */, NULL
);
111 skip("Pbuffer creation failed!\n");
113 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
114 pbuffer_hdc
= pwglGetPbufferDCARB(pbuffer
);
115 res
= GetPixelFormat(pbuffer_hdc
);
116 ok(res
== iPixelFormat
, "Unexpected iPixelFormat=%d returned by GetPixelFormat for format %d\n", res
, iPixelFormat
);
117 trace("iPixelFormat returned by GetPixelFormat: %d\n", res
);
118 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat
);
120 pwglReleasePbufferDCARB(pbuffer
, hdc
);
122 else skip("Pbuffer test for onscreen pixelformat skipped as no onscreen format with pbuffer capabilities have been found\n");
124 /* Search for a real offscreen format */
125 for(i
=0, iPixelFormat
=0; i
<nFormats
; i
++)
127 if(iFormats
[i
] > nOnscreenFormats
)
129 iPixelFormat
= iFormats
[i
];
130 trace("Selected iPixelFormat: %d\n", iPixelFormat
);
135 if(iPixelFormat
!= 0)
138 HPBUFFERARB pbuffer
= pwglCreatePbufferARB(hdc
, iPixelFormat
, 640 /* width */, 480 /* height */, NULL
);
140 skip("Pbuffer creation failed!\n");
142 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
143 pbuffer_hdc
= pwglGetPbufferDCARB(pbuffer
);
144 res
= GetPixelFormat(pbuffer_hdc
);
146 ok(res
== 1, "Unexpected iPixelFormat=%d (1 expected) returned by GetPixelFormat for offscreen format %d\n", res
, iPixelFormat
);
147 trace("iPixelFormat returned by GetPixelFormat: %d\n", res
);
148 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat
);
149 pwglReleasePbufferDCARB(pbuffer
, hdc
);
151 else skip("Pbuffer test for offscreen pixelformat skipped as no offscreen-only format with pbuffer capabilities has been found\n");
154 static void test_setpixelformat(void)
158 PIXELFORMATDESCRIPTOR pfd
= {
159 sizeof(PIXELFORMATDESCRIPTOR
),
165 24, /* 24-bit color depth */
166 0, 0, 0, 0, 0, 0, /* color bits */
167 0, /* alpha buffer */
169 0, /* accumulation buffer */
170 0, 0, 0, 0, /* accum bits */
172 0, /* stencil buffer */
173 0, /* auxiliary buffer */
174 PFD_MAIN_PLANE
, /* main layer */
176 0, 0, 0 /* layer masks */
180 ok(hdc
!= 0, "GetDC(0) failed!\n");
182 /* This should pass even on the main device context */
183 pf
= ChoosePixelFormat(hdc
, &pfd
);
184 ok(pf
!= 0, "ChoosePixelFormat failed on main device context");
186 /* SetPixelFormat on the main device context 'X root window' should fail */
187 res
= SetPixelFormat(hdc
, pf
, &pfd
);
188 ok(res
== 0, "SetPixelFormat on main device context should fail\n");
194 PIXELFORMATDESCRIPTOR pfd
= {
195 sizeof(PIXELFORMATDESCRIPTOR
),
201 24, /* 24-bit color depth */
202 0, 0, 0, 0, 0, 0, /* color bits */
203 0, /* alpha buffer */
205 0, /* accumulation buffer */
206 0, 0, 0, 0, /* accum bits */
208 0, /* stencil buffer */
209 0, /* auxiliary buffer */
210 PFD_MAIN_PLANE
, /* main layer */
212 0, 0, 0 /* layer masks */
215 hwnd
= CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW
,
216 10, 10, 200, 200, NULL
, NULL
, NULL
, NULL
);
217 ok(hwnd
!= NULL
, "err: %d\n", GetLastError());
221 int iPixelFormat
, res
;
223 ShowWindow(hwnd
, SW_SHOW
);
227 iPixelFormat
= ChoosePixelFormat(hdc
, &pfd
);
228 ok(iPixelFormat
> 0, "No pixelformat found!\n"); /* This should never happen as ChoosePixelFormat always returns a closest match */
230 res
= SetPixelFormat(hdc
, iPixelFormat
, &pfd
);
231 ok(res
, "SetPixelformat failed: %x\n", GetLastError());
233 hglrc
= wglCreateContext(hdc
);
234 res
= wglMakeCurrent(hdc
, hglrc
);
235 ok(res
, "wglMakeCurrent failed!\n");
238 test_setpixelformat();
240 wgl_extensions
= pwglGetExtensionsStringARB(hdc
);
241 if(wgl_extensions
== NULL
) skip("Skipping opengl32 tests because this OpenGL implementation doesn't support WGL extensions!\n");
243 if(strstr(wgl_extensions
, "WGL_ARB_pbuffer"))
246 trace("WGL_ARB_pbuffer not supported, skipping pbuffer test\n");