init secondary color to (0,0,0,1). remove some redundant initializations.
[mesa.git] / src / mesa / main / colortab.c
index bb457382705ea8b6090ba410862bbb480cf86b5b..a44f9a01c54b461559f423170e1004bea0dfa159 100644 (file)
@@ -1,10 +1,9 @@
-/* $Id: colortab.c,v 1.41 2001/07/14 17:53:04 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
- * Version:  3.5
+ * Version:  5.1
  *
- * Copyright (C) 1999-2001  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"),
  */
 
 
-#ifdef PC_HEADER
-#include "all.h"
-#else
 #include "glheader.h"
+#include "imports.h"
 #include "colortab.h"
 #include "context.h"
 #include "image.h"
 #include "macros.h"
-#include "mem.h"
-#include "mmath.h"
 #include "state.h"
-#include "swrast/s_span.h" /* XXX SWRAST hack */
-#endif
-
 
 
 /*
@@ -100,26 +92,6 @@ base_colortab_format( GLenum format )
 }
 
 
-void
-_mesa_init_colortable( struct gl_color_table *p )
-{
-   p->FloatTable = GL_FALSE;
-   p->Table = NULL;
-   p->Size = 0;
-   p->IntFormat = GL_RGBA;
-}
-
-
-
-void
-_mesa_free_colortable_data( struct gl_color_table *p )
-{
-   if (p->Table) {
-      FREE(p->Table);
-      p->Table = NULL;
-   }
-}
-
 
 /*
  * Examine table's format and set the component sizes accordingly.
@@ -183,7 +155,7 @@ set_component_sizes( struct gl_color_table *table )
 
 
 
-void
+void GLAPIENTRY
 _mesa_ColorTable( GLenum target, GLenum internalFormat,
                   GLsizei width, GLenum format, GLenum type,
                   const GLvoid *data )
@@ -213,6 +185,14 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat,
          texObj = texUnit->Current3D;
          table = &texObj->Palette;
          break;
+      case GL_TEXTURE_CUBE_MAP_ARB:
+         if (!ctx->Extensions.ARB_texture_cube_map) {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
+            return;
+         }
+         texObj = texUnit->CurrentCubeMap;
+         table = &texObj->Palette;
+         break;
       case GL_PROXY_TEXTURE_1D:
          texObj = ctx->Texture.Proxy1D;
          table = &texObj->Palette;
@@ -228,6 +208,14 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat,
          table = &texObj->Palette;
          proxy = GL_TRUE;
          break;
+      case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
+         if (!ctx->Extensions.ARB_texture_cube_map) {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
+            return;
+         }
+         texObj = ctx->Texture.ProxyCubeMap;
+         table = &texObj->Palette;
+         break;
       case GL_SHARED_TEXTURE_PALETTE_EXT:
          table = &ctx->Texture.Palette;
          break;
@@ -247,6 +235,30 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat,
          table = &ctx->ProxyColorTable;
          proxy = GL_TRUE;
          break;
+      case GL_TEXTURE_COLOR_TABLE_SGI:
+         if (!ctx->Extensions.SGI_texture_color_table) {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
+            return;
+         }
+         table = &(texUnit->ColorTable);
+         floatTable = GL_TRUE;
+         rScale = ctx->Pixel.TextureColorTableScale[0];
+         gScale = ctx->Pixel.TextureColorTableScale[1];
+         bScale = ctx->Pixel.TextureColorTableScale[2];
+         aScale = ctx->Pixel.TextureColorTableScale[3];
+         rBias = ctx->Pixel.TextureColorTableBias[0];
+         gBias = ctx->Pixel.TextureColorTableBias[1];
+         bBias = ctx->Pixel.TextureColorTableBias[2];
+         aBias = ctx->Pixel.TextureColorTableBias[3];
+         break;
+      case GL_PROXY_TEXTURE_COLOR_TABLE_SGI:
+         if (!ctx->Extensions.SGI_texture_color_table) {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
+            return;
+         }
+         table = &(texUnit->ProxyColorTable);
+         proxy = GL_TRUE;
+         break;
       case GL_POST_CONVOLUTION_COLOR_TABLE:
          table = &ctx->PostConvolutionColorTable;
          floatTable = GL_TRUE;
@@ -306,9 +318,7 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat,
          table->Format = (GLenum) 0;
       }
       else {
-         char msg[100];
-         sprintf(msg, "glColorTable(width=%d)", width);
-         _mesa_error(ctx, GL_INVALID_VALUE, msg);
+         _mesa_error(ctx, GL_INVALID_VALUE, "glColorTable(width=%d)", width);
       }
       return;
    }
@@ -429,7 +439,7 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat,
 
 
 
-void
+void GLAPIENTRY
 _mesa_ColorSubTable( GLenum target, GLsizei start,
                      GLsizei count, GLenum format, GLenum type,
                      const GLvoid *data )
@@ -456,6 +466,14 @@ _mesa_ColorSubTable( GLenum target, GLsizei start,
          texObj = texUnit->Current3D;
          table = &texObj->Palette;
          break;
+      case GL_TEXTURE_CUBE_MAP_ARB:
+         if (!ctx->Extensions.ARB_texture_cube_map) {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)");
+            return;
+         }
+         texObj = texUnit->CurrentCubeMap;
+         table = &texObj->Palette;
+         break;
       case GL_SHARED_TEXTURE_PALETTE_EXT:
          table = &ctx->Texture.Palette;
          break;
@@ -470,6 +488,21 @@ _mesa_ColorSubTable( GLenum target, GLsizei start,
          bBias = ctx->Pixel.ColorTableBias[2];
          aBias = ctx->Pixel.ColorTableBias[3];
          break;
+      case GL_TEXTURE_COLOR_TABLE_SGI:
+         if (!ctx->Extensions.SGI_texture_color_table) {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)");
+            return;
+         }
+         table = &(texUnit->ColorTable);
+         rScale = ctx->Pixel.TextureColorTableScale[0];
+         gScale = ctx->Pixel.TextureColorTableScale[1];
+         bScale = ctx->Pixel.TextureColorTableScale[2];
+         aScale = ctx->Pixel.TextureColorTableScale[3];
+         rBias = ctx->Pixel.TextureColorTableBias[0];
+         gBias = ctx->Pixel.TextureColorTableBias[1];
+         bBias = ctx->Pixel.TextureColorTableBias[2];
+         aBias = ctx->Pixel.TextureColorTableBias[3];
+         break;
       case GL_POST_CONVOLUTION_COLOR_TABLE:
          table = &ctx->PostConvolutionColorTable;
          rScale = ctx->Pixel.PCCTscale[0];
@@ -604,7 +637,7 @@ _mesa_ColorSubTable( GLenum target, GLsizei start,
 
 
 /* XXX not tested */
