move mesa32 over to new dir
[reactos.git] / reactos / lib / mesa32 / src / 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
26 #include "glheader.h"
27 #include "colormac.h"
28 #include "context.h"
29 #include "fog.h"
30 #include "mtypes.h"
31
32
33
34 void GLAPIENTRY
35 _mesa_Fogf(GLenum pname, GLfloat param)
36 {
37 _mesa_Fogfv(pname, &param);
38 }
39
40
41 void GLAPIENTRY
42 _mesa_Fogi(GLenum pname, GLint param )
43 {
44 GLfloat fparam = (GLfloat) param;
45 _mesa_Fogfv(pname, &fparam);
46 }
47
48
49 void GLAPIENTRY
50 _mesa_Fogiv(GLenum pname, const GLint *params )
51 {
52 GLfloat p[4];
53 switch (pname) {
54 case GL_FOG_MODE:
55 case GL_FOG_DENSITY:
56 case GL_FOG_START:
57 case GL_FOG_END:
58 case GL_FOG_INDEX:
59 case GL_FOG_COORDINATE_SOURCE_EXT:
60 p[0] = (GLfloat) *params;
61 break;
62 case GL_FOG_COLOR:
63 p[0] = INT_TO_FLOAT( params[0] );
64 p[1] = INT_TO_FLOAT( params[1] );
65 p[2] = INT_TO_FLOAT( params[2] );
66 p[3] = INT_TO_FLOAT( params[3] );
67 break;
68 default:
69 /* Error will be caught later in _mesa_Fogfv */
70 ;
71 }
72 _mesa_Fogfv(pname, p);
73 }
74
75
76 void GLAPIENTRY
77 _mesa_Fogfv( GLenum pname, const GLfloat *params )
78 {
79 GET_CURRENT_CONTEXT(ctx);
80 GLenum m;
81 ASSERT_OUTSIDE_BEGIN_END(ctx);
82
83 switch (pname) {
84 case GL_FOG_MODE:
85 m = (GLenum) (GLint) *params;
86 switch (m) {
87 case GL_LINEAR:
88 case GL_EXP:
89 case GL_EXP2:
90 break;
91 default:
92 _mesa_error( ctx, GL_INVALID_ENUM, "glFog" );
93 return;
94 }
95 if (ctx->Fog.Mode == m)
96 return;
97 FLUSH_VERTICES(ctx, _NEW_FOG);
98 ctx->Fog.Mode = m;
99 break;
100 case GL_FOG_DENSITY:
101 if (*params<0.0) {
102 _mesa_error( ctx, GL_INVALID_VALUE, "glFog" );
103 return;
104 }
105 if (ctx->Fog.Density == *params)
106 return;
107 FLUSH_VERTICES(ctx, _NEW_FOG);
108 ctx->Fog.Density = *params;
109 break;
110 case GL_FOG_START:
111 if (ctx->Fog.Start == *params)
112 return;
113 FLUSH_VERTICES(ctx, _NEW_FOG);
114 ctx->Fog.Start = *params;
115 break;
116 case GL_FOG_END:
117 if (ctx->Fog.End == *params)
118 return;
119 FLUSH_VERTICES(ctx, _NEW_FOG);
120 ctx->Fog.End = *params;
121 break;
122 case GL_FOG_INDEX:
123 if (ctx->Fog.Index == *params)
124 return;
125 FLUSH_VERTICES(ctx, _NEW_FOG);
126 ctx->Fog.Index = *params;
127 break;
128 case GL_FOG_COLOR:
129 if (TEST_EQ_4V(ctx->Fog.Color, params))
130 return;
131 FLUSH_VERTICES(ctx, _NEW_FOG);
132 ctx->Fog.Color[0] = CLAMP(params[0], 0.0F, 1.0F);
133 ctx->Fog.Color[1] = CLAMP(params[1], 0.0F, 1.0F);
134 ctx->Fog.Color[2] = CLAMP(params[2], 0.0F, 1.0F);
135 ctx->Fog.Color[3] = CLAMP(params[3], 0.0F, 1.0F);
136 break;
137 case GL_FOG_COORDINATE_SOURCE_EXT: {
138 GLenum p = (GLenum) (GLint) *params;
139 if (!ctx->Extensions.EXT_fog_coord ||
140 (p != GL_FOG_COORDINATE_EXT && p != GL_FRAGMENT_DEPTH_EXT)) {
141 _mesa_error(ctx, GL_INVALID_ENUM, "glFog");
142 return;
143 }
144 if (ctx->Fog.FogCoordinateSource == p)
145 return;
146 FLUSH_VERTICES(ctx, _NEW_FOG);
147 ctx->Fog.FogCoordinateSource = p;
148 break;
149 }
150 default:
151 _mesa_error( ctx, GL_INVALID_ENUM, "glFog" );
152 return;
153 }
154
155 if (ctx->Driver.Fogfv) {
156 (*ctx->Driver.Fogfv)( ctx, pname, params );
157 }
158 }
159
160
161 /**********************************************************************/
162 /***** Initialization *****/
163 /**********************************************************************/
164
165 void _mesa_init_fog( GLcontext * ctx )
166 {
167 /* Fog group */
168 ctx->Fog.Enabled = GL_FALSE;
169 ctx->Fog.Mode = GL_EXP;
170 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
171 ctx->Fog.Index = 0.0;
172 ctx->Fog.Density = 1.0;
173 ctx->Fog.Start = 0.0;
174 ctx->Fog.End = 1.0;
175 ctx->Fog.ColorSumEnabled = GL_FALSE;
176 ctx->Fog.FogCoordinateSource = GL_FRAGMENT_DEPTH_EXT;
177 }