Replace Proxy1D/2D/etc with ProxyTex[] indexed by TEXTURE_x_INDEX.
authorBrian <brian.paul@tungstengraphics.com>
Thu, 16 Aug 2007 10:06:13 +0000 (11:06 +0100)
committerBrian <brian.paul@tungstengraphics.com>
Thu, 16 Aug 2007 10:06:13 +0000 (11:06 +0100)
Simplification in colortab.c too.

src/mesa/drivers/dri/tdfx/tdfx_tex.c
src/mesa/main/colortab.c
src/mesa/main/mtypes.h
src/mesa/main/teximage.c
src/mesa/main/texstate.c

index 89865d963795edd990ace72cdd85de8b477022e3..64946385b6da07f9f8a51fb93710e512b50f4d16 100644 (file)
@@ -1822,7 +1822,7 @@ tdfxTestProxyTexImage(GLcontext *ctx, GLenum target,
             tdfxTexInfo *ti;
             int memNeeded;
 
-            tObj = ctx->Texture.Proxy2D;
+            tObj = ctx->Texture.ProxyTex[TEXTURE_2D_INDEX];
             if (!tObj->DriverData)
                 tObj->DriverData = fxAllocTexObjData(fxMesa);
             ti = TDFX_TEXTURE_DATA(tObj);
index 610acba3068aeaa42aed4eb61de551342b9be193..97120398f9b616453b485e40b32d20c7c4ee127f 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5.3
+ * Version:  7.1
  *
  * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
@@ -30,6 +30,7 @@
 #include "image.h"
 #include "macros.h"
 #include "state.h"
+#include "teximage.h"
 
 
 /**
@@ -305,49 +306,6 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat,
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex */
 
    switch (target) {
-      case GL_TEXTURE_1D:
-         texObj = texUnit->Current1D;
-         table = &texObj->Palette;
-         break;
-      case GL_TEXTURE_2D:
-         texObj = texUnit->Current2D;
-         table = &texObj->Palette;
-         break;
-      case GL_TEXTURE_3D:
-         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;
-         proxy = GL_TRUE;
-         break;
-      case GL_PROXY_TEXTURE_2D:
-         texObj = ctx->Texture.Proxy2D;
-         table = &texObj->Palette;
-         proxy = GL_TRUE;
-         break;
-      case GL_PROXY_TEXTURE_3D:
-         texObj = ctx->Texture.Proxy3D;
-         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;
@@ -396,8 +354,19 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat,
          proxy = GL_TRUE;
          break;
       default:
-         _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
-         return;
+         /* try texture targets */
+         {
+            struct gl_texture_object *texobj
+               = _mesa_select_tex_object(ctx, texUnit, target);
+            if (texobj) {
+               table = &texobj->Palette;
+               proxy = _mesa_is_proxy_texture(target);
+            }
+            else {
+               _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
+               return;
+            }
+         }
    }
 
    assert(table);
@@ -499,26 +468,6 @@ _mesa_ColorSubTable( GLenum target, GLsizei start,
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
    switch (target) {
-      case GL_TEXTURE_1D:
-         texObj = texUnit->Current1D;
-         table = &texObj->Palette;
-         break;
-      case GL_TEXTURE_2D:
-         texObj = texUnit->Current2D;
-         table = &texObj->Palette;
-         break;
-      case GL_TEXTURE_3D:
-         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;
@@ -547,8 +496,15 @@ _mesa_ColorSubTable( GLenum target, GLsizei start,
          bias = ctx->Pixel.ColorTableBias[COLORTABLE_POSTCOLORMATRIX];
          break;
       default:
-         _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)");
-         return;
+         /* try texture targets */
+         texObj = _mesa_select_tex_object(ctx, texUnit, target);
+         if (texObj && !_mesa_is_proxy_texture(target)) {
+            table = &texObj->Palette;
+         }
+         else {
+            _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)");
+            return;
+         }
    }
 
    assert(table);
@@ -636,22 +592,6 @@ _mesa_GetColorTable( GLenum target, GLenum format,
    }
 
    switch (target) {
-      case GL_TEXTURE_1D:
-         table = &texUnit->Current1D->Palette;
-         break;
-      case GL_TEXTURE_2D:
-         table = &texUnit->Current2D->Palette;
-         break;
-      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;
@@ -672,8 +612,18 @@ _mesa_GetColorTable( GLenum target, GLenum format,
          table = &ctx->ColorTable[COLORTABLE_POSTCOLORMATRIX];
          break;
       default:
-         _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
-         return;
+         /* try texture targets */
+         {
+            struct gl_texture_object *texobj
+               = _mesa_select_tex_object(ctx, texUnit, target);
+            if (texobj && !_mesa_is_proxy_texture(target)) {
+               table = &texobj->Palette;
+            }
+            else {
+               _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
+               return;
+            }
+         }
    }
 
    ASSERT(table);
@@ -781,65 +731,41 @@ _mesa_GetColorTable( GLenum target, GLenum format,
 void GLAPIENTRY
 _mesa_ColorTableParameterfv(GLenum target, GLenum pname, const GLfloat *params)
 {
+   GLfloat *scale, *bias;
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
    switch (target) {
-      case GL_COLOR_TABLE_SGI:
-         if (pname == GL_COLOR_TABLE_SCALE_SGI) {
-            COPY_4V(ctx->Pixel.ColorTableScale[COLORTABLE_PRECONVOLUTION], params);
-         }
-         else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
-            COPY_4V(ctx->Pixel.ColorTableBias[COLORTABLE_PRECONVOLUTION], params);
-         }
-         else {
-            _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
-            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) {
-            COPY_4V(ctx->Pixel.TextureColorTableScale, params);
-         }
-         else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
-            COPY_4V(ctx->Pixel.TextureColorTableBias, params);
-         }
-         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) {
-            COPY_4V(ctx->Pixel.ColorTableScale[COLORTABLE_POSTCONVOLUTION], params);
-         }
-         else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
-            COPY_4V(ctx->Pixel.ColorTableBias[COLORTABLE_POSTCONVOLUTION], params);
-         }
-         else {
-            _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
-            return;
-         }
-         break;
-      case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI:
-         if (pname == GL_COLOR_TABLE_SCALE_SGI) {
-            COPY_4V(ctx->Pixel.ColorTableScale[COLORTABLE_POSTCOLORMATRIX], params);
-         }
-         else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
-            COPY_4V(ctx->Pixel.ColorTableBias[COLORTABLE_POSTCOLORMATRIX], params);
-         }
-         else {
-            _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
-            return;
-         }
-         break;
-      default:
-         _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)");
-         return;
+   case GL_COLOR_TABLE_SGI:
+      scale = ctx->Pixel.ColorTableScale[COLORTABLE_PRECONVOLUTION];
+      bias  = ctx->Pixel.ColorTableBias[COLORTABLE_PRECONVOLUTION];
+      break;
+   case GL_TEXTURE_COLOR_TABLE_SGI:
+      scale = ctx->Pixel.TextureColorTableScale;
+      bias  = ctx->Pixel.TextureColorTableBias;
+      break;
+   case GL_POST_CONVOLUTION_COLOR_TABLE_SGI:
+      scale = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCONVOLUTION];
+      bias  = ctx->Pixel.ColorTableBias[COLORTABLE_POSTCONVOLUTION];
+      break;
+   case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI:
+      scale = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCOLORMATRIX];
+      bias  = ctx->Pixel.ColorTableBias[COLORTABLE_POSTCOLORMATRIX];
+      break;
+   default:
+      _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)");
+      return;
+   }
+
+   if (pname == GL_COLOR_TABLE_SCALE_SGI) {
+      COPY_4V(scale, params);
+   }
+   else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
+      COPY_4V(bias, params);
+   }
+   else {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
+      return;
    }
 
    ctx->NewState |= _NEW_PIXEL;
