ovr_multiview: add some basic glsl tests
[piglit.git] / tests / spec / ext_clear_texture / error.c
blobce9506e135a532edd2183d87f1aa4ae8fb33c481
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_es_version = 31;
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 glClearTexSubImageEXT(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 glClearTexSubImageEXT(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 glClearTexSubImageEXT(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 glClearTexSubImageEXT(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 glClearTexSubImageEXT(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 glClearTexSubImageEXT(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 glClearTexSubImageEXT(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 glClearTexSubImageEXT(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 glClearTexSubImageEXT(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 glClearTexSubImageEXT(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 glClearTexSubImageEXT(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 piglit_require_extension("GL_EXT_clear_texture");
213 /* Create a texture using the zero texture */
214 glTexImage2D(GL_TEXTURE_2D,
215 0, /* level */
216 GL_RGBA,
217 1, 1, /* width/height */
218 0, /* border */
219 GL_RGBA,
220 GL_UNSIGNED_BYTE,
221 NULL);
223 /* Using the zero texture should result in an error even if it
224 * is a valid texture */
225 glClearTexImageEXT(0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
226 pass &= piglit_check_gl_error(GL_INVALID_OPERATION);
228 /* We shouldn't be able to use a texture number that doesn't
229 * exist yet */
230 glClearTexImageEXT(100, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
231 pass &= piglit_check_gl_error(GL_INVALID_OPERATION);
233 glGenTextures(1, &tex);
235 /* We shouldn't be able to use a texture that doesn't have any
236 * data yet */
237 glClearTexImage(tex, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
238 pass &= piglit_check_gl_error(GL_INVALID_OPERATION);
240 /* Set level 1 */
241 glBindTexture(GL_TEXTURE_2D, tex);
242 glTexImage2D(GL_TEXTURE_2D,
243 1, /* level */
244 GL_RGBA,
245 1, 1, /* width/height */
246 0, /* border */
247 GL_RGBA,
248 GL_UNSIGNED_BYTE,
249 NULL);
251 /* We shouldn't be able to clear a level that doesn't have
252 * data yet */
253 glClearTexImage(tex, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
254 pass &= piglit_check_gl_error(GL_INVALID_OPERATION);
256 /* But we should be able to clear level 1 */
257 glClearTexImage(tex, 1, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
258 pass &= piglit_check_gl_error(GL_NO_ERROR);
260 glBindTexture(GL_TEXTURE_2D, 0);
261 glDeleteTextures(1, &tex);
263 pass &= test_sub_clear();
265 pass &= test_invalid_format(GL_DEPTH_COMPONENT,
266 GL_DEPTH_COMPONENT,
267 GL_UNSIGNED_INT,
268 GL_RGBA,
269 GL_UNSIGNED_BYTE);
271 pass &= test_invalid_format(GL_RGBA,
272 GL_RGBA,
273 GL_UNSIGNED_BYTE,
274 GL_DEPTH_COMPONENT,
275 GL_UNSIGNED_INT);
277 if (piglit_is_extension_supported("GL_ARB_texture_view")) {
278 pass &= test_texture_view();
281 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
284 enum piglit_result
285 piglit_display(void)
287 /* unused */
288 return PIGLIT_FAIL;