Merge remote branch 'origin/nvc0'
[mesa.git] / src / mesa / main / enable.c
index 12ce14c5d04e2b6ac5eb6f89e585a2e04ef05c55..f247092410b4d3bf1c6db4f80cc8fb2fc7564d87 100644 (file)
@@ -32,8 +32,8 @@
 #include "context.h"
 #include "enable.h"
 #include "light.h"
-#include "macros.h"
 #include "simple_list.h"
+#include "mfeatures.h"
 #include "mtypes.h"
 #include "enums.h"
 #include "api_arrayelt.h"
@@ -43,9 +43,7 @@
 
 #define CHECK_EXTENSION(EXTNAME, CAP)                                  \
    if (!ctx->Extensions.EXTNAME) {                                     \
-      _mesa_error(ctx, GL_INVALID_ENUM, "gl%sClientState(0x%x)",       \
-                  state ? "Enable" : "Disable", CAP);                  \
-      return;                                                          \
+      goto invalid_enum_error;                                         \
    }
 
 
@@ -53,7 +51,7 @@
  * Helper to enable/disable client-side state.
  */
 static void
-client_state(GLcontext *ctx, GLenum cap, GLboolean state)
+client_state(struct gl_context *ctx, GLenum cap, GLboolean state)
 {
    struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
    GLuint flag;
@@ -127,10 +125,17 @@ client_state(GLcontext *ctx, GLenum cap, GLboolean state)
          break;
 #endif /* FEATURE_NV_vertex_program */
 
+      /* GL_NV_primitive_restart */
+      case GL_PRIMITIVE_RESTART_NV:
+        if (!ctx->Extensions.NV_primitive_restart) {
+            goto invalid_enum_error;
+         }
+         var = &ctx->Array.PrimitiveRestart;
+         flag = 0;
+         break;
+
       default:
-         _mesa_error( ctx, GL_INVALID_ENUM,
-                      "glEnable/DisableClientState(0x%x)", cap);
-         return;
+         goto invalid_enum_error;
    }
 
    if (*var == state)
@@ -151,6 +156,12 @@ client_state(GLcontext *ctx, GLenum cap, GLboolean state)
    if (ctx->Driver.Enable) {
       ctx->Driver.Enable( ctx, cap, state );
    }
+
+   return;
+
+invalid_enum_error:
+   _mesa_error(ctx, GL_INVALID_ENUM, "gl%sClientState(0x%x)",
+               state ? "Enable" : "Disable", cap);
 }
 
 
