mesa: don't flag _NEW_TRANSFORM for primitive restart
[mesa.git] / src / mesa / main / enable.c
index edd4751e1adea13cd87b58961348e2a4e92088f1..861d46e23f73460bf442006d69e784f40f8d5736 100644 (file)
 
 
 #include "glheader.h"
+#include "blend.h"
 #include "clip.h"
 #include "context.h"
+#include "debug_output.h"
 #include "enable.h"
 #include "errors.h"
 #include "light.h"
-#include "simple_list.h"
 #include "mtypes.h"
 #include "enums.h"
-#include "api_arrayelt.h"
 #include "texstate.h"
-#include "drivers/common/meta.h"
 
 
 
@@ -105,11 +104,13 @@ client_state(struct gl_context *ctx, GLenum cap, GLboolean state)
       case GL_POINT_SIZE_ARRAY_OES:
          var = &vao->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled;
          flag = VERT_BIT_POINT_SIZE;
+         FLUSH_VERTICES(ctx, _NEW_PROGRAM);
+         ctx->VertexProgram.PointSizeEnabled = state;
          break;
 
       /* GL_NV_primitive_restart */
       case GL_PRIMITIVE_RESTART_NV:
-        if (!ctx->Extensions.NV_primitive_restart) {
+         if (!ctx->Extensions.NV_primitive_restart) {
             goto invalid_enum_error;
          }
          var = &ctx->Array.PrimitiveRestart;
@@ -125,8 +126,6 @@ client_state(struct gl_context *ctx, GLenum cap, GLboolean state)
 
    FLUSH_VERTICES(ctx, _NEW_ARRAY);
 
-   _ae_invalidate_state(ctx, _NEW_ARRAY);
-
    *var = state;
 
    update_derived_primitive_restart_state(ctx);
@@ -146,7 +145,7 @@ client_state(struct gl_context *ctx, GLenum cap, GLboolean state)
 
 invalid_enum_error:
    _mesa_error(ctx, GL_INVALID_ENUM, "gl%sClientState(%s)",
-               state ? "Enable" : "Disable", _mesa_lookup_enum_by_nr(cap));
+               state ? "Enable" : "Disable", _mesa_enum_to_string(cap));
 }
 
 
@@ -225,7 +224,7 @@ enable_texture(struct gl_context *ctx, GLboolean state, GLbitfield texBit)
    if (texUnit->Enabled == newenabled)
        return GL_FALSE;
 
-   FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+   FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);
    texUnit->Enabled = newenabled;
    return GL_TRUE;
 }
@@ -240,7 +239,18 @@ _mesa_set_multisample(struct gl_context *ctx, GLboolean state)
 {
    if (ctx->Multisample.Enabled == state)
       return;
-   FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
+
+   /* GL compatibility needs Multisample.Enable to determine program state
+    * constants.
+    */
+   if (ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGLES ||
+       !ctx->DriverFlags.NewMultisampleEnable) {
+      FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
+   } else {
+      FLUSH_VERTICES(ctx, 0);
+   }
+
+   ctx->NewDriverState |= ctx->DriverFlags.NewMultisampleEnable;
    ctx->Multisample.Enabled = state;
 
    if (ctx->Driver.Enable) {
@@ -257,7 +267,10 @@ _mesa_set_framebuffer_srgb(struct gl_context *ctx, GLboolean state)
 {
    if (ctx->Color.sRGBEnabled == state)
       return;
-   FLUSH_VERTICES(ctx, _NEW_BUFFERS);
+
+   /* TODO: Switch i965 to the new flag and remove the conditional */
+   FLUSH_VERTICES(ctx, ctx->DriverFlags.NewFramebufferSRGB ? 0 : _NEW_BUFFERS);
+   ctx->NewDriverState |= ctx->DriverFlags.NewFramebufferSRGB;
    ctx->Color.sRGBEnabled = state;
 
    if (ctx->Driver.Enable) {
@@ -283,7 +296,7 @@ _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",
                   state ? "glEnable" : "glDisable",
-                  _mesa_lookup_enum_by_nr(cap),
+                  _mesa_enum_to_string(cap),
                   ctx->NewState);
 
    switch (cap) {
@@ -292,7 +305,9 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
             goto invalid_enum_error;
          if (ctx->Color.AlphaEnabled == state)
             return;
+         /* AlphaEnabled is used by the fixed-func fragment program */
          FLUSH_VERTICES(ctx, _NEW_COLOR);
+         ctx->NewDriverState |= ctx->DriverFlags.NewAlphaTest;
          ctx->Color.AlphaEnabled = state;
          break;
       case GL_AUTO_NORMAL:
@@ -308,12 +323,12 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
             GLbitfield newEnabled =
                state * ((1 << ctx->Const.MaxDrawBuffers) - 1);
             if (newEnabled != ctx->Color.BlendEnabled) {
-               FLUSH_VERTICES(ctx, _NEW_COLOR);
+               _mesa_flush_vertices_for_blend_state(ctx);
                ctx->Color.BlendEnabled = newEnabled;
             }
          }
          break;
-      case GL_CLIP_DISTANCE0:
+      case GL_CLIP_DISTANCE0: /* aka GL_CLIP_PLANE0 */
       case GL_CLIP_DISTANCE1:
       case GL_CLIP_DISTANCE2:
       case GL_CLIP_DISTANCE3:
@@ -339,7 +354,7 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
             }
             else {
                ctx->Transform.ClipPlanesEnabled &= ~(1 << p);
-            }               
+            }
          }
          break;
       case GL_COLOR_MATERIAL:
