2 * Copyright © 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
25 * \name ActiveShaderProgram-invalid-program.c
26 * Verify glActiveShaderProgram with invalid program parameter
28 * There are several cases outlined in the GL 4.4 spec where
29 * glActiveShaderProgram should generate specific errors. In addition,
30 * section 2.3.1 (Errors) says:
32 * "Currently, when an error flag is set, results of GL operation are
33 * undefined only if an OUT_OF_MEMORY error has occurred. In other cases,
34 * there are no side effects unless otherwise noted; the command which
35 * generates the error is ignored so that it has no effect on GL state or
36 * framebuffer contents."
38 * After calling glActiveShaderProgram with an invalid parameter, verify that
39 * the active program state has not been modified.
42 #include "piglit-util-gl.h"
43 #include "sso-common.h"
45 PIGLIT_GL_TEST_CONFIG_BEGIN
47 config
.supports_gl_compat_version
= 20;
48 config
.supports_gl_core_version
= 31;
50 PIGLIT_GL_TEST_CONFIG_END
52 static const char vs_code_template
[] =
54 "void main() { gl_Position = vec4(0); }\n"
57 static const char *const invalid_code
=
58 "#version 123456789\n"
59 "void main() { gl_Position = jambon_banh_mi(); }\n"
63 piglit_init(int argc
, char **argv
)
71 unsigned glsl_version
;
74 piglit_require_extension("GL_ARB_separate_shader_objects");
76 glsl_version
= pick_a_glsl_version();
78 glGenProgramPipelines(1, &pipe
);
79 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
81 glBindProgramPipeline(pipe
);
83 (void)!asprintf(&source
, vs_code_template
, glsl_version
);
84 vs_prog
= glCreateShaderProgramv(GL_VERTEX_SHADER
, 1,
85 (const GLchar
*const *) &source
);
86 pass
= piglit_link_check_status(vs_prog
) && pass
;
88 /* First, make a valid program active.
90 glActiveShaderProgram(pipe
, vs_prog
);
91 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
93 /* Next, try to make an invalid program active and verify that the
94 * correct error is generated. Also make sure the old program is
97 * Section 7.4 (Program Pipeline Objects) under ActiveShaderProgram of
98 * the OpenGL 4.4 spec says:
100 * "An INVALID_VALUE error is generated if program is not zero and
101 * is not the name of either a program or shader object."
103 glActiveShaderProgram(pipe
, ~vs_prog
);
104 pass
= piglit_check_gl_error(GL_INVALID_VALUE
) && pass
;
106 glGetProgramPipelineiv(pipe
, GL_ACTIVE_PROGRAM
, (GLint
*) &active_prog
);
107 if (active_prog
!= vs_prog
) {
108 printf("glActiveShaderProgram with an invalid program name "
109 "changed the active program state.\n");
112 glActiveShaderProgram(pipe
, vs_prog
);
115 /* Try the same thing with a valid shader object (that is not part of
116 * a linked program). Verify that the correct error is generated, and
117 * make sure the old program is still active.
119 * Section 7.4 (Program Pipeline Objects) under ActiveShaderProgram of
120 * the OpenGL 4.4 spec says:
122 * "An INVALID_OPERATION error is generated if program is the name
123 * of a shader object."
125 shader
= piglit_compile_shader_text(GL_VERTEX_SHADER
, source
);
126 glActiveShaderProgram(pipe
, shader
);
127 pass
= piglit_check_gl_error(GL_INVALID_OPERATION
) && pass
;
129 glGetProgramPipelineiv(pipe
, GL_ACTIVE_PROGRAM
, (GLint
*) &active_prog
);
130 if (active_prog
!= vs_prog
) {
131 printf("glActiveShaderProgram with a shader object "
132 "changed the active program state.\n");
135 glActiveShaderProgram(pipe
, vs_prog
);
138 /* Finally, try the same thing with a valid program that is not
139 * linked. Verify that the correct error is generated, and make sure
140 * the old program is still active.
142 * Section 7.4 (Program Pipeline Objects) under ActiveShaderProgram of
143 * the OpenGL 4.4 spec says:
145 * "An INVALID_OPERATION error is generated if program is not zero
146 * and has not been linked, or was last linked unsuccessfully."
148 unlinked_prog
= glCreateShaderProgramv(GL_VERTEX_SHADER
, 1,
149 (const GLchar
*const *) &invalid_code
);
151 glActiveShaderProgram(pipe
, unlinked_prog
);
152 pass
= piglit_check_gl_error(GL_INVALID_OPERATION
) && pass
;
154 glGetProgramPipelineiv(pipe
, GL_ACTIVE_PROGRAM
, (GLint
*) &active_prog
);
155 if (active_prog
!= vs_prog
) {
156 printf("glActiveShaderProgram with an unlinked program "
157 "changed the active program state.\n");
160 glActiveShaderProgram(pipe
, vs_prog
);
165 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);