Allow different max texture sizes for 1/2D, 3D and cube maps.
[mesa.git] / src / mesa / tnl / t_imm_fixup.c
index 1c3cf2861c5037ae5a59e9bfcbe15e5c6bdcf220..fdfeff566a144d5e987930b218274b4c016e6964 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: t_imm_fixup.c,v 1.13 2001/04/30 21:08:52 keithw Exp $ */
+/* $Id: t_imm_fixup.c,v 1.20 2001/06/04 16:09:28 keithw Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -290,9 +290,9 @@ void _tnl_fixup_input( GLcontext *ctx, struct immediate *IM )
       if (fixup & VERT_RGBA) {
         if (orflag & VERT_RGBA)
            _tnl_fixup_4f( IM->Color, IM->Flag, start, VERT_RGBA );
-/*      else */
-/*         fixup_first_4f( IM->Color, IM->Flag, VERT_END_VB, start,  */
-/*                         IM->Color[start] ); */
+        /* No need for else case as the drivers understand stride
+         * zero here.  (TODO - propogate this)
+         */
       }
       
       if (fixup & VERT_SPEC_RGB) {
@@ -364,6 +364,18 @@ static void copy_material( struct immediate *next,
    MEMCPY(next->Material[dst], prev->Material[src], 2*sizeof(GLmaterial));
 }
 
+static GLboolean is_fan_like[GL_POLYGON+1] = {
+   GL_FALSE,
+   GL_FALSE,
+   GL_TRUE,                    /* line loop */
+   GL_FALSE,
+   GL_FALSE,
+   GL_FALSE,
+   GL_TRUE,                    /* tri fan */
+   GL_FALSE,
+   GL_FALSE,
+   GL_TRUE                     /* polygon */
+};
 
 
 /* Copy the untransformed data from the shared vertices of a primitive
@@ -391,10 +403,6 @@ void _tnl_copy_immediate_vertices( GLcontext *ctx, struct immediate *next )
    }
 
    next->CopyStart = next->Start - count;
-/*     fprintf(stderr, "%s prim %s count %d source %p\n", */
-/*        __FUNCTION__,  */
-/*        _mesa_lookup_enum_by_nr(ctx->Driver.CurrentExecPrimitive), */
-/*        count, prev); */
 
    if ((prev->CopyOrFlag & VERT_DATA) == VERT_ELT &&
        ctx->Array.LockCount &&
@@ -406,22 +414,31 @@ void _tnl_copy_immediate_vertices( GLcontext *ctx, struct immediate *next )
       {
         GLuint src = elts[i+offset];
         GLuint dst = next->CopyStart+i;
-
         next->Elt[dst] = prev->Elt[src];
         next->Flag[dst] = VERT_ELT;
-        next->CopyOrFlag |= VERT_ELT;
-        next->CopyAndFlag &= VERT_ELT;
       }
+      next->CopyOrFlag |= VERT_ELT;
+      next->CopyAndFlag &= VERT_ELT;
    }
    else {
       /* prev->CopyOrFlag is hacked to include values generated by eval:
        */
       GLuint copy = tnl->pipeline.inputs & prev->CopyOrFlag;
-
-/*        _tnl_print_vert_flags(__FUNCTION__, copy); */
-          
-          
-      next->TexSize |= tnl->ExecCopyTexSize;
+      GLuint flag;
+
+      if (is_fan_like[ctx->Driver.CurrentExecPrimitive]) {
+        next->TexSize |= tnl->ExecCopyTexSize;
+        next->CopyOrFlag |= (prev->CopyOrFlag & VERT_FIXUP);
+        next->CopyAndFlag &= (prev->CopyOrFlag & VERT_FIXUP);
+        flag = (prev->CopyOrFlag & VERT_FIXUP);
+      } 
+      else {
+        /* Don't let an early 'glColor', etc. poison the elt path.
+         */
+        next->CopyAndFlag &= (prev->OrFlag & VERT_FIXUP);
+        flag = (prev->OrFlag & VERT_FIXUP);
+      }
+        
 
       /* Copy whole vertices
        */
@@ -431,8 +448,6 @@ void _tnl_copy_immediate_vertices( GLcontext *ctx, struct immediate *next )
         GLuint isrc = src - prev->CopyStart;
         GLuint dst = next->CopyStart+i;
 
-/*      fprintf(stderr, "src %d isrc %d dst %d\n", src, isrc, dst); */
-
         /* Values subject to eval must be copied out of the 'inputs'
          * struct.  (Copied rows should not be evaluated twice).
          *
@@ -474,11 +489,10 @@ void _tnl_copy_immediate_vertices( GLcontext *ctx, struct immediate *next )
            next->FogCoord[dst] = prev->FogCoord[src];
         }
 
-        next->Flag[dst] = (prev->CopyOrFlag & VERT_FIXUP);
+        next->Flag[dst] = flag;
+        next->OrFlag |= prev->Flag[src]; /* for non-fanlike prims, 
+                                            otherwise redundant */
       }
-
-      next->CopyOrFlag |= (prev->CopyOrFlag & VERT_FIXUP);
-      next->CopyAndFlag &= (prev->CopyOrFlag & VERT_FIXUP);
    }
 
    if (--tnl->ExecCopySource->ref_count == 0)
@@ -500,8 +514,6 @@ void _tnl_fixup_compiled_cassette( GLcontext *ctx, struct immediate *IM )
    GLuint count = IM->Count;
    GLuint start = IM->Start;
 
