ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_clear_texture / error.c
blob404f318f09deb4de413da2725f742817bb19e75a
1 /*
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
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.
24 /** @file error.c
26 * Tests the various error conditions that glClearTexSubImage should
27 * signal.
30 #include "common.h"
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
42 static bool
43 test_sub_clear(void)
45 GLuint tex;
46 bool pass = true;
48 glGenTextures(1, &tex);
49 glBindTexture(GL_TEXTURE_2D, tex);
50 glTexImage2D(GL_TEXTURE_2D,
51 0, /* level */
52 GL_RGBA,
53 4, 4, /* width/height */
54 0, /* border */
55 GL_RGBA,
56 GL_UNSIGNED_BYTE,
57 NULL);
58 glTexImage2D(GL_TEXTURE_2D,
59 1, /* level */
60 GL_RGBA,
61 2, 2, /* width/height */
62 0, /* border */
63 GL_RGBA,
64 GL_UNSIGNED_BYTE,
65 NULL);
66 glTexImage2D(GL_TEXTURE_2D,
67 2, /* level */
68 GL_RGBA,
69 1, 1, /* width/height */
70 0, /* border */
71 GL_RGBA,
72 GL_UNSIGNED_BYTE,
73 NULL);
74 glBindTexture(GL_TEXTURE_2D, 0);
76 /* test invalid x */
77 glClearTexSubImage(tex,
78 0, /* level */
79 -1, 0, 0, /* x/y/z */
80 1, 1, 1, /* width/height/depth */
81 GL_RGBA, GL_UNSIGNED_BYTE,
82 NULL /* data */);
83 pass &= piglit_check_gl_error(GL_INVALID_OPERATION);
85 /* test invalid y */
86 glClearTexSubImage(tex,
87 0, /* level */
88 0, -1, 0, /* x/y/z */
89 1, 1, 1, /* width/height/depth */
90 GL_RGBA, GL_UNSIGNED_BYTE,
91 NULL /* data */);
92 pass &= piglit_check_gl_error(GL_INVALID_OPERATION);
94 /* test invalid z */
95 glClearTexSubImage(tex,
96 0, /* level */
97 0, 0, -1, /* x/y/z */
98 1, 1, 1, /* width/height/depth */
99 GL_RGBA, GL_UNSIGNED_BYTE,
100 NULL /* data */);
101 pass &= piglit_check_gl_error(GL_INVALID_OPERATION);
103 /* test invalid width */
104 glClearTexSubImage(tex,
105 0, /* level */
106 1, 1, 0, /* x/y/z */
107 4, 1, 1, /* width/height/depth */
108 GL_RGBA, GL_UNSIGNED_BYTE,
109 NULL /* data */);
110 pass &= piglit_check_gl_error(GL_INVALID_OPERATION);
112 /* Test invalid height */
113 glClearTexSubImage(tex,
114 0, /* level */
115 1, 1, 0, /* x/y/z */
116 1, 4, 1, /* width/height/depth */
117 GL_RGBA, GL_UNSIGNED_BYTE,
118 NULL /* data */);
119 pass &= piglit_check_gl_error(GL_INVALID_OPERATION);
121 /* Test invalid depth */
122 glClearTexSubImage(tex,
123 0, /* level */
124 1, 1, 0, /* x/y/z */
125 1, 1, 2, /* width/height/depth */
126 GL_RGBA, GL_UNSIGNED_BYTE,
127 NULL /* data */);
128 pass &= piglit_check_gl_error(GL_INVALID_OPERATION);
130 /* test clearing invalid region of level 1 */
131 glClearTexSubImage(tex,
132 1, /* level */
133 1, 1, 0, /* x/y/z */
134 2, 3, 1, /* width/height/depth */
135 GL_RGBA, GL_UNSIGNED_BYTE,
136 NULL /* data */);
137 pass &= piglit_check_gl_error(GL_INVALID_OPERATION);
139 /* Test no error */
140 glClearTexSubImage(tex,
141 0, /* level */
142 1, 1, 0, /* x/y/z */
143 2, 3, 1, /* width/height/depth */
144 GL_RGBA, GL_UNSIGNED_BYTE,
145 NULL /* data */);
146 pass &= piglit_check_gl_error(GL_NO_ERROR);
148 glDeleteTextures(1, &tex);
150 return pass;
154 static bool
155 test_texture_view(void)
157 GLuint tex, view;
158 bool pass = true;
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,
176 2, /* level */
177 0, 0, 0, /* x/y/z */
178 1, 1, 1, /* width/height/depth */
179 GL_RGBA, GL_UNSIGNED_BYTE,
180 NULL /* data */);
181 pass &= piglit_check_gl_error(GL_INVALID_OPERATION);
183 /* clearing all of level 0 should work */
184 glClearTexSubImage(view,
185 0, /* level */
186 0, 0, 0, /* x/y/z */
187 2, 2, 1, /* width/height/depth */
188 GL_RGBA, GL_UNSIGNED_BYTE,
189 NULL /* data */);
190 pass &= piglit_check_gl_error(GL_NO_ERROR);
192 /* try to clear invalid region of level 0 */
193 glClearTexSubImage(view,
194 0, /* level */
195 0, 0, 0, /* x/y/z */
196 4, 4, 1, /* width/height/depth */
197 GL_RGBA, GL_UNSIGNED_BYTE,
198 NULL /* data */);
199 pass &= piglit_check_gl_error(GL_INVALID_OPERATION);
201 return pass;
205 void
206 piglit_init(int argc, char **argv)
208 GLuint tex;
209 bool pass = true;
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,
222 0, /* level */
223 GL_RGBA,
224 1, 1, /* width/height */
225 0, /* border */
226 GL_RGBA,
227 GL_UNSIGNED_BYTE,
228 NULL);
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
236 * exist yet */
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
243 * data yet */
244 glClearTexImage(tex, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
245 pass &= piglit_check_gl_error(GL_INVALID_OPERATION);
247 /* Set level 1 */
248 glBindTexture(GL_TEXTURE_2D, tex);
249 glTexImage2D(GL_TEXTURE_2D,
250 1, /* level */
251 GL_RGBA,
252 1, 1, /* width/height */
253 0, /* border */
254 GL_RGBA,
255 GL_UNSIGNED_BYTE,
256 NULL);
258 /* We shouldn't be able to clear a level that doesn't have
259 * data yet */
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,
273 GL_DEPTH_COMPONENT,
274 GL_UNSIGNED_INT,
275 GL_RGBA,
276 GL_UNSIGNED_BYTE);
278 pass &= test_invalid_format(GL_RGBA,
279 GL_RGBA,
280 GL_UNSIGNED_BYTE,
281 GL_DEPTH_COMPONENT,
282 GL_UNSIGNED_INT);
284 if (piglit_is_extension_supported("GL_ARB_texture_view")) {
285 pass &= test_texture_view();
288 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
291 enum piglit_result
292 piglit_display(void)
294 /* unused */
295 return PIGLIT_FAIL;