Call UpdateMaterials when they have changed
authorKeith Whitwell <keith@tungstengraphics.com>
Tue, 9 Dec 2003 14:19:41 +0000 (14:19 +0000)
committerKeith Whitwell <keith@tungstengraphics.com>
Tue, 9 Dec 2003 14:19:41 +0000 (14:19 +0000)
src/mesa/tnl/t_context.h
src/mesa/tnl/t_save_api.c
src/mesa/tnl/t_save_playback.c
src/mesa/tnl/t_vtx_api.c

index 9d806da81fc52ec8cdf58a52d27a68193548d29f..33c4e06985dcdc613a3b8a129d8d059e02a6f0ca 100644 (file)
@@ -255,6 +255,7 @@ struct tnl_vtx {
    attrfv_func tabfv[_TNL_ATTRIB_MAX][4];
    struct tnl_eval eval;
    GLboolean *edgeflag_tmp;
+   GLboolean have_materials;
 };
 
 
@@ -282,7 +283,8 @@ struct tnl_vertex_list {
    GLfloat *buffer;
    GLuint count;
    GLuint wrap_count;          /* number of copied vertices at start */
-   GLuint dangling_attr_ref;   /* current attr implicitly referenced 
+   GLboolean have_materials;   /* bit of a hack - quick check for materials */
+   GLboolean dangling_attr_ref;        /* current attr implicitly referenced 
                                   outside the list */
 
    GLfloat *normal_lengths;
@@ -333,7 +335,8 @@ struct tnl_save {
    GLfloat vertex[_TNL_ATTRIB_MAX*4];     /* current values */
    GLfloat *attrptr[_TNL_ATTRIB_MAX];
    GLuint counter, initial_counter;
-   GLuint dangling_attr_ref;
+   GLboolean dangling_attr_ref;
+   GLboolean have_materials;
 
    GLuint opcode_vertex_list;
 
index e95c1c98eb09c2e98ceaa29338c6f3b93a300d9c..08a5036c6d1b7d9e40709589c55ec2328263841c 100644 (file)
@@ -475,7 +475,7 @@ static void _save_upgrade_vertex( GLcontext *ctx,
        */
       if (tnl->save.currentsz[attr] == 0) {
         assert(oldsz == 0);
-        tnl->save.dangling_attr_ref = attr;
+        tnl->save.dangling_attr_ref = GL_TRUE;
         _mesa_debug(0, "_save_upgrade_vertex: dangling reference attr %d\n", 
                      attr); 
 
@@ -680,11 +680,12 @@ static void _save_reset_vertex( GLcontext *ctx )
    save_init_13( tnl );
    save_init_14( tnl );
    save_init_15( tnl );
-
+      
    for (i = 0 ; i < _TNL_ATTRIB_MAX ; i++)
       tnl->save.attrsz[i] = 0;
-
+      
    tnl->save.vertex_size = 0;
+   tnl->save.have_materials = 0;
 
    _save_reset_counters( ctx ); 
 }
@@ -989,6 +990,7 @@ static void GLAPIENTRY _save_VertexAttrib4fvNV( GLuint index, const GLfloat *v )
 do {                                                   \
    if (tnl->save.attrsz[A] < N) {                      \
       _save_upgrade_vertex( ctx, A, N );               \
+      tnl->save.have_materials = GL_TRUE;               \
    }                                                   \
                                                        \
    {                                                   \
index 083901f079d8e9d49ae78afa5428769f08a01d5e..eaf30a3c18198202e8802468a7bb85d1305ce7f2 100644 (file)
@@ -149,6 +149,10 @@ static void _playback_copy_to_current( GLcontext *ctx,
       _mesa_update_color_material(ctx, ctx->Current.Attrib[VERT_ATTRIB_COLOR0]);
    }
 
+   if (node->have_materials) {
+      tnl->Driver.NotifyMaterialChange( ctx );
+   }
+
    /* CurrentExecPrimitive
     */
    if (node->prim_count) {
index 2fd5ccab1f32a1ea2cc475ea3153e19190160f15..482a316453cc9189d6ccaefec19d414e72ec4327 100644 (file)
@@ -132,7 +132,11 @@ static void _tnl_copy_to_current( GLcontext *ctx )
    if (ctx->Light.ColorMaterialEnabled) {
       _mesa_update_color_material(ctx, ctx->Current.Attrib[VERT_ATTRIB_COLOR0]);
    }
-   
+
+   if (tnl->vtx.have_materials) {
+      tnl->Driver.NotifyMaterialChange( ctx );
+   }
+         
    ctx->Driver.NeedFlush &= ~FLUSH_UPDATE_CURRENT;
 }
 
@@ -193,15 +197,12 @@ static void _tnl_wrap_upgrade_vertex( GLcontext *ctx,
    /* Heuristic: Attempt to isolate attributes received outside
     * begin/end so that they don't bloat the vertices.
     */
-#if 1
    if (ctx->Driver.CurrentExecPrimitive == PRIM_OUTSIDE_BEGIN_END &&
        tnl->vtx.attrsz[attr] == 0 
        && lastcount > 8
       ) {
       init_attrfv( tnl );
    }
-#endif
-      
 
    /* Fix up sizes:
     */
@@ -430,13 +431,7 @@ ATTRS( 14 )
 ATTRS( 15 )
 
 static void init_attrfv( TNLcontext *tnl )
-{
-#if defined( WIN32 ) || defined( __VMS )
-   if (0) fprintf(stderr, "%s %d\n", "init_attrfv", tnl->vtx.vertex_size);
-#else
-   if (0) fprintf(stderr, "%s %d\n", __FUNCTION__, tnl->vtx.vertex_size);
-#endif
-   
+{   
    if (tnl->vtx.vertex_size) {
       GLuint i;
       
@@ -461,6 +456,7 @@ static void init_attrfv( TNLcontext *tnl )
         tnl->vtx.attrsz[i] = 0;
 
       tnl->vtx.vertex_size = 0;
+      tnl->vtx.have_materials = 0;
    }
 }
 
@@ -762,6 +758,7 @@ static void GLAPIENTRY _tnl_VertexAttrib4fvNV( GLuint index, const GLfloat *v )
 do {                                                   \
    if (tnl->vtx.attrsz[A] != N) {                      \
       _tnl_fixup_vertex( ctx, A, N );                  \
+      tnl->vtx.have_materials = GL_TRUE;               \
    }                                                   \
                                                        \
    {                                                   \
@@ -984,13 +981,11 @@ static void GLAPIENTRY _tnl_Begin( GLenum mode )
         return;
       }
 
-#if 1
       /* Heuristic: attempt to isolate attributes occuring outside
        * begin/end pairs.
        */
       if (tnl->vtx.vertex_size && !tnl->vtx.attrsz[0]) 
         _tnl_FlushVertices( ctx, ~0 );
-#endif
 
       i = tnl->vtx.prim_count++;
       tnl->vtx.prim[i].mode = mode | PRIM_BEGIN;
@@ -1111,14 +1106,8 @@ void _tnl_FlushVertices( GLcontext *ctx, GLuint flags )
 
    if (tnl->vtx.counter != tnl->vtx.initial_counter) {
       _tnl_flush_vtx( ctx );
-#if 0
-      init_0(tnl);
-#endif
    }
 
-#if 0
-   if (flags & FLUSH_UPDATE_CURRENT)
-#endif
    {
       _tnl_copy_to_current( ctx );