mesa: don't include m_xform.h where not needed
[mesa.git] / src / mesa / main / enable.c
index bf86e6db7d2db5fa203f1aec819819c44cf2a6fb..7ff3b15c8465368d021329e65c97494ce028c302 100644 (file)
@@ -5,9 +5,9 @@
 
 /*
  * Mesa 3-D graphics library
- * Version:  6.5.1
+ * Version:  7.0.3
  *
- * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2007  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"),
@@ -37,7 +37,7 @@
 #include "mtypes.h"
 #include "enums.h"
 #include "math/m_matrix.h"
-#include "math/m_xform.h"
+#include "api_arrayelt.h"
 
 
 
    }
 
 
+/**
+ * Helper to enable/disable client-side state.
+ */
 static void
-client_state( GLcontext *ctx, GLenum cap, GLboolean state )
+client_state(GLcontext *ctx, GLenum cap, GLboolean state)
 {
    GLuint flag;
    GLboolean *var;
@@ -89,6 +92,13 @@ client_state( GLcontext *ctx, GLenum cap, GLboolean state )
          flag = _NEW_ARRAY_COLOR1;
          break;
 
+#if FEATURE_point_size_array
+      case GL_POINT_SIZE_ARRAY_OES:
+         var = &ctx->Array.ArrayObj->PointSize.Enabled;
+         flag = _NEW_ARRAY_POINT_SIZE;
+         break;
+#endif
+
 #if FEATURE_NV_vertex_program
       case GL_VERTEX_ATTRIB_ARRAY0_NV:
       case GL_VERTEX_ATTRIB_ARRAY1_NV:
@@ -126,6 +136,9 @@ client_state( GLcontext *ctx, GLenum cap, GLboolean state )
 
    FLUSH_VERTICES(ctx, _NEW_ARRAY);
    ctx->Array.NewState |= flag;
+
+   _ae_invalidate_state(ctx, _NEW_ARRAY);
+
    *var = state;
 
    if (state)
@@ -134,17 +147,14 @@ client_state( GLcontext *ctx, GLenum cap, GLboolean state )
       ctx->Array.ArrayObj->_Enabled &= ~flag;
 
    if (ctx->Driver.Enable) {
-      (*ctx->Driver.Enable)( ctx, cap, state );
+      ctx->Driver.Enable( ctx, cap, state );
    }
 }
 
 
 /**
  * Enable GL capability.
- *
- * \param cap capability.
- *
- * \sa glEnable().
+ * \param cap  state to enable/disable.
  *
  * Get's the current context, assures that we're outside glBegin()/glEnd() and
  * calls client_state().
@@ -160,10 +170,7 @@ _mesa_EnableClientState( GLenum cap )
 
 /**
  * Disable GL capability.
- *
- * \param cap capability.
- *
- * \sa glDisable().
+ * \param cap  state to enable/disable.
  *
  * Get's the current context, assures that we're outside glBegin()/glEnd() and
  * calls client_state().
@@ -195,10 +202,49 @@ _mesa_DisableClientState( GLenum cap )
 
 
 /**
- * Perform glEnable() and glDisable() calls.
+ * Return pointer to current texture unit for setting/getting coordinate
+ * state.
+ * Note that we'll set GL_INVALID_OPERATION if the active texture unit is
+ * higher than the number of supported coordinate units.  And we'll return NULL.
+ */
+static struct gl_texture_unit *
+get_texcoord_unit(GLcontext *ctx)
+{
+   if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glEnable/Disable(texcoord unit)");
+      return NULL;
+   }
+   else {
+      return &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+   }
+}
+
+
+/**
+ * Helper function to enable or disable a texture target.
+ */
+static GLboolean
+enable_texture(GLcontext *ctx, GLboolean state, GLbitfield bit)
+{
+   const GLuint curr = ctx->Texture.CurrentUnit;
+   struct gl_texture_unit *texUnit = &ctx->Texture.Unit[curr];
+   const GLuint newenabled = (!state)
+       ? (texUnit->Enabled & ~bit) :  (texUnit->Enabled | bit);
+
+   if (!ctx->DrawBuffer->Visual.rgbMode || texUnit->Enabled == newenabled)
+       return GL_FALSE;
+
+   FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+   texUnit->Enabled = newenabled;
+   return GL_TRUE;
+}
+
+
+/**
+ * Helper function to enable or disable state.
  *
  * \param ctx GL context.
- * \param cap capability.
+ * \param cap  the state to enable/disable
  * \param state whether to enable or disable the specified capability.
  *
  * Updates the current context and flushes the vertices as needed. For
@@ -206,7 +252,8 @@ _mesa_DisableClientState( GLenum cap )
  * are effectivly present before updating. Notifies the driver via
  * dd_function_table::Enable.
  */
