2 * Copyright © 2016 Jamey Sharp
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
21 * DEALINGS IN THE SOFTWARE.
25 * \file shadersource-no-compile.c
26 * OpenGL 4.5 Core Profile section 7.1, in the documentation for CompileShader,
27 * says: "Changing the source code of a shader object with ShaderSource does not
28 * change its compile status or the compiled shader code."
30 * This test creates a shader, compiles it, changes its source, and links it.
31 * The spec requires rendering done with this shader to be consistent with the
32 * old source, not the new source, since the shader isn't compiled again after
33 * the source is changed.
35 * According to Karol Herbst, the game "Divinity: Original Sin - Enhanced
36 * Edition" depends on this odd quirk of the spec. See:
37 * https://lists.freedesktop.org/archives/mesa-dev/2016-March/109789.html
39 #include "piglit-util-gl.h"
41 PIGLIT_GL_TEST_CONFIG_BEGIN
43 config
.supports_gl_compat_version
= 20;
45 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
47 PIGLIT_GL_TEST_CONFIG_END
49 static const char vs_text
[] =
50 "void main() { gl_Position = gl_Vertex; }";
52 /* good_fs_text uses a constant green color, while bad_fs_text uses a
53 * constant red color, so that we can tell which version of the fragment
54 * shader got executed. Both are distinct from the clear-color so we can
55 * tell if the shader ran at all.
58 static const char good_fs_text
[] =
59 "void main() { gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); }";
61 static const char bad_fs_text
[] =
62 "void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }";
67 static const float green
[3] = { 0.0, 1.0, 0.0 };
69 glClear(GL_COLOR_BUFFER_BIT
);
71 piglit_draw_rect(-1, -1, 2, 2);
72 if (!piglit_probe_pixel_rgb(15, 15, green
))
79 piglit_init(int argc
, char **argv
)
81 GLuint vs
= piglit_compile_shader_text(GL_VERTEX_SHADER
, vs_text
);
82 GLuint fs
= piglit_compile_shader_text(GL_FRAGMENT_SHADER
, good_fs_text
);
83 const GLchar
*bad_fs_texts
[] = { bad_fs_text
};
86 /* Change the shader source, but don't recompile it before linking. */
87 glShaderSource(fs
, 1, bad_fs_texts
, NULL
);
88 prog
= piglit_link_simple_program(vs
, fs
);
90 piglit_report_result(PIGLIT_FAIL
);
97 glClearColor(0.3, 0.3, 0.3, 0.0);