README: recommend Ninja by default and switch to cmake --build
[piglit.git] / tests / fbo / fbo-storage-formats.c
blobbb74efb2f021b7c6abd2ef0a9aec67046efbc263
1 /*
2 * Copyright (c) 2011 VMware, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
25 * @file fbo-storage-formats.c
27 * Test the internalFormat parameter to glRenderbufferStorage()
29 * Author:
30 * Brian Paul
33 #include "piglit-util-gl.h"
35 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config.supports_gl_compat_version = 10;
39 config.window_visual = PIGLIT_GL_VISUAL_RGB;
40 config.khr_no_error_support = PIGLIT_NO_ERRORS;
42 PIGLIT_GL_TEST_CONFIG_END
44 #define EXT_packed_depth_stencil 1
45 #define ARB_framebuffer_object 2
46 #define ARB_texture_rg 3
47 #define MAX_EXT 4
49 static GLboolean have_extension[MAX_EXT];
53 struct format_info
55 GLenum format;
56 GLuint extension;
60 static const struct format_info formats[] = {
61 { GL_RGB, 0 },
62 { GL_R3_G3_B2, 0 },
63 { GL_RGB4, 0 },
64 { GL_RGB5, 0 },
65 { GL_RGB8, 0 },
66 { GL_RGB10, 0 },
67 { GL_RGB12, 0 },
68 { GL_RGB16, 0 },
69 { GL_RGBA, 0 },
70 { GL_RGBA2, 0 },
71 { GL_RGBA4, 0 },
72 { GL_RGB5_A1, 0 },
73 { GL_RGBA8, 0 },
74 { GL_RGB10_A2, 0 },
75 { GL_RGBA12, 0 },
76 { GL_RGBA16, 0 },
77 { GL_STENCIL_INDEX, 0 },
78 { GL_STENCIL_INDEX1_EXT, 0 },
79 { GL_STENCIL_INDEX4_EXT, 0 },
80 { GL_STENCIL_INDEX8_EXT, 0 },
81 { GL_STENCIL_INDEX16_EXT, 0 },
82 { GL_DEPTH_COMPONENT, 0 },
83 { GL_DEPTH_COMPONENT16, 0 },
84 { GL_DEPTH_COMPONENT24, 0 },
85 { GL_DEPTH_COMPONENT32, 0 },
87 /* GL_ARB_framebuffer_object additions */
88 { GL_ALPHA, ARB_framebuffer_object },
89 { GL_ALPHA4, ARB_framebuffer_object },
90 { GL_ALPHA8, ARB_framebuffer_object },
91 { GL_ALPHA12, ARB_framebuffer_object },
92 { GL_ALPHA16, ARB_framebuffer_object },
93 { GL_LUMINANCE_ALPHA, ARB_framebuffer_object },
94 { GL_LUMINANCE, ARB_framebuffer_object },
95 { GL_INTENSITY, ARB_framebuffer_object },
97 /* GL_ARB_texture_rg */
98 { GL_RED, ARB_texture_rg },
99 { GL_R8, ARB_texture_rg },
100 { GL_R16, ARB_texture_rg },
101 { GL_RG, ARB_texture_rg },
102 { GL_RG8, ARB_texture_rg },
103 { GL_RG16, ARB_texture_rg },
104 #if 0
105 /* XXX also depend on texture_float, texture_integer extensions */
106 { GL_R16F, ARB_texture_rg },
107 { GL_R32F, ARB_texture_rg },
108 { GL_RG16F, ARB_texture_rg },
109 { GL_RG32F, ARB_texture_rg },
110 { GL_R8I, ARB_texture_rg },
111 { GL_R8UI, ARB_texture_rg },
112 { GL_R16I, ARB_texture_rg },
113 { GL_R16UI, ARB_texture_rg },
114 { GL_R32I, ARB_texture_rg },
115 { GL_R32UI, ARB_texture_rg },
116 { GL_RG8I, ARB_texture_rg },
117 { GL_RG8UI, ARB_texture_rg },
118 { GL_RG16I, ARB_texture_rg },
119 { GL_RG16UI, ARB_texture_rg },
120 { GL_RG32I, ARB_texture_rg },
121 { GL_RG32UI, ARB_texture_rg },
122 #endif
124 /* GL_EXT_packed_depth_stencil */
125 { GL_DEPTH_STENCIL_EXT, EXT_packed_depth_stencil },
126 { GL_DEPTH24_STENCIL8_EXT, EXT_packed_depth_stencil }
130 static const GLenum invalid_formats[] = {
131 GL_COLOR_INDEX,
132 GL_COLOR_INDEX1_EXT,
133 GL_COLOR_INDEX2_EXT,
134 GL_COLOR_INDEX4_EXT,
135 GL_COLOR_INDEX8_EXT,
136 GL_COLOR_INDEX12_EXT,
137 GL_COLOR_INDEX16_EXT,
139 GL_COMPRESSED_ALPHA,
140 GL_COMPRESSED_LUMINANCE,
141 GL_COMPRESSED_LUMINANCE_ALPHA,
142 GL_COMPRESSED_INTENSITY,
143 GL_COMPRESSED_RGB,
144 GL_COMPRESSED_RGBA,
146 GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
147 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
148 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
149 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
151 GL_COMPRESSED_RED,
152 GL_COMPRESSED_RG,
154 GL_YCBCR_MESA,
156 GL_DUDV_ATI,
157 GL_DU8DV8_ATI
161 static enum piglit_result
162 test(void)
164 GLuint fbo, rb;
165 int i;
166 GLboolean pass = GL_TRUE;
168 glGenFramebuffersEXT(1, &fbo);
169 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
170 if (!piglit_check_gl_error(GL_NO_ERROR))
171 piglit_report_result(PIGLIT_FAIL);
173 glGenRenderbuffersEXT(1, &rb);
174 if (!piglit_check_gl_error(GL_NO_ERROR))
175 piglit_report_result(PIGLIT_FAIL);
176 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb);
178 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
179 GL_COLOR_ATTACHMENT0,
180 GL_RENDERBUFFER_EXT,
181 rb);
182 if (!piglit_check_gl_error(GL_NO_ERROR))
183 piglit_report_result(PIGLIT_FAIL);
185 /* clear out any errors */
186 while (glGetError())
189 /* test formats that should be accepted */
190 for (i = 0; i < ARRAY_SIZE(formats); i++) {
191 const char *name = piglit_get_gl_enum_name(formats[i].format);
193 if (!have_extension[formats[i].extension]) {
194 piglit_report_subtest_result(PIGLIT_SKIP, "%s", name);
195 continue;
198 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, formats[i].format,
199 piglit_width, piglit_height);
200 if (!piglit_check_gl_error(GL_NO_ERROR)) {
201 piglit_report_subtest_result(PIGLIT_FAIL, "%s", name);
202 pass = GL_FALSE;
203 } else {
204 GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
205 printf("%s is %s\n",
206 name,
207 (status == GL_FRAMEBUFFER_COMPLETE ? "complete" : "incomplete"));
208 piglit_report_subtest_result(PIGLIT_PASS, "%s", name);
212 /* test formats that should fail */
213 if (!piglit_khr_no_error) {
214 for (i = 0; i < ARRAY_SIZE(invalid_formats); i++) {
215 const char *name = piglit_get_gl_enum_name(invalid_formats[i]);
217 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,
218 invalid_formats[i],
219 piglit_width, piglit_height);
220 if (!piglit_check_gl_error(GL_INVALID_ENUM)) {
221 piglit_report_subtest_result(PIGLIT_FAIL, "%s", name);
222 pass = GL_FALSE;
223 } else {
224 piglit_report_subtest_result(PIGLIT_PASS, "%s", name);
227 } else {
228 printf("Skipping error tests because KHR_NO_ERROR is enabled\n");
229 for (i = 0; i < ARRAY_SIZE(invalid_formats); i++) {
230 const char *name = piglit_get_gl_enum_name(invalid_formats[i]);
231 piglit_report_subtest_result(PIGLIT_SKIP, "%s", name);
235 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
239 enum piglit_result
240 piglit_display(void)
242 return test();
246 static void
247 enumerate_subtests(void)
249 const char *names[64];
251 assert(ARRAY_SIZE(formats) + ARRAY_SIZE(invalid_formats) < 64);
253 int t = 0;
254 for (int i = 0; i < ARRAY_SIZE(formats); i++) {
255 names[t++] = piglit_get_gl_enum_name(formats[i].format);
257 for (int i = 0; i < ARRAY_SIZE(invalid_formats); i++) {
258 names[t++] = piglit_get_gl_enum_name(invalid_formats[i]);
260 names[t] = NULL;
262 piglit_register_subtests(names);
266 void
267 piglit_init(int argc, char**argv)
269 enumerate_subtests();
271 piglit_require_extension("GL_EXT_framebuffer_object");
273 have_extension[0] = GL_TRUE;
274 have_extension[EXT_packed_depth_stencil] = piglit_is_extension_supported("GL_EXT_packed_depth_stencil");
275 have_extension[ARB_framebuffer_object] = piglit_is_extension_supported("GL_ARB_framebuffer_object");
276 have_extension[ARB_texture_rg] = piglit_is_extension_supported("GL_ARB_texture_rg");
278 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);