-void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
+void
+_mesa_set_enable(GLcontext *ctx, GLenum cap, GLboolean state)
 {
    if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx, "%s %s (newstate is %x)\n",
@@ -285,7 +332,6 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
          FLUSH_VERTICES(ctx, _NEW_POLYGON);
          ctx->Polygon.CullFlag = state;
          break;
-
       case GL_CULL_VERTEX_EXT:
          CHECK_EXTENSION(EXT_cull_vertex, cap);
          if (ctx->Transform.CullVertexFlag == state)
@@ -293,13 +339,8 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
          FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
          ctx->Transform.CullVertexFlag = state;
          break;
-
       case GL_DEPTH_TEST:
-         if (state && ctx->DrawBuffer->Visual.depthBits == 0) {
-            _mesa_warning(ctx,"glEnable(GL_DEPTH_TEST) but no depth buffer");
-            return;
-         }
-         if (ctx->Depth.Test==state)
+         if (ctx->Depth.Test == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_DEPTH);
          ctx->Depth.Test = state;
@@ -308,13 +349,13 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
          if (ctx->NoDither) {
             state = GL_FALSE; /* MESA_NO_DITHER env var */
          }
-         if (ctx->Color.DitherFlag==state)
+         if (ctx->Color.DitherFlag == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_COLOR);
          ctx->Color.DitherFlag = state;
          break;
       case GL_FOG:
-         if (ctx->Fog.Enabled==state)
+         if (ctx->Fog.Enabled == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_FOG);
          ctx->Fog.Enabled = state;
@@ -351,12 +392,10 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
             return;
          FLUSH_VERTICES(ctx, _NEW_LIGHT);
          ctx->Light.Enabled = state;
-
          if (ctx->Light.Enabled && ctx->Light.Model.TwoSide)
-          ctx->_TriangleCaps |= DD_TRI_LIGHT_TWOSIDE;
+            ctx->_TriangleCaps |= DD_TRI_LIGHT_TWOSIDE;
          else
-          ctx->_TriangleCaps &= ~DD_TRI_LIGHT_TWOSIDE;
+            ctx->_TriangleCaps &= ~DD_TRI_LIGHT_TWOSIDE;
          break;
       case GL_LINE_SMOOTH:
          if (ctx->Line.SmoothFlag == state)
@@ -505,41 +544,41 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
          ctx->Transform.Normalize = state;
          break;
       case GL_POINT_SMOOTH:
-         if (ctx->Point.SmoothFlag==state)
+         if (ctx->Point.SmoothFlag == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_POINT);
          ctx->Point.SmoothFlag = state;
          ctx->_TriangleCaps ^= DD_POINT_SMOOTH;
          break;
       case GL_POLYGON_SMOOTH:
-         if (ctx->Polygon.SmoothFlag==state)
+         if (ctx->Polygon.SmoothFlag == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_POLYGON);
          ctx->Polygon.SmoothFlag = state;
          ctx->_TriangleCaps ^= DD_TRI_SMOOTH;
          break;
       case GL_POLYGON_STIPPLE:
-         if (ctx->Polygon.StippleFlag==state)
+         if (ctx->Polygon.StippleFlag == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_POLYGON);
          ctx->Polygon.StippleFlag = state;
          ctx->_TriangleCaps ^= DD_TRI_STIPPLE;
          break;
       case GL_POLYGON_OFFSET_POINT:
-         if (ctx->Polygon.OffsetPoint==state)
+         if (ctx->Polygon.OffsetPoint == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_POLYGON);
          ctx->Polygon.OffsetPoint = state;
          break;
       case GL_POLYGON_OFFSET_LINE:
-         if (ctx->Polygon.OffsetLine==state)
+         if (ctx->Polygon.OffsetLine == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_POLYGON);
          ctx->Polygon.OffsetLine = state;
          break;
       case GL_POLYGON_OFFSET_FILL:
          /*case GL_POLYGON_OFFSET_EXT:*/
-         if (ctx->Polygon.OffsetFill==state)
+         if (ctx->Polygon.OffsetFill == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_POLYGON);
          ctx->Polygon.OffsetFill = state;
@@ -551,7 +590,7 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
          ctx->Transform.RescaleNormals = state;
          break;
       case GL_SCISSOR_TEST:
-         if (ctx->Scissor.Enabled==state)
+         if (ctx->Scissor.Enabled == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_SCISSOR);
          ctx->Scissor.Enabled = state;
@@ -568,98 +607,82 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
                           "glEnable(GL_STENCIL_TEST) but no stencil buffer");
             return;
          }
