2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
35 _mesa_Fogf(GLenum pname
, GLfloat param
)
39 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
40 _mesa_Fogfv(pname
, fparam
);
45 _mesa_Fogi(GLenum pname
, GLint param
)
48 fparam
[0] = (GLfloat
) param
;
49 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
50 _mesa_Fogfv(pname
, fparam
);
55 _mesa_Fogiv(GLenum pname
, const GLint
*params
)
64 case GL_FOG_COORDINATE_SOURCE_EXT
:
65 case GL_FOG_DISTANCE_MODE_NV
:
66 p
[0] = (GLfloat
) *params
;
69 p
[0] = INT_TO_FLOAT( params
[0] );
70 p
[1] = INT_TO_FLOAT( params
[1] );
71 p
[2] = INT_TO_FLOAT( params
[2] );
72 p
[3] = INT_TO_FLOAT( params
[3] );
75 /* Error will be caught later in _mesa_Fogfv */
76 ASSIGN_4V(p
, 0.0F
, 0.0F
, 0.0F
, 0.0F
);
78 _mesa_Fogfv(pname
, p
);
83 _mesa_Fogfv( GLenum pname
, const GLfloat
*params
)
85 GET_CURRENT_CONTEXT(ctx
);
90 m
= (GLenum
) (GLint
) *params
;
93 ctx
->Fog
._PackedMode
= FOG_LINEAR
;
96 ctx
->Fog
._PackedMode
= FOG_EXP
;
99 ctx
->Fog
._PackedMode
= FOG_EXP2
;
102 _mesa_error( ctx
, GL_INVALID_ENUM
, "glFog" );
105 if (ctx
->Fog
.Mode
== m
)
107 FLUSH_VERTICES(ctx
, _NEW_FOG
);
109 ctx
->Fog
._PackedEnabledMode
= ctx
->Fog
.Enabled
?
110 ctx
->Fog
._PackedMode
: FOG_NONE
;
114 _mesa_error( ctx
, GL_INVALID_VALUE
, "glFog" );
117 if (ctx
->Fog
.Density
== *params
)
119 FLUSH_VERTICES(ctx
, _NEW_FOG
);
120 ctx
->Fog
.Density
= *params
;
123 if (ctx
->Fog
.Start
== *params
)
125 FLUSH_VERTICES(ctx
, _NEW_FOG
);
126 ctx
->Fog
.Start
= *params
;
129 if (ctx
->Fog
.End
== *params
)
131 FLUSH_VERTICES(ctx
, _NEW_FOG
);
132 ctx
->Fog
.End
= *params
;
135 if (ctx
->API
!= API_OPENGL_COMPAT
)
137 if (ctx
->Fog
.Index
== *params
)
139 FLUSH_VERTICES(ctx
, _NEW_FOG
);
140 ctx
->Fog
.Index
= *params
;
143 if (TEST_EQ_4V(ctx
->Fog
.Color
, params
))
145 FLUSH_VERTICES(ctx
, _NEW_FOG
);
146 ctx
->Fog
.ColorUnclamped
[0] = params
[0];
147 ctx
->Fog
.ColorUnclamped
[1] = params
[1];
148 ctx
->Fog
.ColorUnclamped
[2] = params
[2];
149 ctx
->Fog
.ColorUnclamped
[3] = params
[3];
150 ctx
->Fog
.Color
[0] = CLAMP(params
[0], 0.0F
, 1.0F
);
151 ctx
->Fog
.Color
[1] = CLAMP(params
[1], 0.0F
, 1.0F
);
152 ctx
->Fog
.Color
[2] = CLAMP(params
[2], 0.0F
, 1.0F
);
153 ctx
->Fog
.Color
[3] = CLAMP(params
[3], 0.0F
, 1.0F
);
155 case GL_FOG_COORDINATE_SOURCE_EXT
: {
156 GLenum p
= (GLenum
) (GLint
) *params
;
157 if (ctx
->API
!= API_OPENGL_COMPAT
||
158 (p
!= GL_FOG_COORDINATE_EXT
&& p
!= GL_FRAGMENT_DEPTH_EXT
)) {
159 _mesa_error(ctx
, GL_INVALID_ENUM
, "glFog");
162 if (ctx
->Fog
.FogCoordinateSource
== p
)
164 FLUSH_VERTICES(ctx
, _NEW_FOG
);
165 ctx
->Fog
.FogCoordinateSource
= p
;
168 case GL_FOG_DISTANCE_MODE_NV
: {
169 GLenum p
= (GLenum
) (GLint
) *params
;
170 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.NV_fog_distance
||
171 (p
!= GL_EYE_RADIAL_NV
&& p
!= GL_EYE_PLANE
&& p
!= GL_EYE_PLANE_ABSOLUTE_NV
)) {
172 _mesa_error(ctx
, GL_INVALID_ENUM
, "glFog");
175 if (ctx
->Fog
.FogDistanceMode
== p
)
177 FLUSH_VERTICES(ctx
, _NEW_FOG
);
178 ctx
->Fog
.FogDistanceMode
= p
;
185 if (ctx
->Driver
.Fogfv
) {
186 ctx
->Driver
.Fogfv( ctx
, pname
, params
);
192 _mesa_error( ctx
, GL_INVALID_ENUM
, "glFog" );
197 /**********************************************************************/
198 /***** Initialization *****/
199 /**********************************************************************/
201 void _mesa_init_fog( struct gl_context
* ctx
)
204 ctx
->Fog
.Enabled
= GL_FALSE
;
205 ctx
->Fog
.Mode
= GL_EXP
;
206 ctx
->Fog
._PackedMode
= FOG_EXP
;
207 ctx
->Fog
._PackedEnabledMode
= FOG_NONE
;
208 ASSIGN_4V( ctx
->Fog
.Color
, 0.0, 0.0, 0.0, 0.0 );
209 ASSIGN_4V( ctx
->Fog
.ColorUnclamped
, 0.0, 0.0, 0.0, 0.0 );
210 ctx
->Fog
.Index
= 0.0;
211 ctx
->Fog
.Density
= 1.0;
212 ctx
->Fog
.Start
= 0.0;
214 ctx
->Fog
.ColorSumEnabled
= GL_FALSE
;
215 ctx
->Fog
.FogCoordinateSource
= GL_FRAGMENT_DEPTH_EXT
;
216 ctx
->Fog
.FogDistanceMode
= GL_EYE_PLANE_ABSOLUTE_NV
;