Initial implementation of MESA_texture_array
[mesa.git] / src / mesa / main / enable.c
index 0d54c29949b855e932f88ed543a046a795ac40a9..52dd63f2cefb1f7767b9268ef7ff85a7eb4d2e8f 100644 (file)
@@ -190,6 +190,25 @@ _mesa_DisableClientState( GLenum cap )
    }
 
 
+/**
+ * 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.
@@ -558,45 +577,21 @@ _mesa_set_enable(GLcontext *ctx, GLenum cap, GLboolean state)
          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)
+      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_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)
+      case GL_TEXTURE_2D:
+         if (!enable_texture(ctx, state, TEXTURE_2D_BIT)) {
             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_3D:
+         if (!enable_texture(ctx, state, TEXTURE_3D_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];
@@ -663,24 +658,24 @@ _mesa_set_enable(GLcontext *ctx, GLenum cap, GLboolean state)
       /* 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);
@@ -715,18 +710,9 @@ _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;
 
@@ -879,18 +865,8 @@ _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;
 
@@ -946,6 +922,22 @@ _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);
@@ -1001,6 +993,18 @@ _mesa_Disable( GLenum cap )
    }
 
 
+/**
+ * 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.
  *
@@ -1117,23 +1121,11 @@ _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;
@@ -1192,13 +1184,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:
@@ -1219,11 +1211,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:
@@ -1343,11 +1331,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: