-/* $Id: t_vb_lighttmp.h,v 1.2 2001/01/03 15:59:30 brianp Exp $ */
-
/*
* Mesa 3-D graphics library
- * Version: 3.5
- *
- * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
- *
+ * Version: 5.1
+ *
+ * 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"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
- *
+ *
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
*
*
* Authors:
- * Brian Paul <brianp@valinux.com>
- * Keith Whitwell <keithw@valinux.com>
+ * Brian Paul
+ * Keith Whitwell <keith@tungstengraphics.com>
*/
-#if (IDX & LIGHT_FLAGS)
-# define VSTRIDE (4 * sizeof(GLfloat))
-# define NSTRIDE (3 * sizeof(GLfloat))
-# define CHECK_MATERIAL(x) (flags[x] & VERT_MATERIAL)
-# define CHECK_END_VB(x) (flags[x] & VERT_END_VB)
-# if (IDX & LIGHT_COLORMATERIAL)
-# define CMSTRIDE STRIDE_4UB(CMcolor, (4 * sizeof(GLubyte)))
-# define CHECK_COLOR_MATERIAL(x) (flags[x] & VERT_RGBA)
-# define CHECK_VALIDATE(x) (flags[x] & (VERT_RGBA|VERT_MATERIAL))
-# define DO_ANOTHER_NORMAL(x) \
- ((flags[x] & (VERT_RGBA|VERT_NORM|VERT_END_VB|VERT_MATERIAL)) == VERT_NORM)
-# define REUSE_LIGHT_RESULTS(x) \
- ((flags[x] & (VERT_RGBA|VERT_NORM|VERT_END_VB|VERT_MATERIAL)) == 0)
-# else
-# define CMSTRIDE 0
-# define CHECK_COLOR_MATERIAL(x) 0
-# define CHECK_VALIDATE(x) (flags[x] & (VERT_MATERIAL))
-# define DO_ANOTHER_NORMAL(x) \
- ((flags[x] & (VERT_NORM|VERT_END_VB|VERT_MATERIAL)) == VERT_NORM)
-# define REUSE_LIGHT_RESULTS(x) \
- ((flags[x] & (VERT_NORM|VERT_END_VB|VERT_MATERIAL)) == 0)
-# endif
-#else
-# define VSTRIDE vstride
-# define NSTRIDE nstride
-# define CHECK_MATERIAL(x) 0 /* no materials on array paths */
-# define CHECK_END_VB(XX) (XX >= nr)
-# if (IDX & LIGHT_COLORMATERIAL)
-# define CMSTRIDE STRIDE_4UB(CMcolor, CMstride)
-# define CHECK_COLOR_MATERIAL(x) (x < nr) /* always have colormaterial */
-# define CHECK_VALIDATE(x) (x < nr)
-# define DO_ANOTHER_NORMAL(x) 0 /* always stop to recalc colormat */
-# else
-# define CMSTRIDE 0
-# define CHECK_COLOR_MATERIAL(x) 0 /* no colormaterial */
-# define CHECK_VALIDATE(x) (0)
-# define DO_ANOTHER_NORMAL(XX) (XX < nr) /* keep going to end of vb */
-# endif
-# define REUSE_LIGHT_RESULTS(x) 0 /* always have a new normal */
-#endif
-
-
-
-#if (IDX & LIGHT_TWOSIDE)
+#if IDX & LIGHT_TWOSIDE
# define NR_SIDES 2
#else
# define NR_SIDES 1
#endif
+/* define TRACE to trace lighting code */
+/* #define TRACE 1 */
-static void TAG(light_rgba_spec)( GLcontext *ctx,
+/*
+ * ctx is the current context
+ * VB is the vertex buffer
+ * stage is the lighting stage-private data
+ * input is the vector of eye or object-space vertex coordinates
+ */
+static void TAG(light_rgba_spec)( GLcontext *ctx,
struct vertex_buffer *VB,
- struct gl_pipeline_stage *stage,
+ struct tnl_pipeline_stage *stage,
GLvector4f *input )
{
struct light_stage_data *store = LIGHT_STAGE_DATA(stage);
GLfloat (*base)[3] = ctx->Light._BaseColor;
- const GLchan *sumA = ctx->Light._BaseAlpha;
-
+ GLfloat sumA[2];
GLuint j;
- GLuint vstride = input->stride;
+ const GLuint vstride = input->stride;
const GLfloat *vertex = (GLfloat *)input->data;
- GLuint nstride = VB->NormalPtr->stride;
- const GLfloat *normal = (GLfloat *)VB->NormalPtr->data;
-
- GLchan (*CMcolor)[4];
- GLuint CMstride;
-
- GLchan (*Fcolor)[4] = (GLchan (*)[4]) store->LitColor[0].data;
- GLchan (*Bcolor)[4] = (GLchan (*)[4]) store->LitColor[1].data;
- GLchan (*Fspec)[4] = (GLchan (*)[4]) store->LitSecondary[0].data;
- GLchan (*Bspec)[4] = (GLchan (*)[4]) store->LitSecondary[1].data;
- GLuint nr = VB->Count;
-
- GLuint *flags = VB->Flag;
- struct gl_material (*new_material)[2] = VB->Material;
- GLuint *new_material_mask = VB->MaterialMask;
+ const GLuint nstride = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->stride;
+ const GLfloat *normal = (GLfloat *)VB->AttribPtr[_TNL_ATTRIB_NORMAL]->data;
+
+ GLfloat (*Fcolor)[4] = (GLfloat (*)[4]) store->LitColor[0].data;
+ GLfloat (*Fspec)[4] = (GLfloat (*)[4]) store->LitSecondary[0].data;
+#if IDX & LIGHT_TWOSIDE
+ GLfloat (*Bcolor)[4] = (GLfloat (*)[4]) store->LitColor[1].data;
+ GLfloat (*Bspec)[4] = (GLfloat (*)[4]) store->LitSecondary[1].data;
+#endif
- (void) flags;
- (void) nstride;
- (void) vstride;
+ const GLuint nr = VB->Count;
- if (IDX & LIGHT_COLORMATERIAL) {
- CMcolor = (GLchan (*)[4]) VB->ColorPtr[0]->data;
- CMstride = VB->ColorPtr[0]->stride;
- }
+#ifdef TRACE
+ fprintf(stderr, "%s\n", __FUNCTION__ );
+#endif
VB->ColorPtr[0] = &store->LitColor[0];
VB->SecondaryColorPtr[0] = &store->LitSecondary[0];
+ sumA[0] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3];
+
+#if IDX & LIGHT_TWOSIDE
+ VB->ColorPtr[1] = &store->LitColor[1];
+ VB->SecondaryColorPtr[1] = &store->LitSecondary[1];
+ sumA[1] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3];
+#endif
- if (IDX & LIGHT_TWOSIDE) {
- VB->ColorPtr[1] = &store->LitColor[1];
- VB->SecondaryColorPtr[1] = &store->LitSecondary[1];
- }
- /* Side-effects done, can we finish now?
- */
- if (stage->changed_inputs == 0)
- return;
+ store->LitColor[0].stride = 16;
+ store->LitColor[1].stride = 16;
- for ( j=0 ;
- j<nr ;
- j++,STRIDE_F(vertex,VSTRIDE),STRIDE_F(normal,NSTRIDE),CMSTRIDE)
- {
+ for (j = 0; j < nr; j++,STRIDE_F(vertex,vstride),STRIDE_F(normal,nstride)) {
GLfloat sum[2][3], spec[2][3];
struct gl_light *light;
-
- if ( CHECK_COLOR_MATERIAL(j) )
- gl_update_color_material( ctx, CMcolor[j] );
- if ( CHECK_MATERIAL(j) )
- gl_update_material( ctx, new_material[j], new_material_mask[j] );
-
- if ( CHECK_VALIDATE(j) )
- gl_validate_all_lighting_tables( ctx );
+#if IDX & LIGHT_MATERIAL
+ update_materials( ctx, store );
+ sumA[0] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3];
+#if IDX & LIGHT_TWOSIDE
+ sumA[1] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3];
+#endif
+#endif
COPY_3V(sum[0], base[0]);
ZERO_3V(spec[0]);
- if (IDX & LIGHT_TWOSIDE) {
- COPY_3V(sum[1], base[1]);
- ZERO_3V(spec[1]);
- }
-
+#if IDX & LIGHT_TWOSIDE
+ COPY_3V(sum[1], base[1]);
+ ZERO_3V(spec[1]);
+#endif
+
/* Add contribution from each enabled light source */
foreach (light, &ctx->Light.EnabledList) {
GLfloat n_dot_h;
GLfloat correction;
- GLint side;
+ GLint side;
GLfloat contrib[3];
GLfloat attenuation;
GLfloat VP[3]; /* unit vector from vertex to light */
GLfloat invd = 1.0F / d;
SELF_SCALE_SCALAR_3V(VP, invd);
}
-
- attenuation = 1.0F / (light->ConstantAttenuation + d *
- (light->LinearAttenuation + d *
+
+ attenuation = 1.0F / (light->ConstantAttenuation + d *
+ (light->LinearAttenuation + d *
light->QuadraticAttenuation));
/* spotlight attenuation */
if (light->_Flags & LIGHT_SPOT) {
GLfloat PV_dot_dir = - DOT3(VP, light->_NormDirection);
-
+
if (PV_dot_dir<light->_CosCutoff) {
continue; /* this light makes no contribution */
}
else {
- double x = PV_dot_dir * (EXP_TABLE_SIZE-1);
- int k = (int) x;
+ GLdouble x = PV_dot_dir * (EXP_TABLE_SIZE-1);
+ GLint k = (GLint) x;
GLfloat spot = (GLfloat) (light->_SpotExpTable[k][0]
- + (x-k)*light->_SpotExpTable[k][1]);
+ + (x-k)*light->_SpotExpTable[k][1]);
attenuation *= spot;
}
}
}
-
- if (attenuation < 1e-3)
+ if (attenuation < 1e-3)
continue; /* this light makes no contribution */
/* Compute dot product or normal and vector from V to light pos */
/* Which side gets the diffuse & specular terms? */
if (n_dot_VP < 0.0F) {
ACC_SCALE_SCALAR_3V(sum[0], attenuation, light->_MatAmbient[0]);
- if (!(IDX & LIGHT_TWOSIDE)) {
- continue;
- }
+#if IDX & LIGHT_TWOSIDE
side = 1;
correction = -1;
n_dot_VP = -n_dot_VP;
+#else
+ continue;
+#endif
}
else {
- if (IDX & LIGHT_TWOSIDE) {
- ACC_SCALE_SCALAR_3V( sum[1], attenuation, light->_MatAmbient[1]);
- }
+#if IDX & LIGHT_TWOSIDE
+ ACC_SCALE_SCALAR_3V( sum[1], attenuation, light->_MatAmbient[1]);
+#endif
side = 0;
correction = 1;
- }
+ }
/* diffuse term */
COPY_3V(contrib, light->_MatAmbient[side]);
else {
h = light->_h_inf_norm;
}
-
+
n_dot_h = correction * DOT3(normal, h);
if (n_dot_h > 0.0F) {
}
} /*loop over lights*/
- UNCLAMPED_FLOAT_TO_RGB_CHAN( Fcolor[j], sum[0] );
- UNCLAMPED_FLOAT_TO_RGB_CHAN( Fspec[j], spec[0] );
+ COPY_3V( Fcolor[j], sum[0] );
+ COPY_3V( Fspec[j], spec[0] );
Fcolor[j][3] = sumA[0];
-
- if (IDX & LIGHT_TWOSIDE) {
- UNCLAMPED_FLOAT_TO_RGB_CHAN( Bcolor[j], sum[1] );
- UNCLAMPED_FLOAT_TO_RGB_CHAN( Bspec[j], spec[1] );
- Bcolor[j][3] = sumA[1];
- }
- }
-
- if ( CHECK_COLOR_MATERIAL(j) )
- gl_update_color_material( ctx, CMcolor[j] );
-
- if ( CHECK_MATERIAL(j) )
- gl_update_material( ctx, new_material[j], new_material_mask[j] );
- if ( CHECK_VALIDATE(j) )
- gl_validate_all_lighting_tables( ctx );
+#if IDX & LIGHT_TWOSIDE
+ COPY_3V( Bcolor[j], sum[1] );
+ COPY_3V( Bspec[j], spec[1] );
+ Bcolor[j][3] = sumA[1];
+#endif
+ }
}
-static void TAG(light_rgba)( GLcontext *ctx,
+static void TAG(light_rgba)( GLcontext *ctx,
struct vertex_buffer *VB,
- struct gl_pipeline_stage *stage,
+ struct tnl_pipeline_stage *stage,
GLvector4f *input )
{
struct light_stage_data *store = LIGHT_STAGE_DATA(stage);
GLuint j;
GLfloat (*base)[3] = ctx->Light._BaseColor;
- const GLchan *sumA = ctx->Light._BaseAlpha;
+ GLfloat sumA[2];
- GLuint vstride = input->stride;
+ const GLuint vstride = input->stride;
const GLfloat *vertex = (GLfloat *) input->data;
- GLuint nstride = VB->NormalPtr->stride;
- const GLfloat *normal = (GLfloat *)VB->NormalPtr->data;
-
- GLubyte (*CMcolor)[4];
- GLuint CMstride;
-
- GLchan (*Fcolor)[4] = (GLchan (*)[4]) store->LitColor[0].data;
- GLchan (*Bcolor)[4] = (GLchan (*)[4]) store->LitColor[1].data;
- GLuint *flags = VB->Flag;
+ const GLuint nstride = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->stride;
+ const GLfloat *normal = (GLfloat *)VB->AttribPtr[_TNL_ATTRIB_NORMAL]->data;
- struct gl_material (*new_material)[2] = VB->Material;
- GLuint *new_material_mask = VB->MaterialMask;
- GLuint nr = VB->Count;
+ GLfloat (*Fcolor)[4] = (GLfloat (*)[4]) store->LitColor[0].data;
+#if IDX & LIGHT_TWOSIDE
+ GLfloat (*Bcolor)[4] = (GLfloat (*)[4]) store->LitColor[1].data;
+#endif
- (void) flags;
- (void) nstride;
- (void) vstride;
+ const GLuint nr = VB->Count;
- if (IDX & LIGHT_COLORMATERIAL) {
- CMcolor = VB->ColorPtr[0]->data;
- CMstride = VB->ColorPtr[0]->stride;
- }
+#ifdef TRACE
+ fprintf(stderr, "%s\n", __FUNCTION__ );
+#endif
VB->ColorPtr[0] = &store->LitColor[0];
- if (IDX & LIGHT_TWOSIDE)
- VB->ColorPtr[1] = &store->LitColor[1];
+ sumA[0] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3];
+
+#if IDX & LIGHT_TWOSIDE
+ VB->ColorPtr[1] = &store->LitColor[1];
+ sumA[1] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3];
+#endif
- if (stage->changed_inputs == 0)
- return;
+ store->LitColor[0].stride = 16;
+ store->LitColor[1].stride = 16;
- for ( j=0 ;
- j<nr ;
- j++,STRIDE_F(vertex,VSTRIDE), STRIDE_F(normal,NSTRIDE),CMSTRIDE)
- {
+ for (j = 0; j < nr; j++,STRIDE_F(vertex,vstride),STRIDE_F(normal,nstride)) {
GLfloat sum[2][3];
struct gl_light *light;
- if ( CHECK_COLOR_MATERIAL(j) )
- gl_update_color_material( ctx, (GLchan *)CMcolor[j] );
-
- if ( CHECK_MATERIAL(j) )
- gl_update_material( ctx, new_material[j], new_material_mask[j] );
-
- if ( CHECK_VALIDATE(j) )
- gl_validate_all_lighting_tables( ctx );
+#if IDX & LIGHT_MATERIAL
+ update_materials( ctx, store );
+ sumA[0] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3];
+#if IDX & LIGHT_TWOSIDE
+ sumA[1] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3];
+#endif
+#endif
COPY_3V(sum[0], base[0]);
-
- if ( IDX & LIGHT_TWOSIDE )
- COPY_3V(sum[1], base[1]);
-
+
+#if IDX & LIGHT_TWOSIDE
+ COPY_3V(sum[1], base[1]);
+#endif
+
/* Add contribution from each enabled light source */
foreach (light, &ctx->Light.EnabledList) {
GLfloat n_dot_h;
GLfloat correction;
- GLint side;
+ GLint side;
GLfloat contrib[3];
GLfloat attenuation = 1.0;
GLfloat VP[3]; /* unit vector from vertex to light */
SUB_3V(VP, light->_Position, vertex);
- d = LEN_3FV( VP );
+ d = (GLfloat) LEN_3FV( VP );
if ( d > 1e-6) {
GLfloat invd = 1.0F / d;
SELF_SCALE_SCALAR_3V(VP, invd);
}
- attenuation = 1.0F / (light->ConstantAttenuation + d *
- (light->LinearAttenuation + d *
+ attenuation = 1.0F / (light->ConstantAttenuation + d *
+ (light->LinearAttenuation + d *
light->QuadraticAttenuation));
/* spotlight attenuation */
continue; /* this light makes no contribution */
}
else {
- double x = PV_dot_dir * (EXP_TABLE_SIZE-1);
- int k = (int) x;
- GLfloat spot = (light->_SpotExpTable[k][0]
+ GLdouble x = PV_dot_dir * (EXP_TABLE_SIZE-1);
+ GLint k = (GLint) x;
+ GLfloat spot = (GLfloat) (light->_SpotExpTable[k][0]
+ (x-k)*light->_SpotExpTable[k][1]);
attenuation *= spot;
}
}
}
-
- if (attenuation < 1e-3)
+ if (attenuation < 1e-3)
continue; /* this light makes no contribution */
-
/* Compute dot product or normal and vector from V to light pos */
n_dot_VP = DOT3( normal, VP );
/* which side are we lighting? */
if (n_dot_VP < 0.0F) {
ACC_SCALE_SCALAR_3V(sum[0], attenuation, light->_MatAmbient[0]);
-
- if (!(IDX & LIGHT_TWOSIDE))
- continue;
-
+#if IDX & LIGHT_TWOSIDE
side = 1;
correction = -1;
n_dot_VP = -n_dot_VP;
+#else
+ continue;
+#endif
}
else {
- if (IDX & LIGHT_TWOSIDE) {
- ACC_SCALE_SCALAR_3V( sum[1], attenuation, light->_MatAmbient[1]);
- }
+#if IDX & LIGHT_TWOSIDE
+ ACC_SCALE_SCALAR_3V( sum[1], attenuation, light->_MatAmbient[1]);
+#endif
side = 0;
correction = 1;
- }
-
+ }
+
COPY_3V(contrib, light->_MatAmbient[side]);
/* diffuse term */
else {
h = light->_h_inf_norm;
}
-
+
n_dot_h = correction * DOT3(normal, h);
- if (n_dot_h > 0.0F)
+ if (n_dot_h > 0.0F)
{
GLfloat spec_coef;
struct gl_shine_tab *tab = ctx->_ShineTable[side];
-
+
GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec_coef );
ACC_SCALE_SCALAR_3V( contrib, spec_coef,
}
ACC_SCALE_SCALAR_3V( sum[side], attenuation, contrib );
- }
-
- UNCLAMPED_FLOAT_TO_RGB_CHAN( Fcolor[j], sum[0] );
- Fcolor[j][3] = sumA[0];
-
- if (IDX & LIGHT_TWOSIDE) {
- UNCLAMPED_FLOAT_TO_RGB_CHAN( Bcolor[j], sum[1] );
- Bcolor[j][3] = sumA[1];
}
- }
- if ( CHECK_COLOR_MATERIAL(j) )
- gl_update_color_material( ctx, (GLchan *)CMcolor[j] );
-
- if ( CHECK_MATERIAL(j) )
- gl_update_material( ctx, new_material[j], new_material_mask[j] );
+ COPY_3V( Fcolor[j], sum[0] );
+ Fcolor[j][3] = sumA[0];
- if ( CHECK_VALIDATE(j) )
- gl_validate_all_lighting_tables( ctx );
+#if IDX & LIGHT_TWOSIDE
+ COPY_3V( Bcolor[j], sum[1] );
+ Bcolor[j][3] = sumA[1];
+#endif
+ }
}
/* As below, but with just a single light.
*/
-static void TAG(light_fast_rgba_single)( GLcontext *ctx,
+static void TAG(light_fast_rgba_single)( GLcontext *ctx,
struct vertex_buffer *VB,
- struct gl_pipeline_stage *stage,
+ struct tnl_pipeline_stage *stage,
GLvector4f *input )
{
struct light_stage_data *store = LIGHT_STAGE_DATA(stage);
- GLuint nstride = VB->NormalPtr->stride;
- const GLfloat *normal = (GLfloat *)VB->NormalPtr->data;
- GLubyte (*CMcolor)[4];
- GLuint CMstride;
- GLchan (*Fcolor)[4] = (GLchan (*)[4]) store->LitColor[0].data;
- GLchan (*Bcolor)[4] = (GLchan (*)[4]) store->LitColor[1].data;
- struct gl_light *light = ctx->Light.EnabledList.next;
- GLuint *flags = VB->Flag;
- GLchan baseubyte[2][4];
+ const GLuint nstride = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->stride;
+ const GLfloat *normal = (GLfloat *)VB->AttribPtr[_TNL_ATTRIB_NORMAL]->data;
+ GLfloat (*Fcolor)[4] = (GLfloat (*)[4]) store->LitColor[0].data;
+#if IDX & LIGHT_TWOSIDE
+ GLfloat (*Bcolor)[4] = (GLfloat (*)[4]) store->LitColor[1].data;
+#endif
+ const struct gl_light *light = ctx->Light.EnabledList.next;
GLuint j = 0;
- struct gl_material (*new_material)[2] = VB->Material;
- GLuint *new_material_mask = VB->MaterialMask;
- GLfloat base[2][3];
- GLuint nr = VB->Count;
+ GLfloat base[2][4];
+#if IDX & LIGHT_MATERIAL
+ const GLuint nr = VB->Count;
+#else
+ const GLuint nr = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->count;
+#endif
- (void) input; /* doesn't refer to Eye or Obj */
- (void) flags;
- (void) nr;
- (void) nstride;
+#ifdef TRACE
+ fprintf(stderr, "%s\n", __FUNCTION__ );
+#endif
- if (IDX & LIGHT_COLORMATERIAL) {
- CMcolor = VB->ColorPtr[0]->data;
- CMstride = VB->ColorPtr[0]->stride;
- }
+ (void) input; /* doesn't refer to Eye or Obj */
VB->ColorPtr[0] = &store->LitColor[0];
- if (IDX & LIGHT_TWOSIDE)
- VB->ColorPtr[1] = &store->LitColor[1];
-
- if (stage->changed_inputs == 0)
- return;
+#if IDX & LIGHT_TWOSIDE
+ VB->ColorPtr[1] = &store->LitColor[1];
+#endif
- if ( CHECK_COLOR_MATERIAL(j) )
- gl_update_color_material( ctx, (GLchan *)CMcolor[j] );
+ if (nr > 1) {
+ store->LitColor[0].stride = 16;
+ store->LitColor[1].stride = 16;
+ }
+ else {
+ store->LitColor[0].stride = 0;
+ store->LitColor[1].stride = 0;
+ }
- if ( CHECK_MATERIAL(j) )
- gl_update_material( ctx, new_material[j], new_material_mask[j] );
+ for (j = 0; j < nr; j++, STRIDE_F(normal,nstride)) {
- if ( CHECK_VALIDATE(j) )
- gl_validate_all_lighting_tables( ctx );
+ GLfloat n_dot_VP;
- baseubyte[0][3] = ctx->Light._BaseAlpha[0];
- baseubyte[1][3] = ctx->Light._BaseAlpha[1];
+#if IDX & LIGHT_MATERIAL
+ update_materials( ctx, store );
+#endif
- do {
/* No attenuation, so incoporate _MatAmbient into base color.
*/
+#if !(IDX & LIGHT_MATERIAL)
+ if ( j == 0 )
+#endif
{
COPY_3V(base[0], light->_MatAmbient[0]);
ACC_3V(base[0], ctx->Light._BaseColor[0] );
- UNCLAMPED_FLOAT_TO_RGB_CHAN( baseubyte[0], base[0] );
-
- if (IDX & LIGHT_TWOSIDE) {
- COPY_3V(base[1], light->_MatAmbient[1]);
- ACC_3V(base[1], ctx->Light._BaseColor[1]);
- UNCLAMPED_FLOAT_TO_RGB_CHAN( baseubyte[1], base[1]);
- }
- }
+ base[0][3] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3];
- do {
- GLfloat n_dot_VP = DOT3(normal, light->_VP_inf_norm);
-
- COPY_CHAN4(Fcolor[j], baseubyte[0]);
- if (IDX & LIGHT_TWOSIDE) COPY_CHAN4(Bcolor[j], baseubyte[1]);
+#if IDX & LIGHT_TWOSIDE
+ COPY_3V(base[1], light->_MatAmbient[1]);
+ ACC_3V(base[1], ctx->Light._BaseColor[1]);
+ base[1][3] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3];
+#endif
+ }
- if (n_dot_VP < 0.0F) {
- if (IDX & LIGHT_TWOSIDE) {
- GLfloat n_dot_h = -DOT3(normal, light->_h_inf_norm);
- GLfloat sum[3];
- COPY_3V(sum, base[1]);
- ACC_SCALE_SCALAR_3V(sum, -n_dot_VP, light->_MatDiffuse[1]);
- if (n_dot_h > 0.0F) {
- GLfloat spec;
- GET_SHINE_TAB_ENTRY( ctx->_ShineTable[1], n_dot_h, spec );
- ACC_SCALE_SCALAR_3V(sum, spec, light->_MatSpecular[1]);
- }
- UNCLAMPED_FLOAT_TO_RGB_CHAN(Bcolor[j], sum );
- }
- } else {
- GLfloat n_dot_h = DOT3(normal, light->_h_inf_norm);
- GLfloat sum[3];
- COPY_3V(sum, base[0]);
- ACC_SCALE_SCALAR_3V(sum, n_dot_VP, light->_MatDiffuse[0]);
- if (n_dot_h > 0.0F) {
- GLfloat spec;
- GET_SHINE_TAB_ENTRY( ctx->_ShineTable[0], n_dot_h, spec );
- ACC_SCALE_SCALAR_3V(sum, spec, light->_MatSpecular[0]);
+ n_dot_VP = DOT3(normal, light->_VP_inf_norm);
+
+ if (n_dot_VP < 0.0F) {
+#if IDX & LIGHT_TWOSIDE
+ GLfloat n_dot_h = -DOT3(normal, light->_h_inf_norm);
+ GLfloat sum[3];
+ COPY_3V(sum, base[1]);
+ ACC_SCALE_SCALAR_3V(sum, -n_dot_VP, light->_MatDiffuse[1]);
+ if (n_dot_h > 0.0F) {
+ GLfloat spec;
+ GET_SHINE_TAB_ENTRY( ctx->_ShineTable[1], n_dot_h, spec );
+ ACC_SCALE_SCALAR_3V(sum, spec, light->_MatSpecular[1]);
+ }
+ COPY_3V(Bcolor[j], sum );
+ Bcolor[j][3] = base[1][3];
+#endif
+ COPY_4FV(Fcolor[j], base[0]);
+ }
+ else {
+ GLfloat n_dot_h = DOT3(normal, light->_h_inf_norm);
+ GLfloat sum[3];
+ COPY_3V(sum, base[0]);
+ ACC_SCALE_SCALAR_3V(sum, n_dot_VP, light->_MatDiffuse[0]);
+ if (n_dot_h > 0.0F) {
+ GLfloat spec;
+ GET_SHINE_TAB_ENTRY( ctx->_ShineTable[0], n_dot_h, spec );
+ ACC_SCALE_SCALAR_3V(sum, spec, light->_MatSpecular[0]);
- }
- UNCLAMPED_FLOAT_TO_RGB_CHAN(Fcolor[j], sum );
}
-
- j++;
- STRIDE_F(normal, NSTRIDE);
- } while (DO_ANOTHER_NORMAL(j));
-
-
- for ( ; REUSE_LIGHT_RESULTS(j) ; j++ ) {
- COPY_CHAN4(Fcolor[j], Fcolor[j-1]);
- if (IDX & LIGHT_TWOSIDE)
- COPY_CHAN4(Bcolor[j], Bcolor[j-1]);
- STRIDE_F(normal, NSTRIDE);
+ COPY_3V(Fcolor[j], sum );
+ Fcolor[j][3] = base[0][3];
+#if IDX & LIGHT_TWOSIDE
+ COPY_4FV(Bcolor[j], base[1]);
+#endif
}
-
- /* Have to recompute our base colors on material change.
- */
- if ( CHECK_MATERIAL(j) )
- gl_update_material( ctx, new_material[j], new_material_mask[j] );
-
- if ( CHECK_COLOR_MATERIAL(j) )
- gl_update_color_material( ctx, (GLchan *)CMcolor[j] );
-
- if ( CHECK_VALIDATE(j) )
- gl_validate_all_lighting_tables( ctx );
-
- } while (!CHECK_END_VB(j));
-}
+ }
+}
/* Light infinite lights
*/
-static void TAG(light_fast_rgba)( GLcontext *ctx,
+static void TAG(light_fast_rgba)( GLcontext *ctx,
struct vertex_buffer *VB,
- struct gl_pipeline_stage *stage,
+ struct tnl_pipeline_stage *stage,
GLvector4f *input )
{
struct light_stage_data *store = LIGHT_STAGE_DATA(stage);
- const GLchan *sumA = ctx->Light._BaseAlpha;
- GLuint nstride = VB->NormalPtr->stride;
- const GLfloat *normal = (GLfloat *)VB->NormalPtr->data;
- GLubyte (*CMcolor)[4];
- GLuint CMstride;
- GLchan (*Fcolor)[4] = (GLchan (*)[4]) store->LitColor[0].data;
- GLchan (*Bcolor)[4] = (GLchan (*)[4]) store->LitColor[1].data;
- GLuint *flags = VB->Flag;
+ GLfloat sumA[2];
+ const GLuint nstride = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->stride;
+ const GLfloat *normal = (GLfloat *)VB->AttribPtr[_TNL_ATTRIB_NORMAL]->data;
+ GLfloat (*Fcolor)[4] = (GLfloat (*)[4]) store->LitColor[0].data;
+#if IDX & LIGHT_TWOSIDE
+ GLfloat (*Bcolor)[4] = (GLfloat (*)[4]) store->LitColor[1].data;
+#endif
GLuint j = 0;
- struct gl_material (*new_material)[2] = VB->Material;
- GLuint *new_material_mask = VB->MaterialMask;
- GLuint nr = VB->Count;
- struct gl_light *light;
+#if IDX & LIGHT_MATERIAL
+ const GLuint nr = VB->Count;
+#else
+ const GLuint nr = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->count;
+#endif
+ const struct gl_light *light;
+
+#ifdef TRACE
+ fprintf(stderr, "%s %d\n", __FUNCTION__, nr );
+#endif
- (void) flags;
(void) input;
- (void) nr;
- (void) nstride;
- if (IDX & LIGHT_COLORMATERIAL) {
- CMcolor = VB->ColorPtr[0]->data;
- CMstride = VB->ColorPtr[0]->stride;
- }
+ sumA[0] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3];
+ sumA[1] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3];
VB->ColorPtr[0] = &store->LitColor[0];
- if (IDX & LIGHT_TWOSIDE)
- VB->ColorPtr[1] = &store->LitColor[1];
+#if IDX & LIGHT_TWOSIDE
+ VB->ColorPtr[1] = &store->LitColor[1];
+#endif
- if ( CHECK_COLOR_MATERIAL(j) )
- gl_update_color_material( ctx, *CMcolor );
+ if (nr > 1) {
+ store->LitColor[0].stride = 16;
+ store->LitColor[1].stride = 16;
+ }
+ else {
+ store->LitColor[0].stride = 0;
+ store->LitColor[1].stride = 0;
+ }
- if ( CHECK_MATERIAL(j) )
- gl_update_material( ctx, new_material[j], new_material_mask[j] );
+ for (j = 0; j < nr; j++, STRIDE_F(normal,nstride)) {
- if ( CHECK_VALIDATE(j) )
- gl_validate_all_lighting_tables( ctx );
+ GLfloat sum[2][3];
- do {
- do {
- GLfloat sum[2][3];
+#if IDX & LIGHT_MATERIAL
+ update_materials( ctx, store );
- COPY_3V(sum[0], ctx->Light._BaseColor[0]);
- if (IDX & LIGHT_TWOSIDE)
- COPY_3V(sum[1], ctx->Light._BaseColor[1]);
+ sumA[0] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3];
+#if IDX & LIGHT_TWOSIDE
+ sumA[1] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3];
+#endif
+#endif
- foreach (light, &ctx->Light.EnabledList) {
- GLfloat n_dot_h, n_dot_VP, spec;
- ACC_3V(sum[0], light->_MatAmbient[0]);
- if (IDX & LIGHT_TWOSIDE)
- ACC_3V(sum[1], light->_MatAmbient[1]);
+ COPY_3V(sum[0], ctx->Light._BaseColor[0]);
+#if IDX & LIGHT_TWOSIDE
+ COPY_3V(sum[1], ctx->Light._BaseColor[1]);
+#endif
- n_dot_VP = DOT3(normal, light->_VP_inf_norm);
+ foreach (light, &ctx->Light.EnabledList) {
+ GLfloat n_dot_h, n_dot_VP, spec;
- if (n_dot_VP > 0.0F) {
- ACC_SCALE_SCALAR_3V(sum[0], n_dot_VP, light->_MatDiffuse[0]);
- n_dot_h = DOT3(normal, light->_h_inf_norm);
- if (n_dot_h > 0.0F) {
- struct gl_shine_tab *tab = ctx->_ShineTable[0];
- GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec );
- ACC_SCALE_SCALAR_3V( sum[0], spec,
- light->_MatSpecular[0]);
- }
- }
- else if (IDX & LIGHT_TWOSIDE) {
- ACC_SCALE_SCALAR_3V(sum[1], -n_dot_VP, light->_MatDiffuse[1]);
- n_dot_h = -DOT3(normal, light->_h_inf_norm);
- if (n_dot_h > 0.0F) {
- struct gl_shine_tab *tab = ctx->_ShineTable[1];
- GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec );
- ACC_SCALE_SCALAR_3V( sum[1], spec,
- light->_MatSpecular[1]);
- }
+ ACC_3V(sum[0], light->_MatAmbient[0]);
+#if IDX & LIGHT_TWOSIDE
+ ACC_3V(sum[1], light->_MatAmbient[1]);
+#endif
+
+ n_dot_VP = DOT3(normal, light->_VP_inf_norm);
+
+ if (n_dot_VP > 0.0F) {
+ ACC_SCALE_SCALAR_3V(sum[0], n_dot_VP, light->_MatDiffuse[0]);
+ n_dot_h = DOT3(normal, light->_h_inf_norm);
+ if (n_dot_h > 0.0F) {
+ struct gl_shine_tab *tab = ctx->_ShineTable[0];
+ GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec );
+ ACC_SCALE_SCALAR_3V( sum[0], spec, light->_MatSpecular[0]);
}
}
-
- UNCLAMPED_FLOAT_TO_RGB_CHAN( Fcolor[j], sum[0] );
- Fcolor[j][3] = sumA[0];
-
- if (IDX & LIGHT_TWOSIDE) {
- UNCLAMPED_FLOAT_TO_RGB_CHAN( Bcolor[j], sum[1] );
- Bcolor[j][3] = sumA[1];
+#if IDX & LIGHT_TWOSIDE
+ else {
+ ACC_SCALE_SCALAR_3V(sum[1], -n_dot_VP, light->_MatDiffuse[1]);
+ n_dot_h = -DOT3(normal, light->_h_inf_norm);
+ if (n_dot_h > 0.0F) {
+ struct gl_shine_tab *tab = ctx->_ShineTable[1];
+ GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec );
+ ACC_SCALE_SCALAR_3V( sum[1], spec, light->_MatSpecular[1]);
+ }
}
-
- j++;
- STRIDE_F(normal, NSTRIDE);
- } while (DO_ANOTHER_NORMAL(j));
-
- /* Reuse the shading results while there is no change to
- * normal or material values.
- */
- for ( ; REUSE_LIGHT_RESULTS(j) ; j++ ) {
- COPY_CHAN4(Fcolor[j], Fcolor[j-1]);
- if (IDX & LIGHT_TWOSIDE)
- COPY_CHAN4(Bcolor[j], Bcolor[j-1]);
- STRIDE_F(normal, NSTRIDE);
+#endif
}
- if ( CHECK_COLOR_MATERIAL(j) )
- gl_update_color_material( ctx, CMcolor[j] );
-
- if ( CHECK_MATERIAL(j) )
- gl_update_material( ctx, new_material[j], new_material_mask[j] );
-
- if ( CHECK_VALIDATE(j) )
- gl_validate_all_lighting_tables( ctx );
+ COPY_3V( Fcolor[j], sum[0] );
+ Fcolor[j][3] = sumA[0];
- } while (!CHECK_END_VB(j));
-}
+#if IDX & LIGHT_TWOSIDE
+ COPY_3V( Bcolor[j], sum[1] );
+ Bcolor[j][3] = sumA[1];
+#endif
+ }
+}
* normal - array of [n] surface normal vector
* Output: indexResult - resulting array of [n] color indexes
*/
-static void TAG(light_ci)( GLcontext *ctx,
+static void TAG(light_ci)( GLcontext *ctx,
struct vertex_buffer *VB,
- struct gl_pipeline_stage *stage,
+ struct tnl_pipeline_stage *stage,
GLvector4f *input )
{
struct light_stage_data *store = LIGHT_STAGE_DATA(stage);
GLuint j;
- GLuint vstride = input->stride;
+ const GLuint vstride = input->stride;
const GLfloat *vertex = (GLfloat *) input->data;
- GLuint nstride = VB->NormalPtr->stride;
- const GLfloat *normal = (GLfloat *)VB->NormalPtr->data;
- GLubyte (*CMcolor)[4];
- GLuint CMstride;
- GLuint *flags = VB->Flag;
- GLuint *indexResult[2];
- struct gl_material (*new_material)[2] = VB->Material;
- GLuint *new_material_mask = VB->MaterialMask;
- GLuint nr = VB->Count;
-
- (void) flags;
- (void) nstride;
- (void) vstride;
+ const GLuint nstride = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->stride;
+ const GLfloat *normal = (GLfloat *)VB->AttribPtr[_TNL_ATTRIB_NORMAL]->data;
+ GLfloat *indexResult[2];
+ const GLuint nr = VB->Count;
- VB->IndexPtr[0] = &store->LitIndex[0];
- if (IDX & LIGHT_TWOSIDE)
- VB->IndexPtr[1] = &store->LitIndex[1];
+#ifdef TRACE
+ fprintf(stderr, "%s\n", __FUNCTION__ );
+#endif
- indexResult[0] = VB->IndexPtr[0]->data;
- indexResult[1] = VB->IndexPtr[1]->data;
+ VB->IndexPtr[0] = &store->LitIndex[0];
+#if IDX & LIGHT_TWOSIDE
+ VB->IndexPtr[1] = &store->LitIndex[1];
+#endif
- if (IDX & LIGHT_COLORMATERIAL) {
- CMcolor = VB->ColorPtr[0]->data;
- CMstride = VB->ColorPtr[0]->stride;
- }
+ indexResult[0] = (GLfloat *)VB->IndexPtr[0]->data;
+#if IDX & LIGHT_TWOSIDE
+ indexResult[1] = (GLfloat *)VB->IndexPtr[1]->data;
+#endif
/* loop over vertices */
- for ( j=0 ;
- j<nr ;
- j++,STRIDE_F(vertex,VSTRIDE),STRIDE_F(normal, NSTRIDE), CMSTRIDE)
- {
+ for (j=0; j<nr; j++,STRIDE_F(vertex,vstride),STRIDE_F(normal, nstride)) {
GLfloat diffuse[2], specular[2];
GLuint side = 0;
struct gl_light *light;
-
- if ( CHECK_COLOR_MATERIAL(j) )
- gl_update_color_material( ctx, (GLchan *)CMcolor[j] );
-
- if ( CHECK_MATERIAL(j) )
- gl_update_material( ctx, new_material[j], new_material_mask[j] );
- if ( CHECK_VALIDATE(j) )
- gl_validate_all_lighting_tables( ctx );
+#if IDX & LIGHT_MATERIAL
+ update_materials( ctx, store );
+#endif
diffuse[0] = specular[0] = 0.0F;
- if ( IDX & LIGHT_TWOSIDE ) {
+#if IDX & LIGHT_TWOSIDE
diffuse[1] = specular[1] = 0.0F;
- }
+#endif
/* Accumulate diffuse and specular from each light source */
foreach (light, &ctx->Light.EnabledList) {
}
else {
GLfloat d; /* distance from vertex to light */
-
+
SUB_3V(VP, light->_Position, vertex);
- d = LEN_3FV( VP );
+ d = (GLfloat) LEN_3FV( VP );
if ( d > 1e-6) {
GLfloat invd = 1.0F / d;
SELF_SCALE_SCALAR_3V(VP, invd);
}
- attenuation = 1.0F / (light->ConstantAttenuation + d *
- (light->LinearAttenuation + d *
+ attenuation = 1.0F / (light->ConstantAttenuation + d *
+ (light->LinearAttenuation + d *
light->QuadraticAttenuation));
/* spotlight attenuation */
if (light->_Flags & LIGHT_SPOT) {
GLfloat PV_dot_dir = - DOT3(VP, light->_NormDirection);
- if (PV_dot_dir<light->_CosCutoff) {
+ if (PV_dot_dir < light->_CosCutoff) {
continue; /* this light makes no contribution */
}
else {
- double x = PV_dot_dir * (EXP_TABLE_SIZE-1);
- int k = (int) x;
- GLfloat spot = (light->_SpotExpTable[k][0]
+ GLdouble x = PV_dot_dir * (EXP_TABLE_SIZE-1);
+ GLint k = (GLint) x;
+ GLfloat spot = (GLfloat) (light->_SpotExpTable[k][0]
+ (x-k)*light->_SpotExpTable[k][1]);
attenuation *= spot;
}
}
}
- if (attenuation < 1e-3)
+ if (attenuation < 1e-3)
continue; /* this light makes no contribution */
n_dot_VP = DOT3( normal, VP );
/* which side are we lighting? */
if (n_dot_VP < 0.0F) {
- if (!(IDX & LIGHT_TWOSIDE))
- continue;
+#if IDX & LIGHT_TWOSIDE
side = 1;
correction = -1;
n_dot_VP = -n_dot_VP;
+#else
+ continue;
+#endif
}
/* accumulate diffuse term */
}
else if (light->_Flags & LIGHT_POSITIONAL) {
h = VP;
- ACC_3V(h, ctx->_EyeZDir);
+ /* Strangely, disabling this addition fixes a conformance
+ * problem. If this code is enabled, l_sed.c fails.
+ */
+ /*ACC_3V(h, ctx->_EyeZDir);*/
NORMALIZE_3FV(h);
}
else {
}
n_dot_h = correction * DOT3(normal, h);
-
- if (n_dot_h > 0.0F)
- {
+ if (n_dot_h > 0.0F) {
GLfloat spec_coef;
struct gl_shine_tab *tab = ctx->_ShineTable[side];
GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec_coef);
/* Now compute final color index */
for (side = 0 ; side < NR_SIDES ; side++) {
- struct gl_material *mat = &ctx->Light.Material[side];
+ const GLfloat *ind = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_INDEXES + side];
GLfloat index;
if (specular[side] > 1.0F) {
- index = mat->SpecularIndex;
+ index = ind[MAT_INDEX_SPECULAR];
}
else {
- GLfloat d_a = mat->DiffuseIndex - mat->AmbientIndex;
- GLfloat s_a = mat->SpecularIndex - mat->AmbientIndex;
-
- index = mat->AmbientIndex
- + diffuse[side] * (1.0F-specular[side]) * d_a
- + specular[side] * s_a;
-
- if (index > mat->SpecularIndex) {
- index = mat->SpecularIndex;
+ GLfloat d_a = ind[MAT_INDEX_DIFFUSE] - ind[MAT_INDEX_AMBIENT];
+ GLfloat s_a = ind[MAT_INDEX_SPECULAR] - ind[MAT_INDEX_AMBIENT];
+ index = (ind[MAT_INDEX_AMBIENT]
+ + diffuse[side] * (1.0F-specular[side]) * d_a
+ + specular[side] * s_a);
+ if (index > ind[MAT_INDEX_SPECULAR]) {
+ index = ind[MAT_INDEX_SPECULAR];
}
}
- indexResult[side][j] = (GLuint) (GLint) index;
+ indexResult[side][j] = index;
}
} /*for vertex*/
-
- if ( CHECK_COLOR_MATERIAL(j) )
- gl_update_color_material( ctx, CMcolor[j] );
-
- if ( CHECK_MATERIAL(j) )
- gl_update_material( ctx, new_material[j], new_material_mask[j] );
-
- if ( CHECK_VALIDATE(j) )
- gl_validate_all_lighting_tables( ctx );
}
#undef TAG
-#undef IDX
+#undef IDX
#undef NR_SIDES
-#undef NSTRIDE
-#undef VSTRIDE
-#undef CHECK_MATERIAL
-#undef CHECK_END_VB
-#undef DO_ANOTHER_NORMAL
-#undef REUSE_LIGHT_RESULTS
-#undef CMSTRIDE
-#undef CHECK_COLOR_MATERIAL
-#undef CHECK_VALIDATE