@@ -879,40 +805,6 @@ _mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params )
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    switch (target) {
-      case GL_TEXTURE_1D:
-         table = &texUnit->Current1D->Palette;
-         break;
-      case GL_TEXTURE_2D:
-         table = &texUnit->Current2D->Palette;
-         break;
-      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;
-      case GL_PROXY_TEXTURE_2D:
-         table = &ctx->Texture.Proxy2D->Palette;
-         break;
-      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;
@@ -981,8 +873,19 @@ _mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params )
          table = &ctx->ProxyColorTable[COLORTABLE_POSTCOLORMATRIX];
          break;
       default:
-         _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(target)");
-         return;
+         /* try texture targets */
+         {
+            struct gl_texture_object *texobj
+               = _mesa_select_tex_object(ctx, texUnit, target);
+            if (texobj) {
+               table = &texobj->Palette;
+            }
+            else {
+               _mesa_error(ctx, GL_INVALID_ENUM,
+                           "glGetColorTableParameterfv(target)");
+               return;
+            }
+         }
    }
 
    assert(table);
@@ -1029,40 +932,6 @@ _mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params )
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    switch (target) {
-      case GL_TEXTURE_1D:
-         table = &texUnit->Current1D->Palette;
-         break;
-      case GL_TEXTURE_2D:
-         table = &texUnit->Current2D->Palette;
-         break;
-      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;
-      case GL_PROXY_TEXTURE_2D:
-         table = &ctx->Texture.Proxy2D->Palette;
-         break;
-      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;
@@ -1161,8 +1030,19 @@ _mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params )
          table = &ctx->ProxyColorTable[COLORTABLE_POSTCOLORMATRIX];
          break;
       default:
-         _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(target)");
-         return;
+         /* Try texture targets */
+         {
+            struct gl_texture_object *texobj
+               = _mesa_select_tex_object(ctx, texUnit, target);
+            if (texobj) {
+               table = &texobj->Palette;
+            }
+            else {
+               _mesa_error(ctx, GL_INVALID_ENUM,
+                           "glGetColorTableParameteriv(target)");
+               return;
+            }
+         }
    }
 
    assert(table);
index 0f578c5616d87f25dd425b8876e20e561e052874..a04815a021c35df9d7f01f6eb9da88893b20ae56 100644 (file)
@@ -1576,6 +1576,7 @@ struct gl_texture_attrib
 
    struct gl_texture_unit Unit[MAX_TEXTURE_UNITS];
 
+#if 0
    struct gl_texture_object *Proxy1D;
    struct gl_texture_object *Proxy2D;
    struct gl_texture_object *Proxy3D;
@@ -1583,6 +1584,9 @@ struct gl_texture_attrib
    struct gl_texture_object *ProxyRect;
    struct gl_texture_object *Proxy1DArray;
    struct gl_texture_object *Proxy2DArray;
+#else
+   struct gl_texture_object *ProxyTex[NUM_TEXTURE_TARGETS];
+#endif
 
    /** GL_EXT_shared_texture_palette */
    GLboolean SharedPalette;
index 3420d8e2bafd675a6dfa5c4dd679ddf135dd97dc..56322f87af14d7e01e1ca17fed5a2fe5df425155 100644 (file)
@@ -760,15 +760,15 @@ _mesa_select_tex_object(GLcontext *ctx, const struct gl_texture_unit *texUnit,
       case GL_TEXTURE_1D:
          return texUnit->Current1D;
       case GL_PROXY_TEXTURE_1D:
-         return ctx->Texture.Proxy1D;
+         return ctx->Texture.ProxyTex[TEXTURE_1D_INDEX];
       case GL_TEXTURE_2D:
          return texUnit->Current2D;
       case GL_PROXY_TEXTURE_2D:
-         return ctx->Texture.Proxy2D;
+         return ctx->Texture.ProxyTex[TEXTURE_2D_INDEX];
       case GL_TEXTURE_3D:
          return texUnit->Current3D;
       case GL_PROXY_TEXTURE_3D:
-         return ctx->Texture.Proxy3D;
+         return ctx->Texture.ProxyTex[TEXTURE_3D_INDEX];
       case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
       case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
       case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
@@ -780,25 +780,25 @@ _mesa_select_tex_object(GLcontext *ctx, const struct gl_texture_unit *texUnit,
                 ? texUnit->CurrentCubeMap : NULL;
       case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
          return ctx->Extensions.ARB_texture_cube_map
-                ? ctx->Texture.ProxyCubeMap : NULL;
+                ? ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX] : NULL;
       case GL_TEXTURE_RECTANGLE_NV:
          return ctx->Extensions.NV_texture_rectangle
                 ? texUnit->CurrentRect : NULL;
       case GL_PROXY_TEXTURE_RECTANGLE_NV:
          return ctx->Extensions.NV_texture_rectangle
-                ? ctx->Texture.ProxyRect : NULL;
+                ? ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX] : NULL;
       case GL_TEXTURE_1D_ARRAY_EXT:
          return ctx->Extensions.MESA_texture_array
                 ? texUnit->Current1DArray : NULL;
       case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
          return ctx->Extensions.MESA_texture_array
