Fixed typo
[reactos.git] / dll / opengl / mesa / main / fog.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 5.1
4 *
5 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #include <precomp.h>
26
27 void GLAPIENTRY
28 _mesa_Fogf(GLenum pname, GLfloat param)
29 {
30 GLfloat fparam[4];
31 fparam[0] = param;
32 fparam[1] = fparam[2] = fparam[3] = 0.0F;
33 _mesa_Fogfv(pname, fparam);
34 }
35
36
37 void GLAPIENTRY
38 _mesa_Fogi(GLenum pname, GLint param )
39 {
40 GLfloat fparam[4];
41 fparam[0] = (GLfloat) param;
42 fparam[1] = fparam[2] = fparam[3] = 0.0F;
43 _mesa_Fogfv(pname, fparam);
44 }
45
46
47 void GLAPIENTRY
48 _mesa_Fogiv(GLenum pname, const GLint *params )
49 {
50 GLfloat p[4];
51 switch (pname) {
52 case GL_FOG_MODE:
53 case GL_FOG_DENSITY:
54 case GL_FOG_START:
55 case GL_FOG_END:
56 case GL_FOG_INDEX:
57 case GL_FOG_COORDINATE_SOURCE_EXT:
58 p[0] = (GLfloat) *params;
59 break;
60 case GL_FOG_COLOR:
61 p[0] = INT_TO_FLOAT( params[0] );
62 p[1] = INT_TO_FLOAT( params[1] );
63 p[2] = INT_TO_FLOAT( params[2] );
64 p[3] = INT_TO_FLOAT( params[3] );
65 break;
66 default:
67 /* Error will be caught later in _mesa_Fogfv */
68 ASSIGN_4V(p, 0.0F, 0.0F, 0.0F, 0.0F);
69 }
70 _mesa_Fogfv(pname, p);
71 }
72
73
74 /**
75 * Update the gl_fog_attrib::_Scale field.
76 */
77 static void
78 update_fog_scale(struct gl_context *ctx)
79 {
80 if (ctx->Fog.End == ctx->Fog.Start)
81 ctx->Fog._Scale = 1.0f;
82 else
83 ctx->Fog._Scale = 1.0f / (ctx->Fog.End - ctx->Fog.Start);
84 }
85
86
87 void GLAPIENTRY
88 _mesa_Fogfv( GLenum pname, const GLfloat *params )
89 {
90 GET_CURRENT_CONTEXT(ctx);
91 GLenum m;
92 ASSERT_OUTSIDE_BEGIN_END(ctx);
93
94 switch (pname) {
95 case GL_FOG_MODE:
96 m = (GLenum) (GLint) *params;
97 switch (m) {
98 case GL_LINEAR:
99 case GL_EXP:
100 case GL_EXP2:
101 break;
102 default:
103 _mesa_error( ctx, GL_INVALID_ENUM, "glFog" );
104 return;
105 }
106 if (ctx->Fog.Mode == m)
107 return;
108 FLUSH_VERTICES(ctx, _NEW_FOG);
109 ctx->Fog.Mode = m;
110 break;
111 case GL_FOG_DENSITY:
112 if (*params<0.0) {
113 _mesa_error( ctx, GL_INVALID_VALUE, "glFog" );
114 return;
115 }
116 if (ctx->Fog.Density == *params)
117 return;
118 FLUSH_VERTICES(ctx, _NEW_FOG);
119 ctx->Fog.Density = *params;
120 break;
121 case GL_FOG_START:
122 if (ctx->Fog.Start == *params)
123 return;
124 FLUSH_VERTICES(ctx, _NEW_FOG);
125 ctx->Fog.Start = *params;
126 update_fog_scale(ctx);
127 break;
128 case GL_FOG_END:
129 if (ctx->Fog.End == *params)
130 return;
131 FLUSH_VERTICES(ctx, _NEW_FOG);
132 ctx->Fog.End = *params;
133 update_fog_scale(ctx);
134 break;
135 case GL_FOG_INDEX:
136 if (ctx->Fog.Index == *params)
137 return;
138 FLUSH_VERTICES(ctx, _NEW_FOG);
139 ctx->Fog.Index = *params;
140 break;
141 case GL_FOG_COLOR:
142 if (TEST_EQ_4V(ctx->Fog.Color, params))
143 return;
144 FLUSH_VERTICES(ctx, _NEW_FOG);
145 ctx->Fog.Color[0] = params[0];
146 ctx->Fog.Color[1] = params[1];
147 ctx->Fog.Color[2] = params[2];
148 ctx->Fog.Color[3] = params[3];
149 break;
150 case GL_FOG_COORDINATE_SOURCE_EXT: {
151 GLenum p = (GLenum) (GLint) *params;
152 if (!ctx->Extensions.EXT_fog_coord ||
153 (p != GL_FOG_COORDINATE_EXT && p != GL_FRAGMENT_DEPTH_EXT)) {
154 _mesa_error(ctx, GL_INVALID_ENUM, "glFog");
155 return;
156 }
157 if (ctx->Fog.FogCoordinateSource == p)
158 return;
159 FLUSH_VERTICES(ctx, _NEW_FOG);
160 ctx->Fog.FogCoordinateSource = p;
161 break;
162 }
163 case GL_FOG_DISTANCE_MODE_NV: {
164 GLenum p = (GLenum) (GLint) *params;
165 if (!ctx->Extensions.NV_fog_distance ||
166 (p != GL_EYE_RADIAL_NV && p != GL_EYE_PLANE && p != GL_EYE_PLANE_ABSOLUTE_NV)) {
167 _mesa_error(ctx, GL_INVALID_ENUM, "glFog");
168 return;
169 }
170 if (ctx->Fog.FogDistanceMode == p)
171 return;
172 FLUSH_VERTICES(ctx, _NEW_FOG);
173 ctx->Fog.FogDistanceMode = p;
174 break;
175 }
176 default:
177 _mesa_error( ctx, GL_INVALID_ENUM, "glFog" );
178 return;
179 }
180
181 if (ctx->Driver.Fogfv) {
182 (*ctx->Driver.Fogfv)( ctx, pname, params );
183 }
184 }
185
186
187 /**********************************************************************/
188 /***** Initialization *****/
189 /**********************************************************************/
190
191 void _mesa_init_fog( struct gl_context * ctx )
192 {
193 /* Fog group */
194 ctx->Fog.Enabled = GL_FALSE;
195 ctx->Fog.Mode = GL_EXP;
196 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
197 ctx->Fog.Index = 0.0;
198 ctx->Fog.Density = 1.0;
199 ctx->Fog.Start = 0.0;
200 ctx->Fog.End = 1.0;
201 ctx->Fog.FogCoordinateSource = GL_FRAGMENT_DEPTH_EXT;
202 ctx->Fog._Scale = 1.0f;
203 ctx->Fog.FogDistanceMode = GL_EYE_PLANE_ABSOLUTE_NV;
204 }