@@ -364,35 +379,19 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
       case GL_DEPTH_TEST:
          if (ctx->Depth.Test == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_DEPTH);
+         FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepth ? 0 : _NEW_DEPTH);
+         ctx->NewDriverState |= ctx->DriverFlags.NewDepth;
          ctx->Depth.Test = state;
          break;
       case GL_DEBUG_OUTPUT:
-         if (!_mesa_is_desktop_gl(ctx)) {
-            goto invalid_enum_error;
-         }
-         else {
-            struct gl_debug_state *debug = _mesa_get_debug_state(ctx);
-            if (debug) {
-               debug->DebugOutput = state;
-            }
-         }
-         break;
       case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB:
-         if (!_mesa_is_desktop_gl(ctx)) {
-            goto invalid_enum_error;
-         }
-         else {
-            struct gl_debug_state *debug = _mesa_get_debug_state(ctx);
-            if (debug) {
-               debug->SyncOutput = state;
-            }
-         }
+         _mesa_set_debug_state_int(ctx, cap, state);
          break;
       case GL_DITHER:
          if (ctx->Color.DitherFlag == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_COLOR);
+         FLUSH_VERTICES(ctx, ctx->DriverFlags.NewBlend ? 0 : _NEW_COLOR);
+         ctx->NewDriverState |= ctx->DriverFlags.NewBlend;
          ctx->Color.DitherFlag = state;
          break;
       case GL_FOG:
@@ -402,6 +401,7 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
             return;
          FLUSH_VERTICES(ctx, _NEW_FOG);
          ctx->Fog.Enabled = state;
+         ctx->Fog._PackedEnabledMode = state ? ctx->Fog._PackedMode : FOG_NONE;
          break;
       case GL_LIGHT0:
       case GL_LIGHT1:
@@ -418,11 +418,10 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
          FLUSH_VERTICES(ctx, _NEW_LIGHT);
          ctx->Light.Light[cap-GL_LIGHT0].Enabled = state;
          if (state) {
-            insert_at_tail(&ctx->Light.EnabledList,
-                           &ctx->Light.Light[cap-GL_LIGHT0]);
+            ctx->Light._EnabledLights |= 1u << (cap - GL_LIGHT0);
          }
          else {
-            remove_from_list(&ctx->Light.Light[cap-GL_LIGHT0]);
+            ctx->Light._EnabledLights &= ~(1u << (cap - GL_LIGHT0));
          }
          break;
       case GL_LIGHTING:
@@ -454,15 +453,27 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
             goto invalid_enum_error;
          if (ctx->Color.IndexLogicOpEnabled == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_COLOR);
+         FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLogicOp ? 0 : _NEW_COLOR);
+         ctx->NewDriverState |= ctx->DriverFlags.NewLogicOp;
          ctx->Color.IndexLogicOpEnabled = state;
          break;
+      case GL_CONSERVATIVE_RASTERIZATION_INTEL:
+         if (!_mesa_has_INTEL_conservative_rasterization(ctx))
+            goto invalid_enum_error;
+         if (ctx->IntelConservativeRasterization == state)
+            return;
+         FLUSH_VERTICES(ctx, 0);
+         ctx->NewDriverState |=
+            ctx->DriverFlags.NewIntelConservativeRasterization;
+         ctx->IntelConservativeRasterization = state;
+         break;
       case GL_COLOR_LOGIC_OP:
          if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
             goto invalid_enum_error;
          if (ctx->Color.ColorLogicOpEnabled == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_COLOR);