-/*     fprintf(stderr, "%s\n", __FUNCTION__); */
-
    if (count == start)
       return;
 
@@ -580,94 +592,6 @@ void _tnl_fixup_compiled_cassette( GLcontext *ctx, struct immediate *IM )
 
       } while (vulnerable);
    }
-
-   /* Can potentially overwrite primitive details - need to save the
-    * first slot:
-    */
-   tnl->DlistPrimitive = IM->Primitive[IM->Start];
-   tnl->DlistPrimitiveLength = IM->PrimitiveLength[IM->Start];
-   tnl->DlistLastPrimitive = IM->LastPrimitive;
-
-   /* The first primitive may be different from what was recorded in
-    * the immediate struct.  Consider an immediate that starts with a
-    * glBegin, compiled in a display list, which is called from within
-    * an existing Begin/End object.
-    */
-   if (ctx->Driver.CurrentExecPrimitive == GL_POLYGON+1) {
-      GLuint i;
-
-      if (IM->BeginState & VERT_ERROR_1)
-        _mesa_error( ctx, GL_INVALID_OPERATION, "glBegin/glEnd");
-
-      for (i = IM->Start ; i <= IM->Count ; i += IM->PrimitiveLength[i])
-        if (IM->Flag[i] & (VERT_BEGIN|VERT_END_VB))
-           break;
-
-      /* Would like to just ignore vertices upto this point.  Can't
-       * set copystart because it might skip materials?
-       */
-      ASSERT(IM->Start == IM->CopyStart);
-      if (i > IM->CopyStart) {
-        IM->Primitive[IM->CopyStart] = GL_POLYGON+1;
-        IM->PrimitiveLength[IM->CopyStart] = i - IM->CopyStart;
-        if (IM->Flag[i] & VERT_END_VB) {
-           IM->Primitive[IM->CopyStart] |= PRIM_LAST;
-           IM->LastPrimitive = IM->CopyStart;
-        }
-      }
-   } else {
-      GLuint i;
-
-      if (IM->BeginState & VERT_ERROR_0)
-        _mesa_error( ctx, GL_INVALID_OPERATION, "glBegin/glEnd");
-
-      if (IM->CopyStart == IM->Start &&
-         IM->Flag[IM->Start] & (VERT_END|VERT_END_VB))
-      {
-      }
-      else
-      {
-        IM->Primitive[IM->CopyStart] = ctx->Driver.CurrentExecPrimitive;
-        if (tnl->ExecParity)
-           IM->Primitive[IM->CopyStart] |= PRIM_PARITY;
-
-
-        for (i = IM->Start ; i <= IM->Count ; i += IM->PrimitiveLength[i])
-           if (IM->Flag[i] & (VERT_END|VERT_END_VB)) {
-              IM->PrimitiveLength[IM->CopyStart] = i - IM->CopyStart;
-              if (IM->Flag[i] & VERT_END_VB) {
-                 IM->Primitive[IM->CopyStart] |= PRIM_LAST;
-                 IM->LastPrimitive = IM->CopyStart;
-              }
-              if (IM->Flag[i] & VERT_END) {
-                 IM->Primitive[IM->CopyStart] |= PRIM_END;
-              }
-              break;
-           }
-      }
-   }
-
-   if (IM->Primitive[IM->LastPrimitive] & PRIM_END)
-      ctx->Driver.CurrentExecPrimitive = GL_POLYGON+1;
-   else
-      ctx->Driver.CurrentExecPrimitive =
-        IM->Primitive[IM->LastPrimitive] & PRIM_MODE_MASK;
-
-/*     fprintf(stderr, "setting cep %x in %s\n",  */
-/*        ctx->Driver.CurrentExecPrimitive, __FUNCTION__); */
-/*     fprintf(stderr, "%s lastprim %d: %x\n", __FUNCTION__,  */
-/*        IM->LastPrimitive, IM->Primitive[IM->LastPrimitive]); */
-}
-
-
-/* Undo any changes potentially made to the immediate in the range
- * IM->Start..IM->Count above.
- */
-void _tnl_restore_compiled_cassette( GLcontext *ctx, struct immediate *IM )
-{
-   TNLcontext *tnl = TNL_CONTEXT(ctx);
-   IM->Primitive[IM->Start] = tnl->DlistPrimitive;
-   IM->PrimitiveLength[IM->Start] = tnl->DlistPrimitiveLength;
 }
 
 
@@ -813,8 +737,8 @@ void _tnl_upgrade_current_data( GLcontext *ctx,
                                GLuint flags )
 {
    TNLcontext *tnl = TNL_CONTEXT(ctx);
-   struct immediate *IM = TNL_CURRENT_IM(ctx); /* hmmm */
    struct vertex_buffer *VB = &tnl->vb;
+   struct immediate *IM = (struct immediate *)VB->import_source;
 
    ASSERT(IM);
 
@@ -829,9 +753,13 @@ void _tnl_upgrade_current_data( GLcontext *ctx,
       tmp->Flags = 0;
 
       COPY_4FV( IM->Color[start], ctx->Current.Color);   
+
+      ASSERT(IM->Flag[IM->LastData+1] & VERT_END_VB);
+
       fixup_first_4f( IM->Color, IM->Flag, VERT_END_VB, start, 
                      IM->Color[start] );
 
       VB->importable_data &= ~VERT_RGBA;
    }
 }