ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / ext_fog_coord / modes.c
blob4b7ba72d69b6c77c00a293fa28f941e760283595
1 /*
2 * Copyright © 2010 Intel Corporation
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 /** @file modes.c
26 * Tests that the three fog modes work with fog enabled using EXT_fog_coord.
29 #include "piglit-util-gl.h"
31 PIGLIT_GL_TEST_CONFIG_BEGIN
33 config.supports_gl_compat_version = 10;
35 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
37 PIGLIT_GL_TEST_CONFIG_END
39 enum piglit_result
40 piglit_display(void)
42 GLboolean pass = GL_TRUE;
43 int i, mode;
44 float near = 0.0, far = 1.0;
45 GLfloat fogcolor[4] = {1, 1, 1, 1};
47 glEnable(GL_FOG);
48 glFogfv(GL_FOG_COLOR, fogcolor);
49 glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
50 glColor4f(0, 0, 0, 0.5);
52 glMatrixMode(GL_PROJECTION);
53 glLoadIdentity();
54 glOrtho(0, 1, 0, 1, -near, -far);
56 for (mode = 0; mode < 3; mode++) {
57 float y = mode / 3.0;
58 float h = 1.0 / 3.0;
60 switch (mode) {
61 case 0:
62 glFogi(GL_FOG_MODE, GL_LINEAR);
63 glFogf(GL_FOG_START, near);
64 glFogf(GL_FOG_END, far);
65 break;
66 case 1:
67 glFogi(GL_FOG_MODE, GL_EXP);
68 glFogf(GL_FOG_DENSITY, 2);
69 break;
70 case 2:
71 glFogi(GL_FOG_MODE, GL_EXP2);
72 glFogf(GL_FOG_DENSITY, 2);
73 break;
76 for (i = 0; i < 5; i++) {
77 float x = i / 5.0;
78 float w = 1.0 / 5.0;
79 float z = near + (far - near) * i / 5.0;
81 glFogCoordfEXT(z);
82 piglit_draw_rect(x, y, w, h);
86 for (mode = 0; mode < 3; mode++) {
87 float y = (mode + 0.5) / 3.0 * piglit_height;
88 for (i = 0; i < 5; i++) {
89 float x = (i + 0.5) / 5.0 * piglit_width;
90 float z = near + (far - near) * i / 5.0;
91 float f;
92 float color[4];
94 switch (mode) {
95 case 0:
96 f = (far - z) / (far - near);
97 break;
98 case 1:
99 f = expf(-(2.0 * z));
100 break;
101 case 2:
102 f = expf(-(2.0 * z) * (2.0 * z));
103 break;
105 if (f > 1.0)
106 f = 1.0;
107 if (f < 0.0)
108 f = 0.0;
110 color[0] = 1.0 - f;
111 color[1] = 1.0 - f;
112 color[2] = 1.0 - f;
113 color[3] = 0.5;
115 pass = pass & piglit_probe_pixel_rgba(x, y, color);
119 piglit_present_results();
121 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
124 void piglit_init(int argc, char**argv)
126 piglit_require_extension("GL_EXT_fog_coord");