-         if (ctx->Stencil.Enabled==state)
+         if (ctx->Stencil.Enabled == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_STENCIL);
          ctx->Stencil.Enabled = state;
          break;
-      case GL_TEXTURE_1D: {
-         const GLuint curr = ctx->Texture.CurrentUnit;
-         struct gl_texture_unit *texUnit = &ctx->Texture.Unit[curr];
-         GLuint newenabled = texUnit->Enabled & ~TEXTURE_1D_BIT;
-         if (state)
-            newenabled |= TEXTURE_1D_BIT;
-         if (!ctx->DrawBuffer->Visual.rgbMode
-             || texUnit->Enabled == newenabled)
-            return;
-         FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-         texUnit->Enabled = newenabled;
-         break;
-      }
-      case GL_TEXTURE_2D: {
-         const GLuint curr = ctx->Texture.CurrentUnit;
-         struct gl_texture_unit *texUnit = &ctx->Texture.Unit[curr];
-         GLuint newenabled = texUnit->Enabled & ~TEXTURE_2D_BIT;
-         if (state)
-            newenabled |= TEXTURE_2D_BIT;
-         if (!ctx->DrawBuffer->Visual.rgbMode
-             || texUnit->Enabled == newenabled)
-            return;
-         FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-         texUnit->Enabled = newenabled;
-         break;
-      }
-      case GL_TEXTURE_3D: {
-         const GLuint curr = ctx->Texture.CurrentUnit;
-         struct gl_texture_unit *texUnit = &ctx->Texture.Unit[curr];
-         GLuint newenabled = texUnit->Enabled & ~TEXTURE_3D_BIT;
-         if (state)
-            newenabled |= TEXTURE_3D_BIT;
-         if (!ctx->DrawBuffer->Visual.rgbMode
-             || texUnit->Enabled == newenabled)
+      case GL_TEXTURE_1D:
+         if (!enable_texture(ctx, state, TEXTURE_1D_BIT)) {
             return;
-         FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-         texUnit->Enabled = newenabled;
+         }
          break;
-      }
-      case GL_TEXTURE_GEN_Q: {
-         GLuint unit = ctx->Texture.CurrentUnit;
-         struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
-         GLuint newenabled = texUnit->TexGenEnabled & ~Q_BIT;
-         if (state)
-            newenabled |= Q_BIT;
-         if (texUnit->TexGenEnabled == newenabled)
+      case GL_TEXTURE_2D:
+         if (!enable_texture(ctx, state, TEXTURE_2D_BIT)) {
             return;
-         FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-         texUnit->TexGenEnabled = newenabled;
+         }
          break;
-      }
-      case GL_TEXTURE_GEN_R: {
-         GLuint unit = ctx->Texture.CurrentUnit;
-         struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
-         GLuint newenabled = texUnit->TexGenEnabled & ~R_BIT;
-         if (state)
-            newenabled |= R_BIT;
-         if (texUnit->TexGenEnabled == newenabled)
+      case GL_TEXTURE_3D:
+         if (!enable_texture(ctx, state, TEXTURE_3D_BIT)) {
             return;
-         FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-         texUnit->TexGenEnabled = newenabled;
+         }
          break;
-      }
-      case GL_TEXTURE_GEN_S: {
-         GLuint unit = ctx->Texture.CurrentUnit;
-         struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
-         GLuint newenabled = texUnit->TexGenEnabled & ~S_BIT;
-         if (state)
-            newenabled |= S_BIT;
-         if (texUnit->TexGenEnabled == newenabled)
-            return;
-         FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-         texUnit->TexGenEnabled = newenabled;
+      case GL_TEXTURE_GEN_Q:
+         {
+            struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+            if (texUnit) {
+               GLuint newenabled = texUnit->TexGenEnabled & ~Q_BIT;
+               if (state)
+                  newenabled |= Q_BIT;
+               if (texUnit->TexGenEnabled == newenabled)
+                  return;
+               FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+               texUnit->TexGenEnabled = newenabled;
+            }
+         }
          break;
-      }
-      case GL_TEXTURE_GEN_T: {
-         GLuint unit = ctx->Texture.CurrentUnit;
-         struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
-         GLuint newenabled = texUnit->TexGenEnabled & ~T_BIT;
-         if (state)
-            newenabled |= T_BIT;
-         if (texUnit->TexGenEnabled == newenabled)
-            return;
-         FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-         texUnit->TexGenEnabled = newenabled;
+      case GL_TEXTURE_GEN_R:
+         {
+            struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+            if (texUnit) {
+               GLuint newenabled = texUnit->TexGenEnabled & ~R_BIT;
+               if (state)
+                  newenabled |= R_BIT;
+               if (texUnit->TexGenEnabled == newenabled)
+                  return;
+               FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+               texUnit->TexGenEnabled = newenabled;
+            }
+         }
+         break;
+      case GL_TEXTURE_GEN_S:
+         {
+            struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+            if (texUnit) {
+               GLuint newenabled = texUnit->TexGenEnabled & ~S_BIT;
+               if (state)
+                  newenabled |= S_BIT;
+               if (texUnit->TexGenEnabled == newenabled)
+                  return;
+               FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+               texUnit->TexGenEnabled = newenabled;
+            }
+         }
+         break;
+      case GL_TEXTURE_GEN_T:
+         {
+            struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+            if (texUnit) {
+               GLuint newenabled = texUnit->TexGenEnabled & ~T_BIT;
+               if (state)
+                  newenabled |= T_BIT;
+               if (texUnit->TexGenEnabled == newenabled)
+                  return;
+               FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+               texUnit->TexGenEnabled = newenabled;
+            }
+         }
          break;
-      }
 
       /*
        * CLIENT STATE!!!
@@ -672,30 +695,31 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
       case GL_EDGE_FLAG_ARRAY:
       case GL_FOG_COORDINATE_ARRAY_EXT:
       case GL_SECONDARY_COLOR_ARRAY_EXT:
+      case GL_POINT_SIZE_ARRAY_OES:
          client_state( ctx, cap, state );
          return;
 
       /* GL_SGI_color_table */
       case GL_COLOR_TABLE_SGI:
          CHECK_EXTENSION(SGI_color_table, cap);
