summaryrefslogtreecommitdiffstats
path: root/src/mesa/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/api_noop.c58
-rw-r--r--src/mesa/main/attrib.c4
-rw-r--r--src/mesa/main/light.c421
-rw-r--r--src/mesa/main/light.h7
-rw-r--r--src/mesa/main/mtypes.h83
-rw-r--r--src/mesa/main/rastpos.c25
6 files changed, 213 insertions, 385 deletions
diff --git a/src/mesa/main/api_noop.c b/src/mesa/main/api_noop.c
index a1f689d6f95..bab333dca8a 100644
--- a/src/mesa/main/api_noop.c
+++ b/src/mesa/main/api_noop.c
@@ -98,56 +98,28 @@ void _mesa_noop_Normal3fv( const GLfloat *v )
void _mesa_noop_Materialfv( GLenum face, GLenum pname, const GLfloat *params )
{
GET_CURRENT_CONTEXT(ctx);
- struct gl_material mat[2];
+ GLint i, nr;
+ struct gl_material *mat = &ctx->Light.Material;
GLuint bitmask = _mesa_material_bitmask( ctx, face, pname, ~0,
"_mesa_noop_Materialfv" );
+
+ if (ctx->Light.ColorMaterialEnabled)
+ bitmask &= ~ctx->Light.ColorMaterialBitmask;
+
if (bitmask == 0)
return;
- if (bitmask & FRONT_AMBIENT_BIT) {
- COPY_4FV( mat[0].Ambient, params );
- }
- if (bitmask & BACK_AMBIENT_BIT) {
- COPY_4FV( mat[1].Ambient, params );
- }
- if (bitmask & FRONT_DIFFUSE_BIT) {
- COPY_4FV( mat[0].Diffuse, params );
- }
- if (bitmask & BACK_DIFFUSE_BIT) {
- COPY_4FV( mat[1].Diffuse, params );
- }
- if (bitmask & FRONT_SPECULAR_BIT) {
- COPY_4FV( mat[0].Specular, params );
- }
- if (bitmask & BACK_SPECULAR_BIT) {
- COPY_4FV( mat[1].Specular, params );
- }
- if (bitmask & FRONT_EMISSION_BIT) {
- COPY_4FV( mat[0].Emission, params );
- }
- if (bitmask & BACK_EMISSION_BIT) {
- COPY_4FV( mat[1].Emission, params );
- }
- if (bitmask & FRONT_SHININESS_BIT) {
- GLfloat shininess = CLAMP( params[0], 0.0F, ctx->Const.MaxShininess );
- mat[0].Shininess = shininess;
- }
- if (bitmask & BACK_SHININESS_BIT) {
- GLfloat shininess = CLAMP( params[0], 0.0F, ctx->Const.MaxShininess );
- mat[1].Shininess = shininess;
- }
- if (bitmask & FRONT_INDEXES_BIT) {
- mat[0].AmbientIndex = params[0];
- mat[0].DiffuseIndex = params[1];
- mat[0].SpecularIndex = params[2];
- }
- if (bitmask & BACK_INDEXES_BIT) {
- mat[1].AmbientIndex = params[0];
- mat[1].DiffuseIndex = params[1];
- mat[1].SpecularIndex = params[2];
+ switch (face) {
+ case GL_SHININESS: nr = 1; break;
+ case GL_COLOR_INDEXES: nr = 3; break;
+ default: nr = 4 ; break;
}
- _mesa_update_material( ctx, mat, bitmask );
+ for (i = 0 ; i < MAT_ATTRIB_MAX ; i++)
+ if (bitmask & (1<<i))
+ COPY_SZ_4V( mat->Attrib[i], nr, params );
+
+ _mesa_update_material( ctx, bitmask );
}
void _mesa_noop_Color4ub( GLubyte a, GLubyte b, GLubyte c, GLubyte d )
diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c
index 19cee76d5de..5299c5c1cdd 100644
--- a/src/mesa/main/attrib.c
+++ b/src/mesa/main/attrib.c
@@ -954,8 +954,8 @@ _mesa_PopAttrib(void)
_mesa_LightModelf(GL_LIGHT_MODEL_COLOR_CONTROL,
(GLfloat) light->Model.ColorControl);
/* materials */
- MEMCPY(ctx->Light.Material, light->Material,
- 2 * sizeof(struct gl_material));
+ MEMCPY(&ctx->Light.Material, &light->Material,
+ sizeof(struct gl_material));
/* shade model */
_mesa_ShadeModel(light->ShadeModel);
/* color material */
diff --git a/src/mesa/main/light.c b/src/mesa/main/light.c
index 046738882d3..c9e0fbd73a8 100644
--- a/src/mesa/main/light.c
+++ b/src/mesa/main/light.c
@@ -495,26 +495,26 @@ _mesa_material_bitmask( GLcontext *ctx, GLenum face, GLenum pname,
/* Make a bitmask indicating what material attribute(s) we're updating */
switch (pname) {
case GL_EMISSION:
- bitmask |= FRONT_EMISSION_BIT | BACK_EMISSION_BIT;
+ bitmask |= MAT_BIT_FRONT_EMISSION | MAT_BIT_BACK_EMISSION;
break;
case GL_AMBIENT:
- bitmask |= FRONT_AMBIENT_BIT | BACK_AMBIENT_BIT;
+ bitmask |= MAT_BIT_FRONT_AMBIENT | MAT_BIT_BACK_AMBIENT;
break;
case GL_DIFFUSE:
- bitmask |= FRONT_DIFFUSE_BIT | BACK_DIFFUSE_BIT;
+ bitmask |= MAT_BIT_FRONT_DIFFUSE | MAT_BIT_BACK_DIFFUSE;
break;
case GL_SPECULAR:
- bitmask |= FRONT_SPECULAR_BIT | BACK_SPECULAR_BIT;
+ bitmask |= MAT_BIT_FRONT_SPECULAR | MAT_BIT_BACK_SPECULAR;
break;
case GL_SHININESS:
- bitmask |= FRONT_SHININESS_BIT | BACK_SHININESS_BIT;
+ bitmask |= MAT_BIT_FRONT_SHININESS | MAT_BIT_BACK_SHININESS;
break;
case GL_AMBIENT_AND_DIFFUSE:
- bitmask |= FRONT_AMBIENT_BIT | BACK_AMBIENT_BIT;
- bitmask |= FRONT_DIFFUSE_BIT | BACK_DIFFUSE_BIT;
+ bitmask |= MAT_BIT_FRONT_AMBIENT | MAT_BIT_BACK_AMBIENT;
+ bitmask |= MAT_BIT_FRONT_DIFFUSE | MAT_BIT_BACK_DIFFUSE;
break;
case GL_COLOR_INDEXES:
- bitmask |= FRONT_INDEXES_BIT | BACK_INDEXES_BIT;
+ bitmask |= MAT_BIT_FRONT_INDEXES | MAT_BIT_BACK_INDEXES;
break;
default:
_mesa_error( ctx, GL_INVALID_ENUM, where );
@@ -541,74 +541,28 @@ _mesa_material_bitmask( GLcontext *ctx, GLenum face, GLenum pname,
}
-/* Perform a straight copy between pairs of materials.
+
+/* Perform a straight copy between materials.
*/
-void _mesa_copy_material_pairs( struct gl_material dst[2],
- const struct gl_material src[2],
- GLuint bitmask )
+void _mesa_copy_materials( struct gl_material *dst,
+ const struct gl_material *src,
+ GLuint bitmask )
{
- if (bitmask & FRONT_EMISSION_BIT) {
- COPY_4FV( dst[0].Emission, src[0].Emission );
- }
- if (bitmask & BACK_EMISSION_BIT) {
- COPY_4FV( dst[1].Emission, src[1].Emission );
- }
- if (bitmask & FRONT_AMBIENT_BIT) {
- COPY_4FV( dst[0].Ambient, src[0].Ambient );
- }
- if (bitmask & BACK_AMBIENT_BIT) {
- COPY_4FV( dst[1].Ambient, src[1].Ambient );
- }
- if (bitmask & FRONT_DIFFUSE_BIT) {
- COPY_4FV( dst[0].Diffuse, src[0].Diffuse );
- }
- if (bitmask & BACK_DIFFUSE_BIT) {
- COPY_4FV( dst[1].Diffuse, src[1].Diffuse );
- }
- if (bitmask & FRONT_SPECULAR_BIT) {
- COPY_4FV( dst[0].Specular, src[0].Specular );
- }
- if (bitmask & BACK_SPECULAR_BIT) {
- COPY_4FV( dst[1].Specular, src[1].Specular );
- }
- if (bitmask & FRONT_SHININESS_BIT) {
- dst[0].Shininess = src[0].Shininess;
- }
- if (bitmask & BACK_SHININESS_BIT) {
- dst[1].Shininess = src[1].Shininess;
- }
- if (bitmask & FRONT_INDEXES_BIT) {
- dst[0].AmbientIndex = src[0].AmbientIndex;
- dst[0].DiffuseIndex = src[0].DiffuseIndex;
- dst[0].SpecularIndex = src[0].SpecularIndex;
- }
- if (bitmask & BACK_INDEXES_BIT) {
- dst[1].AmbientIndex = src[1].AmbientIndex;
- dst[1].DiffuseIndex = src[1].DiffuseIndex;
- dst[1].SpecularIndex = src[1].SpecularIndex;
- }
+ int i;
+
+ for (i = 0 ; i < MAT_ATTRIB_MAX ; i++)
+ if (bitmask & (1<<i))
+ COPY_4FV( dst->Attrib[i], src->Attrib[i] );
}
-/*
- * Check if the global material has to be updated with info that was
- * associated with a vertex via glMaterial.
- * This function is used when any material values get changed between
- * glBegin/glEnd either by calling glMaterial() or by calling glColor()
- * when GL_COLOR_MATERIAL is enabled.
- *
- * src[0] is front material, src[1] is back material
- *
- * Additionally keeps the precomputed lighting state uptodate.
+
+/* Update derived values following a change in ctx->Light.Material
*/
-void _mesa_update_material( GLcontext *ctx,
- const struct gl_material src[2],
- GLuint bitmask )
+void _mesa_update_material( GLcontext *ctx, GLuint bitmask )
{
struct gl_light *light, *list = &ctx->Light.EnabledList;
-
- if (ctx->Light.ColorMaterialEnabled)
- bitmask &= ~ctx->Light.ColorMaterialBitmask;
+ GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
if (MESA_VERBOSE&VERBOSE_IMMEDIATE)
_mesa_debug(ctx, "_mesa_update_material, mask 0x%x\n", bitmask);
@@ -616,117 +570,74 @@ void _mesa_update_material( GLcontext *ctx,
if (!bitmask)
return;
- /* update material emission */
- if (bitmask & FRONT_EMISSION_BIT) {
- struct gl_material *mat = &ctx->Light.Material[0];
- COPY_4FV( mat->Emission, src[0].Emission );
- }
- if (bitmask & BACK_EMISSION_BIT) {
- struct gl_material *mat = &ctx->Light.Material[1];
- COPY_4FV( mat->Emission, src[1].Emission );
- }
-
/* update material ambience */
- if (bitmask & FRONT_AMBIENT_BIT) {
- struct gl_material *mat = &ctx->Light.Material[0];
- COPY_4FV( mat->Ambient, src[0].Ambient );
+ if (bitmask & MAT_BIT_FRONT_AMBIENT) {
foreach (light, list) {
- SCALE_3V( light->_MatAmbient[0], light->Ambient, src[0].Ambient);
+ SCALE_3V( light->_MatAmbient[0], light->Ambient,
+ mat[MAT_ATTRIB_FRONT_AMBIENT]);
}
}
- if (bitmask & BACK_AMBIENT_BIT) {
- struct gl_material *mat = &ctx->Light.Material[1];
- COPY_4FV( mat->Ambient, src[1].Ambient );
+
+ if (bitmask & MAT_BIT_BACK_AMBIENT) {
foreach (light, list) {
- SCALE_3V( light->_MatAmbient[1], light->Ambient, src[1].Ambient);
+ SCALE_3V( light->_MatAmbient[1], light->Ambient,
+ mat[MAT_ATTRIB_BACK_AMBIENT]);
}
}
/* update BaseColor = emission + scene's ambience * material's ambience */
- if (bitmask & (FRONT_EMISSION_BIT | FRONT_AMBIENT_BIT)) {
- struct gl_material *mat = &ctx->Light.Material[0];
- COPY_3V( ctx->Light._BaseColor[0], mat->Emission );
- ACC_SCALE_3V( ctx->Light._BaseColor[0], mat->Ambient,
+ if (bitmask & (MAT_BIT_FRONT_EMISSION | MAT_BIT_FRONT_AMBIENT)) {
+ COPY_3V( ctx->Light._BaseColor[0], mat[MAT_ATTRIB_FRONT_EMISSION] );
+ ACC_SCALE_3V( ctx->Light._BaseColor[0], mat[MAT_ATTRIB_FRONT_AMBIENT],
ctx->Light.Model.Ambient );
}
- if (bitmask & (BACK_EMISSION_BIT | BACK_AMBIENT_BIT)) {
- struct gl_material *mat = &ctx->Light.Material[1];
- COPY_3V( ctx->Light._BaseColor[1], mat->Emission );
- ACC_SCALE_3V( ctx->Light._BaseColor[1], mat->Ambient,
+
+ if (bitmask & (MAT_BIT_BACK_EMISSION | MAT_BIT_BACK_AMBIENT)) {
+ COPY_3V( ctx->Light._BaseColor[1], mat[MAT_ATTRIB_BACK_EMISSION] );
+ ACC_SCALE_3V( ctx->Light._BaseColor[1], mat[MAT_ATTRIB_BACK_AMBIENT],
ctx->Light.Model.Ambient );
}
/* update material diffuse values */
- if (bitmask & FRONT_DIFFUSE_BIT) {
- struct gl_material *mat = &ctx->Light.Material[0];
- COPY_4FV( mat->Diffuse, src[0].Diffuse );
+ if (bitmask & MAT_BIT_FRONT_DIFFUSE) {
foreach (light, list) {
- SCALE_3V( light->_MatDiffuse[0], light->Diffuse, mat->Diffuse );
+ SCALE_3V( light->_MatDiffuse[0], light->Diffuse,
+ mat[MAT_ATTRIB_FRONT_DIFFUSE] );
}
}
- if (bitmask & BACK_DIFFUSE_BIT) {
- struct gl_material *mat = &ctx->Light.Material[1];
- COPY_4FV( mat->Diffuse, src[1].Diffuse );
+
+ if (bitmask & MAT_BIT_BACK_DIFFUSE) {
foreach (light, list) {
- SCALE_3V( light->_MatDiffuse[1], light->Diffuse, mat->Diffuse );
+ SCALE_3V( light->_MatDiffuse[1], light->Diffuse,
+ mat[MAT_ATTRIB_BACK_DIFFUSE] );
}
}
/* update material specular values */
- if (bitmask & FRONT_SPECULAR_BIT) {
- struct gl_material *mat = &ctx->Light.Material[0];
- COPY_4FV( mat->Specular, src[0].Specular );
+ if (bitmask & MAT_BIT_FRONT_SPECULAR) {
foreach (light, list) {
- SCALE_3V( light->_MatSpecular[0], light->Specular, mat->Specular);
+ SCALE_3V( light->_MatSpecular[0], light->Specular,
+ mat[MAT_ATTRIB_FRONT_SPECULAR]);
}
}
- if (bitmask & BACK_SPECULAR_BIT) {
- struct gl_material *mat = &ctx->Light.Material[1];
- COPY_4FV( mat->Specular, src[1].Specular );
+
+ if (bitmask & MAT_BIT_BACK_SPECULAR) {
foreach (light, list) {
- SCALE_3V( light->_MatSpecular[1], light->Specular, mat->Specular);
+ SCALE_3V( light->_MatSpecular[1], light->Specular,
+ mat[MAT_ATTRIB_BACK_SPECULAR]);
}
}
- if (bitmask & FRONT_SHININESS_BIT) {
- ctx->Light.Material[0].Shininess = src[0].Shininess;
+ if (bitmask & MAT_BIT_FRONT_SHININESS) {
_mesa_invalidate_shine_table( ctx, 0 );
}
- if (bitmask & BACK_SHININESS_BIT) {
- ctx->Light.Material[1].Shininess = src[1].Shininess;
- _mesa_invalidate_shine_table( ctx, 1 );
- }
-
- if (bitmask & FRONT_INDEXES_BIT) {
- ctx->Light.Material[0].AmbientIndex = src[0].AmbientIndex;
- ctx->Light.Material[0].DiffuseIndex = src[0].DiffuseIndex;
- ctx->Light.Material[0].SpecularIndex = src[0].SpecularIndex;
- }
- if (bitmask & BACK_INDEXES_BIT) {
- ctx->Light.Material[1].AmbientIndex = src[1].AmbientIndex;
- ctx->Light.Material[1].DiffuseIndex = src[1].DiffuseIndex;
- ctx->Light.Material[1].SpecularIndex = src[1].SpecularIndex;
- }
- if (0) {
- struct gl_material *mat = &ctx->Light.Material[0];
- _mesa_debug(ctx, "update_mat emission : %f %f %f\n",
- mat->Emission[0], mat->Emission[1], mat->Emission[2]);
- _mesa_debug(ctx, "update_mat specular : %f %f %f\n",
- mat->Specular[0], mat->Specular[1], mat->Specular[2]);
- _mesa_debug(ctx, "update_mat diffuse : %f %f %f\n",
- mat->Diffuse[0], mat->Diffuse[1], mat->Diffuse[2]);
- _mesa_debug(ctx, "update_mat ambient : %f %f %f\n",
- mat->Ambient[0], mat->Ambient[1], mat->Ambient[2]);
+ if (bitmask & MAT_BIT_BACK_SHININESS) {
+ _mesa_invalidate_shine_table( ctx, 1 );
}
}
-
-
-
-
-
/*
* Update the current materials from the given rgba color
* according to the bitmask in ColorMaterialBitmask, which is
@@ -735,98 +646,15 @@ void _mesa_update_material( GLcontext *ctx,
void _mesa_update_color_material( GLcontext *ctx,
const GLfloat color[4] )
{
- struct gl_light *light, *list = &ctx->Light.EnabledList;
GLuint bitmask = ctx->Light.ColorMaterialBitmask;
+ struct gl_material *mat = &ctx->Light.Material;
+ int i;
- if (MESA_VERBOSE&VERBOSE_IMMEDIATE)
- _mesa_debug(ctx, "_mesa_update_color_material, mask 0x%x\n", bitmask);
-
- /* update emissive colors */
- if (bitmask & FRONT_EMISSION_BIT) {
- struct gl_material *mat = &ctx->Light.Material[0];
- COPY_4FV( mat->Emission, color );
- }
-
- if (bitmask & BACK_EMISSION_BIT) {
- struct gl_material *mat = &ctx->Light.Material[1];
- COPY_4FV( mat->Emission, color );
- }
-
- /* update light->_MatAmbient = light's ambient * material's ambient */
- if (bitmask & FRONT_AMBIENT_BIT) {
- struct gl_material *mat = &ctx->Light.Material[0];
- foreach (light, list) {
- SCALE_3V( light->_MatAmbient[0], light->Ambient, color);
- }
- COPY_4FV( mat->Ambient, color );
- }
-
- if (bitmask & BACK_AMBIENT_BIT) {
- struct gl_material *mat = &ctx->Light.Material[1];
- foreach (light, list) {
- SCALE_3V( light->_MatAmbient[1], light->Ambient, color);
- }
- COPY_4FV( mat->Ambient, color );
- }
-
- /* update BaseColor = emission + scene's ambience * material's ambience */
- if (bitmask & (FRONT_EMISSION_BIT | FRONT_AMBIENT_BIT)) {
- struct gl_material *mat = &ctx->Light.Material[0];
- COPY_3V( ctx->Light._BaseColor[0], mat->Emission );
- ACC_SCALE_3V( ctx->Light._BaseColor[0], mat->Ambient, ctx->Light.Model.Ambient );
- }
-
- if (bitmask & (BACK_EMISSION_BIT | BACK_AMBIENT_BIT)) {
- struct gl_material *mat = &ctx->Light.Material[1];
- COPY_3V( ctx->Light._BaseColor[1], mat->Emission );
- ACC_SCALE_3V( ctx->Light._BaseColor[1], mat->Ambient, ctx->Light.Model.Ambient );
- }
-
- /* update light->_MatDiffuse = light's diffuse * material's diffuse */
- if (bitmask & FRONT_DIFFUSE_BIT) {
- struct gl_material *mat = &ctx->Light.Material[0];
- COPY_4FV( mat->Diffuse, color );
- foreach (light, list) {
- SCALE_3V( light->_MatDiffuse[0], light->Diffuse, mat->Diffuse );
- }
- }
-
- if (bitmask & BACK_DIFFUSE_BIT) {
- struct gl_material *mat = &ctx->Light.Material[1];
- COPY_4FV( mat->Diffuse, color );
- foreach (light, list) {
- SCALE_3V( light->_MatDiffuse[1], light->Diffuse, mat->Diffuse );
- }
- }
-
- /* update light->_MatSpecular = light's specular * material's specular */
- if (bitmask & FRONT_SPECULAR_BIT) {
- struct gl_material *mat = &ctx->Light.Material[0];
- COPY_4FV( mat->Specular, color );
- foreach (light, list) {
- ACC_SCALE_3V( light->_MatSpecular[0], light->Specular, mat->Specular);
- }
- }
-
- if (bitmask & BACK_SPECULAR_BIT) {
- struct gl_material *mat = &ctx->Light.Material[1];
- COPY_4FV( mat->Specular, color );
- foreach (light, list) {
- ACC_SCALE_3V( light->_MatSpecular[1], light->Specular, mat->Specular);
- }
- }
+ for (i = 0 ; i < MAT_ATTRIB_MAX ; i++)
+ if (bitmask & (1<<i))
+ COPY_4FV( mat->Attrib[i], color );
- if (0) {
- struct gl_material *mat = &ctx->Light.Material[0];
- _mesa_debug(ctx, "update_color_mat emission : %f %f %f\n",
- mat->Emission[0], mat->Emission[1], mat->Emission[2]);
- _mesa_debug(ctx, "update_color_mat specular : %f %f %f\n",
- mat->Specular[0], mat->Specular[1], mat->Specular[2]);
- _mesa_debug(ctx, "update_color_mat diffuse : %f %f %f\n",
- mat->Diffuse[0], mat->Diffuse[1], mat->Diffuse[2]);
- _mesa_debug(ctx, "update_color_mat ambient : %f %f %f\n",
- mat->Ambient[0], mat->Ambient[1], mat->Ambient[2]);
- }
+ _mesa_update_material( ctx, bitmask );
}
@@ -837,10 +665,10 @@ _mesa_ColorMaterial( GLenum face, GLenum mode )
{
GET_CURRENT_CONTEXT(ctx);
GLuint bitmask;
- GLuint legal = (FRONT_EMISSION_BIT | BACK_EMISSION_BIT |
- FRONT_SPECULAR_BIT | BACK_SPECULAR_BIT |
- FRONT_DIFFUSE_BIT | BACK_DIFFUSE_BIT |
- FRONT_AMBIENT_BIT | BACK_AMBIENT_BIT);
+ GLuint legal = (MAT_BIT_FRONT_EMISSION | MAT_BIT_BACK_EMISSION |
+ MAT_BIT_FRONT_SPECULAR | MAT_BIT_BACK_SPECULAR |
+ MAT_BIT_FRONT_DIFFUSE | MAT_BIT_BACK_DIFFUSE |
+ MAT_BIT_FRONT_AMBIENT | MAT_BIT_BACK_AMBIENT);
ASSERT_OUTSIDE_BEGIN_END(ctx);
if (MESA_VERBOSE&VERBOSE_API)
@@ -878,6 +706,7 @@ _mesa_GetMaterialfv( GLenum face, GLenum pname, GLfloat *params )
{
GET_CURRENT_CONTEXT(ctx);
GLuint f;
+ GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* update materials */
if (face==GL_FRONT) {
@@ -890,26 +719,27 @@ _mesa_GetMaterialfv( GLenum face, GLenum pname, GLfloat *params )
_mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(face)" );
return;
}
+
switch (pname) {
case GL_AMBIENT:
- COPY_4FV( params, ctx->Light.Material[f].Ambient );
+ COPY_4FV( params, mat[MAT_ATTRIB_AMBIENT(f)] );
break;
case GL_DIFFUSE:
- COPY_4FV( params, ctx->Light.Material[f].Diffuse );
+ COPY_4FV( params, mat[MAT_ATTRIB_DIFFUSE(f)] );
break;
case GL_SPECULAR:
- COPY_4FV( params, ctx->Light.Material[f].Specular );
+ COPY_4FV( params, mat[MAT_ATTRIB_SPECULAR(f)] );
break;
case GL_EMISSION:
- COPY_4FV( params, ctx->Light.Material[f].Emission );
+ COPY_4FV( params, mat[MAT_ATTRIB_EMISSION(f)] );
break;
case GL_SHININESS:
- *params = ctx->Light.Material[f].Shininess;
+ *params = mat[MAT_ATTRIB_SHININESS(f)][0];
break;
case GL_COLOR_INDEXES:
- params[0] = ctx->Light.Material[f].AmbientIndex;
- params[1] = ctx->Light.Material[f].DiffuseIndex;
- params[2] = ctx->Light.Material[f].SpecularIndex;
+ params[0] = mat[MAT_ATTRIB_INDEXES(f)][0];
+ params[1] = mat[MAT_ATTRIB_INDEXES(f)][1];
+ params[2] = mat[MAT_ATTRIB_INDEXES(f)][2];
break;
default:
_mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(pname)" );
@@ -923,6 +753,7 @@ _mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params )
{
GET_CURRENT_CONTEXT(ctx);
GLuint f;
+ GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* update materials */
if (face==GL_FRONT) {
@@ -937,36 +768,36 @@ _mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params )
}
switch (pname) {
case GL_AMBIENT:
- params[0] = FLOAT_TO_INT( ctx->Light.Material[f].Ambient[0] );
- params[1] = FLOAT_TO_INT( ctx->Light.Material[f].Ambient[1] );
- params[2] = FLOAT_TO_INT( ctx->Light.Material[f].Ambient[2] );
- params[3] = FLOAT_TO_INT( ctx->Light.Material[f].Ambient[3] );
+ params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][0] );
+ params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][1] );
+ params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][2] );
+ params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_AMBIENT(f)][3] );
break;
case GL_DIFFUSE:
- params[0] = FLOAT_TO_INT( ctx->Light.Material[f].Diffuse[0] );
- params[1] = FLOAT_TO_INT( ctx->Light.Material[f].Diffuse[1] );
- params[2] = FLOAT_TO_INT( ctx->Light.Material[f].Diffuse[2] );
- params[3] = FLOAT_TO_INT( ctx->Light.Material[f].Diffuse[3] );
+ params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][0] );
+ params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][1] );
+ params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][2] );
+ params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_DIFFUSE(f)][3] );
break;
case GL_SPECULAR:
- params[0] = FLOAT_TO_INT( ctx->Light.Material[f].Specular[0] );
- params[1] = FLOAT_TO_INT( ctx->Light.Material[f].Specular[1] );
- params[2] = FLOAT_TO_INT( ctx->Light.Material[f].Specular[2] );
- params[3] = FLOAT_TO_INT( ctx->Light.Material[f].Specular[3] );
+ params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][0] );
+ params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][1] );
+ params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][2] );
+ params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_SPECULAR(f)][3] );
break;
case GL_EMISSION:
- params[0] = FLOAT_TO_INT( ctx->Light.Material[f].Emission[0] );
- params[1] = FLOAT_TO_INT( ctx->Light.Material[f].Emission[1] );
- params[2] = FLOAT_TO_INT( ctx->Light.Material[f].Emission[2] );
- params[3] = FLOAT_TO_INT( ctx->Light.Material[f].Emission[3] );
+ params[0] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][0] );
+ params[1] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][1] );
+ params[2] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][2] );
+ params[3] = FLOAT_TO_INT( mat[MAT_ATTRIB_EMISSION(f)][3] );
break;
case GL_SHININESS:
- *params = IROUND( ctx->Light.Material[f].Shininess );
+ *params = IROUND( mat[MAT_ATTRIB_SHININESS(f)][0] );
break;
case GL_COLOR_INDEXES:
- params[0] = IROUND( ctx->Light.Material[f].AmbientIndex );
- params[1] = IROUND( ctx->Light.Material[f].DiffuseIndex );
- params[2] = IROUND( ctx->Light.Material[f].SpecularIndex );
+ params[0] = IROUND( mat[MAT_ATTRIB_INDEXES(f)][0] );
+ params[1] = IROUND( mat[MAT_ATTRIB_INDEXES(f)][1] );
+ params[2] = IROUND( mat[MAT_ATTRIB_INDEXES(f)][2] );
break;
default:
_mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(pname)" );
@@ -1120,11 +951,11 @@ _mesa_validate_all_lighting_tables( GLcontext *ctx )
GLint i;
GLfloat shininess;
- shininess = ctx->Light.Material[0].Shininess;
+ shininess = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_SHININESS][0];
if (!ctx->_ShineTable[0] || ctx->_ShineTable[0]->shininess != shininess)
validate_shine_table( ctx, 0, shininess );
- shininess = ctx->Light.Material[1].Shininess;
+ shininess = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_SHININESS][0];
if (!ctx->_ShineTable[1] || ctx->_ShineTable[1]->shininess != shininess)
validate_shine_table( ctx, 1, shininess );
@@ -1180,26 +1011,22 @@ _mesa_update_lighting( GLcontext *ctx )
* are flushed, they will update the derived state at that time.
*/
if (ctx->Visual.rgbMode) {
- GLuint sides = ctx->Light.Model.TwoSide ? 2 : 1;
- GLuint side;
- for (side=0; side < sides; side++) {
- struct gl_material *mat = &ctx->Light.Material[side];
-
- COPY_3V(ctx->Light._BaseColor[side], mat->Emission);
- ACC_SCALE_3V(ctx->Light._BaseColor[side],
- ctx->Light.Model.Ambient,
- mat->Ambient);
- }
-
- foreach (light, &ctx->Light.EnabledList) {
- for (side=0; side< sides; side++) {
- const struct gl_material *mat = &ctx->Light.Material[side];
- SCALE_3V( light->_MatDiffuse[side], light->Diffuse, mat->Diffuse );
- SCALE_3V( light->_MatAmbient[side], light->Ambient, mat->Ambient );
- SCALE_3V( light->_MatSpecular[side], light->Specular,
- mat->Specular);
- }
- }
+ if (ctx->Light.Model.TwoSide)
+ _mesa_update_material( ctx,
+ MAT_BIT_FRONT_EMISSION |
+ MAT_BIT_FRONT_AMBIENT |
+ MAT_BIT_FRONT_DIFFUSE |
+ MAT_BIT_FRONT_SPECULAR |
+ MAT_BIT_BACK_EMISSION |
+ MAT_BIT_BACK_AMBIENT |
+ MAT_BIT_BACK_DIFFUSE |
+ MAT_BIT_BACK_SPECULAR);
+ else
+ _mesa_update_material( ctx,
+ MAT_BIT_FRONT_EMISSION |
+ MAT_BIT_FRONT_AMBIENT |
+ MAT_BIT_FRONT_DIFFUSE |
+ MAT_BIT_FRONT_SPECULAR);
}
else {
static const GLfloat ci[3] = { .30F, .59F, .11F };
@@ -1431,14 +1258,19 @@ init_lightmodel( struct gl_lightmodel *lm )
static void
init_material( struct gl_material *m )
{
- ASSIGN_4V( m->Ambient, 0.2F, 0.2F, 0.2F, 1.0F );
- ASSIGN_4V( m->Diffuse, 0.8F, 0.8F, 0.8F, 1.0F );
- ASSIGN_4V( m->Specular, 0.0F, 0.0F, 0.0F, 1.0F );
- ASSIGN_4V( m->Emission, 0.0F, 0.0F, 0.0F, 1.0F );
- m->Shininess = 0.0;
- m->AmbientIndex = 0;
- m->DiffuseIndex = 1;
- m->SpecularIndex = 1;
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_AMBIENT], 0.2F, 0.2F, 0.2F, 1.0F );
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_DIFFUSE], 0.8F, 0.8F, 0.8F, 1.0F );
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_SPECULAR], 0.0F, 0.0F, 0.0F, 1.0F );
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_EMISSION], 0.0F, 0.0F, 0.0F, 1.0F );
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_SHININESS], 0.0F, 0.0F, 0.0F, 0.0F );
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_FRONT_INDEXES], 0.0F, 1.0F, 1.0F, 0.0F );
+
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_AMBIENT], 0.2F, 0.2F, 0.2F, 1.0F );
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_DIFFUSE], 0.8F, 0.8F, 0.8F, 1.0F );
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_SPECULAR], 0.0F, 0.0F, 0.0F, 1.0F );
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_EMISSION], 0.0F, 0.0F, 0.0F, 1.0F );
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_SHININESS], 0.0F, 0.0F, 0.0F, 0.0F );
+ ASSIGN_4V( m->Attrib[MAT_ATTRIB_BACK_INDEXES], 0.0F, 1.0F, 1.0F, 0.0F );
}
@@ -1453,8 +1285,7 @@ void _mesa_init_lighting( GLcontext *ctx )
make_empty_list( &ctx->Light.EnabledList );
init_lightmodel( &ctx->Light.Model );
- init_material( &ctx->Light.Material[0] );
- init_material( &ctx->Light.Material[1] );
+ init_material( &ctx->Light.Material );
ctx->Light.ShadeModel = GL_SMOOTH;
ctx->Light.Enabled = GL_FALSE;
ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
diff --git a/src/mesa/main/light.h b/src/mesa/main/light.h
index 240a6317b71..1eb7f56985f 100644
--- a/src/mesa/main/light.h
+++ b/src/mesa/main/light.h
@@ -111,12 +111,11 @@ extern void _mesa_update_lighting( GLcontext *ctx );
extern void _mesa_update_tnl_spaces( GLcontext *ctx, GLuint new_state );
extern void _mesa_update_material( GLcontext *ctx,
- const struct gl_material src[2],
GLuint bitmask );
-extern void _mesa_copy_material_pairs( struct gl_material dst[2],
- const struct gl_material src[2],
- GLuint bitmask );
+extern void _mesa_copy_materials( struct gl_material *dst,
+ const struct gl_material *src,
+ GLuint bitmask );
extern void _mesa_update_color_material( GLcontext *ctx,
const GLfloat rgba[4] );
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 27b01eee08f..5c321d0d99a 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -233,26 +233,58 @@ struct gl_color_table {
* \name Bit flags used for updating material values.
*/
/*@{*/
-#define FRONT_AMBIENT_BIT 0x1
-#define BACK_AMBIENT_BIT 0x2
-#define FRONT_DIFFUSE_BIT 0x4
-#define BACK_DIFFUSE_BIT 0x8
-#define FRONT_SPECULAR_BIT 0x10
-#define BACK_SPECULAR_BIT 0x20
-#define FRONT_EMISSION_BIT 0x40
-#define BACK_EMISSION_BIT 0x80
-#define FRONT_SHININESS_BIT 0x100
-#define BACK_SHININESS_BIT 0x200
-#define FRONT_INDEXES_BIT 0x400
-#define BACK_INDEXES_BIT 0x800
-
-#define FRONT_MATERIAL_BITS (FRONT_EMISSION_BIT | FRONT_AMBIENT_BIT | \
- FRONT_DIFFUSE_BIT | FRONT_SPECULAR_BIT | \
- FRONT_SHININESS_BIT | FRONT_INDEXES_BIT)
-
-#define BACK_MATERIAL_BITS (BACK_EMISSION_BIT | BACK_AMBIENT_BIT | \
- BACK_DIFFUSE_BIT | BACK_SPECULAR_BIT | \
- BACK_SHININESS_BIT | BACK_INDEXES_BIT)
+#define MAT_ATTRIB_FRONT_AMBIENT 0
+#define MAT_ATTRIB_BACK_AMBIENT 1
+#define MAT_ATTRIB_FRONT_DIFFUSE 2
+#define MAT_ATTRIB_BACK_DIFFUSE 3
+#define MAT_ATTRIB_FRONT_SPECULAR 4
+#define MAT_ATTRIB_BACK_SPECULAR 5
+#define MAT_ATTRIB_FRONT_EMISSION 6
+#define MAT_ATTRIB_BACK_EMISSION 7
+#define MAT_ATTRIB_FRONT_SHININESS 8
+#define MAT_ATTRIB_BACK_SHININESS 9
+#define MAT_ATTRIB_FRONT_INDEXES 10
+#define MAT_ATTRIB_BACK_INDEXES 11
+#define MAT_ATTRIB_MAX 12
+
+#define MAT_ATTRIB_AMBIENT(f) (MAT_ATTRIB_FRONT_AMBIENT+(f))
+#define MAT_ATTRIB_DIFFUSE(f) (MAT_ATTRIB_FRONT_DIFFUSE+(f))
+#define MAT_ATTRIB_SPECULAR(f) (MAT_ATTRIB_FRONT_SPECULAR+(f))
+#define MAT_ATTRIB_EMISSION(f) (MAT_ATTRIB_FRONT_EMISSION+(f))
+#define MAT_ATTRIB_SHININESS(f)(MAT_ATTRIB_FRONT_SHININESS+(f))
+#define MAT_ATTRIB_INDEXES(f) (MAT_ATTRIB_FRONT_INDEXES+(f))
+
+#define MAT_INDEX_AMBIENT 0
+#define MAT_INDEX_DIFFUSE 1
+#define MAT_INDEX_SPECULAR 2
+
+#define MAT_BIT_FRONT_AMBIENT (1<<MAT_ATTRIB_FRONT_AMBIENT)
+#define MAT_BIT_BACK_AMBIENT (1<<MAT_ATTRIB_BACK_AMBIENT)
+#define MAT_BIT_FRONT_DIFFUSE (1<<MAT_ATTRIB_FRONT_DIFFUSE)
+#define MAT_BIT_BACK_DIFFUSE (1<<MAT_ATTRIB_BACK_DIFFUSE)
+#define MAT_BIT_FRONT_SPECULAR (1<<MAT_ATTRIB_FRONT_SPECULAR)
+#define MAT_BIT_BACK_SPECULAR (1<<MAT_ATTRIB_BACK_SPECULAR)
+#define MAT_BIT_FRONT_EMISSION (1<<MAT_ATTRIB_FRONT_EMISSION)
+#define MAT_BIT_BACK_EMISSION (1<<MAT_ATTRIB_BACK_EMISSION)
+#define MAT_BIT_FRONT_SHININESS (1<<MAT_ATTRIB_FRONT_SHININESS)
+#define MAT_BIT_BACK_SHININESS (1<<MAT_ATTRIB_BACK_SHININESS)
+#define MAT_BIT_FRONT_INDEXES (1<<MAT_ATTRIB_FRONT_INDEXES)
+#define MAT_BIT_BACK_INDEXES (1<<MAT_ATTRIB_BACK_INDEXES)
+
+
+#define FRONT_MATERIAL_BITS (MAT_BIT_FRONT_EMISSION | \
+ MAT_BIT_FRONT_AMBIENT | \
+ MAT_BIT_FRONT_DIFFUSE | \
+ MAT_BIT_FRONT_SPECULAR | \
+ MAT_BIT_FRONT_SHININESS | \
+ MAT_BIT_FRONT_INDEXES)
+
+#define BACK_MATERIAL_BITS (MAT_BIT_BACK_EMISSION | \
+ MAT_BIT_BACK_AMBIENT | \
+ MAT_BIT_BACK_DIFFUSE | \
+ MAT_BIT_BACK_SPECULAR | \
+ MAT_BIT_BACK_SHININESS | \
+ MAT_BIT_BACK_INDEXES)
#define ALL_MATERIAL_BITS (FRONT_MATERIAL_BITS | BACK_MATERIAL_BITS)
/*@}*/
@@ -331,14 +363,7 @@ struct gl_lightmodel {
*/
struct gl_material
{
- GLfloat Ambient[4];
- GLfloat Diffuse[4];
- GLfloat Specular[4];
- GLfloat Emission[4];
- GLfloat Shininess;
- GLfloat AmbientIndex; /**< for color index lighting */
- GLfloat DiffuseIndex; /**< for color index lighting */
- GLfloat SpecularIndex; /**< for color index lighting */
+ GLfloat Attrib[MAT_ATTRIB_MAX][4];
};
@@ -664,7 +689,7 @@ struct gl_light_attrib {
* Must flush FLUSH_VERTICES before referencing:
*/
/*@{*/
- struct gl_material Material[2]; /**< Material 0=front, 1=back */
+ struct gl_material Material; /**< Includes front & back values */
/*@}*/
GLboolean Enabled; /**< Lighting enabled flag */
diff --git a/src/mesa/main/rastpos.c b/src/mesa/main/rastpos.c
index 8184a25b975..218e4f7ed2e 100644
--- a/src/mesa/main/rastpos.c
+++ b/src/mesa/main/rastpos.c
@@ -140,7 +140,8 @@ shade_rastpos(GLcontext *ctx,
_mesa_validate_all_lighting_tables( ctx );
COPY_3V(diffuseColor, base[0]);
- diffuseColor[3] = CLAMP( ctx->Light.Material[0].Diffuse[3], 0.0F, 1.0F );
+ diffuseColor[3] = CLAMP(
+ ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3], 0.0F, 1.0F );
ASSIGN_4V(specularColor, 0.0, 0.0, 0.0, 0.0);
foreach (light, &ctx->Light.EnabledList) {
@@ -223,9 +224,9 @@ shade_rastpos(GLcontext *ctx,
n_dot_h = DOT3(normal, h);
if (n_dot_h > 0.0F) {
- const struct gl_material *mat = &ctx->Light.Material[0];
+ GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
GLfloat spec_coef;
- GLfloat shininess = mat->Shininess;
+ GLfloat shininess = mat[MAT_ATTRIB_FRONT_SHININESS][0];
if (!normalized) {
n_dot_h *= n_dot_h;
@@ -264,16 +265,16 @@ shade_rastpos(GLcontext *ctx,
Rspec[3] = CLAMP(specularColor[3], 0.0F, 1.0F);
}
else {
- struct gl_material *mat = &ctx->Light.Material[0];
- GLfloat d_a = mat->DiffuseIndex - mat->AmbientIndex;
- GLfloat s_a = mat->SpecularIndex - mat->AmbientIndex;
- GLfloat ind = mat->AmbientIndex
- + diffuse * (1.0F-specular) * d_a
- + specular * s_a;
- if (ind > mat->SpecularIndex) {
- ind = mat->SpecularIndex;
+ GLfloat *ind = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_INDEXES];
+ GLfloat d_a = ind[MAT_INDEX_DIFFUSE] - ind[MAT_INDEX_AMBIENT];
+ GLfloat s_a = ind[MAT_INDEX_SPECULAR] - ind[MAT_INDEX_AMBIENT];
+ GLfloat i = (ind[MAT_INDEX_AMBIENT]
+ + diffuse * (1.0F-specular) * d_a
+ + specular * s_a);
+ if (i > ind[MAT_INDEX_SPECULAR]) {
+ i = ind[MAT_INDEX_SPECULAR];
}
- *Rindex = (GLuint) (GLint) ind;
+ *Rindex = (GLuint) (GLint) i;
}
}