2 * Copyright © 2011 Intel Corporation
3 * Copyright 2011 Red Hat, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 /** @file glx-fbconfig-compliance.c
26 * Verify that there exists at least one fbconfig conforming to the
27 * minimum requirements specified by GLX 1.4 section 3.3.3
30 #include "piglit-util-gl.h"
31 #include "piglit-glx-util.h"
33 static PFNGLXGETFBCONFIGSPROC GetFBConfigs
= NULL
;
34 static PFNGLXGETFBCONFIGATTRIBPROC GetFBConfigAttrib
= NULL
;
35 static PFNGLXGETVISUALFROMFBCONFIGPROC GetVisualFromFBConfig
= NULL
;
36 static PFNGLXCHOOSEFBCONFIGPROC ChooseFBConfig
= NULL
;
38 int piglit_width
= 10;
39 int piglit_height
= 10;
42 config_is_sufficient(Display
*dpy
, GLXFBConfig config
, int vdepth
, int rgba
)
46 int color_red
, color_green
, color_blue
;
50 int color_buffer_size
;
53 GetFBConfigAttrib(dpy
, config
, GLX_DRAWABLE_TYPE
, &draw_type
);
54 GetFBConfigAttrib(dpy
, config
, GLX_RENDER_TYPE
, &render_type
);
55 GetFBConfigAttrib(dpy
, config
, GLX_CONFIG_CAVEAT
, &caveat
);
56 GetFBConfigAttrib(dpy
, config
, GLX_RED_SIZE
, &color_red
);
57 GetFBConfigAttrib(dpy
, config
, GLX_GREEN_SIZE
, &color_green
);
58 GetFBConfigAttrib(dpy
, config
, GLX_BLUE_SIZE
, &color_blue
);
59 GetFBConfigAttrib(dpy
, config
, GLX_STENCIL_SIZE
, &stencil
);
60 GetFBConfigAttrib(dpy
, config
, GLX_DEPTH_SIZE
, &depth
);
61 GetFBConfigAttrib(dpy
, config
, GLX_BUFFER_SIZE
, &color_buffer_size
);
62 GetFBConfigAttrib(dpy
, config
, GLX_LEVEL
, &level
);
64 /* must support window rendering */
65 if ((draw_type
& GLX_WINDOW_BIT
) == 0) {
69 /* must support rgba, if rgba, or ci, if ci */
71 if ((render_type
& GLX_RGBA_BIT
) == 0) {
75 if ((render_type
& GLX_COLOR_INDEX_BIT
) == 0) {
80 /* must not be non-conformant */
81 if (caveat
== GLX_NON_CONFORMANT_CONFIG
) {
85 /* must have at least one color buffer */
86 if ((color_red
+ color_green
+ color_blue
) < 1) {
90 /* must have at least 1 bit of stencil */
95 /* must have at least 12 bits of depth */
100 /* color depth must match deepest visual depth */
101 if (color_buffer_size
!= vdepth
) {
105 /* must exist on fb level 0 */
114 get_max_visual_depth(Display
*dpy
, int rgba
)
116 XVisualInfo
template, *vi
= NULL
;
120 for (class = StaticColor
; class <= DirectColor
; class++) {
121 if (class > PseudoColor
&& !rgba
)
124 template.class = class;
125 vi
= XGetVisualInfo(dpy
, VisualClassMask
, &template, &nvis
);
130 for (i
= 0; i
< nvis
; i
++)
131 if (vi
[i
].depth
> depth
)
142 main(int argc
, char **argv
)
146 GLXFBConfig
*configs
;
151 dpy
= XOpenDisplay(NULL
);
153 fprintf(stderr
, "couldn't open display\n");
154 piglit_report_result(PIGLIT_FAIL
);
157 /* Test requires at least GLX version 1.3. Otherwise there is no
158 * glXGetFBConfigs function.
160 piglit_require_glx_version(dpy
, 1, 3);
161 piglit_require_glx_extension(dpy
, "GLX_ARB_get_proc_address");
163 GetFBConfigs
= (PFNGLXGETFBCONFIGSPROC
)
164 glXGetProcAddressARB((GLubyte
*) "glXGetFBConfigs");
165 GetFBConfigAttrib
= (PFNGLXGETFBCONFIGATTRIBPROC
)
166 glXGetProcAddressARB((GLubyte
*) "glXGetFBConfigAttrib");
167 GetVisualFromFBConfig
= (PFNGLXGETVISUALFROMFBCONFIGPROC
)
168 glXGetProcAddressARB((GLubyte
*) "glXGetVisualFromFBConfig");
170 configs
= GetFBConfigs(dpy
, DefaultScreen(dpy
), &num_configs
);
172 /* rgba support is mandatory */
173 visual_depth
= get_max_visual_depth(dpy
, 1);
177 for (i
= 0; i
< num_configs
; i
++)
178 conformant
|= config_is_sufficient(dpy
, configs
[i
],
181 /* color index support is not mandatory */
182 visual_depth
= get_max_visual_depth(dpy
, 0);
184 GLXFBConfig
*ci_configs
;
186 int ci_conformant
= 0;
187 const int ci_attribs
[] = {
188 GLX_RENDER_TYPE
, GLX_COLOR_INDEX_BIT
,
189 GLX_DRAWABLE_TYPE
, GLX_WINDOW_BIT
,
193 /* even if you have CI visuals, you needn't have CI fbconfigs */
194 ci_configs
= ChooseFBConfig(dpy
, DefaultScreen(dpy
),
195 ci_attribs
, &num_ci_configs
);
199 /* but if you do have them, they must conform */
200 for (i
= 0; i
< num_configs
; i
++)
201 ci_conformant
= config_is_sufficient(dpy
, configs
[i
],
204 conformant
&= ci_conformant
;
208 piglit_report_result(conformant
? PIGLIT_PASS
: PIGLIT_FAIL
);