README: recommend Ninja by default and switch to cmake --build
[piglit.git] / tests / fbo / fbo-storage-completeness.c
blob01b9264ed4125c1faa1f44811803562ff5fbba23
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-completeness.c
27 * Tests if glRenderbufferStorage() affects framebuffer completeness.
29 * Author:
30 * Brian Paul
31 * Marek Olšák
34 #include "piglit-util-gl.h"
36 PIGLIT_GL_TEST_CONFIG_BEGIN
38 config.supports_gl_compat_version = 10;
40 config.window_visual = PIGLIT_GL_VISUAL_RGB;
41 config.khr_no_error_support = PIGLIT_NO_ERRORS;
43 PIGLIT_GL_TEST_CONFIG_END
45 #define EXT_packed_depth_stencil 1
46 #define ARB_framebuffer_object 2
47 #define ARB_texture_rg 3
48 #define MAX_EXT 4
50 static GLboolean have_extension[MAX_EXT];
54 struct format_info
56 GLenum format;
57 GLuint extension;
61 static const struct format_info formats[] = {
62 { GL_RGB, 0 },
63 { GL_R3_G3_B2, 0 },
64 { GL_RGB4, 0 },
65 { GL_RGB5, 0 },
66 { GL_RGB8, 0 },
67 { GL_RGB10, 0 },
68 { GL_RGB12, 0 },
69 { GL_RGB16, 0 },
70 { GL_RGBA, 0 },
71 { GL_RGBA2, 0 },
72 { GL_RGBA4, 0 },
73 { GL_RGB5_A1, 0 },
74 { GL_RGBA8, 0 },
75 { GL_RGB10_A2, 0 },
76 { GL_RGBA12, 0 },
77 { GL_RGBA16, 0 },
78 { GL_STENCIL_INDEX, 0 },
79 { GL_STENCIL_INDEX1_EXT, 0 },
80 { GL_STENCIL_INDEX4_EXT, 0 },
81 { GL_STENCIL_INDEX8_EXT, 0 },
82 { GL_STENCIL_INDEX16_EXT, 0 },
83 { GL_DEPTH_COMPONENT, 0 },
84 { GL_DEPTH_COMPONENT16, 0 },
85 { GL_DEPTH_COMPONENT24, 0 },
86 { GL_DEPTH_COMPONENT32, 0 },
88 /* GL_ARB_framebuffer_object additions */
89 { GL_ALPHA, ARB_framebuffer_object },
90 { GL_ALPHA4, ARB_framebuffer_object },
91 { GL_ALPHA8, ARB_framebuffer_object },
92 { GL_ALPHA12, ARB_framebuffer_object },
93 { GL_ALPHA16, ARB_framebuffer_object },
94 { GL_LUMINANCE_ALPHA, ARB_framebuffer_object },
95 { GL_LUMINANCE, ARB_framebuffer_object },
96 { GL_INTENSITY, ARB_framebuffer_object },
98 /* GL_ARB_texture_rg */
99 { GL_RED, ARB_texture_rg },
100 { GL_R8, ARB_texture_rg },
101 { GL_R16, ARB_texture_rg },
102 { GL_RG, ARB_texture_rg },
103 { GL_RG8, ARB_texture_rg },
104 { GL_RG16, ARB_texture_rg },
105 #if 0
106 /* XXX also depend on texture_float, texture_integer extensions */
107 { GL_R16F, ARB_texture_rg },
108 { GL_R32F, ARB_texture_rg },
109 { GL_RG16F, ARB_texture_rg },
110 { GL_RG32F, ARB_texture_rg },
111 { GL_R8I, ARB_texture_rg },
112 { GL_R8UI, ARB_texture_rg },
113 { GL_R16I, ARB_texture_rg },
114 { GL_R16UI, ARB_texture_rg },
115 { GL_R32I, ARB_texture_rg },
116 { GL_R32UI, ARB_texture_rg },
117 { GL_RG8I, ARB_texture_rg },
118 { GL_RG8UI, ARB_texture_rg },
119 { GL_RG16I, ARB_texture_rg },
120 { GL_RG16UI, ARB_texture_rg },
121 { GL_RG32I, ARB_texture_rg },
122 { GL_RG32UI, ARB_texture_rg },
123 #endif
125 /* GL_EXT_packed_depth_stencil */
126 { GL_DEPTH_STENCIL_EXT, EXT_packed_depth_stencil },
127 { GL_DEPTH24_STENCIL8_EXT, EXT_packed_depth_stencil }
131 static enum piglit_result
132 test(void)
134 GLuint fbo, rb;
135 int i;
136 int incomplete = -1, complete = -1;
138 /* clear out any errors */
139 while (glGetError())
142 /* find a format which is incomplete */
143 for (i = 0; i < ARRAY_SIZE(formats); i++) {
144 if (!have_extension[formats[i].extension])
145 continue;
147 glGenFramebuffersEXT(1, &fbo);
148 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
149 if (!piglit_check_gl_error(GL_NO_ERROR))
150 piglit_report_result(PIGLIT_FAIL);
152 glGenRenderbuffersEXT(1, &rb);
153 if (!piglit_check_gl_error(GL_NO_ERROR))
154 piglit_report_result(PIGLIT_FAIL);
155 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb);
157 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
158 GL_COLOR_ATTACHMENT0,
159 GL_RENDERBUFFER_EXT,
160 rb);
161 if (!piglit_check_gl_error(GL_NO_ERROR))
162 piglit_report_result(PIGLIT_FAIL);
164 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, formats[i].format,
165 piglit_width, piglit_height);
166 if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) ==
167 GL_FRAMEBUFFER_COMPLETE_EXT) {
168 complete = i;
169 } else {
170 incomplete = i;
173 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);
174 glDeleteFramebuffersEXT(1, &fbo);
175 glDeleteRenderbuffersEXT(1, &rb);
177 if (incomplete != -1 && complete != -1)
178 break;
180 if (complete == -1) {
181 printf("Found no renderbuffer format which is framebuffer "
182 "complete.\n");
183 return PIGLIT_FAIL;
185 if (incomplete == -1)
186 return PIGLIT_PASS;
188 glGenFramebuffersEXT(1, &fbo);
189 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
190 if (!piglit_check_gl_error(GL_NO_ERROR))
191 piglit_report_result(PIGLIT_FAIL);
193 glGenRenderbuffersEXT(1, &rb);
194 if (!piglit_check_gl_error(GL_NO_ERROR))
195 piglit_report_result(PIGLIT_FAIL);
196 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb);
198 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
199 GL_COLOR_ATTACHMENT0,
200 GL_RENDERBUFFER_EXT,
201 rb);
202 if (!piglit_check_gl_error(GL_NO_ERROR))
203 piglit_report_result(PIGLIT_FAIL);
205 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, formats[complete].format,
206 piglit_width, piglit_height);
207 if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) !=
208 GL_FRAMEBUFFER_COMPLETE_EXT) {
209 printf("The format which was previously framebuffer complete "
210 "is now incomplete.\n");
211 return PIGLIT_FAIL;
214 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,
215 formats[incomplete].format,
216 piglit_width, piglit_height);
217 if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) ==
218 GL_FRAMEBUFFER_COMPLETE_EXT) {
219 printf("The format which was previously framebuffer incomplete "
220 "is now complete.\n");
221 return PIGLIT_FAIL;
224 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);
225 glDeleteFramebuffersEXT(1, &fbo);
226 glDeleteRenderbuffersEXT(1, &rb);
228 return PIGLIT_PASS;
232 enum piglit_result
233 piglit_display(void)
235 return test();
239 void
240 piglit_init(int argc, char**argv)
242 piglit_require_extension("GL_EXT_framebuffer_object");
244 have_extension[0] = GL_TRUE;
245 have_extension[EXT_packed_depth_stencil] = piglit_is_extension_supported("GL_EXT_packed_depth_stencil");
246 have_extension[ARB_framebuffer_object] = piglit_is_extension_supported("GL_ARB_framebuffer_object");
247 have_extension[ARB_texture_rg] = piglit_is_extension_supported("GL_ARB_texture_rg");
249 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);