diff options
Diffstat (limited to 'xc/extras/Mesa/src/light.c')
-rw-r--r-- | xc/extras/Mesa/src/light.c | 252 |
1 files changed, 203 insertions, 49 deletions
diff --git a/xc/extras/Mesa/src/light.c b/xc/extras/Mesa/src/light.c index 9e9503278..ed41e2311 100644 --- a/xc/extras/Mesa/src/light.c +++ b/xc/extras/Mesa/src/light.c @@ -1,10 +1,9 @@ -/* $Id: light.c,v 1.1.1.1 2000/01/06 13:26:56 faith Exp $ */ /* * Mesa 3-D graphics library - * Version: 3.1 + * Version: 3.3 * - * Copyright (C) 1999 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2000 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,27 +24,16 @@ */ - - - #ifdef PC_HEADER #include "all.h" #else -#include <float.h> -#ifndef XFree86Server -#include <assert.h> -#include <float.h> -#include <math.h> -#include <stdlib.h> -#include <stdio.h> -#else -#include "GL/xf86glx.h" -#endif +#include "glheader.h" #include "context.h" #include "enums.h" #include "light.h" #include "macros.h" #include "matrix.h" +#include "mem.h" #include "mmath.h" #include "simple_list.h" #include "types.h" @@ -54,9 +42,16 @@ #endif +/* XXX this is a bit of a hack needed for compilation within XFree86 */ +#ifndef FLT_MIN +#define FLT_MIN 1e-37 +#endif + -void gl_ShadeModel( GLcontext *ctx, GLenum mode ) +void +_mesa_ShadeModel( GLenum mode ) { + GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glShadeModel"); if (MESA_VERBOSE & VERBOSE_API) @@ -64,12 +59,12 @@ void gl_ShadeModel( GLcontext *ctx, GLenum mode ) if (mode == GL_FLAT || mode == GL_SMOOTH) { if (ctx->Light.ShadeModel != mode) { - ctx->Light.ShadeModel = mode; + ctx->Light.ShadeModel = mode; if (ctx->Light.ShadeModel == GL_FLAT) - ctx->TriangleCaps |= DD_FLATSHADE; + SET_BITS(ctx->TriangleCaps, DD_FLATSHADE); else - ctx->TriangleCaps &= ~DD_FLATSHADE; - ctx->NewState |= NEW_RASTER_OPS; + CLEAR_BITS(ctx->TriangleCaps, DD_FLATSHADE); + ctx->NewState |= NEW_RASTER_OPS; if (ctx->Driver.ShadeModel) (*ctx->Driver.ShadeModel)( ctx, mode ); } @@ -81,19 +76,25 @@ void gl_ShadeModel( GLcontext *ctx, GLenum mode ) -void gl_Lightfv( GLcontext *ctx, - GLenum light, GLenum pname, const GLfloat *params, - GLint nparams ) +void +_mesa_Lightf( GLenum light, GLenum pname, GLfloat param ) { - GLint l; + _mesa_Lightfv( light, pname, ¶m ); +} - (void) nparams; + +void +_mesa_Lightfv( GLenum light, GLenum pname, const GLfloat *params ) +{ + GET_CURRENT_CONTEXT(ctx); + GLint l; + GLint nParams; ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glLight"); l = (GLint) (light - GL_LIGHT0); - if (l<0 || l>=MAX_LIGHTS) { + if (l < 0 || l >= MAX_LIGHTS) { gl_error( ctx, GL_INVALID_ENUM, "glLight" ); return; } @@ -101,18 +102,22 @@ void gl_Lightfv( GLcontext *ctx, switch (pname) { case GL_AMBIENT: COPY_4V( ctx->Light.Light[l].Ambient, params ); + nParams = 4; break; case GL_DIFFUSE: COPY_4V( ctx->Light.Light[l].Diffuse, params ); + nParams = 4; break; case GL_SPECULAR: COPY_4V( ctx->Light.Light[l].Specular, params ); + nParams = 4; break; case GL_POSITION: /* transform position by ModelView matrix */ TRANSFORM_POINT( ctx->Light.Light[l].EyePosition, ctx->ModelView.m, params ); + nParams = 4; break; case GL_SPOT_DIRECTION: /* transform direction by inverse modelview */ @@ -122,6 +127,7 @@ void gl_Lightfv( GLcontext *ctx, TRANSFORM_NORMAL( ctx->Light.Light[l].EyeDirection, params, ctx->ModelView.inv ); + nParams = 3; break; case GL_SPOT_EXPONENT: if (params[0]<0.0 || params[0]>128.0) { @@ -132,6 +138,7 @@ void gl_Lightfv( GLcontext *ctx, ctx->Light.Light[l].SpotExponent = params[0]; gl_compute_spot_exp_table( &ctx->Light.Light[l] ); } + nParams = 1; break; case GL_SPOT_CUTOFF: if ((params[0]<0.0 || params[0]>90.0) && params[0]!=180.0) { @@ -142,6 +149,7 @@ void gl_Lightfv( GLcontext *ctx, ctx->Light.Light[l].CosCutoff = cos(params[0]*DEG2RAD); if (ctx->Light.Light[l].CosCutoff < 0) ctx->Light.Light[l].CosCutoff = 0; + nParams = 1; break; case GL_CONSTANT_ATTENUATION: if (params[0]<0.0) { @@ -149,6 +157,7 @@ void gl_Lightfv( GLcontext *ctx, return; } ctx->Light.Light[l].ConstantAttenuation = params[0]; + nParams = 1; break; case GL_LINEAR_ATTENUATION: if (params[0]<0.0) { @@ -156,6 +165,7 @@ void gl_Lightfv( GLcontext *ctx, return; } ctx->Light.Light[l].LinearAttenuation = params[0]; + nParams = 1; break; case GL_QUADRATIC_ATTENUATION: if (params[0]<0.0) { @@ -163,23 +173,73 @@ void gl_Lightfv( GLcontext *ctx, return; } ctx->Light.Light[l].QuadraticAttenuation = params[0]; + nParams = 1; break; default: gl_error( ctx, GL_INVALID_ENUM, "glLight" ); - break; + return; } if (ctx->Driver.Lightfv) - ctx->Driver.Lightfv( ctx, light, pname, params, nparams ); + ctx->Driver.Lightfv( ctx, light, pname, params, nParams ); ctx->NewState |= NEW_LIGHTING; } +void +_mesa_Lighti( GLenum light, GLenum pname, GLint param ) +{ + _mesa_Lightiv( light, pname, ¶m ); +} + -void gl_GetLightfv( GLcontext *ctx, - GLenum light, GLenum pname, GLfloat *params ) +void +_mesa_Lightiv( GLenum light, GLenum pname, const GLint *params ) { + GLfloat fparam[4]; + + switch (pname) { + case GL_AMBIENT: + case GL_DIFFUSE: + case GL_SPECULAR: + fparam[0] = INT_TO_FLOAT( params[0] ); + fparam[1] = INT_TO_FLOAT( params[1] ); + fparam[2] = INT_TO_FLOAT( params[2] ); + fparam[3] = INT_TO_FLOAT( params[3] ); + break; + case GL_POSITION: + fparam[0] = (GLfloat) params[0]; + fparam[1] = (GLfloat) params[1]; + fparam[2] = (GLfloat) params[2]; + fparam[3] = (GLfloat) params[3]; + break; + case GL_SPOT_DIRECTION: + fparam[0] = (GLfloat) params[0]; + fparam[1] = (GLfloat) params[1]; + fparam[2] = (GLfloat) params[2]; + break; + case GL_SPOT_EXPONENT: + case GL_SPOT_CUTOFF: + case GL_CONSTANT_ATTENUATION: + case GL_LINEAR_ATTENUATION: + case GL_QUADRATIC_ATTENUATION: + fparam[0] = (GLfloat) params[0]; + break; + default: + /* error will be caught later in gl_Lightfv */ + ; + } + + _mesa_Lightfv( light, pname, fparam ); +} + + + +void +_mesa_GetLightfv( GLenum light, GLenum pname, GLfloat *params ) +{ + GET_CURRENT_CONTEXT(ctx); GLint l = (GLint) (light - GL_LIGHT0); ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetLight"); @@ -228,8 +288,10 @@ void gl_GetLightfv( GLcontext *ctx, -void gl_GetLightiv( GLcontext *ctx, GLenum light, GLenum pname, GLint *params ) +void +_mesa_GetLightiv( GLenum light, GLenum pname, GLint *params ) { + GET_CURRENT_CONTEXT(ctx); GLint l = (GLint) (light - GL_LIGHT0); ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetLight"); @@ -297,9 +359,11 @@ void gl_GetLightiv( GLcontext *ctx, GLenum light, GLenum pname, GLint *params ) /**********************************************************************/ -void gl_LightModelfv( GLcontext *ctx, GLenum pname, const GLfloat *params ) +void +_mesa_LightModelfv( GLenum pname, const GLfloat *params ) { - ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glLightModel"); + GET_CURRENT_CONTEXT(ctx); + ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glLightModelfv"); switch (pname) { case GL_LIGHT_MODEL_AMBIENT: @@ -320,11 +384,11 @@ void gl_LightModelfv( GLcontext *ctx, GLenum pname, const GLfloat *params ) case GL_LIGHT_MODEL_COLOR_CONTROL: if (params[0] == (GLfloat) GL_SINGLE_COLOR) { ctx->Light.Model.ColorControl = GL_SINGLE_COLOR; - ctx->TriangleCaps &= ~DD_SEPERATE_SPECULAR; + CLEAR_BITS(ctx->TriangleCaps, DD_SEPERATE_SPECULAR); } else if (params[0] == (GLfloat) GL_SEPARATE_SPECULAR_COLOR) { ctx->Light.Model.ColorControl = GL_SEPARATE_SPECULAR_COLOR; - ctx->TriangleCaps |= DD_SEPERATE_SPECULAR; + SET_BITS(ctx->TriangleCaps, DD_SEPERATE_SPECULAR); } else { gl_error( ctx, GL_INVALID_ENUM, "glLightModel(param)" ); @@ -343,6 +407,46 @@ void gl_LightModelfv( GLcontext *ctx, GLenum pname, const GLfloat *params ) } +void +_mesa_LightModeliv( GLenum pname, const GLint *params ) +{ + GLfloat fparam[4]; + GET_CURRENT_CONTEXT(ctx); + ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glLightModeliv"); + + switch (pname) { + case GL_LIGHT_MODEL_AMBIENT: + fparam[0] = INT_TO_FLOAT( params[0] ); + fparam[1] = INT_TO_FLOAT( params[1] ); + fparam[2] = INT_TO_FLOAT( params[2] ); + fparam[3] = INT_TO_FLOAT( params[3] ); + break; + case GL_LIGHT_MODEL_LOCAL_VIEWER: + case GL_LIGHT_MODEL_TWO_SIDE: + case GL_LIGHT_MODEL_COLOR_CONTROL: + fparam[0] = (GLfloat) params[0]; + break; + default: + /* Error will be caught later in gl_LightModelfv */ + ; + } + _mesa_LightModelfv( pname, fparam ); +} + + +void +_mesa_LightModeli( GLenum pname, GLint param ) +{ + _mesa_LightModeliv( pname, ¶m ); +} + + +void +_mesa_LightModelf( GLenum pname, GLfloat param ) +{ + _mesa_LightModelfv( pname, ¶m ); +} + /********** MATERIAL **********/ @@ -568,11 +672,11 @@ void gl_update_color_material( GLcontext *ctx, GLfloat tmp[4], color[4]; UBYTE_RGBA_TO_FLOAT_RGBA( color, rgba ); - + if (MESA_VERBOSE&VERBOSE_IMMEDIATE) fprintf(stderr, "gl_update_color_material, mask %x\n", bitmask); - + if (bitmask & FRONT_AMBIENT_BIT) { struct gl_material *mat = &ctx->Light.Material[0]; SUB_3V( tmp, color, mat->Ambient ); @@ -675,8 +779,10 @@ void gl_update_color_material( GLcontext *ctx, -void gl_ColorMaterial( GLcontext *ctx, GLenum face, GLenum mode ) +void +_mesa_ColorMaterial( GLenum face, GLenum mode ) { + GET_CURRENT_CONTEXT(ctx); GLuint bitmask; GLuint legal = (FRONT_EMISSION_BIT | BACK_EMISSION_BIT | FRONT_SPECULAR_BIT | BACK_SPECULAR_BIT | @@ -704,12 +810,21 @@ void gl_ColorMaterial( GLcontext *ctx, GLenum face, GLenum mode ) + +void +_mesa_Materialf( GLenum face, GLenum pname, GLfloat param ) +{ + _mesa_Materialfv( face, pname, ¶m ); +} + + /* KW: This is now called directly (ie by name) from the glMaterial* * API functions. */ -void gl_Materialfv( GLcontext *ctx, - GLenum face, GLenum pname, const GLfloat *params ) +void +_mesa_Materialfv( GLenum face, GLenum pname, const GLfloat *params ) { + GET_CURRENT_CONTEXT(ctx); struct immediate *IM; struct gl_material *mat; GLuint bitmask; @@ -735,6 +850,7 @@ void gl_Materialfv( GLcontext *ctx, IM->MaterialMask[count] = 0; } + IM->MaterialMask[count] |= bitmask; mat = IM->Material[count]; @@ -783,11 +899,48 @@ void gl_Materialfv( GLcontext *ctx, } +void +_mesa_Materiali(GLenum face, GLenum pname, GLint param ) +{ + _mesa_Materialiv(face, pname, ¶m); +} + + +void +_mesa_Materialiv(GLenum face, GLenum pname, const GLint *params ) +{ + GLfloat fparam[4]; + switch (pname) { + case GL_AMBIENT: + case GL_DIFFUSE: + case GL_SPECULAR: + case GL_EMISSION: + case GL_AMBIENT_AND_DIFFUSE: + fparam[0] = INT_TO_FLOAT( params[0] ); + fparam[1] = INT_TO_FLOAT( params[1] ); + fparam[2] = INT_TO_FLOAT( params[2] ); + fparam[3] = INT_TO_FLOAT( params[3] ); + break; + case GL_SHININESS: + fparam[0] = (GLfloat) params[0]; + break; + case GL_COLOR_INDEXES: + fparam[0] = (GLfloat) params[0]; + fparam[1] = (GLfloat) params[1]; + fparam[2] = (GLfloat) params[2]; + break; + default: + /* Error will be caught later in gl_Materialfv */ + ; + } + _mesa_Materialfv(face, pname, fparam); +} -void gl_GetMaterialfv( GLcontext *ctx, - GLenum face, GLenum pname, GLfloat *params ) +void +_mesa_GetMaterialfv( GLenum face, GLenum pname, GLfloat *params ) { + GET_CURRENT_CONTEXT(ctx); GLuint f; ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetMaterialfv"); @@ -830,9 +983,10 @@ void gl_GetMaterialfv( GLcontext *ctx, -void gl_GetMaterialiv( GLcontext *ctx, - GLenum face, GLenum pname, GLint *params ) +void +_mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params ) { + GET_CURRENT_CONTEXT(ctx); GLuint f; ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetMaterialiv"); @@ -1010,8 +1164,8 @@ void gl_compute_shine_table( GLcontext *ctx, GLuint i, GLfloat shininess ) - -void gl_reinit_light_attrib( GLcontext *ctx, struct gl_light_attrib *l ) +#if 0 +static void gl_reinit_light_attrib( GLcontext *ctx, struct gl_light_attrib *l ) { GLuint i; @@ -1031,7 +1185,7 @@ void gl_reinit_light_attrib( GLcontext *ctx, struct gl_light_attrib *l ) insert_at_tail( &l->EnabledList, &l->Light[i] ); } } - +#endif /* @@ -1121,7 +1275,7 @@ void gl_update_lighting( GLcontext *ctx ) void gl_compute_light_positions( GLcontext *ctx ) { struct gl_light *light; - + if (ctx->Light.NeedVertices && !ctx->Light.Model.LocalViewer) { GLfloat eye_z[3] = { 0, 0, 1 }; if (!ctx->NeedEyeCoords) { |