#if (IDX & LIGHT_FLAGS)
# define VSTRIDE (4 * sizeof(GLfloat))
# define NSTRIDE nstride
# define CHECK_MATERIAL(x) (flags[x] & VERT_BIT_MATERIAL)
# define CHECK_END_VB(x) (flags[x] & VERT_BIT_END_VB)
# if (IDX & LIGHT_COLORMATERIAL)
# define CMSTRIDE STRIDE_F(CMcolor, CMstride)
# define CHECK_COLOR_MATERIAL(x) (flags[x] & VERT_BIT_COLOR0)
# define CHECK_VALIDATE(x) (flags[x] & (VERT_BIT_COLOR0|VERT_BIT_MATERIAL))
# define DO_ANOTHER_NORMAL(x) \
((flags[x] & (VERT_BIT_COLOR0|VERT_BIT_NORMAL|VERT_BIT_END_VB|VERT_BIT_MATERIAL)) == VERT_BIT_NORMAL)
# define REUSE_LIGHT_RESULTS(x) \
((flags[x] & (VERT_BIT_COLOR0|VERT_BIT_NORMAL|VERT_BIT_END_VB|VERT_BIT_MATERIAL)) == 0)
# else
# define CMSTRIDE (void)0
# define CHECK_COLOR_MATERIAL(x) 0
# define CHECK_VALIDATE(x) (flags[x] & (VERT_BIT_MATERIAL))
# define DO_ANOTHER_NORMAL(x) \
((flags[x] & (VERT_BIT_NORMAL|VERT_BIT_END_VB|VERT_BIT_MATERIAL)) == VERT_BIT_NORMAL)
# define REUSE_LIGHT_RESULTS(x) \
((flags[x] & (VERT_BIT_NORMAL|VERT_BIT_END_VB|VERT_BIT_MATERIAL)) == 0)
# endif
#else
# define VSTRIDE vstride
# define NSTRIDE nstride
# define CHECK_MATERIAL(x) 0
# define CHECK_END_VB(XX) (XX >= nr)
# if (IDX & LIGHT_COLORMATERIAL)
# define CMSTRIDE STRIDE_F(CMcolor, CMstride)
# define CHECK_COLOR_MATERIAL(x) (x < nr)
# define CHECK_VALIDATE(x) (x < nr)
# define DO_ANOTHER_NORMAL(x) 0
# else
# define CMSTRIDE (void)0
# define CHECK_COLOR_MATERIAL(x) 0
# define CHECK_VALIDATE(x) (0)
# define DO_ANOTHER_NORMAL(XX) (XX < nr)
# endif
# define REUSE_LIGHT_RESULTS(x) 0
#endif
#if (IDX & LIGHT_TWOSIDE)
# define NR_SIDES 2
#else
# define NR_SIDES 1
#endif
static void TAG(light_rgba_spec)( GLcontext *ctx,
struct vertex_buffer *VB,
struct gl_pipeline_stage *stage,
GLvector4f *input )
{
struct light_stage_data *store = LIGHT_STAGE_DATA(stage);
GLfloat (*base)[3] = ctx->Light._BaseColor;
GLchan sumA[2];
GLuint j;
const GLuint vstride = input->stride;
const GLfloat *vertex = (GLfloat *)input->data;
const GLuint nstride = VB->NormalPtr->stride;
const GLfloat *normal = (GLfloat *)VB->NormalPtr->data;
GLfloat *CMcolor;
#if IDX & LIGHT_COLORMATERIAL
GLuint CMstride;
#endif
GLchan (*Fcolor)[4] = (GLchan (*)[4]) store->LitColor[0].Ptr;
#if IDX & LIGHT_TWOSIDE
GLchan (*Bcolor)[4] = (GLchan (*)[4]) store->LitColor[1].Ptr;
#endif
GLchan (*Fspec)[4] = (GLchan (*)[4]) store->LitSecondary[0].Ptr;
#if IDX & LIGHT_TWOSIDE
GLchan (*Bspec)[4] = (GLchan (*)[4]) store->LitSecondary[1].Ptr;
#endif
const GLuint nr = VB->Count;
const GLuint *flags = VB->Flag;
struct gl_material (*new_material)[2] = VB->Material;
const GLuint *new_material_mask = VB->MaterialMask;
(void) flags;
(void) nstride;
(void) vstride;
#ifdef TRACE
fprintf(stderr, "%s\n", __FUNCTION__ );
#endif
#if IDX & LIGHT_COLORMATERIAL
if (VB->ColorPtr[0]->Type != GL_FLOAT ||
VB->ColorPtr[0]->Size != 4)
import_color_material( ctx, stage );
CMcolor = (GLfloat *) VB->ColorPtr[0]->Ptr;
CMstride = VB->ColorPtr[0]->StrideB;
#endif
VB->ColorPtr[0] = &store->LitColor[0];
VB->SecondaryColorPtr[0] = &store->LitSecondary[0];
UNCLAMPED_FLOAT_TO_CHAN(sumA[0], ctx->Light.Material[0].Diffuse[3]);
#if IDX & LIGHT_TWOSIDE
VB->ColorPtr[1] = &store->LitColor[1];
VB->SecondaryColorPtr[1] = &store->LitSecondary[1];
UNCLAMPED_FLOAT_TO_CHAN(sumA[1], ctx->Light.Material[1].Diffuse[3]);
#endif
if (stage->changed_inputs == 0)
return;
for ( j=0 ;
j<nr ;
j++,STRIDE_F(vertex,VSTRIDE),STRIDE_F(normal,NSTRIDE),CMSTRIDE)
{
GLfloat sum[2][3], spec[2][3];
struct gl_light *light;
if ( CHECK_COLOR_MATERIAL(j) )
_mesa_update_color_material( ctx, CMcolor );
if ( CHECK_MATERIAL(j) )
_mesa_update_material( ctx, new_material[j], new_material_mask[j] );
if ( CHECK_VALIDATE(j) ) {
TNL_CONTEXT(ctx)->Driver.NotifyMaterialChange( ctx );
UNCLAMPED_FLOAT_TO_CHAN(sumA[0], ctx->Light.Material[0].Diffuse[3]);
#if IDX & LIGHT_TWOSIDE
UNCLAMPED_FLOAT_TO_CHAN(sumA[1], ctx->Light.Material[1].Diffuse[3]);
#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]);
#endif
foreach (light, &ctx->Light.EnabledList) {
GLfloat n_dot_h;
GLfloat correction;
GLint side;
GLfloat contrib[3];
GLfloat attenuation;
GLfloat VP[3];
GLfloat n_dot_VP;
GLfloat *h;
if (!(light->_Flags & LIGHT_POSITIONAL)) {
COPY_3V(VP, light->_VP_inf_norm);
attenuation = light->_VP_inf_spot_attenuation;
}
else {
GLfloat d;
SUB_3V(VP, light->_Position, vertex);
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 *
light->QuadraticAttenuation));
if (light->_Flags & LIGHT_SPOT) {
GLfloat PV_dot_dir = - DOT3(VP, light->_NormDirection);
if (PV_dot_dir<light->_CosCutoff) {
continue;
}
else {
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)
continue;
n_dot_VP = DOT3( normal, VP );
if (n_dot_VP < 0.0F) {
ACC_SCALE_SCALAR_3V(sum[0], attenuation, light->_MatAmbient[0]);
#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]);
#endif
side = 0;
correction = 1;
}
COPY_3V(contrib, light->_MatAmbient[side]);
ACC_SCALE_SCALAR_3V(contrib, n_dot_VP, light->_MatDiffuse[side]);
ACC_SCALE_SCALAR_3V(sum[side], attenuation, contrib );
if (ctx->Light.Model.LocalViewer) {
GLfloat v[3];
COPY_3V(v, vertex);
NORMALIZE_3FV(v);
SUB_3V(VP, VP, v);
h = VP;
NORMALIZE_3FV(h);
}
else if (light->_Flags & LIGHT_POSITIONAL) {
h = VP;
ACC_3V(h, ctx->_EyeZDir);
NORMALIZE_3FV(h);
}
else {
h = light->_h_inf_norm;
}
n_dot_h = correction * DOT3(normal, h);
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 );
if (spec_coef > 1.0e-10) {
spec_coef *= attenuation;
ACC_SCALE_SCALAR_3V( spec[side], spec_coef,
light->_MatSpecular[side]);
}
}
}
UNCLAMPED_FLOAT_TO_RGB_CHAN( Fcolor[j], sum[0] );
UNCLAMPED_FLOAT_TO_RGB_CHAN( 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];
#endif
}
}
static void TAG(light_rgba)( GLcontext *ctx,
struct vertex_buffer *VB,
struct gl_pipeline_stage *stage,
GLvector4f *input )
{
struct light_stage_data *store = LIGHT_STAGE_DATA(stage);
GLuint j;
GLfloat (*base)[3] = ctx->Light._BaseColor;
GLchan sumA[2];
const GLuint vstride = input->stride;
const GLfloat *vertex = (GLfloat *) input->data;
const GLuint nstride = VB->NormalPtr->stride;
const GLfloat *normal = (GLfloat *)VB->NormalPtr->data;
GLfloat *CMcolor;
#if IDX & LIGHT_COLORMATERIAL
GLuint CMstride;
#endif
GLchan (*Fcolor)[4] = (GLchan (*)[4]) store->LitColor[0].Ptr;
#if IDX & LIGHT_TWOSIDE
GLchan (*Bcolor)[4] = (GLchan (*)[4]) store->LitColor[1].Ptr;
#endif
const GLuint *flags = VB->Flag;
struct gl_material (*new_material)[2] = VB->Material;
const GLuint *new_material_mask = VB->MaterialMask;
const GLuint nr = VB->Count;
#ifdef TRACE
fprintf(stderr, "%s\n", __FUNCTION__ );
#endif
(void) flags;
(void) nstride;
(void) vstride;
#if IDX & LIGHT_COLORMATERIAL
if (VB->ColorPtr[0]->Type != GL_FLOAT ||
VB->ColorPtr[0]->Size != 4)
import_color_material( ctx, stage );
CMcolor = (GLfloat *)VB->ColorPtr[0]->Ptr;
CMstride = VB->ColorPtr[0]->StrideB;
#endif
VB->ColorPtr[0] = &store->LitColor[0];
UNCLAMPED_FLOAT_TO_CHAN(sumA[0], ctx->Light.Material[0].Diffuse[3]);
#if IDX & LIGHT_TWOSIDE
VB->ColorPtr[1] = &store->LitColor[1];
UNCLAMPED_FLOAT_TO_CHAN(sumA[1], ctx->Light.Material[1].Diffuse[3]);
#endif
if (stage->changed_inputs == 0)
return;
for ( j=0 ;
j<nr ;
j++,STRIDE_F(vertex,VSTRIDE), STRIDE_F(normal,NSTRIDE),CMSTRIDE)
{
GLfloat sum[2][3];
struct gl_light *light;
if ( CHECK_COLOR_MATERIAL(j) )
_mesa_update_color_material( ctx, CMcolor );
if ( CHECK_MATERIAL(j) )
_mesa_update_material( ctx, new_material[j], new_material_mask[j] );
if ( CHECK_VALIDATE(j) ) {
TNL_CONTEXT(ctx)->Driver.NotifyMaterialChange( ctx );
UNCLAMPED_FLOAT_TO_CHAN(sumA[0], ctx->Light.Material[0].Diffuse[3]);
#if IDX & LIGHT_TWOSIDE
UNCLAMPED_FLOAT_TO_CHAN(sumA[1], ctx->Light.Material[1].Diffuse[3]);
#endif
}
COPY_3V(sum[0], base[0]);
#if IDX & LIGHT_TWOSIDE
COPY_3V(sum[1], base[1]);
#endif
foreach (light, &ctx->Light.EnabledList) {
GLfloat n_dot_h;
GLfloat correction;
GLint side;
GLfloat contrib[3];
GLfloat attenuation = 1.0;
GLfloat VP[3];
GLfloat n_dot_VP;
GLfloat *h;
if (!(light->_Flags & LIGHT_POSITIONAL)) {
COPY_3V(VP, light->_VP_inf_norm);
attenuation = light->_VP_inf_spot_attenuation;
}
else {
GLfloat d;
SUB_3V(VP, light->_Position, vertex);
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 *
light->QuadraticAttenuation));
if (light->_Flags & LIGHT_SPOT) {
GLfloat PV_dot_dir = - DOT3(VP, light->_NormDirection);
if (PV_dot_dir<light->_CosCutoff) {
continue;
}
else {
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)
continue;
n_dot_VP = DOT3( normal, VP );
if (n_dot_VP < 0.0F) {
ACC_SCALE_SCALAR_3V(sum[0], attenuation, light->_MatAmbient[0]);
#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]);
#endif
side = 0;
correction = 1;
}
COPY_3V(contrib, light->_MatAmbient[side]);
ACC_SCALE_SCALAR_3V(contrib, n_dot_VP, light->_MatDiffuse[side]);
{
if (ctx->Light.Model.LocalViewer) {
GLfloat v[3];
COPY_3V(v, vertex);
NORMALIZE_3FV(v);
SUB_3V(VP, VP, v);
h = VP;
NORMALIZE_3FV(h);
}
else if (light->_Flags & LIGHT_POSITIONAL) {
h = VP;
ACC_3V(h, ctx->_EyeZDir);
NORMALIZE_3FV(h);
}
else {
h = light->_h_inf_norm;
}
n_dot_h = correction * DOT3(normal, h);
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,
light->_MatSpecular[side]);
}
}
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];
#endif
}
}
static void TAG(light_fast_rgba_single)( GLcontext *ctx,
struct vertex_buffer *VB,
struct gl_pipeline_stage *stage,
GLvector4f *input )
{
struct light_stage_data *store = LIGHT_STAGE_DATA(stage);
const GLuint nstride = VB->NormalPtr->stride;
const GLfloat *normal = (GLfloat *)VB->NormalPtr->data;
GLfloat *CMcolor;
#if IDX & LIGHT_COLORMATERIAL
GLuint CMstride;
#endif
GLchan (*Fcolor)[4] = (GLchan (*)[4]) store->LitColor[0].Ptr;
#if IDX & LIGHT_TWOSIDE
GLchan (*Bcolor)[4] = (GLchan (*)[4]) store->LitColor[1].Ptr;
#endif
const struct gl_light *light = ctx->Light.EnabledList.next;
const GLuint *flags = VB->Flag;
GLchan basechan[2][4];
GLuint j = 0;
struct gl_material (*new_material)[2] = VB->Material;
const GLuint *new_material_mask = VB->MaterialMask;
GLfloat base[2][3];
const GLuint nr = VB->Count;
#ifdef TRACE
fprintf(stderr, "%s\n", __FUNCTION__ );
#endif
(void) input;
(void) flags;
(void) nr;
(void) nstride;
#if IDX & LIGHT_COLORMATERIAL
if (VB->ColorPtr[0]->Type != GL_FLOAT ||
VB->ColorPtr[0]->Size != 4)
import_color_material( ctx, stage );
CMcolor = (GLfloat *)VB->ColorPtr[0]->Ptr;
CMstride = VB->ColorPtr[0]->StrideB;
#endif
VB->ColorPtr[0] = &store->LitColor[0];
#if IDX & LIGHT_TWOSIDE
VB->ColorPtr[1] = &store->LitColor[1];
#endif
if (stage->changed_inputs == 0)
return;
do {
if ( CHECK_COLOR_MATERIAL(j) ) {
_mesa_update_color_material( ctx, CMcolor );
}
if ( CHECK_MATERIAL(j) )
_mesa_update_material( ctx, new_material[j], new_material_mask[j] );
if ( CHECK_VALIDATE(j) )
TNL_CONTEXT(ctx)->Driver.NotifyMaterialChange( ctx );
COPY_3V(base[0], light->_MatAmbient[0]);
ACC_3V(base[0], ctx->Light._BaseColor[0] );
UNCLAMPED_FLOAT_TO_RGB_CHAN( basechan[0], base[0] );
UNCLAMPED_FLOAT_TO_CHAN(basechan[0][3],
ctx->Light.Material[0].Diffuse[3]);
#if IDX & LIGHT_TWOSIDE
COPY_3V(base[1], light->_MatAmbient[1]);
ACC_3V(base[1], ctx->Light._BaseColor[1]);
UNCLAMPED_FLOAT_TO_RGB_CHAN( basechan[1], base[1]);
UNCLAMPED_FLOAT_TO_CHAN(basechan[1][3],
ctx->Light.Material[1].Diffuse[3]);
#endif
do {
GLfloat 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]);
}
UNCLAMPED_FLOAT_TO_RGB_CHAN(Bcolor[j], sum );
Bcolor[j][3] = basechan[1][3];
#endif
COPY_CHAN4(Fcolor[j], basechan[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 );
Fcolor[j][3] = basechan[0][3];
#if IDX & LIGHT_TWOSIDE
COPY_CHAN4(Bcolor[j], basechan[1]);
#endif
}
j++;
CMSTRIDE;
STRIDE_F(normal, NSTRIDE);
} while (DO_ANOTHER_NORMAL(j));
for ( ; REUSE_LIGHT_RESULTS(j) ; j++, CMSTRIDE, STRIDE_F(normal,NSTRIDE))
{
COPY_CHAN4(Fcolor[j], Fcolor[j-1]);
#if IDX & LIGHT_TWOSIDE
COPY_CHAN4(Bcolor[j], Bcolor[j-1]);
#endif
}
} while (!CHECK_END_VB(j));
}
static void TAG(light_fast_rgba)( GLcontext *ctx,
struct vertex_buffer *VB,
struct gl_pipeline_stage *stage,
GLvector4f *input )
{
struct light_stage_data *store = LIGHT_STAGE_DATA(stage);
GLchan sumA[2];
const GLuint nstride = VB->NormalPtr->stride;
const GLfloat *normal = (GLfloat *)VB->NormalPtr->data;
GLfloat *CMcolor;
#if IDX & LIGHT_COLORMATERIAL
GLuint CMstride;
#endif
GLchan (*Fcolor)[4] = (GLchan (*)[4]) store->LitColor[0].Ptr;
#if IDX & LIGHT_TWOSIDE
GLchan (*Bcolor)[4] = (GLchan (*)[4]) store->LitColor[1].Ptr;
#endif
const GLuint *flags = VB->Flag;
GLuint j = 0;
struct gl_material (*new_material)[2] = VB->Material;
GLuint *new_material_mask = VB->MaterialMask;
const GLuint nr = VB->Count;
const struct gl_light *light;
#ifdef TRACE
fprintf(stderr, "%s\n", __FUNCTION__ );
#endif
(void) flags;
(void) input;
(void) nr;
(void) nstride;
UNCLAMPED_FLOAT_TO_CHAN(sumA[0], ctx->Light.Material[0].Diffuse[3]);
UNCLAMPED_FLOAT_TO_CHAN(sumA[1], ctx->Light.Material[1].Diffuse[3]);
#if IDX & LIGHT_COLORMATERIAL
if (VB->ColorPtr[0]->Type != GL_FLOAT ||
VB->ColorPtr[0]->Size != 4)
import_color_material( ctx, stage );
CMcolor = (GLfloat *)VB->ColorPtr[0]->Ptr;
CMstride = VB->ColorPtr[0]->StrideB;
#endif
VB->ColorPtr[0] = &store->LitColor[0];
#if IDX & LIGHT_TWOSIDE
VB->ColorPtr[1] = &store->LitColor[1];
#endif
if (stage->changed_inputs == 0)
return;
do {
do {
GLfloat sum[2][3];
if ( CHECK_COLOR_MATERIAL(j) )
_mesa_update_color_material( ctx, CMcolor );
if ( CHECK_MATERIAL(j) )
_mesa_update_material( ctx, new_material[j], new_material_mask[j] );
if ( CHECK_VALIDATE(j) ) {
TNL_CONTEXT(ctx)->Driver.NotifyMaterialChange( ctx );
UNCLAMPED_FLOAT_TO_CHAN(sumA[0], ctx->Light.Material[0].Diffuse[3]);
#if IDX & LIGHT_TWOSIDE
UNCLAMPED_FLOAT_TO_CHAN(sumA[1], ctx->Light.Material[1].Diffuse[3]);
#endif
}
COPY_3V(sum[0], ctx->Light._BaseColor[0]);
#if IDX & LIGHT_TWOSIDE
COPY_3V(sum[1], ctx->Light._BaseColor[1]);
#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]);
#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]);
}
}
#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]);
}
}
#endif
}
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];
#endif
j++;
CMSTRIDE;
STRIDE_F(normal, NSTRIDE);
} while (DO_ANOTHER_NORMAL(j));
for ( ; REUSE_LIGHT_RESULTS(j) ; j++, CMSTRIDE, STRIDE_F(normal, NSTRIDE))
{
COPY_CHAN4(Fcolor[j], Fcolor[j-1]);
#if IDX & LIGHT_TWOSIDE
COPY_CHAN4(Bcolor[j], Bcolor[j-1]);
#endif
}
} while (!CHECK_END_VB(j));
}
static void TAG(light_ci)( GLcontext *ctx,
struct vertex_buffer *VB,
struct gl_pipeline_stage *stage,
GLvector4f *input )
{
struct light_stage_data *store = LIGHT_STAGE_DATA(stage);
GLuint j;
const GLuint vstride = input->stride;
const GLfloat *vertex = (GLfloat *) input->data;
const GLuint nstride = VB->NormalPtr->stride;
const GLfloat *normal = (GLfloat *)VB->NormalPtr->data;
GLfloat *CMcolor;
#if IDX & LIGHT_COLORMATERIAL
GLuint CMstride;
#endif
const GLuint *flags = VB->Flag;
GLuint *indexResult[2];
struct gl_material (*new_material)[2] = VB->Material;
GLuint *new_material_mask = VB->MaterialMask;
const GLuint nr = VB->Count;
#ifdef TRACE
fprintf(stderr, "%s\n", __FUNCTION__ );
#endif
(void) flags;
(void) nstride;
(void) vstride;
VB->IndexPtr[0] = &store->LitIndex[0];
#if IDX & LIGHT_TWOSIDE
VB->IndexPtr[1] = &store->LitIndex[1];
#endif
if (stage->changed_inputs == 0)
return;
indexResult[0] = VB->IndexPtr[0]->data;
#if IDX & LIGHT_TWOSIDE
indexResult[1] = VB->IndexPtr[1]->data;
#endif
#if IDX & LIGHT_COLORMATERIAL
if (VB->ColorPtr[0]->Type != GL_FLOAT ||
VB->ColorPtr[0]->Size != 4)
import_color_material( ctx, stage );
CMcolor = (GLfloat *)VB->ColorPtr[0]->Ptr;
CMstride = VB->ColorPtr[0]->StrideB;
#endif
for ( j=0 ;
j<nr ;
j++,STRIDE_F(vertex,VSTRIDE),STRIDE_F(normal, NSTRIDE), CMSTRIDE)
{
GLfloat diffuse[2], specular[2];
GLuint side = 0;
struct gl_light *light;
if ( CHECK_COLOR_MATERIAL(j) )
_mesa_update_color_material( ctx, CMcolor );
if ( CHECK_MATERIAL(j) )
_mesa_update_material( ctx, new_material[j], new_material_mask[j] );
if ( CHECK_VALIDATE(j) )
TNL_CONTEXT(ctx)->Driver.NotifyMaterialChange( ctx );
diffuse[0] = specular[0] = 0.0F;
#if IDX & LIGHT_TWOSIDE
diffuse[1] = specular[1] = 0.0F;
#endif
foreach (light, &ctx->Light.EnabledList) {
GLfloat attenuation = 1.0F;
GLfloat VP[3];
GLfloat n_dot_VP;
GLfloat *h, n_dot_h, correction = 1.0;
if (!(light->_Flags & LIGHT_POSITIONAL)) {
COPY_3V(VP, light->_VP_inf_norm);
}
else {
GLfloat d;
SUB_3V(VP, light->_Position, vertex);
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 *
light->QuadraticAttenuation));
if (light->_Flags & LIGHT_SPOT) {
GLfloat PV_dot_dir = - DOT3(VP, light->_NormDirection);
if (PV_dot_dir < light->_CosCutoff) {
continue;
}
else {
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)
continue;
n_dot_VP = DOT3( normal, VP );
if (n_dot_VP < 0.0F) {
#if IDX & LIGHT_TWOSIDE
side = 1;
correction = -1;
n_dot_VP = -n_dot_VP;
#else
continue;
#endif
}
diffuse[side] += n_dot_VP * light->_dli * attenuation;
if (ctx->Light.Model.LocalViewer) {
GLfloat v[3];
COPY_3V(v, vertex);
NORMALIZE_3FV(v);
SUB_3V(VP, VP, v);
h = VP;
NORMALIZE_3FV(h);
}
else if (light->_Flags & LIGHT_POSITIONAL) {
h = VP;
NORMALIZE_3FV(h);
}
else {
h = light->_h_inf_norm;
}
n_dot_h = correction * DOT3(normal, h);
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);
specular[side] += spec_coef * light->_sli * attenuation;
}
}
for (side = 0 ; side < NR_SIDES ; side++) {
struct gl_material *mat = &ctx->Light.Material[side];
GLfloat index;
if (specular[side] > 1.0F) {
index = mat->SpecularIndex;
}
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;
}
}
indexResult[side][j] = (GLuint) (GLint) index;
}
}
}
static void TAG(init_light_tab)( void )
{
_tnl_light_tab[IDX] = TAG(light_rgba);
_tnl_light_fast_tab[IDX] = TAG(light_fast_rgba);
_tnl_light_fast_single_tab[IDX] = TAG(light_fast_rgba_single);
_tnl_light_spec_tab[IDX] = TAG(light_rgba_spec);
_tnl_light_ci_tab[IDX] = TAG(light_ci);
}
#undef TAG
#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