use BCOPY macro on FreeBSD
[mesa.git] / src / mesa / main / varray.c
index be7fc8798fc5af5d12e269f8f81c5e2268207542..5b069c5e76f414ceed121790ca5a23f849865593 100644 (file)
@@ -1,10 +1,10 @@
-/* $Id: varray.c,v 1.16 1999/11/18 23:56:04 brianp Exp $ */
+/* $Id: varray.c,v 1.21 2000/02/25 03:55:40 keithw Exp $ */
 
 /*
  * Mesa 3-D graphics library
  * Version:  3.1
  * 
- * Copyright (C) 1999  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2000  Brian Paul   All Rights Reserved.
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -37,6 +37,7 @@
 #include "macros.h"
 #include "mmath.h"
 #include "pipeline.h"
+#include "state.h"
 #include "texstate.h"
 #include "translate.h"
 #include "types.h"
@@ -341,9 +342,10 @@ _mesa_EdgeFlagPointer(GLsizei stride, const void *vptr)
 }
 
 
+#if 0
 /* Called only from gl_DrawElements
  */
-void gl_CVAEltPointer( GLcontext *ctx, GLenum type, const GLvoid *ptr )
+static void gl_CVAEltPointer( GLcontext *ctx, GLenum type, const GLvoid *ptr )
 {
    switch (type) {
       case GL_UNSIGNED_BYTE:
@@ -365,7 +367,7 @@ void gl_CVAEltPointer( GLcontext *ctx, GLenum type, const GLvoid *ptr )
    ctx->CVA.EltFunc = gl_trans_1ui_tab[TYPE_IDX(type)];
    ctx->Array.NewArrayState |= VERT_ELT; /* ??? */
 }
-
+#endif
 
 
 /* KW: Batch function to exec all the array elements in the input
@@ -462,7 +464,8 @@ _mesa_ArrayElement( GLint i )
 }
 
 
-void gl_ArrayElement( GLcontext *CC, GLint i )
+static void
+gl_ArrayElement( GLcontext *CC, GLint i )
 {
    struct immediate *im = CC->input;
    ARRAY_ELT( im, i );
@@ -505,14 +508,23 @@ _mesa_DrawArrays(GLenum mode, GLint start, GLsizei count)
        * rendering to keep it turned on.
        */
       relock = ctx->CompileCVAFlag;
-      ctx->CompileCVAFlag = 0;
 
-      if (!elt->pipeline_valid || relock)
+      if (relock) {
+        ctx->CompileCVAFlag = 0;
+        elt->pipeline_valid = 0;
+      }
+
+      if (!elt->pipeline_valid)
         gl_build_immediate_pipeline( ctx );
 
       required = elt->inputs;
       fallback = (elt->inputs & ~ctx->Array.Summary);
 
+      /* The translate function doesn't do anything about size.  It
+       * just ensures that type and stride come out right.
+       */
+      IM->v.Obj.size = ctx->Array.Vertex.Size;
+
       if (required & VERT_RGBA) 
       {
         Color = &ctx->Array.Color;
@@ -587,8 +599,6 @@ _mesa_DrawArrays(GLenum mode, GLint start, GLsizei count)
       VB->Material = IM->Material;
       VB->BoundsPtr = 0;
 
-      IM->v.Obj.size = ctx->Array.Vertex.Size;  /* added by Andree Borrmann */
-
       while (remaining > 0) {
          GLint vbspace = VB_MAX - VB_START;
         GLuint count, n;
@@ -671,11 +681,11 @@ _mesa_DrawArrays(GLenum mode, GLint start, GLsizei count)
 
         VB->NextPrimitive[VB->CopyStart] = VB->Count;
         VB->Primitive[VB->CopyStart] = mode;
+        ctx->Array.Flag[count] |= VERT_END_VB;
 
          /* Transform and render.
          */
          gl_run_pipeline( VB );
-         gl_flush_vb( ctx, "DrawArrays" );  /* added by Andree Borrmann */
         gl_reset_vb( VB );
 
         ctx->Array.Flag[count] = ctx->Array.Flags;
@@ -685,7 +695,12 @@ _mesa_DrawArrays(GLenum mode, GLint start, GLsizei count)
          remaining -= n;
       }
 
-      ctx->CompileCVAFlag = relock;
+      gl_reset_input( ctx );
+
+      if (relock) {
+        ctx->CompileCVAFlag = relock;
+        elt->pipeline_valid = 0;
+      }
    }
    else if (ctx->Array.Vertex.Enabled) 
    {
@@ -802,7 +817,7 @@ _mesa_DrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indice
       return;
    }
 
-   if (mode > GL_POLYGON) {
+   if (mode < 0 || mode > GL_POLYGON) {
       gl_error( ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" );
       return;
    }
@@ -1108,6 +1123,13 @@ _mesa_DrawRangeElements(GLenum mode, GLuint start,
       return;
    }
 
+#if 0
+   /*
+    * XXX something in locked arrays is broken!  If start = 0,
+    * end = 1 and count = 2 we'll take the LockArrays path and
+    * get incorrect results.  See Scott McMillan's bug of 3 Jan 2000.
+    * For now, don't use locked arrays.
+    */
    if (!ctx->Array.LockCount && 2*count > (GLint) 3*(end-start)) {
       glLockArraysEXT( start, end );
       glDrawElements( mode, count, type, indices );
@@ -1115,6 +1137,9 @@ _mesa_DrawRangeElements(GLenum mode, GLuint start,
    } else {
       glDrawElements( mode, count, type, indices );
    }
+#else
+   glDrawElements( mode, count, type, indices );
+#endif
 }