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: using fog.
28 #include "piglit-util-gl.h"
30 PIGLIT_GL_TEST_CONFIG_BEGIN
32 config
.supports_gl_compat_version
= 10;
33 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
35 PIGLIT_GL_TEST_CONFIG_END
37 static const float color1
[] = {0.2, 0.3, 0.8, 0.8};
38 static const float color2
[] = {0.9, 0.8, 0.3, 0.3};
40 static float resultLin
[] = {0.0, 0.0, 0.0, 0.0};
41 static float resultExp
[] = {0.0, 0.0, 0.0, 0.0};
42 static float resultEx2
[] = {0.0, 0.0, 0.0, 0.0};
44 static const float z
= 0.8;
45 static const float dens
= 0.4;
52 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
54 glClearColor(1.0, 0.0, 0.0, 1.0);
55 glClear(GL_COLOR_BUFFER_BIT
);
59 glFogfv(GL_FOG_COLOR
, color1
);
60 glFogf(GL_FOG_DENSITY
, dens
);
61 glFogf(GL_FOG_START
, 0.0);
62 glFogf(GL_FOG_END
, 1.0);
63 glHint(GL_FOG_HINT
, GL_NICEST
);
65 glEnable(GL_FRAGMENT_SHADER_ATI
);
67 glFogi(GL_FOG_MODE
, GL_LINEAR
);
68 piglit_draw_rect_z(z
, 0, 0,
69 piglit_width
/ 4, piglit_height
);
70 glFogi(GL_FOG_MODE
, GL_EXP
);
71 piglit_draw_rect_z(z
, piglit_width
/ 4, 0,
72 piglit_width
/ 4, piglit_height
);
73 glFogi(GL_FOG_MODE
, GL_EXP2
);
74 piglit_draw_rect_z(z
, 2 * piglit_width
/ 4, 0,
75 piglit_width
/ 4, piglit_height
);
77 piglit_draw_rect_z(z
, 3 * piglit_width
/ 4, 0,
78 piglit_width
/ 4, piglit_height
);
79 glDisable(GL_FRAGMENT_SHADER_ATI
);
81 pass
= pass
&& piglit_probe_rect_rgba(0, 0,
83 piglit_height
, resultLin
);
84 pass
= pass
&& piglit_probe_rect_rgba(piglit_width
/ 4, 0,
86 piglit_height
, resultExp
);
87 pass
= pass
&& piglit_probe_rect_rgba(2 * piglit_width
/ 4, 0,
89 piglit_height
, resultEx2
);
90 pass
= pass
&& piglit_probe_rect_rgba(3 * piglit_width
/ 4, 0,
92 piglit_height
, color2
);
94 piglit_present_results();
96 pass
&= piglit_check_gl_error(GL_NO_ERROR
);
98 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
102 piglit_init(int argc
, char **argv
)
107 piglit_require_extension("GL_ATI_fragment_shader");
109 glBeginFragmentShaderATI();
110 glColorFragmentOp1ATI(GL_MOV_ATI
, GL_REG_0_ATI
, GL_NONE
, GL_NONE
,
111 GL_PRIMARY_COLOR_ARB
, GL_NONE
, GL_NONE
);
112 glAlphaFragmentOp1ATI(GL_MOV_ATI
, GL_REG_0_ATI
, GL_NONE
,
113 GL_PRIMARY_COLOR_ARB
, GL_NONE
, GL_NONE
);
114 glEndFragmentShaderATI();
116 /* compute the expected results */
118 for (u
=0; u
<3; u
++) {
119 f
= (1.0-z
)/(1.0-0.0);
120 resultLin
[u
] = f
*color2
[u
] + (1.0-f
)*color1
[u
];
122 resultExp
[u
] = f
*color2
[u
] + (1.0-f
)*color1
[u
];
123 f
= exp(-pow(dens
*z
,2.0));
124 resultEx2
[u
] = f
*color2
[u
] + (1.0-f
)*color1
[u
];
126 resultLin
[3] = color2
[3];
127 resultExp
[3] = color2
[3];
128 resultEx2
[3] = color2
[3];
130 if (!piglit_check_gl_error(GL_NO_ERROR
))
131 piglit_report_result(PIGLIT_FAIL
);