2 * Copyright © 2017 Fabian Bieler
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 * @file linear-fog.c: Draw using linear fog in GLSL.
27 * Simple fog test with constant fog coordinates.
30 #include "piglit-util-gl.h"
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config
.supports_gl_compat_version
= 20;
35 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
;
36 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
38 PIGLIT_GL_TEST_CONFIG_END
40 static const char *vs_text
=
42 " gl_Position = gl_Vertex; \n"
43 " gl_FogFragCoord = gl_MultiTexCoord0.x; \n"
44 " gl_FrontColor = gl_Color; \n"
46 static const char *fs_text
=
48 " float bf = (gl_FogFragCoord - gl_Fog.start) * gl_Fog.scale; \n"
49 " gl_FragColor = mix(gl_Color, gl_Fog.color, bf); \n"
52 static const float vertex_color
[] = {.25, .5, .75, .25};
53 static const float fog_color
[] = {1, .5, 1, 0};
54 static const float fog_start
= 100;
55 static const float fog_end
= 200;
62 for (int j
= 0; j
< 5; ++j
) {
63 const float fog_coord
= 100 + j
* 25;
65 (fog_coord
- fog_start
) / (fog_end
- fog_start
);
66 float expected_color
[4];
67 for (int i
= 0; i
< 4; ++i
)
68 expected_color
[i
] = bf
* fog_color
[i
] +
69 (1 - bf
) * vertex_color
[i
];
71 glClear(GL_COLOR_BUFFER_BIT
);
73 glTexCoord1f(fog_coord
);
74 piglit_draw_rect(-1, -1, 2, 2);
76 pass
= piglit_probe_pixel_rgba(piglit_width
/ 2,
82 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
86 piglit_init(int argc
, char **argv
)
88 const int program
= piglit_build_simple_program(vs_text
, fs_text
);
90 glUseProgram(program
);
92 glColor4fv(vertex_color
);
93 glFogf(GL_FOG_START
, fog_start
);
94 glFogf(GL_FOG_END
, fog_end
);
95 glFogfv(GL_FOG_COLOR
, fog_color
);