-                ? ctx->Texture.Proxy1DArray : NULL;
+                ? ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX] : NULL;
       case GL_TEXTURE_2D_ARRAY_EXT:
          return ctx->Extensions.MESA_texture_array
                 ? texUnit->Current2DArray : NULL;
       case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
          return ctx->Extensions.MESA_texture_array
-                ? ctx->Texture.Proxy2DArray : NULL;
+                ? ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX] : NULL;
       default:
          _mesa_problem(NULL, "bad target in _mesa_select_tex_object()");
          return NULL;
@@ -924,106 +924,106 @@ _mesa_get_proxy_tex_image(GLcontext *ctx, GLenum target, GLint level)
    case GL_PROXY_TEXTURE_1D:
       if (level >= ctx->Const.MaxTextureLevels)
          return NULL;
-      texImage = ctx->Texture.Proxy1D->Image[0][level];
+      texImage = ctx->Texture.ProxyTex[TEXTURE_1D_INDEX]->Image[0][level];
       if (!texImage) {
          texImage = ctx->Driver.NewTextureImage(ctx);
          if (!texImage) {
             _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
             return NULL;
          }
-         ctx->Texture.Proxy1D->Image[0][level] = texImage;
+         ctx->Texture.ProxyTex[TEXTURE_1D_INDEX]->Image[0][level] = texImage;
          /* Set the 'back' pointer */
-         texImage->TexObject = ctx->Texture.Proxy1D;
+         texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_1D_INDEX];
       }
       return texImage;
    case GL_PROXY_TEXTURE_2D:
       if (level >= ctx->Const.MaxTextureLevels)
          return NULL;
-      texImage = ctx->Texture.Proxy2D->Image[0][level];
+      texImage = ctx->Texture.ProxyTex[TEXTURE_2D_INDEX]->Image[0][level];
       if (!texImage) {
          texImage = ctx->Driver.NewTextureImage(ctx);
          if (!texImage) {
             _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
             return NULL;
          }
-         ctx->Texture.Proxy2D->Image[0][level] = texImage;
+         ctx->Texture.ProxyTex[TEXTURE_2D_INDEX]->Image[0][level] = texImage;
          /* Set the 'back' pointer */
-         texImage->TexObject = ctx->Texture.Proxy2D;
+         texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_2D_INDEX];
       }
       return texImage;
    case GL_PROXY_TEXTURE_3D:
       if (level >= ctx->Const.Max3DTextureLevels)
          return NULL;
-      texImage = ctx->Texture.Proxy3D->Image[0][level];
+      texImage = ctx->Texture.ProxyTex[TEXTURE_3D_INDEX]->Image[0][level];
       if (!texImage) {
          texImage = ctx->Driver.NewTextureImage(ctx);
          if (!texImage) {
             _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
             return NULL;
          }
-         ctx->Texture.Proxy3D->Image[0][level] = texImage;
+         ctx->Texture.ProxyTex[TEXTURE_3D_INDEX]->Image[0][level] = texImage;
          /* Set the 'back' pointer */
-         texImage->TexObject = ctx->Texture.Proxy3D;
+         texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_3D_INDEX];
       }
       return texImage;
    case GL_PROXY_TEXTURE_CUBE_MAP:
       if (level >= ctx->Const.MaxCubeTextureLevels)
          return NULL;