@@ -189,16 +200,12 @@ _mesa_DisableClientState( GLenum cap )
 #undef CHECK_EXTENSION
 #define CHECK_EXTENSION(EXTNAME, CAP)                                  \
    if (!ctx->Extensions.EXTNAME) {                                     \
-      _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(0x%x)",                  \
-                  state ? "Enable" : "Disable", CAP);                  \
-      return;                                                          \
+      goto invalid_enum_error;                                         \
    }
 
 #define CHECK_EXTENSION2(EXT1, EXT2, CAP)                              \
    if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) {               \
-      _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(0x%x)",                  \
-                  state ? "Enable" : "Disable", CAP);                  \
-      return;                                                          \
+      goto invalid_enum_error;                                         \
    }
 
 
@@ -210,7 +217,7 @@ _mesa_DisableClientState( GLenum cap )
  * higher than the number of supported coordinate units.  And we'll return NULL.
  */
 static struct gl_texture_unit *
-get_texcoord_unit(GLcontext *ctx)
+get_texcoord_unit(struct gl_context *ctx)
 {
    if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glEnable/Disable(texcoord unit)");
@@ -228,7 +235,7 @@ get_texcoord_unit(GLcontext *ctx)
  * \return GL_TRUE if state is changing or GL_FALSE if no change
  */
 static GLboolean
-enable_texture(GLcontext *ctx, GLboolean state, GLbitfield texBit)
+enable_texture(struct gl_context *ctx, GLboolean state, GLbitfield texBit)
 {
    struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
    const GLbitfield newenabled = state
@@ -256,7 +263,7 @@ enable_texture(GLcontext *ctx, GLboolean state, GLbitfield texBit)
  * dd_function_table::Enable.
  */
 void
-_mesa_set_enable(GLcontext *ctx, GLenum cap, GLboolean state)
+_mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
 {
    if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx, "%s %s (newstate is %x)\n",
@@ -278,10 +285,13 @@ _mesa_set_enable(GLcontext *ctx, GLenum cap, GLboolean state)
          ctx->Eval.AutoNormal = state;
          break;
       case GL_BLEND:
-         if (ctx->Color.BlendEnabled == state)
-            return;
-         FLUSH_VERTICES(ctx, _NEW_COLOR);
-         ctx->Color.BlendEnabled = state;
+         {
+            GLbitfield newEnabled = state * ((1 << ctx->Const.MaxDrawBuffers) - 1);
+            if (newEnabled != ctx->Color.BlendEnabled) {
+               FLUSH_VERTICES(ctx, _NEW_COLOR);
+               ctx->Color.BlendEnabled = newEnabled;
+            }
+         }
          break;
 #if FEATURE_userclip
       case GL_CLIP_PLANE0:
@@ -335,13 +345,6 @@ _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)
-            return;
-         FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
-         ctx->Transform.CullVertexFlag = state;
-         break;
       case GL_DEPTH_TEST:
          if (ctx->Depth.Test == state)
             return;
@@ -349,9 +352,6 @@ _mesa_set_enable(GLcontext *ctx, GLenum cap, GLboolean state)
          ctx->Depth.Test = state;
          break;
       case GL_DITHER:
-         if (ctx->NoDither) {
-            state = GL_FALSE; /* MESA_NO_DITHER env var */
-         }
          if (ctx->Color.DitherFlag == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_COLOR);
@@ -363,13 +363,6 @@ _mesa_set_enable(GLcontext *ctx, GLenum cap, GLboolean state)
          FLUSH_VERTICES(ctx, _NEW_FOG);
          ctx->Fog.Enabled = state;
          break;
-      case GL_HISTOGRAM:
-         CHECK_EXTENSION(EXT_histogram, cap);
-         if (ctx->Pixel.HistogramEnabled == state)
-            return;
-         FLUSH_VERTICES(ctx, _NEW_PIXEL);
-         ctx->Pixel.HistogramEnabled = state;
-         break;
       case GL_LIGHT0:
       case GL_LIGHT1:
       case GL_LIGHT2:
@@ -534,12 +527,6 @@ _mesa_set_enable(GLcontext *ctx, GLenum cap, GLboolean state)
          FLUSH_VERTICES(ctx, _NEW_EVAL);
          ctx->Eval.Map2Vertex4 = state;
          break;
-      case GL_MINMAX:
-         if (ctx->Pixel.MinMaxEnabled == state)
-            return;
-         FLUSH_VERTICES(ctx, _NEW_PIXEL);
-         ctx->Pixel.MinMaxEnabled = state;
-         break;
       case GL_NORMALIZE:
          if (ctx->Transform.Normalize == state)
             return;
@@ -682,6 +669,25 @@ _mesa_set_enable(GLcontext *ctx, GLenum cap, GLboolean state)
          }
          break;
 
+#if FEATURE_ES1
+      case GL_TEXTURE_GEN_STR_OES:
+        /* disable S, T, and R at the same time */
+        {
+            struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+            if (texUnit) {
+               GLuint newenabled =
+                 texUnit->TexGenEnabled & ~STR_BITS;
+               if (state)
+                  newenabled |= STR_BITS;
+               if (texUnit->TexGenEnabled == newenabled)
+                  return;
+               FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+               texUnit->TexGenEnabled = newenabled;
+            }
+         }
+         break;
+#endif
+
       /*
        * CLIENT STATE!!!
        */
@@ -697,59 +703,6 @@ _mesa_set_enable(GLcontext *ctx, GLenum cap, GLboolean state)
          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[COLORTABLE_PRECONVOLUTION] == state)
-            return;
-         FLUSH_VERTICES(ctx, _NEW_PIXEL);
-         ctx->Pixel.ColorTableEnabled[COLORTABLE_PRECONVOLUTION] = state;
-         break;
-      case GL_POST_CONVOLUTION_COLOR_TABLE_SGI:
-         CHECK_EXTENSION(SGI_color_table, cap);
-         if (ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCONVOLUTION] == state)
-            return;
-         FLUSH_VERTICES(ctx, _NEW_PIXEL);
-         ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCONVOLUTION] = state;
-         break;
-      case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI:
-         CHECK_EXTENSION(SGI_color_table, cap);
-         if (ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCOLORMATRIX] == state)
-            return;
-         FLUSH_VERTICES(ctx, _NEW_PIXEL);
-         ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCOLORMATRIX] = state;
-         break;
-      case GL_TEXTURE_COLOR_TABLE_SGI:
-         CHECK_EXTENSION(SGI_texture_color_table, cap);
-         if (ctx->Texture.Unit[ctx->Texture.CurrentUnit].ColorTableEnabled == state)
-            return;
-         FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-         ctx->Texture.Unit[ctx->Texture.CurrentUnit].ColorTableEnabled = state;
-         break;
-
-      /* GL_EXT_convolution */
-      case GL_CONVOLUTION_1D:
-         CHECK_EXTENSION(EXT_convolution, cap);
-         if (ctx->Pixel.Convolution1DEnabled == state)
-            return;
-         FLUSH_VERTICES(ctx, _NEW_PIXEL);
-         ctx->Pixel.Convolution1DEnabled = state;
-         break;
-      case GL_CONVOLUTION_2D:
-         CHECK_EXTENSION(EXT_convolution, cap);
-         if (ctx->Pixel.Convolution2DEnabled == state)
-            return;
-         FLUSH_VERTICES(ctx, _NEW_PIXEL);
-         ctx->Pixel.Convolution2DEnabled = state;
-         break;
-      case GL_SEPARABLE_2D:
-         CHECK_EXTENSION(EXT_convolution, cap);
-         if (ctx->Pixel.Separable2DEnabled == state)
-            return;
-         FLUSH_VERTICES(ctx, _NEW_PIXEL);
-         ctx->Pixel.Separable2DEnabled = state;
-         break;
-
       /* GL_ARB_texture_cube_map */
       case GL_TEXTURE_CUBE_MAP_ARB:
          CHECK_EXTENSION(ARB_texture_cube_map, cap);
