2 * Copyright © 2013 Henri Verbeet <hverbeet@gmail.com>
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
24 /** @file glsl-fs-fogscale.c
26 * Tests that gl_Fog.scale is equivalent to
27 * "1.0 / (gl_Fog.end - gl_Fog.start)" when fog start and end are equal. The
28 * expectation is that 1.0 / 0.0 will produce a value similar to +INF. This
29 * takes into account that some GPUs may not have a representation for INF.
32 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config
.supports_gl_compat_version
= 20;
38 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
40 PIGLIT_GL_TEST_CONFIG_END
42 const char * tests
[4] = { "vs and fs", "gs-out and fs", "vs, gs and fs", NULL
};
44 static const char vs_source
[] =
47 " gl_Position = gl_Vertex;\n"
48 " gl_FogFragCoord = gl_Position.x;\n"
51 static const char *dummy_vs_source
=
54 " gl_Position = gl_Vertex;\n"
57 static const char fs_source
[] =
60 " gl_FragColor = vec4(gl_FogFragCoord * gl_Fog.scale * vec2(1.0, -1.0), 0.0, 1.0);\n"
64 test_prog(unsigned prog
, const char *test_name
)
66 static const float green
[] = {0.0f
, 1.0f
, 0.0f
, 1.0f
};
67 static const float red
[] = {1.0f
, 0.0f
, 0.0f
, 1.0f
};
72 glClearColor(0.0, 0.0, 1.0, 0.0);
73 glClear(GL_COLOR_BUFFER_BIT
);
75 piglit_draw_rect(-1, -1, 2, 2);
76 pass
= piglit_probe_rect_rgba(0, 0,
77 piglit_width
/ 2, piglit_height
,
79 pass
= piglit_probe_rect_rgba(piglit_width
/ 2, 0,
80 piglit_width
/ 2, piglit_height
,
83 piglit_report_subtest_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
, "%s",
90 create_gs_source(char **gs_source
, char *fogFragCoordValue
)
92 (void)!asprintf(gs_source
,
93 "#version 150 compatibility\n"
94 "layout(triangles) in;\n"
95 "layout(triangle_strip, max_vertices = 3) out;\n"
99 " for (int i = 0; i < 3; i++) {\n"
100 " gl_Position = gl_in[i].gl_Position;\n"
101 " gl_FogFragCoord = %s;\n"
115 /* Test simple vs and fs program */
116 GLuint prog
= piglit_build_simple_program(vs_source
, fs_source
);
117 test_prog(prog
, tests
[0]);
119 /* Test passing gl_FogFragCoord via the Geometry Shader */
120 if (piglit_get_gl_version() >= 32) {
121 /* Test gl_FogFragCoord gs output only */
122 create_gs_source(&gs_source
, "gl_Position.x");
123 prog
= piglit_build_simple_program_multiple_shaders(
124 GL_VERTEX_SHADER
, dummy_vs_source
,
125 GL_GEOMETRY_SHADER
, gs_source
,
126 GL_FRAGMENT_SHADER
, fs_source
,
128 pass
= pass
&& test_prog(prog
, tests
[1]);
130 /* Test gl_FogFragCoord both as a gs output and input */
131 create_gs_source(&gs_source2
, "gl_in[i].gl_FogFragCoord");
132 prog
= piglit_build_simple_program_multiple_shaders(
133 GL_VERTEX_SHADER
, vs_source
,
134 GL_GEOMETRY_SHADER
, gs_source2
,
135 GL_FRAGMENT_SHADER
, fs_source
,
137 pass
= pass
&& test_prog(prog
, tests
[2]);
140 piglit_report_subtest_result(PIGLIT_SKIP
, "%s", tests
[1]);
141 piglit_report_subtest_result(PIGLIT_SKIP
, "%s", tests
[2]);
144 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
148 piglit_init(int argc
, char **argv
)
150 piglit_register_subtests(tests
);
152 glFogf(GL_FOG_START
, 0.0f
);
153 glFogf(GL_FOG_END
, 0.0f
);