-void
+void GLAPIENTRY
 _mesa_CopyColorTable(GLenum target, GLenum internalformat,
                      GLint x, GLint y, GLsizei width)
 {
@@ -618,7 +651,7 @@ _mesa_CopyColorTable(GLenum target, GLenum internalformat,
 
 
 /* XXX not tested */
-void
+void GLAPIENTRY
 _mesa_CopyColorSubTable(GLenum target, GLsizei start,
                         GLint x, GLint y, GLsizei width)
 {
@@ -630,7 +663,7 @@ _mesa_CopyColorSubTable(GLenum target, GLsizei start,
 
 
 
-void
+void GLAPIENTRY
 _mesa_GetColorTable( GLenum target, GLenum format,
                      GLenum type, GLvoid *data )
 {
@@ -654,12 +687,26 @@ _mesa_GetColorTable( GLenum target, GLenum format,
       case GL_TEXTURE_3D:
          table = &texUnit->Current3D->Palette;
          break;
+      case GL_TEXTURE_CUBE_MAP_ARB:
+         if (!ctx->Extensions.ARB_texture_cube_map) {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
+            return;
+         }
+         table = &texUnit->CurrentCubeMap->Palette;
+         break;
       case GL_SHARED_TEXTURE_PALETTE_EXT:
          table = &ctx->Texture.Palette;
          break;
       case GL_COLOR_TABLE:
          table = &ctx->ColorTable;
          break;
+      case GL_TEXTURE_COLOR_TABLE_SGI:
+         if (!ctx->Extensions.SGI_texture_color_table) {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
+            return;
+         }
+         table = &(texUnit->ColorTable);
+         break;
       case GL_POST_CONVOLUTION_COLOR_TABLE:
          table = &ctx->PostConvolutionColorTable;
          break;
@@ -817,7 +864,7 @@ _mesa_GetColorTable( GLenum target, GLenum format,
 
 
 
-void
+void GLAPIENTRY
 _mesa_ColorTableParameterfv(GLenum target, GLenum pname, const GLfloat *params)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -842,6 +889,28 @@ _mesa_ColorTableParameterfv(GLenum target, GLenum pname, const GLfloat *params)
             return;
          }
          break;
+      case GL_TEXTURE_COLOR_TABLE_SGI:
+         if (!ctx->Extensions.SGI_texture_color_table) {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)");
+            return;
+         }
+         if (pname == GL_COLOR_TABLE_SCALE_SGI) {
+            ctx->Pixel.TextureColorTableScale[0] = params[0];
+            ctx->Pixel.TextureColorTableScale[1] = params[1];
+            ctx->Pixel.TextureColorTableScale[2] = params[2];
+            ctx->Pixel.TextureColorTableScale[3] = params[3];
+         }
+         else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
+            ctx->Pixel.TextureColorTableBias[0] = params[0];
+            ctx->Pixel.TextureColorTableBias[1] = params[1];
+            ctx->Pixel.TextureColorTableBias[2] = params[2];
+            ctx->Pixel.TextureColorTableBias[3] = params[3];
+         }
+         else {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
+            return;
+         }
+         break;
       case GL_POST_CONVOLUTION_COLOR_TABLE_SGI:
          if (pname == GL_COLOR_TABLE_SCALE_SGI) {
             ctx->Pixel.PCCTscale[0] = params[0];
@@ -888,11 +957,12 @@ _mesa_ColorTableParameterfv(GLenum target, GLenum pname, const GLfloat *params)
 
 
 
-void
+void GLAPIENTRY
 _mesa_ColorTableParameteriv(GLenum target, GLenum pname, const GLint *params)
 {
    GLfloat fparams[4];
    if (pname == GL_COLOR_TABLE_SGI ||
+       pname == GL_TEXTURE_COLOR_TABLE_SGI ||
        pname == GL_POST_CONVOLUTION_COLOR_TABLE_SGI ||
        pname == GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI) {
       /* four values */
@@ -910,7 +980,7 @@ _mesa_ColorTableParameteriv(GLenum target, GLenum pname, const GLint *params)
 
 
 
-void
+void GLAPIENTRY
 _mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -928,6 +998,14 @@ _mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params )
       case GL_TEXTURE_3D:
          table = &texUnit->Current3D->Palette;
          break;
+      case GL_TEXTURE_CUBE_MAP_ARB:
+         if (!ctx->Extensions.ARB_texture_cube_map) {
+            _mesa_error(ctx, GL_INVALID_ENUM,
+                        "glGetColorTableParameterfv(target)");
+            return;
+         }
+         table = &texUnit->CurrentCubeMap->Palette;
+         break;
       case GL_PROXY_TEXTURE_1D:
          table = &ctx->Texture.Proxy1D->Palette;
          break;
@@ -937,6 +1015,14 @@ _mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params )
       case GL_PROXY_TEXTURE_3D:
          table = &ctx->Texture.Proxy3D->Palette;
          break;
+      case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
+         if (!ctx->Extensions.ARB_texture_cube_map) {
+            _mesa_error(ctx, GL_INVALID_ENUM,
+                        "glGetColorTableParameterfv(target)");
+            return;
+         }
+         table = &ctx->Texture.ProxyCubeMap->Palette;
+         break;
       case GL_SHARED_TEXTURE_PALETTE_EXT:
          table = &ctx->Texture.Palette;
          break;
@@ -960,6 +1046,34 @@ _mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params )
       case GL_PROXY_COLOR_TABLE:
          table = &ctx->ProxyColorTable;
          break;
+      case GL_TEXTURE_COLOR_TABLE_SGI:
+         if (!ctx->Extensions.SGI_texture_color_table) {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
+            return;
+         }
+         table = &(texUnit->ColorTable);
+         if (pname == GL_COLOR_TABLE_SCALE_SGI) {
+            params[0] = ctx->Pixel.TextureColorTableScale[0];
+            params[1] = ctx->Pixel.TextureColorTableScale[1];
+            params[2] = ctx->Pixel.TextureColorTableScale[2];
+            params[3] = ctx->Pixel.TextureColorTableScale[3];
+            return;
+         }
+         else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
+            params[0] = ctx->Pixel.TextureColorTableBias[0];
+            params[1] = ctx->Pixel.TextureColorTableBias[1];
+            params[2] = ctx->Pixel.TextureColorTableBias[2];
+            params[3] = ctx->Pixel.TextureColorTableBias[3];
+            return;
+         }
+         break;
+      case GL_PROXY_TEXTURE_COLOR_TABLE_SGI:
+         if (!ctx->Extensions.SGI_texture_color_table) {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
+            return;
+         }
+         table = &(texUnit->ProxyColorTable);
+         break;
       case GL_POST_CONVOLUTION_COLOR_TABLE:
          table = &ctx->PostConvolutionColorTable;
          if (pname == GL_COLOR_TABLE_SCALE_SGI) {
@@ -1009,28 +1123,28 @@ _mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params )
 
    switch (pname) {
       case GL_COLOR_TABLE_FORMAT:
-         *params = table->IntFormat;
+         *params = (GLfloat) table->IntFormat;
          break;
       case GL_COLOR_TABLE_WIDTH:
-         *params = table->Size;
+         *params = (GLfloat) table->Size;
          break;
       case GL_COLOR_TABLE_RED_SIZE:
-         *params = table->RedSize;
+         *params = (GLfloat) table->RedSize;
          break;
       case GL_COLOR_TABLE_GREEN_SIZE:
-         *params = table->GreenSize;
+         *params = (GLfloat) table->GreenSize;
          break;
       case GL_COLOR_TABLE_BLUE_SIZE:
-         *params = table->BlueSize;
+         *params = (GLfloat) table->BlueSize;
          break;
       case GL_COLOR_TABLE_ALPHA_SIZE:
-         *params = table->AlphaSize;
+         *params = (GLfloat) table->AlphaSize;
          break;
       case GL_COLOR_TABLE_LUMINANCE_SIZE:
-         *params = table->LuminanceSize;
+         *params = (GLfloat) table->LuminanceSize;
          break;
       case GL_COLOR_TABLE_INTENSITY_SIZE:
-         *params = table->IntensitySize;
+         *params = (GLfloat) table->IntensitySize;
          break;
       default:
          _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(pname)" );
@@ -1040,7 +1154,7 @@ _mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params )
 
 
 
-void
+void GLAPIENTRY
 _mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -1058,6 +1172,14 @@ _mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params )
       case GL_TEXTURE_3D:
          table = &texUnit->Current3D->Palette;
          break;
+      case GL_TEXTURE_CUBE_MAP_ARB:
+         if (!ctx->Extensions.ARB_texture_cube_map) {
+            _mesa_error(ctx, GL_INVALID_ENUM,
+                        "glGetColorTableParameteriv(target)");
+            return;
+         }
+         table = &texUnit->CurrentCubeMap->Palette;
+         break;
       case GL_PROXY_TEXTURE_1D:
          table = &ctx->Texture.Proxy1D->Palette;
          break;
@@ -1067,6 +1189,14 @@ _mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params )
       case GL_PROXY_TEXTURE_3D:
          table = &ctx->Texture.Proxy3D->Palette;
          break;
+      case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
+         if (!ctx->Extensions.ARB_texture_cube_map) {
+            _mesa_error(ctx, GL_INVALID_ENUM,
+                        "glGetColorTableParameteriv(target)");
+            return;
+         }
+         table = &ctx->Texture.ProxyCubeMap->Palette;
+         break;
       case GL_SHARED_TEXTURE_PALETTE_EXT:
          table = &ctx->Texture.Palette;
          break;
@@ -1090,6 +1220,34 @@ _mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params )
       case GL_PROXY_COLOR_TABLE:
          table = &ctx->ProxyColorTable;
          break;
