Ignore:
Timestamp:
May 21, 2000, 10:57:14 PM (25 years ago)
Author:
jeroen
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/opengl/mesa/fog_tmp.h

    r2938 r3582  
    1 /* $Id: fog_tmp.h,v 1.1 2000-02-29 00:48:30 sandervl Exp $ */
     1/* $Id: fog_tmp.h,v 1.2 2000-05-21 20:46:23 jeroen Exp $ */
    22
    33/*
     
    2929 */
    3030static void TAG(make_fog_coord)( struct vertex_buffer *VB,
    31                                 const GLvector4f *eye,
    32                                 GLubyte flag)
     31                                const GLvector4f *eye,
     32                                GLubyte flag)
    3333{
    3434   const GLcontext *ctx = VB->ctx;
     
    3838   GLuint stride = eye->stride;
    3939   GLuint n = VB->Count - VB->Start;
    40    GLubyte (*out)[4];           
     40   GLubyte (*out)[4];
    4141   GLfloat d;
    4242   GLuint i;
     
    5252      switch (ctx->Fog.Mode) {
    5353      case GL_LINEAR:
    54         d = 1.0F / (ctx->Fog.End - ctx->Fog.Start);
    55         for ( i = 0 ; i < n ; i++, STRIDE_F(v, stride)) {
    56             CULLCHECK {
    57                GLfloat f = (end - ABSF(v[2])) * d;
    58                FLOAT_COLOR_TO_UBYTE_COLOR(out[i][3], f);
    59             }
    60         }
    61         break;
     54        d = 1.0F / (ctx->Fog.End - ctx->Fog.Start);
     55        for ( i = 0 ; i < n ; i++, STRIDE_F(v, stride)) {
     56            CULLCHECK {
     57               GLfloat f = (end - ABSF(v[2])) * d;
     58               FLOAT_COLOR_TO_UBYTE_COLOR(out[i][3], f);
     59            }
     60        }
     61        break;
    6262      case GL_EXP:
    63         d = -ctx->Fog.Density;
    64         for ( i = 0 ; i < n ; i++, STRIDE_F(v,stride)) {
    65             CULLCHECK {
    66                GLfloat f = exp( d*ABSF(v[2]) ); /* already clamped */
    67                FLOAT_COLOR_TO_UBYTE_COLOR(out[i][3], f);
    68             }
    69         }
    70         break;
     63        d = -ctx->Fog.Density;
     64        for ( i = 0 ; i < n ; i++, STRIDE_F(v,stride)) {
     65            CULLCHECK {
     66               GLfloat f = exp( d*ABSF(v[2]) ); /* already clamped */
     67               FLOAT_COLOR_TO_UBYTE_COLOR(out[i][3], f);
     68            }
     69        }
     70        break;
    7171      case GL_EXP2:
    72         d = -(ctx->Fog.Density*ctx->Fog.Density);
    73         for ( i = 0 ; i < n ; i++, STRIDE_F(v, stride)) {
    74             CULLCHECK {
    75                GLfloat z = v[2];
    76                GLfloat f = exp( d*z*z ); /* already clamped */
    77                FLOAT_COLOR_TO_UBYTE_COLOR(out[i][3], f);
    78             }
    79         }
    80         break;
     72        d = -(ctx->Fog.Density*ctx->Fog.Density);
     73        for ( i = 0 ; i < n ; i++, STRIDE_F(v, stride)) {
     74            CULLCHECK {
     75               GLfloat z = v[2];
     76               GLfloat f = exp( d*z*z ); /* already clamped */
     77               FLOAT_COLOR_TO_UBYTE_COLOR(out[i][3], f);
     78            }
     79        }
     80        break;
    8181      default:
    82         gl_problem(ctx, "Bad fog mode in make_fog_coord");
    83         return;
     82        gl_problem(ctx, "Bad fog mode in make_fog_coord");
     83        return;
    8484      }
    8585   }
     
    8989
    9090      if (ctx->Fog.Mode == GL_LINEAR) {
    91         GLfloat f = ctx->Fog.End * (ctx->Fog.End - ctx->Fog.Start);
    92         CLAMP_FLOAT_COLOR( f );
    93         f = 1.0 - f;
    94         FLOAT_COLOR_TO_UBYTE_COLOR(r, f);
     91        GLfloat f = ctx->Fog.End * (ctx->Fog.End - ctx->Fog.Start);
     92        CLAMP_FLOAT_COLOR( f );
     93        f = 1.0 - f;
     94        FLOAT_COLOR_TO_UBYTE_COLOR(r, f);
    9595      }
    9696
    9797      for (i = 0 ; i < n ; i++)
    98         out[i][3] = r;
     98        out[i][3] = r;
    9999   }
    100100}
     
    105105
    106106#if 0
    107 /* For 3.3: use fog coordinates as intermediate step in all fog
     107/* TODO : use fog coordinates as intermediate step in all fog
    108108 * calculations.
    109109 */
    110110
    111111static void TAG(fog_rgba_vertices)( struct vertex_buffer *VB,
    112                                     GLuint side,
    113                                     GLubyte flag)
     112                                    GLuint side,
     113                                    GLubyte flag)
    114114{
    115115   const GLcontext *ctx = VB->ctx;
     
    143143   for ( i = 0 ; i < n ; i++, STRIDE_F(spec, sp_stride), in += in_stride) {
    144144      CULLCHECK {
    145         GLint fc = (GLint) spec[3], ifc = 255 - fc;
    146        
    147         out[i][0] = (fc * in[0] + ifc * rFog) >> 8;
    148         out[i][1] = (fc * in[1] + ifc * gFog) >> 8;
    149         out[i][2] = (fc * in[2] + ifc * bFog) >> 8;
     145        GLint fc = (GLint) spec[3], ifc = 255 - fc;
     146
     147        out[i][0] = (fc * in[0] + ifc * rFog) >> 8;
     148        out[i][1] = (fc * in[1] + ifc * gFog) >> 8;
     149        out[i][2] = (fc * in[2] + ifc * bFog) >> 8;
    150150      }
    151151   }
     
    155155
    156156static void TAG(fog_ci_vertices)( struct vertex_buffer *VB,
    157                                   GLuint side,
    158                                   GLubyte flag )
     157                                  GLuint side,
     158                                  GLubyte flag )
    159159{
    160160   GLcontext *ctx = VB->ctx;
     
    182182
    183183
    184    /* NOTE: the extensive use of casts generates better/faster code for MIPS */
     184   /* NOTE: the use of casts generates better/faster code for MIPS */
    185185   for ( i = 0; i < n ; i++, STRIDE_F(v,stride), STRIDE_UI(in,in_stride))
    186186      CULLCHECK {
     
    200200
    201201static void TAG(fog_rgba_vertices)( struct vertex_buffer *VB,
    202                                     GLuint side,
    203                                     GLubyte flag)
     202                                    GLuint side,
     203                                    GLubyte flag)
    204204{
    205205   const GLcontext *ctx = VB->ctx;
     
    233233      switch (ctx->Fog.Mode) {
    234234      case GL_LINEAR:
    235         d = 1.0F / (ctx->Fog.End - ctx->Fog.Start);
    236         for ( i = 0 ; i < n ; i++, STRIDE_F(v, stride), in += in_stride) {
    237             CULLCHECK {
    238                GLfloat f = (end - ABSF(v[2])) * d;
    239                if (f >= 1.0) continue;
    240                if (f < 0) {
    241                   CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][0], rFog);
    242                   CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][1], gFog);
    243                   CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][2], bFog);
    244                } else {
    245                   t = f * UBYTE_COLOR_TO_FLOAT_COLOR(in[0]) + (1.0F-f)*rFog;
    246                   CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][0], t);
    247        
    248                   t = f * UBYTE_COLOR_TO_FLOAT_COLOR(in[1]) + (1.0F-f)*gFog;
    249                   CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][1], t);
    250        
    251                   t = f * UBYTE_COLOR_TO_FLOAT_COLOR(in[2]) + (1.0F-f)*bFog;
    252                   CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][2], t);
    253 
    254                }
    255             }
    256         }
    257         break;
     235        d = 1.0F / (ctx->Fog.End - ctx->Fog.Start);
     236        for ( i = 0 ; i < n ; i++, STRIDE_F(v, stride), in += in_stride) {
     237            CULLCHECK {
     238               GLfloat f = (end - ABSF(v[2])) * d;
     239               if (f >= 1.0) continue;
     240               if (f < 0) {
     241                  CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][0], rFog);
     242                  CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][1], gFog);
     243                  CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][2], bFog);
     244               } else {
     245                  t = f * UBYTE_COLOR_TO_FLOAT_COLOR(in[0]) + (1.0F-f)*rFog;
     246                  CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][0], t);
     247
     248                  t = f * UBYTE_COLOR_TO_FLOAT_COLOR(in[1]) + (1.0F-f)*gFog;
     249                  CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][1], t);
     250
     251                  t = f * UBYTE_COLOR_TO_FLOAT_COLOR(in[2]) + (1.0F-f)*bFog;
     252                  CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][2], t);
     253
     254               }
     255            }
     256        }
     257        break;
    258258      case GL_EXP:
    259         d = -ctx->Fog.Density;
    260         for ( i = 0 ; i < n ; i++, STRIDE_F(v,stride), in += in_stride) {
    261             CULLCHECK {
    262                GLfloat f = exp( d*ABSF(v[2]) ); /* already clamped */
    263 
    264                t = f * UBYTE_COLOR_TO_FLOAT_COLOR(in[0]) + (1.0F-f)*rFog;
    265                CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][0], t);
    266        
    267                t = f * UBYTE_COLOR_TO_FLOAT_COLOR(in[1]) + (1.0F-f)*gFog;
    268                CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][1], t);
    269        
    270                t = f * UBYTE_COLOR_TO_FLOAT_COLOR(in[2]) + (1.0F-f)*bFog;
    271                CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][2], t);
    272             }
    273         }
    274         break;
     259        d = -ctx->Fog.Density;
     260        for ( i = 0 ; i < n ; i++, STRIDE_F(v,stride), in += in_stride) {
     261            CULLCHECK {
     262               GLfloat f = exp( d*ABSF(v[2]) ); /* already clamped */
     263
     264               t = f * UBYTE_COLOR_TO_FLOAT_COLOR(in[0]) + (1.0F-f)*rFog;
     265               CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][0], t);
     266
     267               t = f * UBYTE_COLOR_TO_FLOAT_COLOR(in[1]) + (1.0F-f)*gFog;
     268               CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][1], t);
     269
     270               t = f * UBYTE_COLOR_TO_FLOAT_COLOR(in[2]) + (1.0F-f)*bFog;
     271               CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][2], t);
     272            }
     273        }
     274        break;
    275275      case GL_EXP2:
    276         d = -(ctx->Fog.Density*ctx->Fog.Density);
    277         for ( i = 0 ; i < n ; i++, STRIDE_F(v, stride), in += in_stride) {
    278             CULLCHECK {
    279                GLfloat z = v[2];
    280                GLfloat f = exp( d*z*z ); /* already clamped */
    281 
    282                t = f * UBYTE_COLOR_TO_FLOAT_COLOR(in[0]) + (1.0F-f)*rFog;
    283                CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][0], t);
    284        
    285                t = f * UBYTE_COLOR_TO_FLOAT_COLOR(in[1]) + (1.0F-f)*gFog;
    286                CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][1], t);
    287        
    288                t = f * UBYTE_COLOR_TO_FLOAT_COLOR(in[2]) + (1.0F-f)*bFog;
    289                CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][2], t);
    290             }
    291         }
    292         break;
    293         default:
    294             gl_problem(ctx, "Bad fog mode in gl_fog_rgba_vertices");
    295         return;
     276        d = -(ctx->Fog.Density*ctx->Fog.Density);
     277        for ( i = 0 ; i < n ; i++, STRIDE_F(v, stride), in += in_stride) {
     278            CULLCHECK {
     279               GLfloat z = v[2];
     280               GLfloat f = exp( d*z*z ); /* already clamped */
     281
     282               t = f * UBYTE_COLOR_TO_FLOAT_COLOR(in[0]) + (1.0F-f)*rFog;
     283               CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][0], t);
     284
     285               t = f * UBYTE_COLOR_TO_FLOAT_COLOR(in[1]) + (1.0F-f)*gFog;
     286               CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][1], t);
     287
     288               t = f * UBYTE_COLOR_TO_FLOAT_COLOR(in[2]) + (1.0F-f)*bFog;
     289               CLAMPED_FLOAT_COLOR_TO_UBYTE_COLOR(out[i][2], t);
     290            }
     291        }
     292        break;
     293        default:
     294            gl_problem(ctx, "Bad fog mode in gl_fog_rgba_vertices");
     295        return;
    296296      }
    297297   }
     
    312312
    313313      for (i = 0 ; i < n ; i++) {
    314         /* CULLCHECK */ {
    315             out[i][0] = r;
    316             out[i][1] = g;
    317             out[i][2] = b;
    318         }
     314        /* CULLCHECK */ {
     315            out[i][0] = r;
     316            out[i][1] = g;
     317            out[i][2] = b;
     318        }
    319319      }
    320320   }
     
    330330 */
    331331static void TAG(fog_ci_vertices)( struct vertex_buffer *VB,
    332                                   GLuint side,
    333                                   GLubyte flag )
     332                                  GLuint side,
     333                                  GLubyte flag )
    334334{
    335335   GLcontext *ctx = VB->ctx;
     
    362362      case GL_LINEAR:
    363363      {
    364         GLfloat d = 1.0F / (ctx->Fog.End - ctx->Fog.Start);
    365         GLfloat fogindex = ctx->Fog.Index;
    366         GLfloat fogend = ctx->Fog.End;
    367 
    368          for ( i = 0; i < n ; i++, STRIDE_F(v,stride), STRIDE_UI(in,in_stride))
    369         {
    370             CULLCHECK {
    371                GLfloat f = (fogend - ABSF(v[2])) * d;
    372                f = CLAMP( f, 0.0, 1.0 );
    373                *out = (GLint) ((GLfloat)(GLint) *in + (1.0F-f) * fogindex);
    374             }
    375         }
    376         break;
     364        GLfloat d = 1.0F / (ctx->Fog.End - ctx->Fog.Start);
     365        GLfloat fogindex = ctx->Fog.Index;
     366        GLfloat fogend = ctx->Fog.End;
     367
     368         for ( i = 0; i < n ; i++, STRIDE_F(v,stride), STRIDE_UI(in,in_stride))
     369        {
     370            CULLCHECK {
     371               GLfloat f = (fogend - ABSF(v[2])) * d;
     372               f = CLAMP( f, 0.0, 1.0 );
     373               *out = (GLint) ((GLfloat)(GLint) *in + (1.0F-f) * fogindex);
     374            }
     375        }
     376        break;
    377377      }
    378378      case GL_EXP:
    379379      {
    380         GLfloat d = -ctx->Fog.Density;
    381         GLfloat fogindex = ctx->Fog.Index;
    382          for ( i = 0; i < n ; i++, STRIDE_F(v,stride), STRIDE_UI(in,in_stride))
    383         {
    384             CULLCHECK {
    385                GLfloat f = exp( d * ABSF(v[2]) );
    386                *out = (GLint) ((GLfloat)(GLint) *in + (1.0F-f) * fogindex);
    387             }
    388         }
    389         break;
     380        GLfloat d = -ctx->Fog.Density;
     381        GLfloat fogindex = ctx->Fog.Index;
     382         for ( i = 0; i < n ; i++, STRIDE_F(v,stride), STRIDE_UI(in,in_stride))
     383        {
     384            CULLCHECK {
     385               GLfloat f = exp( d * ABSF(v[2]) );
     386               *out = (GLint) ((GLfloat)(GLint) *in + (1.0F-f) * fogindex);
     387            }
     388        }
     389        break;
    390390      }
    391391      case GL_EXP2:
    392392      {
    393         GLfloat d = -(ctx->Fog.Density*ctx->Fog.Density);
    394         GLfloat fogindex = ctx->Fog.Index;
    395          for ( i = 0; i < n ; i++, STRIDE_F(v,stride),STRIDE_UI(in,in_stride))
    396         {
    397             CULLCHECK {
    398                GLfloat z = v[2]; /*ABSF(v[i][2]);*/
    399                GLfloat f = exp( d * z*z ); /* was -d ??? */
    400                out[i] = (GLint) ((GLfloat)(GLint) *in + (1.0F-f) * fogindex);
    401             }
    402         }
    403         break;
     393        GLfloat d = -(ctx->Fog.Density*ctx->Fog.Density);
     394        GLfloat fogindex = ctx->Fog.Index;
     395         for ( i = 0; i < n ; i++, STRIDE_F(v,stride),STRIDE_UI(in,in_stride))
     396        {
     397            CULLCHECK {
     398               GLfloat z = v[2]; /*ABSF(v[i][2]);*/
     399               GLfloat f = exp( d * z*z ); /* was -d ??? */
     400               out[i] = (GLint) ((GLfloat)(GLint) *in + (1.0F-f) * fogindex);
     401            }
     402        }
     403        break;
    404404      }
    405405      default:
    406         gl_problem(ctx, "Bad fog mode in gl_fog_ci_vertices");
    407         return;
     406        gl_problem(ctx, "Bad fog mode in gl_fog_ci_vertices");
     407        return;
    408408      }
    409409   } else if (ctx->Fog.Mode == GL_LINEAR) {
     
    414414      fogindex = (GLuint)(f * ctx->Fog.Index);
    415415      if (fogindex) {
    416          for ( i = 0; i < n ; i++, STRIDE_F(v,stride), STRIDE_UI(in,in_stride))
    417         {
    418             CULLCHECK {
    419                *out = *in + fogindex;
    420             }
    421         }
     416         for ( i = 0; i < n ; i++, STRIDE_F(v,stride), STRIDE_UI(in,in_stride))
     417        {
     418            CULLCHECK {
     419               *out = *in + fogindex;
     420            }
     421        }
    422422      }
    423423   }
Note: See TracChangeset for help on using the changeset viewer.