-         if (ctx->Pixel.ColorTableEnabled == state)
+         if (ctx->Pixel.ColorTableEnabled[COLORTABLE_PRECONVOLUTION] == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_PIXEL);
-         ctx->Pixel.ColorTableEnabled = state;
+         ctx->Pixel.ColorTableEnabled[COLORTABLE_PRECONVOLUTION] = state;
          break;
       case GL_POST_CONVOLUTION_COLOR_TABLE_SGI:
          CHECK_EXTENSION(SGI_color_table, cap);
-         if (ctx->Pixel.PostConvolutionColorTableEnabled == state)
+         if (ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCONVOLUTION] == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_PIXEL);
-         ctx->Pixel.PostConvolutionColorTableEnabled = state;
+         ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCONVOLUTION] = state;
          break;
       case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI:
          CHECK_EXTENSION(SGI_color_table, cap);
-         if (ctx->Pixel.PostColorMatrixColorTableEnabled == state)
+         if (ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCOLORMATRIX] == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_PIXEL);
-         ctx->Pixel.PostColorMatrixColorTableEnabled = state;
+         ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCOLORMATRIX] = state;
          break;
       case GL_TEXTURE_COLOR_TABLE_SGI:
          CHECK_EXTENSION(SGI_texture_color_table, cap);
@@ -730,18 +754,9 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
 
       /* GL_ARB_texture_cube_map */
       case GL_TEXTURE_CUBE_MAP_ARB:
