2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
36 _mesa_Fogf(GLenum pname
, GLfloat param
)
40 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
41 _mesa_Fogfv(pname
, fparam
);
46 _mesa_Fogi(GLenum pname
, GLint param
)
49 fparam
[0] = (GLfloat
) param
;
50 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
51 _mesa_Fogfv(pname
, fparam
);
56 _mesa_Fogiv(GLenum pname
, const GLint
*params
)
65 case GL_FOG_COORDINATE_SOURCE_EXT
:
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 * Update the gl_fog_attrib::_Scale field.
86 update_fog_scale(struct gl_context
*ctx
)
88 if (ctx
->Fog
.End
== ctx
->Fog
.Start
)
89 ctx
->Fog
._Scale
= 1.0f
;
91 ctx
->Fog
._Scale
= 1.0f
/ (ctx
->Fog
.End
- ctx
->Fog
.Start
);
96 _mesa_Fogfv( GLenum pname
, const GLfloat
*params
)
98 GET_CURRENT_CONTEXT(ctx
);
100 ASSERT_OUTSIDE_BEGIN_END(ctx
);
104 m
= (GLenum
) (GLint
) *params
;
111 _mesa_error( ctx
, GL_INVALID_ENUM
, "glFog" );
114 if (ctx
->Fog
.Mode
== m
)
116 FLUSH_VERTICES(ctx
, _NEW_FOG
);
121 _mesa_error( ctx
, GL_INVALID_VALUE
, "glFog" );
124 if (ctx
->Fog
.Density
== *params
)
126 FLUSH_VERTICES(ctx
, _NEW_FOG
);
127 ctx
->Fog
.Density
= *params
;
130 if (ctx
->Fog
.Start
== *params
)
132 FLUSH_VERTICES(ctx
, _NEW_FOG
);
133 ctx
->Fog
.Start
= *params
;
134 update_fog_scale(ctx
);
137 if (ctx
->Fog
.End
== *params
)
139 FLUSH_VERTICES(ctx
, _NEW_FOG
);
140 ctx
->Fog
.End
= *params
;
141 update_fog_scale(ctx
);
144 if (ctx
->Fog
.Index
== *params
)
146 FLUSH_VERTICES(ctx
, _NEW_FOG
);
147 ctx
->Fog
.Index
= *params
;
150 if (TEST_EQ_4V(ctx
->Fog
.Color
, params
))
152 FLUSH_VERTICES(ctx
, _NEW_FOG
);
153 ctx
->Fog
.Color
[0] = CLAMP(params
[0], 0.0F
, 1.0F
);
154 ctx
->Fog
.Color
[1] = CLAMP(params
[1], 0.0F
, 1.0F
);
155 ctx
->Fog
.Color
[2] = CLAMP(params
[2], 0.0F
, 1.0F
);
156 ctx
->Fog
.Color
[3] = CLAMP(params
[3], 0.0F
, 1.0F
);
158 case GL_FOG_COORDINATE_SOURCE_EXT
: {
159 GLenum p
= (GLenum
) (GLint
) *params
;
160 if (!ctx
->Extensions
.EXT_fog_coord
||
161 (p
!= GL_FOG_COORDINATE_EXT
&& p
!= GL_FRAGMENT_DEPTH_EXT
)) {
162 _mesa_error(ctx
, GL_INVALID_ENUM
, "glFog");
165 if (ctx
->Fog
.FogCoordinateSource
== p
)
167 FLUSH_VERTICES(ctx
, _NEW_FOG
);
168 ctx
->Fog
.FogCoordinateSource
= p
;
172 _mesa_error( ctx
, GL_INVALID_ENUM
, "glFog" );
176 if (ctx
->Driver
.Fogfv
) {
177 (*ctx
->Driver
.Fogfv
)( ctx
, pname
, params
);
182 /**********************************************************************/
183 /***** Initialization *****/
184 /**********************************************************************/
186 void _mesa_init_fog( struct gl_context
* ctx
)
189 ctx
->Fog
.Enabled
= GL_FALSE
;
190 ctx
->Fog
.Mode
= GL_EXP
;
191 ASSIGN_4V( ctx
->Fog
.Color
, 0.0, 0.0, 0.0, 0.0 );
192 ctx
->Fog
.Index
= 0.0;
193 ctx
->Fog
.Density
= 1.0;
194 ctx
->Fog
.Start
= 0.0;
196 ctx
->Fog
.ColorSumEnabled
= GL_FALSE
;
197 ctx
->Fog
.FogCoordinateSource
= GL_FRAGMENT_DEPTH_EXT
;
198 ctx
->Fog
._Scale
= 1.0f
;