X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Ffog.c;h=50a61bd84bff8bfac1cdfc7306be2a7a3b92062e;hb=4147bb24d49a10498e00039fc1dc9aa5f1316777;hp=0c1214e9a3b94547a889540c994ed757508c3dfc;hpb=08836341788a9f9d638d9dc8328510ccd18ddeb5;p=mesa.git diff --git a/src/mesa/main/fog.c b/src/mesa/main/fog.c index 0c1214e9a3b..50a61bd84bf 100644 --- a/src/mesa/main/fog.c +++ b/src/mesa/main/fog.c @@ -1,10 +1,8 @@ -/* $Id: fog.c,v 1.33 2001/03/03 20:33:27 brianp Exp $ */ - /* * Mesa 3-D graphics library - * Version: 3.5 + * Version: 5.1 * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2003 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -25,26 +23,22 @@ */ -#ifdef PC_HEADER -#include "all.h" -#else #include "glheader.h" #include "colormac.h" #include "context.h" #include "fog.h" #include "mtypes.h" -#endif -void +void GLAPIENTRY _mesa_Fogf(GLenum pname, GLfloat param) { _mesa_Fogfv(pname, ¶m); } -void +void GLAPIENTRY _mesa_Fogi(GLenum pname, GLint param ) { GLfloat fparam = (GLfloat) param; @@ -52,7 +46,7 @@ _mesa_Fogi(GLenum pname, GLint param ) } -void +void GLAPIENTRY _mesa_Fogiv(GLenum pname, const GLint *params ) { GLfloat p[4]; @@ -79,7 +73,15 @@ _mesa_Fogiv(GLenum pname, const GLint *params ) } -void +#define UPDATE_FOG_SCALE(ctx) do {\ + if (ctx->Fog.End == ctx->Fog.Start)\ + ctx->Fog._Scale = 1.0f;\ + else\ + ctx->Fog._Scale = 1.0f / (ctx->Fog.End - ctx->Fog.Start);\ + } while(0) + + +void GLAPIENTRY _mesa_Fogfv( GLenum pname, const GLfloat *params ) { GET_CURRENT_CONTEXT(ctx); @@ -114,17 +116,19 @@ _mesa_Fogfv( GLenum pname, const GLfloat *params ) ctx->Fog.Density = *params; break; case GL_FOG_START: - if (ctx->Fog.Start == *params) - return; - FLUSH_VERTICES(ctx, _NEW_FOG); - ctx->Fog.Start = *params; - break; + if (ctx->Fog.Start == *params) + return; + FLUSH_VERTICES(ctx, _NEW_FOG); + ctx->Fog.Start = *params; + UPDATE_FOG_SCALE(ctx); + break; case GL_FOG_END: - if (ctx->Fog.End == *params) - return; - FLUSH_VERTICES(ctx, _NEW_FOG); - ctx->Fog.End = *params; - break; + if (ctx->Fog.End == *params) + return; + FLUSH_VERTICES(ctx, _NEW_FOG); + ctx->Fog.End = *params; + UPDATE_FOG_SCALE(ctx); + break; case GL_FOG_INDEX: if (ctx->Fog.Index == *params) return; @@ -132,18 +136,19 @@ _mesa_Fogfv( GLenum pname, const GLfloat *params ) ctx->Fog.Index = *params; break; case GL_FOG_COLOR: - if (TEST_EQ_4V(ctx->Fog.Color, params)) + if (TEST_EQ_4V(ctx->Fog.Color, params)) return; FLUSH_VERTICES(ctx, _NEW_FOG); - ctx->Fog.Color[0] = params[0]; - ctx->Fog.Color[1] = params[1]; - ctx->Fog.Color[2] = params[2]; - ctx->Fog.Color[3] = params[3]; + ctx->Fog.Color[0] = CLAMP(params[0], 0.0F, 1.0F); + ctx->Fog.Color[1] = CLAMP(params[1], 0.0F, 1.0F); + ctx->Fog.Color[2] = CLAMP(params[2], 0.0F, 1.0F); + ctx->Fog.Color[3] = CLAMP(params[3], 0.0F, 1.0F); break; case GL_FOG_COORDINATE_SOURCE_EXT: { - GLenum p = (GLenum)(GLint) *params; - if (p != GL_FOG_COORDINATE_EXT && p != GL_FRAGMENT_DEPTH_EXT) { - _mesa_error( ctx, GL_INVALID_ENUM, "glFog" ); + GLenum p = (GLenum) (GLint) *params; + if (!ctx->Extensions.EXT_fog_coord || + (p != GL_FOG_COORDINATE_EXT && p != GL_FRAGMENT_DEPTH_EXT)) { + _mesa_error(ctx, GL_INVALID_ENUM, "glFog"); return; } if (ctx->Fog.FogCoordinateSource == p) @@ -163,3 +168,21 @@ _mesa_Fogfv( GLenum pname, const GLfloat *params ) } +/**********************************************************************/ +/***** Initialization *****/ +/**********************************************************************/ + +void _mesa_init_fog( GLcontext * ctx ) +{ + /* Fog group */ + ctx->Fog.Enabled = GL_FALSE; + ctx->Fog.Mode = GL_EXP; + ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 ); + ctx->Fog.Index = 0.0; + ctx->Fog.Density = 1.0; + ctx->Fog.Start = 0.0; + ctx->Fog.End = 1.0; + ctx->Fog.ColorSumEnabled = GL_FALSE; + ctx->Fog.FogCoordinateSource = GL_FRAGMENT_DEPTH_EXT; + ctx->Fog._Scale = 1.0f; +}