ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / ati_fragment_shader / render-sources.c
blob9b4f5af3360c94497375ffc0c61952c163817d50
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 * - various data sources for calculations in fragment shader
27 * - texture coordinates
28 * - texture sample
29 * - constant
30 * - primary color
31 * - secondary interpolator
32 * - one, zero
33 * - switch between named fragment shaders
34 * - use undefined default shader (rendering is undefined but shouldn't crash)
37 #include "piglit-util-gl.h"
39 PIGLIT_GL_TEST_CONFIG_BEGIN
41 config.supports_gl_compat_version = 10;
42 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
44 PIGLIT_GL_TEST_CONFIG_END
46 static const float color1[] = {0.2, 0.3, 0.8};
47 static const float color2[] = {0.9, 0.8, 0.3};
48 static const float texcoord[] = {0.2, 0.7, 0.4};
49 static const float texcolor[] = {0.8, 0.1, 0.7};
51 static float result_const[] = {0.0, 0.0, 0.0};
52 static float result_tex[] = {0.0, 0.0, 0.0};
53 static float result_color[] = {0.0, 0.0, 0.0};
55 static GLuint tex;
57 enum {
58 SHADER_TEX = 1,
59 SHADER_CONST,
60 SHADER_COLOR,
63 enum piglit_result
64 piglit_display(void)
66 bool pass = true;
68 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
70 glClearColor(1.0, 0.0, 0.0, 1.0);
71 glClear(GL_COLOR_BUFFER_BIT);
73 glColor3fv(color1);
74 glSecondaryColor3fvEXT(color2);
75 glTexCoord3fv(texcoord);
77 glEnable(GL_TEXTURE_2D);
79 glEnable(GL_FRAGMENT_SHADER_ATI);
80 glBindFragmentShaderATI(0);
81 piglit_draw_rect(0, 0,
82 piglit_width / 4, piglit_height);
83 glBindFragmentShaderATI(SHADER_CONST);
84 piglit_draw_rect(piglit_width / 4, 0,
85 piglit_width / 4, piglit_height);
86 glBindFragmentShaderATI(SHADER_COLOR);
87 piglit_draw_rect(2 * piglit_width / 4, 0,
88 piglit_width / 4, piglit_height);
89 glBindFragmentShaderATI(SHADER_TEX);
90 piglit_draw_rect(3 * piglit_width / 4, 0,
91 piglit_width / 4, piglit_height);
92 glDisable(GL_FRAGMENT_SHADER_ATI);
94 #if 0
95 /* Mesa uses fixed-function when the shader is invalid, but
96 * it's undefined
98 pass = pass && piglit_probe_rect_rgb(0, 0,
99 piglit_width / 4,
100 piglit_height, color1 * texcolor);
101 #endif
102 pass = pass && piglit_probe_rect_rgb(piglit_width / 4, 0,
103 piglit_width / 4,
104 piglit_height, result_const);
105 pass = pass && piglit_probe_rect_rgb(2 * piglit_width / 4, 0,
106 piglit_width / 4,
107 piglit_height, result_color);
108 pass = pass && piglit_probe_rect_rgb(3 * piglit_width / 4, 0,
109 piglit_width / 4,
110 piglit_height, result_tex);
112 piglit_present_results();
114 pass &= piglit_check_gl_error(GL_NO_ERROR);
116 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
119 void
120 piglit_init(int argc, char **argv)
122 unsigned u;
124 piglit_require_extension("GL_ATI_fragment_shader");
126 /* create shaders that use all possible input sources:
127 * texcoord, sample, const, zero, one, pri&sec color
130 glBindFragmentShaderATI(SHADER_TEX);
131 glBeginFragmentShaderATI();
132 glPassTexCoordATI(GL_REG_1_ATI, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI);
133 glSampleMapATI(GL_REG_0_ATI, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI);
134 glColorFragmentOp2ATI(GL_MUL_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE,
135 GL_REG_0_ATI, GL_NONE, GL_NONE,
136 GL_REG_1_ATI, GL_NONE, GL_NONE);
137 glEndFragmentShaderATI();
139 glBindFragmentShaderATI(SHADER_CONST);
140 glBeginFragmentShaderATI();
141 glColorFragmentOp3ATI(GL_LERP_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE,
142 GL_CON_1_ATI, GL_NONE, GL_NONE,
143 GL_ONE, GL_NONE, GL_NONE,
144 GL_ZERO, GL_NONE, GL_NONE);
145 glSetFragmentShaderConstantATI(GL_CON_1_ATI, color2);
146 glEndFragmentShaderATI();
148 glBindFragmentShaderATI(SHADER_COLOR);
149 glBeginFragmentShaderATI();
150 glColorFragmentOp2ATI(GL_MUL_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE,
151 GL_SECONDARY_INTERPOLATOR_ATI, GL_NONE, GL_NONE,
152 GL_PRIMARY_COLOR_ARB, GL_NONE, GL_NONE);
153 glEndFragmentShaderATI();
155 /* create a texture */
157 glGenTextures(1, &tex);
158 glBindTexture(GL_TEXTURE_2D, tex);
159 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_FLOAT,
160 (void*)texcolor);
161 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
162 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
163 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
164 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
166 /* compute the expected results */
168 for (u=0; u<3; u++) {
169 result_const[u] = color2[u];
170 result_tex[u] = texcoord[u] * texcolor[u];
171 result_color[u] = color1[u] * color2[u];
174 if (!piglit_check_gl_error(GL_NO_ERROR))
175 piglit_report_result(PIGLIT_FAIL);