Support ARB_texture_env_crossbar. Changes the way programs are
[mesa.git] / src / mesa / main / colortab.c
index 862f210bb984ad1bf443bd38a6e5a5061474b44a..600ebd2fb99b313e779f915865932e118bd5986a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.1
+ * Version:  6.3
  *
  * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
  *
@@ -24,7 +24,7 @@
 
 
 #include "glheader.h"
-#include "imports.h"
+#include "bufferobj.h"
 #include "colortab.h"
 #include "context.h"
 #include "image.h"
@@ -175,11 +175,11 @@ set_component_sizes( struct gl_color_table *table )
  * Update/replace all or part of a color table.  Helper function
  * used by _mesa_ColorTable() and _mesa_ColorSubTable().
  * The table->Table buffer should already be allocated.
- * \param start first entry to update
- * \param count number of entries to update
- * \param format format of user-provided table data
- * \param type datatype of user-provided table data
- * \param data user-provided table data
+ * \param start first entry to update
+ * \param count number of entries to update
+ * \param format format of user-provided table data
+ * \param type datatype of user-provided table data
+ * \param data user-provided table data
  * \param [rgba]Scale - RGBA scale factors
  * \param [rgba]Bias - RGBA bias factors
  */
@@ -192,6 +192,27 @@ store_colortable_entries(GLcontext *ctx, struct gl_color_table *table,
                         GLfloat bScale, GLfloat bBias,
                         GLfloat aScale, GLfloat aBias)
 {
+   if (ctx->Unpack.BufferObj->Name) {
+      /* Get/unpack the color table data from a PBO */
+      GLubyte *buf;
+      if (!_mesa_validate_pbo_access(1, &ctx->Unpack, count, 1, 1,
+                                     format, type, data)) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "glColor[Sub]Table(bad PBO access)");
+         return;
+      }
+      buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
+                                              GL_READ_ONLY_ARB,
+                                              ctx->Unpack.BufferObj);
+      if (!buf) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "glColor[Sub]Table(PBO mapped)");
+         return;
+      }
+      data = ADD_POINTERS(buf, data);
+   }
+
+
    if (table->Type == GL_FLOAT) {
       /* convert user-provided data to GLfloat values */
       GLfloat tempTab[MAX_COLOR_TABLE_SIZE * 4];
@@ -199,15 +220,18 @@ store_colortable_entries(GLcontext *ctx, struct gl_color_table *table,
       GLint i;
 
       _mesa_unpack_color_span_float(ctx,
-                                   count,          /* number of pixels */
-                                   table->Format,  /* dest format */
-                                    tempTab,        /* dest address */
-                                    format, type, data, /* src data */
-                                   &ctx->Unpack,
+                                    count,         /* number of pixels */
+                                    table->Format, /* dest format */
+                                    tempTab,       /* dest address */
+                                    format, type,  /* src format/type */
+                                    data,          /* src data */
+                                    &ctx->Unpack,
                                     IMAGE_CLAMP_BIT); /* transfer ops */
 
+      /* the destination */
       tableF = (GLfloat *) table->Table;
 
+      /* Apply scale & bias & clamp now */
       switch (table->Format) {
          case GL_INTENSITY:
             for (i = 0; i < count; i++) {
@@ -267,6 +291,11 @@ store_colortable_entries(GLcontext *ctx, struct gl_color_table *table,
                                   &ctx->Unpack,
                                   0);                 /* transfer ops */
    }
+
+   if (ctx->Unpack.BufferObj->Name) {
+      ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
+                              ctx->Unpack.BufferObj);
+   }
 }
 
 
@@ -414,7 +443,7 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat,
 
    assert(table);
 
-   if (!_mesa_is_legal_format_and_type(format, type) ||
+   if (!_mesa_is_legal_format_and_type(ctx, format, type) ||
        format == GL_INTENSITY) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glColorTable(format or type)");
       return;
@@ -454,7 +483,6 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat,
    table->Size = width;
    table->IntFormat = internalFormat;
    table->Format = (GLenum) baseFormat;
-   set_component_sizes(table);
 
    comps = _mesa_components_in_format(table->Format);
    assert(comps > 0);  /* error should have been caught sooner */
@@ -491,6 +519,9 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat,
       }
    } /* proxy */
 
+   /* do this after the table's Type and Format are set */
+   set_component_sizes(table);
+
    if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) {
       /* texture object palette, texObj==NULL means the shared palette */
       if (ctx->Driver.UpdateTexturePalette) {
@@ -514,7 +545,6 @@ _mesa_ColorSubTable( GLenum target, GLsizei start,
    struct gl_color_table *table = NULL;
    GLfloat rScale = 1.0, gScale = 1.0, bScale = 1.0, aScale = 1.0;
    GLfloat rBias  = 0.0, gBias  = 0.0, bBias  = 0.0, aBias  = 0.0;
-   GLint comps;
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
    switch (target) {
@@ -596,7 +626,7 @@ _mesa_ColorSubTable( GLenum target, GLsizei start,
 
    assert(table);
 
-   if (!_mesa_is_legal_format_and_type(format, type) ||
+   if (!_mesa_is_legal_format_and_type(ctx, format, type) ||
        format == GL_INTENSITY) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glColorSubTable(format or type)");
       return;
@@ -607,8 +637,8 @@ _mesa_ColorSubTable( GLenum target, GLsizei start,
       return;
    }
 
-   comps = _mesa_components_in_format(table->Format);
-   assert(comps > 0);  /* error should have been caught sooner */
+   /* error should have been caught sooner */
+   assert(_mesa_components_in_format(table->Format) > 0);
 
    if (start + count > (GLint) table->Size) {
       _mesa_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)");
@@ -639,7 +669,6 @@ _mesa_ColorSubTable( GLenum target, GLsizei start,
 
 
 
-/* XXX not tested */
 void GLAPIENTRY
 _mesa_CopyColorTable(GLenum target, GLenum internalformat,
                      GLint x, GLint y, GLsizei width)
@@ -653,7 +682,6 @@ _mesa_CopyColorTable(GLenum target, GLenum internalformat,
 
 
 
-/* XXX not tested */
 void GLAPIENTRY
 _mesa_CopyColorSubTable(GLenum target, GLsizei start,
                         GLint x, GLint y, GLsizei width)
@@ -861,8 +889,34 @@ _mesa_GetColorTable( GLenum target, GLenum format,
          return;
    }
 
+   if (ctx->Pack.BufferObj->Name) {
+      /* pack color table into PBO */
+      GLubyte *buf;
+      if (!_mesa_validate_pbo_access(1, &ctx->Pack, table->Size, 1, 1,
+                                     format, type, data)) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "glGetColorTable(invalid PBO access)");
+         return;
+      }
+      buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
+                                              GL_WRITE_ONLY_ARB,
+                                              ctx->Pack.BufferObj);
+      if (!buf) {
+         /* buffer is already mapped - that's an error */
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "glGetColorTable(PBO is mapped)");
+         return;
+      }
+      data = ADD_POINTERS(buf, data);
+   }
+
    _mesa_pack_rgba_span_chan(ctx, table->Size, (const GLchan (*)[4]) rgba,
                         format, type, data, &ctx->Pack, GL_FALSE);
+
+   if (ctx->Pack.BufferObj->Name) {
+      ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
+                              ctx->Pack.BufferObj);
+   }
 }