1 /**************************************************************************
3 Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
16 The above copyright notice and this permission notice (including the
17 next paragraph) shall be included in all copies or substantial
18 portions of the Software.
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 **************************************************************************/
32 * Keith Whitwell <keithw@vmware.com>
35 #include "main/glheader.h"
36 #include "main/imports.h"
37 #include "main/context.h"
38 #include "main/mtypes.h"
39 #include "main/enums.h"
40 #include "main/macros.h"
42 #include "radeon_screen.h"
43 #include "radeon_fog.h"
45 /**********************************************************************/
46 /* Fog blend factor computation for hw tcl */
47 /* same calculation used as in t_vb_fog.c */
48 /**********************************************************************/
50 #define FOG_EXP_TABLE_SIZE 256
51 #define FOG_MAX (10.0)
52 #define EXP_FOG_MAX .0006595
53 #define FOG_INCR (FOG_MAX/FOG_EXP_TABLE_SIZE)
54 static GLfloat exp_table
[FOG_EXP_TABLE_SIZE
];
57 #define NEG_EXP( result, narg ) \
59 GLfloat f = (GLfloat) (narg * (1.0/FOG_INCR)); \
60 GLint k = (GLint) f; \
61 if (k > FOG_EXP_TABLE_SIZE-2) \
62 result = (GLfloat) EXP_FOG_MAX; \
64 result = exp_table[k] + (f-k)*(exp_table[k+1]-exp_table[k]); \
67 #define NEG_EXP( result, narg ) \
69 result = exp(-narg); \
75 * Initialize the exp_table[] lookup table for approximating exp().
78 radeonInitStaticFogData( void )
82 for ( ; i
< FOG_EXP_TABLE_SIZE
; i
++, f
+= FOG_INCR
) {
83 exp_table
[i
] = (GLfloat
) exp(-f
);
88 * Compute per-vertex fog blend factors from fog coordinates by
89 * evaluating the GL_LINEAR, GL_EXP or GL_EXP2 fog function.
90 * Fog coordinates are distances from the eye (typically between the
91 * near and far clip plane distances).
92 * Note the fog (eye Z) coords may be negative so we use ABS(z) below.
93 * Fog blend factors are in the range [0,1].
96 radeonComputeFogBlendFactor( struct gl_context
*ctx
, GLfloat fogcoord
)
98 GLfloat end
= ctx
->Fog
.End
;
100 const GLfloat z
= FABSF(fogcoord
);
102 switch (ctx
->Fog
.Mode
) {
104 if (ctx
->Fog
.Start
== ctx
->Fog
.End
)
107 d
= 1.0F
/ (ctx
->Fog
.End
- ctx
->Fog
.Start
);
108 temp
= (end
- z
) * d
;
109 return CLAMP(temp
, 0.0F
, 1.0F
);
112 d
= ctx
->Fog
.Density
;
113 NEG_EXP( temp
, d
* z
);
117 d
= ctx
->Fog
.Density
*ctx
->Fog
.Density
;
118 NEG_EXP( temp
, d
* z
* z
);
122 _mesa_problem(ctx
, "Bad fog mode in make_fog_coord");