_mesa_light(struct gl_context *ctx, GLuint lnum, GLenum pname, const GLfloat *params);
-/* Lerp between adjacent values in the f(x) lookup table, giving a
- * continuous function, with adequeate overall accuracy. (Though
- * still pretty good compared to a straight lookup).
- * Result should be a GLfloat.
+/*
+ * Compute dp ^ SpecularExponent.
+ * Lerp between adjacent values in the f(x) lookup table, giving a
+ * continuous function, with adequate overall accuracy. (Though still
+ * pretty good compared to a straight lookup).
*/
-#define GET_SHINE_TAB_ENTRY( table, dp, result ) \
-do { \
- struct gl_shine_tab *_tab = table; \
- float f = (dp * (SHINE_TABLE_SIZE-1)); \
- int k = (int) f; \
- if (k < 0 /* gcc may cast an overflow float value to negative int value*/ \
- || k > SHINE_TABLE_SIZE-2) \
- result = (GLfloat) pow( dp, _tab->shininess ); \
- else \
- result = _tab->tab[k] + (f-k)*(_tab->tab[k+1]-_tab->tab[k]); \
-} while (0)
+static inline GLfloat
+_mesa_lookup_shininess(const struct gl_context *ctx, GLuint face, GLfloat dp)
+{
+ const struct gl_shine_tab *tab = ctx->_ShineTable[face];
+ float f = dp * (SHINE_TABLE_SIZE - 1);
+ int k = (int) f;
+ if (k < 0 /* gcc may cast an overflow float value to negative int value */
+ || k > SHINE_TABLE_SIZE - 2)
+ return powf(dp, tab->shininess);
+ else
+ return tab->tab[k] + (f - k) * (tab->tab[k+1] - tab->tab[k]);
+}
extern GLuint _mesa_material_bitmask( struct gl_context *ctx,
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 );
-
+ GLfloat spec_coef = _mesa_lookup_shininess(ctx, side, n_dot_h);
if (spec_coef > 1.0e-10) {
spec_coef *= attenuation;
ACC_SCALE_SCALAR_3V( spec[side], spec_coef,
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 = _mesa_lookup_shininess(ctx, side, n_dot_h);
ACC_SCALE_SCALAR_3V( contrib, spec_coef,
light->_MatSpecular[side]);
}
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 = _mesa_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 = _mesa_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];
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 = _mesa_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 = _mesa_lookup_shininess(ctx, 1, n_dot_h);
ACC_SCALE_SCALAR_3V( sum[1], spec, light->_MatSpecular[1]);
}
}