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
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
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
42 GLenum internalformat
;
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 */
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
))
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
))
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
))
92 glTexSubImage1D(GL_TEXTURE_2D
, 0, 6, 10, GL_RGBA
, GL_FLOAT
, NULL
);
93 if (!piglit_check_gl_error(GL_INVALID_ENUM
))
96 glTexSubImage1D(GL_PROXY_TEXTURE_1D
, 0, 6, 10, GL_RGBA
, GL_FLOAT
, NULL
);
97 if (!piglit_check_gl_error(GL_INVALID_ENUM
))
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
))
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
))
109 glCopyTexImage1D(GL_PROXY_TEXTURE_1D
, 0, GL_RGBA
, 4, 4, 16, 0);
110 if (!piglit_check_gl_error(GL_INVALID_ENUM
))
113 glCopyTexImage2D(GL_PROXY_TEXTURE_2D
, 0, GL_RGBA
, 4, 4, 16, 16, 0);
114 if (!piglit_check_gl_error(GL_INVALID_ENUM
))
117 glCopyTexImage2D(GL_TEXTURE_1D
, 0, GL_RGBA
, 4, 4, 16, 16, 0);
118 if (!piglit_check_gl_error(GL_INVALID_ENUM
))
122 glCopyTexSubImage1D(GL_PROXY_TEXTURE_1D
, 0, 4, 4, 6, 10);
123 if (!piglit_check_gl_error(GL_INVALID_ENUM
))
126 glCopyTexSubImage2D(GL_PROXY_TEXTURE_2D
, 0, 4, 4, 6, 6, 10, 10);
127 if (!piglit_check_gl_error(GL_INVALID_ENUM
))
130 glCopyTexSubImage3D(GL_PROXY_TEXTURE_3D
, 0, 4, 4, 4, 6, 6, 10, 10);
131 if (!piglit_check_gl_error(GL_INVALID_ENUM
))
139 /** Test texture size errors and subtexture position errors */
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
))
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
))
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
))
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
))
162 glCopyTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 1<<28, 1<<28, 0);
163 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
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
))
175 glTexSubImage2D(GL_TEXTURE_2D
, 0, -6, -6, 10, 10, GL_RGBA
, GL_FLOAT
, NULL
);
176 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
180 glCopyTexSubImage2D(GL_TEXTURE_2D
, 0, -6, -6, 2, 2, 10, 10);
181 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
184 glCopyTexSubImage2D(GL_TEXTURE_2D
, 0, 6, 6, 2, 2, 200, 200);
185 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
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
))
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
))
202 /* Test the combinations of depth formats in glTexImage{123}D() */
204 test_depth_formats(const struct format_desc
*test
, GLenum expected_error
,
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"))
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"))
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
;
234 /* Test the combinations of depth formats in glTexSubImage{123}D() */
236 test_depth_formats_storage(const struct format_desc
*test
, GLenum expected_error
,
241 char buffer
[16 * 16 * 16 * 8] = {0};
244 /* Not strictly required, but makes the test simpler */
245 if (!piglit_is_extension_supported("GL_ARB_texture_storage"))
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"))
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"))
275 glTexStorage3D(GL_TEXTURE_2D_ARRAY
, 1, test
[i
].internalformat
,
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
;
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
))
308 pass
= test_depth_formats(formats_not_allowed
, GL_INVALID_OPERATION
,
309 ARRAY_SIZE(formats_not_allowed
))
312 pass
= test_depth_formats_storage(formats_allowed
, GL_NO_ERROR
,
313 ARRAY_SIZE(formats_allowed
))
315 pass
= test_depth_formats_storage(formats_not_allowed
, GL_INVALID_OPERATION
,
316 ARRAY_SIZE(formats_not_allowed
))
320 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
325 piglit_init(int argc
, char **argv
)