1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Mesa 3-D graphics library 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Copyright (C) 1999-2003 Brian Paul All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 8bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 9bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 11bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 12bf215546Sopenharmony_ci * 13bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included 14bf215546Sopenharmony_ci * in all copies or substantial portions of the Software. 15bf215546Sopenharmony_ci * 16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20bf215546Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21bf215546Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22bf215546Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 23bf215546Sopenharmony_ci */ 24bf215546Sopenharmony_ci 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci#include "glheader.h" 27bf215546Sopenharmony_ci#include "context.h" 28bf215546Sopenharmony_ci#include "fog.h" 29bf215546Sopenharmony_ci#include "macros.h" 30bf215546Sopenharmony_ci#include "mtypes.h" 31bf215546Sopenharmony_ci#include "api_exec_decl.h" 32bf215546Sopenharmony_ci 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_civoid GLAPIENTRY 35bf215546Sopenharmony_ci_mesa_Fogf(GLenum pname, GLfloat param) 36bf215546Sopenharmony_ci{ 37bf215546Sopenharmony_ci GLfloat fparam[4]; 38bf215546Sopenharmony_ci fparam[0] = param; 39bf215546Sopenharmony_ci fparam[1] = fparam[2] = fparam[3] = 0.0F; 40bf215546Sopenharmony_ci _mesa_Fogfv(pname, fparam); 41bf215546Sopenharmony_ci} 42bf215546Sopenharmony_ci 43bf215546Sopenharmony_ci 44bf215546Sopenharmony_civoid GLAPIENTRY 45bf215546Sopenharmony_ci_mesa_Fogi(GLenum pname, GLint param ) 46bf215546Sopenharmony_ci{ 47bf215546Sopenharmony_ci GLfloat fparam[4]; 48bf215546Sopenharmony_ci fparam[0] = (GLfloat) param; 49bf215546Sopenharmony_ci fparam[1] = fparam[2] = fparam[3] = 0.0F; 50bf215546Sopenharmony_ci _mesa_Fogfv(pname, fparam); 51bf215546Sopenharmony_ci} 52bf215546Sopenharmony_ci 53bf215546Sopenharmony_ci 54bf215546Sopenharmony_civoid GLAPIENTRY 55bf215546Sopenharmony_ci_mesa_Fogiv(GLenum pname, const GLint *params ) 56bf215546Sopenharmony_ci{ 57bf215546Sopenharmony_ci GLfloat p[4]; 58bf215546Sopenharmony_ci switch (pname) { 59bf215546Sopenharmony_ci case GL_FOG_MODE: 60bf215546Sopenharmony_ci case GL_FOG_DENSITY: 61bf215546Sopenharmony_ci case GL_FOG_START: 62bf215546Sopenharmony_ci case GL_FOG_END: 63bf215546Sopenharmony_ci case GL_FOG_INDEX: 64bf215546Sopenharmony_ci case GL_FOG_COORDINATE_SOURCE_EXT: 65bf215546Sopenharmony_ci case GL_FOG_DISTANCE_MODE_NV: 66bf215546Sopenharmony_ci p[0] = (GLfloat) *params; 67bf215546Sopenharmony_ci break; 68bf215546Sopenharmony_ci case GL_FOG_COLOR: 69bf215546Sopenharmony_ci p[0] = INT_TO_FLOAT( params[0] ); 70bf215546Sopenharmony_ci p[1] = INT_TO_FLOAT( params[1] ); 71bf215546Sopenharmony_ci p[2] = INT_TO_FLOAT( params[2] ); 72bf215546Sopenharmony_ci p[3] = INT_TO_FLOAT( params[3] ); 73bf215546Sopenharmony_ci break; 74bf215546Sopenharmony_ci default: 75bf215546Sopenharmony_ci /* Error will be caught later in _mesa_Fogfv */ 76bf215546Sopenharmony_ci ASSIGN_4V(p, 0.0F, 0.0F, 0.0F, 0.0F); 77bf215546Sopenharmony_ci } 78bf215546Sopenharmony_ci _mesa_Fogfv(pname, p); 79bf215546Sopenharmony_ci} 80bf215546Sopenharmony_ci 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_civoid GLAPIENTRY 83bf215546Sopenharmony_ci_mesa_Fogfv( GLenum pname, const GLfloat *params ) 84bf215546Sopenharmony_ci{ 85bf215546Sopenharmony_ci GET_CURRENT_CONTEXT(ctx); 86bf215546Sopenharmony_ci GLenum m; 87bf215546Sopenharmony_ci 88bf215546Sopenharmony_ci switch (pname) { 89bf215546Sopenharmony_ci case GL_FOG_MODE: 90bf215546Sopenharmony_ci m = (GLenum) (GLint) *params; 91bf215546Sopenharmony_ci switch (m) { 92bf215546Sopenharmony_ci case GL_LINEAR: 93bf215546Sopenharmony_ci ctx->Fog._PackedMode = FOG_LINEAR; 94bf215546Sopenharmony_ci break; 95bf215546Sopenharmony_ci case GL_EXP: 96bf215546Sopenharmony_ci ctx->Fog._PackedMode = FOG_EXP; 97bf215546Sopenharmony_ci break; 98bf215546Sopenharmony_ci case GL_EXP2: 99bf215546Sopenharmony_ci ctx->Fog._PackedMode = FOG_EXP2; 100bf215546Sopenharmony_ci break; 101bf215546Sopenharmony_ci default: 102bf215546Sopenharmony_ci _mesa_error( ctx, GL_INVALID_ENUM, "glFog" ); 103bf215546Sopenharmony_ci return; 104bf215546Sopenharmony_ci } 105bf215546Sopenharmony_ci if (ctx->Fog.Mode == m) 106bf215546Sopenharmony_ci return; 107bf215546Sopenharmony_ci FLUSH_VERTICES(ctx, _NEW_FOG, GL_FOG_BIT); 108bf215546Sopenharmony_ci ctx->Fog.Mode = m; 109bf215546Sopenharmony_ci if (ctx->Fog.Enabled) { 110bf215546Sopenharmony_ci ctx->Fog._PackedEnabledMode = ctx->Fog._PackedMode; 111bf215546Sopenharmony_ci ctx->NewState |= _NEW_FF_FRAG_PROGRAM; 112bf215546Sopenharmony_ci } 113bf215546Sopenharmony_ci break; 114bf215546Sopenharmony_ci case GL_FOG_DENSITY: 115bf215546Sopenharmony_ci if (*params<0.0F) { 116bf215546Sopenharmony_ci _mesa_error( ctx, GL_INVALID_VALUE, "glFog" ); 117bf215546Sopenharmony_ci return; 118bf215546Sopenharmony_ci } 119bf215546Sopenharmony_ci if (ctx->Fog.Density == *params) 120bf215546Sopenharmony_ci return; 121bf215546Sopenharmony_ci FLUSH_VERTICES(ctx, _NEW_FOG, GL_FOG_BIT); 122bf215546Sopenharmony_ci ctx->Fog.Density = *params; 123bf215546Sopenharmony_ci break; 124bf215546Sopenharmony_ci case GL_FOG_START: 125bf215546Sopenharmony_ci if (ctx->Fog.Start == *params) 126bf215546Sopenharmony_ci return; 127bf215546Sopenharmony_ci FLUSH_VERTICES(ctx, _NEW_FOG, GL_FOG_BIT); 128bf215546Sopenharmony_ci ctx->Fog.Start = *params; 129bf215546Sopenharmony_ci break; 130bf215546Sopenharmony_ci case GL_FOG_END: 131bf215546Sopenharmony_ci if (ctx->Fog.End == *params) 132bf215546Sopenharmony_ci return; 133bf215546Sopenharmony_ci FLUSH_VERTICES(ctx, _NEW_FOG, GL_FOG_BIT); 134bf215546Sopenharmony_ci ctx->Fog.End = *params; 135bf215546Sopenharmony_ci break; 136bf215546Sopenharmony_ci case GL_FOG_INDEX: 137bf215546Sopenharmony_ci if (ctx->API != API_OPENGL_COMPAT) 138bf215546Sopenharmony_ci goto invalid_pname; 139bf215546Sopenharmony_ci if (ctx->Fog.Index == *params) 140bf215546Sopenharmony_ci return; 141bf215546Sopenharmony_ci FLUSH_VERTICES(ctx, _NEW_FOG, GL_FOG_BIT); 142bf215546Sopenharmony_ci ctx->Fog.Index = *params; 143bf215546Sopenharmony_ci break; 144bf215546Sopenharmony_ci case GL_FOG_COLOR: 145bf215546Sopenharmony_ci if (TEST_EQ_4V(ctx->Fog.Color, params)) 146bf215546Sopenharmony_ci return; 147bf215546Sopenharmony_ci FLUSH_VERTICES(ctx, _NEW_FOG, GL_FOG_BIT); 148bf215546Sopenharmony_ci ctx->Fog.ColorUnclamped[0] = params[0]; 149bf215546Sopenharmony_ci ctx->Fog.ColorUnclamped[1] = params[1]; 150bf215546Sopenharmony_ci ctx->Fog.ColorUnclamped[2] = params[2]; 151bf215546Sopenharmony_ci ctx->Fog.ColorUnclamped[3] = params[3]; 152bf215546Sopenharmony_ci ctx->Fog.Color[0] = CLAMP(params[0], 0.0F, 1.0F); 153bf215546Sopenharmony_ci ctx->Fog.Color[1] = CLAMP(params[1], 0.0F, 1.0F); 154bf215546Sopenharmony_ci ctx->Fog.Color[2] = CLAMP(params[2], 0.0F, 1.0F); 155bf215546Sopenharmony_ci ctx->Fog.Color[3] = CLAMP(params[3], 0.0F, 1.0F); 156bf215546Sopenharmony_ci break; 157bf215546Sopenharmony_ci case GL_FOG_COORDINATE_SOURCE_EXT: { 158bf215546Sopenharmony_ci GLenum p = (GLenum) (GLint) *params; 159bf215546Sopenharmony_ci if (ctx->API != API_OPENGL_COMPAT || 160bf215546Sopenharmony_ci (p != GL_FOG_COORDINATE_EXT && p != GL_FRAGMENT_DEPTH_EXT)) { 161bf215546Sopenharmony_ci _mesa_error(ctx, GL_INVALID_ENUM, "glFog"); 162bf215546Sopenharmony_ci return; 163bf215546Sopenharmony_ci } 164bf215546Sopenharmony_ci if (ctx->Fog.FogCoordinateSource == p) 165bf215546Sopenharmony_ci return; 166bf215546Sopenharmony_ci FLUSH_VERTICES(ctx, _NEW_FOG | _NEW_FF_VERT_PROGRAM, GL_FOG_BIT); 167bf215546Sopenharmony_ci ctx->Fog.FogCoordinateSource = p; 168bf215546Sopenharmony_ci break; 169bf215546Sopenharmony_ci } 170bf215546Sopenharmony_ci case GL_FOG_DISTANCE_MODE_NV: { 171bf215546Sopenharmony_ci GLenum p = (GLenum) (GLint) *params; 172bf215546Sopenharmony_ci if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.NV_fog_distance || 173bf215546Sopenharmony_ci (p != GL_EYE_RADIAL_NV && p != GL_EYE_PLANE && p != GL_EYE_PLANE_ABSOLUTE_NV)) { 174bf215546Sopenharmony_ci _mesa_error(ctx, GL_INVALID_ENUM, "glFog"); 175bf215546Sopenharmony_ci return; 176bf215546Sopenharmony_ci } 177bf215546Sopenharmony_ci if (ctx->Fog.FogDistanceMode == p) 178bf215546Sopenharmony_ci return; 179bf215546Sopenharmony_ci FLUSH_VERTICES(ctx, _NEW_FOG | _NEW_FF_VERT_PROGRAM, GL_FOG_BIT); 180bf215546Sopenharmony_ci ctx->Fog.FogDistanceMode = p; 181bf215546Sopenharmony_ci break; 182bf215546Sopenharmony_ci } 183bf215546Sopenharmony_ci default: 184bf215546Sopenharmony_ci goto invalid_pname; 185bf215546Sopenharmony_ci } 186bf215546Sopenharmony_ci 187bf215546Sopenharmony_ci return; 188bf215546Sopenharmony_ci 189bf215546Sopenharmony_ciinvalid_pname: 190bf215546Sopenharmony_ci _mesa_error( ctx, GL_INVALID_ENUM, "glFog" ); 191bf215546Sopenharmony_ci return; 192bf215546Sopenharmony_ci} 193bf215546Sopenharmony_ci 194bf215546Sopenharmony_ci 195bf215546Sopenharmony_ci/**********************************************************************/ 196bf215546Sopenharmony_ci/***** Initialization *****/ 197bf215546Sopenharmony_ci/**********************************************************************/ 198bf215546Sopenharmony_ci 199bf215546Sopenharmony_civoid _mesa_init_fog( struct gl_context * ctx ) 200bf215546Sopenharmony_ci{ 201bf215546Sopenharmony_ci /* Fog group */ 202bf215546Sopenharmony_ci ctx->Fog.Enabled = GL_FALSE; 203bf215546Sopenharmony_ci ctx->Fog.Mode = GL_EXP; 204bf215546Sopenharmony_ci ctx->Fog._PackedMode = FOG_EXP; 205bf215546Sopenharmony_ci ctx->Fog._PackedEnabledMode = FOG_NONE; 206bf215546Sopenharmony_ci ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 ); 207bf215546Sopenharmony_ci ASSIGN_4V( ctx->Fog.ColorUnclamped, 0.0, 0.0, 0.0, 0.0 ); 208bf215546Sopenharmony_ci ctx->Fog.Index = 0.0; 209bf215546Sopenharmony_ci ctx->Fog.Density = 1.0; 210bf215546Sopenharmony_ci ctx->Fog.Start = 0.0; 211bf215546Sopenharmony_ci ctx->Fog.End = 1.0; 212bf215546Sopenharmony_ci ctx->Fog.ColorSumEnabled = GL_FALSE; 213bf215546Sopenharmony_ci ctx->Fog.FogCoordinateSource = GL_FRAGMENT_DEPTH_EXT; 214bf215546Sopenharmony_ci ctx->Fog.FogDistanceMode = GL_EYE_PLANE_ABSOLUTE_NV; 215bf215546Sopenharmony_ci} 216