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
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 * Tests rendering with GL_ATI_fragment_shader:
26 * - using local and global constants
27 * - updating global constants
30 #include "piglit-util-gl.h"
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config
.supports_gl_compat_version
= 10;
35 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
37 PIGLIT_GL_TEST_CONFIG_END
39 static const float color1
[] = {0.4, 0.2, 0.6};
40 static const float color2
[] = {0.7, 0.2, 0.3};
41 static const float color3
[] = {0.1, 0.7, 0.2};
42 static const float color4
[] = {0.8, 0.1, 0.7};
44 static float result1p3
[] = {0.0, 0.0, 0.0};
45 static float result2p3
[] = {0.0, 0.0, 0.0};
46 static float result4p3
[] = {0.0, 0.0, 0.0};
48 static const unsigned s_local
= 42;
49 static const unsigned s_global
= 13;
56 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
58 glClearColor(1.0, 0.0, 0.0, 1.0);
59 glClear(GL_COLOR_BUFFER_BIT
);
61 glEnable(GL_FRAGMENT_SHADER_ATI
);
62 glSetFragmentShaderConstantATI(GL_CON_7_ATI
, color2
);
63 glSetFragmentShaderConstantATI(GL_CON_4_ATI
, color3
);
64 glBindFragmentShaderATI(s_global
);
65 piglit_draw_rect(0, 0, piglit_width
/ 4, piglit_height
); /* 2+3 */
66 glBindFragmentShaderATI(s_local
);
67 piglit_draw_rect(piglit_width
/ 4, 0,
68 piglit_width
/ 4, piglit_height
); /* 1+3 */
69 glBindFragmentShaderATI(s_global
);
70 glSetFragmentShaderConstantATI(GL_CON_7_ATI
, color4
);
71 piglit_draw_rect(2 * piglit_width
/ 4, 0,
72 piglit_width
/ 4, piglit_height
); /* 4+3 */
73 glBindFragmentShaderATI(s_local
);
74 piglit_draw_rect(3 * piglit_width
/ 4, 0,
75 piglit_width
/ 4, piglit_height
); /*1+3 */
76 glDisable(GL_FRAGMENT_SHADER_ATI
);
78 pass
= pass
&& piglit_probe_rect_rgb(0, 0,
80 piglit_height
, result2p3
);
81 pass
= pass
&& piglit_probe_rect_rgb(piglit_width
/ 4, 0,
83 piglit_height
, result1p3
);
84 pass
= pass
&& piglit_probe_rect_rgb(2 * piglit_width
/ 4, 0,
86 piglit_height
, result4p3
);
87 pass
= pass
&& piglit_probe_rect_rgb(3 * piglit_width
/ 4, 0,
89 piglit_height
, result1p3
);
91 piglit_present_results();
93 pass
&= piglit_check_gl_error(GL_NO_ERROR
);
95 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
99 piglit_init(int argc
, char **argv
)
103 piglit_require_extension("GL_ATI_fragment_shader");
105 /* create identical shaders, but one of them has a local constant */
107 glBindFragmentShaderATI(s_global
);
108 glBeginFragmentShaderATI();
109 glColorFragmentOp2ATI(GL_ADD_ATI
, GL_REG_0_ATI
, GL_NONE
, GL_NONE
,
110 GL_CON_7_ATI
, GL_NONE
, GL_NONE
,
111 GL_CON_4_ATI
, GL_NONE
, GL_NONE
);
112 glEndFragmentShaderATI();
114 glBindFragmentShaderATI(s_local
);
115 glBeginFragmentShaderATI();
116 glColorFragmentOp2ATI(GL_ADD_ATI
, GL_REG_0_ATI
, GL_NONE
, GL_NONE
,
117 GL_CON_7_ATI
, GL_NONE
, GL_NONE
,
118 GL_CON_4_ATI
, GL_NONE
, GL_NONE
);
119 glSetFragmentShaderConstantATI(GL_CON_7_ATI
, color1
);
120 glEndFragmentShaderATI();
122 /* compute the expected results */
124 for (u
=0; u
<3; u
++) {
125 result1p3
[u
] = color1
[u
]+color3
[u
];
126 result2p3
[u
] = color2
[u
]+color3
[u
];
127 result4p3
[u
] = color4
[u
]+color3
[u
];
130 if (!piglit_check_gl_error(GL_NO_ERROR
))
131 piglit_report_result(PIGLIT_FAIL
);