2 * Copyright (c) 2014 Intel Corporation
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
26 * Tests the various error conditions that glClearTexSubImage should
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config
.supports_gl_compat_version
= 14;
36 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
38 config
.khr_no_error_support
= PIGLIT_HAS_ERRORS
;
40 PIGLIT_GL_TEST_CONFIG_END
48 glGenTextures(1, &tex
);
49 glBindTexture(GL_TEXTURE_2D
, tex
);
50 glTexImage2D(GL_TEXTURE_2D
,
53 4, 4, /* width/height */
58 glTexImage2D(GL_TEXTURE_2D
,
61 2, 2, /* width/height */
66 glTexImage2D(GL_TEXTURE_2D
,
69 1, 1, /* width/height */
74 glBindTexture(GL_TEXTURE_2D
, 0);
77 glClearTexSubImage(tex
,
80 1, 1, 1, /* width/height/depth */
81 GL_RGBA
, GL_UNSIGNED_BYTE
,
83 pass
&= piglit_check_gl_error(GL_INVALID_OPERATION
);
86 glClearTexSubImage(tex
,
89 1, 1, 1, /* width/height/depth */
90 GL_RGBA
, GL_UNSIGNED_BYTE
,
92 pass
&= piglit_check_gl_error(GL_INVALID_OPERATION
);
95 glClearTexSubImage(tex
,
98 1, 1, 1, /* width/height/depth */
99 GL_RGBA
, GL_UNSIGNED_BYTE
,
101 pass
&= piglit_check_gl_error(GL_INVALID_OPERATION
);
103 /* test invalid width */
104 glClearTexSubImage(tex
,
107 4, 1, 1, /* width/height/depth */
108 GL_RGBA
, GL_UNSIGNED_BYTE
,
110 pass
&= piglit_check_gl_error(GL_INVALID_OPERATION
);
112 /* Test invalid height */
113 glClearTexSubImage(tex
,
116 1, 4, 1, /* width/height/depth */
117 GL_RGBA
, GL_UNSIGNED_BYTE
,
119 pass
&= piglit_check_gl_error(GL_INVALID_OPERATION
);
121 /* Test invalid depth */
122 glClearTexSubImage(tex
,
125 1, 1, 2, /* width/height/depth */
126 GL_RGBA
, GL_UNSIGNED_BYTE
,
128 pass
&= piglit_check_gl_error(GL_INVALID_OPERATION
);
130 /* test clearing invalid region of level 1 */
131 glClearTexSubImage(tex
,
134 2, 3, 1, /* width/height/depth */
135 GL_RGBA
, GL_UNSIGNED_BYTE
,
137 pass
&= piglit_check_gl_error(GL_INVALID_OPERATION
);
140 glClearTexSubImage(tex
,
143 2, 3, 1, /* width/height/depth */
144 GL_RGBA
, GL_UNSIGNED_BYTE
,
146 pass
&= piglit_check_gl_error(GL_NO_ERROR
);
148 glDeleteTextures(1, &tex
);
155 test_texture_view(void)
160 glGenTextures(1, &tex
);
161 glBindTexture(GL_TEXTURE_2D
, tex
);
163 glTexStorage2D(GL_TEXTURE_2D
, 3, GL_RGBA8
, 4, 4);
165 /* create view of levels 1..2 as 0..1 */
166 glGenTextures(1, &view
);
167 glTextureView(view
, GL_TEXTURE_2D
, tex
,
168 GL_RGBA8
, 1, 2, 0, 1);
170 glBindTexture(GL_TEXTURE_2D
, view
);
172 pass
&= piglit_check_gl_error(GL_NO_ERROR
);
174 /* try to clear invalid level */
175 glClearTexSubImage(view
,
178 1, 1, 1, /* width/height/depth */
179 GL_RGBA
, GL_UNSIGNED_BYTE
,
181 pass
&= piglit_check_gl_error(GL_INVALID_OPERATION
);
183 /* clearing all of level 0 should work */
184 glClearTexSubImage(view
,
187 2, 2, 1, /* width/height/depth */
188 GL_RGBA
, GL_UNSIGNED_BYTE
,
190 pass
&= piglit_check_gl_error(GL_NO_ERROR
);
192 /* try to clear invalid region of level 0 */
193 glClearTexSubImage(view
,
196 4, 4, 1, /* width/height/depth */
197 GL_RGBA
, GL_UNSIGNED_BYTE
,
199 pass
&= piglit_check_gl_error(GL_INVALID_OPERATION
);
206 piglit_init(int argc
, char **argv
)
211 /* glClearTexture is either in the GL_ARB_clear_texture
212 * extension or in core in GL 4.4
214 if (piglit_get_gl_version() < 44 &&
215 !piglit_is_extension_supported("GL_ARB_clear_texture")) {
216 printf("OpenGL 4.4 or GL_ARB_clear_texture is required.\n");
217 piglit_report_result(PIGLIT_SKIP
);
220 /* Create a texture using the zero texture */
221 glTexImage2D(GL_TEXTURE_2D
,
224 1, 1, /* width/height */
230 /* Using the zero texture should result in an error even if it
231 * is a valid texture */
232 glClearTexImage(0, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
233 pass
&= piglit_check_gl_error(GL_INVALID_OPERATION
);
235 /* We shouldn't be able to use a texture number that doesn't
237 glClearTexImage(100, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
238 pass
&= piglit_check_gl_error(GL_INVALID_OPERATION
);
240 glGenTextures(1, &tex
);
242 /* We shouldn't be able to use a texture that doesn't have any
244 glClearTexImage(tex
, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
245 pass
&= piglit_check_gl_error(GL_INVALID_OPERATION
);
248 glBindTexture(GL_TEXTURE_2D
, tex
);
249 glTexImage2D(GL_TEXTURE_2D
,
252 1, 1, /* width/height */
258 /* We shouldn't be able to clear a level that doesn't have
260 glClearTexImage(tex
, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
261 pass
&= piglit_check_gl_error(GL_INVALID_OPERATION
);
263 /* But we should be able to clear level 1 */
264 glClearTexImage(tex
, 1, GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
265 pass
&= piglit_check_gl_error(GL_NO_ERROR
);
267 glBindTexture(GL_TEXTURE_2D
, 0);
268 glDeleteTextures(1, &tex
);
270 pass
&= test_sub_clear();
272 pass
&= test_invalid_format(GL_DEPTH_COMPONENT
,
278 pass
&= test_invalid_format(GL_RGBA
,
284 if (piglit_is_extension_supported("GL_ARB_texture_view")) {
285 pass
&= test_texture_view();
288 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);