shader_runner: don't use deleted query objects
[piglit.git] / tests / texturing / teximage-errors.c
blob47d5d28e460d820e42ebd86a1f5a564f9f73ce0c
1 /*
2 * Copyright (c) 2010 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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NON-INFRINGEMENT. IN NO EVENT SHALL VMWARE AND/OR THEIR SUPPLIERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
25 /**
26 * @file
27 * Tests glTexImage functions for invalid values, error reporting.
30 #include "piglit-util-gl.h"
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config.supports_gl_compat_version = 10;
35 config.supports_gl_core_version = 31;
36 config.window_visual = PIGLIT_GL_VISUAL_RGB;
37 config.khr_no_error_support = PIGLIT_HAS_ERRORS;
39 PIGLIT_GL_TEST_CONFIG_END
41 struct format_desc {
42 GLenum internalformat;
43 GLenum format;
44 GLenum type;
47 static const struct format_desc formats_allowed[] = {
48 {GL_DEPTH_COMPONENT16, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8},
49 {GL_DEPTH_COMPONENT24, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8},
50 {GL_DEPTH_COMPONENT32F, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8},
52 {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_FLOAT},
53 {GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_FLOAT},
54 {GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT},
56 {GL_DEPTH24_STENCIL8, GL_DEPTH_COMPONENT, GL_FLOAT},
57 {GL_DEPTH32F_STENCIL8, GL_DEPTH_COMPONENT, GL_FLOAT},
59 {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8},
60 {GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}};
62 static const struct format_desc formats_not_allowed[] = {
63 {GL_DEPTH_COMPONENT16, GL_STENCIL_INDEX, GL_INT},
64 {GL_DEPTH_COMPONENT24, GL_STENCIL_INDEX, GL_INT},
65 {GL_DEPTH_COMPONENT32F, GL_STENCIL_INDEX, GL_INT},
67 {GL_DEPTH24_STENCIL8, GL_STENCIL_INDEX, GL_INT},
68 {GL_DEPTH32F_STENCIL8, GL_STENCIL_INDEX, GL_INT},
70 {GL_RGBA8, GL_DEPTH_COMPONENT, GL_FLOAT},
71 {GL_RGBA8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}};
73 /** Test target params to glTexImage functions */
74 static GLboolean
75 test_targets(void)
77 /* all of these should generate GL_INVALID_ENUM */
79 glTexImage1D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 0, GL_RGBA, GL_FLOAT, NULL);
80 if (!piglit_check_gl_error(GL_INVALID_ENUM))
81 return GL_FALSE;
83 glTexImage2D(GL_TEXTURE_3D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_FLOAT, NULL);
84 if (!piglit_check_gl_error(GL_INVALID_ENUM))
85 return GL_FALSE;
87 glTexImage3D(GL_TEXTURE_1D, 0, GL_RGBA, 16, 16, 16, 0, GL_RGBA, GL_FLOAT, NULL);
88 if (!piglit_check_gl_error(GL_INVALID_ENUM))
89 return GL_FALSE;
92 glTexSubImage1D(GL_TEXTURE_2D, 0, 6, 10, GL_RGBA, GL_FLOAT, NULL);
93 if (!piglit_check_gl_error(GL_INVALID_ENUM))
94 return GL_FALSE;
96 glTexSubImage1D(GL_PROXY_TEXTURE_1D, 0, 6, 10, GL_RGBA, GL_FLOAT, NULL);
97 if (!piglit_check_gl_error(GL_INVALID_ENUM))
98 return GL_FALSE;
100 glTexSubImage2D(GL_PROXY_TEXTURE_2D, 0, 6, 6, 10, 10, GL_RGBA, GL_FLOAT, NULL);
101 if (!piglit_check_gl_error(GL_INVALID_ENUM))
102 return GL_FALSE;
104 glTexSubImage3D(GL_PROXY_TEXTURE_2D, 0, 6, 6, 6, 10, 10, 10, GL_RGBA, GL_FLOAT, NULL);
105 if (!piglit_check_gl_error(GL_INVALID_ENUM))
106 return GL_FALSE;
109 glCopyTexImage1D(GL_PROXY_TEXTURE_1D, 0, GL_RGBA, 4, 4, 16, 0);
110 if (!piglit_check_gl_error(GL_INVALID_ENUM))
111 return GL_FALSE;
113 glCopyTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGBA, 4, 4, 16, 16, 0);
114 if (!piglit_check_gl_error(GL_INVALID_ENUM))
115 return GL_FALSE;
117 glCopyTexImage2D(GL_TEXTURE_1D, 0, GL_RGBA, 4, 4, 16, 16, 0);
118 if (!piglit_check_gl_error(GL_INVALID_ENUM))
119 return GL_FALSE;
122 glCopyTexSubImage1D(GL_PROXY_TEXTURE_1D, 0, 4, 4, 6, 10);
123 if (!piglit_check_gl_error(GL_INVALID_ENUM))
124 return GL_FALSE;
126 glCopyTexSubImage2D(GL_PROXY_TEXTURE_2D, 0, 4, 4, 6, 6, 10, 10);
127 if (!piglit_check_gl_error(GL_INVALID_ENUM))
128 return GL_FALSE;
130 glCopyTexSubImage3D(GL_PROXY_TEXTURE_3D, 0, 4, 4, 4, 6, 6, 10, 10);
131 if (!piglit_check_gl_error(GL_INVALID_ENUM))
132 return GL_FALSE;
135 return GL_TRUE;
139 /** Test texture size errors and subtexture position errors */
140 static GLboolean
141 test_pos_and_sizes(void)
143 /* all of these should generate GL_INVALID_VALUE */
145 glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, -16, 0, GL_RGBA, GL_FLOAT, NULL);
146 if (!piglit_check_gl_error(GL_INVALID_VALUE))
147 return GL_FALSE;
149 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, -6, -5, 0, GL_RGBA, GL_FLOAT, NULL);
150 if (!piglit_check_gl_error(GL_INVALID_VALUE))
151 return GL_FALSE;
153 glTexImage2D(GL_TEXTURE_2D, -2, GL_RGBA, 16, 16, 0, GL_RGBA, GL_FLOAT, NULL);
154 if (!piglit_check_gl_error(GL_INVALID_VALUE))
155 return GL_FALSE;
157 glTexImage2D(GL_TEXTURE_2D, 2000, GL_RGBA, 16, 16, 0, GL_RGBA, GL_FLOAT, NULL);
158 if (!piglit_check_gl_error(GL_INVALID_VALUE))
159 return GL_FALSE;
162 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 1<<28, 1<<28, 0);
163 if (!piglit_check_gl_error(GL_INVALID_VALUE))
164 return GL_FALSE;
167 /* setup valid 2D texture for subsequent TexSubImage calls */
168 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_FLOAT, NULL);
171 glTexSubImage2D(GL_TEXTURE_2D, 0, 6, 6, 100, 100, GL_RGBA, GL_FLOAT, NULL);
172 if (!piglit_check_gl_error(GL_INVALID_VALUE))
173 return GL_FALSE;
175 glTexSubImage2D(GL_TEXTURE_2D, 0, -6, -6, 10, 10, GL_RGBA, GL_FLOAT, NULL);
176 if (!piglit_check_gl_error(GL_INVALID_VALUE))
177 return GL_FALSE;
180 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, -6, -6, 2, 2, 10, 10);
181 if (!piglit_check_gl_error(GL_INVALID_VALUE))
182 return GL_FALSE;
184 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 6, 6, 2, 2, 200, 200);
185 if (!piglit_check_gl_error(GL_INVALID_VALUE))
186 return GL_FALSE;
188 /* mipmap level 1 doesn't exist */
189 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 8, 8, GL_RGBA, GL_FLOAT, NULL);
190 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
191 return GL_FALSE;
193 /* mipmap level 2 doesn't exist */
194 glCopyTexSubImage2D(GL_TEXTURE_2D, 2, 0, 0, 0, 0, 4, 4);
195 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
196 return GL_FALSE;
199 return GL_TRUE;
202 /* Test the combinations of depth formats in glTexImage{123}D() */
203 static bool
204 test_depth_formats(const struct format_desc *test, GLenum expected_error,
205 GLint n_tests)
207 int i;
208 bool result = true;
210 for (i = 0; i < n_tests; i++) {
211 if ((test[i].internalformat == GL_DEPTH_COMPONENT32F ||
212 test[i].internalformat == GL_DEPTH32F_STENCIL8) &&
213 !piglit_is_extension_supported("GL_ARB_depth_buffer_float"))
214 continue;
216 glTexImage1D(GL_TEXTURE_1D, 0, test[i].internalformat, 16, 0,
217 test[i].format, test[i].type, NULL);
218 result = piglit_check_gl_error(expected_error) && result;
220 glTexImage2D(GL_TEXTURE_2D, 0, test[i].internalformat, 16, 16,
221 0, test[i].format, test[i].type, NULL);
222 result = piglit_check_gl_error(expected_error) && result;
224 if (!piglit_is_extension_supported("GL_EXT_texture_array"))
225 continue;
227 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, test[i].internalformat,
228 16, 16, 16, 0, test[i].format, test[i].type, NULL);
229 result = piglit_check_gl_error(expected_error) && result;
231 return result;
234 /* Test the combinations of depth formats in glTexSubImage{123}D() */
235 static bool
236 test_depth_formats_storage(const struct format_desc *test, GLenum expected_error,
237 GLint n_tests)
239 int i;
240 bool result = true;
241 char buffer[16 * 16 * 16 * 8] = {0};
242 GLuint tex[3];
244 /* Not strictly required, but makes the test simpler */
245 if (!piglit_is_extension_supported("GL_ARB_texture_storage"))
246 return true;
248 for (i = 0; i < n_tests; i++, glDeleteTextures(3, tex)) {
249 glGenTextures(3, tex);
251 if ((test[i].internalformat == GL_DEPTH_COMPONENT32F ||
252 test[i].internalformat == GL_DEPTH32F_STENCIL8) &&
253 !piglit_is_extension_supported("GL_ARB_depth_buffer_float"))
254 continue;
256 glBindTexture(GL_TEXTURE_1D, tex[0]);
257 glBindTexture(GL_TEXTURE_2D, tex[1]);
258 glBindTexture(GL_TEXTURE_2D_ARRAY, tex[2]);
260 glTexStorage1D(GL_TEXTURE_1D, 1, test[i].internalformat, 16);
261 result = piglit_check_gl_error(GL_NO_ERROR) && result;
262 glTexSubImage1D(GL_TEXTURE_1D, 0, 0, 16,
263 test[i].format, test[i].type, buffer);
264 result = piglit_check_gl_error(expected_error) && result;
266 glTexStorage2D(GL_TEXTURE_2D, 1, test[i].internalformat, 16, 16);
267 result = piglit_check_gl_error(GL_NO_ERROR) && result;
268 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 16, 16,
269 test[i].format, test[i].type, buffer);
270 result = piglit_check_gl_error(expected_error) && result;
272 if (!piglit_is_extension_supported("GL_EXT_texture_array"))
273 continue;
275 glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, test[i].internalformat,
276 16, 16, 16);
277 result = piglit_check_gl_error(GL_NO_ERROR) && result;
278 glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, 16, 16, 16,
279 test[i].format, test[i].type, buffer);
280 result = piglit_check_gl_error(expected_error) && result;
282 return result;
285 enum piglit_result
286 piglit_display(void)
288 bool pass = true;
289 pass = test_targets() && pass;
290 pass = test_pos_and_sizes() && pass;
292 if (piglit_get_gl_version() >= 14
293 || piglit_is_extension_supported("GL_ARB_depth_texture")) {
294 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3
295 * Core Profile spec says:
297 * Textures with a base internal format of DEPTH_COMPONENT or
298 * DEPTH_STENCIL require either depth component data or
299 * depth/stencil component data. Textures with other base
300 * internal formats require RGBA component data. The error
301 * INVALID_OPERATION is generated if one of the base internal
302 * format and format is DEPTH_COMPONENT or DEPTH_STENCIL, and
303 * the other is neither of these values.
305 pass = test_depth_formats(formats_allowed, GL_NO_ERROR,
306 ARRAY_SIZE(formats_allowed))
307 && pass;
308 pass = test_depth_formats(formats_not_allowed, GL_INVALID_OPERATION,
309 ARRAY_SIZE(formats_not_allowed))
310 && pass;
312 pass = test_depth_formats_storage(formats_allowed, GL_NO_ERROR,
313 ARRAY_SIZE(formats_allowed))
314 && pass;
315 pass = test_depth_formats_storage(formats_not_allowed, GL_INVALID_OPERATION,
316 ARRAY_SIZE(formats_not_allowed))
317 && pass;
320 return pass ? PIGLIT_PASS: PIGLIT_FAIL;
324 void
325 piglit_init(int argc, char **argv)