ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / ati_fragment_shader / render-precedence.c
blobdf47db0a9c43ba61cdf9ca13986f9eb507b85c67
1 /*
2 * Copyright © 2017 Miklós Máté
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 /**
25 * Tests rendering with GL_ATI_fragment_shader:
26 * - precedence between ATI_fragment_shader, ARB_fragment_program, GLSL
27 * - ARB_fragment_program overrides ATI_fragment_shader
28 * - GLSL overrides both
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config.supports_gl_compat_version = 10;
36 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
38 PIGLIT_GL_TEST_CONFIG_END
40 static const float color1[] = {0.2, 0.3, 0.8};
41 static const float color2[] = {0.9, 0.8, 0.3};
42 static const float texcoord[] = {0.2, 0.7, 0.4};
44 static bool have_fp = false;
45 static bool have_fs = false;
47 static GLuint glslprog;
49 enum piglit_result
50 piglit_display(void)
52 bool pass = true;
54 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
56 glClearColor(1.0, 0.0, 0.0, 1.0);
57 glClear(GL_COLOR_BUFFER_BIT);
59 glColor3fv(color1);
60 glSecondaryColor3fvEXT(color2);
61 glTexCoord3fv(texcoord);
63 glEnable(GL_FRAGMENT_SHADER_ATI);
64 piglit_draw_rect(0, 0, piglit_width / 4, piglit_height);
65 if (have_fp) {
66 glEnable(GL_FRAGMENT_PROGRAM_ARB);
67 piglit_draw_rect(piglit_width / 4, 0,
68 piglit_width / 4, piglit_height);
69 glDisable(GL_FRAGMENT_PROGRAM_ARB);
71 if (have_fs) {
72 glUseProgram(glslprog);
73 piglit_draw_rect(2 * piglit_width / 4, 0,
74 piglit_width / 4, piglit_height);
75 glUseProgram(0);
77 if (have_fp && have_fs) {
78 glUseProgram(glslprog);
79 glEnable(GL_FRAGMENT_PROGRAM_ARB);
80 piglit_draw_rect(3 * piglit_width / 4, 0,
81 piglit_width / 4, piglit_height);
82 glUseProgram(0);
83 glDisable(GL_FRAGMENT_PROGRAM_ARB);
85 glDisable(GL_FRAGMENT_SHADER_ATI);
87 pass = pass && piglit_probe_rect_rgb(0, 0,
88 piglit_width / 4,
89 piglit_height, color2);
90 if (have_fp)
91 pass = pass && piglit_probe_rect_rgb(piglit_width / 4, 0,
92 piglit_width / 4,
93 piglit_height, texcoord);
94 if (have_fs)
95 pass = pass && piglit_probe_rect_rgb(2 * piglit_width / 4, 0,
96 piglit_width / 4,
97 piglit_height, color1);
98 if (have_fp && have_fs)
99 pass = pass && piglit_probe_rect_rgb(3 * piglit_width / 4, 0,
100 piglit_width / 4,
101 piglit_height, color1);
103 piglit_present_results();
105 pass &= piglit_check_gl_error(GL_NO_ERROR);
107 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
110 const char *arbfp_str =
111 "!!ARBfp1.0\n"
112 "MOV result.color, fragment.texcoord[0];\n"
113 "END";
115 const char *glslfs_str =
116 "void main() { gl_FragColor = gl_Color; }";
118 void
119 piglit_init(int argc, char **argv)
121 piglit_require_extension("GL_ATI_fragment_shader");
123 /* create shaders */
125 glBeginFragmentShaderATI();
126 glColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE,
127 GL_SECONDARY_INTERPOLATOR_ATI, GL_NONE, GL_NONE);
128 glEndFragmentShaderATI();
130 if (piglit_is_extension_supported("GL_ARB_fragment_program")) {
131 have_fp = true;
132 piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, arbfp_str);
135 if (piglit_is_extension_supported("GL_ARB_fragment_shader")) {
136 have_fs = true;
137 glslprog = piglit_build_simple_program(NULL, glslfs_str);
140 if (!piglit_check_gl_error(GL_NO_ERROR))
141 piglit_report_result(PIGLIT_FAIL);