+         FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLogicOp ? 0 : _NEW_COLOR);
+         ctx->NewDriverState |= ctx->DriverFlags.NewLogicOp;
          ctx->Color.ColorLogicOpEnabled = state;
          break;
       case GL_MAP1_COLOR_4:
@@ -677,7 +688,9 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
             GLbitfield newEnabled =
                state * ((1 << ctx->Const.MaxViewports) - 1);
             if (newEnabled != ctx->Scissor.EnableFlags) {
-               FLUSH_VERTICES(ctx, _NEW_SCISSOR);
+               FLUSH_VERTICES(ctx, ctx->DriverFlags.NewScissorTest ? 0 :
+                                                                _NEW_SCISSOR);
+               ctx->NewDriverState |= ctx->DriverFlags.NewScissorTest;
                ctx->Scissor.EnableFlags = newEnabled;
             }
          }
@@ -685,7 +698,8 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
       case GL_STENCIL_TEST:
          if (ctx->Stencil.Enabled == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_STENCIL);
+         FLUSH_VERTICES(ctx, ctx->DriverFlags.NewStencil ? 0 : _NEW_STENCIL);
+         ctx->NewDriverState |= ctx->DriverFlags.NewStencil;
          ctx->Stencil.Enabled = state;
          break;
       case GL_TEXTURE_1D:
@@ -726,15 +740,15 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
                   newenabled |= coordBit;
                if (texUnit->TexGenEnabled == newenabled)
                   return;
-               FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+               FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);
                texUnit->TexGenEnabled = newenabled;
             }
          }
          break;
 
       case GL_TEXTURE_GEN_STR_OES:
-        /* disable S, T, and R at the same time */
-        {
+         /* disable S, T, and R at the same time */
+         {
             struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
 
             if (ctx->API != API_OPENGLES)
@@ -742,12 +756,12 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
 
             if (texUnit) {
                GLuint newenabled =
-                 texUnit->TexGenEnabled & ~STR_BITS;
+                  texUnit->TexGenEnabled & ~STR_BITS;
                if (state)
                   newenabled |= STR_BITS;
                if (texUnit->TexGenEnabled == newenabled)
                   return;
-               FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+               FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);
                texUnit->TexGenEnabled = newenabled;
             }
          }
@@ -757,17 +771,27 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
       case GL_VERTEX_ARRAY:
       case GL_NORMAL_ARRAY:
       case GL_COLOR_ARRAY:
-      case GL_INDEX_ARRAY:
       case GL_TEXTURE_COORD_ARRAY:
+         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
+            goto invalid_enum_error;
+         client_state( ctx, cap, state );
+         return;
+      case GL_INDEX_ARRAY:
       case GL_EDGE_FLAG_ARRAY:
       case GL_FOG_COORDINATE_ARRAY_EXT:
       case GL_SECONDARY_COLOR_ARRAY_EXT:
+         if (ctx->API != API_OPENGL_COMPAT)
+            goto invalid_enum_error;
+         client_state( ctx, cap, state );
+         return;
       case GL_POINT_SIZE_ARRAY_OES:
+         if (ctx->API != API_OPENGLES)
+            goto invalid_enum_error;
          client_state( ctx, cap, state );
          return;
 
       /* GL_ARB_texture_cube_map */
-      case GL_TEXTURE_CUBE_MAP_ARB:
+      case GL_TEXTURE_CUBE_MAP:
          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
             goto invalid_enum_error;
          CHECK_EXTENSION(ARB_texture_cube_map, cap);
@@ -795,7 +819,9 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
       case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
          if (ctx->Multisample.SampleAlphaToCoverage == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
+         FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleAlphaToXEnable ? 0 :
+                                                         _NEW_MULTISAMPLE);
+         ctx->NewDriverState |= ctx->DriverFlags.NewSampleAlphaToXEnable;
          ctx->Multisample.SampleAlphaToCoverage = state;
          break;
       case GL_SAMPLE_ALPHA_TO_ONE_ARB:
@@ -803,13 +829,17 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
             goto invalid_enum_error;
          if (ctx->Multisample.SampleAlphaToOne == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
+         FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleAlphaToXEnable ? 0 :
+                                                         _NEW_MULTISAMPLE);
+         ctx->NewDriverState |= ctx->DriverFlags.NewSampleAlphaToXEnable;
          ctx->Multisample.SampleAlphaToOne = state;
          break;
       case GL_SAMPLE_COVERAGE_ARB:
          if (ctx->Multisample.SampleCoverage == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
+         FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleMask ? 0 :
+                                                         _NEW_MULTISAMPLE);
+         ctx->NewDriverState |= ctx->DriverFlags.NewSampleMask;
          ctx->Multisample.SampleCoverage = state;
          break;
       case GL_SAMPLE_COVERAGE_INVERT_ARB:
@@ -817,18 +847,22 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
             goto invalid_enum_error;
          if (ctx->Multisample.SampleCoverageInvert == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
+         FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleMask ? 0 :
+                                                         _NEW_MULTISAMPLE);
+         ctx->NewDriverState |= ctx->DriverFlags.NewSampleMask;
          ctx->Multisample.SampleCoverageInvert = state;
          break;
 
       /* GL_ARB_sample_shading */
       case GL_SAMPLE_SHADING:
-         if (!_mesa_is_desktop_gl(ctx))
+         if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
             goto invalid_enum_error;
          CHECK_EXTENSION(ARB_sample_shading, cap);
          if (ctx->Multisample.SampleShading == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
+         FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleShading ? 0 :
+                                                         _NEW_MULTISAMPLE);
+         ctx->NewDriverState |= ctx->DriverFlags.NewSampleShading;
          ctx->Multisample.SampleShading = state;
          break;
 
@@ -859,7 +893,7 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
          CHECK_EXTENSION(ARB_vertex_program, cap);
          if (ctx->VertexProgram.Enabled == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_PROGRAM); 
+         FLUSH_VERTICES(ctx, _NEW_PROGRAM);
          ctx->VertexProgram.Enabled = state;
          break;
       case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
@@ -880,7 +914,7 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
          CHECK_EXTENSION(ARB_vertex_program, cap);
          if (ctx->VertexProgram.TwoSideEnabled == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_PROGRAM); 
+         FLUSH_VERTICES(ctx, _NEW_PROGRAM);
          ctx->VertexProgram.TwoSideEnabled = state;
          break;
 
@@ -901,7 +935,8 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
          CHECK_EXTENSION(EXT_stencil_two_side, cap);
          if (ctx->Stencil.TestTwoSide == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_STENCIL);
+         FLUSH_VERTICES(ctx, ctx->DriverFlags.NewStencil ? 0 : _NEW_STENCIL);
+         ctx->NewDriverState |= ctx->DriverFlags.NewStencil;
          ctx->Stencil.TestTwoSide = state;
          if (state) {
             ctx->Stencil._BackFace = 2;
@@ -927,44 +962,45 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
          CHECK_EXTENSION(EXT_depth_bounds_test, cap);
          if (ctx->Depth.BoundsTest == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_DEPTH);
+         FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepth ? 0 : _NEW_DEPTH);
+         ctx->NewDriverState |= ctx->DriverFlags.NewDepth;
          ctx->Depth.BoundsTest = state;
          break;
 
       case GL_DEPTH_CLAMP:
          if (!_mesa_is_desktop_gl(ctx))
             goto invalid_enum_error;
-        CHECK_EXTENSION(ARB_depth_clamp, cap);
+         CHECK_EXTENSION(ARB_depth_clamp, cap);
          if (ctx->Transform.DepthClamp == state)
             return;
          FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
-        ctx->Transform.DepthClamp = state;
-        break;
+         ctx->Transform.DepthClamp = state;
+         break;
 
       case GL_FRAGMENT_SHADER_ATI:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
         CHECK_EXTENSION(ATI_fragment_shader, cap);
-       if (ctx->ATIFragmentShader.Enabled == state)
-         return;
-       FLUSH_VERTICES(ctx, _NEW_PROGRAM);
-       ctx->ATIFragmentShader.Enabled = state;
+        if (ctx->ATIFragmentShader.Enabled == state)
+           return;
+        FLUSH_VERTICES(ctx, _NEW_PROGRAM);
+        ctx->ATIFragmentShader.Enabled = state;
         break;
 
       case GL_TEXTURE_CUBE_MAP_SEAMLESS:
          if (!_mesa_is_desktop_gl(ctx))
             goto invalid_enum_error;
