fbo-mrt-alphatest: Actually require MRTs to be available.
[piglit.git] / tests / spec / arb_direct_state_access / texture-errors.c
blobf8bc6f593c2610a2d82709f3d38b0f7672b995c6
1 /*
2 * Copyright (c) 2010 VMware, Inc.
3 * Copyright (c) 2014 Intel Corporation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NON-INFRINGEMENT. IN NO EVENT SHALL VMWARE AND/OR THEIR SUPPLIERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
26 /**
27 * @file
28 * Adapted from teximage-errors.c to test ARB_direct_state_access by
29 * Laura Ekstrand <laura@jlekstrand.net>.
30 * Tests gl*Texture* functions for error reporting.
33 #include "piglit-util-gl.h"
35 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config.supports_gl_compat_version = 20;
38 config.supports_gl_core_version = 31;
39 config.window_visual = PIGLIT_GL_VISUAL_RGB;
40 config.khr_no_error_support = PIGLIT_HAS_ERRORS;
42 PIGLIT_GL_TEST_CONFIG_END
44 /** Test texture size errors and subtexture position errors */
45 static bool
46 test_pos_and_sizes(void)
48 bool pass = true;
49 GLuint name;
51 /* all of these should generate GL_INVALID_VALUE */
52 glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, -16, 0, GL_RGBA, GL_FLOAT, NULL);
53 pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
55 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, -6, -5, 0, GL_RGBA, GL_FLOAT, NULL);
56 pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
58 glTexImage2D(GL_TEXTURE_2D, -2, GL_RGBA, 16, 16, 0, GL_RGBA, GL_FLOAT, NULL);
59 pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
61 glTexImage2D(GL_TEXTURE_2D, 2000, GL_RGBA, 16, 16, 0, GL_RGBA, GL_FLOAT, NULL);
62 pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
64 /* Setup dsa. */
65 glCreateTextures(GL_TEXTURE_2D, 1, &name);
66 glBindTextureUnit(0, name); /* Since next command isn't bindless. */
68 /* setup valid 2D texture for subsequent TexSubImage calls */
69 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_FLOAT, NULL);
71 glTextureSubImage2D(name, 0, 6, 6, 100, 100, GL_RGBA, GL_FLOAT, NULL);
72 pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
74 glTextureSubImage2D(name, 0, -6, -6, 10, 10, GL_RGBA, GL_FLOAT, NULL);
75 pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
77 glCopyTextureSubImage2D(name, 0, -6, -6, 2, 2, 10, 10);
78 pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
80 glCopyTextureSubImage2D(name, 0, 6, 6, 2, 2, 200, 200);
81 pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
83 /* mipmap level 1 doesn't exist */
84 glTextureSubImage2D(name, 1, 0, 0, 8, 8, GL_RGBA, GL_FLOAT, NULL);
85 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
87 /* mipmap level 2 doesn't exist */
88 glCopyTextureSubImage2D(name, 2, 0, 0, 0, 0, 4, 4);
89 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
91 /* To test 1D and 3D entry points, let's try using the wrong functions. */
92 glTextureSubImage1D(name, 0, 0, 4, GL_RGBA, GL_FLOAT, NULL);
93 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
95 glTextureSubImage3D(name, 0, 0, 0, 0, 4, 4, 4, GL_RGBA, GL_FLOAT, NULL);
96 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
98 glCopyTextureSubImage1D(name, 0, 0, 0, 0, 4);
99 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
101 glCopyTextureSubImage3D(name, 0, 0, 0, 0, 0, 0, 4, 4);
102 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
104 return pass;
108 * The texture parameter must be an existing texture object as returned
109 * by glCreateTextures
111 static bool
112 test_target_name(void)
114 static const GLuint badname = 250;
115 static const GLfloat fvec[2] = { 1.0, 1.0 };
116 static const GLint ivec[2] = { -1, 1 };
117 static const GLuint uvec[2] = { 1, 1 };
118 bool pass = true;
120 glTextureParameteri(badname, GL_TEXTURE_MAX_LEVEL, 4);
121 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
123 glTextureParameterf(badname, GL_TEXTURE_MAX_LEVEL, 4.0);
124 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
126 glTextureParameterfv(badname, GL_TEXTURE_MAX_LEVEL, fvec);
127 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
129 glTextureParameteriv(badname, GL_TEXTURE_MAX_LEVEL, ivec);
130 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
132 glTextureParameterIiv(badname, GL_TEXTURE_MAX_LEVEL, ivec);
133 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
135 glTextureParameterIuiv(badname, GL_TEXTURE_MAX_LEVEL, uvec);
136 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
138 piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
139 "glTextureParameter: GL_INVALID_OPERATION "
140 "on bad texture");
141 return pass;
144 /* same as test_target_name, but for the getter functions */
145 static bool
146 test_getter_target_name(void)
148 static const GLuint badname = 250;
149 GLfloat f;
150 GLuint u;
151 GLint i;
152 bool pass = true;
154 glGetTextureParameterfv(badname, GL_TEXTURE_MAX_LEVEL, &f);
155 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
157 glGetTextureParameteriv(badname, GL_TEXTURE_MAX_LEVEL, &i);
158 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
160 glGetTextureParameterIiv(badname, GL_TEXTURE_MAX_LEVEL, &i);
161 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
163 glGetTextureParameterIuiv(badname, GL_TEXTURE_MAX_LEVEL, &u);
164 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
166 piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
167 "glGetTextureParameter: "
168 "GL_INVALID_OPERATION on bad texture");
169 return pass;
172 static bool
173 test_getter_pname(void)
175 GLuint name;
176 GLfloat f;
177 GLuint u;
178 GLint i;
179 bool pass = true;
181 /* Setup dsa. */
182 glCreateTextures(GL_TEXTURE_2D, 1, &name);
183 glBindTextureUnit(0, name); /* Since next command isn't bindless. */
185 glGetTextureParameterfv(name, GL_TEXTURE_1D, &f);
186 pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;
188 glGetTextureParameteriv(name, GL_TEXTURE_1D, &i);
189 pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;
191 glGetTextureParameterIiv(name, GL_TEXTURE_1D, &i);
192 pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;
194 glGetTextureParameterIuiv(name, GL_TEXTURE_1D, &u);
195 pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;
197 piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
198 "glGetTextureParameter: GL_INVALID_ENUM "
199 "on bad pname");
200 return pass;
203 static bool
204 test_pname(void)
206 GLuint name;
207 const static GLfloat f = 1.0;
208 const static GLuint u = 1;
209 const static GLint i = -5;
210 bool pass = true;
212 /* Setup dsa. */
213 glCreateTextures(GL_TEXTURE_2D, 1, &name);
214 glBindTextureUnit(0, name); /* Since next command isn't bindless. */
216 glTextureParameterfv(name, GL_TEXTURE_1D, &f);
217 pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;
219 glTextureParameteriv(name, GL_TEXTURE_1D, &i);
220 pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;
222 glTextureParameterIiv(name, GL_TEXTURE_1D, &i);
223 pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;
225 glTextureParameterIuiv(name, GL_TEXTURE_1D, &u);
226 pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;
228 piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
229 "glTextureParameter: GL_INVALID_ENUM on "
230 "bad pname");
231 return pass;
234 /* GL_INVALID_ENUM is generated if glTextureParamter{if} is called for a
235 * non-scalar parameter
237 static bool
238 test_scalar_vector(void)
240 bool pass = true;
241 const static GLfloat f = 1.0;
242 const static GLint i = -1;
243 GLuint name;
245 /* Setup dsa. */
246 glCreateTextures(GL_TEXTURE_2D, 1, &name);
247 glBindTextureUnit(0, name); /* Since next command isn't bindless. */
249 glTextureParameteri(name, GL_TEXTURE_BORDER_COLOR, i);
250 pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;
252 glTextureParameterf(name, GL_TEXTURE_BORDER_COLOR, f);
253 pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;
255 piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
256 "glTextureParameter{if}: GL_INVALID_ENUM "
257 "for non-scalars");
258 return pass;
261 /* GL_INVALID_OPERATION (GL 4.6) is generated if the effective target is either
262 * GL_TEXTURE_2D_MULTISAMPLE or GL_TEXTURE_2D_MULTISAMPLE_ARRAY, and pname is
263 * any of the sampler states.
265 /* XXX: Is this actually a valid implementation? */
266 static bool
267 test_multisample(void)
269 bool pass = true;
270 static const GLfloat f = 1.0;
271 static const GLint i = -1;
272 static const GLfloat fvec[2] = { 1.0, -1.0 };
273 static const GLint ivec[2] = { 1, -1 };
274 static const GLuint uvec[2] = { 1, 4 };
275 GLuint name;
277 /* GL_TEXTURE_2D_MULTISAMPLE_ARRAY */
278 glCreateTextures(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 1, &name);
279 glBindTextureUnit(0, name); /* Since next command isn't bindless. */
281 glTextureParameteri(name, GL_TEXTURE_WRAP_R, i);
282 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
284 glTextureParameterf(name, GL_TEXTURE_WRAP_R, f);
285 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
287 glTextureParameterfv(name, GL_TEXTURE_WRAP_R, fvec);
288 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
290 glTextureParameteriv(name, GL_TEXTURE_WRAP_R, ivec);
291 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
293 glTextureParameterIiv(name, GL_TEXTURE_WRAP_R, ivec);
294 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
296 glTextureParameterIuiv(name, GL_TEXTURE_WRAP_R, uvec);
297 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
299 /* GL_TEXTURE_2D_MULTISAMPLE */
300 glDeleteTextures(1, &name);
301 glCreateTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &name);
302 glBindTextureUnit(0, name); /* Since next command isn't bindless. */
304 glTextureParameteri(name, GL_TEXTURE_WRAP_R, i);
305 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
307 glTextureParameterf(name, GL_TEXTURE_WRAP_R, f);
308 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
310 glTextureParameterfv(name, GL_TEXTURE_WRAP_R, fvec);
311 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
313 glTextureParameteriv(name, GL_TEXTURE_WRAP_R, ivec);
314 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
316 glTextureParameterIiv(name, GL_TEXTURE_WRAP_R, ivec);
317 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
319 glTextureParameterIuiv(name, GL_TEXTURE_WRAP_R, uvec);
320 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
322 piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
323 "glTextureParameter: GL_INVALID_OPERATION if "
324 "multisample+sampler state");
325 return pass;
328 /* GL_INVALID_ENUM is generated if the effective target is GL_TEXTURE_RECTANGLE
329 * and either of pnames GL_TEXTURE_WRAP_S or GL_TEXTURE_WRAP_T is set to either
330 * GL_MIRROR_CLAMP_TO_EDGE, GL_MIRRORED_REPEAT or GL_REPEAT.
332 static bool
333 test_texture_rec(void)
335 bool pass = true;
336 GLuint name;
338 /* GL_TEXTURE_2D_MULTISAMPLE_ARRAY */
339 glCreateTextures(GL_TEXTURE_RECTANGLE, 1, &name);
340 glBindTextureUnit(0, name); /* Since next command isn't bindless. */
342 glTextureParameteri(name, GL_TEXTURE_WRAP_S, GL_MIRROR_CLAMP_TO_EDGE);
343 pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;
345 glTextureParameteri(name, GL_TEXTURE_WRAP_T, GL_MIRROR_CLAMP_TO_EDGE);
346 pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;
348 glTextureParameteri(name, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
349 pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;
351 glTextureParameteri(name, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
352 pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;
354 glTextureParameteri(name, GL_TEXTURE_WRAP_S, GL_REPEAT);
355 pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;
357 glTextureParameteri(name, GL_TEXTURE_WRAP_T, GL_REPEAT);
358 pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;
360 piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
361 "glTextureParameter: GL_INVALID_ENUM in "
362 "texture_rectangle case");
363 return pass;
366 /* GL_INVALID_ENUM is generated if the effective target is GL_TEXTURE_RECTANGLE
367 * and pname GL_TEXTURE_MIN_FILTER is set to a value other than GL_NEAREST or
368 * GL_LINEAR (no mipmap filtering is permitted).
370 static bool
371 test_texture_rec_min_filter(void)
373 bool pass = true;
374 GLuint name;
376 glCreateTextures(GL_TEXTURE_RECTANGLE, 1, &name);
377 glBindTextureUnit(0, name); /* Since next command isn't bindless. */
379 glTextureParameteri(name, GL_TEXTURE_MIN_FILTER, 0);
380 pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;
382 piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
383 "glTextureParameter: GL_INVALID_ENUM for "
384 "texture_rectangle+min_filter");
385 return pass;
388 /* GL_INVALID_OPERATION is generated if the effective target is either
389 * GL_TEXTURE_2D_MULTISAMPLE or GL_TEXTURE_2D_MULTISAMPLE_ARRAY, and pname
390 * GL_TEXTURE_BASE_LEVEL is set to a value other than zero.
392 static bool
393 test_multisample_texture_base(void)
395 bool pass = true;
396 GLuint name;
398 glCreateTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &name);
399 glBindTextureUnit(0, name); /* Since next command isn't bindless. */
401 glTextureParameteri(name, GL_TEXTURE_BASE_LEVEL, 1);
402 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
404 glCreateTextures(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 1, &name);
405 glBindTextureUnit(0, name); /* Since next command isn't bindless. */
407 glTextureParameteri(name, GL_TEXTURE_BASE_LEVEL, 1);
408 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
410 piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
411 "glTextureParameter: GL_INVALID_OPERATION "
412 "for multisample+texture_base");
413 return pass;
416 /* GL_INVALID_OPERATION is generated if the effective target is
417 * GL_TEXTURE_RECTANGLE and pname GL_TEXTURE_BASE_LEVEL is set to any value
418 * other than zero.
420 static bool
421 test_texture_rec_texture_base(void)
423 bool pass = true;
424 GLuint name;
426 glCreateTextures(GL_TEXTURE_RECTANGLE, 1, &name);
427 glBindTextureUnit(0, name); /* Since next command isn't bindless. */
429 glTextureParameteri(name, GL_TEXTURE_BASE_LEVEL, 1);
430 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
432 piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
433 "glTextureParameter: GL_INVALID_OPERATION "
434 "for texture_rectangle+min_filter");
435 return pass;
438 /* GL_INVALID_VALUE is generated if pname is GL_TEXTURE_BASE_LEVEL or
439 * GL_TEXTURE_MAX_LEVEL, and param or params is negative.
441 static bool
442 test_texture_level_negative(void)
444 bool pass = true;
445 GLuint name;
447 glCreateTextures(GL_TEXTURE_2D, 1, &name);
448 glBindTextureUnit(0, name); /* Since next command isn't bindless. */
450 glTextureParameteri(name, GL_TEXTURE_BASE_LEVEL, -1);
451 pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
453 glTextureParameteri(name, GL_TEXTURE_MAX_LEVEL, -1);
454 pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
456 piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
457 "glTextureParameter: GL_INVALID_VALUE for "
458 "negative tex_*_level");
459 return pass;
462 enum piglit_result
463 piglit_display(void)
465 bool pass = true;
467 pass = test_pos_and_sizes() && pass;
468 pass = test_target_name() && pass;
469 pass = test_getter_target_name() && pass;
470 pass = test_pname() && pass;
471 pass = test_getter_pname() && pass;
472 pass = test_scalar_vector() && pass;
473 pass = test_texture_level_negative() && pass;
474 if (piglit_is_extension_supported("GL_ARB_texture_multisample")){
475 pass = test_multisample() && pass;
476 pass = test_multisample_texture_base() && pass;
478 if (piglit_is_extension_supported("GL_ARB_texture_rectangle")) {
479 pass = test_texture_rec() && pass;
480 pass = test_texture_rec_min_filter() && pass;
481 pass = test_texture_rec_texture_base() && pass;
484 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
488 void
489 piglit_init(int argc, char **argv)
491 piglit_require_extension("GL_ARB_direct_state_access");