mesa: Extension boilerplate for INTEL_shader_atomic_float_minmax
[mesa.git] / src / mesa / main / enable.c
index 8e99f2504f19042c086bf78e76f6a28f080368ec..d1b2f3a962505dc8bbe1b09cd86ee5c223c9b0f8 100644 (file)
@@ -29,6 +29,7 @@
 
 
 #include "glheader.h"
+#include "arrayobj.h"
 #include "blend.h"
 #include "clip.h"
 #include "context.h"
@@ -38,7 +39,9 @@
 #include "light.h"
 #include "mtypes.h"
 #include "enums.h"
+#include "state.h"
 #include "texstate.h"
+#include "varray.h"
 
 
 
@@ -57,55 +60,56 @@ update_derived_primitive_restart_state(struct gl_context *ctx)
       || ctx->Array.PrimitiveRestartFixedIndex;
 }
 
+
+/**
+ * Helper to enable/disable VAO client-side state.
+ */
+static void
+vao_state(struct gl_context *ctx, gl_vert_attrib attr, GLboolean state)
+{
+   if (state)
+      _mesa_enable_vertex_array_attrib(ctx, ctx->Array.VAO, attr);
+   else
+      _mesa_disable_vertex_array_attrib(ctx, ctx->Array.VAO, attr);
+}
+
+
 /**
  * Helper to enable/disable client-side state.
  */
 static void
 client_state(struct gl_context *ctx, GLenum cap, GLboolean state)
 {
-   struct gl_vertex_array_object *vao = ctx->Array.VAO;
-   GLbitfield64 flag;
-   GLboolean *var;
-
    switch (cap) {
       case GL_VERTEX_ARRAY:
-         var = &vao->VertexAttrib[VERT_ATTRIB_POS].Enabled;
-         flag = VERT_BIT_POS;
+         vao_state(ctx, VERT_ATTRIB_POS, state);
          break;
       case GL_NORMAL_ARRAY:
-         var = &vao->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled;
-         flag = VERT_BIT_NORMAL;
+         vao_state(ctx, VERT_ATTRIB_NORMAL, state);
          break;
       case GL_COLOR_ARRAY:
-         var = &vao->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled;
-         flag = VERT_BIT_COLOR0;
+         vao_state(ctx, VERT_ATTRIB_COLOR0, state);
          break;
       case GL_INDEX_ARRAY:
-         var = &vao->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled;
-         flag = VERT_BIT_COLOR_INDEX;
+         vao_state(ctx, VERT_ATTRIB_COLOR_INDEX, state);
          break;
       case GL_TEXTURE_COORD_ARRAY:
-         var = &vao->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Enabled;
-         flag = VERT_BIT_TEX(ctx->Array.ActiveTexture);
+         vao_state(ctx, VERT_ATTRIB_TEX(ctx->Array.ActiveTexture), state);
          break;
       case GL_EDGE_FLAG_ARRAY:
-         var = &vao->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled;
-         flag = VERT_BIT_EDGEFLAG;
+         vao_state(ctx, VERT_ATTRIB_EDGEFLAG, state);
          break;
       case GL_FOG_COORDINATE_ARRAY_EXT:
-         var = &vao->VertexAttrib[VERT_ATTRIB_FOG].Enabled;
-         flag = VERT_BIT_FOG;
+         vao_state(ctx, VERT_ATTRIB_FOG, state);
          break;
       case GL_SECONDARY_COLOR_ARRAY_EXT:
-         var = &vao->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled;
-         flag = VERT_BIT_COLOR1;
+         vao_state(ctx, VERT_ATTRIB_COLOR1, state);
          break;
 
       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;
+         vao_state(ctx, VERT_ATTRIB_POINT_SIZE, state);
          break;
 
       /* GL_NV_primitive_restart */
@@ -124,20 +128,6 @@ client_state(struct gl_context *ctx, GLenum cap, GLboolean state)
          goto invalid_enum_error;
    }
 
-   if (*var == state)
-      return;
-
-   FLUSH_VERTICES(ctx, _NEW_ARRAY);
-
-   *var = state;
-
-   if (state)
-      vao->_Enabled |= flag;
-   else
-      vao->_Enabled &= ~flag;
-
-   vao->NewArrays |= flag;
-
    if (ctx->Driver.Enable) {
       ctx->Driver.Enable( ctx, cap, state );
    }
@@ -197,7 +187,7 @@ _mesa_DisableClientState( GLenum cap )
  * 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 *
+static struct gl_fixedfunc_texture_unit *
 get_texcoord_unit(struct gl_context *ctx)
 {
    if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
@@ -205,7 +195,7 @@ get_texcoord_unit(struct gl_context *ctx)
       return NULL;
    }
    else {
-      return &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+      return &ctx->Texture.FixedFuncUnit[ctx->Texture.CurrentUnit];
    }
 }
 