-      texImage = ctx->Texture.ProxyCubeMap->Image[0][level];
+      texImage = ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX]->Image[0][level];
       if (!texImage) {
          texImage = ctx->Driver.NewTextureImage(ctx);
          if (!texImage) {
             _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
             return NULL;
          }
-         ctx->Texture.ProxyCubeMap->Image[0][level] = texImage;
+         ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX]->Image[0][level] = texImage;
          /* Set the 'back' pointer */
-         texImage->TexObject = ctx->Texture.ProxyCubeMap;
+         texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX];
       }
       return texImage;
    case GL_PROXY_TEXTURE_RECTANGLE_NV:
       if (level > 0)
          return NULL;
-      texImage = ctx->Texture.ProxyRect->Image[0][level];
+      texImage = ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX]->Image[0][level];
       if (!texImage) {
          texImage = ctx->Driver.NewTextureImage(ctx);
          if (!texImage) {
             _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
             return NULL;
          }
-         ctx->Texture.ProxyRect->Image[0][level] = texImage;
+         ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX]->Image[0][level] = texImage;
          /* Set the 'back' pointer */
-         texImage->TexObject = ctx->Texture.ProxyRect;
+         texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX];
       }
       return texImage;
    case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
       if (level >= ctx->Const.MaxTextureLevels)
          return NULL;
-      texImage = ctx->Texture.Proxy1DArray->Image[0][level];
+      texImage = ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX]->Image[0][level];
       if (!texImage) {
          texImage = ctx->Driver.NewTextureImage(ctx);
          if (!texImage) {
             _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
             return NULL;
          }
-         ctx->Texture.Proxy1DArray->Image[0][level] = texImage;
+         ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX]->Image[0][level] = texImage;
          /* Set the 'back' pointer */
-         texImage->TexObject = ctx->Texture.Proxy1DArray;
+         texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX];
       }
       return texImage;
    case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
       if (level >= ctx->Const.MaxTextureLevels)
          return NULL;
-      texImage = ctx->Texture.Proxy2DArray->Image[0][level];
+      texImage = ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX]->Image[0][level];
       if (!texImage) {
          texImage = ctx->Driver.NewTextureImage(ctx);
          if (!texImage) {
             _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
             return NULL;
          }
-         ctx->Texture.Proxy2DArray->Image[0][level] = texImage;
+         ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX]->Image[0][level] = texImage;
          /* Set the 'back' pointer */
-         texImage->TexObject = ctx->Texture.Proxy2DArray;
+         texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX];
       }
       return texImage;
    default:
@@ -2591,7 +2591,7 @@ _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat,
                               1, border)) {
          /* when error, clear all proxy texture image parameters */
          if (texImage)
-            clear_teximage_fields(ctx->Texture.Proxy2D->Image[0][level]);
+            clear_teximage_fields(ctx->Texture.ProxyTex[TEXTURE_2D_INDEX]->Image[0][level]);
       }
       else {
          /* no error, set the tex image parameters */
index 91ee6513dcf56026adcef41f2c0c57253a87755a..020e3eef4c0e3c0fc1e8765fa6a91709753c9934 100644 (file)
@@ -3060,54 +3060,32 @@ _mesa_update_texture( GLcontext *ctx, GLuint new_state )
 static GLboolean
 alloc_proxy_textures( GLcontext *ctx )
 {
-   ctx->Texture.Proxy1D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D);
-   if (!ctx->Texture.Proxy1D)
-      goto cleanup;
-
-   ctx->Texture.Proxy2D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_2D);
-   if (!ctx->Texture.Proxy2D)
-      goto cleanup;
-
-   ctx->Texture.Proxy3D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_3D);
-   if (!ctx->Texture.Proxy3D)
-      goto cleanup;
-
-   ctx->Texture.ProxyCubeMap = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_CUBE_MAP_ARB);
-   if (!ctx->Texture.ProxyCubeMap)
-      goto cleanup;
-
-   ctx->Texture.ProxyRect = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_RECTANGLE_NV);
-   if (!ctx->Texture.ProxyRect)
-      goto cleanup;
-
-   ctx->Texture.Proxy1DArray = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D_ARRAY_EXT);
-   if (!ctx->Texture.Proxy1DArray)
-      goto cleanup;
-
-   ctx->Texture.Proxy2DArray = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_2D_ARRAY_EXT);
-   if (!ctx->Texture.Proxy2DArray)
-      goto cleanup;
-
-   assert(ctx->Texture.Proxy1D->RefCount == 1);
+   static const GLenum targets[] = {
+      GL_TEXTURE_1D,
+      GL_TEXTURE_2D,
+      GL_TEXTURE_3D,
+      GL_TEXTURE_CUBE_MAP_ARB,
+      GL_TEXTURE_RECTANGLE_NV,
+      GL_TEXTURE_1D_ARRAY_EXT,
+      GL_TEXTURE_2D_ARRAY_EXT
+   };
+   GLint tgt;
+
+   ASSERT(Elements(targets) == NUM_TEXTURE_TARGETS);
+
+   for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
+      if (!(ctx->Texture.ProxyTex[tgt]
+            = ctx->Driver.NewTextureObject(ctx, 0, targets[tgt]))) {
+         /* out of memory, free what we did allocate */
+         while (--tgt >= 0) {
+            ctx->Driver.DeleteTexture(ctx, ctx->Texture.ProxyTex[tgt]);
+         }
+         return GL_FALSE;
+      }
+   }
 
+   assert(ctx->Texture.ProxyTex[0]->RefCount == 1); /* sanity check */
    return GL_TRUE;
-
- cleanup:
-   if (ctx->Texture.Proxy1D)
-      (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy1D);
-   if (ctx->Texture.Proxy2D)
-      (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy2D);
-   if (ctx->Texture.Proxy3D)
-      (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy3D);
-   if (ctx->Texture.ProxyCubeMap)
-      (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.ProxyCubeMap);
-   if (ctx->Texture.ProxyRect)
-      (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.ProxyRect);
-   if (ctx->Texture.Proxy1DArray)
-      (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy1DArray);
-   if (ctx->Texture.Proxy2DArray)
-      (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy2DArray);
-   return GL_FALSE;
 }
 
 
@@ -3201,7 +3179,7 @@ _mesa_init_texture(GLcontext *ctx)
 void
 _mesa_free_texture_data(GLcontext *ctx)
 {
-   GLuint u;
+   GLuint u, tgt;
 
    /* unreference current textures */
    for (u = 0; u < MAX_TEXTURE_IMAGE_UNITS; u++) {
@@ -3216,13 +3194,8 @@ _mesa_free_texture_data(GLcontext *ctx)
    }
 
    /* Free proxy texture objects */
-   (ctx->Driver.DeleteTexture)(ctx,  ctx->Texture.Proxy1D );
-   (ctx->Driver.DeleteTexture)(ctx,  ctx->Texture.Proxy2D );
-   (ctx->Driver.DeleteTexture)(ctx,  ctx->Texture.Proxy3D );
-   (ctx->Driver.DeleteTexture)(ctx,  ctx->Texture.ProxyCubeMap );
-   (ctx->Driver.DeleteTexture)(ctx,  ctx->Texture.ProxyRect );
-   (ctx->Driver.DeleteTexture)(ctx,  ctx->Texture.Proxy1DArray );
-   (ctx->Driver.DeleteTexture)(ctx,  ctx->Texture.Proxy2DArray );
+   for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++)
+      ctx->Driver.DeleteTexture(ctx, ctx->Texture.ProxyTex[tgt]);
 
    for (u = 0; u < MAX_TEXTURE_IMAGE_UNITS; u++)
       _mesa_free_colortable_data( &ctx->Texture.Unit[u].ColorTable );