Minor tweaks to help out at a driver level.
[mesa.git] / src / mesa / main / api_arrayelt.c
index 98be1699eaf87668a1a98bb4f1d5f56d2dcdda9e..aefeadf228a16dde9b3ea7e9e6e0097aaa23f521 100644 (file)
@@ -1,10 +1,8 @@
-/* $Id: api_arrayelt.c,v 1.6 2002/01/14 16:06:35 brianp Exp $ */
-
 /*
  * Mesa 3-D graphics library
- * Version:  4.1
+ * Version:  5.1
  *
- * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2003  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"),
  */
 
 /* Author:
- *    Keith Whitwell <keith_whitwell@yahoo.com>
+ *    Keith Whitwell <keith@tungstengraphics.com>
  */
 
 #include "glheader.h"
 #include "api_arrayelt.h"
 #include "context.h"
 #include "glapi.h"
-#include "mem.h"
+#include "imports.h"
 #include "macros.h"
 #include "mtypes.h"
 
@@ -53,7 +51,7 @@ typedef struct {
 } AEarray;
 
 typedef struct {
-   AEtexarray texarrays[MAX_TEXTURE_UNITS+1];
+   AEtexarray texarrays[MAX_TEXTURE_COORD_UNITS + 1];
    AEarray arrays[32];
    GLuint NewState;
 } AEcontext;
@@ -63,7 +61,7 @@ typedef struct {
 
 static void (*colorfuncs[2][8])( const void * ) = {
    { (array_func)glColor3bv,
-     (array_func)glColor3ub,
+     (array_func)glColor3ubv,
      (array_func)glColor3sv,
      (array_func)glColor3usv,
      (array_func)glColor3iv,
@@ -72,7 +70,7 @@ static void (*colorfuncs[2][8])( const void * ) = {
      (array_func)glColor3dv },
 
    { (array_func)glColor4bv,
-     (array_func)glColor4ub,
+     (array_func)glColor4ubv,
      (array_func)glColor4sv,
      (array_func)glColor4usv,
      (array_func)glColor4iv,
@@ -252,6 +250,9 @@ static void (*fogcoordfuncs[8])( const void * ) = {
 
 GLboolean _ae_create_context( GLcontext *ctx )
 {
+   if (ctx->aelt_context)
+      return GL_TRUE;
+
    ctx->aelt_context = MALLOC( sizeof(AEcontext) );
    if (!ctx->aelt_context)
       return GL_FALSE;
@@ -275,9 +276,9 @@ static void _ae_update_state( GLcontext *ctx )
    AEcontext *actx = AE_CONTEXT(ctx);
    AEtexarray *ta = actx->texarrays;
    AEarray *aa = actx->arrays;
-   int i;
+   GLuint i;
 
-   for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++)
+   for (i = 0 ; i < ctx->Const.MaxTextureCoordUnits ; i++)
       if (ctx->Array.TexCoord[i].Enabled) {
         ta->unit = i;
         ta->array = &ctx->Array.TexCoord[i];
@@ -336,7 +337,7 @@ static void _ae_update_state( GLcontext *ctx )
 }
 
 
-void _ae_loopback_array_elt( GLint elt )
+void GLAPIENTRY _ae_loopback_array_elt( GLint elt )
 {
    GET_CURRENT_CONTEXT(ctx);
    AEcontext *actx = AE_CONTEXT(ctx);
@@ -347,13 +348,19 @@ void _ae_loopback_array_elt( GLint elt )
       _ae_update_state( ctx );
 
    for (ta = actx->texarrays ; ta->func ; ta++) {
-      ta->func( ta->unit, (char *)ta->array->Ptr + elt * ta->array->StrideB );
+      GLubyte *src = ta->array->BufferObj->Data
+                   + (GLuint) ta->array->Ptr
+                   + elt * ta->array->StrideB;
+      ta->func( ta->unit + GL_TEXTURE0_ARB, src);
    }
 
    /* Must be last
     */
    for (aa = actx->arrays ; aa->func ; aa++) {
-      aa->func( (char *)aa->array->Ptr + elt * aa->array->StrideB );
+      GLubyte *src = aa->array->BufferObj->Data
+                   + (GLuint) aa->array->Ptr
+                   + elt * aa->array->StrideB;
+      aa->func( src );
    }
 }