blob: c0e4b4a907c324f06c36ee5b99f422903feba6ce [file] [log] [blame]
Keith Whitwell58e99172001-01-05 02:26:48 +00001/* $Id: fog.c,v 1.32 2001/01/05 02:26:48 keithw Exp $ */
jtgafb833d1999-08-19 00:55:39 +00002
3/*
4 * Mesa 3-D graphics library
Brian Paul1c4b3f42000-10-27 18:38:35 +00005 * Version: 3.5
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00006 *
Brian Paul5829f0c2000-02-02 22:21:39 +00007 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00008 *
jtgafb833d1999-08-19 00:55:39 +00009 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000015 *
jtgafb833d1999-08-19 00:55:39 +000016 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000018 *
jtgafb833d1999-08-19 00:55:39 +000019 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
28#ifdef PC_HEADER
29#include "all.h"
30#else
Brian Paulfbd8f211999-11-11 01:22:25 +000031#include "glheader.h"
Brian Paulc893a012000-10-28 20:41:13 +000032#include "colormac.h"
jtgafb833d1999-08-19 00:55:39 +000033#include "context.h"
34#include "fog.h"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000035#include "mtypes.h"
jtgafb833d1999-08-19 00:55:39 +000036#endif
37
38
39
Brian Paulfbd8f211999-11-11 01:22:25 +000040void
41_mesa_Fogf(GLenum pname, GLfloat param)
jtgafb833d1999-08-19 00:55:39 +000042{
Brian Paulfbd8f211999-11-11 01:22:25 +000043 _mesa_Fogfv(pname, &param);
44}
45
46
47void
48_mesa_Fogi(GLenum pname, GLint param )
49{
50 GLfloat fparam = (GLfloat) param;
51 _mesa_Fogfv(pname, &fparam);
52}
53
54
55void
56_mesa_Fogiv(GLenum pname, const GLint *params )
57{
58 GLfloat p[4];
59 switch (pname) {
60 case GL_FOG_MODE:
61 case GL_FOG_DENSITY:
62 case GL_FOG_START:
63 case GL_FOG_END:
64 case GL_FOG_INDEX:
Keith Whitwellfe5d67d2000-10-27 16:44:40 +000065 case GL_FOG_COORDINATE_SOURCE_EXT:
Brian Paulfbd8f211999-11-11 01:22:25 +000066 p[0] = (GLfloat) *params;
67 break;
68 case GL_FOG_COLOR:
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] );
73 break;
74 default:
Brian Paulab8de7b2000-02-02 22:22:59 +000075 /* Error will be caught later in _mesa_Fogfv */
Brian Paulfbd8f211999-11-11 01:22:25 +000076 ;
77 }
78 _mesa_Fogfv(pname, p);
79}
80
81
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000082void
Brian Paulfbd8f211999-11-11 01:22:25 +000083_mesa_Fogfv( GLenum pname, const GLfloat *params )
84{
85 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +000086 GLenum m;
Keith Whitwellcab974c2000-12-26 05:09:27 +000087 ASSERT_OUTSIDE_BEGIN_END(ctx);
Brian Paulbf996da2000-06-05 14:33:06 +000088
jtgafb833d1999-08-19 00:55:39 +000089 switch (pname) {
90 case GL_FOG_MODE:
91 m = (GLenum) (GLint) *params;
Keith Whitwellcab974c2000-12-26 05:09:27 +000092 switch (m) {
93 case GL_LINEAR:
94 case GL_EXP:
95 case GL_EXP2:
96 break;
97 default:
jtgafb833d1999-08-19 00:55:39 +000098 gl_error( ctx, GL_INVALID_ENUM, "glFog" );
99 return;
100 }
Keith Whitwell58e99172001-01-05 02:26:48 +0000101 if (ctx->Fog.Mode == m)
102 return;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000103 FLUSH_VERTICES(ctx, _NEW_FOG);
104 ctx->Fog.Mode = m;
jtgafb833d1999-08-19 00:55:39 +0000105 break;
106 case GL_FOG_DENSITY:
107 if (*params<0.0) {
108 gl_error( ctx, GL_INVALID_VALUE, "glFog" );
109 return;
110 }
Keith Whitwellcab974c2000-12-26 05:09:27 +0000111 if (ctx->Fog.Density == *params)
112 return;
113 FLUSH_VERTICES(ctx, _NEW_FOG);
114 ctx->Fog.Density = *params;
jtgafb833d1999-08-19 00:55:39 +0000115 break;
116 case GL_FOG_START:
Keith Whitwellcab974c2000-12-26 05:09:27 +0000117 if (ctx->Fog.Start == *params)
118 return;
119 FLUSH_VERTICES(ctx, _NEW_FOG);
jtgafb833d1999-08-19 00:55:39 +0000120 ctx->Fog.Start = *params;
121 break;
122 case GL_FOG_END:
Keith Whitwellcab974c2000-12-26 05:09:27 +0000123 if (ctx->Fog.End == *params)
124 return;
125 FLUSH_VERTICES(ctx, _NEW_FOG);
jtgafb833d1999-08-19 00:55:39 +0000126 ctx->Fog.End = *params;
127 break;
128 case GL_FOG_INDEX:
Keith Whitwellcab974c2000-12-26 05:09:27 +0000129 if (ctx->Fog.Index == *params)
130 return;
131 FLUSH_VERTICES(ctx, _NEW_FOG);
132 ctx->Fog.Index = *params;
jtgafb833d1999-08-19 00:55:39 +0000133 break;
134 case GL_FOG_COLOR:
Keith Whitwell58e99172001-01-05 02:26:48 +0000135 if (TEST_EQ_4V(ctx->Fog.Color, params))
Keith Whitwellcab974c2000-12-26 05:09:27 +0000136 return;
137 FLUSH_VERTICES(ctx, _NEW_FOG);
jtgafb833d1999-08-19 00:55:39 +0000138 ctx->Fog.Color[0] = params[0];
139 ctx->Fog.Color[1] = params[1];
140 ctx->Fog.Color[2] = params[2];
141 ctx->Fog.Color[3] = params[3];
142 break;
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000143 case GL_FOG_COORDINATE_SOURCE_EXT: {
144 GLenum p = (GLenum)(GLint) *params;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000145 if (p != GL_FOG_COORDINATE_EXT && p != GL_FRAGMENT_DEPTH_EXT) {
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000146 gl_error( ctx, GL_INVALID_ENUM, "glFog" );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000147 return;
148 }
Keith Whitwell58e99172001-01-05 02:26:48 +0000149 if (ctx->Fog.FogCoordinateSource == p)
150 return;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000151 FLUSH_VERTICES(ctx, _NEW_FOG);
152 ctx->Fog.FogCoordinateSource = p;
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000153 break;
154 }
jtgafb833d1999-08-19 00:55:39 +0000155 default:
156 gl_error( ctx, GL_INVALID_ENUM, "glFog" );
157 return;
158 }
159
160 if (ctx->Driver.Fogfv) {
161 (*ctx->Driver.Fogfv)( ctx, pname, params );
162 }
jtgafb833d1999-08-19 00:55:39 +0000163}
164
165