Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /**
  2.  * \file enable.c
  3.  * Enable/disable/query GL capabilities.
  4.  */
  5.  
  6. /*
  7.  * Mesa 3-D graphics library
  8.  *
  9.  * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  10.  *
  11.  * Permission is hereby granted, free of charge, to any person obtaining a
  12.  * copy of this software and associated documentation files (the "Software"),
  13.  * to deal in the Software without restriction, including without limitation
  14.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  15.  * and/or sell copies of the Software, and to permit persons to whom the
  16.  * Software is furnished to do so, subject to the following conditions:
  17.  *
  18.  * The above copyright notice and this permission notice shall be included
  19.  * in all copies or substantial portions of the Software.
  20.  *
  21.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  22.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  24.  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  25.  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  26.  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  27.  * OTHER DEALINGS IN THE SOFTWARE.
  28.  */
  29.  
  30.  
  31. #include "glheader.h"
  32. #include "clip.h"
  33. #include "context.h"
  34. #include "enable.h"
  35. #include "light.h"
  36. #include "simple_list.h"
  37. #include "mtypes.h"
  38. #include "enums.h"
  39. #include "api_arrayelt.h"
  40. #include "texstate.h"
  41. #include "drivers/common/meta.h"
  42.  
  43.  
  44.  
  45. #define CHECK_EXTENSION(EXTNAME, CAP)                                   \
  46.    if (!ctx->Extensions.EXTNAME) {                                      \
  47.       goto invalid_enum_error;                                          \
  48.    }
  49.  
  50.  
  51. static void
  52. update_derived_primitive_restart_state(struct gl_context *ctx)
  53. {
  54.    /* Update derived primitive restart state.
  55.     */
  56.    ctx->Array._PrimitiveRestart = ctx->Array.PrimitiveRestart
  57.       || ctx->Array.PrimitiveRestartFixedIndex;
  58. }
  59.  
  60. /**
  61.  * Helper to enable/disable client-side state.
  62.  */
  63. static void
  64. client_state(struct gl_context *ctx, GLenum cap, GLboolean state)
  65. {
  66.    struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
  67.    GLbitfield64 flag;
  68.    GLboolean *var;
  69.  
  70.    switch (cap) {
  71.       case GL_VERTEX_ARRAY:
  72.          var = &arrayObj->VertexAttrib[VERT_ATTRIB_POS].Enabled;
  73.          flag = VERT_BIT_POS;
  74.          break;
  75.       case GL_NORMAL_ARRAY:
  76.          var = &arrayObj->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled;
  77.          flag = VERT_BIT_NORMAL;
  78.          break;
  79.       case GL_COLOR_ARRAY:
  80.          var = &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled;
  81.          flag = VERT_BIT_COLOR0;
  82.          break;
  83.       case GL_INDEX_ARRAY:
  84.          var = &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled;
  85.          flag = VERT_BIT_COLOR_INDEX;
  86.          break;
  87.       case GL_TEXTURE_COORD_ARRAY:
  88.          var = &arrayObj->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Enabled;
  89.          flag = VERT_BIT_TEX(ctx->Array.ActiveTexture);
  90.          break;
  91.       case GL_EDGE_FLAG_ARRAY:
  92.          var = &arrayObj->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled;
  93.          flag = VERT_BIT_EDGEFLAG;
  94.          break;
  95.       case GL_FOG_COORDINATE_ARRAY_EXT:
  96.          var = &arrayObj->VertexAttrib[VERT_ATTRIB_FOG].Enabled;
  97.          flag = VERT_BIT_FOG;
  98.          break;
  99.       case GL_SECONDARY_COLOR_ARRAY_EXT:
  100.          var = &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled;
  101.          flag = VERT_BIT_COLOR1;
  102.          break;
  103.  
  104.       case GL_POINT_SIZE_ARRAY_OES:
  105.          var = &arrayObj->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled;
  106.          flag = VERT_BIT_POINT_SIZE;
  107.          break;
  108.  
  109.       /* GL_NV_primitive_restart */
  110.       case GL_PRIMITIVE_RESTART_NV:
  111.          if (!ctx->Extensions.NV_primitive_restart) {
  112.             goto invalid_enum_error;
  113.          }
  114.          var = &ctx->Array.PrimitiveRestart;
  115.          flag = 0;
  116.          break;
  117.  
  118.       default:
  119.          goto invalid_enum_error;
  120.    }
  121.  
  122.    if (*var == state)
  123.       return;
  124.  
  125.    FLUSH_VERTICES(ctx, _NEW_ARRAY);
  126.  
  127.    _ae_invalidate_state(ctx, _NEW_ARRAY);
  128.  
  129.    *var = state;
  130.  
  131.    update_derived_primitive_restart_state(ctx);
  132.  
  133.    if (state)
  134.       arrayObj->_Enabled |= flag;
  135.    else
  136.       arrayObj->_Enabled &= ~flag;
  137.  
  138.    if (ctx->Driver.Enable) {
  139.       ctx->Driver.Enable( ctx, cap, state );
  140.    }
  141.  
  142.    return;
  143.  
  144. invalid_enum_error:
  145.    _mesa_error(ctx, GL_INVALID_ENUM, "gl%sClientState(%s)",
  146.                state ? "Enable" : "Disable", _mesa_lookup_enum_by_nr(cap));
  147. }
  148.  
  149.  
  150. /**
  151.  * Enable GL capability.
  152.  * \param cap  state to enable/disable.
  153.  *
  154.  * Get's the current context, assures that we're outside glBegin()/glEnd() and
  155.  * calls client_state().
  156.  */
  157. void GLAPIENTRY
  158. _mesa_EnableClientState( GLenum cap )
  159. {
  160.    GET_CURRENT_CONTEXT(ctx);
  161.    client_state( ctx, cap, GL_TRUE );
  162. }
  163.  
  164.  
  165. /**
  166.  * Disable GL capability.
  167.  * \param cap  state to enable/disable.
  168.  *
  169.  * Get's the current context, assures that we're outside glBegin()/glEnd() and
  170.  * calls client_state().
  171.  */
  172. void GLAPIENTRY
  173. _mesa_DisableClientState( GLenum cap )
  174. {
  175.    GET_CURRENT_CONTEXT(ctx);
  176.    client_state( ctx, cap, GL_FALSE );
  177. }
  178.  
  179.  
  180. #undef CHECK_EXTENSION
  181. #define CHECK_EXTENSION(EXTNAME, CAP)                                   \
  182.    if (!ctx->Extensions.EXTNAME) {                                      \
  183.       goto invalid_enum_error;                                          \
  184.    }
  185.  
  186. #define CHECK_EXTENSION2(EXT1, EXT2, CAP)                               \
  187.    if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) {                \
  188.       goto invalid_enum_error;                                          \
  189.    }
  190.  
  191. /**
  192.  * Return pointer to current texture unit for setting/getting coordinate
  193.  * state.
  194.  * Note that we'll set GL_INVALID_OPERATION and return NULL if the active
  195.  * texture unit is higher than the number of supported coordinate units.
  196.  */
  197. static struct gl_texture_unit *
  198. get_texcoord_unit(struct gl_context *ctx)
  199. {
  200.    if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
  201.       _mesa_error(ctx, GL_INVALID_OPERATION, "glEnable/Disable(texcoord unit)");
  202.       return NULL;
  203.    }
  204.    else {
  205.       return &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
  206.    }
  207. }
  208.  
  209.  
  210. /**
  211.  * Helper function to enable or disable a texture target.
  212.  * \param bit  one of the TEXTURE_x_BIT values
  213.  * \return GL_TRUE if state is changing or GL_FALSE if no change
  214.  */
  215. static GLboolean
  216. enable_texture(struct gl_context *ctx, GLboolean state, GLbitfield texBit)
  217. {
  218.    struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
  219.    const GLbitfield newenabled = state
  220.       ? (texUnit->Enabled | texBit) : (texUnit->Enabled & ~texBit);
  221.  
  222.    if (texUnit->Enabled == newenabled)
  223.        return GL_FALSE;
  224.  
  225.    FLUSH_VERTICES(ctx, _NEW_TEXTURE);
  226.    texUnit->Enabled = newenabled;
  227.    return GL_TRUE;
  228. }
  229.  
  230.  
  231. /**
  232.  * Helper function to enable or disable GL_MULTISAMPLE, skipping the check for
  233.  * whether the API supports it (GLES doesn't).
  234.  */
  235. void
  236. _mesa_set_multisample(struct gl_context *ctx, GLboolean state)
  237. {
  238.    if (ctx->Multisample.Enabled == state)
  239.       return;
  240.    FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
  241.    ctx->Multisample.Enabled = state;
  242.  
  243.    if (ctx->Driver.Enable) {
  244.       ctx->Driver.Enable(ctx, GL_MULTISAMPLE, state);
  245.    }
  246. }
  247.  
  248. /**
  249.  * Helper function to enable or disable GL_FRAMEBUFFER_SRGB, skipping the
  250.  * check for whether the API supports it (GLES doesn't).
  251.  */
  252. void
  253. _mesa_set_framebuffer_srgb(struct gl_context *ctx, GLboolean state)
  254. {
  255.    if (ctx->Color.sRGBEnabled == state)
  256.       return;
  257.    FLUSH_VERTICES(ctx, _NEW_BUFFERS);
  258.    ctx->Color.sRGBEnabled = state;
  259.  
  260.    if (ctx->Driver.Enable) {
  261.       ctx->Driver.Enable(ctx, GL_FRAMEBUFFER_SRGB, state);
  262.    }
  263. }
  264.  
  265. /**
  266.  * Helper function to enable or disable state.
  267.  *
  268.  * \param ctx GL context.
  269.  * \param cap  the state to enable/disable
  270.  * \param state whether to enable or disable the specified capability.
  271.  *
  272.  * Updates the current context and flushes the vertices as needed. For
  273.  * capabilities associated with extensions it verifies that those extensions
  274.  * are effectivly present before updating. Notifies the driver via
  275.  * dd_function_table::Enable.
  276.  */
  277. void
  278. _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
  279. {
  280.    if (MESA_VERBOSE & VERBOSE_API)
  281.       _mesa_debug(ctx, "%s %s (newstate is %x)\n",
  282.                   state ? "glEnable" : "glDisable",
  283.                   _mesa_lookup_enum_by_nr(cap),
  284.                   ctx->NewState);
  285.  
  286.    switch (cap) {
  287.       case GL_ALPHA_TEST:
  288.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  289.             goto invalid_enum_error;
  290.          if (ctx->Color.AlphaEnabled == state)
  291.             return;
  292.          FLUSH_VERTICES(ctx, _NEW_COLOR);
  293.          ctx->Color.AlphaEnabled = state;
  294.          break;
  295.       case GL_AUTO_NORMAL:
  296.          if (ctx->API != API_OPENGL_COMPAT)
  297.             goto invalid_enum_error;
  298.          if (ctx->Eval.AutoNormal == state)
  299.             return;
  300.          FLUSH_VERTICES(ctx, _NEW_EVAL);
  301.          ctx->Eval.AutoNormal = state;
  302.          break;
  303.       case GL_BLEND:
  304.          {
  305.             GLbitfield newEnabled =
  306.                state * ((1 << ctx->Const.MaxDrawBuffers) - 1);
  307.             if (newEnabled != ctx->Color.BlendEnabled) {
  308.                FLUSH_VERTICES(ctx, _NEW_COLOR);
  309.                ctx->Color.BlendEnabled = newEnabled;
  310.             }
  311.          }
  312.          break;
  313.       case GL_CLIP_DISTANCE0:
  314.       case GL_CLIP_DISTANCE1:
  315.       case GL_CLIP_DISTANCE2:
  316.       case GL_CLIP_DISTANCE3:
  317.       case GL_CLIP_DISTANCE4:
  318.       case GL_CLIP_DISTANCE5:
  319.       case GL_CLIP_DISTANCE6:
  320.       case GL_CLIP_DISTANCE7:
  321.          {
  322.             const GLuint p = cap - GL_CLIP_DISTANCE0;
  323.  
  324.             if (p >= ctx->Const.MaxClipPlanes)
  325.                goto invalid_enum_error;
  326.  
  327.             if ((ctx->Transform.ClipPlanesEnabled & (1 << p))
  328.                 == ((GLuint) state << p))
  329.                return;
  330.  
  331.             FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
  332.  
  333.             if (state) {
  334.                ctx->Transform.ClipPlanesEnabled |= (1 << p);
  335.                _mesa_update_clip_plane(ctx, p);
  336.             }
  337.             else {
  338.                ctx->Transform.ClipPlanesEnabled &= ~(1 << p);
  339.             }              
  340.          }
  341.          break;
  342.       case GL_COLOR_MATERIAL:
  343.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  344.             goto invalid_enum_error;
  345.          if (ctx->Light.ColorMaterialEnabled == state)
  346.             return;
  347.          FLUSH_VERTICES(ctx, _NEW_LIGHT);
  348.          FLUSH_CURRENT(ctx, 0);
  349.          ctx->Light.ColorMaterialEnabled = state;
  350.          if (state) {
  351.             _mesa_update_color_material( ctx,
  352.                                   ctx->Current.Attrib[VERT_ATTRIB_COLOR0] );
  353.          }
  354.          break;
  355.       case GL_CULL_FACE:
  356.          if (ctx->Polygon.CullFlag == state)
  357.             return;
  358.          FLUSH_VERTICES(ctx, _NEW_POLYGON);
  359.          ctx->Polygon.CullFlag = state;
  360.          break;
  361.       case GL_DEPTH_TEST:
  362.          if (ctx->Depth.Test == state)
  363.             return;
  364.          FLUSH_VERTICES(ctx, _NEW_DEPTH);
  365.          ctx->Depth.Test = state;
  366.          break;
  367.       case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB:
  368.          if (!_mesa_is_desktop_gl(ctx))
  369.             goto invalid_enum_error;
  370.          ctx->Debug.SyncOutput = state;
  371.          break;
  372.       case GL_DITHER:
  373.          if (ctx->Color.DitherFlag == state)
  374.             return;
  375.          FLUSH_VERTICES(ctx, _NEW_COLOR);
  376.          ctx->Color.DitherFlag = state;
  377.          break;
  378.       case GL_FOG:
  379.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  380.             goto invalid_enum_error;
  381.          if (ctx->Fog.Enabled == state)
  382.             return;
  383.          FLUSH_VERTICES(ctx, _NEW_FOG);
  384.          ctx->Fog.Enabled = state;
  385.          break;
  386.       case GL_LIGHT0:
  387.       case GL_LIGHT1:
  388.       case GL_LIGHT2:
  389.       case GL_LIGHT3:
  390.       case GL_LIGHT4:
  391.       case GL_LIGHT5:
  392.       case GL_LIGHT6:
  393.       case GL_LIGHT7:
  394.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  395.             goto invalid_enum_error;
  396.          if (ctx->Light.Light[cap-GL_LIGHT0].Enabled == state)
  397.             return;
  398.          FLUSH_VERTICES(ctx, _NEW_LIGHT);
  399.          ctx->Light.Light[cap-GL_LIGHT0].Enabled = state;
  400.          if (state) {
  401.             insert_at_tail(&ctx->Light.EnabledList,
  402.                            &ctx->Light.Light[cap-GL_LIGHT0]);
  403.          }
  404.          else {
  405.             remove_from_list(&ctx->Light.Light[cap-GL_LIGHT0]);
  406.          }
  407.          break;
  408.       case GL_LIGHTING:
  409.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  410.             goto invalid_enum_error;
  411.          if (ctx->Light.Enabled == state)
  412.             return;
  413.          FLUSH_VERTICES(ctx, _NEW_LIGHT);
  414.          ctx->Light.Enabled = state;
  415.          break;
  416.       case GL_LINE_SMOOTH:
  417.          if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
  418.             goto invalid_enum_error;
  419.          if (ctx->Line.SmoothFlag == state)
  420.             return;
  421.          FLUSH_VERTICES(ctx, _NEW_LINE);
  422.          ctx->Line.SmoothFlag = state;
  423.          break;
  424.       case GL_LINE_STIPPLE:
  425.          if (ctx->API != API_OPENGL_COMPAT)
  426.             goto invalid_enum_error;
  427.          if (ctx->Line.StippleFlag == state)
  428.             return;
  429.          FLUSH_VERTICES(ctx, _NEW_LINE);
  430.          ctx->Line.StippleFlag = state;
  431.          break;
  432.       case GL_INDEX_LOGIC_OP:
  433.          if (ctx->API != API_OPENGL_COMPAT)
  434.             goto invalid_enum_error;
  435.          if (ctx->Color.IndexLogicOpEnabled == state)
  436.             return;
  437.          FLUSH_VERTICES(ctx, _NEW_COLOR);
  438.          ctx->Color.IndexLogicOpEnabled = state;
  439.          break;
  440.       case GL_COLOR_LOGIC_OP:
  441.          if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
  442.             goto invalid_enum_error;
  443.          if (ctx->Color.ColorLogicOpEnabled == state)
  444.             return;
  445.          FLUSH_VERTICES(ctx, _NEW_COLOR);
  446.          ctx->Color.ColorLogicOpEnabled = state;
  447.          break;
  448.       case GL_MAP1_COLOR_4:
  449.          if (ctx->API != API_OPENGL_COMPAT)
  450.             goto invalid_enum_error;
  451.          if (ctx->Eval.Map1Color4 == state)
  452.             return;
  453.          FLUSH_VERTICES(ctx, _NEW_EVAL);
  454.          ctx->Eval.Map1Color4 = state;
  455.          break;
  456.       case GL_MAP1_INDEX:
  457.          if (ctx->API != API_OPENGL_COMPAT)
  458.             goto invalid_enum_error;
  459.          if (ctx->Eval.Map1Index == state)
  460.             return;
  461.          FLUSH_VERTICES(ctx, _NEW_EVAL);
  462.          ctx->Eval.Map1Index = state;
  463.          break;
  464.       case GL_MAP1_NORMAL:
  465.          if (ctx->API != API_OPENGL_COMPAT)
  466.             goto invalid_enum_error;
  467.          if (ctx->Eval.Map1Normal == state)
  468.             return;
  469.          FLUSH_VERTICES(ctx, _NEW_EVAL);
  470.          ctx->Eval.Map1Normal = state;
  471.          break;
  472.       case GL_MAP1_TEXTURE_COORD_1:
  473.          if (ctx->API != API_OPENGL_COMPAT)
  474.             goto invalid_enum_error;
  475.          if (ctx->Eval.Map1TextureCoord1 == state)
  476.             return;
  477.          FLUSH_VERTICES(ctx, _NEW_EVAL);
  478.          ctx->Eval.Map1TextureCoord1 = state;
  479.          break;
  480.       case GL_MAP1_TEXTURE_COORD_2:
  481.          if (ctx->API != API_OPENGL_COMPAT)
  482.             goto invalid_enum_error;
  483.          if (ctx->Eval.Map1TextureCoord2 == state)
  484.             return;
  485.          FLUSH_VERTICES(ctx, _NEW_EVAL);
  486.          ctx->Eval.Map1TextureCoord2 = state;
  487.          break;
  488.       case GL_MAP1_TEXTURE_COORD_3:
  489.          if (ctx->API != API_OPENGL_COMPAT)
  490.             goto invalid_enum_error;
  491.          if (ctx->Eval.Map1TextureCoord3 == state)
  492.             return;
  493.          FLUSH_VERTICES(ctx, _NEW_EVAL);
  494.          ctx->Eval.Map1TextureCoord3 = state;
  495.          break;
  496.       case GL_MAP1_TEXTURE_COORD_4:
  497.          if (ctx->API != API_OPENGL_COMPAT)
  498.             goto invalid_enum_error;
  499.          if (ctx->Eval.Map1TextureCoord4 == state)
  500.             return;
  501.          FLUSH_VERTICES(ctx, _NEW_EVAL);
  502.          ctx->Eval.Map1TextureCoord4 = state;
  503.          break;
  504.       case GL_MAP1_VERTEX_3:
  505.          if (ctx->API != API_OPENGL_COMPAT)
  506.             goto invalid_enum_error;
  507.          if (ctx->Eval.Map1Vertex3 == state)
  508.             return;
  509.          FLUSH_VERTICES(ctx, _NEW_EVAL);
  510.          ctx->Eval.Map1Vertex3 = state;
  511.          break;
  512.       case GL_MAP1_VERTEX_4:
  513.          if (ctx->API != API_OPENGL_COMPAT)
  514.             goto invalid_enum_error;
  515.          if (ctx->Eval.Map1Vertex4 == state)
  516.             return;
  517.          FLUSH_VERTICES(ctx, _NEW_EVAL);
  518.          ctx->Eval.Map1Vertex4 = state;
  519.          break;
  520.       case GL_MAP2_COLOR_4:
  521.          if (ctx->API != API_OPENGL_COMPAT)
  522.             goto invalid_enum_error;
  523.          if (ctx->Eval.Map2Color4 == state)
  524.             return;
  525.          FLUSH_VERTICES(ctx, _NEW_EVAL);
  526.          ctx->Eval.Map2Color4 = state;
  527.          break;
  528.       case GL_MAP2_INDEX:
  529.          if (ctx->API != API_OPENGL_COMPAT)
  530.             goto invalid_enum_error;
  531.          if (ctx->Eval.Map2Index == state)
  532.             return;
  533.          FLUSH_VERTICES(ctx, _NEW_EVAL);
  534.          ctx->Eval.Map2Index = state;
  535.          break;
  536.       case GL_MAP2_NORMAL:
  537.          if (ctx->API != API_OPENGL_COMPAT)
  538.             goto invalid_enum_error;
  539.          if (ctx->Eval.Map2Normal == state)
  540.             return;
  541.          FLUSH_VERTICES(ctx, _NEW_EVAL);
  542.          ctx->Eval.Map2Normal = state;
  543.          break;
  544.       case GL_MAP2_TEXTURE_COORD_1:
  545.          if (ctx->API != API_OPENGL_COMPAT)
  546.             goto invalid_enum_error;
  547.          if (ctx->Eval.Map2TextureCoord1 == state)
  548.             return;
  549.          FLUSH_VERTICES(ctx, _NEW_EVAL);
  550.          ctx->Eval.Map2TextureCoord1 = state;
  551.          break;
  552.       case GL_MAP2_TEXTURE_COORD_2:
  553.          if (ctx->API != API_OPENGL_COMPAT)
  554.             goto invalid_enum_error;
  555.          if (ctx->Eval.Map2TextureCoord2 == state)
  556.             return;
  557.          FLUSH_VERTICES(ctx, _NEW_EVAL);
  558.          ctx->Eval.Map2TextureCoord2 = state;
  559.          break;
  560.       case GL_MAP2_TEXTURE_COORD_3:
  561.          if (ctx->API != API_OPENGL_COMPAT)
  562.             goto invalid_enum_error;
  563.          if (ctx->Eval.Map2TextureCoord3 == state)
  564.             return;
  565.          FLUSH_VERTICES(ctx, _NEW_EVAL);
  566.          ctx->Eval.Map2TextureCoord3 = state;
  567.          break;
  568.       case GL_MAP2_TEXTURE_COORD_4:
  569.          if (ctx->API != API_OPENGL_COMPAT)
  570.             goto invalid_enum_error;
  571.          if (ctx->Eval.Map2TextureCoord4 == state)
  572.             return;
  573.          FLUSH_VERTICES(ctx, _NEW_EVAL);
  574.          ctx->Eval.Map2TextureCoord4 = state;
  575.          break;
  576.       case GL_MAP2_VERTEX_3:
  577.          if (ctx->API != API_OPENGL_COMPAT)
  578.             goto invalid_enum_error;
  579.          if (ctx->Eval.Map2Vertex3 == state)
  580.             return;
  581.          FLUSH_VERTICES(ctx, _NEW_EVAL);
  582.          ctx->Eval.Map2Vertex3 = state;
  583.          break;
  584.       case GL_MAP2_VERTEX_4:
  585.          if (ctx->API != API_OPENGL_COMPAT)
  586.             goto invalid_enum_error;
  587.          if (ctx->Eval.Map2Vertex4 == state)
  588.             return;
  589.          FLUSH_VERTICES(ctx, _NEW_EVAL);
  590.          ctx->Eval.Map2Vertex4 = state;
  591.          break;
  592.       case GL_NORMALIZE:
  593.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  594.             goto invalid_enum_error;
  595.          if (ctx->Transform.Normalize == state)
  596.             return;
  597.          FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
  598.          ctx->Transform.Normalize = state;
  599.          break;
  600.       case GL_POINT_SMOOTH:
  601.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  602.             goto invalid_enum_error;
  603.          if (ctx->Point.SmoothFlag == state)
  604.             return;
  605.          FLUSH_VERTICES(ctx, _NEW_POINT);
  606.          ctx->Point.SmoothFlag = state;
  607.          break;
  608.       case GL_POLYGON_SMOOTH:
  609.          if (!_mesa_is_desktop_gl(ctx))
  610.             goto invalid_enum_error;
  611.          if (ctx->Polygon.SmoothFlag == state)
  612.             return;
  613.          FLUSH_VERTICES(ctx, _NEW_POLYGON);
  614.          ctx->Polygon.SmoothFlag = state;
  615.          break;
  616.       case GL_POLYGON_STIPPLE:
  617.          if (ctx->API != API_OPENGL_COMPAT)
  618.             goto invalid_enum_error;
  619.          if (ctx->Polygon.StippleFlag == state)
  620.             return;
  621.          FLUSH_VERTICES(ctx, _NEW_POLYGON);
  622.          ctx->Polygon.StippleFlag = state;
  623.          break;
  624.       case GL_POLYGON_OFFSET_POINT:
  625.          if (!_mesa_is_desktop_gl(ctx))
  626.             goto invalid_enum_error;
  627.          if (ctx->Polygon.OffsetPoint == state)
  628.             return;
  629.          FLUSH_VERTICES(ctx, _NEW_POLYGON);
  630.          ctx->Polygon.OffsetPoint = state;
  631.          break;
  632.       case GL_POLYGON_OFFSET_LINE:
  633.          if (!_mesa_is_desktop_gl(ctx))
  634.             goto invalid_enum_error;
  635.          if (ctx->Polygon.OffsetLine == state)
  636.             return;
  637.          FLUSH_VERTICES(ctx, _NEW_POLYGON);
  638.          ctx->Polygon.OffsetLine = state;
  639.          break;
  640.       case GL_POLYGON_OFFSET_FILL:
  641.          if (ctx->Polygon.OffsetFill == state)
  642.             return;
  643.          FLUSH_VERTICES(ctx, _NEW_POLYGON);
  644.          ctx->Polygon.OffsetFill = state;
  645.          break;
  646.       case GL_RESCALE_NORMAL_EXT:
  647.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  648.             goto invalid_enum_error;
  649.          if (ctx->Transform.RescaleNormals == state)
  650.             return;
  651.          FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
  652.          ctx->Transform.RescaleNormals = state;
  653.          break;
  654.       case GL_SCISSOR_TEST:
  655.          if (ctx->Scissor.Enabled == state)
  656.             return;
  657.          FLUSH_VERTICES(ctx, _NEW_SCISSOR);
  658.          ctx->Scissor.Enabled = state;
  659.          break;
  660.       case GL_STENCIL_TEST:
  661.          if (ctx->Stencil.Enabled == state)
  662.             return;
  663.          FLUSH_VERTICES(ctx, _NEW_STENCIL);
  664.          ctx->Stencil.Enabled = state;
  665.          break;
  666.       case GL_TEXTURE_1D:
  667.          if (ctx->API != API_OPENGL_COMPAT)
  668.             goto invalid_enum_error;
  669.          if (!enable_texture(ctx, state, TEXTURE_1D_BIT)) {
  670.             return;
  671.          }
  672.          break;
  673.       case GL_TEXTURE_2D:
  674.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  675.             goto invalid_enum_error;
  676.          if (!enable_texture(ctx, state, TEXTURE_2D_BIT)) {
  677.             return;
  678.          }
  679.          break;
  680.       case GL_TEXTURE_3D:
  681.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  682.             goto invalid_enum_error;
  683.          if (!enable_texture(ctx, state, TEXTURE_3D_BIT)) {
  684.             return;
  685.          }
  686.          break;
  687.       case GL_TEXTURE_GEN_S:
  688.       case GL_TEXTURE_GEN_T:
  689.       case GL_TEXTURE_GEN_R:
  690.       case GL_TEXTURE_GEN_Q:
  691.          {
  692.             struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
  693.  
  694.             if (ctx->API != API_OPENGL_COMPAT)
  695.                goto invalid_enum_error;
  696.  
  697.             if (texUnit) {
  698.                GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
  699.                GLbitfield newenabled = texUnit->TexGenEnabled & ~coordBit;
  700.                if (state)
  701.                   newenabled |= coordBit;
  702.                if (texUnit->TexGenEnabled == newenabled)
  703.                   return;
  704.                FLUSH_VERTICES(ctx, _NEW_TEXTURE);
  705.                texUnit->TexGenEnabled = newenabled;
  706.             }
  707.          }
  708.          break;
  709.  
  710.       case GL_TEXTURE_GEN_STR_OES:
  711.          /* disable S, T, and R at the same time */
  712.          {
  713.             struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
  714.  
  715.             if (ctx->API != API_OPENGLES)
  716.                goto invalid_enum_error;
  717.  
  718.             if (texUnit) {
  719.                GLuint newenabled =
  720.                   texUnit->TexGenEnabled & ~STR_BITS;
  721.                if (state)
  722.                   newenabled |= STR_BITS;
  723.                if (texUnit->TexGenEnabled == newenabled)
  724.                   return;
  725.                FLUSH_VERTICES(ctx, _NEW_TEXTURE);
  726.                texUnit->TexGenEnabled = newenabled;
  727.             }
  728.          }
  729.          break;
  730.  
  731.       /* client-side state */
  732.       case GL_VERTEX_ARRAY:
  733.       case GL_NORMAL_ARRAY:
  734.       case GL_COLOR_ARRAY:
  735.       case GL_INDEX_ARRAY:
  736.       case GL_TEXTURE_COORD_ARRAY:
  737.       case GL_EDGE_FLAG_ARRAY:
  738.       case GL_FOG_COORDINATE_ARRAY_EXT:
  739.       case GL_SECONDARY_COLOR_ARRAY_EXT:
  740.       case GL_POINT_SIZE_ARRAY_OES:
  741.          client_state( ctx, cap, state );
  742.          return;
  743.  
  744.       /* GL_ARB_texture_cube_map */
  745.       case GL_TEXTURE_CUBE_MAP_ARB:
  746.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  747.             goto invalid_enum_error;
  748.          CHECK_EXTENSION(ARB_texture_cube_map, cap);
  749.          if (!enable_texture(ctx, state, TEXTURE_CUBE_BIT)) {
  750.             return;
  751.          }
  752.          break;
  753.  
  754.       /* GL_EXT_secondary_color */
  755.       case GL_COLOR_SUM_EXT:
  756.          if (ctx->API != API_OPENGL_COMPAT)
  757.             goto invalid_enum_error;
  758.          CHECK_EXTENSION(ARB_vertex_program, cap);
  759.          if (ctx->Fog.ColorSumEnabled == state)
  760.             return;
  761.          FLUSH_VERTICES(ctx, _NEW_FOG);
  762.          ctx->Fog.ColorSumEnabled = state;
  763.          break;
  764.  
  765.       /* GL_ARB_multisample */
  766.       case GL_MULTISAMPLE_ARB:
  767.          if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
  768.             goto invalid_enum_error;
  769.          _mesa_set_multisample(ctx, state);
  770.          return;
  771.       case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
  772.          if (ctx->Multisample.SampleAlphaToCoverage == state)
  773.             return;
  774.          FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
  775.          ctx->Multisample.SampleAlphaToCoverage = state;
  776.          break;
  777.       case GL_SAMPLE_ALPHA_TO_ONE_ARB:
  778.          if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
  779.             goto invalid_enum_error;
  780.          if (ctx->Multisample.SampleAlphaToOne == state)
  781.             return;
  782.          FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
  783.          ctx->Multisample.SampleAlphaToOne = state;
  784.          break;
  785.       case GL_SAMPLE_COVERAGE_ARB:
  786.          if (ctx->Multisample.SampleCoverage == state)
  787.             return;
  788.          FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
  789.          ctx->Multisample.SampleCoverage = state;
  790.          break;
  791.       case GL_SAMPLE_COVERAGE_INVERT_ARB:
  792.          if (!_mesa_is_desktop_gl(ctx))
  793.             goto invalid_enum_error;
  794.          if (ctx->Multisample.SampleCoverageInvert == state)
  795.             return;
  796.          FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
  797.          ctx->Multisample.SampleCoverageInvert = state;
  798.          break;
  799.  
  800.       /* GL_IBM_rasterpos_clip */
  801.       case GL_RASTER_POSITION_UNCLIPPED_IBM:
  802.          if (ctx->API != API_OPENGL_COMPAT)
  803.             goto invalid_enum_error;
  804.          if (ctx->Transform.RasterPositionUnclipped == state)
  805.             return;
  806.          FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
  807.          ctx->Transform.RasterPositionUnclipped = state;
  808.          break;
  809.  
  810.       /* GL_NV_point_sprite */
  811.       case GL_POINT_SPRITE_NV:
  812.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  813.             goto invalid_enum_error;
  814.          CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite, cap);
  815.          if (ctx->Point.PointSprite == state)
  816.             return;
  817.          FLUSH_VERTICES(ctx, _NEW_POINT);
  818.          ctx->Point.PointSprite = state;
  819.          break;
  820.  
  821.       case GL_VERTEX_PROGRAM_ARB:
  822.          if (ctx->API != API_OPENGL_COMPAT)
  823.             goto invalid_enum_error;
  824.          CHECK_EXTENSION(ARB_vertex_program, cap);
  825.          if (ctx->VertexProgram.Enabled == state)
  826.             return;
  827.          FLUSH_VERTICES(ctx, _NEW_PROGRAM);
  828.          ctx->VertexProgram.Enabled = state;
  829.          break;
  830.       case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
  831.          /* This was added with ARB_vertex_program, but it is also used with
  832.           * GLSL vertex shaders on desktop.
  833.           */
  834.          if (!_mesa_is_desktop_gl(ctx))
  835.             goto invalid_enum_error;
  836.          CHECK_EXTENSION(ARB_vertex_program, cap);
  837.          if (ctx->VertexProgram.PointSizeEnabled == state)
  838.             return;
  839.          FLUSH_VERTICES(ctx, _NEW_PROGRAM);
  840.          ctx->VertexProgram.PointSizeEnabled = state;
  841.          break;
  842.       case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
  843.          if (ctx->API != API_OPENGL_COMPAT)
  844.             goto invalid_enum_error;
  845.          CHECK_EXTENSION(ARB_vertex_program, cap);
  846.          if (ctx->VertexProgram.TwoSideEnabled == state)
  847.             return;
  848.          FLUSH_VERTICES(ctx, _NEW_PROGRAM);
  849.          ctx->VertexProgram.TwoSideEnabled = state;
  850.          break;
  851.  
  852.       /* GL_NV_texture_rectangle */
  853.       case GL_TEXTURE_RECTANGLE_NV:
  854.          if (ctx->API != API_OPENGL_COMPAT)
  855.             goto invalid_enum_error;
  856.          CHECK_EXTENSION(NV_texture_rectangle, cap);
  857.          if (!enable_texture(ctx, state, TEXTURE_RECT_BIT)) {
  858.             return;
  859.          }
  860.          break;
  861.  
  862.       /* GL_EXT_stencil_two_side */
  863.       case GL_STENCIL_TEST_TWO_SIDE_EXT:
  864.          if (ctx->API != API_OPENGL_COMPAT)
  865.             goto invalid_enum_error;
  866.          CHECK_EXTENSION(EXT_stencil_two_side, cap);
  867.          if (ctx->Stencil.TestTwoSide == state)
  868.             return;
  869.          FLUSH_VERTICES(ctx, _NEW_STENCIL);
  870.          ctx->Stencil.TestTwoSide = state;
  871.          if (state) {
  872.             ctx->Stencil._BackFace = 2;
  873.          } else {
  874.             ctx->Stencil._BackFace = 1;
  875.          }
  876.          break;
  877.  
  878.       case GL_FRAGMENT_PROGRAM_ARB:
  879.          if (ctx->API != API_OPENGL_COMPAT)
  880.             goto invalid_enum_error;
  881.          CHECK_EXTENSION(ARB_fragment_program, cap);
  882.          if (ctx->FragmentProgram.Enabled == state)
  883.             return;
  884.          FLUSH_VERTICES(ctx, _NEW_PROGRAM);
  885.          ctx->FragmentProgram.Enabled = state;
  886.          break;
  887.  
  888.       /* GL_EXT_depth_bounds_test */
  889.       case GL_DEPTH_BOUNDS_TEST_EXT:
  890.          if (!_mesa_is_desktop_gl(ctx))
  891.             goto invalid_enum_error;
  892.          CHECK_EXTENSION(EXT_depth_bounds_test, cap);
  893.          if (ctx->Depth.BoundsTest == state)
  894.             return;
  895.          FLUSH_VERTICES(ctx, _NEW_DEPTH);
  896.          ctx->Depth.BoundsTest = state;
  897.          break;
  898.  
  899.       case GL_DEPTH_CLAMP:
  900.          if (!_mesa_is_desktop_gl(ctx))
  901.             goto invalid_enum_error;
  902.          CHECK_EXTENSION(ARB_depth_clamp, cap);
  903.          if (ctx->Transform.DepthClamp == state)
  904.             return;
  905.          FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
  906.          ctx->Transform.DepthClamp = state;
  907.          break;
  908.  
  909.       case GL_FRAGMENT_SHADER_ATI:
  910.          if (ctx->API != API_OPENGL_COMPAT)
  911.             goto invalid_enum_error;
  912.         CHECK_EXTENSION(ATI_fragment_shader, cap);
  913.         if (ctx->ATIFragmentShader.Enabled == state)
  914.           return;
  915.         FLUSH_VERTICES(ctx, _NEW_PROGRAM);
  916.         ctx->ATIFragmentShader.Enabled = state;
  917.         break;
  918.  
  919.       /* GL_MESA_texture_array */
  920.       case GL_TEXTURE_1D_ARRAY_EXT:
  921.          if (ctx->API != API_OPENGL_COMPAT)
  922.             goto invalid_enum_error;
  923.          CHECK_EXTENSION(MESA_texture_array, cap);
  924.          if (!enable_texture(ctx, state, TEXTURE_1D_ARRAY_BIT)) {
  925.             return;
  926.          }
  927.          break;
  928.  
  929.       case GL_TEXTURE_2D_ARRAY_EXT:
  930.          if (ctx->API != API_OPENGL_COMPAT)
  931.             goto invalid_enum_error;
  932.          CHECK_EXTENSION(MESA_texture_array, cap);
  933.          if (!enable_texture(ctx, state, TEXTURE_2D_ARRAY_BIT)) {
  934.             return;
  935.          }
  936.          break;
  937.  
  938.       case GL_TEXTURE_CUBE_MAP_SEAMLESS:
  939.          if (!_mesa_is_desktop_gl(ctx))
  940.             goto invalid_enum_error;
  941.          CHECK_EXTENSION(ARB_seamless_cube_map, cap);
  942.          if (ctx->Texture.CubeMapSeamless != state) {
  943.             FLUSH_VERTICES(ctx, _NEW_TEXTURE);
  944.             ctx->Texture.CubeMapSeamless = state;
  945.          }
  946.          break;
  947.  
  948.       case GL_RASTERIZER_DISCARD:
  949.          if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
  950.             goto invalid_enum_error;
  951.          CHECK_EXTENSION(EXT_transform_feedback, cap);
  952.          if (ctx->RasterDiscard != state) {
  953.             FLUSH_VERTICES(ctx, 0);
  954.             ctx->NewDriverState |= ctx->DriverFlags.NewRasterizerDiscard;
  955.             ctx->RasterDiscard = state;
  956.          }
  957.          break;
  958.  
  959.       /* GL 3.1 primitive restart.  Note: this enum is different from
  960.        * GL_PRIMITIVE_RESTART_NV (which is client state).
  961.        */
  962.       case GL_PRIMITIVE_RESTART:
  963.          if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
  964.             goto invalid_enum_error;
  965.          }
  966.          if (ctx->Array.PrimitiveRestart != state) {
  967.             FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
  968.             ctx->Array.PrimitiveRestart = state;
  969.             update_derived_primitive_restart_state(ctx);
  970.          }
  971.          break;
  972.  
  973.       case GL_PRIMITIVE_RESTART_FIXED_INDEX:
  974.          if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility)
  975.             goto invalid_enum_error;
  976.          if (ctx->Array.PrimitiveRestartFixedIndex != state) {
  977.             FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
  978.             ctx->Array.PrimitiveRestartFixedIndex = state;
  979.             update_derived_primitive_restart_state(ctx);
  980.          }
  981.          break;
  982.  
  983.       /* GL3.0 - GL_framebuffer_sRGB */
  984.       case GL_FRAMEBUFFER_SRGB_EXT:
  985.          if (!_mesa_is_desktop_gl(ctx))
  986.             goto invalid_enum_error;
  987.          CHECK_EXTENSION(EXT_framebuffer_sRGB, cap);
  988.          _mesa_set_framebuffer_srgb(ctx, state);
  989.          return;
  990.  
  991.       /* GL_OES_EGL_image_external */
  992.       case GL_TEXTURE_EXTERNAL_OES:
  993.          if (!_mesa_is_gles(ctx))
  994.             goto invalid_enum_error;
  995.          CHECK_EXTENSION(OES_EGL_image_external, cap);
  996.          if (!enable_texture(ctx, state, TEXTURE_EXTERNAL_BIT)) {
  997.             return;
  998.          }
  999.          break;
  1000.  
  1001.       /* ARB_texture_multisample */
  1002.       case GL_SAMPLE_MASK:
  1003.          if (!_mesa_is_desktop_gl(ctx))
  1004.             goto invalid_enum_error;
  1005.          CHECK_EXTENSION(ARB_texture_multisample, cap);
  1006.          if (ctx->Multisample.SampleMask == state)
  1007.             return;
  1008.          FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
  1009.          ctx->Multisample.SampleMask = state;
  1010.          break;
  1011.  
  1012.       default:
  1013.          goto invalid_enum_error;
  1014.    }
  1015.  
  1016.    if (ctx->Driver.Enable) {
  1017.       ctx->Driver.Enable( ctx, cap, state );
  1018.    }
  1019.  
  1020.    return;
  1021.  
  1022. invalid_enum_error:
  1023.    _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(%s)",
  1024.                state ? "Enable" : "Disable", _mesa_lookup_enum_by_nr(cap));
  1025. }
  1026.  
  1027.  
  1028. /**
  1029.  * Enable GL capability.  Called by glEnable()
  1030.  * \param cap  state to enable.
  1031.  */
  1032. void GLAPIENTRY
  1033. _mesa_Enable( GLenum cap )
  1034. {
  1035.    GET_CURRENT_CONTEXT(ctx);
  1036.  
  1037.    _mesa_set_enable( ctx, cap, GL_TRUE );
  1038. }
  1039.  
  1040.  
  1041. /**
  1042.  * Disable GL capability.  Called by glDisable()
  1043.  * \param cap  state to disable.
  1044.  */
  1045. void GLAPIENTRY
  1046. _mesa_Disable( GLenum cap )
  1047. {
  1048.    GET_CURRENT_CONTEXT(ctx);
  1049.  
  1050.    _mesa_set_enable( ctx, cap, GL_FALSE );
  1051. }
  1052.  
  1053.  
  1054.  
  1055. /**
  1056.  * Enable/disable an indexed state var.
  1057.  */
  1058. void
  1059. _mesa_set_enablei(struct gl_context *ctx, GLenum cap,
  1060.                   GLuint index, GLboolean state)
  1061. {
  1062.    ASSERT(state == 0 || state == 1);
  1063.    switch (cap) {
  1064.    case GL_BLEND:
  1065.       if (!ctx->Extensions.EXT_draw_buffers2) {
  1066.          goto invalid_enum_error;
  1067.       }
  1068.       if (index >= ctx->Const.MaxDrawBuffers) {
  1069.          _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
  1070.                      state ? "glEnableIndexed" : "glDisableIndexed", index);
  1071.          return;
  1072.       }
  1073.       if (((ctx->Color.BlendEnabled >> index) & 1) != state) {
  1074.          FLUSH_VERTICES(ctx, _NEW_COLOR);
  1075.          if (state)
  1076.             ctx->Color.BlendEnabled |= (1 << index);
  1077.          else
  1078.             ctx->Color.BlendEnabled &= ~(1 << index);
  1079.       }
  1080.       break;
  1081.    default:
  1082.       goto invalid_enum_error;
  1083.    }
  1084.    return;
  1085.  
  1086. invalid_enum_error:
  1087.     _mesa_error(ctx, GL_INVALID_ENUM, "%s(cap=%s)",
  1088.                 state ? "glEnablei" : "glDisablei",
  1089.                 _mesa_lookup_enum_by_nr(cap));
  1090. }
  1091.  
  1092.  
  1093. void GLAPIENTRY
  1094. _mesa_Disablei( GLenum cap, GLuint index )
  1095. {
  1096.    GET_CURRENT_CONTEXT(ctx);
  1097.    _mesa_set_enablei(ctx, cap, index, GL_FALSE);
  1098. }
  1099.  
  1100.  
  1101. void GLAPIENTRY
  1102. _mesa_Enablei( GLenum cap, GLuint index )
  1103. {
  1104.    GET_CURRENT_CONTEXT(ctx);
  1105.    _mesa_set_enablei(ctx, cap, index, GL_TRUE);
  1106. }
  1107.  
  1108.  
  1109. GLboolean GLAPIENTRY
  1110. _mesa_IsEnabledi( GLenum cap, GLuint index )
  1111. {
  1112.    GET_CURRENT_CONTEXT(ctx);
  1113.    ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
  1114.    switch (cap) {
  1115.    case GL_BLEND:
  1116.       if (index >= ctx->Const.MaxDrawBuffers) {
  1117.          _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
  1118.                      index);
  1119.          return GL_FALSE;
  1120.       }
  1121.       return (ctx->Color.BlendEnabled >> index) & 1;
  1122.    default:
  1123.       _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabledIndexed(cap=%s)",
  1124.                   _mesa_lookup_enum_by_nr(cap));
  1125.       return GL_FALSE;
  1126.    }
  1127. }
  1128.  
  1129.  
  1130.  
  1131.  
  1132. #undef CHECK_EXTENSION
  1133. #define CHECK_EXTENSION(EXTNAME)                        \
  1134.    if (!ctx->Extensions.EXTNAME) {                      \
  1135.       goto invalid_enum_error;                          \
  1136.    }
  1137.  
  1138. #undef CHECK_EXTENSION2
  1139. #define CHECK_EXTENSION2(EXT1, EXT2)                            \
  1140.    if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) {        \
  1141.       goto invalid_enum_error;                                  \
  1142.    }
  1143.  
  1144.  
  1145. /**
  1146.  * Helper function to determine whether a texture target is enabled.
  1147.  */
  1148. static GLboolean
  1149. is_texture_enabled(struct gl_context *ctx, GLbitfield bit)
  1150. {
  1151.    const struct gl_texture_unit *const texUnit =
  1152.        &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
  1153.    return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE;
  1154. }
  1155.  
  1156.  
  1157. /**
  1158.  * Return simple enable/disable state.
  1159.  *
  1160.  * \param cap  state variable to query.
  1161.  *
  1162.  * Returns the state of the specified capability from the current GL context.
  1163.  * For the capabilities associated with extensions verifies that those
  1164.  * extensions are effectively present before reporting.
  1165.  */
  1166. GLboolean GLAPIENTRY
  1167. _mesa_IsEnabled( GLenum cap )
  1168. {
  1169.    GET_CURRENT_CONTEXT(ctx);
  1170.    ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
  1171.  
  1172.    switch (cap) {
  1173.       case GL_ALPHA_TEST:
  1174.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  1175.             goto invalid_enum_error;
  1176.          return ctx->Color.AlphaEnabled;
  1177.       case GL_AUTO_NORMAL:
  1178.          if (ctx->API != API_OPENGL_COMPAT)
  1179.             goto invalid_enum_error;
  1180.          return ctx->Eval.AutoNormal;
  1181.       case GL_BLEND:
  1182.          return ctx->Color.BlendEnabled & 1;  /* return state for buffer[0] */
  1183.       case GL_CLIP_DISTANCE0:
  1184.       case GL_CLIP_DISTANCE1:
  1185.       case GL_CLIP_DISTANCE2:
  1186.       case GL_CLIP_DISTANCE3:
  1187.       case GL_CLIP_DISTANCE4:
  1188.       case GL_CLIP_DISTANCE5:
  1189.       case GL_CLIP_DISTANCE6:
  1190.       case GL_CLIP_DISTANCE7: {
  1191.          const GLuint p = cap - GL_CLIP_DISTANCE0;
  1192.  
  1193.          if (p >= ctx->Const.MaxClipPlanes)
  1194.             goto invalid_enum_error;
  1195.  
  1196.          return (ctx->Transform.ClipPlanesEnabled >> p) & 1;
  1197.       }
  1198.       case GL_COLOR_MATERIAL:
  1199.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  1200.             goto invalid_enum_error;
  1201.          return ctx->Light.ColorMaterialEnabled;
  1202.       case GL_CULL_FACE:
  1203.          return ctx->Polygon.CullFlag;
  1204.       case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB:
  1205.          if (!_mesa_is_desktop_gl(ctx))
  1206.             goto invalid_enum_error;
  1207.          return ctx->Debug.SyncOutput;
  1208.       case GL_DEPTH_TEST:
  1209.          return ctx->Depth.Test;
  1210.       case GL_DITHER:
  1211.          return ctx->Color.DitherFlag;
  1212.       case GL_FOG:
  1213.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  1214.             goto invalid_enum_error;
  1215.          return ctx->Fog.Enabled;
  1216.       case GL_LIGHTING:
  1217.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  1218.             goto invalid_enum_error;
  1219.          return ctx->Light.Enabled;
  1220.       case GL_LIGHT0:
  1221.       case GL_LIGHT1:
  1222.       case GL_LIGHT2:
  1223.       case GL_LIGHT3:
  1224.       case GL_LIGHT4:
  1225.       case GL_LIGHT5:
  1226.       case GL_LIGHT6:
  1227.       case GL_LIGHT7:
  1228.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  1229.             goto invalid_enum_error;
  1230.          return ctx->Light.Light[cap-GL_LIGHT0].Enabled;
  1231.       case GL_LINE_SMOOTH:
  1232.          if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
  1233.             goto invalid_enum_error;
  1234.          return ctx->Line.SmoothFlag;
  1235.       case GL_LINE_STIPPLE:
  1236.          if (ctx->API != API_OPENGL_COMPAT)
  1237.             goto invalid_enum_error;
  1238.          return ctx->Line.StippleFlag;
  1239.       case GL_INDEX_LOGIC_OP:
  1240.          if (ctx->API != API_OPENGL_COMPAT)
  1241.             goto invalid_enum_error;
  1242.          return ctx->Color.IndexLogicOpEnabled;
  1243.       case GL_COLOR_LOGIC_OP:
  1244.          if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
  1245.             goto invalid_enum_error;
  1246.          return ctx->Color.ColorLogicOpEnabled;
  1247.       case GL_MAP1_COLOR_4:
  1248.          if (ctx->API != API_OPENGL_COMPAT)
  1249.             goto invalid_enum_error;
  1250.          return ctx->Eval.Map1Color4;
  1251.       case GL_MAP1_INDEX:
  1252.          if (ctx->API != API_OPENGL_COMPAT)
  1253.             goto invalid_enum_error;
  1254.          return ctx->Eval.Map1Index;
  1255.       case GL_MAP1_NORMAL:
  1256.          if (ctx->API != API_OPENGL_COMPAT)
  1257.             goto invalid_enum_error;
  1258.          return ctx->Eval.Map1Normal;
  1259.       case GL_MAP1_TEXTURE_COORD_1:
  1260.          if (ctx->API != API_OPENGL_COMPAT)
  1261.             goto invalid_enum_error;
  1262.          return ctx->Eval.Map1TextureCoord1;
  1263.       case GL_MAP1_TEXTURE_COORD_2:
  1264.          if (ctx->API != API_OPENGL_COMPAT)
  1265.             goto invalid_enum_error;
  1266.          return ctx->Eval.Map1TextureCoord2;
  1267.       case GL_MAP1_TEXTURE_COORD_3:
  1268.          if (ctx->API != API_OPENGL_COMPAT)
  1269.             goto invalid_enum_error;
  1270.          return ctx->Eval.Map1TextureCoord3;
  1271.       case GL_MAP1_TEXTURE_COORD_4:
  1272.          if (ctx->API != API_OPENGL_COMPAT)
  1273.             goto invalid_enum_error;
  1274.          return ctx->Eval.Map1TextureCoord4;
  1275.       case GL_MAP1_VERTEX_3:
  1276.          if (ctx->API != API_OPENGL_COMPAT)
  1277.             goto invalid_enum_error;
  1278.          return ctx->Eval.Map1Vertex3;
  1279.       case GL_MAP1_VERTEX_4:
  1280.          if (ctx->API != API_OPENGL_COMPAT)
  1281.             goto invalid_enum_error;
  1282.          return ctx->Eval.Map1Vertex4;
  1283.       case GL_MAP2_COLOR_4:
  1284.          if (ctx->API != API_OPENGL_COMPAT)
  1285.             goto invalid_enum_error;
  1286.          return ctx->Eval.Map2Color4;
  1287.       case GL_MAP2_INDEX:
  1288.          if (ctx->API != API_OPENGL_COMPAT)
  1289.             goto invalid_enum_error;
  1290.          return ctx->Eval.Map2Index;
  1291.       case GL_MAP2_NORMAL:
  1292.          if (ctx->API != API_OPENGL_COMPAT)
  1293.             goto invalid_enum_error;
  1294.          return ctx->Eval.Map2Normal;
  1295.       case GL_MAP2_TEXTURE_COORD_1:
  1296.          if (ctx->API != API_OPENGL_COMPAT)
  1297.             goto invalid_enum_error;
  1298.          return ctx->Eval.Map2TextureCoord1;
  1299.       case GL_MAP2_TEXTURE_COORD_2:
  1300.          if (ctx->API != API_OPENGL_COMPAT)
  1301.             goto invalid_enum_error;
  1302.          return ctx->Eval.Map2TextureCoord2;
  1303.       case GL_MAP2_TEXTURE_COORD_3:
  1304.          if (ctx->API != API_OPENGL_COMPAT)
  1305.             goto invalid_enum_error;
  1306.          return ctx->Eval.Map2TextureCoord3;
  1307.       case GL_MAP2_TEXTURE_COORD_4:
  1308.          if (ctx->API != API_OPENGL_COMPAT)
  1309.             goto invalid_enum_error;
  1310.          return ctx->Eval.Map2TextureCoord4;
  1311.       case GL_MAP2_VERTEX_3:
  1312.          if (ctx->API != API_OPENGL_COMPAT)
  1313.             goto invalid_enum_error;
  1314.          return ctx->Eval.Map2Vertex3;
  1315.       case GL_MAP2_VERTEX_4:
  1316.          if (ctx->API != API_OPENGL_COMPAT)
  1317.             goto invalid_enum_error;
  1318.          return ctx->Eval.Map2Vertex4;
  1319.       case GL_NORMALIZE:
  1320.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  1321.             goto invalid_enum_error;
  1322.          return ctx->Transform.Normalize;
  1323.       case GL_POINT_SMOOTH:
  1324.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  1325.             goto invalid_enum_error;
  1326.          return ctx->Point.SmoothFlag;
  1327.       case GL_POLYGON_SMOOTH:
  1328.          if (!_mesa_is_desktop_gl(ctx))
  1329.             goto invalid_enum_error;
  1330.          return ctx->Polygon.SmoothFlag;
  1331.       case GL_POLYGON_STIPPLE:
  1332.          if (ctx->API != API_OPENGL_COMPAT)
  1333.             goto invalid_enum_error;
  1334.          return ctx->Polygon.StippleFlag;
  1335.       case GL_POLYGON_OFFSET_POINT:
  1336.          if (!_mesa_is_desktop_gl(ctx))
  1337.             goto invalid_enum_error;
  1338.          return ctx->Polygon.OffsetPoint;
  1339.       case GL_POLYGON_OFFSET_LINE:
  1340.          if (!_mesa_is_desktop_gl(ctx))
  1341.             goto invalid_enum_error;
  1342.          return ctx->Polygon.OffsetLine;
  1343.       case GL_POLYGON_OFFSET_FILL:
  1344.          return ctx->Polygon.OffsetFill;
  1345.       case GL_RESCALE_NORMAL_EXT:
  1346.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  1347.             goto invalid_enum_error;
  1348.          return ctx->Transform.RescaleNormals;
  1349.       case GL_SCISSOR_TEST:
  1350.          return ctx->Scissor.Enabled;
  1351.       case GL_STENCIL_TEST:
  1352.          return ctx->Stencil.Enabled;
  1353.       case GL_TEXTURE_1D:
  1354.          if (ctx->API != API_OPENGL_COMPAT)
  1355.             goto invalid_enum_error;
  1356.          return is_texture_enabled(ctx, TEXTURE_1D_BIT);
  1357.       case GL_TEXTURE_2D:
  1358.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  1359.             goto invalid_enum_error;
  1360.          return is_texture_enabled(ctx, TEXTURE_2D_BIT);
  1361.       case GL_TEXTURE_3D:
  1362.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  1363.             goto invalid_enum_error;
  1364.          return is_texture_enabled(ctx, TEXTURE_3D_BIT);
  1365.       case GL_TEXTURE_GEN_S:
  1366.       case GL_TEXTURE_GEN_T:
  1367.       case GL_TEXTURE_GEN_R:
  1368.       case GL_TEXTURE_GEN_Q:
  1369.          {
  1370.             const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
  1371.  
  1372.             if (ctx->API != API_OPENGL_COMPAT)
  1373.                goto invalid_enum_error;
  1374.  
  1375.             if (texUnit) {
  1376.                GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
  1377.                return (texUnit->TexGenEnabled & coordBit) ? GL_TRUE : GL_FALSE;
  1378.             }
  1379.          }
  1380.          return GL_FALSE;
  1381.       case GL_TEXTURE_GEN_STR_OES:
  1382.          {
  1383.             const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
  1384.  
  1385.             if (ctx->API != API_OPENGLES)
  1386.                goto invalid_enum_error;
  1387.  
  1388.             if (texUnit) {
  1389.                return (texUnit->TexGenEnabled & STR_BITS) == STR_BITS
  1390.                   ? GL_TRUE : GL_FALSE;
  1391.             }
  1392.          }
  1393.  
  1394.       /* client-side state */
  1395.       case GL_VERTEX_ARRAY:
  1396.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  1397.             goto invalid_enum_error;
  1398.          return ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POS].Enabled;
  1399.       case GL_NORMAL_ARRAY:
  1400.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  1401.             goto invalid_enum_error;
  1402.          return ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled;
  1403.       case GL_COLOR_ARRAY:
  1404.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  1405.             goto invalid_enum_error;
  1406.          return ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled;
  1407.       case GL_INDEX_ARRAY:
  1408.          if (ctx->API != API_OPENGL_COMPAT)
  1409.             goto invalid_enum_error;
  1410.          return ctx->Array.ArrayObj->
  1411.             VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled;
  1412.       case GL_TEXTURE_COORD_ARRAY:
  1413.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  1414.             goto invalid_enum_error;
  1415.          return ctx->Array.ArrayObj->
  1416.             VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Enabled;
  1417.       case GL_EDGE_FLAG_ARRAY:
  1418.          if (ctx->API != API_OPENGL_COMPAT)
  1419.             goto invalid_enum_error;
  1420.          return ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled;
  1421.       case GL_FOG_COORDINATE_ARRAY_EXT:
  1422.          if (ctx->API != API_OPENGL_COMPAT)
  1423.             goto invalid_enum_error;
  1424.          return ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_FOG].Enabled;
  1425.       case GL_SECONDARY_COLOR_ARRAY_EXT:
  1426.          if (ctx->API != API_OPENGL_COMPAT)
  1427.             goto invalid_enum_error;
  1428.          return ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled;
  1429.       case GL_POINT_SIZE_ARRAY_OES:
  1430.          if (ctx->API != API_OPENGLES)
  1431.             goto invalid_enum_error;
  1432.          return ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled;
  1433.  
  1434.       /* GL_ARB_texture_cube_map */
  1435.       case GL_TEXTURE_CUBE_MAP_ARB:
  1436.          CHECK_EXTENSION(ARB_texture_cube_map);
  1437.          return is_texture_enabled(ctx, TEXTURE_CUBE_BIT);
  1438.  
  1439.       /* GL_EXT_secondary_color */
  1440.       case GL_COLOR_SUM_EXT:
  1441.          if (ctx->API != API_OPENGL_COMPAT)
  1442.             goto invalid_enum_error;
  1443.          CHECK_EXTENSION(ARB_vertex_program);
  1444.          return ctx->Fog.ColorSumEnabled;
  1445.  
  1446.       /* GL_ARB_multisample */
  1447.       case GL_MULTISAMPLE_ARB:
  1448.          if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
  1449.             goto invalid_enum_error;
  1450.          return ctx->Multisample.Enabled;
  1451.       case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
  1452.          return ctx->Multisample.SampleAlphaToCoverage;
  1453.       case GL_SAMPLE_ALPHA_TO_ONE_ARB:
  1454.          if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
  1455.             goto invalid_enum_error;
  1456.          return ctx->Multisample.SampleAlphaToOne;
  1457.       case GL_SAMPLE_COVERAGE_ARB:
  1458.          return ctx->Multisample.SampleCoverage;
  1459.       case GL_SAMPLE_COVERAGE_INVERT_ARB:
  1460.          if (!_mesa_is_desktop_gl(ctx))
  1461.             goto invalid_enum_error;
  1462.          return ctx->Multisample.SampleCoverageInvert;
  1463.  
  1464.       /* GL_IBM_rasterpos_clip */
  1465.       case GL_RASTER_POSITION_UNCLIPPED_IBM:
  1466.          if (ctx->API != API_OPENGL_COMPAT)
  1467.             goto invalid_enum_error;
  1468.          return ctx->Transform.RasterPositionUnclipped;
  1469.  
  1470.       /* GL_NV_point_sprite */
  1471.       case GL_POINT_SPRITE_NV:
  1472.          if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
  1473.             goto invalid_enum_error;
  1474.          CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite)
  1475.          return ctx->Point.PointSprite;
  1476.  
  1477.       case GL_VERTEX_PROGRAM_ARB:
  1478.          if (ctx->API != API_OPENGL_COMPAT)
  1479.             goto invalid_enum_error;
  1480.          CHECK_EXTENSION(ARB_vertex_program);
  1481.          return ctx->VertexProgram.Enabled;
  1482.       case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
  1483.          /* This was added with ARB_vertex_program, but it is also used with
  1484.           * GLSL vertex shaders on desktop.
  1485.           */
  1486.          if (!_mesa_is_desktop_gl(ctx))
  1487.             goto invalid_enum_error;
  1488.          CHECK_EXTENSION(ARB_vertex_program);
  1489.          return ctx->VertexProgram.PointSizeEnabled;
  1490.       case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
  1491.          if (ctx->API != API_OPENGL_COMPAT)
  1492.             goto invalid_enum_error;
  1493.          CHECK_EXTENSION(ARB_vertex_program);
  1494.          return ctx->VertexProgram.TwoSideEnabled;
  1495.  
  1496.       /* GL_NV_texture_rectangle */
  1497.       case GL_TEXTURE_RECTANGLE_NV:
  1498.          if (ctx->API != API_OPENGL_COMPAT)
  1499.             goto invalid_enum_error;
  1500.          CHECK_EXTENSION(NV_texture_rectangle);
  1501.          return is_texture_enabled(ctx, TEXTURE_RECT_BIT);
  1502.  
  1503.       /* GL_EXT_stencil_two_side */
  1504.       case GL_STENCIL_TEST_TWO_SIDE_EXT:
  1505.          if (ctx->API != API_OPENGL_COMPAT)
  1506.             goto invalid_enum_error;
  1507.          CHECK_EXTENSION(EXT_stencil_two_side);
  1508.          return ctx->Stencil.TestTwoSide;
  1509.  
  1510.       case GL_FRAGMENT_PROGRAM_ARB:
  1511.          if (ctx->API != API_OPENGL_COMPAT)
  1512.             goto invalid_enum_error;
  1513.          return ctx->FragmentProgram.Enabled;
  1514.  
  1515.       /* GL_EXT_depth_bounds_test */
  1516.       case GL_DEPTH_BOUNDS_TEST_EXT:
  1517.          if (!_mesa_is_desktop_gl(ctx))
  1518.             goto invalid_enum_error;
  1519.          CHECK_EXTENSION(EXT_depth_bounds_test);
  1520.          return ctx->Depth.BoundsTest;
  1521.  
  1522.       /* GL_ARB_depth_clamp */
  1523.       case GL_DEPTH_CLAMP:
  1524.          if (!_mesa_is_desktop_gl(ctx))
  1525.             goto invalid_enum_error;
  1526.          CHECK_EXTENSION(ARB_depth_clamp);
  1527.          return ctx->Transform.DepthClamp;
  1528.  
  1529.       case GL_FRAGMENT_SHADER_ATI:
  1530.          if (ctx->API != API_OPENGL_COMPAT)
  1531.             goto invalid_enum_error;
  1532.          CHECK_EXTENSION(ATI_fragment_shader);
  1533.          return ctx->ATIFragmentShader.Enabled;
  1534.  
  1535.       case GL_TEXTURE_CUBE_MAP_SEAMLESS:
  1536.          if (!_mesa_is_desktop_gl(ctx))
  1537.             goto invalid_enum_error;
  1538.          CHECK_EXTENSION(ARB_seamless_cube_map);
  1539.          return ctx->Texture.CubeMapSeamless;
  1540.  
  1541.       case GL_RASTERIZER_DISCARD:
  1542.          if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
  1543.             goto invalid_enum_error;
  1544.          CHECK_EXTENSION(EXT_transform_feedback);
  1545.          return ctx->RasterDiscard;
  1546.  
  1547.       /* GL_NV_primitive_restart */
  1548.       case GL_PRIMITIVE_RESTART_NV:
  1549.          if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.NV_primitive_restart) {
  1550.             goto invalid_enum_error;
  1551.          }
  1552.          return ctx->Array.PrimitiveRestart;
  1553.  
  1554.       /* GL 3.1 primitive restart */
  1555.       case GL_PRIMITIVE_RESTART:
  1556.          if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
  1557.             goto invalid_enum_error;
  1558.          }
  1559.          return ctx->Array.PrimitiveRestart;
  1560.  
  1561.       case GL_PRIMITIVE_RESTART_FIXED_INDEX:
  1562.          if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility) {
  1563.             goto invalid_enum_error;
  1564.          }
  1565.          return ctx->Array.PrimitiveRestartFixedIndex;
  1566.  
  1567.       /* GL3.0 - GL_framebuffer_sRGB */
  1568.       case GL_FRAMEBUFFER_SRGB_EXT:
  1569.          if (!_mesa_is_desktop_gl(ctx))
  1570.             goto invalid_enum_error;
  1571.          CHECK_EXTENSION(EXT_framebuffer_sRGB);
  1572.          return ctx->Color.sRGBEnabled;
  1573.  
  1574.       /* GL_OES_EGL_image_external */
  1575.       case GL_TEXTURE_EXTERNAL_OES:
  1576.          if (!_mesa_is_gles(ctx))
  1577.             goto invalid_enum_error;
  1578.          CHECK_EXTENSION(OES_EGL_image_external);
  1579.          return is_texture_enabled(ctx, TEXTURE_EXTERNAL_BIT);
  1580.  
  1581.       /* ARB_texture_multisample */
  1582.       case GL_SAMPLE_MASK:
  1583.          if (!_mesa_is_desktop_gl(ctx))
  1584.             goto invalid_enum_error;
  1585.          CHECK_EXTENSION(ARB_texture_multisample);
  1586.          return ctx->Multisample.SampleMask;
  1587.  
  1588.       default:
  1589.          goto invalid_enum_error;
  1590.    }
  1591.  
  1592.    return GL_FALSE;
  1593.  
  1594. invalid_enum_error:
  1595.    _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(%s)",
  1596.                _mesa_lookup_enum_by_nr(cap));
  1597.    return GL_FALSE;
  1598. }
  1599.