@@ -980,15 +933,49 @@ _mesa_set_enable(GLcontext *ctx, GLenum cap, GLboolean state)
         ctx->Texture.CubeMapSeamless = state;
         break;
 
+#if FEATURE_EXT_transform_feedback
+      case GL_RASTERIZER_DISCARD:
+        CHECK_EXTENSION(EXT_transform_feedback, cap);
+         if (ctx->TransformFeedback.RasterDiscard != state) {
+            ctx->TransformFeedback.RasterDiscard = state;
+            FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
+         }
+         break;
+#endif
+
+      /* GL 3.1 primitive restart.  Note: this enum is different from
+       * GL_PRIMITIVE_RESTART_NV (which is client state).
+       */
+      case GL_PRIMITIVE_RESTART:
+         if (ctx->VersionMajor * 10 + ctx->VersionMinor < 31) {
+            goto invalid_enum_error;
+         }
+         if (ctx->Array.PrimitiveRestart != state) {
+            FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
+            ctx->Array.PrimitiveRestart = state;
+         }
+         break;
+
+      /* GL3.0 - GL_framebuffer_sRGB */
+      case GL_FRAMEBUFFER_SRGB_EXT:
+         CHECK_EXTENSION(EXT_framebuffer_sRGB, cap);
+         FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+         ctx->Color.sRGBEnabled = state;
+         break;
+
       default:
-         _mesa_error(ctx, GL_INVALID_ENUM,
-                     "%s(0x%x)", state ? "glEnable" : "glDisable", cap);
-         return;
+         goto invalid_enum_error;
    }
 
    if (ctx->Driver.Enable) {
       ctx->Driver.Enable( ctx, cap, state );
    }