-        CHECK_EXTENSION(ARB_seamless_cube_map, cap);
-        if (ctx->Texture.CubeMapSeamless != state) {
-           FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-           ctx->Texture.CubeMapSeamless = state;
-        }
-        break;
+         CHECK_EXTENSION(ARB_seamless_cube_map, cap);
+         if (ctx->Texture.CubeMapSeamless != state) {
+            FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT);
+            ctx->Texture.CubeMapSeamless = state;
+         }
+         break;
 
       case GL_RASTERIZER_DISCARD:
          if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
             goto invalid_enum_error;
-        CHECK_EXTENSION(EXT_transform_feedback, cap);
+         CHECK_EXTENSION(EXT_transform_feedback, cap);
          if (ctx->RasterDiscard != state) {
             FLUSH_VERTICES(ctx, 0);
             ctx->NewDriverState |= ctx->DriverFlags.NewRasterizerDiscard;
@@ -980,17 +1016,17 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
             goto invalid_enum_error;
          }
          if (ctx->Array.PrimitiveRestart != state) {
-            FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
+            FLUSH_VERTICES(ctx, 0);
             ctx->Array.PrimitiveRestart = state;
             update_derived_primitive_restart_state(ctx);
          }
          break;
 
       case GL_PRIMITIVE_RESTART_FIXED_INDEX:
-        if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility)
+         if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility)
             goto invalid_enum_error;
          if (ctx->Array.PrimitiveRestartFixedIndex != state) {
-            FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
+            FLUSH_VERTICES(ctx, 0);
             ctx->Array.PrimitiveRestartFixedIndex = state;
             update_derived_primitive_restart_state(ctx);
          }
@@ -1016,15 +1052,26 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
 
       /* ARB_texture_multisample */
       case GL_SAMPLE_MASK:
-         if (!_mesa_is_desktop_gl(ctx))
+         if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
             goto invalid_enum_error;
          CHECK_EXTENSION(ARB_texture_multisample, cap);
          if (ctx->Multisample.SampleMask == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
+         FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleMask ? 0 :
+                                                         _NEW_MULTISAMPLE);
+         ctx->NewDriverState |= ctx->DriverFlags.NewSampleMask;
          ctx->Multisample.SampleMask = state;
          break;
 
+      case GL_BLEND_ADVANCED_COHERENT_KHR:
+         CHECK_EXTENSION(KHR_blend_equation_advanced_coherent, cap);
+         if (ctx->Color.BlendCoherent == state)
+            return;
+         FLUSH_VERTICES(ctx, ctx->DriverFlags.NewBlend ? 0 : _NEW_COLOR);
+         ctx->NewDriverState |= ctx->DriverFlags.NewBlend;
+         ctx->Color.BlendCoherent = state;
+         break;
+
       default:
          goto invalid_enum_error;
    }
@@ -1037,7 +1084,7 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
 
 invalid_enum_error:
    _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(%s)",
-               state ? "Enable" : "Disable", _mesa_lookup_enum_by_nr(cap));
+               state ? "Enable" : "Disable", _mesa_enum_to_string(cap));
 }
 
 
@@ -1075,7 +1122,7 @@ void
 _mesa_set_enablei(struct gl_context *ctx, GLenum cap,
                   GLuint index, GLboolean state)
 {
-   ASSERT(state == 0 || state == 1);
+   assert(state == 0 || state == 1);
    switch (cap) {
    case GL_BLEND:
       if (!ctx->Extensions.EXT_draw_buffers2) {
@@ -1087,7 +1134,7 @@ _mesa_set_enablei(struct gl_context *ctx, GLenum cap,
          return;
       }
       if (((ctx->Color.BlendEnabled >> index) & 1) != state) {
-         FLUSH_VERTICES(ctx, _NEW_COLOR);
+         _mesa_flush_vertices_for_blend_state(ctx);
          if (state)
             ctx->Color.BlendEnabled |= (1 << index);
          else
@@ -1101,7 +1148,9 @@ _mesa_set_enablei(struct gl_context *ctx, GLenum cap,
          return;
       }
       if (((ctx->Scissor.EnableFlags >> index) & 1) != state) {
-         FLUSH_VERTICES(ctx, _NEW_SCISSOR);
+         FLUSH_VERTICES(ctx,
+                        ctx->DriverFlags.NewScissorTest ? 0 : _NEW_SCISSOR);
+         ctx->NewDriverState |= ctx->DriverFlags.NewScissorTest;
          if (state)
             ctx->Scissor.EnableFlags |= (1 << index);
          else
@@ -1116,7 +1165,7 @@ _mesa_set_enablei(struct gl_context *ctx, GLenum cap,
 invalid_enum_error:
     _mesa_error(ctx, GL_INVALID_ENUM, "%s(cap=%s)",
                 state ? "glEnablei" : "glDisablei",
-                _mesa_lookup_enum_by_nr(cap));
+                _mesa_enum_to_string(cap));
 }
 
 
@@ -1158,7 +1207,7 @@ _mesa_IsEnabledi( GLenum cap, GLuint index )
       return (ctx->Scissor.EnableFlags >> index) & 1;
    default:
       _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabledIndexed(cap=%s)",
-                  _mesa_lookup_enum_by_nr(cap));
+                  _mesa_enum_to_string(cap));
       return GL_FALSE;
    }
 }
