Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenfog.c
Go to the documentation of this file.
00001 /* 00002 * Mesa 3-D graphics library 00003 * Version: 5.1 00004 * 00005 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved. 00006 * 00007 * Permission is hereby granted, free of charge, to any person obtaining a 00008 * copy of this software and associated documentation files (the "Software"), 00009 * to deal in the Software without restriction, including without limitation 00010 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00011 * and/or sell copies of the Software, and to permit persons to whom the 00012 * Software is furnished to do so, subject to the following conditions: 00013 * 00014 * The above copyright notice and this permission notice shall be included 00015 * in all copies or substantial portions of the Software. 00016 * 00017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00018 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00019 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00020 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 00021 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00022 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00023 */ 00024 00025 00026 #include "glheader.h" 00027 #include "colormac.h" 00028 #include "context.h" 00029 #include "fog.h" 00030 #include "mtypes.h" 00031 00032 00033 00034 void GLAPIENTRY 00035 _mesa_Fogf(GLenum pname, GLfloat param) 00036 { 00037 _mesa_Fogfv(pname, ¶m); 00038 } 00039 00040 00041 void GLAPIENTRY 00042 _mesa_Fogi(GLenum pname, GLint param ) 00043 { 00044 GLfloat fparam = (GLfloat) param; 00045 _mesa_Fogfv(pname, &fparam); 00046 } 00047 00048 00049 void GLAPIENTRY 00050 _mesa_Fogiv(GLenum pname, const GLint *params ) 00051 { 00052 GLfloat p[4]; 00053 switch (pname) { 00054 case GL_FOG_MODE: 00055 case GL_FOG_DENSITY: 00056 case GL_FOG_START: 00057 case GL_FOG_END: 00058 case GL_FOG_INDEX: 00059 case GL_FOG_COORDINATE_SOURCE_EXT: 00060 p[0] = (GLfloat) *params; 00061 break; 00062 case GL_FOG_COLOR: 00063 p[0] = INT_TO_FLOAT( params[0] ); 00064 p[1] = INT_TO_FLOAT( params[1] ); 00065 p[2] = INT_TO_FLOAT( params[2] ); 00066 p[3] = INT_TO_FLOAT( params[3] ); 00067 break; 00068 default: 00069 /* Error will be caught later in _mesa_Fogfv */ 00070 ; 00071 } 00072 _mesa_Fogfv(pname, p); 00073 } 00074 00075 00076 #define UPDATE_FOG_SCALE(ctx) do {\ 00077 if (ctx->Fog.End == ctx->Fog.Start)\ 00078 ctx->Fog._Scale = 1.0f;\ 00079 else\ 00080 ctx->Fog._Scale = 1.0f / (ctx->Fog.End - ctx->Fog.Start);\ 00081 } while(0) 00082 00083 00084 void GLAPIENTRY 00085 _mesa_Fogfv( GLenum pname, const GLfloat *params ) 00086 { 00087 GET_CURRENT_CONTEXT(ctx); 00088 GLenum m; 00089 ASSERT_OUTSIDE_BEGIN_END(ctx); 00090 00091 switch (pname) { 00092 case GL_FOG_MODE: 00093 m = (GLenum) (GLint) *params; 00094 switch (m) { 00095 case GL_LINEAR: 00096 case GL_EXP: 00097 case GL_EXP2: 00098 break; 00099 default: 00100 _mesa_error( ctx, GL_INVALID_ENUM, "glFog" ); 00101 return; 00102 } 00103 if (ctx->Fog.Mode == m) 00104 return; 00105 FLUSH_VERTICES(ctx, _NEW_FOG); 00106 ctx->Fog.Mode = m; 00107 break; 00108 case GL_FOG_DENSITY: 00109 if (*params<0.0) { 00110 _mesa_error( ctx, GL_INVALID_VALUE, "glFog" ); 00111 return; 00112 } 00113 if (ctx->Fog.Density == *params) 00114 return; 00115 FLUSH_VERTICES(ctx, _NEW_FOG); 00116 ctx->Fog.Density = *params; 00117 break; 00118 case GL_FOG_START: 00119 if (ctx->Fog.Start == *params) 00120 return; 00121 FLUSH_VERTICES(ctx, _NEW_FOG); 00122 ctx->Fog.Start = *params; 00123 UPDATE_FOG_SCALE(ctx); 00124 break; 00125 case GL_FOG_END: 00126 if (ctx->Fog.End == *params) 00127 return; 00128 FLUSH_VERTICES(ctx, _NEW_FOG); 00129 ctx->Fog.End = *params; 00130 UPDATE_FOG_SCALE(ctx); 00131 break; 00132 case GL_FOG_INDEX: 00133 if (ctx->Fog.Index == *params) 00134 return; 00135 FLUSH_VERTICES(ctx, _NEW_FOG); 00136 ctx->Fog.Index = *params; 00137 break; 00138 case GL_FOG_COLOR: 00139 if (TEST_EQ_4V(ctx->Fog.Color, params)) 00140 return; 00141 FLUSH_VERTICES(ctx, _NEW_FOG); 00142 ctx->Fog.Color[0] = CLAMP(params[0], 0.0F, 1.0F); 00143 ctx->Fog.Color[1] = CLAMP(params[1], 0.0F, 1.0F); 00144 ctx->Fog.Color[2] = CLAMP(params[2], 0.0F, 1.0F); 00145 ctx->Fog.Color[3] = CLAMP(params[3], 0.0F, 1.0F); 00146 break; 00147 case GL_FOG_COORDINATE_SOURCE_EXT: { 00148 GLenum p = (GLenum) (GLint) *params; 00149 if (!ctx->Extensions.EXT_fog_coord || 00150 (p != GL_FOG_COORDINATE_EXT && p != GL_FRAGMENT_DEPTH_EXT)) { 00151 _mesa_error(ctx, GL_INVALID_ENUM, "glFog"); 00152 return; 00153 } 00154 if (ctx->Fog.FogCoordinateSource == p) 00155 return; 00156 FLUSH_VERTICES(ctx, _NEW_FOG); 00157 ctx->Fog.FogCoordinateSource = p; 00158 break; 00159 } 00160 default: 00161 _mesa_error( ctx, GL_INVALID_ENUM, "glFog" ); 00162 return; 00163 } 00164 00165 if (ctx->Driver.Fogfv) { 00166 (*ctx->Driver.Fogfv)( ctx, pname, params ); 00167 } 00168 } 00169 00170 00171 /**********************************************************************/ 00172 /***** Initialization *****/ 00173 /**********************************************************************/ 00174 00175 void _mesa_init_fog( GLcontext * ctx ) 00176 { 00177 /* Fog group */ 00178 ctx->Fog.Enabled = GL_FALSE; 00179 ctx->Fog.Mode = GL_EXP; 00180 ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 ); 00181 ctx->Fog.Index = 0.0; 00182 ctx->Fog.Density = 1.0; 00183 ctx->Fog.Start = 0.0; 00184 ctx->Fog.End = 1.0; 00185 ctx->Fog.ColorSumEnabled = GL_FALSE; 00186 ctx->Fog.FogCoordinateSource = GL_FRAGMENT_DEPTH_EXT; 00187 ctx->Fog._Scale = 1.0f; 00188 } Generated on Sun May 27 2012 04:20:17 for ReactOS by
1.7.6.1
|