Changeset 3598 for trunk/src/opengl/mesa/fog.c
- Timestamp:
- May 23, 2000, 10:41:28 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/opengl/mesa/fog.c
r2962 r3598 1 /* $Id: fog.c,v 1. 2 2000-03-01 18:49:28jeroen Exp $ */1 /* $Id: fog.c,v 1.3 2000-05-23 20:40:33 jeroen Exp $ */ 2 2 3 3 /* 4 4 * Mesa 3-D graphics library 5 * Version: 3. 15 * Version: 3.3 6 6 * 7 7 * Copyright (C) 1999 Brian Paul All Rights Reserved. … … 31 31 #include "all.h" 32 32 #else 33 #ifndef XFree86Server 34 #include <math.h> 35 #include <stdlib.h> 36 #else 37 #include "GL/xf86glx.h" 38 #endif 33 #include "glheader.h" 39 34 #include "types.h" 40 35 #include "context.h" … … 47 42 48 43 49 void gl_Fogfv( GLcontext *ctx, GLenum pname, const GLfloat *params ) 50 { 44 void 45 _mesa_Fogf(GLenum pname, GLfloat param) 46 { 47 _mesa_Fogfv(pname, ¶m); 48 } 49 50 51 void 52 _mesa_Fogi(GLenum pname, GLint param ) 53 { 54 GLfloat fparam = (GLfloat) param; 55 _mesa_Fogfv(pname, &fparam); 56 } 57 58 59 void 60 _mesa_Fogiv(GLenum pname, const GLint *params ) 61 { 62 GLfloat p[4]; 63 switch (pname) { 64 case GL_FOG_MODE: 65 case GL_FOG_DENSITY: 66 case GL_FOG_START: 67 case GL_FOG_END: 68 case GL_FOG_INDEX: 69 p[0] = (GLfloat) *params; 70 break; 71 case GL_FOG_COLOR: 72 p[0] = INT_TO_FLOAT( params[0] ); 73 p[1] = INT_TO_FLOAT( params[1] ); 74 p[2] = INT_TO_FLOAT( params[2] ); 75 p[3] = INT_TO_FLOAT( params[3] ); 76 break; 77 default: 78 /* Error will be caught later in _mesa_Fogfv */ 79 ; 80 } 81 _mesa_Fogfv(pname, p); 82 } 83 84 85 void 86 _mesa_Fogfv( GLenum pname, const GLfloat *params ) 87 { 88 GET_CURRENT_CONTEXT(ctx); 51 89 GLenum m; 52 90 … … 54 92 case GL_FOG_MODE: 55 93 m = (GLenum) (GLint) *params; 56 57 58 59 60 94 if (m==GL_LINEAR || m==GL_EXP || m==GL_EXP2) { 95 ctx->Fog.Mode = m; 96 } 97 else { 98 gl_error( ctx, GL_INVALID_ENUM, "glFog" ); 61 99 return; 62 63 100 } 101 break; 64 102 case GL_FOG_DENSITY: 65 66 103 if (*params<0.0) { 104 gl_error( ctx, GL_INVALID_VALUE, "glFog" ); 67 105 return; 68 69 70 71 72 106 } 107 else { 108 ctx->Fog.Density = *params; 109 } 110 break; 73 111 case GL_FOG_START: 74 75 112 ctx->Fog.Start = *params; 113 break; 76 114 case GL_FOG_END: 77 78 115 ctx->Fog.End = *params; 116 break; 79 117 case GL_FOG_INDEX: 80 81 118 ctx->Fog.Index = *params; 119 break; 82 120 case GL_FOG_COLOR: 83 84 85 86 121 ctx->Fog.Color[0] = params[0]; 122 ctx->Fog.Color[1] = params[1]; 123 ctx->Fog.Color[2] = params[2]; 124 ctx->Fog.Color[3] = params[3]; 87 125 break; 88 126 default: … … 100 138 101 139 typedef void (*fog_func)( struct vertex_buffer *VB, GLuint side, 102 140 GLubyte flag ); 103 141 104 142 typedef void (*fog_coord_func)( struct vertex_buffer *VB, 105 106 143 const GLvector4f *from, 144 GLubyte flag ); 107 145 108 146 static fog_func fog_ci_tab[2]; … … 128 166 #include "fog_tmp.h" 129 167 130 void gl_init_fog( void ) 168 169 void 170 _mesa_init_fog( void ) 131 171 { 132 172 init_fog_tab_masked(); … … 134 174 } 135 175 176 136 177 /* 137 178 * Compute fog for the vertices in the vertex buffer. 138 179 */ 139 void gl_fog_vertices( struct vertex_buffer *VB ) 180 void 181 _mesa_fog_vertices( struct vertex_buffer *VB ) 140 182 { 141 183 GLcontext *ctx = VB->ctx; … … 145 187 /* Fog RGB colors */ 146 188 if (ctx->TriangleCaps & DD_TRI_LIGHT_TWOSIDE) { 147 148 189 fog_rgba_tab[i]( VB, 0, VERT_FACE_FRONT ); 190 fog_rgba_tab[i]( VB, 1, VERT_FACE_REAR ); 149 191 } else { 150 192 fog_rgba_tab[i]( VB, 0, VERT_FACE_FRONT|VERT_FACE_REAR ); 151 193 } 152 194 } … … 154 196 /* Fog color indexes */ 155 197 if (ctx->TriangleCaps & DD_TRI_LIGHT_TWOSIDE) { 156 198 fog_ci_tab[i]( VB, 0, VERT_FACE_FRONT ); 157 199 fog_ci_tab[i]( VB, 1, VERT_FACE_REAR ); 158 200 } else { 159 201 fog_ci_tab[i]( VB, 0, VERT_FACE_FRONT|VERT_FACE_REAR ); 160 202 } 161 203 } … … 175 217 } 176 218 177 void gl_make_fog_coords( struct vertex_buffer *VB ) 219 220 static void gl_make_fog_coords( struct vertex_buffer *VB ) 178 221 { 179 222 GLcontext *ctx = VB->ctx; … … 192 235 193 236 gl_dotprod_tab[0][VB->ObjPtr->size](&VB->Eye, 194 195 196 197 237 2, /* fill z coordinates */ 238 VB->ObjPtr, 239 plane, 240 0 ); 198 241 199 242 make_fog_coord_tab[0]( VB, &VB->Eye, 0 ); … … 233 276 * Output: red, green, blue, alpha - fogged pixel colors 234 277 */ 235 void gl_fog_rgba_pixels( const GLcontext *ctx, 236 GLuint n, const GLdepth z[], GLubyte rgba[][4] ) 278 void 279 _mesa_fog_rgba_pixels( const GLcontext *ctx, 280 GLuint n, const GLdepth z[], GLubyte rgba[][4] ) 237 281 { 238 282 GLfloat c = ctx->ProjectionMatrix.m[10]; … … 265 309 } 266 310 } 267 311 break; 268 312 case GL_EXP: 269 270 271 313 for (i=0;i<n;i++) { 314 GLfloat ndcz = ((GLfloat) z[i] - tz) * szInv; 315 GLfloat eyez = d / (c+ndcz); 272 316 GLfloat f, g; 273 317 if (eyez < 0.0) 274 318 eyez = -eyez; 275 319 f = exp( -ctx->Fog.Density * eyez ); 276 320 g = 1.0F - f; 277 321 rgba[i][RCOMP] = (GLint) (f * rgba[i][RCOMP] + g * rFog); 278 322 rgba[i][GCOMP] = (GLint) (f * rgba[i][GCOMP] + g * gFog); 279 323 rgba[i][BCOMP] = (GLint) (f * rgba[i][BCOMP] + g * bFog); 280 281 324 } 325 break; 282 326 case GL_EXP2: 283 327 { … … 301 345 } 302 346 } 303 347 break; 304 348 default: 305 gl_problem(ctx, "Bad fog mode in gl_fog_rgba_pixels");349 gl_problem(ctx, "Bad fog mode in _mesa_fog_rgba_pixels"); 306 350 return; 307 351 } … … 318 362 * Output: index - fogged pixel color indexes 319 363 */ 320 void gl_fog_ci_pixels( const GLcontext *ctx, 321 GLuint n, const GLdepth z[], GLuint index[] ) 364 void 365 _mesa_fog_ci_pixels( const GLcontext *ctx, 366 GLuint n, const GLdepth z[], GLuint index[] ) 322 367 { 323 368 GLfloat c = ctx->ProjectionMatrix.m[10]; … … 342 387 index[i] = (GLuint) ((GLfloat) index[i] + (1.0F-f) * ctx->Fog.Index); 343 388 } 344 345 389 } 390 break; 346 391 case GL_EXP: 347 392 for (i=0;i<n;i++) { 348 349 393 GLfloat ndcz = ((GLfloat) z[i] - tz) * szInv; 394 GLfloat eyez = -d / (c+ndcz); 350 395 GLfloat f; 351 396 if (eyez < 0.0) 352 397 eyez = -eyez; 353 354 355 356 357 398 f = exp( -ctx->Fog.Density * eyez ); 399 f = CLAMP( f, 0.0F, 1.0F ); 400 index[i] = (GLuint) ((GLfloat) index[i] + (1.0F-f) * ctx->Fog.Index); 401 } 402 break; 358 403 case GL_EXP2: 359 404 { … … 376 421 index[i] = (GLuint) ((GLfloat) index[i] + (1.0F-f) * ctx->Fog.Index); 377 422 } 378 379 423 } 424 break; 380 425 default: 381 gl_problem(ctx, "Bad fog mode in gl_fog_ci_pixels");426 gl_problem(ctx, "Bad fog mode in _mesa_fog_ci_pixels"); 382 427 return; 383 428 }
Note:
See TracChangeset
for help on using the changeset viewer.