Ignore:
Timestamp:
May 23, 2000, 10:41:28 PM (25 years ago)
Author:
jeroen
Message:

* empty log message *

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:28 jeroen Exp $ */
     1/* $Id: fog.c,v 1.3 2000-05-23 20:40:33 jeroen Exp $ */
    22
    33/*
    44 * Mesa 3-D graphics library
    5  * Version:  3.1
     5 * Version:  3.3
    66 *
    77 * Copyright (C) 1999  Brian Paul   All Rights Reserved.
     
    3131#include "all.h"
    3232#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"
    3934#include "types.h"
    4035#include "context.h"
     
    4742
    4843
    49 void gl_Fogfv( GLcontext *ctx, GLenum pname, const GLfloat *params )
    50 {
     44void
     45_mesa_Fogf(GLenum pname, GLfloat param)
     46{
     47   _mesa_Fogfv(pname, &param);
     48}
     49
     50
     51void
     52_mesa_Fogi(GLenum pname, GLint param )
     53{
     54   GLfloat fparam = (GLfloat) param;
     55   _mesa_Fogfv(pname, &fparam);
     56}
     57
     58
     59void
     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
     85void
     86_mesa_Fogfv( GLenum pname, const GLfloat *params )
     87{
     88   GET_CURRENT_CONTEXT(ctx);
    5189   GLenum m;
    5290
     
    5492      case GL_FOG_MODE:
    5593         m = (GLenum) (GLint) *params;
    56         if (m==GL_LINEAR || m==GL_EXP || m==GL_EXP2) {
    57             ctx->Fog.Mode = m;
    58         }
    59         else {
    60             gl_error( ctx, GL_INVALID_ENUM, "glFog" );
     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" );
    6199            return;
    62         }
    63         break;
     100        }
     101        break;
    64102      case GL_FOG_DENSITY:
    65         if (*params<0.0) {
    66             gl_error( ctx, GL_INVALID_VALUE, "glFog" );
     103        if (*params<0.0) {
     104            gl_error( ctx, GL_INVALID_VALUE, "glFog" );
    67105            return;
    68         }
    69         else {
    70             ctx->Fog.Density = *params;
    71         }
    72         break;
     106        }
     107        else {
     108            ctx->Fog.Density = *params;
     109        }
     110        break;
    73111      case GL_FOG_START:
    74         ctx->Fog.Start = *params;
    75         break;
     112        ctx->Fog.Start = *params;
     113        break;
    76114      case GL_FOG_END:
    77         ctx->Fog.End = *params;
    78         break;
     115        ctx->Fog.End = *params;
     116        break;
    79117      case GL_FOG_INDEX:
    80         ctx->Fog.Index = *params;
    81         break;
     118        ctx->Fog.Index = *params;
     119        break;
    82120      case GL_FOG_COLOR:
    83         ctx->Fog.Color[0] = params[0];
    84         ctx->Fog.Color[1] = params[1];
    85         ctx->Fog.Color[2] = params[2];
    86         ctx->Fog.Color[3] = params[3];
     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];
    87125         break;
    88126      default:
     
    100138
    101139typedef void (*fog_func)( struct vertex_buffer *VB, GLuint side,
    102                           GLubyte flag );
     140                          GLubyte flag );
    103141
    104142typedef void (*fog_coord_func)( struct vertex_buffer *VB,
    105                                 const GLvector4f *from,
    106                                 GLubyte flag );
     143                                const GLvector4f *from,
     144                                GLubyte flag );
    107145
    108146static fog_func fog_ci_tab[2];
     
    128166#include "fog_tmp.h"
    129167
    130 void gl_init_fog( void )
     168
     169void
     170_mesa_init_fog( void )
    131171{
    132172   init_fog_tab_masked();
     
    134174}
    135175
     176
    136177/*
    137178 * Compute fog for the vertices in the vertex buffer.
    138179 */
    139 void gl_fog_vertices( struct vertex_buffer *VB )
     180void
     181_mesa_fog_vertices( struct vertex_buffer *VB )
    140182{
    141183   GLcontext *ctx = VB->ctx;
     
    145187      /* Fog RGB colors */
    146188      if (ctx->TriangleCaps & DD_TRI_LIGHT_TWOSIDE) {
    147         fog_rgba_tab[i]( VB, 0, VERT_FACE_FRONT );
    148         fog_rgba_tab[i]( VB, 1, VERT_FACE_REAR );
     189        fog_rgba_tab[i]( VB, 0, VERT_FACE_FRONT );
     190        fog_rgba_tab[i]( VB, 1, VERT_FACE_REAR );
    149191      } else {
    150         fog_rgba_tab[i]( VB, 0, VERT_FACE_FRONT|VERT_FACE_REAR );
     192        fog_rgba_tab[i]( VB, 0, VERT_FACE_FRONT|VERT_FACE_REAR );
    151193      }
    152194   }
     
    154196      /* Fog color indexes */
    155197      if (ctx->TriangleCaps & DD_TRI_LIGHT_TWOSIDE) {
    156         fog_ci_tab[i]( VB, 0, VERT_FACE_FRONT );
     198        fog_ci_tab[i]( VB, 0, VERT_FACE_FRONT );
    157199         fog_ci_tab[i]( VB, 1, VERT_FACE_REAR );
    158200      } else {
    159         fog_ci_tab[i]( VB, 0, VERT_FACE_FRONT|VERT_FACE_REAR );
     201        fog_ci_tab[i]( VB, 0, VERT_FACE_FRONT|VERT_FACE_REAR );
    160202      }
    161203   }
     
    175217}
    176218
    177 void gl_make_fog_coords( struct vertex_buffer *VB )
     219
     220static void gl_make_fog_coords( struct vertex_buffer *VB )
    178221{
    179222   GLcontext *ctx = VB->ctx;
     
    192235
    193236      gl_dotprod_tab[0][VB->ObjPtr->size](&VB->Eye,
    194                                           2, /* fill z coordinates */
    195                                           VB->ObjPtr,
    196                                           plane,
    197                                           0 );
     237                                          2, /* fill z coordinates */
     238                                          VB->ObjPtr,
     239                                          plane,
     240                                          0 );
    198241
    199242      make_fog_coord_tab[0]( VB, &VB->Eye, 0 );
     
    233276 * Output:  red, green, blue, alpha - fogged pixel colors
    234277 */
    235 void gl_fog_rgba_pixels( const GLcontext *ctx,
    236                          GLuint n, const GLdepth z[], GLubyte rgba[][4] )
     278void
     279_mesa_fog_rgba_pixels( const GLcontext *ctx,
     280                       GLuint n, const GLdepth z[], GLubyte rgba[][4] )
    237281{
    238282   GLfloat c = ctx->ProjectionMatrix.m[10];
     
    265309            }
    266310         }
    267         break;
     311        break;
    268312      case GL_EXP:
    269         for (i=0;i<n;i++) {
    270             GLfloat ndcz = ((GLfloat) z[i] - tz) * szInv;
    271             GLfloat eyez = d / (c+ndcz);
     313        for (i=0;i<n;i++) {
     314            GLfloat ndcz = ((GLfloat) z[i] - tz) * szInv;
     315            GLfloat eyez = d / (c+ndcz);
    272316            GLfloat f, g;
    273             if (eyez < 0.0)
     317            if (eyez < 0.0)
    274318               eyez = -eyez;
    275             f = exp( -ctx->Fog.Density * eyez );
     319            f = exp( -ctx->Fog.Density * eyez );
    276320            g = 1.0F - f;
    277321            rgba[i][RCOMP] = (GLint) (f * rgba[i][RCOMP] + g * rFog);
    278322            rgba[i][GCOMP] = (GLint) (f * rgba[i][GCOMP] + g * gFog);
    279323            rgba[i][BCOMP] = (GLint) (f * rgba[i][BCOMP] + g * bFog);
    280         }
    281         break;
     324        }
     325        break;
    282326      case GL_EXP2:
    283327         {
     
    301345            }
    302346         }
    303         break;
     347        break;
    304348      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");
    306350         return;
    307351   }
     
    318362 * Output:  index - fogged pixel color indexes
    319363 */
    320 void gl_fog_ci_pixels( const GLcontext *ctx,
    321                        GLuint n, const GLdepth z[], GLuint index[] )
     364void
     365_mesa_fog_ci_pixels( const GLcontext *ctx,
     366                     GLuint n, const GLdepth z[], GLuint index[] )
    322367{
    323368   GLfloat c = ctx->ProjectionMatrix.m[10];
     
    342387               index[i] = (GLuint) ((GLfloat) index[i] + (1.0F-f) * ctx->Fog.Index);
    343388            }
    344         }
    345         break;
     389        }
     390        break;
    346391      case GL_EXP:
    347392         for (i=0;i<n;i++) {
    348             GLfloat ndcz = ((GLfloat) z[i] - tz) * szInv;
    349             GLfloat eyez = -d / (c+ndcz);
     393            GLfloat ndcz = ((GLfloat) z[i] - tz) * szInv;
     394            GLfloat eyez = -d / (c+ndcz);
    350395            GLfloat f;
    351             if (eyez < 0.0)
     396            if (eyez < 0.0)
    352397               eyez = -eyez;
    353             f = exp( -ctx->Fog.Density * eyez );
    354             f = CLAMP( f, 0.0F, 1.0F );
    355             index[i] = (GLuint) ((GLfloat) index[i] + (1.0F-f) * ctx->Fog.Index);
    356         }
    357         break;
     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;
    358403      case GL_EXP2:
    359404         {
     
    376421               index[i] = (GLuint) ((GLfloat) index[i] + (1.0F-f) * ctx->Fog.Index);
    377422            }
    378         }
    379         break;
     423        }
     424        break;
    380425      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");
    382427         return;
    383428   }
Note: See TracChangeset for help on using the changeset viewer.