Ignore:
Timestamp:
May 23, 2000, 10:41:28 PM (25 years ago)
Author:
jeroen
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/opengl/mesa/light.c

    r2962 r3598  
    1 /* $Id: light.c,v 1.2 2000-03-01 18:49:31 jeroen Exp $ */
     1/* $Id: light.c,v 1.3 2000-05-23 20:40:39 jeroen Exp $ */
    22
    33/*
    44 * Mesa 3-D graphics library
    5  * Version:  3.1
     5 * Version:  3.3
    66 *
    77 * Copyright (C) 1999  Brian Paul   All Rights Reserved.
     
    3232#include "all.h"
    3333#else
    34 #include <float.h>
    35 #ifndef XFree86Server
    36 #include <assert.h>
    37 #include <float.h>
    38 #include <math.h>
    39 #include <stdlib.h>
    40 #include <stdio.h>
    41 #else
    42 #include "GL/xf86glx.h"
    43 #endif
     34#include "glheader.h"
    4435#include "types.h"
    4536#include "context.h"
     
    5243#include "vb.h"
    5344#include "xform.h"
     45#include "mem.h"
    5446#endif
    5547
    56 
    57 
    58 void gl_ShadeModel( GLcontext *ctx, GLenum mode )
    59 {
     48/* XXX this is a bit of a hack needed for compilation within XFree86 */
     49#ifndef FLT_MIN
     50#define FLT_MIN 1e-37
     51#endif
     52
     53
     54void
     55_mesa_ShadeModel( GLenum mode )
     56{
     57   GET_CURRENT_CONTEXT(ctx);
    6058   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glShadeModel");
    6159
     
    6563   if (mode == GL_FLAT || mode == GL_SMOOTH) {
    6664      if (ctx->Light.ShadeModel != mode) {
    67         ctx->Light.ShadeModel = mode;
     65        ctx->Light.ShadeModel = mode;
    6866         if (ctx->Light.ShadeModel == GL_FLAT)
    69             ctx->TriangleCaps |= DD_FLATSHADE;
     67            SET_BITS(ctx->TriangleCaps, DD_FLATSHADE);
    7068         else
    71             ctx->TriangleCaps &= ~DD_FLATSHADE;
    72         ctx->NewState |= NEW_RASTER_OPS;
     69            CLEAR_BITS(ctx->TriangleCaps, DD_FLATSHADE);
     70        ctx->NewState |= NEW_RASTER_OPS;
    7371         if (ctx->Driver.ShadeModel)
    7472            (*ctx->Driver.ShadeModel)( ctx, mode );
     
    8280
    8381
    84 void gl_Lightfv( GLcontext *ctx,
    85                  GLenum light, GLenum pname, const GLfloat *params,
    86                  GLint nparams )
    87 {
     82void
     83_mesa_Lightf( GLenum light, GLenum pname, GLfloat param )
     84{
     85   _mesa_Lightfv( light, pname, &param );
     86}
     87
     88
     89void
     90_mesa_Lightfv( GLenum light, GLenum pname, const GLfloat *params )
     91{
     92   GET_CURRENT_CONTEXT(ctx);
    8893   GLint l;
    89 
    90    (void) nparams;
     94   GLint nParams;
    9195
    9296   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glLight");
     
    9498   l = (GLint) (light - GL_LIGHT0);
    9599
    96    if (l<0 || l>=MAX_LIGHTS) {
     100   if (l < 0 || l >= MAX_LIGHTS) {
    97101      gl_error( ctx, GL_INVALID_ENUM, "glLight" );
    98102      return;
     
    102106      case GL_AMBIENT:
    103107         COPY_4V( ctx->Light.Light[l].Ambient, params );
     108         nParams = 4;
    104109         break;
    105110      case GL_DIFFUSE:
    106111         COPY_4V( ctx->Light.Light[l].Diffuse, params );
     112         nParams = 4;
    107113         break;
    108114      case GL_SPECULAR:
    109115         COPY_4V( ctx->Light.Light[l].Specular, params );
     116         nParams = 4;
    110117         break;
    111118      case GL_POSITION:
    112         /* transform position by ModelView matrix */
    113         TRANSFORM_POINT( ctx->Light.Light[l].EyePosition,
    114                           ctx->ModelView.m,
     119        /* transform position by ModelView matrix */
     120        TRANSFORM_POINT( ctx->Light.Light[l].EyePosition,
     121                          ctx->ModelView.m,
    115122                          params );
     123         nParams = 4;
    116124         break;
    117125      case GL_SPOT_DIRECTION:
    118          /* transform direction by inverse modelview */
    119          if (ctx->ModelView.flags & MAT_DIRTY_INVERSE) {
    120             gl_matrix_analyze( &ctx->ModelView );
    121          }
    122          TRANSFORM_NORMAL( ctx->Light.Light[l].EyeDirection,
    123                            params,
    124                            ctx->ModelView.inv );
     126         /* transform direction by inverse modelview */
     127         if (ctx->ModelView.flags & MAT_DIRTY_INVERSE) {
     128            gl_matrix_analyze( &ctx->ModelView );
     129         }
     130         TRANSFORM_NORMAL( ctx->Light.Light[l].EyeDirection,
     131                           params,
     132                           ctx->ModelView.inv );
     133         nParams = 3;
    125134         break;
    126135      case GL_SPOT_EXPONENT:
     
    133142            gl_compute_spot_exp_table( &ctx->Light.Light[l] );
    134143         }
     144         nParams = 1;
    135145         break;
    136146      case GL_SPOT_CUTOFF:
     
    142152         ctx->Light.Light[l].CosCutoff = cos(params[0]*DEG2RAD);
    143153         if (ctx->Light.Light[l].CosCutoff < 0)
    144             ctx->Light.Light[l].CosCutoff = 0;
     154            ctx->Light.Light[l].CosCutoff = 0;
     155         nParams = 1;
    145156         break;
    146157      case GL_CONSTANT_ATTENUATION:
     
    150161         }
    151162         ctx->Light.Light[l].ConstantAttenuation = params[0];
     163         nParams = 1;
    152164         break;
    153165      case GL_LINEAR_ATTENUATION:
     
    157169         }
    158170         ctx->Light.Light[l].LinearAttenuation = params[0];
     171         nParams = 1;
    159172         break;
    160173      case GL_QUADRATIC_ATTENUATION:
     
    164177         }
    165178         ctx->Light.Light[l].QuadraticAttenuation = params[0];
     179         nParams = 1;
    166180         break;
    167181      default:
    168182         gl_error( ctx, GL_INVALID_ENUM, "glLight" );
    169          break;
     183         return;
    170184   }
    171185
    172186   if (ctx->Driver.Lightfv)
    173       ctx->Driver.Lightfv( ctx, light, pname, params, nparams );
     187      ctx->Driver.Lightfv( ctx, light, pname, params, nParams );
    174188
    175189   ctx->NewState |= NEW_LIGHTING;
    176190}
    177191
    178 
    179 
    180 void gl_GetLightfv( GLcontext *ctx,
    181                     GLenum light, GLenum pname, GLfloat *params )
    182 {
     192void
     193_mesa_Lighti( GLenum light, GLenum pname, GLint param )
     194{
     195   _mesa_Lightiv( light, pname, &param );
     196}
     197
     198
     199void
     200_mesa_Lightiv( GLenum light, GLenum pname, const GLint *params )
     201{
     202   GLfloat fparam[4];
     203
     204   switch (pname) {
     205      case GL_AMBIENT:
     206      case GL_DIFFUSE:
     207      case GL_SPECULAR:
     208         fparam[0] = INT_TO_FLOAT( params[0] );
     209         fparam[1] = INT_TO_FLOAT( params[1] );
     210         fparam[2] = INT_TO_FLOAT( params[2] );
     211         fparam[3] = INT_TO_FLOAT( params[3] );
     212         break;
     213      case GL_POSITION:
     214         fparam[0] = (GLfloat) params[0];
     215         fparam[1] = (GLfloat) params[1];
     216         fparam[2] = (GLfloat) params[2];
     217         fparam[3] = (GLfloat) params[3];
     218         break;
     219      case GL_SPOT_DIRECTION:
     220         fparam[0] = (GLfloat) params[0];
     221         fparam[1] = (GLfloat) params[1];
     222         fparam[2] = (GLfloat) params[2];
     223         break;
     224      case GL_SPOT_EXPONENT:
     225      case GL_SPOT_CUTOFF:
     226      case GL_CONSTANT_ATTENUATION:
     227      case GL_LINEAR_ATTENUATION:
     228      case GL_QUADRATIC_ATTENUATION:
     229         fparam[0] = (GLfloat) params[0];
     230         break;
     231      default:
     232         /* error will be caught later in gl_Lightfv */
     233         ;
     234   }
     235
     236   _mesa_Lightfv( light, pname, fparam );
     237}
     238
     239
     240
     241void
     242_mesa_GetLightfv( GLenum light, GLenum pname, GLfloat *params )
     243{
     244   GET_CURRENT_CONTEXT(ctx);
    183245   GLint l = (GLint) (light - GL_LIGHT0);
    184246
     
    229291
    230292
    231 void gl_GetLightiv( GLcontext *ctx, GLenum light, GLenum pname, GLint *params )
    232 {
     293void
     294_mesa_GetLightiv( GLenum light, GLenum pname, GLint *params )
     295{
     296   GET_CURRENT_CONTEXT(ctx);
    233297   GLint l = (GLint) (light - GL_LIGHT0);
    234298
     
    298362
    299363
    300 void gl_LightModelfv( GLcontext *ctx, GLenum pname, const GLfloat *params )
    301 {
    302    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glLightModel");
     364void
     365_mesa_LightModelfv( GLenum pname, const GLfloat *params )
     366{
     367   GET_CURRENT_CONTEXT(ctx);
     368   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glLightModelfv");
    303369
    304370   switch (pname) {
     
    321387         if (params[0] == (GLfloat) GL_SINGLE_COLOR) {
    322388            ctx->Light.Model.ColorControl = GL_SINGLE_COLOR;
    323             ctx->TriangleCaps &= ~DD_SEPERATE_SPECULAR;
     389            CLEAR_BITS(ctx->TriangleCaps, DD_SEPERATE_SPECULAR);
    324390         }
    325391         else if (params[0] == (GLfloat) GL_SEPARATE_SPECULAR_COLOR) {
    326392            ctx->Light.Model.ColorControl = GL_SEPARATE_SPECULAR_COLOR;
    327             ctx->TriangleCaps |= DD_SEPERATE_SPECULAR;
    328         }
     393            SET_BITS(ctx->TriangleCaps, DD_SEPERATE_SPECULAR);
     394        }
    329395         else {
    330396            gl_error( ctx, GL_INVALID_ENUM, "glLightModel(param)" );
    331397         }
    332         ctx->NewState |= NEW_RASTER_OPS;
     398        ctx->NewState |= NEW_RASTER_OPS;
    333399         break;
    334400      default:
     
    343409}
    344410
     411
     412void
     413_mesa_LightModeliv( GLenum pname, const GLint *params )
     414{
     415   GLfloat fparam[4];
     416   GET_CURRENT_CONTEXT(ctx);
     417   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glLightModeliv");
     418
     419   switch (pname) {
     420      case GL_LIGHT_MODEL_AMBIENT:
     421         fparam[0] = INT_TO_FLOAT( params[0] );
     422         fparam[1] = INT_TO_FLOAT( params[1] );
     423         fparam[2] = INT_TO_FLOAT( params[2] );
     424         fparam[3] = INT_TO_FLOAT( params[3] );
     425         break;
     426      case GL_LIGHT_MODEL_LOCAL_VIEWER:
     427      case GL_LIGHT_MODEL_TWO_SIDE:
     428      case GL_LIGHT_MODEL_COLOR_CONTROL:
     429         fparam[0] = (GLfloat) params[0];
     430         break;
     431      default:
     432         /* Error will be caught later in gl_LightModelfv */
     433         ;
     434   }
     435   _mesa_LightModelfv( pname, fparam );
     436}
     437
     438
     439void
     440_mesa_LightModeli( GLenum pname, GLint param )
     441{
     442   _mesa_LightModeliv( pname, &param );
     443}
     444
     445
     446void
     447_mesa_LightModelf( GLenum pname, GLfloat param )
     448{
     449   _mesa_LightModelfv( pname, &param );
     450}
    345451
    346452
     
    354460 */
    355461GLuint gl_material_bitmask( GLcontext *ctx, GLenum face, GLenum pname,
    356                             GLuint legal,
    357                             const char *where )
     462                            GLuint legal,
     463                            const char *where )
    358464{
    359465   GLuint bitmask = 0;
     
    426532 */
    427533void gl_update_material( GLcontext *ctx,
    428                         struct gl_material *src,
    429                         GLuint bitmask )
     534                        struct gl_material *src,
     535                        GLuint bitmask )
    430536{
    431537   struct gl_light *light, *list = &ctx->Light.EnabledList;
     
    446552      ACC_SCALE_3V( ctx->Light.BaseColor[0], ctx->Light.Model.Ambient, tmp);
    447553      foreach (light, list) {
    448         ACC_SCALE_3V( ctx->Light.BaseColor[0], light->Ambient, tmp );
     554        ACC_SCALE_3V( ctx->Light.BaseColor[0], light->Ambient, tmp );
    449555      }
    450556      COPY_4FV( mat->Ambient, src[0].Ambient );
     
    455561      ACC_SCALE_3V( ctx->Light.BaseColor[1], ctx->Light.Model.Ambient, tmp);
    456562      foreach (light, list) {
    457         ACC_SCALE_3V( ctx->Light.BaseColor[0], light->Ambient, tmp );
     563        ACC_SCALE_3V( ctx->Light.BaseColor[0], light->Ambient, tmp );
    458564      }
    459565      COPY_4FV( mat->Ambient, src[1].Ambient );
     
    463569      SUB_3V( tmp, src[0].Diffuse, mat->Diffuse );
    464570      foreach (light, list) {
    465         ACC_SCALE_3V( light->MatDiffuse[0], light->Diffuse, tmp );
     571        ACC_SCALE_3V( light->MatDiffuse[0], light->Diffuse, tmp );
    466572      }
    467573      COPY_4FV( mat->Diffuse, src[0].Diffuse );
     
    472578      SUB_3V( tmp, src[1].Diffuse, mat->Diffuse );
    473579      foreach (light, list) {
    474         ACC_SCALE_3V( light->MatDiffuse[1], light->Diffuse, tmp );
     580        ACC_SCALE_3V( light->MatDiffuse[1], light->Diffuse, tmp );
    475581      }
    476582      COPY_4FV( mat->Diffuse, src[1].Diffuse );
     
    481587      SUB_3V( tmp, src[0].Specular, mat->Specular );
    482588      foreach (light, list) {
    483         if (light->Flags & LIGHT_SPECULAR) {
    484             ACC_SCALE_3V( light->MatSpecular[0], light->Specular, tmp );
    485             light->IsMatSpecular[0] =
    486                (LEN_SQUARED_3FV(light->MatSpecular[0]) > 1e-16);
    487         }
     589        if (light->Flags & LIGHT_SPECULAR) {
     590            ACC_SCALE_3V( light->MatSpecular[0], light->Specular, tmp );
     591            light->IsMatSpecular[0] =
     592               (LEN_SQUARED_3FV(light->MatSpecular[0]) > 1e-16);
     593        }
    488594      }
    489595      COPY_4FV( mat->Specular, src[0].Specular );
     
    493599      SUB_3V( tmp, src[1].Specular, mat->Specular );
    494600      foreach (light, list) {
    495         if (light->Flags & LIGHT_SPECULAR) {
    496             ACC_SCALE_3V( light->MatSpecular[1], light->Specular, tmp );
    497             light->IsMatSpecular[1] =
    498                (LEN_SQUARED_3FV(light->MatSpecular[1]) > 1e-16);
    499         }
     601        if (light->Flags & LIGHT_SPECULAR) {
     602            ACC_SCALE_3V( light->MatSpecular[1], light->Specular, tmp );
     603            light->IsMatSpecular[1] =
     604               (LEN_SQUARED_3FV(light->MatSpecular[1]) > 1e-16);
     605        }
    500606      }
    501607      COPY_4FV( mat->Specular, src[1].Specular );
     
    538644      struct gl_material *mat = &ctx->Light.Material[0];
    539645      fprintf(stderr, "update_mat  emission : %f %f %f\n",
    540               mat->Emission[0],
    541               mat->Emission[1],
    542               mat->Emission[2]);
     646              mat->Emission[0],
     647              mat->Emission[1],
     648              mat->Emission[2]);
    543649      fprintf(stderr, "update_mat  specular : %f %f %f\n",
    544               mat->Specular[0],
    545               mat->Specular[1],
    546               mat->Specular[2]);
     650              mat->Specular[0],
     651              mat->Specular[1],
     652              mat->Specular[2]);
    547653      fprintf(stderr, "update_mat  diffuse : %f %f %f\n",
    548               mat->Diffuse[0],
    549               mat->Diffuse[1],
    550               mat->Diffuse[2]);
     654              mat->Diffuse[0],
     655              mat->Diffuse[1],
     656              mat->Diffuse[2]);
    551657      fprintf(stderr, "update_mat  ambient : %f %f %f\n",
    552               mat->Ambient[0],
    553               mat->Ambient[1],
    554               mat->Ambient[2]);
     658              mat->Ambient[0],
     659              mat->Ambient[1],
     660              mat->Ambient[2]);
    555661   }
    556662}
     
    562668
    563669void gl_update_color_material( GLcontext *ctx,
    564                                const GLubyte rgba[4] )
     670                               const GLubyte rgba[4] )
    565671{
    566672   struct gl_light *light, *list = &ctx->Light.EnabledList;
     
    579685      ACC_SCALE_3V( ctx->Light.BaseColor[0], ctx->Light.Model.Ambient, tmp);
    580686      foreach (light, list) {
    581         ACC_SCALE_3V( ctx->Light.BaseColor[0], light->Ambient, tmp );
     687        ACC_SCALE_3V( ctx->Light.BaseColor[0], light->Ambient, tmp );
    582688      }
    583689      COPY_4FV( mat->Ambient, color );
     
    589695      ACC_SCALE_3V( ctx->Light.BaseColor[1], ctx->Light.Model.Ambient, tmp);
    590696      foreach (light, list) {
    591         ACC_SCALE_3V( ctx->Light.BaseColor[0], light->Ambient, tmp );
     697        ACC_SCALE_3V( ctx->Light.BaseColor[0], light->Ambient, tmp );
    592698      }
    593699      COPY_4FV( mat->Ambient, color );
     
    598704      SUB_3V( tmp, color, mat->Diffuse );
    599705      foreach (light, list) {
    600         ACC_SCALE_3V( light->MatDiffuse[0], light->Diffuse, tmp );
     706        ACC_SCALE_3V( light->MatDiffuse[0], light->Diffuse, tmp );
    601707      }
    602708      COPY_4FV( mat->Diffuse, color );
     
    608714      SUB_3V( tmp, color, mat->Diffuse );
    609715      foreach (light, list) {
    610         ACC_SCALE_3V( light->MatDiffuse[1], light->Diffuse, tmp );
     716        ACC_SCALE_3V( light->MatDiffuse[1], light->Diffuse, tmp );
    611717      }
    612718      COPY_4FV( mat->Diffuse, color );
     
    618724      SUB_3V( tmp, color, mat->Specular );
    619725      foreach (light, list) {
    620         if (light->Flags & LIGHT_SPECULAR) {
    621             ACC_SCALE_3V( light->MatSpecular[0], light->Specular, tmp );
    622             light->IsMatSpecular[0] =
    623                (LEN_SQUARED_3FV(light->MatSpecular[0]) > 1e-16);
    624         }
     726        if (light->Flags & LIGHT_SPECULAR) {
     727            ACC_SCALE_3V( light->MatSpecular[0], light->Specular, tmp );
     728            light->IsMatSpecular[0] =
     729               (LEN_SQUARED_3FV(light->MatSpecular[0]) > 1e-16);
     730        }
    625731      }
    626732      COPY_4FV( mat->Specular, color );
     
    630736      SUB_3V( tmp, color, mat->Specular );
    631737      foreach (light, list) {
    632         if (light->Flags & LIGHT_SPECULAR) {
    633             ACC_SCALE_3V( light->MatSpecular[1], light->Specular, tmp );
    634             light->IsMatSpecular[1] =
    635                (LEN_SQUARED_3FV(light->MatSpecular[1]) > 1e-16);
    636         }
     738        if (light->Flags & LIGHT_SPECULAR) {
     739            ACC_SCALE_3V( light->MatSpecular[1], light->Specular, tmp );
     740            light->IsMatSpecular[1] =
     741               (LEN_SQUARED_3FV(light->MatSpecular[1]) > 1e-16);
     742        }
    637743      }
    638744      COPY_4FV( mat->Specular, color );
     
    655761      struct gl_material *mat = &ctx->Light.Material[0];
    656762      fprintf(stderr, "update_color_mat  emission : %f %f %f\n",
    657               mat->Emission[0],
    658               mat->Emission[1],
    659               mat->Emission[2]);
     763              mat->Emission[0],
     764              mat->Emission[1],
     765              mat->Emission[2]);
    660766      fprintf(stderr, "update_color_mat  specular : %f %f %f\n",
    661               mat->Specular[0],
    662               mat->Specular[1],
    663               mat->Specular[2]);
     767              mat->Specular[0],
     768              mat->Specular[1],
     769              mat->Specular[2]);
    664770      fprintf(stderr, "update_color_mat  diffuse : %f %f %f\n",
    665               mat->Diffuse[0],
    666               mat->Diffuse[1],
    667               mat->Diffuse[2]);
     771              mat->Diffuse[0],
     772              mat->Diffuse[1],
     773              mat->Diffuse[2]);
    668774      fprintf(stderr, "update_color_mat  ambient : %f %f %f\n",
    669               mat->Ambient[0],
    670               mat->Ambient[1],
    671               mat->Ambient[2]);
    672    }
    673 }
    674 
    675 
    676 
    677 
    678 void gl_ColorMaterial( GLcontext *ctx, GLenum face, GLenum mode )
    679 {
     775              mat->Ambient[0],
     776              mat->Ambient[1],
     777              mat->Ambient[2]);
     778   }
     779}
     780
     781
     782
     783
     784void
     785_mesa_ColorMaterial( GLenum face, GLenum mode )
     786{
     787   GET_CURRENT_CONTEXT(ctx);
    680788   GLuint bitmask;
    681789   GLuint legal = (FRONT_EMISSION_BIT | BACK_EMISSION_BIT |
    682                    FRONT_SPECULAR_BIT | BACK_SPECULAR_BIT |
    683                    FRONT_DIFFUSE_BIT  | BACK_DIFFUSE_BIT  |
    684                    FRONT_AMBIENT_BIT  | BACK_AMBIENT_BIT);
     790                   FRONT_SPECULAR_BIT | BACK_SPECULAR_BIT |
     791                   FRONT_DIFFUSE_BIT  | BACK_DIFFUSE_BIT  |
     792                   FRONT_AMBIENT_BIT  | BACK_AMBIENT_BIT);
    685793
    686794   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glColorMaterial");
     
    688796   if (MESA_VERBOSE&VERBOSE_API)
    689797      fprintf(stderr, "glColorMaterial %s %s\n",
    690               gl_lookup_enum_by_nr(face),
    691               gl_lookup_enum_by_nr(mode));
     798              gl_lookup_enum_by_nr(face),
     799              gl_lookup_enum_by_nr(mode));
    692800
    693801   bitmask = gl_material_bitmask( ctx, face, mode, legal, "glColorMaterial" );
     
    705813
    706814
     815
     816void
     817_mesa_Materialf( GLenum face, GLenum pname, GLfloat param )
     818{
     819   _mesa_Materialfv( face, pname, &param );
     820}
     821
     822
    707823/* KW:  This is now called directly (ie by name) from the glMaterial*
    708824 *      API functions.
    709825 */
    710 void gl_Materialfv( GLcontext *ctx,
    711                     GLenum face, GLenum pname, const GLfloat *params )
    712 {
     826void
     827_mesa_Materialfv( GLenum face, GLenum pname, const GLfloat *params )
     828{
     829   GET_CURRENT_CONTEXT(ctx);
    713830   struct immediate *IM;
    714831   struct gl_material *mat;
     
    725842   if (!IM->Material) {
    726843      IM->Material =
    727         (struct gl_material (*)[2]) MALLOC( sizeof(struct gl_material) *
    728                                              VB_SIZE * 2 );
     844        (struct gl_material (*)[2]) MALLOC( sizeof(struct gl_material) *
     845                                             VB_SIZE * 2 );
    729846      IM->MaterialMask = (GLuint *) MALLOC( sizeof(GLuint) * VB_SIZE );
    730847   }
     
    735852      IM->MaterialMask[count] = 0;
    736853   }
     854
    737855
    738856   IM->MaterialMask[count] |= bitmask;
     
    784902
    785903
    786 
    787 
    788 void gl_GetMaterialfv( GLcontext *ctx,
    789                        GLenum face, GLenum pname, GLfloat *params )
    790 {
     904void
     905_mesa_Materiali(GLenum face, GLenum pname, GLint param )
     906{
     907   _mesa_Materialiv(face, pname, &param);
     908}
     909
     910
     911void
     912_mesa_Materialiv(GLenum face, GLenum pname, const GLint *params )
     913{
     914   GLfloat fparam[4];
     915   switch (pname) {
     916      case GL_AMBIENT:
     917      case GL_DIFFUSE:
     918      case GL_SPECULAR:
     919      case GL_EMISSION:
     920      case GL_AMBIENT_AND_DIFFUSE:
     921         fparam[0] = INT_TO_FLOAT( params[0] );
     922         fparam[1] = INT_TO_FLOAT( params[1] );
     923         fparam[2] = INT_TO_FLOAT( params[2] );
     924         fparam[3] = INT_TO_FLOAT( params[3] );
     925         break;
     926      case GL_SHININESS:
     927         fparam[0] = (GLfloat) params[0];
     928         break;
     929      case GL_COLOR_INDEXES:
     930         fparam[0] = (GLfloat) params[0];
     931         fparam[1] = (GLfloat) params[1];
     932         fparam[2] = (GLfloat) params[2];
     933         break;
     934      default:
     935         /* Error will be caught later in gl_Materialfv */
     936         ;
     937   }
     938   _mesa_Materialfv(face, pname, fparam);
     939}
     940
     941
     942void
     943_mesa_GetMaterialfv( GLenum face, GLenum pname, GLfloat *params )
     944{
     945   GET_CURRENT_CONTEXT(ctx);
    791946   GLuint f;
    792947
     
    809964      case GL_DIFFUSE:
    810965         COPY_4FV( params, ctx->Light.Material[f].Diffuse );
    811         break;
     966        break;
    812967      case GL_SPECULAR:
    813968         COPY_4FV( params, ctx->Light.Material[f].Specular );
    814         break;
     969        break;
    815970      case GL_EMISSION:
    816         COPY_4FV( params, ctx->Light.Material[f].Emission );
    817         break;
     971        COPY_4FV( params, ctx->Light.Material[f].Emission );
     972        break;
    818973      case GL_SHININESS:
    819         *params = ctx->Light.Material[f].Shininess;
    820         break;
     974        *params = ctx->Light.Material[f].Shininess;
     975        break;
    821976      case GL_COLOR_INDEXES:
    822         params[0] = ctx->Light.Material[f].AmbientIndex;
    823         params[1] = ctx->Light.Material[f].DiffuseIndex;
    824         params[2] = ctx->Light.Material[f].SpecularIndex;
    825         break;
     977        params[0] = ctx->Light.Material[f].AmbientIndex;
     978        params[1] = ctx->Light.Material[f].DiffuseIndex;
     979        params[2] = ctx->Light.Material[f].SpecularIndex;
     980        break;
    826981      default:
    827982         gl_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(pname)" );
     
    831986
    832987
    833 void gl_GetMaterialiv( GLcontext *ctx,
    834                        GLenum face, GLenum pname, GLint *params )
    835 {
     988void
     989_mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params )
     990{
     991   GET_CURRENT_CONTEXT(ctx);
    836992   GLuint f;
    837993
     
    8601016         params[2] = FLOAT_TO_INT( ctx->Light.Material[f].Diffuse[2] );
    8611017         params[3] = FLOAT_TO_INT( ctx->Light.Material[f].Diffuse[3] );
    862         break;
     1018        break;
    8631019      case GL_SPECULAR:
    8641020         params[0] = FLOAT_TO_INT( ctx->Light.Material[f].Specular[0] );
     
    8661022         params[2] = FLOAT_TO_INT( ctx->Light.Material[f].Specular[2] );
    8671023         params[3] = FLOAT_TO_INT( ctx->Light.Material[f].Specular[3] );
    868         break;
     1024        break;
    8691025      case GL_EMISSION:
    8701026         params[0] = FLOAT_TO_INT( ctx->Light.Material[f].Emission[0] );
     
    8721028         params[2] = FLOAT_TO_INT( ctx->Light.Material[f].Emission[2] );
    8731029         params[3] = FLOAT_TO_INT( ctx->Light.Material[f].Emission[3] );
    874         break;
     1030        break;
    8751031      case GL_SHININESS:
    8761032         *params = ROUNDF( ctx->Light.Material[f].Shininess );
    877         break;
     1033        break;
    8781034      case GL_COLOR_INDEXES:
    879         params[0] = ROUNDF( ctx->Light.Material[f].AmbientIndex );
    880         params[1] = ROUNDF( ctx->Light.Material[f].DiffuseIndex );
    881         params[2] = ROUNDF( ctx->Light.Material[f].SpecularIndex );
    882         break;
     1035        params[0] = ROUNDF( ctx->Light.Material[f].AmbientIndex );
     1036        params[1] = ROUNDF( ctx->Light.Material[f].DiffuseIndex );
     1037        params[2] = ROUNDF( ctx->Light.Material[f].SpecularIndex );
     1038        break;
    8831039      default:
    8841040         gl_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(pname)" );
     
    9721128   if (shininess == 0) {
    9731129      for (i = 1 ; i <= SHINE_TABLE_SIZE ; i++)
    974         m[i] = 1;
     1130        m[i] = 1;
    9751131   } else {
    9761132      for (i = 1 ; i <= SHINE_TABLE_SIZE ; i++) {
    977         double t = pow( i/(GLfloat)SHINE_TABLE_SIZE, shininess );
    978         m[i] = 0;
    979         if (t > 1e-20) m[i] = t;
     1133        double t = pow( i/(GLfloat)SHINE_TABLE_SIZE, shininess );
     1134        m[i] = 0;
     1135        if (t > 1e-20) m[i] = t;
    9801136      }
    9811137   }
     
    9931149   foreach(s, list)
    9941150      if ( DISTSQR(s->shininess, shininess) < 1e-4 )
    995         break;
     1151        break;
    9961152
    9971153   if (s == list)
    9981154   {
    9991155      foreach(s, list)
    1000         if (s->refcount == 0) break;
     1156        if (s->refcount == 0) break;
    10011157
    10021158      compute_shine_table( s, shininess );
     
    10111167
    10121168
    1013 
    1014 void gl_reinit_light_attrib( GLcontext *ctx, struct gl_light_attrib *l )
     1169#if 0
     1170static void gl_reinit_light_attrib( GLcontext *ctx, struct gl_light_attrib *l )
    10151171{
    10161172   GLuint i;
     
    10291185   for (i = 0 ; i < MAX_LIGHTS ; i++) {
    10301186      if (l->Light[i].Enabled)
    1031         insert_at_tail( &l->EnabledList, &l->Light[i] );
    1032    }
    1033 }
    1034 
     1187        insert_at_tail( &l->EnabledList, &l->Light[i] );
     1188   }
     1189}
     1190#endif
    10351191
    10361192
     
    10521208
    10531209      if (light->EyePosition[3] != 0.0F)
    1054         light->Flags |= LIGHT_POSITIONAL;
     1210        light->Flags |= LIGHT_POSITIONAL;
    10551211
    10561212      if (LEN_SQUARED_3FV(light->Specular) > 1e-16)
    1057         light->Flags |= LIGHT_SPECULAR;
     1213        light->Flags |= LIGHT_SPECULAR;
    10581214
    10591215      if (light->SpotCutoff != 180.0F)
    1060         light->Flags |= LIGHT_SPOT;
     1216        light->Flags |= LIGHT_SPOT;
    10611217
    10621218      ctx->Light.Flags |= light->Flags;
     
    10761232      GLuint side;
    10771233      for (side=0; side < sides; side++) {
    1078         struct gl_material *mat = &ctx->Light.Material[side];
    1079        
    1080         COPY_3V(ctx->Light.BaseColor[side], mat->Emission);
    1081         ACC_SCALE_3V(ctx->Light.BaseColor[side],
    1082                       ctx->Light.Model.Ambient,
    1083                       mat->Ambient);
    1084 
    1085         FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Light.BaseAlpha[side],
    1086                                     ctx->Light.Material[side].Diffuse[3] );
    1087       }
    1088 
    1089       foreach (light, &ctx->Light.EnabledList) {       
    1090         for (side=0; side< sides; side++) {
    1091             struct gl_material *mat = &ctx->Light.Material[side];
    1092             SCALE_3V( light->MatDiffuse[side],  light->Diffuse, mat->Diffuse );
    1093             SCALE_3V( light->MatAmbient[side],  light->Ambient, mat->Ambient );
    1094             ACC_3V( ctx->Light.BaseColor[side], light->MatAmbient[side] );
    1095             if (light->Flags & LIGHT_SPECULAR)
    1096             {
    1097                SCALE_3V( light->MatSpecular[side], light->Specular,
    1098                         mat->Specular);
    1099                light->IsMatSpecular[side] =
    1100                   (LEN_SQUARED_3FV(light->MatSpecular[side]) > 1e-16);
    1101             }
    1102             else
    1103                light->IsMatSpecular[side] = 0;
    1104         }
     1234        struct gl_material *mat = &ctx->Light.Material[side];
     1235
     1236        COPY_3V(ctx->Light.BaseColor[side], mat->Emission);
     1237        ACC_SCALE_3V(ctx->Light.BaseColor[side],
     1238                      ctx->Light.Model.Ambient,
     1239                      mat->Ambient);
     1240
     1241        FLOAT_COLOR_TO_UBYTE_COLOR(ctx->Light.BaseAlpha[side],
     1242                                    ctx->Light.Material[side].Diffuse[3] );
     1243      }
     1244
     1245      foreach (light, &ctx->Light.EnabledList) {
     1246        for (side=0; side< sides; side++) {
     1247            struct gl_material *mat = &ctx->Light.Material[side];
     1248            SCALE_3V( light->MatDiffuse[side],  light->Diffuse, mat->Diffuse );
     1249            SCALE_3V( light->MatAmbient[side],  light->Ambient, mat->Ambient );
     1250            ACC_3V( ctx->Light.BaseColor[side], light->MatAmbient[side] );
     1251            if (light->Flags & LIGHT_SPECULAR)
     1252            {
     1253               SCALE_3V( light->MatSpecular[side], light->Specular,
     1254                        mat->Specular);
     1255               light->IsMatSpecular[side] =
     1256                  (LEN_SQUARED_3FV(light->MatSpecular[side]) > 1e-16);
     1257            }
     1258            else
     1259               light->IsMatSpecular[side] = 0;
     1260        }
    11051261      }
    11061262   }
     
    11101266
    11111267      foreach(light, &ctx->Light.EnabledList) {
    1112         light->dli = DOT3(ci, light->Diffuse);
    1113         light->sli = DOT3(ci, light->Specular);
     1268        light->dli = DOT3(ci, light->Diffuse);
     1269        light->sli = DOT3(ci, light->Specular);
    11141270      }
    11151271   }
     
    11261282      GLfloat eye_z[3] = { 0, 0, 1 };
    11271283      if (!ctx->NeedEyeCoords) {
    1128         TRANSFORM_NORMAL( ctx->EyeZDir, eye_z, ctx->ModelView.m );
     1284        TRANSFORM_NORMAL( ctx->EyeZDir, eye_z, ctx->ModelView.m );
    11291285      } else {
    1130         COPY_3V( ctx->EyeZDir, eye_z );
     1286        COPY_3V( ctx->EyeZDir, eye_z );
    11311287      }
    11321288   }
     
    11351291
    11361292      if (!ctx->NeedEyeCoords) {
    1137         TRANSFORM_POINT( light->Position, ctx->ModelView.inv,
    1138                           light->EyePosition );
     1293        TRANSFORM_POINT( light->Position, ctx->ModelView.inv,
     1294                          light->EyePosition );
    11391295      } else {
    1140         COPY_4FV( light->Position, light->EyePosition );
     1296        COPY_4FV( light->Position, light->EyePosition );
    11411297      }
    11421298
    11431299      if (!(light->Flags & LIGHT_POSITIONAL))
    11441300      {
    1145         /* VP (VP) = Normalize( Position ) */
    1146         COPY_3V( light->VP_inf_norm, light->Position );
    1147         NORMALIZE_3FV( light->VP_inf_norm );
    1148 
    1149         if (!ctx->Light.Model.LocalViewer)
    1150         {
    1151             /* h_inf_norm = Normalize( V_to_P + <0,0,1> ) */
    1152             ADD_3V( light->h_inf_norm, light->VP_inf_norm, ctx->EyeZDir);
    1153             NORMALIZE_3FV( light->h_inf_norm );
    1154         }
    1155 
    1156         light->VP_inf_spot_attenuation = 1.0;
     1301        /* VP (VP) = Normalize( Position ) */
     1302        COPY_3V( light->VP_inf_norm, light->Position );
     1303        NORMALIZE_3FV( light->VP_inf_norm );
     1304
     1305        if (!ctx->Light.Model.LocalViewer)
     1306        {
     1307            /* h_inf_norm = Normalize( V_to_P + <0,0,1> ) */
     1308            ADD_3V( light->h_inf_norm, light->VP_inf_norm, ctx->EyeZDir);
     1309            NORMALIZE_3FV( light->h_inf_norm );
     1310        }
     1311
     1312        light->VP_inf_spot_attenuation = 1.0;
    11571313      }
    11581314
    11591315      if (light->Flags & LIGHT_SPOT)
    11601316      {
    1161         if (ctx->NeedEyeNormals) {
    1162             COPY_3V( light->NormDirection, light->EyeDirection );
    1163         } else {
    1164             TRANSFORM_NORMAL( light->NormDirection,
    1165                               light->EyeDirection,
    1166                               ctx->ModelView.m);
    1167         }
    1168 
    1169         NORMALIZE_3FV( light->NormDirection );
    1170 
    1171 
    1172         /* Unlikely occurrance?
    1173           */
    1174         if (!(light->Flags & LIGHT_POSITIONAL)) {
    1175             GLfloat PV_dot_dir = - DOT3(light->VP_inf_norm,
    1176                                         light->NormDirection);
    1177 
    1178             if (PV_dot_dir > light->CosCutoff) {
    1179                double x = PV_dot_dir * (EXP_TABLE_SIZE-1);
    1180                int k = (int) x;
    1181                light->VP_inf_spot_attenuation =
    1182                   (light->SpotExpTable[k][0] +
    1183                    (x-k)*light->SpotExpTable[k][1]);
    1184             }
    1185             else
    1186                light->VP_inf_spot_attenuation = 0;
    1187         }
     1317        if (ctx->NeedEyeNormals) {
     1318            COPY_3V( light->NormDirection, light->EyeDirection );
     1319        } else {
     1320            TRANSFORM_NORMAL( light->NormDirection,
     1321                              light->EyeDirection,
     1322                              ctx->ModelView.m);
     1323        }
     1324
     1325        NORMALIZE_3FV( light->NormDirection );
     1326
     1327
     1328        /* Unlikely occurrance?
     1329          */
     1330        if (!(light->Flags & LIGHT_POSITIONAL)) {
     1331            GLfloat PV_dot_dir = - DOT3(light->VP_inf_norm,
     1332                                        light->NormDirection);
     1333
     1334            if (PV_dot_dir > light->CosCutoff) {
     1335               double x = PV_dot_dir * (EXP_TABLE_SIZE-1);
     1336               int k = (int) x;
     1337               light->VP_inf_spot_attenuation =
     1338                  (light->SpotExpTable[k][0] +
     1339                   (x-k)*light->SpotExpTable[k][1]);
     1340            }
     1341            else
     1342               light->VP_inf_spot_attenuation = 0;
     1343        }
    11881344      }
    11891345   }
     
    12031359   if (ctx->NeedEyeCoords) {
    12041360      if (ctx->NeedNormals) {
    1205         GLuint transform = NORM_TRANSFORM_NO_ROT;
    1206 
    1207         if (ctx->ModelView.flags & (MAT_FLAG_GENERAL |
    1208                                      MAT_FLAG_ROTATION |
    1209                                      MAT_FLAG_GENERAL_3D |
    1210                                      MAT_FLAG_PERSPECTIVE))
    1211             transform = NORM_TRANSFORM;
    1212 
    1213        
    1214         new_flag = ctx->NewState & NEW_MODELVIEW;
    1215         ctx->vb_rescale_factor = ctx->rescale_factor;
    1216        
    1217         if (ctx->Transform.Normalize)
    1218         {
    1219             ctx->NormalTransform = gl_normal_tab[transform | NORM_NORMALIZE];
    1220         }
    1221         else if (ctx->Transform.RescaleNormals &&
    1222                   ctx->rescale_factor != 1.0)
    1223         {
    1224             ctx->NormalTransform = gl_normal_tab[transform | NORM_RESCALE];
    1225         }
    1226         else
    1227         {
    1228             ctx->NormalTransform = gl_normal_tab[transform];
    1229         }
     1361        GLuint transform = NORM_TRANSFORM_NO_ROT;
     1362
     1363        if (ctx->ModelView.flags & (MAT_FLAG_GENERAL |
     1364                                     MAT_FLAG_ROTATION |
     1365                                     MAT_FLAG_GENERAL_3D |
     1366                                     MAT_FLAG_PERSPECTIVE))
     1367            transform = NORM_TRANSFORM;
     1368
     1369
     1370        new_flag = ctx->NewState & NEW_MODELVIEW;
     1371        ctx->vb_rescale_factor = ctx->rescale_factor;
     1372
     1373        if (ctx->Transform.Normalize)
     1374        {
     1375            ctx->NormalTransform = gl_normal_tab[transform | NORM_NORMALIZE];
     1376        }
     1377        else if (ctx->Transform.RescaleNormals &&
     1378                  ctx->rescale_factor != 1.0)
     1379        {
     1380            ctx->NormalTransform = gl_normal_tab[transform | NORM_RESCALE];
     1381        }
     1382        else
     1383        {
     1384            ctx->NormalTransform = gl_normal_tab[transform];
     1385        }
    12301386      } else {
    1231         ctx->NormalTransform = 0;
     1387        ctx->NormalTransform = 0;
    12321388      }
    12331389   }
    12341390   else {
    12351391      if (ctx->NeedNormals) {
    1236         ctx->vb_rescale_factor = 1.0/ctx->rescale_factor;
    1237 
    1238         if (ctx->Transform.Normalize)
    1239         {
    1240             ctx->NormalTransform = gl_normal_tab[NORM_NORMALIZE];
    1241         }
    1242         else if (!ctx->Transform.RescaleNormals &&
    1243                   ctx->rescale_factor != 1.0)
    1244         {
    1245             ctx->NormalTransform = gl_normal_tab[NORM_RESCALE];
    1246         }
    1247         else
    1248         {
    1249             ctx->NormalTransform = 0;
    1250         }
     1392        ctx->vb_rescale_factor = 1.0/ctx->rescale_factor;
     1393
     1394        if (ctx->Transform.Normalize)
     1395        {
     1396            ctx->NormalTransform = gl_normal_tab[NORM_NORMALIZE];
     1397        }
     1398        else if (!ctx->Transform.RescaleNormals &&
     1399                  ctx->rescale_factor != 1.0)
     1400        {
     1401            ctx->NormalTransform = gl_normal_tab[NORM_RESCALE];
     1402        }
     1403        else
     1404        {
     1405            ctx->NormalTransform = 0;
     1406        }
    12511407      } else {
    1252         ctx->NormalTransform = 0;
     1408        ctx->NormalTransform = 0;
    12531409      }
    12541410   }
Note: See TracChangeset for help on using the changeset viewer.