Fix gcc version checks for _mesa_bitcount
[mesa.git] / src / mesa / main / enable.c
index a038a95c55ac864dd3189d6de660e4f23378152f..689dc8a99ec5d572f9cf25d151fce8cb10bbdaef 100644 (file)
@@ -5,7 +5,6 @@
 
 /*
  * Mesa 3-D graphics library
- * Version:  7.0.3
  *
  * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
 
 
 #include "glheader.h"
+#include "clip.h"
 #include "context.h"
 #include "enable.h"
 #include "light.h"
 #include "simple_list.h"
+#include "mfeatures.h"
 #include "mtypes.h"
 #include "enums.h"
 #include "api_arrayelt.h"
@@ -212,8 +213,8 @@ _mesa_DisableClientState( GLenum cap )
 /**
  * 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.
+ * Note that we'll set GL_INVALID_OPERATION and return NULL if the active
+ * texture unit is higher than the number of supported coordinate units.
  */
 static struct gl_texture_unit *
 get_texcoord_unit(struct gl_context *ctx)
@@ -285,7 +286,8 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
          break;
       case GL_BLEND:
          {
-            GLbitfield newEnabled = state * ((1 << ctx->Const.MaxDrawBuffers) - 1);
+            GLbitfield newEnabled =
+               state * ((1 << ctx->Const.MaxDrawBuffers) - 1);
             if (newEnabled != ctx->Color.BlendEnabled) {
                FLUSH_VERTICES(ctx, _NEW_COLOR);
                ctx->Color.BlendEnabled = newEnabled;
@@ -293,33 +295,29 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
          }
          break;
 #if FEATURE_userclip
-      case GL_CLIP_PLANE0:
-      case GL_CLIP_PLANE1:
-      case GL_CLIP_PLANE2:
-      case GL_CLIP_PLANE3:
-      case GL_CLIP_PLANE4:
-      case GL_CLIP_PLANE5:
+      case GL_CLIP_DISTANCE0:
+      case GL_CLIP_DISTANCE1:
+      case GL_CLIP_DISTANCE2:
+      case GL_CLIP_DISTANCE3:
+      case GL_CLIP_DISTANCE4:
+      case GL_CLIP_DISTANCE5:
+      case GL_CLIP_DISTANCE6:
+      case GL_CLIP_DISTANCE7:
          {
-            const GLuint p = cap - GL_CLIP_PLANE0;
+            const GLuint p = cap - GL_CLIP_DISTANCE0;
 
-            if ((ctx->Transform.ClipPlanesEnabled & (1 << p)) == ((GLuint) state << p))
+            if (p >= ctx->Const.MaxClipPlanes)
+               goto invalid_enum_error;
+
+            if ((ctx->Transform.ClipPlanesEnabled & (1 << p))
+                == ((GLuint) state << p))
                return;
 
             FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
 
             if (state) {
                ctx->Transform.ClipPlanesEnabled |= (1 << p);
-
-               if (_math_matrix_is_dirty(ctx->ProjectionMatrixStack.Top))
-                  _math_matrix_analyse( ctx->ProjectionMatrixStack.Top );
-
-               /* This derived state also calculated in clip.c and
-                * from _mesa_update_state() on changes to EyeUserPlane
-                * and ctx->ProjectionMatrix respectively.
-                */
-               _mesa_transform_vector( ctx->Transform._ClipUserPlane[p],
-                                    ctx->Transform.EyeUserPlane[p],
-                                    ctx->ProjectionMatrixStack.Top->inv );
+               _mesa_update_clip_plane(ctx, p);
             }
             else {
                ctx->Transform.ClipPlanesEnabled &= ~(1 << p);
@@ -351,9 +349,6 @@ _mesa_set_enable(struct gl_context *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);
@@ -569,7 +564,6 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
          ctx->Polygon.OffsetLine = state;
          break;
       case GL_POLYGON_OFFSET_FILL:
-         /*case GL_POLYGON_OFFSET_EXT:*/
          if (ctx->Polygon.OffsetFill == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_POLYGON);
@@ -587,12 +581,6 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
          FLUSH_VERTICES(ctx, _NEW_SCISSOR);
          ctx->Scissor.Enabled = state;
          break;
-      case GL_SHARED_TEXTURE_PALETTE_EXT:
-         if (ctx->Texture.SharedPalette == state)
-            return;
-         FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-         ctx->Texture.SharedPalette = state;
-         break;
       case GL_STENCIL_TEST:
          if (ctx->Stencil.Enabled == state)
             return;
@@ -614,55 +602,17 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
             return;
          }
          break;
-      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_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:
+      case GL_TEXTURE_GEN_R:
+      case GL_TEXTURE_GEN_Q:
          {
             struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
             if (texUnit) {
-               GLuint newenabled = texUnit->TexGenEnabled & ~T_BIT;
+               GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
+               GLbitfield newenabled = texUnit->TexGenEnabled & ~coordBit;
                if (state)
-                  newenabled |= T_BIT;
+                  newenabled |= coordBit;
                if (texUnit->TexGenEnabled == newenabled)
                   return;
                FLUSH_VERTICES(ctx, _NEW_TEXTURE);
@@ -690,9 +640,7 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
          break;
 #endif
 
-      /*
-       * CLIENT STATE!!!
-       */
+      /* client-side state */
       case GL_VERTEX_ARRAY:
       case GL_NORMAL_ARRAY:
       case GL_COLOR_ARRAY:
@@ -705,15 +653,6 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
          client_state( ctx, cap, state );
          return;
 
-      /* GL_SGI_texture_color_table */
-      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_ARB_texture_cube_map */
       case GL_TEXTURE_CUBE_MAP_ARB:
          CHECK_EXTENSION(ARB_texture_cube_map, cap);
@@ -941,15 +880,18 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
 
       case GL_TEXTURE_CUBE_MAP_SEAMLESS:
         CHECK_EXTENSION(ARB_seamless_cube_map, cap);
-        ctx->Texture.CubeMapSeamless = state;
+        if (ctx->Texture.CubeMapSeamless != state) {
+           FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+           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);
+            ctx->TransformFeedback.RasterDiscard = state;
          }
          break;
 #endif
@@ -967,6 +909,13 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean 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:
          goto invalid_enum_error;
    }
@@ -1016,7 +965,8 @@ _mesa_Disable( GLenum cap )
  * Enable/disable an indexed state var.
  */
 void
-_mesa_set_enablei(struct gl_context *ctx, GLenum cap, GLuint index, GLboolean state)
+_mesa_set_enablei(struct gl_context *ctx, GLenum cap,
+                  GLuint index, GLboolean state)
 {
    ASSERT(state == 0 || state == 1);
    switch (cap) {
@@ -1071,6 +1021,7 @@ GLboolean GLAPIENTRY
 _mesa_IsEnabledIndexed( GLenum cap, GLuint index )
 {
    GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
    switch (cap) {
    case GL_BLEND:
       if (index >= ctx->Const.MaxDrawBuffers) {
@@ -1127,6 +1078,8 @@ GLboolean GLAPIENTRY
 _mesa_IsEnabled( GLenum cap )
 {
    GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
+
    switch (cap) {
       case GL_ALPHA_TEST:
          return ctx->Color.AlphaEnabled;
@@ -1134,13 +1087,21 @@ _mesa_IsEnabled( GLenum cap )
         return ctx->Eval.AutoNormal;
       case GL_BLEND:
          return ctx->Color.BlendEnabled & 1;  /* return state for buffer[0] */
-      case GL_CLIP_PLANE0:
-      case GL_CLIP_PLANE1:
-      case GL_CLIP_PLANE2:
-      case GL_CLIP_PLANE3:
-      case GL_CLIP_PLANE4:
-      case GL_CLIP_PLANE5:
-        return (ctx->Transform.ClipPlanesEnabled >> (cap - GL_CLIP_PLANE0)) & 1;
+      case GL_CLIP_DISTANCE0:
+      case GL_CLIP_DISTANCE1:
+      case GL_CLIP_DISTANCE2:
+      case GL_CLIP_DISTANCE3:
+      case GL_CLIP_DISTANCE4:
+      case GL_CLIP_DISTANCE5:
+      case GL_CLIP_DISTANCE6:
+      case GL_CLIP_DISTANCE7: {
+         const GLuint p = cap - GL_CLIP_DISTANCE0;
+
+         if (p >= ctx->Const.MaxClipPlanes)
+            goto invalid_enum_error;
+
+        return (ctx->Transform.ClipPlanesEnabled >> p) & 1;
+      }
       case GL_COLOR_MATERIAL:
         return ctx->Light.ColorMaterialEnabled;
       case GL_CULL_FACE:
@@ -1219,14 +1180,11 @@ _mesa_IsEnabled( GLenum cap )
       case GL_POLYGON_OFFSET_LINE:
         return ctx->Polygon.OffsetLine;
       case GL_POLYGON_OFFSET_FILL:
-      /*case GL_POLYGON_OFFSET_EXT:*/
         return ctx->Polygon.OffsetFill;
       case GL_RESCALE_NORMAL_EXT:
          return ctx->Transform.RescaleNormals;
       case GL_SCISSOR_TEST:
         return ctx->Scissor.Enabled;
-      case GL_SHARED_TEXTURE_PALETTE_EXT:
-         return ctx->Texture.SharedPalette;
       case GL_STENCIL_TEST:
         return ctx->Stencil.Enabled;
       case GL_TEXTURE_1D:
@@ -1235,35 +1193,15 @@ _mesa_IsEnabled( GLenum cap )
          return is_texture_enabled(ctx, TEXTURE_2D_BIT);
       case GL_TEXTURE_3D:
          return is_texture_enabled(ctx, TEXTURE_3D_BIT);
-      case GL_TEXTURE_GEN_Q:
-         {
-            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 = 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 = get_texcoord_unit(ctx);
-            if (texUnit) {
-               return (texUnit->TexGenEnabled & S_BIT) ? GL_TRUE : GL_FALSE;
-            }
-         }
-         return GL_FALSE;
       case GL_TEXTURE_GEN_T:
+      case GL_TEXTURE_GEN_R:
+      case GL_TEXTURE_GEN_Q:
          {
             const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
             if (texUnit) {
-               return (texUnit->TexGenEnabled & T_BIT) ? GL_TRUE : GL_FALSE;
+               GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
+               return (texUnit->TexGenEnabled & coordBit) ? GL_TRUE : GL_FALSE;
             }
          }
          return GL_FALSE;
@@ -1272,14 +1210,13 @@ _mesa_IsEnabled( GLenum cap )
         {
             const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
             if (texUnit) {
-                   return (texUnit->TexGenEnabled & STR_BITS) == STR_BITS ? GL_TRUE : GL_FALSE;
+               return (texUnit->TexGenEnabled & STR_BITS) == STR_BITS
+                  ? GL_TRUE : GL_FALSE;
             }
          }
 #endif
 
-      /*
-       * CLIENT STATE!!!
-       */
+      /* client-side state */
       case GL_VERTEX_ARRAY:
          return (ctx->Array.ArrayObj->Vertex.Enabled != 0);
       case GL_NORMAL_ARRAY:
@@ -1289,7 +1226,8 @@ _mesa_IsEnabled( GLenum cap )
       case GL_INDEX_ARRAY:
          return (ctx->Array.ArrayObj->Index.Enabled != 0);
       case GL_TEXTURE_COORD_ARRAY:
-         return (ctx->Array.ArrayObj->TexCoord[ctx->Array.ActiveTexture].Enabled != 0);
+         return (ctx->Array.ArrayObj->TexCoord[ctx->Array.ActiveTexture]
+                 .Enabled != 0);
       case GL_EDGE_FLAG_ARRAY:
          return (ctx->Array.ArrayObj->EdgeFlag.Enabled != 0);
       case GL_FOG_COORDINATE_ARRAY_EXT:
@@ -1303,11 +1241,6 @@ _mesa_IsEnabled( GLenum cap )
          return (ctx->Array.ArrayObj->PointSize.Enabled != 0);
 #endif
 
-      /* 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_ARB_texture_cube_map */
       case GL_TEXTURE_CUBE_MAP_ARB:
          CHECK_EXTENSION(ARB_texture_cube_map);
@@ -1479,6 +1412,11 @@ _mesa_IsEnabled( GLenum cap )
          }
          return ctx->Array.PrimitiveRestart;
 
+      /* GL3.0 - GL_framebuffer_sRGB */
+      case GL_FRAMEBUFFER_SRGB_EXT:
+        CHECK_EXTENSION(EXT_framebuffer_sRGB);
+        return ctx->Color.sRGBEnabled;
+
       default:
          goto invalid_enum_error;
    }