-         {
-            const GLuint curr = ctx->Texture.CurrentUnit;
-            struct gl_texture_unit *texUnit = &ctx->Texture.Unit[curr];
-            GLuint newenabled = texUnit->Enabled & ~TEXTURE_CUBE_BIT;
-            CHECK_EXTENSION(ARB_texture_cube_map, cap);
-            if (state)
-               newenabled |= TEXTURE_CUBE_BIT;
-            if (!ctx->DrawBuffer->Visual.rgbMode
-                || texUnit->Enabled == newenabled)
-               return;
-            FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-            texUnit->Enabled = newenabled;
+         CHECK_EXTENSION(ARB_texture_cube_map, cap);
+         if (!enable_texture(ctx, state, TEXTURE_CUBE_BIT)) {
+            return;
          }
          break;
 
@@ -756,35 +771,30 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
 
       /* GL_ARB_multisample */
       case GL_MULTISAMPLE_ARB:
-         CHECK_EXTENSION(ARB_multisample, cap);
          if (ctx->Multisample.Enabled == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
          ctx->Multisample.Enabled = state;
          break;
       case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
-         CHECK_EXTENSION(ARB_multisample, cap);
          if (ctx->Multisample.SampleAlphaToCoverage == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
          ctx->Multisample.SampleAlphaToCoverage = state;
          break;
       case GL_SAMPLE_ALPHA_TO_ONE_ARB:
-         CHECK_EXTENSION(ARB_multisample, cap);
          if (ctx->Multisample.SampleAlphaToOne == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
          ctx->Multisample.SampleAlphaToOne = state;
          break;
       case GL_SAMPLE_COVERAGE_ARB:
-         CHECK_EXTENSION(ARB_multisample, cap);
          if (ctx->Multisample.SampleCoverage == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
          ctx->Multisample.SampleCoverage = state;
          break;
       case GL_SAMPLE_COVERAGE_INVERT_ARB:
-         CHECK_EXTENSION(ARB_multisample, cap);
          if (ctx->Multisample.SampleCoverageInvert == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
@@ -894,18 +904,8 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
       /* GL_NV_texture_rectangle */
       case GL_TEXTURE_RECTANGLE_NV:
          CHECK_EXTENSION(NV_texture_rectangle, cap);
-         {
-            const GLuint curr = ctx->Texture.CurrentUnit;
-            struct gl_texture_unit *texUnit = &ctx->Texture.Unit[curr];
-            GLuint newenabled = texUnit->Enabled & ~TEXTURE_RECT_BIT;
-            CHECK_EXTENSION(NV_texture_rectangle, cap);
-            if (state)
-               newenabled |= TEXTURE_RECT_BIT;
-            if (!ctx->DrawBuffer->Visual.rgbMode
-                || texUnit->Enabled == newenabled)
-               return;
-            FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-            texUnit->Enabled = newenabled;
+         if (!enable_texture(ctx, state, TEXTURE_RECT_BIT)) {
+            return;
          }
          break;
 
@@ -917,8 +917,10 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
          FLUSH_VERTICES(ctx, _NEW_STENCIL);
          ctx->Stencil.TestTwoSide = state;
          if (state) {
+            ctx->Stencil._BackFace = 2;
             ctx->_TriangleCaps |= DD_TRI_TWOSTENCIL;
          } else {
+            ctx->Stencil._BackFace = 1;
             ctx->_TriangleCaps &= ~DD_TRI_TWOSTENCIL;
          }
          break;
@@ -948,6 +950,7 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
          break;
 
       /* GL_MESA_program_debug */
+#if FEATURE_MESA_program_debug
       case GL_FRAGMENT_PROGRAM_CALLBACK_MESA:
          CHECK_EXTENSION(MESA_program_debug, cap);
          ctx->FragmentProgram.CallbackEnabled = state;
@@ -956,6 +959,7 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
          CHECK_EXTENSION(MESA_program_debug, cap);
          ctx->VertexProgram.CallbackEnabled = state;
          break;
+#endif
 
 #if FEATURE_ATI_fragment_shader
       case GL_FRAGMENT_SHADER_ATI:
@@ -966,6 +970,22 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
        ctx->ATIFragmentShader.Enabled = state;
         break;
 #endif
+
+      /* GL_MESA_texture_array */
+      case GL_TEXTURE_1D_ARRAY_EXT:
+         CHECK_EXTENSION(MESA_texture_array, cap);
+         if (!enable_texture(ctx, state, TEXTURE_1D_ARRAY_BIT)) {
+            return;
+         }
+         break;
+
+      case GL_TEXTURE_2D_ARRAY_EXT:
+         CHECK_EXTENSION(MESA_texture_array, cap);
+         if (!enable_texture(ctx, state, TEXTURE_2D_ARRAY_BIT)) {
+            return;
+         }
+         break;
+
       default:
          _mesa_error(ctx, GL_INVALID_ENUM,
                      "%s(0x%x)", state ? "glEnable" : "glDisable", cap);
@@ -973,20 +993,14 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
    }
 
    if (ctx->Driver.Enable) {
-      (*ctx->Driver.Enable)( ctx, cap, state );
+      ctx->Driver.Enable( ctx, cap, state );
    }
 }
 
 
 /**
- * Enable GL capability.
- *
- * \param cap capability.
- *
- * \sa glEnable().
- *
- * Get's the current context, assures that we're outside glBegin()/glEnd() and
- * calls _mesa_set_enable().
+ * Enable GL capability.  Called by glEnable()
+ * \param cap  state to enable.
  */
 void GLAPIENTRY
 _mesa_Enable( GLenum cap )
@@ -999,14 +1013,8 @@ _mesa_Enable( GLenum cap )
 
 
 /**
- * Disable GL capability.
- *
- * \param cap capability.
- *
- * \sa glDisable().
- *
- * Get's the current context, assures that we're outside glBegin()/glEnd() and
- * calls _mesa_set_enable().
+ * Disable GL capability.  Called by glDisable()
+ * \param cap  state to disable.
  */
 void GLAPIENTRY
 _mesa_Disable( GLenum cap )
@@ -1032,10 +1040,23 @@ _mesa_Disable( GLenum cap )
       return GL_FALSE;                                         \
    }
 
+
 /**
- * Test whether a capability is enabled.
+ * Helper function to determine whether a texture target is enabled.
+ */
+static GLboolean
+is_texture_enabled(GLcontext *ctx, GLbitfield bit)
+{
+   const struct gl_texture_unit *const texUnit =
+       &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+   return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE;
+}
+
+
+/**
+ * Return simple enable/disable state.
  *
- * \param cap capability.
+ * \param cap  state variable to query.
  *
  * Returns the state of the specified capability from the current GL context.
  * For the capabilities associated with extensions verifies that those
@@ -1148,47 +1169,43 @@ _mesa_IsEnabled( GLenum cap )
       case GL_STENCIL_TEST:
         return ctx->Stencil.Enabled;
       case GL_TEXTURE_1D:
-         {
-            const struct gl_texture_unit *texUnit;
-            texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
-            return (texUnit->Enabled & TEXTURE_1D_BIT) ? GL_TRUE : GL_FALSE;
-         }
+         return is_texture_enabled(ctx, TEXTURE_1D_BIT);
       case GL_TEXTURE_2D:
-         {
-            const struct gl_texture_unit *texUnit;
-            texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
-            return (texUnit->Enabled & TEXTURE_2D_BIT) ? GL_TRUE : GL_FALSE;
-         }
+         return is_texture_enabled(ctx, TEXTURE_2D_BIT);
       case GL_TEXTURE_3D:
-         {
-            const struct gl_texture_unit *texUnit;
-            texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
-            return (texUnit->Enabled & TEXTURE_3D_BIT) ? GL_TRUE : GL_FALSE;
-         }
+         return is_texture_enabled(ctx, TEXTURE_3D_BIT);
       case GL_TEXTURE_GEN_Q:
          {
-            const struct gl_texture_unit *texUnit;
-            texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
-            return (texUnit->TexGenEnabled & Q_BIT) ? GL_TRUE : GL_FALSE;
+            const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+            if (texUnit) {
+               return (texUnit->TexGenEnabled & Q_BIT) ? GL_TRUE : GL_FALSE;
+            }
          }
+         return GL_FALSE;
       case GL_TEXTURE_GEN_R:
          {
-            const struct gl_texture_unit *texUnit;
-            texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
-            return (texUnit->TexGenEnabled & R_BIT) ? GL_TRUE : GL_FALSE;
+            const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+            if (texUnit) {
+               return (texUnit->TexGenEnabled & R_BIT) ? GL_TRUE : GL_FALSE;
+            }
          }
+         return GL_FALSE;
       case GL_TEXTURE_GEN_S:
          {
-            const struct gl_texture_unit *texUnit;
-            texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
-            return (texUnit->TexGenEnabled & S_BIT) ? GL_TRUE : GL_FALSE;
+            const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+            if (texUnit) {
+               return (texUnit->TexGenEnabled & S_BIT) ? GL_TRUE : GL_FALSE;
+            }
          }
+         return GL_FALSE;
       case GL_TEXTURE_GEN_T:
          {
-            const struct gl_texture_unit *texUnit;
-            texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
-            return (texUnit->TexGenEnabled & T_BIT) ? GL_TRUE : GL_FALSE;
+            const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+            if (texUnit) {
+               return (texUnit->TexGenEnabled & T_BIT) ? GL_TRUE : GL_FALSE;
+            }
          }
+         return GL_FALSE;
 
       /*
        * CLIENT STATE!!!
@@ -1211,6 +1228,10 @@ _mesa_IsEnabled( GLenum cap )
       case GL_SECONDARY_COLOR_ARRAY_EXT:
          CHECK_EXTENSION(EXT_secondary_color);
          return (ctx->Array.ArrayObj->SecondaryColor.Enabled != 0);
+#if FEATURE_point_size_array
+      case GL_POINT_SIZE_ARRAY_OES:
+         return (ctx->Array.ArrayObj->PointSize.Enabled != 0);
+#endif
 
       /* GL_EXT_histogram */
       case GL_HISTOGRAM:
@@ -1223,13 +1244,13 @@ _mesa_IsEnabled( GLenum cap )
       /* GL_SGI_color_table */
       case GL_COLOR_TABLE_SGI:
          CHECK_EXTENSION(SGI_color_table);
-         return ctx->Pixel.ColorTableEnabled;
+         return ctx->Pixel.ColorTableEnabled[COLORTABLE_PRECONVOLUTION];
       case GL_POST_CONVOLUTION_COLOR_TABLE_SGI:
          CHECK_EXTENSION(SGI_color_table);
-         return ctx->Pixel.PostConvolutionColorTableEnabled;
+         return ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCONVOLUTION];
       case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI:
          CHECK_EXTENSION(SGI_color_table);
-         return ctx->Pixel.PostColorMatrixColorTableEnabled;
+         return ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCOLORMATRIX];
 
       /* GL_SGI_texture_color_table */
       case GL_TEXTURE_COLOR_TABLE_SGI:
@@ -1250,11 +1271,7 @@ _mesa_IsEnabled( GLenum cap )
       /* GL_ARB_texture_cube_map */
       case GL_TEXTURE_CUBE_MAP_ARB:
          CHECK_EXTENSION(ARB_texture_cube_map);
-         {
-            const struct gl_texture_unit *texUnit;
-            texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
-            return (texUnit->Enabled & TEXTURE_CUBE_BIT) ? GL_TRUE : GL_FALSE;
-         }
+         return is_texture_enabled(ctx, TEXTURE_CUBE_BIT);
 
       /* GL_EXT_secondary_color */
       case GL_COLOR_SUM_EXT:
@@ -1263,19 +1280,14 @@ _mesa_IsEnabled( GLenum cap )
 
       /* GL_ARB_multisample */
       case GL_MULTISAMPLE_ARB:
-         CHECK_EXTENSION(ARB_multisample);
          return ctx->Multisample.Enabled;
       case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
-         CHECK_EXTENSION(ARB_multisample);
          return ctx->Multisample.SampleAlphaToCoverage;
       case GL_SAMPLE_ALPHA_TO_ONE_ARB:
-         CHECK_EXTENSION(ARB_multisample);
          return ctx->Multisample.SampleAlphaToOne;
       case GL_SAMPLE_COVERAGE_ARB:
-         CHECK_EXTENSION(ARB_multisample);
          return ctx->Multisample.SampleCoverage;
       case GL_SAMPLE_COVERAGE_INVERT_ARB:
-         CHECK_EXTENSION(ARB_multisample);
          return ctx->Multisample.SampleCoverageInvert;
 
       /* GL_IBM_rasterpos_clip */
@@ -1374,11 +1386,7 @@ _mesa_IsEnabled( GLenum cap )
       /* GL_NV_texture_rectangle */
       case GL_TEXTURE_RECTANGLE_NV:
          CHECK_EXTENSION(NV_texture_rectangle);
-         {
-            const struct gl_texture_unit *texUnit;
-            texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
-            return (texUnit->Enabled & TEXTURE_RECT_BIT) ? GL_TRUE : GL_FALSE;
-         }
+         return is_texture_enabled(ctx, TEXTURE_RECT_BIT);
 
       /* GL_EXT_stencil_two_side */
       case GL_STENCIL_TEST_TWO_SIDE_EXT:
@@ -1396,12 +1404,15 @@ _mesa_IsEnabled( GLenum cap )
          return ctx->Depth.BoundsTest;
 
       /* GL_MESA_program_debug */
+#if FEATURE_MESA_program_debug
       case GL_FRAGMENT_PROGRAM_CALLBACK_MESA:
          CHECK_EXTENSION(MESA_program_debug);
          return ctx->FragmentProgram.CallbackEnabled;
       case GL_VERTEX_PROGRAM_CALLBACK_MESA:
          CHECK_EXTENSION(MESA_program_debug);
          return ctx->VertexProgram.CallbackEnabled;
+#endif
+
 #if FEATURE_ATI_fragment_shader
       case GL_FRAGMENT_SHADER_ATI:
         CHECK_EXTENSION(ATI_fragment_shader);