arb_copy_image: test copying of different mipmap levels of a texture
[piglit.git] / tests / glx / glx-fbconfig-compliance.c
blob28f927fb8e873a8451c29b509785f2ad64e7a883
1 /*
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
14 * Software.
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
22 * IN THE SOFTWARE.
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;
41 static int
42 config_is_sufficient(Display *dpy, GLXFBConfig config, int vdepth, int rgba)
44 int draw_type;
45 int render_type;
46 int color_red, color_green, color_blue;
47 int caveat;
48 int stencil;
49 int depth;
50 int color_buffer_size;
51 int level;
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) {
66 return 0;
69 /* must support rgba, if rgba, or ci, if ci */
70 if (rgba) {
71 if ((render_type & GLX_RGBA_BIT) == 0) {
72 return 0;
74 } else {
75 if ((render_type & GLX_COLOR_INDEX_BIT) == 0) {
76 return 0;
80 /* must not be non-conformant */
81 if (caveat == GLX_NON_CONFORMANT_CONFIG) {
82 return 0;
85 /* must have at least one color buffer */
86 if ((color_red + color_green + color_blue) < 1) {
87 return 0;
90 /* must have at least 1 bit of stencil */
91 if (stencil < 1) {
92 return 0;
95 /* must have at least 12 bits of depth */
96 if (depth < 12) {
97 return 0;
100 /* color depth must match deepest visual depth */
101 if (color_buffer_size != vdepth) {
102 return 0;
105 /* must exist on fb level 0 */
106 if (level != 0) {
107 return 0;
110 return 1;
113 static int
114 get_max_visual_depth(Display *dpy, int rgba)
116 XVisualInfo template, *vi = NULL;
117 int i, nvis, class;
118 int depth = 0;
120 for (class = StaticColor; class <= DirectColor; class++) {
121 if (class > PseudoColor && !rgba)
122 break;
124 template.class = class;
125 vi = XGetVisualInfo(dpy, VisualClassMask, &template, &nvis);
127 if (!vi)
128 continue;
130 for (i = 0; i < nvis; i++)
131 if (vi[i].depth > depth)
132 depth = vi[i].depth;
134 XFree(vi);
135 vi = NULL;
138 return depth;
142 main(int argc, char **argv)
144 Display *dpy;
145 int i;
146 GLXFBConfig *configs;
147 int num_configs;
148 int visual_depth;
149 int conformant = 0;
151 dpy = XOpenDisplay(NULL);
152 if (dpy == 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);
174 if (!visual_depth)
175 goto out;
177 for (i = 0; i < num_configs; i++)
178 conformant |= config_is_sufficient(dpy, configs[i],
179 visual_depth, 1);
181 /* color index support is not mandatory */
182 visual_depth = get_max_visual_depth(dpy, 0);
183 if (visual_depth) {
184 GLXFBConfig *ci_configs;
185 int num_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,
190 None
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);
196 if (!ci_configs)
197 goto out;
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],
202 visual_depth, 0);
204 conformant &= ci_conformant;
207 out:
208 piglit_report_result(conformant ? PIGLIT_PASS : PIGLIT_FAIL);
209 return 0;