Subversion Repositories shark

Rev

Rev 55 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
55 pj 1
/* $Id: fog.c,v 1.1 2003-02-28 11:42:00 pj Exp $ */
2
 
3
/*
4
 * Mesa 3-D graphics library
5
 * Version:  3.5
6
 *
7
 * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
8
 *
9
 * 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:
15
 *
16
 * The above copyright notice and this permission notice shall be included
17
 * in all copies or substantial portions of the Software.
18
 *
19
 * 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
#include "glheader.h"
29
#include "colormac.h"
30
#include "context.h"
31
#include "fog.h"
32
#include "mtypes.h"
33
 
34
 
35
 
36
void
37
_mesa_Fogf(GLenum pname, GLfloat param)
38
{
39
   _mesa_Fogfv(pname, &param);
40
}
41
 
42
 
43
void
44
_mesa_Fogi(GLenum pname, GLint param )
45
{
46
   GLfloat fparam = (GLfloat) param;
47
   _mesa_Fogfv(pname, &fparam);
48
}
49
 
50
 
51
void
52
_mesa_Fogiv(GLenum pname, const GLint *params )
53
{
54
   GLfloat p[4];
55
   switch (pname) {
56
      case GL_FOG_MODE:
57
      case GL_FOG_DENSITY:
58
      case GL_FOG_START:
59
      case GL_FOG_END:
60
      case GL_FOG_INDEX:
61
      case GL_FOG_COORDINATE_SOURCE_EXT:
62
         p[0] = (GLfloat) *params;
63
         break;
64
      case GL_FOG_COLOR:
65
         p[0] = INT_TO_FLOAT( params[0] );
66
         p[1] = INT_TO_FLOAT( params[1] );
67
         p[2] = INT_TO_FLOAT( params[2] );
68
         p[3] = INT_TO_FLOAT( params[3] );
69
         break;
70
      default:
71
         /* Error will be caught later in _mesa_Fogfv */
72
         ;
73
   }
74
   _mesa_Fogfv(pname, p);
75
}
76
 
77
 
78
void
79
_mesa_Fogfv( GLenum pname, const GLfloat *params )
80
{
81
   GET_CURRENT_CONTEXT(ctx);
82
   GLenum m;
83
   ASSERT_OUTSIDE_BEGIN_END(ctx);
84
 
85
   switch (pname) {
86
      case GL_FOG_MODE:
87
         m = (GLenum) (GLint) *params;
88
         switch (m) {
89
         case GL_LINEAR:
90
         case GL_EXP:
91
         case GL_EXP2:
92
            break;
93
         default:
94
            _mesa_error( ctx, GL_INVALID_ENUM, "glFog" );
95
            return;
96
         }
97
         if (ctx->Fog.Mode == m)
98
            return;
99
         FLUSH_VERTICES(ctx, _NEW_FOG);
100
         ctx->Fog.Mode = m;
101
         break;
102
      case GL_FOG_DENSITY:
103
         if (*params<0.0) {
104
            _mesa_error( ctx, GL_INVALID_VALUE, "glFog" );
105
            return;
106
         }
107
         if (ctx->Fog.Density == *params)
108
            return;
109
         FLUSH_VERTICES(ctx, _NEW_FOG);
110
         ctx->Fog.Density = *params;
111
         break;
112
      case GL_FOG_START:
113
         if (ctx->Fog.Start == *params)
114
            return;
115
         FLUSH_VERTICES(ctx, _NEW_FOG);
116
         ctx->Fog.Start = *params;
117
         break;
118
      case GL_FOG_END:
119
         if (ctx->Fog.End == *params)
120
            return;
121
         FLUSH_VERTICES(ctx, _NEW_FOG);
122
         ctx->Fog.End = *params;
123
         break;
124
      case GL_FOG_INDEX:
125
         if (ctx->Fog.Index == *params)
126
            return;
127
         FLUSH_VERTICES(ctx, _NEW_FOG);
128
         ctx->Fog.Index = *params;
129
         break;
130
      case GL_FOG_COLOR:
131
         if (TEST_EQ_4V(ctx->Fog.Color, params))
132
            return;
133
         FLUSH_VERTICES(ctx, _NEW_FOG);
134
         ctx->Fog.Color[0] = params[0];
135
         ctx->Fog.Color[1] = params[1];
136
         ctx->Fog.Color[2] = params[2];
137
         ctx->Fog.Color[3] = params[3];
138
         break;
139
      case GL_FOG_COORDINATE_SOURCE_EXT: {
140
         GLenum p = (GLenum) (GLint) *params;
141
         if (!ctx->Extensions.EXT_fog_coord ||
142
             (p != GL_FOG_COORDINATE_EXT && p != GL_FRAGMENT_DEPTH_EXT)) {
143
            _mesa_error(ctx, GL_INVALID_ENUM, "glFog");
144
            return;
145
         }
146
         if (ctx->Fog.FogCoordinateSource == p)
147
            return;
148
         FLUSH_VERTICES(ctx, _NEW_FOG);
149
         ctx->Fog.FogCoordinateSource = p;
150
         break;
151
      }
152
      default:
153
         _mesa_error( ctx, GL_INVALID_ENUM, "glFog" );
154
         return;
155
   }
156
 
157
   if (ctx->Driver.Fogfv) {
158
      (*ctx->Driver.Fogfv)( ctx, pname, params );
159
   }
160
}