@@ -218,7 +208,11 @@ get_texcoord_unit(struct gl_context *ctx)
 static GLboolean
 enable_texture(struct gl_context *ctx, GLboolean state, GLbitfield texBit)
 {
-   struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
+   struct gl_fixedfunc_texture_unit *texUnit =
+      _mesa_get_current_fixedfunc_tex_unit(ctx);
+   if (!texUnit)
+      return GL_FALSE;
+
    const GLbitfield newenabled = state
       ? (texUnit->Enabled | texBit) : (texUnit->Enabled & ~texBit);
 
@@ -324,7 +318,8 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
             GLbitfield newEnabled =
                state * ((1 << ctx->Const.MaxDrawBuffers) - 1);
             if (newEnabled != ctx->Color.BlendEnabled) {
-               _mesa_flush_vertices_for_blend_state(ctx);
+               _mesa_flush_vertices_for_blend_adv(ctx, newEnabled,
+                                               ctx->Color._AdvancedBlendMode);
                ctx->Color.BlendEnabled = newEnabled;
             }
          }
@@ -487,6 +482,16 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
             ctx->DriverFlags.NewIntelConservativeRasterization;
          ctx->IntelConservativeRasterization = state;
          break;
+      case GL_CONSERVATIVE_RASTERIZATION_NV:
+         if (!_mesa_has_NV_conservative_raster(ctx))
+            goto invalid_enum_error;
+         if (ctx->ConservativeRasterization == state)
+            return;
+         FLUSH_VERTICES(ctx, 0);
+         ctx->NewDriverState |=
+            ctx->DriverFlags.NewNvConservativeRasterization;
+         ctx->ConservativeRasterization = state;
+         break;
       case GL_COLOR_LOGIC_OP:
          if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
             goto invalid_enum_error;
@@ -758,7 +763,7 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
       case GL_TEXTURE_GEN_R:
       case GL_TEXTURE_GEN_Q:
          {
-            struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+            struct gl_fixedfunc_texture_unit *texUnit = get_texcoord_unit(ctx);
 
             if (ctx->API != API_OPENGL_COMPAT)
                goto invalid_enum_error;
@@ -779,7 +784,7 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
       case GL_TEXTURE_GEN_STR_OES:
          /* disable S, T, and R at the same time */
          {
-            struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+            struct gl_fixedfunc_texture_unit *texUnit = get_texcoord_unit(ctx);
 
             if (ctx->API != API_OPENGLES)
                goto invalid_enum_error;
@@ -925,6 +930,7 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
             return;
          FLUSH_VERTICES(ctx, _NEW_PROGRAM);
          ctx->VertexProgram.Enabled = state;
+         _mesa_update_vertex_processing_mode(ctx);
          break;
       case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
          /* This was added with ARB_vertex_program, but it is also used with
@@ -1193,11 +1199,16 @@ _mesa_set_enablei(struct gl_context *ctx, GLenum cap,
          return;
       }
       if (((ctx->Color.BlendEnabled >> index) & 1) != state) {
-         _mesa_flush_vertices_for_blend_state(ctx);
+         GLbitfield enabled = ctx->Color.BlendEnabled;
+
          if (state)
-            ctx->Color.BlendEnabled |= (1 << index);
+            enabled |= (1 << index);
          else
-            ctx->Color.BlendEnabled &= ~(1 << index);
+            enabled &= ~(1 << index);
+
+         _mesa_flush_vertices_for_blend_adv(ctx, enabled,
+                                            ctx->Color._AdvancedBlendMode);
+         ctx->Color.BlendEnabled = enabled;
       }
       break;
    case GL_SCISSOR_TEST:
@@ -1293,8 +1304,12 @@ _mesa_IsEnabledi( GLenum cap, GLuint index )
 static GLboolean
 is_texture_enabled(struct gl_context *ctx, GLbitfield bit)
 {
-   const struct gl_texture_unit *const texUnit =
-       &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+   const struct gl_fixedfunc_texture_unit *const texUnit =
+      _mesa_get_current_fixedfunc_tex_unit(ctx);
+
+   if (!texUnit)
+      return GL_FALSE;
+
    return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE;
 }
 
@@ -1511,7 +1526,8 @@ _mesa_IsEnabled( GLenum cap )
       case GL_TEXTURE_GEN_R:
       case GL_TEXTURE_GEN_Q:
          {
-            const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+            const struct gl_fixedfunc_texture_unit *texUnit =
+               get_texcoord_unit(ctx);
 
             if (ctx->API != API_OPENGL_COMPAT)
                goto invalid_enum_error;
@@ -1524,7 +1540,8 @@ _mesa_IsEnabled( GLenum cap )
          return GL_FALSE;
       case GL_TEXTURE_GEN_STR_OES:
          {
-            const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
+            const struct gl_fixedfunc_texture_unit *texUnit =
+               get_texcoord_unit(ctx);
 
             if (ctx->API != API_OPENGLES)
                goto invalid_enum_error;
@@ -1743,6 +1760,10 @@ _mesa_IsEnabled( GLenum cap )
          CHECK_EXTENSION(INTEL_conservative_rasterization);
          return ctx->IntelConservativeRasterization;
 
+      case GL_CONSERVATIVE_RASTERIZATION_NV:
+         CHECK_EXTENSION(NV_conservative_raster);
+         return ctx->ConservativeRasterization;
+
       case GL_TILE_RASTER_ORDER_FIXED_MESA:
          CHECK_EXTENSION(MESA_tile_raster_order);
          return ctx->TileRasterOrderFixed;