/*
* Mesa 3-D graphics library
- * Version: 5.1
*
* Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
*
* 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
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
*
*
* Authors:
- * Brian Paul
- * Keith Whitwell <keith@tungstengraphics.com>
+ * Brian Paul Keith Whitwell <keithw@vmware.com>
*/
const GLuint nr = VB->Count;
#ifdef TRACE
- fprintf(stderr, "%s\n", __FUNCTION__ );
+ fprintf(stderr, "%s\n", __func__ );
#endif
VB->AttribPtr[_TNL_ATTRIB_COLOR0] = &store->LitColor[0];
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;
+ GLbitfield mask;
#if IDX & LIGHT_MATERIAL
update_materials( ctx, store );
#endif
/* Add contribution from each enabled light source */
- foreach (light, &ctx->Light.EnabledList) {
+ mask = ctx->Light._EnabledLights;
+ while (mask) {
+ const int l = u_bit_scan(&mask);
+ struct gl_light *light = &ctx->Light.Light[l];
GLfloat n_dot_h;
GLfloat correction;
GLint side;
GLfloat contrib[3];
GLfloat attenuation;
- GLfloat VP[3]; /* unit vector from vertex to light */
+ GLfloat VP[3]; /* unit vector from vertex to light */
GLfloat n_dot_VP; /* n dot VP */
GLfloat *h;
d = (GLfloat) LEN_3FV( VP );
- if (d > 1e-6) {
+ if (d > 1e-6F) {
GLfloat invd = 1.0F / d;
SELF_SCALE_SCALAR_3V(VP, invd);
}
continue; /* this light makes no contribution */
}
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]);
+ GLfloat spot = powf(PV_dot_dir, light->SpotExponent);
attenuation *= spot;
}
}
}
- if (attenuation < 1e-3)
+ if (attenuation < 1e-3F)
continue; /* this light makes no contribution */
/* Compute dot product or normal and vector from V to light pos */
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) {
+ GLfloat spec_coef = lookup_shininess(ctx, side, n_dot_h);
+ if (spec_coef > 1.0e-10F) {
spec_coef *= attenuation;
ACC_SCALE_SCALAR_3V( spec[side], spec_coef,
light->_MatSpecular[side]);
const GLuint nr = VB->Count;
#ifdef TRACE
- fprintf(stderr, "%s\n", __FUNCTION__ );
+ fprintf(stderr, "%s\n", __func__ );
#endif
VB->AttribPtr[_TNL_ATTRIB_COLOR0] = &store->LitColor[0];
for (j = 0; j < nr; j++,STRIDE_F(vertex,vstride),STRIDE_F(normal,nstride)) {
GLfloat sum[2][3];
- struct gl_light *light;
+ GLbitfield mask;
#if IDX & LIGHT_MATERIAL
update_materials( ctx, store );
#endif
/* Add contribution from each enabled light source */
- foreach (light, &ctx->Light.EnabledList) {
-
+ mask = ctx->Light._EnabledLights;
+ while (mask) {
+ const int l = u_bit_scan(&mask);
+ struct gl_light *light = &ctx->Light.Light[l];
GLfloat n_dot_h;
GLfloat correction;
GLint side;
GLfloat contrib[3];
- GLfloat attenuation = 1.0;
+ GLfloat attenuation;
GLfloat VP[3]; /* unit vector from vertex to light */
GLfloat n_dot_VP; /* n dot VP */
GLfloat *h;
else {
GLfloat d; /* distance from vertex to light */
-
SUB_3V(VP, light->_Position, vertex);
d = (GLfloat) LEN_3FV( VP );
- if ( d > 1e-6) {
+ if (d > 1e-6F) {
GLfloat invd = 1.0F / d;
SELF_SCALE_SCALAR_3V(VP, invd);
}
continue; /* this light makes no contribution */
}
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]);
+ GLfloat spot = powf(PV_dot_dir, light->SpotExponent);
attenuation *= spot;
}
}
}
- if (attenuation < 1e-3)
+ if (attenuation < 1e-3F)
continue; /* this light makes no contribution */
/* Compute dot product or normal and vector from V to light pos */
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 (n_dot_h > 0.0F) {
+ GLfloat spec_coef = lookup_shininess(ctx, side, n_dot_h);
ACC_SCALE_SCALAR_3V( contrib, spec_coef,
light->_MatSpecular[side]);
}
#if IDX & LIGHT_TWOSIDE
GLfloat (*Bcolor)[4] = (GLfloat (*)[4]) store->LitColor[1].data;
#endif
- const struct gl_light *light = ctx->Light.EnabledList.next;
+ const struct gl_light *light =
+ &ctx->Light.Light[ffs(ctx->Light._EnabledLights) - 1];
GLuint j = 0;
GLfloat base[2][4];
#if IDX & LIGHT_MATERIAL
#endif
#ifdef TRACE
- fprintf(stderr, "%s\n", __FUNCTION__ );
+ fprintf(stderr, "%s\n", __func__ );
#endif
(void) input; /* doesn't refer to Eye or Obj */
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 );
+ GLfloat spec = lookup_shininess(ctx, 1, n_dot_h);
ACC_SCALE_SCALAR_3V(sum, spec, light->_MatSpecular[1]);
}
COPY_3V(Bcolor[j], sum );
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 );
+ GLfloat spec = lookup_shininess(ctx, 0, n_dot_h);
ACC_SCALE_SCALAR_3V(sum, spec, light->_MatSpecular[0]);
-
}
COPY_3V(Fcolor[j], sum );
Fcolor[j][3] = base[0][3];
#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 );
+ fprintf(stderr, "%s %d\n", __func__, nr );
#endif
(void) input;
for (j = 0; j < nr; j++, STRIDE_F(normal,nstride)) {
GLfloat sum[2][3];
+ GLbitfield mask;
#if IDX & LIGHT_MATERIAL
update_materials( ctx, store );
COPY_3V(sum[1], ctx->Light._BaseColor[1]);
#endif
- foreach (light, &ctx->Light.EnabledList) {
+ mask = ctx->Light._EnabledLights;
+ while (mask) {
+ const int l = u_bit_scan(&mask);
+ const struct gl_light *light = &ctx->Light.Light[l];
GLfloat n_dot_h, n_dot_VP, spec;
ACC_3V(sum[0], light->_MatAmbient[0]);
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 );
+ spec = lookup_shininess(ctx, 0, n_dot_h);
ACC_SCALE_SCALAR_3V( sum[0], spec, light->_MatSpecular[0]);
}
}
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 );
+ spec = lookup_shininess(ctx, 1, n_dot_h);
ACC_SCALE_SCALAR_3V( sum[1], spec, light->_MatSpecular[1]);
}
}