1 /* Copyright © 2011 Intel Corporation
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice (including the next
11 * paragraph) shall be included in all copies or substantial portions of the
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * \file bindfragdataindexed-invalid-parameters.c
25 * Verify that passing invalid parameters to glBindFragDataLocationIndexed
26 * generates the correct errors.
28 * \author Ian Romanick + Dave Airlie (extended tests)
30 #include "piglit-util-gl.h"
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 #ifdef PIGLIT_USE_OPENGL
35 config
.supports_gl_compat_version
= 10;
36 #else // PIGLIT_USE_OPENGLES3
37 config
.supports_gl_es_version
= 30;
39 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
40 config
.khr_no_error_support
= PIGLIT_HAS_ERRORS
;
42 PIGLIT_GL_TEST_CONFIG_END
50 void piglit_init(int argc
, char **argv
)
52 GLint max_draw_buffers
, max_dual_source
;
55 #ifdef PIGLIT_USE_OPENGL
56 piglit_require_gl_version(30);
57 piglit_require_extension("GL_ARB_blend_func_extended");
58 #else // PIGLIT_USE_OPENGLES3
59 piglit_require_extension("GL_EXT_blend_func_extended");
62 glGetIntegerv(GL_MAX_DRAW_BUFFERS
, &max_draw_buffers
);
63 glGetIntegerv(GL_MAX_DUAL_SOURCE_DRAW_BUFFERS
, &max_dual_source
);
65 /* Page 237 (page 253 of the PDF) of the OpenGL 3.0 spec says:
67 * "BindFragDataLocation may be issued before any shader objects
68 * are attached to a program object."
70 * As a result, all of the invalid location tests can be performed
71 * without a shader at all. Only a program object is necessary.
73 prog
= glCreateProgram();
74 if (!piglit_check_gl_error(GL_NO_ERROR
))
75 piglit_report_result(PIGLIT_FAIL
);
77 /* Page 236 (page 252 of the PDF) of the OpenGL 3.0 spec says:
79 * "The error INVALID VALUE is generated if colorNumber is equal
80 * or greater than MAX DRAW BUFFERS."
82 * Since the colorNumber parameter is unsigned, this statement means
83 * an error should be generated if a negative number is used.
85 printf("Trying location = -1...\n");
86 glBindFragDataLocationIndexed(prog
, -1, 0, "foo");
87 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
88 piglit_report_result(PIGLIT_FAIL
);
90 printf("Trying location = GL_MAX_DRAW_BUFFERS...\n");
91 glBindFragDataLocationIndexed(prog
, max_draw_buffers
, 0, "foo");
92 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
93 piglit_report_result(PIGLIT_FAIL
);
96 /* ARB_blend_func_extended says,
97 * The error INVALID_VALUE is generated if <colorNumber> is equal
98 * or greater than MAX_DRAW_BUFFERS and <index> is zero, or if
99 * <colorNumber> is equal or greater than MAX_DUAL_SOURCE_DRAW_BUFFERS
100 * and <index> is greater than or equal to one.
102 printf("Trying index > 1...\n");
103 glBindFragDataLocationIndexed(prog
, 0, 2, "foo");
104 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
105 piglit_report_result(PIGLIT_FAIL
);
107 printf("Trying location = GL_MAX_DUAL_SOURCE_DRAW_BUFFERS with index 1...\n");
108 glBindFragDataLocationIndexed(prog
, max_dual_source
, 1, "foo");
109 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
110 piglit_report_result(PIGLIT_FAIL
);
112 /* Page 236 (page 252 of the PDF) of the OpenGL 3.0 spec says:
114 * "The error INVALID_OPERATION is generated if name starts with
115 * the reserved gl prefix."
117 * This was changed in a later version of the spec. Page 279 (page
118 * 296 of the PDF) of the OpenGL 4.2 Core spec says:
120 * "The error INVALID_OPERATION is generated if name starts with
121 * the reserved gl_ prefix."
123 * The OpenGL 4.2 spec also matches the specified behavior of
124 * glBindAttribLocation as far back as OpenGL 2.0.
126 printf("Trying name = `gl_FragColor'...\n");
127 glBindFragDataLocationIndexed(prog
, 0, 0, "gl_FragColor");
128 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
129 piglit_report_result(PIGLIT_FAIL
);
131 printf("Trying name = `gl_FragDepth'...\n");
132 glBindFragDataLocationIndexed(prog
, 0, 0, "gl_FragDepth");
133 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
134 piglit_report_result(PIGLIT_FAIL
);
136 printf("Trying name = `gl_'...\n");
137 glBindFragDataLocationIndexed(prog
, 0, 0, "gl_");
138 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
139 piglit_report_result(PIGLIT_FAIL
);
141 piglit_report_result(PIGLIT_PASS
);