remove ^M chars, disable shading language extensions
[mesa.git] / src / mesa / main / varray.c
index ddd04b4c81cdf66da834b36dafff9ce35619c7ca..6781b698150298eece542f4e4181ba5be05efb5d 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  5.1
+ * Version:  6.1
  *
- * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2004  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"),
@@ -25,6 +25,7 @@
 
 #include "glheader.h"
 #include "imports.h"
+#include "bufferobj.h"
 #include "context.h"
 #include "enable.h"
 #include "enums.h"
@@ -32,7 +33,7 @@
 #include "texstate.h"
 #include "mtypes.h"
 #include "varray.h"
-
+#include "dispatch.h"
 
 #ifndef GL_BOOLEAN
 #define GL_BOOLEAN 0x9999
@@ -58,7 +59,11 @@ update_array(GLcontext *ctx, struct gl_client_array *array,
    array->Ptr = (const GLubyte *) ptr;
 #if FEATURE_ARB_vertex_buffer_object
    array->BufferObj->RefCount--;
-   /* XXX free buffer object if RefCount == 0 ? */
+   if (array->BufferObj->RefCount <= 0) {
+      ASSERT(array->BufferObj->Name);
+      _mesa_remove_buffer_object( ctx, array->BufferObj );
+      (*ctx->Driver.DeleteBuffer)( ctx, array->BufferObj );
+   }
    array->BufferObj = ctx->Array.ArrayBufferObj;
    array->BufferObj->RefCount++;
    /* Compute the index of the last array element that's inside the buffer.
@@ -618,9 +623,9 @@ _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
    GLint tcomps, ccomps, vcomps;   /* components per texcoord, color, vertex */
    GLenum ctype = 0;               /* color type */
    GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
+   const GLint toffset = 0;        /* always zero */
    GLint defstride;                /* default stride */
    GLint c, f;
-   GLint coordUnitSave;
 
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
@@ -751,37 +756,20 @@ _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
    _mesa_DisableClientState( GL_INDEX_ARRAY );
 
    /* Texcoords */
-   coordUnitSave = ctx->Array.ActiveTexture;
    if (tflag) {
-      GLint i;
-      GLint factor = ctx->Array.TexCoordInterleaveFactor;
-      for (i = 0; i < factor; i++) {
-         _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + i) );
-         _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
-         _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
-                               (GLubyte *) pointer + i * coffset );
-      }
-      for (i = factor; i < (GLint) ctx->Const.MaxTextureCoordUnits; i++) {
-         _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + i) );
-         _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
-      }
+      _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
+      _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
+                             (GLubyte *) pointer + toffset );
    }
    else {
-      GLint i;
-      for (i = 0; i < (GLint) ctx->Const.MaxTextureCoordUnits; i++) {
-         _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + i) );
-         _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
-      }
+      _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
    }
-   /* Restore texture coordinate unit index */
-   _mesa_ClientActiveTextureARB( (GLenum) (GL_TEXTURE0_ARB + coordUnitSave) );
-
 
    /* Color */
    if (cflag) {
       _mesa_EnableClientState( GL_COLOR_ARRAY );
       _mesa_ColorPointer( ccomps, ctype, stride,
-                         (GLubyte*) pointer + coffset );
+                         (GLubyte *) pointer + coffset );
    }
    else {
       _mesa_DisableClientState( GL_COLOR_ARRAY );
@@ -791,13 +779,13 @@ _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
    /* Normals */
    if (nflag) {
       _mesa_EnableClientState( GL_NORMAL_ARRAY );
-      _mesa_NormalPointer( GL_FLOAT, stride,
-                          (GLubyte*) pointer + noffset );
+      _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
    }
    else {
       _mesa_DisableClientState( GL_NORMAL_ARRAY );
    }
 
+   /* Vertices */
    _mesa_EnableClientState( GL_VERTEX_ARRAY );
    _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
                        (GLubyte *) pointer + voffset );
@@ -863,7 +851,7 @@ _mesa_MultiDrawArraysEXT( GLenum mode, GLint *first,
 
    for (i = 0; i < primcount; i++) {
       if (count[i] > 0) {
-         (ctx->Exec->DrawArrays)(mode, first[i], count[i]);
+         CALL_DrawArrays(ctx->Exec, (mode, first[i], count[i]));
       }
    }
 }
@@ -879,15 +867,9 @@ _mesa_MultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type,
 
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
-   if (ctx->Array.ElementArrayBufferObj->Name) {
-      /* use indices in the buffer object */
-      ASSERT(ctx->Array.ElementArrayBufferObj->Data);
-      indices = (const GLvoid **) ctx->Array.ElementArrayBufferObj->Data;
-   }
-
    for (i = 0; i < primcount; i++) {
       if (count[i] > 0) {
-         (ctx->Exec->DrawElements)(mode, count[i], type, indices[i]);
+         CALL_DrawElements(ctx->Exec, (mode, count[i], type, indices[i]));
       }
    }
 }
@@ -906,8 +888,8 @@ _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
 
    for ( i = 0 ; i < primcount ; i++ ) {
       if ( count[i] > 0 ) {
-        (ctx->Exec->DrawArrays)( *(GLenum *) ((char *) mode + (i * modestride)),
-                                 first[i], count[i] );
+         GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
+        CALL_DrawArrays(ctx->Exec, ( m, first[i], count[i] ));
       }
    }
 }
@@ -928,8 +910,8 @@ _mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
 
    for ( i = 0 ; i < primcount ; i++ ) {
       if ( count[i] > 0 ) {
-        (ctx->Exec->DrawElements)( *(GLenum *) ((char *) mode + (i * modestride)),
-                                   count[i], type, indices[i] );
+         GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
+        CALL_DrawElements(ctx->Exec, ( m, count[i], type, indices[i] ));
       }
    }
 }
@@ -994,7 +976,6 @@ _mesa_init_varray( GLcontext * ctx )
       ctx->Array.TexCoord[i].Enabled = GL_FALSE;
       ctx->Array.TexCoord[i].Flags = CA_CLIENT_DATA;
    }
-   ctx->Array.TexCoordInterleaveFactor = 1;
    ctx->Array.EdgeFlag.Stride = 0;
    ctx->Array.EdgeFlag.StrideB = 0;
    ctx->Array.EdgeFlag.Ptr = NULL;