+      case GL_TEXTURE_COLOR_TABLE_SGI:
+         if (!ctx->Extensions.SGI_texture_color_table) {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
+            return;
+         }
+         table = &(texUnit->ColorTable);
+         if (pname == GL_COLOR_TABLE_SCALE_SGI) {
+            params[0] = (GLint) ctx->Pixel.TextureColorTableScale[0];
+            params[1] = (GLint) ctx->Pixel.TextureColorTableScale[1];
+            params[2] = (GLint) ctx->Pixel.TextureColorTableScale[2];
+            params[3] = (GLint) ctx->Pixel.TextureColorTableScale[3];
+            return;
+         }
+         else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
+            params[0] = (GLint) ctx->Pixel.TextureColorTableBias[0];
+            params[1] = (GLint) ctx->Pixel.TextureColorTableBias[1];
+            params[2] = (GLint) ctx->Pixel.TextureColorTableBias[2];
+            params[3] = (GLint) ctx->Pixel.TextureColorTableBias[3];
+            return;
+         }
+         break;
+      case GL_PROXY_TEXTURE_COLOR_TABLE_SGI:
+         if (!ctx->Extensions.SGI_texture_color_table) {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
+            return;
+         }
+         table = &(texUnit->ProxyColorTable);
+         break;
       case GL_POST_CONVOLUTION_COLOR_TABLE:
          table = &ctx->PostConvolutionColorTable;
          if (pname == GL_COLOR_TABLE_SCALE_SGI) {
@@ -1167,3 +1325,57 @@ _mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params )
          return;
    }
 }