@@ -1214,10 +1263,10 @@ _mesa_IsEnabled( GLenum cap )
       case GL_AUTO_NORMAL:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-        return ctx->Eval.AutoNormal;
+         return ctx->Eval.AutoNormal;
       case GL_BLEND:
          return ctx->Color.BlendEnabled & 1;  /* return state for buffer[0] */
-      case GL_CLIP_DISTANCE0:
+      case GL_CLIP_DISTANCE0: /* aka GL_CLIP_PLANE0 */
       case GL_CLIP_DISTANCE1:
       case GL_CLIP_DISTANCE2:
       case GL_CLIP_DISTANCE3:
@@ -1230,38 +1279,25 @@ _mesa_IsEnabled( GLenum cap )
          if (p >= ctx->Const.MaxClipPlanes)
             goto invalid_enum_error;
 
-        return (ctx->Transform.ClipPlanesEnabled >> p) & 1;
+         return (ctx->Transform.ClipPlanesEnabled >> p) & 1;
       }
       case GL_COLOR_MATERIAL:
          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
             goto invalid_enum_error;
-        return ctx->Light.ColorMaterialEnabled;
+         return ctx->Light.ColorMaterialEnabled;
       case GL_CULL_FACE:
          return ctx->Polygon.CullFlag;
       case GL_DEBUG_OUTPUT:
-         if (!_mesa_is_desktop_gl(ctx))
-            goto invalid_enum_error;
-         if (ctx->Debug) {
-            return ctx->Debug->DebugOutput;
-         } else {
-            return GL_FALSE;
-         }
       case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB:
-         if (!_mesa_is_desktop_gl(ctx))
-            goto invalid_enum_error;
-         if (ctx->Debug) {
-            return ctx->Debug->SyncOutput;
-         } else {
-            return GL_FALSE;
-         }
+         return (GLboolean) _mesa_get_debug_state_int(ctx, cap);
       case GL_DEPTH_TEST:
          return ctx->Depth.Test;
       case GL_DITHER:
-        return ctx->Color.DitherFlag;
+         return ctx->Color.DitherFlag;
       case GL_FOG:
          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
             goto invalid_enum_error;
-        return ctx->Fog.Enabled;
+         return ctx->Fog.Enabled;
       case GL_LIGHTING:
          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
             goto invalid_enum_error;
@@ -1280,125 +1316,125 @@ _mesa_IsEnabled( GLenum cap )
       case GL_LINE_SMOOTH:
          if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
             goto invalid_enum_error;
-        return ctx->Line.SmoothFlag;
+         return ctx->Line.SmoothFlag;
       case GL_LINE_STIPPLE:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-        return ctx->Line.StippleFlag;
+         return ctx->Line.StippleFlag;
       case GL_INDEX_LOGIC_OP:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-        return ctx->Color.IndexLogicOpEnabled;
+         return ctx->Color.IndexLogicOpEnabled;
       case GL_COLOR_LOGIC_OP:
          if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
             goto invalid_enum_error;
-        return ctx->Color.ColorLogicOpEnabled;
+         return ctx->Color.ColorLogicOpEnabled;
       case GL_MAP1_COLOR_4:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-        return ctx->Eval.Map1Color4;
+         return ctx->Eval.Map1Color4;
       case GL_MAP1_INDEX:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-        return ctx->Eval.Map1Index;
+         return ctx->Eval.Map1Index;
       case GL_MAP1_NORMAL:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-        return ctx->Eval.Map1Normal;
+         return ctx->Eval.Map1Normal;
       case GL_MAP1_TEXTURE_COORD_1:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-        return ctx->Eval.Map1TextureCoord1;