+
+   return;
+
+invalid_enum_error:
+   _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(0x%x)",
+               state ? "Enable" : "Disable", cap);
 }
 
 
@@ -1020,18 +1007,94 @@ _mesa_Disable( GLenum cap )
 }
 
 
+
+/**
+ * Enable/disable an indexed state var.
+ */
+void
+_mesa_set_enablei(struct gl_context *ctx, GLenum cap, GLuint index, GLboolean state)
+{
+   ASSERT(state == 0 || state == 1);
+   switch (cap) {
+   case GL_BLEND:
+      if (!ctx->Extensions.EXT_draw_buffers2) {
+         goto invalid_enum_error;
+      }
+      if (index >= ctx->Const.MaxDrawBuffers) {
+         _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
+                     state ? "glEnableIndexed" : "glDisableIndexed", index);
+         return;
+      }
+      if (((ctx->Color.BlendEnabled >> index) & 1) != state) {
+         FLUSH_VERTICES(ctx, _NEW_COLOR);
+         if (state)
+            ctx->Color.BlendEnabled |= (1 << index);
+         else
+            ctx->Color.BlendEnabled &= ~(1 << index);
+      }
+      break;
+   default:
+      goto invalid_enum_error;
+   }
+   return;
+
+invalid_enum_error:
+    _mesa_error(ctx, GL_INVALID_ENUM, "%s(cap=%s)",
+                state ? "glEnablei" : "glDisablei",
+                _mesa_lookup_enum_by_nr(cap));
+}
+
+
+void GLAPIENTRY
+_mesa_DisableIndexed( GLenum cap, GLuint index )
+{
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+   _mesa_set_enablei(ctx, cap, index, GL_FALSE);
+}
+
+
+void GLAPIENTRY
+_mesa_EnableIndexed( GLenum cap, GLuint index )
+{
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+   _mesa_set_enablei(ctx, cap, index, GL_TRUE);
+}
+
+
+GLboolean GLAPIENTRY
+_mesa_IsEnabledIndexed( GLenum cap, GLuint index )
+{
+   GET_CURRENT_CONTEXT(ctx);
+   switch (cap) {
+   case GL_BLEND:
+      if (index >= ctx->Const.MaxDrawBuffers) {
+         _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
+                     index);
+         return GL_FALSE;
+      }
+      return (ctx->Color.BlendEnabled >> index) & 1;
+   default:
+      _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabledIndexed(cap=%s)",
+                  _mesa_lookup_enum_by_nr(cap));
+      return GL_FALSE;
+   }
+}
+
+
+
+
 #undef CHECK_EXTENSION
 #define CHECK_EXTENSION(EXTNAME)                       \
    if (!ctx->Extensions.EXTNAME) {                     \
-      _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled");        \
-      return GL_FALSE;                                 \
+      goto invalid_enum_error;                         \
    }
 
 #undef CHECK_EXTENSION2
 #define CHECK_EXTENSION2(EXT1, EXT2)                           \
    if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) {       \
-      _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled");                \
-      return GL_FALSE;                                         \
+      goto invalid_enum_error;                                 \
    }
 
 
@@ -1039,7 +1102,7 @@ _mesa_Disable( GLenum cap )
  * Helper function to determine whether a texture target is enabled.
  */
 static GLboolean
-is_texture_enabled(GLcontext *ctx, GLbitfield bit)
+is_texture_enabled(struct gl_context *ctx, GLbitfield bit)
 {
    const struct gl_texture_unit *const texUnit =
        &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
@@ -1066,7 +1129,7 @@ _mesa_IsEnabled( GLenum cap )
       case GL_AUTO_NORMAL:
         return ctx->Eval.AutoNormal;
       case GL_BLEND:
-         return ctx->Color.BlendEnabled;
+         return ctx->Color.BlendEnabled & 1;  /* return state for buffer[0] */
       case GL_CLIP_PLANE0:
       case GL_CLIP_PLANE1:
       case GL_CLIP_PLANE2:
@@ -1200,6 +1263,15 @@ _mesa_IsEnabled( GLenum cap )
             }
          }
          return GL_FALSE;