+
+/**********************************************************************/
+/*****                      Initialization                        *****/
+/**********************************************************************/
+
+
+void
+_mesa_init_colortable( struct gl_color_table *p )
+{
+   p->FloatTable = GL_FALSE;
+   p->Table = NULL;
+   p->Size = 0;
+   p->IntFormat = GL_RGBA;
+}
+
+
+
+void
+_mesa_free_colortable_data( struct gl_color_table *p )
+{
+   if (p->Table) {
+      FREE(p->Table);
+      p->Table = NULL;
+   }
+}
+
+
+/*
+ * Initialize all colortables for a context.
+ */
+void _mesa_init_colortables( GLcontext * ctx )
+{
+   /* Color tables */
+   _mesa_init_colortable(&ctx->ColorTable);
+   _mesa_init_colortable(&ctx->ProxyColorTable);
+   _mesa_init_colortable(&ctx->PostConvolutionColorTable);
+   _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
+   _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
+   _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
+}
+
+
+/*
+ * Free all colortable data for a context
+ */
+void _mesa_free_colortables_data( GLcontext *ctx )
+{
+   _mesa_free_colortable_data(&ctx->ColorTable);
+   _mesa_free_colortable_data(&ctx->ProxyColorTable);
+   _mesa_free_colortable_data(&ctx->PostConvolutionColorTable);
+   _mesa_free_colortable_data(&ctx->ProxyPostConvolutionColorTable);
+   _mesa_free_colortable_data(&ctx->PostColorMatrixColorTable);
+   _mesa_free_colortable_data(&ctx->ProxyPostColorMatrixColorTable);
+}