summaryrefslogtreecommitdiff
path: root/src/mesa
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa')
-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
-rw-r--r--src/mesa/tnl/t_context.h4
-rw-r--r--src/mesa/tnl/t_imm_api.c62
-rw-r--r--src/mesa/tnl/t_imm_dlist.c62
-rw-r--r--src/mesa/tnl/t_imm_exec.c8
-rw-r--r--src/mesa/tnl/t_imm_fixup.c20
-rw-r--r--src/mesa/tnl/t_vb_light.c8
-rw-r--r--src/mesa/tnl/t_vb_lighttmp.h68
13 files changed, 313 insertions, 517 deletions
diff --git a/src/mesa/main/api_noop.c b/src/mesa/main/api_noop.c
index a1f689d6f9..bab333dca8 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 19cee76d5d..5299c5c1cd 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 046738882d..c9e0fbd73a 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 240a6317b7..1eb7f56985 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 27b01eee08..5c321d0d99 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 8184a25b97..218e4f7ed2 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;
}
}
diff --git a/src/mesa/tnl/t_context.h b/src/mesa/tnl/t_context.h
index 943082d99b..c375a5670b 100644
--- a/src/mesa/tnl/t_context.h
+++ b/src/mesa/tnl/t_context.h
@@ -223,7 +223,7 @@ struct immediate
/* allocate storage for these on demand:
*/
- struct gl_material (*Material)[2];
+ struct gl_material *Material;
GLuint *MaterialMask;
GLuint LastMaterial;
GLuint MaterialOrMask;
@@ -302,7 +302,7 @@ typedef struct vertex_buffer
struct gl_client_array *SecondaryColorPtr[2];/* VERT_BIT_COLOR1 */
GLvector4f *PointSizePtr; /* VERT_BIT_POINT_SIZE */
GLvector4f *FogCoordPtr; /* VERT_BIT_FOG */
- struct gl_material (*Material)[2]; /* VERT_BIT_MATERIAL, optional */
+ struct gl_material *Material; /* VERT_BIT_MATERIAL, optional */
GLuint *MaterialMask; /* VERT_BIT_MATERIAL, optional */
GLuint *Flag; /* VERT_BIT_* flags, optional */
GLuint *Primitive; /* GL_(mode)|PRIM_* flags */
diff --git a/src/mesa/tnl/t_imm_api.c b/src/mesa/tnl/t_imm_api.c
index 868de64c16..0449504300 100644
--- a/src/mesa/tnl/t_imm_api.c
+++ b/src/mesa/tnl/t_imm_api.c
@@ -1256,6 +1256,7 @@ _tnl_Materialfv( GLenum face, GLenum pname, const GLfloat *params )
GLuint count = IM->Count;
struct gl_material *mat;
GLuint bitmask = _mesa_material_bitmask(ctx, face, pname, ~0, "Materialfv");
+ int i, nr;
if (bitmask == 0)
return;
@@ -1273,15 +1274,15 @@ _tnl_Materialfv( GLenum face, GLenum pname, const GLfloat *params )
if (!(IM->Flag[count] & VERT_BIT_MATERIAL)) {
if (!IM->Material) {
- IM->Material = (struct gl_material (*)[2])
- MALLOC( sizeof(struct gl_material) * IMM_SIZE * 2 );
+ IM->Material = (struct gl_material *)
+ MALLOC( sizeof(struct gl_material) * IMM_SIZE );
IM->MaterialMask = (GLuint *) MALLOC( sizeof(GLuint) * IMM_SIZE );
IM->MaterialMask[IM->LastMaterial] = 0;
}
else if (IM->MaterialOrMask & ~bitmask) {
- _mesa_copy_material_pairs( IM->Material[count],
- IM->Material[IM->LastMaterial],
- IM->MaterialOrMask & ~bitmask );
+ _mesa_copy_materials( &IM->Material[count],
+ &IM->Material[IM->LastMaterial],
+ IM->MaterialOrMask & ~bitmask );
}
IM->Flag[count] |= VERT_BIT_MATERIAL;
@@ -1292,51 +1293,18 @@ _tnl_Materialfv( GLenum face, GLenum pname, const GLfloat *params )
IM->MaterialOrMask |= bitmask;
IM->MaterialMask[count] |= bitmask;
- mat = IM->Material[count];
+ mat = &IM->Material[count];
- 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;
}
+ for (i = 0 ; i < MAT_ATTRIB_MAX ; i++)
+ if (bitmask & (1<<i))
+ COPY_SZ_4V( mat->Attrib[i], nr, params );
+
if (tnl->IsolateMaterials &&
!(IM->BeginState & VERT_BEGIN_1)) /* heuristic */
{
diff --git a/src/mesa/tnl/t_imm_dlist.c b/src/mesa/tnl/t_imm_dlist.c
index 3efe61592f..8fcc9b25f0 100644
--- a/src/mesa/tnl/t_imm_dlist.c
+++ b/src/mesa/tnl/t_imm_dlist.c
@@ -527,51 +527,43 @@ _tnl_dlist_init( GLcontext *ctx )
static void
emit_material( const struct gl_material *src, GLuint bitmask )
{
- if (bitmask & FRONT_EMISSION_BIT)
- glMaterialfv( GL_FRONT, GL_EMISSION, src[0].Emission );
+ const GLfloat (*attr)[4] = src->Attrib;
- if (bitmask & BACK_EMISSION_BIT)
- glMaterialfv( GL_BACK, GL_EMISSION, src[1].Emission );
+ if (bitmask & MAT_BIT_FRONT_EMISSION)
+ glMaterialfv( GL_FRONT, GL_EMISSION, attr[MAT_ATTRIB_FRONT_EMISSION] );
- if (bitmask & FRONT_AMBIENT_BIT)
- glMaterialfv( GL_FRONT, GL_AMBIENT, src[0].Ambient );
+ if (bitmask & MAT_BIT_BACK_EMISSION)
+ glMaterialfv( GL_BACK, GL_EMISSION, attr[MAT_ATTRIB_BACK_EMISSION] );
- if (bitmask & BACK_AMBIENT_BIT)
- glMaterialfv( GL_BACK, GL_AMBIENT, src[1].Ambient );
+ if (bitmask & MAT_BIT_FRONT_AMBIENT)
+ glMaterialfv( GL_FRONT, GL_AMBIENT, attr[MAT_ATTRIB_FRONT_AMBIENT] );
- if (bitmask & FRONT_DIFFUSE_BIT)
- glMaterialfv( GL_FRONT, GL_DIFFUSE, src[0].Diffuse );
+ if (bitmask & MAT_BIT_BACK_AMBIENT)
+ glMaterialfv( GL_BACK, GL_AMBIENT, attr[MAT_ATTRIB_BACK_AMBIENT] );
- if (bitmask & BACK_DIFFUSE_BIT)
- glMaterialfv( GL_BACK, GL_DIFFUSE, src[1].Diffuse );
+ if (bitmask & MAT_BIT_FRONT_DIFFUSE)
+ glMaterialfv( GL_FRONT, GL_DIFFUSE, attr[MAT_ATTRIB_FRONT_DIFFUSE] );
- if (bitmask & FRONT_SPECULAR_BIT)
- glMaterialfv( GL_FRONT, GL_SPECULAR, src[0].Specular );
+ if (bitmask & MAT_BIT_BACK_DIFFUSE)
+ glMaterialfv( GL_BACK, GL_DIFFUSE, attr[MAT_ATTRIB_BACK_DIFFUSE] );
- if (bitmask & BACK_SPECULAR_BIT)
- glMaterialfv( GL_BACK, GL_SPECULAR, src[1].Specular );
+ if (bitmask & MAT_BIT_FRONT_SPECULAR)
+ glMaterialfv( GL_FRONT, GL_SPECULAR, attr[MAT_ATTRIB_FRONT_SPECULAR] );
- if (bitmask & FRONT_SHININESS_BIT)
- glMaterialfv( GL_FRONT, GL_SHININESS, &src[0].Shininess );
+ if (bitmask & MAT_BIT_BACK_SPECULAR)
+ glMaterialfv( GL_BACK, GL_SPECULAR, attr[MAT_ATTRIB_BACK_SPECULAR] );
- if (bitmask & BACK_SHININESS_BIT)
- glMaterialfv( GL_BACK, GL_SHININESS, &src[1].Shininess );
+ if (bitmask & MAT_BIT_FRONT_SHININESS)
+ glMaterialfv( GL_FRONT, GL_SHININESS, attr[MAT_ATTRIB_FRONT_SHININESS] );
- if (bitmask & FRONT_INDEXES_BIT) {
- GLfloat ind[3];
- ind[0] = src[0].AmbientIndex;
- ind[1] = src[0].DiffuseIndex;
- ind[2] = src[0].SpecularIndex;
- glMaterialfv( GL_FRONT, GL_COLOR_INDEXES, ind );
- }
+ if (bitmask & MAT_BIT_BACK_SHININESS)
+ glMaterialfv( GL_BACK, GL_SHININESS, attr[MAT_ATTRIB_BACK_SHININESS] );
- if (bitmask & BACK_INDEXES_BIT) {
- GLfloat ind[3];
- ind[0] = src[1].AmbientIndex;
- ind[1] = src[1].DiffuseIndex;
- ind[2] = src[1].SpecularIndex;
- glMaterialfv( GL_BACK, GL_COLOR_INDEXES, ind );
- }
+ if (bitmask & MAT_BIT_FRONT_INDEXES)
+ glMaterialfv( GL_FRONT, GL_COLOR_INDEXES, attr[MAT_ATTRIB_FRONT_INDEXES]);
+
+ if (bitmask & MAT_BIT_BACK_INDEXES)
+ glMaterialfv( GL_BACK, GL_COLOR_INDEXES, attr[MAT_ATTRIB_BACK_INDEXES] );
}
@@ -652,7 +644,7 @@ loopback_compiled_cassette( GLcontext *ctx, struct immediate *IM )
glEdgeFlag( IM->EdgeFlag[i] );
if (flags[i] & VERT_BIT_MATERIAL)
- emit_material( IM->Material[i], IM->MaterialMask[i] );
+ emit_material( &IM->Material[i], IM->MaterialMask[i] );
if (flags[i]&VERT_BITS_OBJ_234)
vertex( IM->Attrib[VERT_ATTRIB_POS][i] );
diff --git a/src/mesa/tnl/t_imm_exec.c b/src/mesa/tnl/t_imm_exec.c
index 38108785a1..f1d6ee8925 100644
--- a/src/mesa/tnl/t_imm_exec.c
+++ b/src/mesa/tnl/t_imm_exec.c
@@ -154,9 +154,11 @@ void _tnl_copy_to_current( GLcontext *ctx, struct immediate *IM,
}
if (flag & VERT_BIT_MATERIAL) {
- _mesa_update_material( ctx,
- IM->Material[IM->LastMaterial],
- IM->MaterialOrMask );
+ _mesa_copy_materials( &ctx->Light.Material,
+ &IM->Material[IM->LastMaterial],
+ IM->MaterialOrMask );
+
+ _mesa_update_material( ctx, IM->MaterialOrMask );
TNL_CONTEXT(ctx)->Driver.NotifyMaterialChange( ctx );
}
diff --git a/src/mesa/tnl/t_imm_fixup.c b/src/mesa/tnl/t_imm_fixup.c
index cf3aa2ed96..5f821e7343 100644
--- a/src/mesa/tnl/t_imm_fixup.c
+++ b/src/mesa/tnl/t_imm_fixup.c
@@ -292,9 +292,9 @@ _tnl_fixup_input( GLcontext *ctx, struct immediate *IM )
i++;
vulnerable &= ~IM->MaterialMask[i];
- _mesa_copy_material_pairs( IM->Material[i],
- ctx->Light.Material,
- vulnerable );
+ _mesa_copy_materials( &IM->Material[i],
+ &ctx->Light.Material,
+ vulnerable );
++i;
@@ -311,14 +311,14 @@ copy_material( struct immediate *next,
/* _mesa_debug(NULL, "%s\n", __FUNCTION__); */
if (next->Material == 0) {
- next->Material = (struct gl_material (*)[2])
- MALLOC( sizeof(struct gl_material) * IMM_SIZE * 2 );
+ next->Material = (struct gl_material *)
+ MALLOC( sizeof(struct gl_material) * IMM_SIZE );
next->MaterialMask = (GLuint *) MALLOC( sizeof(GLuint) * IMM_SIZE );
}
next->MaterialMask[dst] = prev->MaterialOrMask;
- MEMCPY(next->Material[dst], prev->Material[src],
- 2 * sizeof(struct gl_material));
+ MEMCPY(&next->Material[dst], &prev->Material[src],
+ sizeof(struct gl_material));
}
@@ -590,9 +590,9 @@ _tnl_fixup_compiled_cassette( GLcontext *ctx, struct immediate *IM )
i++;
vulnerable &= ~IM->MaterialMask[i];
- _mesa_copy_material_pairs( IM->Material[i],
- ctx->Light.Material,
- vulnerable );
+ _mesa_copy_materials( &IM->Material[i],
+ &ctx->Light.Material,
+ vulnerable );
++i;
diff --git a/src/mesa/tnl/t_vb_light.c b/src/mesa/tnl/t_vb_light.c
index 8675548634..aedbad4254 100644
--- a/src/mesa/tnl/t_vb_light.c
+++ b/src/mesa/tnl/t_vb_light.c
@@ -94,6 +94,14 @@ static void import_color_material( GLcontext *ctx,
}
+static void update_materials( GLcontext *ctx,
+ const struct gl_material *src,
+ GLuint bitmask )
+{
+ _mesa_copy_materials( &ctx->Light.Material, src, bitmask );
+ _mesa_update_material( ctx, bitmask );
+}
+
/* Tables for all the shading functions.
*/
static light_func _tnl_light_tab[MAX_LIGHT_FUNC];
diff --git a/src/mesa/tnl/t_vb_lighttmp.h b/src/mesa/tnl/t_vb_lighttmp.h
index 5ddac76862..db61234253 100644
--- a/src/mesa/tnl/t_vb_lighttmp.h
+++ b/src/mesa/tnl/t_vb_lighttmp.h
@@ -113,7 +113,7 @@ static void TAG(light_rgba_spec)( GLcontext *ctx,
const GLuint nr = VB->Count;
const GLuint *flags = VB->Flag;
- struct gl_material (*new_material)[2] = VB->Material;
+ struct gl_material *new_material = VB->Material;
const GLuint *new_material_mask = VB->MaterialMask;
(void) flags;
@@ -135,12 +135,12 @@ static void TAG(light_rgba_spec)( GLcontext *ctx,
VB->ColorPtr[0] = &store->LitColor[0];
VB->SecondaryColorPtr[0] = &store->LitSecondary[0];
- UNCLAMPED_FLOAT_TO_CHAN(sumA[0], ctx->Light.Material[0].Diffuse[3]);
+ UNCLAMPED_FLOAT_TO_CHAN(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];
- UNCLAMPED_FLOAT_TO_CHAN(sumA[1], ctx->Light.Material[1].Diffuse[3]);
+ UNCLAMPED_FLOAT_TO_CHAN(sumA[1], ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3]);
}
/* Side-effects done, can we finish now?
@@ -159,13 +159,13 @@ static void TAG(light_rgba_spec)( GLcontext *ctx,
_mesa_update_color_material( ctx, CMcolor );
if ( CHECK_MATERIAL(j) )
- _mesa_update_material( ctx, new_material[j], new_material_mask[j] );
+ update_materials( 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]);
+ UNCLAMPED_FLOAT_TO_CHAN(sumA[0], ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3]);
if (IDX & LIGHT_TWOSIDE)
- UNCLAMPED_FLOAT_TO_CHAN(sumA[1], ctx->Light.Material[1].Diffuse[3]);
+ UNCLAMPED_FLOAT_TO_CHAN(sumA[1], ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3]);
}
COPY_3V(sum[0], base[0]);
@@ -325,7 +325,7 @@ static void TAG(light_rgba)( GLcontext *ctx,
GLchan (*color[2])[4];
const GLuint *flags = VB->Flag;
- struct gl_material (*new_material)[2] = VB->Material;
+ struct gl_material *new_material = VB->Material;
const GLuint *new_material_mask = VB->MaterialMask;
const GLuint nr = VB->Count;
@@ -350,11 +350,11 @@ static void TAG(light_rgba)( GLcontext *ctx,
}
VB->ColorPtr[0] = &store->LitColor[0];
- UNCLAMPED_FLOAT_TO_CHAN(sumA[0], ctx->Light.Material[0].Diffuse[3]);
+ UNCLAMPED_FLOAT_TO_CHAN(sumA[0], ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3]);
if (IDX & LIGHT_TWOSIDE) {
VB->ColorPtr[1] = &store->LitColor[1];
- UNCLAMPED_FLOAT_TO_CHAN(sumA[1], ctx->Light.Material[1].Diffuse[3]);
+ UNCLAMPED_FLOAT_TO_CHAN(sumA[1], ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3]);
}
if (stage->changed_inputs == 0)
@@ -371,13 +371,13 @@ static void TAG(light_rgba)( GLcontext *ctx,
_mesa_update_color_material( ctx, CMcolor );
if ( CHECK_MATERIAL(j) )
- _mesa_update_material( ctx, new_material[j], new_material_mask[j] );
+ update_materials( 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]);
+ UNCLAMPED_FLOAT_TO_CHAN(sumA[0], ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3]);
if (IDX & LIGHT_TWOSIDE)
- UNCLAMPED_FLOAT_TO_CHAN(sumA[1], ctx->Light.Material[1].Diffuse[3]);
+ UNCLAMPED_FLOAT_TO_CHAN(sumA[1], ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3]);
}
COPY_3V(sum[0], base[0]);
@@ -535,7 +535,7 @@ static void TAG(light_fast_rgba_single)( GLcontext *ctx,
const GLuint *flags = VB->Flag;
GLchan basechan[2][4];
GLuint j = 0;
- struct gl_material (*new_material)[2] = VB->Material;
+ struct gl_material *new_material = VB->Material;
const GLuint *new_material_mask = VB->MaterialMask;
GLfloat base[2][3];
const GLuint nr = VB->Count;
@@ -572,7 +572,7 @@ static void TAG(light_fast_rgba_single)( GLcontext *ctx,
}
if ( CHECK_MATERIAL(j) )
- _mesa_update_material( ctx, new_material[j], new_material_mask[j] );
+ update_materials( ctx, &new_material[j], new_material_mask[j] );
if ( CHECK_VALIDATE(j) )
TNL_CONTEXT(ctx)->Driver.NotifyMaterialChange( ctx );
@@ -584,14 +584,14 @@ static void TAG(light_fast_rgba_single)( GLcontext *ctx,
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]);
+ ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_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]);
+ ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3]);
}
do {
@@ -663,7 +663,7 @@ static void TAG(light_fast_rgba)( GLcontext *ctx,
GLchan (*Bcolor)[4] = (GLchan (*)[4]) store->LitColor[1].Ptr;
const GLuint *flags = VB->Flag;
GLuint j = 0;
- struct gl_material (*new_material)[2] = VB->Material;
+ struct gl_material *new_material = VB->Material;
GLuint *new_material_mask = VB->MaterialMask;
const GLuint nr = VB->Count;
const struct gl_light *light;
@@ -677,8 +677,8 @@ static void TAG(light_fast_rgba)( GLcontext *ctx,
(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]);
+ UNCLAMPED_FLOAT_TO_CHAN(sumA[0], ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3]);
+ UNCLAMPED_FLOAT_TO_CHAN(sumA[1], ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3]);
if (IDX & LIGHT_COLORMATERIAL) {
if (VB->ColorPtr[0]->Type != GL_FLOAT ||
@@ -704,14 +704,14 @@ static void TAG(light_fast_rgba)( GLcontext *ctx,
_mesa_update_color_material( ctx, CMcolor );
if ( CHECK_MATERIAL(j) )
- _mesa_update_material( ctx, new_material[j], new_material_mask[j] );
+ update_materials( 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]);
+ UNCLAMPED_FLOAT_TO_CHAN(sumA[0], ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3]);
if (IDX & LIGHT_TWOSIDE)
UNCLAMPED_FLOAT_TO_CHAN(sumA[1],
- ctx->Light.Material[1].Diffuse[3]);
+ ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE][3]);
}
@@ -804,7 +804,7 @@ static void TAG(light_ci)( GLcontext *ctx,
GLuint CMstride;
const GLuint *flags = VB->Flag;
GLuint *indexResult[2];
- struct gl_material (*new_material)[2] = VB->Material;
+ struct gl_material *new_material = VB->Material;
GLuint *new_material_mask = VB->MaterialMask;
const GLuint nr = VB->Count;
@@ -849,7 +849,7 @@ static void TAG(light_ci)( GLcontext *ctx,
_mesa_update_color_material( ctx, CMcolor );
if ( CHECK_MATERIAL(j) )
- _mesa_update_material( ctx, new_material[j], new_material_mask[j] );
+ update_materials( ctx, &new_material[j], new_material_mask[j] );
if ( CHECK_VALIDATE(j) )
TNL_CONTEXT(ctx)->Driver.NotifyMaterialChange( ctx );
@@ -953,22 +953,20 @@ static void TAG(light_ci)( GLcontext *ctx,
/* 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];
+ GLfloat i = (ind[MAT_INDEX_AMBIENT]
+ + diffuse[side] * (1.0F-specular[side]) * d_a
+ + specular[side] * s_a);
+ if (i > ind[MAT_INDEX_SPECULAR]) {
+ i = ind[MAT_INDEX_SPECULAR];
}
}
indexResult[side][j] = (GLuint) (GLint) index;