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
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
25 * @file fbo-storage-formats.c
27 * Test the internalFormat parameter to glRenderbufferStorage()
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
49 static GLboolean have_extension
[MAX_EXT
];
60 static const struct format_info formats
[] = {
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
},
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
},
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
[] = {
136 GL_COLOR_INDEX12_EXT
,
137 GL_COLOR_INDEX16_EXT
,
140 GL_COMPRESSED_LUMINANCE
,
141 GL_COMPRESSED_LUMINANCE_ALPHA
,
142 GL_COMPRESSED_INTENSITY
,
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
,
161 static enum piglit_result
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
,
182 if (!piglit_check_gl_error(GL_NO_ERROR
))
183 piglit_report_result(PIGLIT_FAIL
);
185 /* clear out any errors */
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
);
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
);
204 GLenum status
= glCheckFramebufferStatus(GL_FRAMEBUFFER
);
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
,
219 piglit_width
, piglit_height
);
220 if (!piglit_check_gl_error(GL_INVALID_ENUM
)) {
221 piglit_report_subtest_result(PIGLIT_FAIL
, "%s", name
);
224 piglit_report_subtest_result(PIGLIT_PASS
, "%s", name
);
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
;
247 enumerate_subtests(void)
249 const char *names
[64];
251 assert(ARRAY_SIZE(formats
) + ARRAY_SIZE(invalid_formats
) < 64);
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
]);
262 piglit_register_subtests(names
);
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
);