+         return ctx->Eval.Map1TextureCoord1;
       case GL_MAP1_TEXTURE_COORD_2:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-        return ctx->Eval.Map1TextureCoord2;
+         return ctx->Eval.Map1TextureCoord2;
       case GL_MAP1_TEXTURE_COORD_3:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-        return ctx->Eval.Map1TextureCoord3;
+         return ctx->Eval.Map1TextureCoord3;
       case GL_MAP1_TEXTURE_COORD_4:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-        return ctx->Eval.Map1TextureCoord4;
+         return ctx->Eval.Map1TextureCoord4;
       case GL_MAP1_VERTEX_3:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-        return ctx->Eval.Map1Vertex3;
+         return ctx->Eval.Map1Vertex3;
       case GL_MAP1_VERTEX_4:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-        return ctx->Eval.Map1Vertex4;
+         return ctx->Eval.Map1Vertex4;
       case GL_MAP2_COLOR_4:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-        return ctx->Eval.Map2Color4;
+         return ctx->Eval.Map2Color4;
       case GL_MAP2_INDEX:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-        return ctx->Eval.Map2Index;
+         return ctx->Eval.Map2Index;
       case GL_MAP2_NORMAL:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-        return ctx->Eval.Map2Normal;
+         return ctx->Eval.Map2Normal;
       case GL_MAP2_TEXTURE_COORD_1:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-        return ctx->Eval.Map2TextureCoord1;
+         return ctx->Eval.Map2TextureCoord1;
       case GL_MAP2_TEXTURE_COORD_2:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-        return ctx->Eval.Map2TextureCoord2;
+         return ctx->Eval.Map2TextureCoord2;
       case GL_MAP2_TEXTURE_COORD_3:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-        return ctx->Eval.Map2TextureCoord3;
+         return ctx->Eval.Map2TextureCoord3;
       case GL_MAP2_TEXTURE_COORD_4:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-        return ctx->Eval.Map2TextureCoord4;
+         return ctx->Eval.Map2TextureCoord4;
       case GL_MAP2_VERTEX_3:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-        return ctx->Eval.Map2Vertex3;
+         return ctx->Eval.Map2Vertex3;
       case GL_MAP2_VERTEX_4:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-        return ctx->Eval.Map2Vertex4;
+         return ctx->Eval.Map2Vertex4;
       case GL_NORMALIZE:
          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
             goto invalid_enum_error;
-        return ctx->Transform.Normalize;
+         return ctx->Transform.Normalize;
       case GL_POINT_SMOOTH:
          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
             goto invalid_enum_error;
-        return ctx->Point.SmoothFlag;
+         return ctx->Point.SmoothFlag;
       case GL_POLYGON_SMOOTH:
          if (!_mesa_is_desktop_gl(ctx))
             goto invalid_enum_error;
-        return ctx->Polygon.SmoothFlag;
+         return ctx->Polygon.SmoothFlag;
       case GL_POLYGON_STIPPLE:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-        return ctx->Polygon.StippleFlag;
+         return ctx->Polygon.StippleFlag;
       case GL_POLYGON_OFFSET_POINT:
          if (!_mesa_is_desktop_gl(ctx))
             goto invalid_enum_error;
-        return ctx->Polygon.OffsetPoint;
+         return ctx->Polygon.OffsetPoint;
       case GL_POLYGON_OFFSET_LINE:
          if (!_mesa_is_desktop_gl(ctx))
             goto invalid_enum_error;
-        return ctx->Polygon.OffsetLine;
+         return ctx->Polygon.OffsetLine;
       case GL_POLYGON_OFFSET_FILL:
-        return ctx->Polygon.OffsetFill;
+         return ctx->Polygon.OffsetFill;
       case GL_RESCALE_NORMAL_EXT:
          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
             goto invalid_enum_error;
          return ctx->Transform.RescaleNormals;
       case GL_SCISSOR_TEST:
-        return ctx->Scissor.EnableFlags & 1;  /* return state for index 0 */
+         return ctx->Scissor.EnableFlags & 1;  /* return state for index 0 */
       case GL_STENCIL_TEST:
-        return ctx->Stencil.Enabled;
+         return ctx->Stencil.Enabled;
       case GL_TEXTURE_1D:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
@@ -1428,7 +1464,7 @@ _mesa_IsEnabled( GLenum cap )
          }
          return GL_FALSE;
       case GL_TEXTURE_GEN_STR_OES:
-        {
+         {
             const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
 
             if (ctx->API != API_OPENGLES)
@@ -1481,7 +1517,7 @@ _mesa_IsEnabled( GLenum cap )
          return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled;
 
       /* GL_ARB_texture_cube_map */
-      case GL_TEXTURE_CUBE_MAP_ARB:
+      case GL_TEXTURE_CUBE_MAP:
          CHECK_EXTENSION(ARB_texture_cube_map);
          return is_texture_enabled(ctx, TEXTURE_CUBE_BIT);
 
@@ -1577,19 +1613,19 @@ _mesa_IsEnabled( GLenum cap )
       case GL_FRAGMENT_SHADER_ATI:
          if (ctx->API != API_OPENGL_COMPAT)
             goto invalid_enum_error;
-        CHECK_EXTENSION(ATI_fragment_shader);
-        return ctx->ATIFragmentShader.Enabled;
+         CHECK_EXTENSION(ATI_fragment_shader);
+         return ctx->ATIFragmentShader.Enabled;
 
       case GL_TEXTURE_CUBE_MAP_SEAMLESS:
          if (!_mesa_is_desktop_gl(ctx))
             goto invalid_enum_error;
-        CHECK_EXTENSION(ARB_seamless_cube_map);
-        return ctx->Texture.CubeMapSeamless;
+         CHECK_EXTENSION(ARB_seamless_cube_map);
+         return ctx->Texture.CubeMapSeamless;
 
       case GL_RASTERIZER_DISCARD:
          if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
             goto invalid_enum_error;
-        CHECK_EXTENSION(EXT_transform_feedback);
+         CHECK_EXTENSION(EXT_transform_feedback);
          return ctx->RasterDiscard;
 
       /* GL_NV_primitive_restart */
@@ -1607,7 +1643,7 @@ _mesa_IsEnabled( GLenum cap )
          return ctx->Array.PrimitiveRestart;
 
       case GL_PRIMITIVE_RESTART_FIXED_INDEX:
-        if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility) {
+         if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility) {
             goto invalid_enum_error;
          }
          return ctx->Array.PrimitiveRestartFixedIndex;
@@ -1616,30 +1652,38 @@ _mesa_IsEnabled( GLenum cap )
       case GL_FRAMEBUFFER_SRGB_EXT:
          if (!_mesa_is_desktop_gl(ctx))
             goto invalid_enum_error;
-        CHECK_EXTENSION(EXT_framebuffer_sRGB);
-        return ctx->Color.sRGBEnabled;
+         CHECK_EXTENSION(EXT_framebuffer_sRGB);
+         return ctx->Color.sRGBEnabled;
 
       /* GL_OES_EGL_image_external */
       case GL_TEXTURE_EXTERNAL_OES:
          if (!_mesa_is_gles(ctx))
             goto invalid_enum_error;
-        CHECK_EXTENSION(OES_EGL_image_external);
+         CHECK_EXTENSION(OES_EGL_image_external);
          return is_texture_enabled(ctx, TEXTURE_EXTERNAL_BIT);
 
       /* ARB_texture_multisample */
       case GL_SAMPLE_MASK:
-         if (!_mesa_is_desktop_gl(ctx))
+         if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
             goto invalid_enum_error;
          CHECK_EXTENSION(ARB_texture_multisample);
          return ctx->Multisample.SampleMask;
 
       /* ARB_sample_shading */
       case GL_SAMPLE_SHADING:
-         if (!_mesa_is_desktop_gl(ctx))
+         if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
             goto invalid_enum_error;
          CHECK_EXTENSION(ARB_sample_shading);
          return ctx->Multisample.SampleShading;
 
+      case GL_BLEND_ADVANCED_COHERENT_KHR:
+         CHECK_EXTENSION(KHR_blend_equation_advanced_coherent);
+         return ctx->Color.BlendCoherent;
+
+      case GL_CONSERVATIVE_RASTERIZATION_INTEL:
+         CHECK_EXTENSION(INTEL_conservative_rasterization);
+         return ctx->IntelConservativeRasterization;
+
       default:
          goto invalid_enum_error;
    }
@@ -1648,6 +1692,6 @@ _mesa_IsEnabled( GLenum cap )
 
 invalid_enum_error:
    _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(%s)",
-               _mesa_lookup_enum_by_nr(cap));
+               _mesa_enum_to_string(cap));
    return GL_FALSE;
 }