+#if FEATURE_ES1
+      case GL_TEXTURE_GEN_STR_OES:
+        {
+            const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+            if (texUnit) {
+                   return (texUnit->TexGenEnabled & STR_BITS) == STR_BITS ? GL_TRUE : GL_FALSE;
+            }
+         }
+#endif
 
       /*
        * CLIENT STATE!!!
@@ -1227,41 +1299,6 @@ _mesa_IsEnabled( GLenum cap )
          return (ctx->Array.ArrayObj->PointSize.Enabled != 0);
 #endif
 
-      /* GL_EXT_histogram */
-      case GL_HISTOGRAM:
-         CHECK_EXTENSION(EXT_histogram);
-         return ctx->Pixel.HistogramEnabled;
-      case GL_MINMAX:
-         CHECK_EXTENSION(EXT_histogram);
-         return ctx->Pixel.MinMaxEnabled;
-
-      /* GL_SGI_color_table */
-      case GL_COLOR_TABLE_SGI:
-         CHECK_EXTENSION(SGI_color_table);
-         return ctx->Pixel.ColorTableEnabled[COLORTABLE_PRECONVOLUTION];
-      case GL_POST_CONVOLUTION_COLOR_TABLE_SGI:
-         CHECK_EXTENSION(SGI_color_table);
-         return ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCONVOLUTION];
-      case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI:
-         CHECK_EXTENSION(SGI_color_table);
-         return ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCOLORMATRIX];
-
-      /* GL_SGI_texture_color_table */
-      case GL_TEXTURE_COLOR_TABLE_SGI:
-         CHECK_EXTENSION(SGI_texture_color_table);
-         return ctx->Texture.Unit[ctx->Texture.CurrentUnit].ColorTableEnabled;
-
-      /* GL_EXT_convolution */
-      case GL_CONVOLUTION_1D:
-         CHECK_EXTENSION(EXT_convolution);
-         return ctx->Pixel.Convolution1DEnabled;
-      case GL_CONVOLUTION_2D:
-         CHECK_EXTENSION(EXT_convolution);
-         return ctx->Pixel.Convolution2DEnabled;
-      case GL_SEPARABLE_2D:
-         CHECK_EXTENSION(EXT_convolution);
-         return ctx->Pixel.Separable2DEnabled;
-
       /* GL_ARB_texture_cube_map */
       case GL_TEXTURE_CUBE_MAP_ARB:
          CHECK_EXTENSION(ARB_texture_cube_map);
@@ -1413,8 +1450,38 @@ _mesa_IsEnabled( GLenum cap )
         CHECK_EXTENSION(ARB_seamless_cube_map);
         return ctx->Texture.CubeMapSeamless;
 
+#if FEATURE_EXT_transform_feedback
+      case GL_RASTERIZER_DISCARD:
+        CHECK_EXTENSION(EXT_transform_feedback);
+         return ctx->TransformFeedback.RasterDiscard;
+#endif
+
+      /* GL_NV_primitive_restart */
+      case GL_PRIMITIVE_RESTART_NV:
+        if (!ctx->Extensions.NV_primitive_restart) {
+            goto invalid_enum_error;
+         }
+         return ctx->Array.PrimitiveRestart;
+
+      /* GL 3.1 primitive restart */
+      case GL_PRIMITIVE_RESTART:
+         if (ctx->VersionMajor * 10 + ctx->VersionMinor < 31) {
+            goto invalid_enum_error;
+         }
+         return ctx->Array.PrimitiveRestart;
+
+      /* GL3.0 - GL_framebuffer_sRGB */
+      case GL_FRAMEBUFFER_SRGB_EXT:
+        CHECK_EXTENSION(EXT_framebuffer_sRGB);
+        return ctx->Color.sRGBEnabled;
+
       default:
-         _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(0x%x)", (int) cap);
-        return GL_FALSE;
+         goto invalid_enum_error;
    }
+
+   return GL_FALSE;
+
+invalid_enum_error:
+   _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(0x%x)", (int) cap);
+   return GL_FALSE;
 }