xref: /third_party/mesa3d/src/mesa/main/enable.c (revision bf215546)
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 "arrayobj.h"
33#include "blend.h"
34#include "clip.h"
35#include "context.h"
36#include "debug_output.h"
37#include "draw_validate.h"
38#include "enable.h"
39#include "errors.h"
40#include "light.h"
41#include "mtypes.h"
42#include "enums.h"
43#include "state.h"
44#include "texstate.h"
45#include "varray.h"
46#include "api_exec_decl.h"
47
48#include "state_tracker/st_cb_bitmap.h"
49#include "state_tracker/st_context.h"
50
51void
52_mesa_update_derived_primitive_restart_state(struct gl_context *ctx)
53{
54   if (ctx->Array.PrimitiveRestart ||
55       ctx->Array.PrimitiveRestartFixedIndex) {
56      unsigned restart_index[3] = {
57         _mesa_primitive_restart_index(ctx, 1),
58         _mesa_primitive_restart_index(ctx, 2),
59         _mesa_primitive_restart_index(ctx, 4),
60      };
61
62      ctx->Array._RestartIndex[0] = restart_index[0];
63      ctx->Array._RestartIndex[1] = restart_index[1];
64      ctx->Array._RestartIndex[2] = restart_index[2];
65
66      /* Enable primitive restart only when the restart index can have an
67       * effect. This is required for correctness in AMD GFX8 support.
68       * Other hardware may also benefit from taking a faster, non-restart path
69       * when possible.
70       */
71      ctx->Array._PrimitiveRestart[0] = true && restart_index[0] <= UINT8_MAX;
72      ctx->Array._PrimitiveRestart[1] = true && restart_index[1] <= UINT16_MAX;
73      ctx->Array._PrimitiveRestart[2] = true;
74   } else {
75      ctx->Array._PrimitiveRestart[0] = false;
76      ctx->Array._PrimitiveRestart[1] = false;
77      ctx->Array._PrimitiveRestart[2] = false;
78   }
79}
80
81
82/**
83 * Helper to enable/disable VAO client-side state.
84 */
85static void
86vao_state(struct gl_context *ctx, struct gl_vertex_array_object* vao,
87          gl_vert_attrib attr, GLboolean state)
88{
89   if (state)
90      _mesa_enable_vertex_array_attrib(ctx, vao, attr);
91   else
92      _mesa_disable_vertex_array_attrib(ctx, vao, attr);
93}
94
95
96/**
97 * Helper to enable/disable client-side state.
98 */
99static void
100client_state(struct gl_context *ctx, struct gl_vertex_array_object* vao,
101             GLenum cap, GLboolean state)
102{
103   switch (cap) {
104      case GL_VERTEX_ARRAY:
105         vao_state(ctx, vao, VERT_ATTRIB_POS, state);
106         break;
107      case GL_NORMAL_ARRAY:
108         vao_state(ctx, vao, VERT_ATTRIB_NORMAL, state);
109         break;
110      case GL_COLOR_ARRAY:
111         vao_state(ctx, vao, VERT_ATTRIB_COLOR0, state);
112         break;
113      case GL_INDEX_ARRAY:
114         vao_state(ctx, vao, VERT_ATTRIB_COLOR_INDEX, state);
115         break;
116      case GL_TEXTURE_COORD_ARRAY:
117         vao_state(ctx, vao, VERT_ATTRIB_TEX(ctx->Array.ActiveTexture), state);
118         break;
119      case GL_EDGE_FLAG_ARRAY:
120         vao_state(ctx, vao, VERT_ATTRIB_EDGEFLAG, state);
121         break;
122      case GL_FOG_COORDINATE_ARRAY_EXT:
123         vao_state(ctx, vao, VERT_ATTRIB_FOG, state);
124         break;
125      case GL_SECONDARY_COLOR_ARRAY_EXT:
126         vao_state(ctx, vao, VERT_ATTRIB_COLOR1, state);
127         break;
128
129      case GL_POINT_SIZE_ARRAY_OES:
130         if (ctx->VertexProgram.PointSizeEnabled != state) {
131            FLUSH_VERTICES(ctx, _NEW_PROGRAM, 0);
132            ctx->VertexProgram.PointSizeEnabled = state;
133         }
134         vao_state(ctx, vao, VERT_ATTRIB_POINT_SIZE, state);
135         break;
136
137      /* GL_NV_primitive_restart */
138      case GL_PRIMITIVE_RESTART_NV:
139         if (!_mesa_has_NV_primitive_restart(ctx))
140            goto invalid_enum_error;
141         if (ctx->Array.PrimitiveRestart == state)
142            return;
143
144         ctx->Array.PrimitiveRestart = state;
145         _mesa_update_derived_primitive_restart_state(ctx);
146         return;
147
148      default:
149         goto invalid_enum_error;
150   }
151   return;
152
153invalid_enum_error:
154   _mesa_error(ctx, GL_INVALID_ENUM, "gl%sClientState(%s)",
155               state ? "Enable" : "Disable", _mesa_enum_to_string(cap));
156}
157
158
159/* Helper for GL_EXT_direct_state_access following functions:
160 *   - EnableClientStateIndexedEXT
161 *   - EnableClientStateiEXT
162 *   - DisableClientStateIndexedEXT
163 *   - DisableClientStateiEXT
164 */
165static void
166client_state_i(struct gl_context *ctx, struct gl_vertex_array_object* vao,
167               GLenum cap, GLuint index, GLboolean state)
168{
169   int saved_active;
170
171   if (cap != GL_TEXTURE_COORD_ARRAY) {
172      _mesa_error(ctx, GL_INVALID_ENUM, "gl%sClientStateiEXT(cap=%s)",
173         state ? "Enable" : "Disable",
174         _mesa_enum_to_string(cap));
175      return;
176   }
177
178   if (index >= ctx->Const.MaxTextureCoordUnits) {
179      _mesa_error(ctx, GL_INVALID_VALUE, "gl%sClientStateiEXT(index=%d)",
180         state ? "Enable" : "Disable",
181         index);
182      return;
183   }
184
185   saved_active = ctx->Array.ActiveTexture;
186   _mesa_ClientActiveTexture(GL_TEXTURE0 + index);
187   client_state(ctx, vao, cap, state);
188   _mesa_ClientActiveTexture(GL_TEXTURE0 + saved_active);
189}
190
191
192/**
193 * Enable GL capability.
194 * \param cap  state to enable/disable.
195 *
196 * Get's the current context, assures that we're outside glBegin()/glEnd() and
197 * calls client_state().
198 */
199void GLAPIENTRY
200_mesa_EnableClientState( GLenum cap )
201{
202   GET_CURRENT_CONTEXT(ctx);
203   client_state( ctx, ctx->Array.VAO, cap, GL_TRUE );
204}
205
206
207void GLAPIENTRY
208_mesa_EnableVertexArrayEXT( GLuint vaobj, GLenum cap )
209{
210   GET_CURRENT_CONTEXT(ctx);
211   struct gl_vertex_array_object* vao = _mesa_lookup_vao_err(ctx, vaobj,
212                                                             true,
213                                                             "glEnableVertexArrayEXT");
214   if (!vao)
215      return;
216
217   /* The EXT_direct_state_access spec says:
218    *    "Additionally EnableVertexArrayEXT and DisableVertexArrayEXT accept
219    *    the tokens TEXTURE0 through TEXTUREn where n is less than the
220    *    implementation-dependent limit of MAX_TEXTURE_COORDS.  For these
221    *    GL_TEXTUREi tokens, EnableVertexArrayEXT and DisableVertexArrayEXT
222    *    act identically to EnableVertexArrayEXT(vaobj, TEXTURE_COORD_ARRAY)
223    *    or DisableVertexArrayEXT(vaobj, TEXTURE_COORD_ARRAY) respectively
224    *    as if the active client texture is set to texture coordinate set i
225    *    based on the token TEXTUREi indicated by array."
226    */
227   if (GL_TEXTURE0 <= cap && cap < GL_TEXTURE0 + ctx->Const.MaxTextureCoordUnits) {
228      GLuint saved_active = ctx->Array.ActiveTexture;
229      _mesa_ClientActiveTexture(cap);
230      client_state(ctx, vao, GL_TEXTURE_COORD_ARRAY, GL_TRUE);
231      _mesa_ClientActiveTexture(GL_TEXTURE0 + saved_active);
232   } else {
233      client_state(ctx, vao, cap, GL_TRUE);
234   }
235}
236
237
238void GLAPIENTRY
239_mesa_EnableClientStateiEXT( GLenum cap, GLuint index )
240{
241   GET_CURRENT_CONTEXT(ctx);
242   client_state_i(ctx, ctx->Array.VAO, cap, index, GL_TRUE);
243}
244
245
246/**
247 * Disable GL capability.
248 * \param cap  state to enable/disable.
249 *
250 * Get's the current context, assures that we're outside glBegin()/glEnd() and
251 * calls client_state().
252 */
253void GLAPIENTRY
254_mesa_DisableClientState( GLenum cap )
255{
256   GET_CURRENT_CONTEXT(ctx);
257   client_state( ctx, ctx->Array.VAO, cap, GL_FALSE );
258}
259
260void GLAPIENTRY
261_mesa_DisableVertexArrayEXT( GLuint vaobj, GLenum cap )
262{
263   GET_CURRENT_CONTEXT(ctx);
264   struct gl_vertex_array_object* vao = _mesa_lookup_vao_err(ctx, vaobj,
265                                                             true,
266                                                             "glDisableVertexArrayEXT");
267   if (!vao)
268      return;
269
270   /* The EXT_direct_state_access spec says:
271    *    "Additionally EnableVertexArrayEXT and DisableVertexArrayEXT accept
272    *    the tokens TEXTURE0 through TEXTUREn where n is less than the
273    *    implementation-dependent limit of MAX_TEXTURE_COORDS.  For these
274    *    GL_TEXTUREi tokens, EnableVertexArrayEXT and DisableVertexArrayEXT
275    *    act identically to EnableVertexArrayEXT(vaobj, TEXTURE_COORD_ARRAY)
276    *    or DisableVertexArrayEXT(vaobj, TEXTURE_COORD_ARRAY) respectively
277    *    as if the active client texture is set to texture coordinate set i
278    *    based on the token TEXTUREi indicated by array."
279    */
280   if (GL_TEXTURE0 <= cap && cap < GL_TEXTURE0 + ctx->Const.MaxTextureCoordUnits) {
281      GLuint saved_active = ctx->Array.ActiveTexture;
282      _mesa_ClientActiveTexture(cap);
283      client_state(ctx, vao, GL_TEXTURE_COORD_ARRAY, GL_FALSE);
284      _mesa_ClientActiveTexture(GL_TEXTURE0 + saved_active);
285   } else {
286      client_state(ctx, vao, cap, GL_FALSE);
287   }
288}
289
290void GLAPIENTRY
291_mesa_DisableClientStateiEXT( GLenum cap, GLuint index )
292{
293   GET_CURRENT_CONTEXT(ctx);
294   client_state_i(ctx, ctx->Array.VAO, cap, index, GL_FALSE);
295}
296
297/**
298 * Return pointer to current texture unit for setting/getting coordinate
299 * state.
300 * Note that we'll set GL_INVALID_OPERATION and return NULL if the active
301 * texture unit is higher than the number of supported coordinate units.
302 */
303static struct gl_fixedfunc_texture_unit *
304get_texcoord_unit(struct gl_context *ctx)
305{
306   if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
307      _mesa_error(ctx, GL_INVALID_OPERATION, "glEnable/Disable(texcoord unit)");
308      return NULL;
309   }
310   else {
311      return &ctx->Texture.FixedFuncUnit[ctx->Texture.CurrentUnit];
312   }
313}
314
315
316/**
317 * Helper function to enable or disable a texture target.
318 * \param bit  one of the TEXTURE_x_BIT values
319 * \return GL_TRUE if state is changing or GL_FALSE if no change
320 */
321static GLboolean
322enable_texture(struct gl_context *ctx, GLboolean state, GLbitfield texBit)
323{
324   struct gl_fixedfunc_texture_unit *texUnit =
325      _mesa_get_fixedfunc_tex_unit(ctx, ctx->Texture.CurrentUnit);
326   if (!texUnit)
327      return GL_FALSE;
328
329   const GLbitfield newenabled = state
330      ? (texUnit->Enabled | texBit) : (texUnit->Enabled & ~texBit);
331
332   if (texUnit->Enabled == newenabled)
333       return GL_FALSE;
334
335   FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE, GL_TEXTURE_BIT | GL_ENABLE_BIT);
336   texUnit->Enabled = newenabled;
337   return GL_TRUE;
338}
339
340
341/**
342 * Helper function to enable or disable GL_MULTISAMPLE, skipping the check for
343 * whether the API supports it (GLES doesn't).
344 */
345void
346_mesa_set_multisample(struct gl_context *ctx, GLboolean state)
347{
348   if (ctx->Multisample.Enabled == state)
349      return;
350
351   /* GL compatibility needs Multisample.Enable to determine program state
352    * constants.
353    */
354   if (ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGLES) {
355      FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE, GL_MULTISAMPLE_BIT | GL_ENABLE_BIT);
356   } else {
357      FLUSH_VERTICES(ctx, 0, GL_MULTISAMPLE_BIT | GL_ENABLE_BIT);
358   }
359
360   ctx->NewDriverState |= ctx->DriverFlags.NewMultisampleEnable;
361   ctx->Multisample.Enabled = state;
362}
363
364/**
365 * Helper function to enable or disable GL_FRAMEBUFFER_SRGB, skipping the
366 * check for whether the API supports it (GLES doesn't).
367 */
368void
369_mesa_set_framebuffer_srgb(struct gl_context *ctx, GLboolean state)
370{
371   if (ctx->Color.sRGBEnabled == state)
372      return;
373
374   /* TODO: Switch i965 to the new flag and remove the conditional */
375   FLUSH_VERTICES(ctx, 0,
376                  GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT);
377   ctx->NewDriverState |= ST_NEW_FB_STATE;
378   ctx->Color.sRGBEnabled = state;
379}
380
381/**
382 * Helper function to enable or disable state.
383 *
384 * \param ctx GL context.
385 * \param cap  the state to enable/disable
386 * \param state whether to enable or disable the specified capability.
387 *
388 * Updates the current context and flushes the vertices as needed. For
389 * capabilities associated with extensions it verifies that those extensions
390 * are effectivly present before updating. Notifies the driver via
391 * dd_function_table::Enable.
392 */
393void
394_mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
395{
396   if (MESA_VERBOSE & VERBOSE_API)
397      _mesa_debug(ctx, "%s %s (newstate is %x)\n",
398                  state ? "glEnable" : "glDisable",
399                  _mesa_enum_to_string(cap),
400                  ctx->NewState);
401
402   switch (cap) {
403      case GL_ALPHA_TEST:
404         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
405            goto invalid_enum_error;
406         if (ctx->Color.AlphaEnabled == state)
407            return;
408         /* AlphaEnabled is used by the fixed-func fragment program */
409         FLUSH_VERTICES(ctx, _NEW_COLOR | _NEW_FF_FRAG_PROGRAM,
410                        GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT);
411         ctx->NewDriverState |= ctx->DriverFlags.NewAlphaTest;
412         ctx->Color.AlphaEnabled = state;
413         break;
414      case GL_AUTO_NORMAL:
415         if (ctx->API != API_OPENGL_COMPAT)
416            goto invalid_enum_error;
417         if (ctx->Eval.AutoNormal == state)
418            return;
419         FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT);
420         vbo_exec_update_eval_maps(ctx);
421         ctx->Eval.AutoNormal = state;
422         break;
423      case GL_BLEND:
424         {
425            GLbitfield newEnabled =
426               state * ((1 << ctx->Const.MaxDrawBuffers) - 1);
427            if (newEnabled != ctx->Color.BlendEnabled) {
428               _mesa_flush_vertices_for_blend_adv(ctx, newEnabled,
429                                               ctx->Color._AdvancedBlendMode);
430               ctx->PopAttribState |= GL_ENABLE_BIT;
431               ctx->Color.BlendEnabled = newEnabled;
432               _mesa_update_allow_draw_out_of_order(ctx);
433               _mesa_update_valid_to_render_state(ctx);
434            }
435         }
436         break;
437      case GL_CLIP_DISTANCE0: /* aka GL_CLIP_PLANE0 */
438      case GL_CLIP_DISTANCE1:
439      case GL_CLIP_DISTANCE2:
440      case GL_CLIP_DISTANCE3:
441      case GL_CLIP_DISTANCE4:
442      case GL_CLIP_DISTANCE5:
443      case GL_CLIP_DISTANCE6:
444      case GL_CLIP_DISTANCE7:
445         {
446            const GLuint p = cap - GL_CLIP_DISTANCE0;
447
448            if (p >= ctx->Const.MaxClipPlanes)
449               goto invalid_enum_error;
450
451            if ((ctx->Transform.ClipPlanesEnabled & (1 << p))
452                == ((GLuint) state << p))
453               return;
454
455            /* The compatibility profile needs _NEW_TRANSFORM to transform
456             * clip planes according to the projection matrix.
457             */
458            if (ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGLES) {
459               FLUSH_VERTICES(ctx, _NEW_TRANSFORM,
460                              GL_TRANSFORM_BIT | GL_ENABLE_BIT);
461            } else {
462               FLUSH_VERTICES(ctx, 0, GL_TRANSFORM_BIT | GL_ENABLE_BIT);
463            }
464            ctx->NewDriverState |= ctx->DriverFlags.NewClipPlaneEnable;
465
466            if (state) {
467               ctx->Transform.ClipPlanesEnabled |= (1 << p);
468
469               /* The projection matrix transforms the clip plane. */
470               /* TODO: glEnable might not be the best place to do it. */
471               if (ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGLES) {
472                  _mesa_update_clip_plane(ctx, p);
473                  ctx->NewDriverState |= ST_NEW_CLIP_STATE;
474               }
475            }
476            else {
477               ctx->Transform.ClipPlanesEnabled &= ~(1 << p);
478            }
479         }
480         break;
481      case GL_COLOR_MATERIAL:
482         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
483            goto invalid_enum_error;
484         if (ctx->Light.ColorMaterialEnabled == state)
485            return;
486         FLUSH_VERTICES(ctx, _NEW_LIGHT_CONSTANTS | _NEW_FF_VERT_PROGRAM,
487                        GL_LIGHTING_BIT | GL_ENABLE_BIT);
488         FLUSH_CURRENT(ctx, 0);
489         ctx->Light.ColorMaterialEnabled = state;
490         if (state) {
491            _mesa_update_color_material( ctx,
492                                  ctx->Current.Attrib[VERT_ATTRIB_COLOR0] );
493         }
494         break;
495      case GL_CULL_FACE:
496         if (ctx->Polygon.CullFlag == state)
497            return;
498         FLUSH_VERTICES(ctx, 0,
499                        GL_POLYGON_BIT | GL_ENABLE_BIT);
500         ctx->NewDriverState |= ST_NEW_RASTERIZER;
501         ctx->Polygon.CullFlag = state;
502         break;
503      case GL_DEPTH_TEST:
504         if (ctx->Depth.Test == state)
505            return;
506         FLUSH_VERTICES(ctx, 0,
507                        GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT);
508         ctx->NewDriverState |= ST_NEW_DSA;
509         ctx->Depth.Test = state;
510         _mesa_update_allow_draw_out_of_order(ctx);
511         break;
512      case GL_DEBUG_OUTPUT:
513      case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB:
514         _mesa_set_debug_state_int(ctx, cap, state);
515         _mesa_update_debug_callback(ctx);
516         break;
517      case GL_DITHER:
518         if (ctx->Color.DitherFlag == state)
519            return;
520         FLUSH_VERTICES(ctx, 0,
521                        GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT);
522         ctx->NewDriverState |= ST_NEW_BLEND;
523         ctx->Color.DitherFlag = state;
524         break;
525      case GL_FOG:
526         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
527            goto invalid_enum_error;
528         if (ctx->Fog.Enabled == state)
529            return;
530         FLUSH_VERTICES(ctx, _NEW_FOG | _NEW_FF_FRAG_PROGRAM,
531                        GL_FOG_BIT | GL_ENABLE_BIT);
532         ctx->Fog.Enabled = state;
533         ctx->Fog._PackedEnabledMode = state ? ctx->Fog._PackedMode : FOG_NONE;
534         break;
535      case GL_LIGHT0:
536      case GL_LIGHT1:
537      case GL_LIGHT2:
538      case GL_LIGHT3:
539      case GL_LIGHT4:
540      case GL_LIGHT5:
541      case GL_LIGHT6:
542      case GL_LIGHT7:
543         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
544            goto invalid_enum_error;
545         if (ctx->Light.Light[cap-GL_LIGHT0].Enabled == state)
546            return;
547         FLUSH_VERTICES(ctx, _NEW_LIGHT_CONSTANTS | _NEW_FF_VERT_PROGRAM,
548                        GL_LIGHTING_BIT | GL_ENABLE_BIT);
549         ctx->Light.Light[cap-GL_LIGHT0].Enabled = state;
550         if (state) {
551            ctx->Light._EnabledLights |= 1u << (cap - GL_LIGHT0);
552         }
553         else {
554            ctx->Light._EnabledLights &= ~(1u << (cap - GL_LIGHT0));
555         }
556         break;
557      case GL_LIGHTING:
558         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
559            goto invalid_enum_error;
560         if (ctx->Light.Enabled == state)
561            return;
562         FLUSH_VERTICES(ctx, _NEW_LIGHT_CONSTANTS | _NEW_FF_VERT_PROGRAM |
563                        _NEW_FF_FRAG_PROGRAM | _NEW_LIGHT_STATE,
564                        GL_LIGHTING_BIT | GL_ENABLE_BIT);
565         ctx->Light.Enabled = state;
566         break;
567      case GL_LINE_SMOOTH:
568         if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
569            goto invalid_enum_error;
570         if (ctx->Line.SmoothFlag == state)
571            return;
572         FLUSH_VERTICES(ctx, 0,
573                        GL_LINE_BIT | GL_ENABLE_BIT);
574         ctx->NewDriverState |= ST_NEW_RASTERIZER;
575         ctx->Line.SmoothFlag = state;
576         break;
577      case GL_LINE_STIPPLE:
578         if (ctx->API != API_OPENGL_COMPAT)
579            goto invalid_enum_error;
580         if (ctx->Line.StippleFlag == state)
581            return;
582         FLUSH_VERTICES(ctx, 0,
583                        GL_LINE_BIT | GL_ENABLE_BIT);
584         ctx->NewDriverState |= ST_NEW_RASTERIZER;
585         ctx->Line.StippleFlag = state;
586         break;
587      case GL_INDEX_LOGIC_OP:
588         if (ctx->API != API_OPENGL_COMPAT)
589            goto invalid_enum_error;
590         if (ctx->Color.IndexLogicOpEnabled == state)
591            return;
592         FLUSH_VERTICES(ctx, 0,
593                        GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT);
594         ctx->NewDriverState |= ST_NEW_BLEND;
595         ctx->Color.IndexLogicOpEnabled = state;
596         break;
597      case GL_CONSERVATIVE_RASTERIZATION_INTEL:
598         if (!_mesa_has_INTEL_conservative_rasterization(ctx))
599            goto invalid_enum_error;
600         if (ctx->IntelConservativeRasterization == state)
601            return;
602         FLUSH_VERTICES(ctx, 0, 0);
603         ctx->NewDriverState |= ST_NEW_RASTERIZER;
604         ctx->IntelConservativeRasterization = state;
605         _mesa_update_valid_to_render_state(ctx);
606         break;
607      case GL_CONSERVATIVE_RASTERIZATION_NV:
608         if (!_mesa_has_NV_conservative_raster(ctx))
609            goto invalid_enum_error;
610         if (ctx->ConservativeRasterization == state)
611            return;
612         FLUSH_VERTICES(ctx, 0, GL_ENABLE_BIT);
613         ctx->NewDriverState |= ST_NEW_RASTERIZER;
614         ctx->ConservativeRasterization = state;
615         break;
616      case GL_COLOR_LOGIC_OP:
617         if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
618            goto invalid_enum_error;
619         if (ctx->Color.ColorLogicOpEnabled == state)
620            return;
621         FLUSH_VERTICES(ctx, 0,
622                        GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT);
623         ctx->NewDriverState |= ST_NEW_BLEND;
624         ctx->Color.ColorLogicOpEnabled = state;
625         _mesa_update_allow_draw_out_of_order(ctx);
626         break;
627      case GL_MAP1_COLOR_4:
628         if (ctx->API != API_OPENGL_COMPAT)
629            goto invalid_enum_error;
630         if (ctx->Eval.Map1Color4 == state)
631            return;
632         FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT);
633         vbo_exec_update_eval_maps(ctx);
634         ctx->Eval.Map1Color4 = state;
635         break;
636      case GL_MAP1_INDEX:
637         if (ctx->API != API_OPENGL_COMPAT)
638            goto invalid_enum_error;
639         if (ctx->Eval.Map1Index == state)
640            return;
641         FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT);
642         vbo_exec_update_eval_maps(ctx);
643         ctx->Eval.Map1Index = state;
644         break;
645      case GL_MAP1_NORMAL:
646         if (ctx->API != API_OPENGL_COMPAT)
647            goto invalid_enum_error;
648         if (ctx->Eval.Map1Normal == state)
649            return;
650         FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT);
651         vbo_exec_update_eval_maps(ctx);
652         ctx->Eval.Map1Normal = state;
653         break;
654      case GL_MAP1_TEXTURE_COORD_1:
655         if (ctx->API != API_OPENGL_COMPAT)
656            goto invalid_enum_error;
657         if (ctx->Eval.Map1TextureCoord1 == state)
658            return;
659         FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT);
660         vbo_exec_update_eval_maps(ctx);
661         ctx->Eval.Map1TextureCoord1 = state;
662         break;
663      case GL_MAP1_TEXTURE_COORD_2:
664         if (ctx->API != API_OPENGL_COMPAT)
665            goto invalid_enum_error;
666         if (ctx->Eval.Map1TextureCoord2 == state)
667            return;
668         FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT);
669         vbo_exec_update_eval_maps(ctx);
670         ctx->Eval.Map1TextureCoord2 = state;
671         break;
672      case GL_MAP1_TEXTURE_COORD_3:
673         if (ctx->API != API_OPENGL_COMPAT)
674            goto invalid_enum_error;
675         if (ctx->Eval.Map1TextureCoord3 == state)
676            return;
677         FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT);
678         vbo_exec_update_eval_maps(ctx);
679         ctx->Eval.Map1TextureCoord3 = state;
680         break;
681      case GL_MAP1_TEXTURE_COORD_4:
682         if (ctx->API != API_OPENGL_COMPAT)
683            goto invalid_enum_error;
684         if (ctx->Eval.Map1TextureCoord4 == state)
685            return;
686         FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT);
687         vbo_exec_update_eval_maps(ctx);
688         ctx->Eval.Map1TextureCoord4 = state;
689         break;
690      case GL_MAP1_VERTEX_3:
691         if (ctx->API != API_OPENGL_COMPAT)
692            goto invalid_enum_error;
693         if (ctx->Eval.Map1Vertex3 == state)
694            return;
695         FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT);
696         vbo_exec_update_eval_maps(ctx);
697         ctx->Eval.Map1Vertex3 = state;
698         break;
699      case GL_MAP1_VERTEX_4:
700         if (ctx->API != API_OPENGL_COMPAT)
701            goto invalid_enum_error;
702         if (ctx->Eval.Map1Vertex4 == state)
703            return;
704         FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT);
705         vbo_exec_update_eval_maps(ctx);
706         ctx->Eval.Map1Vertex4 = state;
707         break;
708      case GL_MAP2_COLOR_4:
709         if (ctx->API != API_OPENGL_COMPAT)
710            goto invalid_enum_error;
711         if (ctx->Eval.Map2Color4 == state)
712            return;
713         FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT);
714         vbo_exec_update_eval_maps(ctx);
715         ctx->Eval.Map2Color4 = state;
716         break;
717      case GL_MAP2_INDEX:
718         if (ctx->API != API_OPENGL_COMPAT)
719            goto invalid_enum_error;
720         if (ctx->Eval.Map2Index == state)
721            return;
722         FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT);
723         vbo_exec_update_eval_maps(ctx);
724         ctx->Eval.Map2Index = state;
725         break;
726      case GL_MAP2_NORMAL:
727         if (ctx->API != API_OPENGL_COMPAT)
728            goto invalid_enum_error;
729         if (ctx->Eval.Map2Normal == state)
730            return;
731         FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT);
732         vbo_exec_update_eval_maps(ctx);
733         ctx->Eval.Map2Normal = state;
734         break;
735      case GL_MAP2_TEXTURE_COORD_1:
736         if (ctx->API != API_OPENGL_COMPAT)
737            goto invalid_enum_error;
738         if (ctx->Eval.Map2TextureCoord1 == state)
739            return;
740         FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT);
741         vbo_exec_update_eval_maps(ctx);
742         ctx->Eval.Map2TextureCoord1 = state;
743         break;
744      case GL_MAP2_TEXTURE_COORD_2:
745         if (ctx->API != API_OPENGL_COMPAT)
746            goto invalid_enum_error;
747         if (ctx->Eval.Map2TextureCoord2 == state)
748            return;
749         FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT);
750         vbo_exec_update_eval_maps(ctx);
751         ctx->Eval.Map2TextureCoord2 = state;
752         break;
753      case GL_MAP2_TEXTURE_COORD_3:
754         if (ctx->API != API_OPENGL_COMPAT)
755            goto invalid_enum_error;
756         if (ctx->Eval.Map2TextureCoord3 == state)
757            return;
758         FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT);
759         vbo_exec_update_eval_maps(ctx);
760         ctx->Eval.Map2TextureCoord3 = state;
761         break;
762      case GL_MAP2_TEXTURE_COORD_4:
763         if (ctx->API != API_OPENGL_COMPAT)
764            goto invalid_enum_error;
765         if (ctx->Eval.Map2TextureCoord4 == state)
766            return;
767         FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT);
768         vbo_exec_update_eval_maps(ctx);
769         ctx->Eval.Map2TextureCoord4 = state;
770         break;
771      case GL_MAP2_VERTEX_3:
772         if (ctx->API != API_OPENGL_COMPAT)
773            goto invalid_enum_error;
774         if (ctx->Eval.Map2Vertex3 == state)
775            return;
776         FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT);
777         vbo_exec_update_eval_maps(ctx);
778         ctx->Eval.Map2Vertex3 = state;
779         break;
780      case GL_MAP2_VERTEX_4:
781         if (ctx->API != API_OPENGL_COMPAT)
782            goto invalid_enum_error;
783         if (ctx->Eval.Map2Vertex4 == state)
784            return;
785         FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT | GL_ENABLE_BIT);
786         vbo_exec_update_eval_maps(ctx);
787         ctx->Eval.Map2Vertex4 = state;
788         break;
789      case GL_NORMALIZE:
790         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
791            goto invalid_enum_error;
792         if (ctx->Transform.Normalize == state)
793            return;
794         FLUSH_VERTICES(ctx, _NEW_TRANSFORM | _NEW_FF_VERT_PROGRAM,
795                        GL_TRANSFORM_BIT | GL_ENABLE_BIT);
796         ctx->Transform.Normalize = state;
797         break;
798      case GL_POINT_SMOOTH:
799         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
800            goto invalid_enum_error;
801         if (ctx->Point.SmoothFlag == state)
802            return;
803         FLUSH_VERTICES(ctx, _NEW_POINT, GL_POINT_BIT | GL_ENABLE_BIT);
804         ctx->Point.SmoothFlag = state;
805         break;
806      case GL_POLYGON_SMOOTH:
807         if (!_mesa_is_desktop_gl(ctx))
808            goto invalid_enum_error;
809         if (ctx->Polygon.SmoothFlag == state)
810            return;
811         FLUSH_VERTICES(ctx, 0,
812                        GL_POLYGON_BIT | GL_ENABLE_BIT);
813         ctx->NewDriverState |= ST_NEW_RASTERIZER;
814         ctx->Polygon.SmoothFlag = state;
815         break;
816      case GL_POLYGON_STIPPLE:
817         if (ctx->API != API_OPENGL_COMPAT)
818            goto invalid_enum_error;
819         if (ctx->Polygon.StippleFlag == state)
820            return;
821         FLUSH_VERTICES(ctx, 0,
822                        GL_POLYGON_BIT | GL_ENABLE_BIT);
823         ctx->NewDriverState |= ST_NEW_RASTERIZER;
824         ctx->Polygon.StippleFlag = state;
825         break;
826      case GL_POLYGON_OFFSET_POINT:
827         if (!_mesa_is_desktop_gl(ctx))
828            goto invalid_enum_error;
829         if (ctx->Polygon.OffsetPoint == state)
830            return;
831         FLUSH_VERTICES(ctx, 0,
832                        GL_POLYGON_BIT | GL_ENABLE_BIT);
833         ctx->NewDriverState |= ST_NEW_RASTERIZER;
834         ctx->Polygon.OffsetPoint = state;
835         break;
836      case GL_POLYGON_OFFSET_LINE:
837         if (!_mesa_is_desktop_gl(ctx))
838            goto invalid_enum_error;
839         if (ctx->Polygon.OffsetLine == state)
840            return;
841         FLUSH_VERTICES(ctx, 0,
842                        GL_POLYGON_BIT | GL_ENABLE_BIT);
843         ctx->NewDriverState |= ST_NEW_RASTERIZER;
844         ctx->Polygon.OffsetLine = state;
845         break;
846      case GL_POLYGON_OFFSET_FILL:
847         if (ctx->Polygon.OffsetFill == state)
848            return;
849         FLUSH_VERTICES(ctx, 0,
850                        GL_POLYGON_BIT | GL_ENABLE_BIT);
851         ctx->NewDriverState |= ST_NEW_RASTERIZER;
852         ctx->Polygon.OffsetFill = state;
853         break;
854      case GL_RESCALE_NORMAL_EXT:
855         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
856            goto invalid_enum_error;
857         if (ctx->Transform.RescaleNormals == state)
858            return;
859         FLUSH_VERTICES(ctx, _NEW_TRANSFORM | _NEW_FF_VERT_PROGRAM,
860                        GL_TRANSFORM_BIT | GL_ENABLE_BIT);
861         ctx->Transform.RescaleNormals = state;
862         break;
863      case GL_SCISSOR_TEST:
864         {
865            /* Must expand glEnable to all scissors */
866            GLbitfield newEnabled =
867               state * ((1 << ctx->Const.MaxViewports) - 1);
868            if (newEnabled != ctx->Scissor.EnableFlags) {
869               st_flush_bitmap_cache(st_context(ctx));
870
871               FLUSH_VERTICES(ctx, 0,
872                              GL_SCISSOR_BIT | GL_ENABLE_BIT);
873               ctx->NewDriverState |= ST_NEW_SCISSOR | ST_NEW_RASTERIZER;
874               ctx->Scissor.EnableFlags = newEnabled;
875            }
876         }
877         break;
878      case GL_STENCIL_TEST:
879         if (ctx->Stencil.Enabled == state)
880            return;
881         FLUSH_VERTICES(ctx, 0,
882                        GL_STENCIL_BUFFER_BIT | GL_ENABLE_BIT);
883         ctx->NewDriverState |= ST_NEW_DSA;
884         ctx->Stencil.Enabled = state;
885         _mesa_update_allow_draw_out_of_order(ctx);
886         break;
887      case GL_TEXTURE_1D:
888         if (ctx->API != API_OPENGL_COMPAT)
889            goto invalid_enum_error;
890         if (!enable_texture(ctx, state, TEXTURE_1D_BIT)) {
891            return;
892         }
893         break;
894      case GL_TEXTURE_2D:
895         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
896            goto invalid_enum_error;
897         if (!enable_texture(ctx, state, TEXTURE_2D_BIT)) {
898            return;
899         }
900         break;
901      case GL_TEXTURE_3D:
902         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
903            goto invalid_enum_error;
904         if (!enable_texture(ctx, state, TEXTURE_3D_BIT)) {
905            return;
906         }
907         break;
908      case GL_TEXTURE_GEN_S:
909      case GL_TEXTURE_GEN_T:
910      case GL_TEXTURE_GEN_R:
911      case GL_TEXTURE_GEN_Q:
912         {
913            struct gl_fixedfunc_texture_unit *texUnit = get_texcoord_unit(ctx);
914
915            if (ctx->API != API_OPENGL_COMPAT)
916               goto invalid_enum_error;
917
918            if (texUnit) {
919               GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
920               GLbitfield newenabled = texUnit->TexGenEnabled & ~coordBit;
921               if (state)
922                  newenabled |= coordBit;
923               if (texUnit->TexGenEnabled == newenabled)
924                  return;
925               FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE | _NEW_FF_VERT_PROGRAM |
926                              _NEW_FF_FRAG_PROGRAM,
927                              GL_TEXTURE_BIT | GL_ENABLE_BIT);
928               texUnit->TexGenEnabled = newenabled;
929            }
930         }
931         break;
932
933      case GL_TEXTURE_GEN_STR_OES:
934         /* disable S, T, and R at the same time */
935         {
936            struct gl_fixedfunc_texture_unit *texUnit = get_texcoord_unit(ctx);
937
938            if (ctx->API != API_OPENGLES)
939               goto invalid_enum_error;
940
941            if (texUnit) {
942               GLuint newenabled =
943                  texUnit->TexGenEnabled & ~STR_BITS;
944               if (state)
945                  newenabled |= STR_BITS;
946               if (texUnit->TexGenEnabled == newenabled)
947                  return;
948               FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE | _NEW_FF_VERT_PROGRAM |
949                              _NEW_FF_FRAG_PROGRAM, 0);
950               texUnit->TexGenEnabled = newenabled;
951            }
952         }
953         break;
954
955      /* client-side state */
956      case GL_VERTEX_ARRAY:
957      case GL_NORMAL_ARRAY:
958      case GL_COLOR_ARRAY:
959      case GL_TEXTURE_COORD_ARRAY:
960         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
961            goto invalid_enum_error;
962         client_state( ctx, ctx->Array.VAO, cap, state );
963         return;
964      case GL_INDEX_ARRAY:
965      case GL_EDGE_FLAG_ARRAY:
966      case GL_FOG_COORDINATE_ARRAY_EXT:
967      case GL_SECONDARY_COLOR_ARRAY_EXT:
968         if (ctx->API != API_OPENGL_COMPAT)
969            goto invalid_enum_error;
970         client_state( ctx, ctx->Array.VAO, cap, state );
971         return;
972      case GL_POINT_SIZE_ARRAY_OES:
973         if (ctx->API != API_OPENGLES)
974            goto invalid_enum_error;
975         client_state( ctx, ctx->Array.VAO, cap, state );
976         return;
977
978      /* GL_ARB_texture_cube_map */
979      case GL_TEXTURE_CUBE_MAP:
980         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
981            goto invalid_enum_error;
982         if (!enable_texture(ctx, state, TEXTURE_CUBE_BIT)) {
983            return;
984         }
985         break;
986
987      /* GL_EXT_secondary_color */
988      case GL_COLOR_SUM_EXT:
989         if (ctx->API != API_OPENGL_COMPAT)
990            goto invalid_enum_error;
991         if (ctx->Fog.ColorSumEnabled == state)
992            return;
993         FLUSH_VERTICES(ctx, _NEW_FOG | _NEW_FF_FRAG_PROGRAM,
994                        GL_FOG_BIT | GL_ENABLE_BIT);
995         ctx->Fog.ColorSumEnabled = state;
996         break;
997
998      /* GL_ARB_multisample */
999      case GL_MULTISAMPLE_ARB:
1000         if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1001            goto invalid_enum_error;
1002         _mesa_set_multisample(ctx, state);
1003         return;
1004      case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
1005         if (ctx->Multisample.SampleAlphaToCoverage == state)
1006            return;
1007         FLUSH_VERTICES(ctx, 0,
1008                        GL_MULTISAMPLE_BIT | GL_ENABLE_BIT);
1009         ctx->NewDriverState |= ST_NEW_BLEND;
1010         ctx->Multisample.SampleAlphaToCoverage = state;
1011         break;
1012      case GL_SAMPLE_ALPHA_TO_ONE_ARB:
1013         if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1014            goto invalid_enum_error;
1015         if (ctx->Multisample.SampleAlphaToOne == state)
1016            return;
1017         FLUSH_VERTICES(ctx, 0,
1018                        GL_MULTISAMPLE_BIT | GL_ENABLE_BIT);
1019         ctx->NewDriverState |= ST_NEW_BLEND;
1020         ctx->Multisample.SampleAlphaToOne = state;
1021         break;
1022      case GL_SAMPLE_COVERAGE_ARB:
1023         if (ctx->Multisample.SampleCoverage == state)
1024            return;
1025         FLUSH_VERTICES(ctx, 0,
1026                        GL_MULTISAMPLE_BIT | GL_ENABLE_BIT);
1027         ctx->NewDriverState |= ST_NEW_SAMPLE_STATE;
1028         ctx->Multisample.SampleCoverage = state;
1029         break;
1030      case GL_SAMPLE_COVERAGE_INVERT_ARB:
1031         if (!_mesa_is_desktop_gl(ctx))
1032            goto invalid_enum_error;
1033         if (ctx->Multisample.SampleCoverageInvert == state)
1034            return;
1035         FLUSH_VERTICES(ctx, 0, GL_MULTISAMPLE_BIT);
1036         ctx->NewDriverState |= ST_NEW_SAMPLE_STATE;
1037         ctx->Multisample.SampleCoverageInvert = state;
1038         break;
1039
1040      /* GL_ARB_sample_shading */
1041      case GL_SAMPLE_SHADING:
1042         if (!_mesa_has_ARB_sample_shading(ctx) && !_mesa_is_gles3(ctx))
1043            goto invalid_enum_error;
1044         if (ctx->Multisample.SampleShading == state)
1045            return;
1046         FLUSH_VERTICES(ctx, 0,
1047                        GL_MULTISAMPLE_BIT | GL_ENABLE_BIT);
1048         ctx->NewDriverState |= ctx->DriverFlags.NewSampleShading;
1049         ctx->Multisample.SampleShading = state;
1050         break;
1051
1052      /* GL_IBM_rasterpos_clip */
1053      case GL_RASTER_POSITION_UNCLIPPED_IBM:
1054         if (ctx->API != API_OPENGL_COMPAT)
1055            goto invalid_enum_error;
1056         if (ctx->Transform.RasterPositionUnclipped == state)
1057            return;
1058         FLUSH_VERTICES(ctx, 0, GL_TRANSFORM_BIT | GL_ENABLE_BIT);
1059         ctx->Transform.RasterPositionUnclipped = state;
1060         break;
1061
1062      /* GL_ARB_point_sprite */
1063      case GL_POINT_SPRITE:
1064         if (!(ctx->API == API_OPENGL_COMPAT &&
1065               _mesa_has_ARB_point_sprite(ctx)) &&
1066             !_mesa_has_OES_point_sprite(ctx))
1067            goto invalid_enum_error;
1068         if (ctx->Point.PointSprite == state)
1069            return;
1070         FLUSH_VERTICES(ctx, _NEW_POINT | _NEW_FF_VERT_PROGRAM |
1071                        _NEW_FF_FRAG_PROGRAM, GL_POINT_BIT | GL_ENABLE_BIT);
1072         ctx->Point.PointSprite = state;
1073         break;
1074
1075      case GL_VERTEX_PROGRAM_ARB:
1076         if (!_mesa_has_ARB_vertex_program(ctx))
1077            goto invalid_enum_error;
1078         if (ctx->VertexProgram.Enabled == state)
1079            return;
1080         FLUSH_VERTICES(ctx, _NEW_PROGRAM, GL_ENABLE_BIT);
1081         ctx->VertexProgram.Enabled = state;
1082         _mesa_update_vertex_processing_mode(ctx);
1083         _mesa_update_valid_to_render_state(ctx);
1084         break;
1085      case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
1086         /* This was added with ARB_vertex_program, but it is also used with
1087          * GLSL vertex shaders on desktop.
1088          */
1089         if (!_mesa_has_ARB_vertex_program(ctx) &&
1090             ctx->API != API_OPENGL_CORE)
1091            goto invalid_enum_error;
1092         if (ctx->VertexProgram.PointSizeEnabled == state)
1093            return;
1094         FLUSH_VERTICES(ctx, _NEW_PROGRAM, GL_ENABLE_BIT);
1095         ctx->VertexProgram.PointSizeEnabled = state;
1096         break;
1097      case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
1098         if (!_mesa_has_ARB_vertex_program(ctx))
1099            goto invalid_enum_error;
1100         if (ctx->VertexProgram.TwoSideEnabled == state)
1101            return;
1102         FLUSH_VERTICES(ctx, _NEW_PROGRAM, GL_ENABLE_BIT);
1103         ctx->VertexProgram.TwoSideEnabled = state;
1104         break;
1105
1106      /* GL_NV_texture_rectangle */
1107      case GL_TEXTURE_RECTANGLE_NV:
1108         if (!_mesa_has_NV_texture_rectangle(ctx))
1109            goto invalid_enum_error;
1110         if (!enable_texture(ctx, state, TEXTURE_RECT_BIT)) {
1111            return;
1112         }
1113         break;
1114
1115      /* GL_EXT_stencil_two_side */
1116      case GL_STENCIL_TEST_TWO_SIDE_EXT:
1117         if (!_mesa_has_EXT_stencil_two_side(ctx))
1118            goto invalid_enum_error;
1119         if (ctx->Stencil.TestTwoSide == state)
1120            return;
1121         FLUSH_VERTICES(ctx, 0,
1122                        GL_STENCIL_BUFFER_BIT | GL_ENABLE_BIT);
1123         ctx->NewDriverState |= ST_NEW_DSA;
1124         ctx->Stencil.TestTwoSide = state;
1125         if (state) {
1126            ctx->Stencil._BackFace = 2;
1127         } else {
1128            ctx->Stencil._BackFace = 1;
1129         }
1130         break;
1131
1132      case GL_FRAGMENT_PROGRAM_ARB:
1133         if (!_mesa_has_ARB_fragment_program(ctx))
1134            goto invalid_enum_error;
1135         if (ctx->FragmentProgram.Enabled == state)
1136            return;
1137         FLUSH_VERTICES(ctx, _NEW_PROGRAM, GL_ENABLE_BIT);
1138         ctx->FragmentProgram.Enabled = state;
1139         _mesa_update_valid_to_render_state(ctx);
1140         break;
1141
1142      /* GL_EXT_depth_bounds_test */
1143      case GL_DEPTH_BOUNDS_TEST_EXT:
1144         if (!_mesa_has_EXT_depth_bounds_test(ctx))
1145            goto invalid_enum_error;
1146         if (ctx->Depth.BoundsTest == state)
1147            return;
1148         FLUSH_VERTICES(ctx, 0, GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT);
1149         ctx->NewDriverState |= ST_NEW_DSA;
1150         ctx->Depth.BoundsTest = state;
1151         break;
1152
1153      case GL_DEPTH_CLAMP:
1154         if (!_mesa_has_ARB_depth_clamp(ctx) &&
1155             !_mesa_has_EXT_depth_clamp(ctx))
1156            goto invalid_enum_error;
1157         if (ctx->Transform.DepthClampNear == state &&
1158             ctx->Transform.DepthClampFar == state)
1159            return;
1160         FLUSH_VERTICES(ctx, 0,
1161                        GL_TRANSFORM_BIT | GL_ENABLE_BIT);
1162         ctx->NewDriverState |= ST_NEW_RASTERIZER;
1163         ctx->Transform.DepthClampNear = state;
1164         ctx->Transform.DepthClampFar = state;
1165         break;
1166
1167      case GL_DEPTH_CLAMP_NEAR_AMD:
1168         if (!_mesa_has_AMD_depth_clamp_separate(ctx))
1169            goto invalid_enum_error;
1170         if (ctx->Transform.DepthClampNear == state)
1171            return;
1172         FLUSH_VERTICES(ctx, 0,
1173                        GL_TRANSFORM_BIT | GL_ENABLE_BIT);
1174         ctx->NewDriverState |= ST_NEW_RASTERIZER;
1175         ctx->Transform.DepthClampNear = state;
1176         break;
1177
1178      case GL_DEPTH_CLAMP_FAR_AMD:
1179         if (!_mesa_has_AMD_depth_clamp_separate(ctx))
1180            goto invalid_enum_error;
1181         if (ctx->Transform.DepthClampFar == state)
1182            return;
1183         FLUSH_VERTICES(ctx, 0,
1184                        GL_TRANSFORM_BIT | GL_ENABLE_BIT);
1185         ctx->NewDriverState |= ST_NEW_RASTERIZER;
1186         ctx->Transform.DepthClampFar = state;
1187         break;
1188
1189      case GL_FRAGMENT_SHADER_ATI:
1190        if (!_mesa_has_ATI_fragment_shader(ctx))
1191           goto invalid_enum_error;
1192        if (ctx->ATIFragmentShader.Enabled == state)
1193           return;
1194        FLUSH_VERTICES(ctx, _NEW_PROGRAM, GL_ENABLE_BIT);
1195        ctx->ATIFragmentShader.Enabled = state;
1196        break;
1197
1198      case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1199         if (!_mesa_has_ARB_seamless_cube_map(ctx))
1200            goto invalid_enum_error;
1201         if (ctx->Texture.CubeMapSeamless != state) {
1202            FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT, 0);
1203            ctx->Texture.CubeMapSeamless = state;
1204         }
1205         break;
1206
1207      case GL_RASTERIZER_DISCARD:
1208         if (!(_mesa_has_EXT_transform_feedback(ctx) || _mesa_is_gles3(ctx)))
1209            goto invalid_enum_error;
1210         if (ctx->RasterDiscard != state) {
1211            FLUSH_VERTICES(ctx, 0, 0);
1212            ctx->NewDriverState |= ST_NEW_RASTERIZER;
1213            ctx->RasterDiscard = state;
1214         }
1215         break;
1216
1217      case GL_TILE_RASTER_ORDER_FIXED_MESA:
1218         if (!_mesa_has_MESA_tile_raster_order(ctx))
1219            goto invalid_enum_error;
1220         if (ctx->TileRasterOrderFixed != state) {
1221            FLUSH_VERTICES(ctx, 0, GL_ENABLE_BIT);
1222            ctx->NewDriverState |= ST_NEW_RASTERIZER;
1223            ctx->TileRasterOrderFixed = state;
1224         }
1225         break;
1226
1227      case GL_TILE_RASTER_ORDER_INCREASING_X_MESA:
1228         if (!_mesa_has_MESA_tile_raster_order(ctx))
1229            goto invalid_enum_error;
1230         if (ctx->TileRasterOrderIncreasingX != state) {
1231            FLUSH_VERTICES(ctx, 0, GL_ENABLE_BIT);
1232            ctx->NewDriverState |= ST_NEW_RASTERIZER;
1233            ctx->TileRasterOrderIncreasingX = state;
1234         }
1235         break;
1236
1237      case GL_TILE_RASTER_ORDER_INCREASING_Y_MESA:
1238         if (!_mesa_has_MESA_tile_raster_order(ctx))
1239            goto invalid_enum_error;
1240         if (ctx->TileRasterOrderIncreasingY != state) {
1241            FLUSH_VERTICES(ctx, 0, GL_ENABLE_BIT);
1242            ctx->NewDriverState |= ST_NEW_RASTERIZER;
1243            ctx->TileRasterOrderIncreasingY = state;
1244         }
1245         break;
1246
1247      /* GL 3.1 primitive restart.  Note: this enum is different from
1248       * GL_PRIMITIVE_RESTART_NV (which is client state).
1249       */
1250      case GL_PRIMITIVE_RESTART:
1251         if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
1252            goto invalid_enum_error;
1253         }
1254         if (ctx->Array.PrimitiveRestart != state) {
1255            ctx->Array.PrimitiveRestart = state;
1256            _mesa_update_derived_primitive_restart_state(ctx);
1257         }
1258         break;
1259
1260      case GL_PRIMITIVE_RESTART_FIXED_INDEX:
1261         if (!_mesa_is_gles3(ctx) && !_mesa_has_ARB_ES3_compatibility(ctx))
1262            goto invalid_enum_error;
1263         if (ctx->Array.PrimitiveRestartFixedIndex != state) {
1264            ctx->Array.PrimitiveRestartFixedIndex = state;
1265            _mesa_update_derived_primitive_restart_state(ctx);
1266         }
1267         break;
1268
1269      /* GL3.0 - GL_framebuffer_sRGB */
1270      case GL_FRAMEBUFFER_SRGB_EXT:
1271         if (!_mesa_has_EXT_framebuffer_sRGB(ctx) &&
1272             !_mesa_has_EXT_sRGB_write_control(ctx))
1273            goto invalid_enum_error;
1274         _mesa_set_framebuffer_srgb(ctx, state);
1275         return;
1276
1277      /* GL_OES_EGL_image_external */
1278      case GL_TEXTURE_EXTERNAL_OES:
1279         if (!_mesa_has_OES_EGL_image_external(ctx))
1280            goto invalid_enum_error;
1281         if (!enable_texture(ctx, state, TEXTURE_EXTERNAL_BIT)) {
1282            return;
1283         }
1284         break;
1285
1286      /* ARB_texture_multisample */
1287      case GL_SAMPLE_MASK:
1288         if (!_mesa_has_ARB_texture_multisample(ctx) && !_mesa_is_gles31(ctx))
1289            goto invalid_enum_error;
1290         if (ctx->Multisample.SampleMask == state)
1291            return;
1292         FLUSH_VERTICES(ctx, 0, 0);
1293         ctx->NewDriverState |= ST_NEW_SAMPLE_STATE;
1294         ctx->Multisample.SampleMask = state;
1295         break;
1296
1297      case GL_BLEND_ADVANCED_COHERENT_KHR:
1298         if (!_mesa_has_KHR_blend_equation_advanced_coherent(ctx))
1299            goto invalid_enum_error;
1300         if (ctx->Color.BlendCoherent == state)
1301            return;
1302         FLUSH_VERTICES(ctx, 0, GL_COLOR_BUFFER_BIT);
1303         ctx->NewDriverState |= ST_NEW_BLEND;
1304         ctx->Color.BlendCoherent = state;
1305         break;
1306
1307      case GL_BLACKHOLE_RENDER_INTEL:
1308         if (!_mesa_has_INTEL_blackhole_render(ctx))
1309            goto invalid_enum_error;
1310         if (ctx->IntelBlackholeRender == state)
1311            return;
1312         FLUSH_VERTICES(ctx, 0, 0);
1313         ctx->IntelBlackholeRender = state;
1314         ctx->pipe->set_frontend_noop(ctx->pipe, state);
1315         break;
1316
1317      default:
1318         goto invalid_enum_error;
1319   }
1320   return;
1321
1322invalid_enum_error:
1323   _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(%s)",
1324               state ? "Enable" : "Disable", _mesa_enum_to_string(cap));
1325}
1326
1327
1328/**
1329 * Enable GL capability.  Called by glEnable()
1330 * \param cap  state to enable.
1331 */
1332void GLAPIENTRY
1333_mesa_Enable( GLenum cap )
1334{
1335   GET_CURRENT_CONTEXT(ctx);
1336
1337   _mesa_set_enable( ctx, cap, GL_TRUE );
1338}
1339
1340
1341/**
1342 * Disable GL capability.  Called by glDisable()
1343 * \param cap  state to disable.
1344 */
1345void GLAPIENTRY
1346_mesa_Disable( GLenum cap )
1347{
1348   GET_CURRENT_CONTEXT(ctx);
1349
1350   _mesa_set_enable( ctx, cap, GL_FALSE );
1351}
1352
1353
1354
1355/**
1356 * Enable/disable an indexed state var.
1357 */
1358void
1359_mesa_set_enablei(struct gl_context *ctx, GLenum cap,
1360                  GLuint index, GLboolean state)
1361{
1362   assert(state == 0 || state == 1);
1363   switch (cap) {
1364   case GL_BLEND:
1365      if (!ctx->Extensions.EXT_draw_buffers2) {
1366         goto invalid_enum_error;
1367      }
1368      if (index >= ctx->Const.MaxDrawBuffers) {
1369         _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1370                     state ? "glEnableIndexed" : "glDisableIndexed", index);
1371         return;
1372      }
1373      if (((ctx->Color.BlendEnabled >> index) & 1) != state) {
1374         GLbitfield enabled = ctx->Color.BlendEnabled;
1375
1376         if (state)
1377            enabled |= (1 << index);
1378         else
1379            enabled &= ~(1 << index);
1380
1381         _mesa_flush_vertices_for_blend_adv(ctx, enabled,
1382                                            ctx->Color._AdvancedBlendMode);
1383         ctx->PopAttribState |= GL_ENABLE_BIT;
1384         ctx->Color.BlendEnabled = enabled;
1385         _mesa_update_allow_draw_out_of_order(ctx);
1386         _mesa_update_valid_to_render_state(ctx);
1387      }
1388      break;
1389   case GL_SCISSOR_TEST:
1390      if (index >= ctx->Const.MaxViewports) {
1391         _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1392                     state ? "glEnablei" : "glDisablei", index);
1393         return;
1394      }
1395      if (((ctx->Scissor.EnableFlags >> index) & 1) != state) {
1396         st_flush_bitmap_cache(st_context(ctx));
1397
1398         FLUSH_VERTICES(ctx, 0,
1399                        GL_SCISSOR_BIT | GL_ENABLE_BIT);
1400         ctx->NewDriverState |= ST_NEW_SCISSOR | ST_NEW_RASTERIZER;
1401         if (state)
1402            ctx->Scissor.EnableFlags |= (1 << index);
1403         else
1404            ctx->Scissor.EnableFlags &= ~(1 << index);
1405      }
1406      break;
1407   /* EXT_direct_state_access */
1408   case GL_TEXTURE_1D:
1409   case GL_TEXTURE_2D:
1410   case GL_TEXTURE_3D:
1411   case GL_TEXTURE_CUBE_MAP:
1412   case GL_TEXTURE_GEN_S:
1413   case GL_TEXTURE_GEN_T:
1414   case GL_TEXTURE_GEN_R:
1415   case GL_TEXTURE_GEN_Q:
1416   case GL_TEXTURE_RECTANGLE_ARB: {
1417      const GLuint curTexUnitSave = ctx->Texture.CurrentUnit;
1418      if (index >= MAX2(ctx->Const.MaxCombinedTextureImageUnits,
1419                        ctx->Const.MaxTextureCoordUnits)) {
1420         _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1421                     state ? "glEnablei" : "glDisablei", index);
1422         return;
1423      }
1424      _mesa_ActiveTexture(GL_TEXTURE0 + index);
1425      _mesa_set_enable( ctx, cap, state );
1426      _mesa_ActiveTexture(GL_TEXTURE0 + curTexUnitSave);
1427      break;
1428   }
1429   default:
1430      goto invalid_enum_error;
1431   }
1432   return;
1433
1434invalid_enum_error:
1435    _mesa_error(ctx, GL_INVALID_ENUM, "%s(cap=%s)",
1436                state ? "glEnablei" : "glDisablei",
1437                _mesa_enum_to_string(cap));
1438}
1439
1440
1441void GLAPIENTRY
1442_mesa_Disablei( GLenum cap, GLuint index )
1443{
1444   GET_CURRENT_CONTEXT(ctx);
1445   _mesa_set_enablei(ctx, cap, index, GL_FALSE);
1446}
1447
1448
1449void GLAPIENTRY
1450_mesa_Enablei( GLenum cap, GLuint index )
1451{
1452   GET_CURRENT_CONTEXT(ctx);
1453   _mesa_set_enablei(ctx, cap, index, GL_TRUE);
1454}
1455
1456
1457GLboolean GLAPIENTRY
1458_mesa_IsEnabledi( GLenum cap, GLuint index )
1459{
1460   GET_CURRENT_CONTEXT(ctx);
1461   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1462   switch (cap) {
1463   case GL_BLEND:
1464      if (index >= ctx->Const.MaxDrawBuffers) {
1465         _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
1466                     index);
1467         return GL_FALSE;
1468      }
1469      return (ctx->Color.BlendEnabled >> index) & 1;
1470   case GL_SCISSOR_TEST:
1471      if (index >= ctx->Const.MaxViewports) {
1472         _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
1473                     index);
1474         return GL_FALSE;
1475      }
1476      return (ctx->Scissor.EnableFlags >> index) & 1;
1477   /* EXT_direct_state_access */
1478   case GL_TEXTURE_1D:
1479   case GL_TEXTURE_2D:
1480   case GL_TEXTURE_3D:
1481   case GL_TEXTURE_CUBE_MAP:
1482   case GL_TEXTURE_GEN_S:
1483   case GL_TEXTURE_GEN_T:
1484   case GL_TEXTURE_GEN_R:
1485   case GL_TEXTURE_GEN_Q:
1486   case GL_TEXTURE_RECTANGLE_ARB: {
1487      GLboolean state;
1488      const GLuint curTexUnitSave = ctx->Texture.CurrentUnit;
1489      if (index >= MAX2(ctx->Const.MaxCombinedTextureImageUnits,
1490                        ctx->Const.MaxTextureCoordUnits)) {
1491         _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
1492                     index);
1493         return GL_FALSE;
1494      }
1495      _mesa_ActiveTexture(GL_TEXTURE0 + index);
1496      state = _mesa_IsEnabled(cap);
1497      _mesa_ActiveTexture(GL_TEXTURE0 + curTexUnitSave);
1498      return state;
1499   }
1500   default:
1501      _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabledIndexed(cap=%s)",
1502                  _mesa_enum_to_string(cap));
1503      return GL_FALSE;
1504   }
1505}
1506
1507
1508
1509/**
1510 * Helper function to determine whether a texture target is enabled.
1511 */
1512static GLboolean
1513is_texture_enabled(struct gl_context *ctx, GLbitfield bit)
1514{
1515   const struct gl_fixedfunc_texture_unit *const texUnit =
1516      _mesa_get_fixedfunc_tex_unit(ctx, ctx->Texture.CurrentUnit);
1517
1518   if (!texUnit)
1519      return GL_FALSE;
1520
1521   return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE;
1522}
1523
1524
1525/**
1526 * Return simple enable/disable state.
1527 *
1528 * \param cap  state variable to query.
1529 *
1530 * Returns the state of the specified capability from the current GL context.
1531 * For the capabilities associated with extensions verifies that those
1532 * extensions are effectively present before reporting.
1533 */
1534GLboolean GLAPIENTRY
1535_mesa_IsEnabled( GLenum cap )
1536{
1537   GET_CURRENT_CONTEXT(ctx);
1538   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1539
1540   switch (cap) {
1541      case GL_ALPHA_TEST:
1542         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1543            goto invalid_enum_error;
1544         return ctx->Color.AlphaEnabled;
1545      case GL_AUTO_NORMAL:
1546         if (ctx->API != API_OPENGL_COMPAT)
1547            goto invalid_enum_error;
1548         return ctx->Eval.AutoNormal;
1549      case GL_BLEND:
1550         return ctx->Color.BlendEnabled & 1;  /* return state for buffer[0] */
1551      case GL_CLIP_DISTANCE0: /* aka GL_CLIP_PLANE0 */
1552      case GL_CLIP_DISTANCE1:
1553      case GL_CLIP_DISTANCE2:
1554      case GL_CLIP_DISTANCE3:
1555      case GL_CLIP_DISTANCE4:
1556      case GL_CLIP_DISTANCE5:
1557      case GL_CLIP_DISTANCE6:
1558      case GL_CLIP_DISTANCE7: {
1559         const GLuint p = cap - GL_CLIP_DISTANCE0;
1560
1561         if (p >= ctx->Const.MaxClipPlanes)
1562            goto invalid_enum_error;
1563
1564         return (ctx->Transform.ClipPlanesEnabled >> p) & 1;
1565      }
1566      case GL_COLOR_MATERIAL:
1567         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1568            goto invalid_enum_error;
1569         return ctx->Light.ColorMaterialEnabled;
1570      case GL_CULL_FACE:
1571         return ctx->Polygon.CullFlag;
1572      case GL_DEBUG_OUTPUT:
1573      case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB:
1574         return (GLboolean) _mesa_get_debug_state_int(ctx, cap);
1575      case GL_DEPTH_TEST:
1576         return ctx->Depth.Test;
1577      case GL_DITHER:
1578         return ctx->Color.DitherFlag;
1579      case GL_FOG:
1580         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1581            goto invalid_enum_error;
1582         return ctx->Fog.Enabled;
1583      case GL_LIGHTING:
1584         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1585            goto invalid_enum_error;
1586         return ctx->Light.Enabled;
1587      case GL_LIGHT0:
1588      case GL_LIGHT1:
1589      case GL_LIGHT2:
1590      case GL_LIGHT3:
1591      case GL_LIGHT4:
1592      case GL_LIGHT5:
1593      case GL_LIGHT6:
1594      case GL_LIGHT7:
1595         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1596            goto invalid_enum_error;
1597         return ctx->Light.Light[cap-GL_LIGHT0].Enabled;
1598      case GL_LINE_SMOOTH:
1599         if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1600            goto invalid_enum_error;
1601         return ctx->Line.SmoothFlag;
1602      case GL_LINE_STIPPLE:
1603         if (ctx->API != API_OPENGL_COMPAT)
1604            goto invalid_enum_error;
1605         return ctx->Line.StippleFlag;
1606      case GL_INDEX_LOGIC_OP:
1607         if (ctx->API != API_OPENGL_COMPAT)
1608            goto invalid_enum_error;
1609         return ctx->Color.IndexLogicOpEnabled;
1610      case GL_COLOR_LOGIC_OP:
1611         if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1612            goto invalid_enum_error;
1613         return ctx->Color.ColorLogicOpEnabled;
1614      case GL_MAP1_COLOR_4:
1615         if (ctx->API != API_OPENGL_COMPAT)
1616            goto invalid_enum_error;
1617         return ctx->Eval.Map1Color4;
1618      case GL_MAP1_INDEX:
1619         if (ctx->API != API_OPENGL_COMPAT)
1620            goto invalid_enum_error;
1621         return ctx->Eval.Map1Index;
1622      case GL_MAP1_NORMAL:
1623         if (ctx->API != API_OPENGL_COMPAT)
1624            goto invalid_enum_error;
1625         return ctx->Eval.Map1Normal;
1626      case GL_MAP1_TEXTURE_COORD_1:
1627         if (ctx->API != API_OPENGL_COMPAT)
1628            goto invalid_enum_error;
1629         return ctx->Eval.Map1TextureCoord1;
1630      case GL_MAP1_TEXTURE_COORD_2:
1631         if (ctx->API != API_OPENGL_COMPAT)
1632            goto invalid_enum_error;
1633         return ctx->Eval.Map1TextureCoord2;
1634      case GL_MAP1_TEXTURE_COORD_3:
1635         if (ctx->API != API_OPENGL_COMPAT)
1636            goto invalid_enum_error;
1637         return ctx->Eval.Map1TextureCoord3;
1638      case GL_MAP1_TEXTURE_COORD_4:
1639         if (ctx->API != API_OPENGL_COMPAT)
1640            goto invalid_enum_error;
1641         return ctx->Eval.Map1TextureCoord4;
1642      case GL_MAP1_VERTEX_3:
1643         if (ctx->API != API_OPENGL_COMPAT)
1644            goto invalid_enum_error;
1645         return ctx->Eval.Map1Vertex3;
1646      case GL_MAP1_VERTEX_4:
1647         if (ctx->API != API_OPENGL_COMPAT)
1648            goto invalid_enum_error;
1649         return ctx->Eval.Map1Vertex4;
1650      case GL_MAP2_COLOR_4:
1651         if (ctx->API != API_OPENGL_COMPAT)
1652            goto invalid_enum_error;
1653         return ctx->Eval.Map2Color4;
1654      case GL_MAP2_INDEX:
1655         if (ctx->API != API_OPENGL_COMPAT)
1656            goto invalid_enum_error;
1657         return ctx->Eval.Map2Index;
1658      case GL_MAP2_NORMAL:
1659         if (ctx->API != API_OPENGL_COMPAT)
1660            goto invalid_enum_error;
1661         return ctx->Eval.Map2Normal;
1662      case GL_MAP2_TEXTURE_COORD_1:
1663         if (ctx->API != API_OPENGL_COMPAT)
1664            goto invalid_enum_error;
1665         return ctx->Eval.Map2TextureCoord1;
1666      case GL_MAP2_TEXTURE_COORD_2:
1667         if (ctx->API != API_OPENGL_COMPAT)
1668            goto invalid_enum_error;
1669         return ctx->Eval.Map2TextureCoord2;
1670      case GL_MAP2_TEXTURE_COORD_3:
1671         if (ctx->API != API_OPENGL_COMPAT)
1672            goto invalid_enum_error;
1673         return ctx->Eval.Map2TextureCoord3;
1674      case GL_MAP2_TEXTURE_COORD_4:
1675         if (ctx->API != API_OPENGL_COMPAT)
1676            goto invalid_enum_error;
1677         return ctx->Eval.Map2TextureCoord4;
1678      case GL_MAP2_VERTEX_3:
1679         if (ctx->API != API_OPENGL_COMPAT)
1680            goto invalid_enum_error;
1681         return ctx->Eval.Map2Vertex3;
1682      case GL_MAP2_VERTEX_4:
1683         if (ctx->API != API_OPENGL_COMPAT)
1684            goto invalid_enum_error;
1685         return ctx->Eval.Map2Vertex4;
1686      case GL_NORMALIZE:
1687         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1688            goto invalid_enum_error;
1689         return ctx->Transform.Normalize;
1690      case GL_POINT_SMOOTH:
1691         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1692            goto invalid_enum_error;
1693         return ctx->Point.SmoothFlag;
1694      case GL_POLYGON_SMOOTH:
1695         if (!_mesa_is_desktop_gl(ctx))
1696            goto invalid_enum_error;
1697         return ctx->Polygon.SmoothFlag;
1698      case GL_POLYGON_STIPPLE:
1699         if (ctx->API != API_OPENGL_COMPAT)
1700            goto invalid_enum_error;
1701         return ctx->Polygon.StippleFlag;
1702      case GL_POLYGON_OFFSET_POINT:
1703         if (!_mesa_is_desktop_gl(ctx))
1704            goto invalid_enum_error;
1705         return ctx->Polygon.OffsetPoint;
1706      case GL_POLYGON_OFFSET_LINE:
1707         if (!_mesa_is_desktop_gl(ctx))
1708            goto invalid_enum_error;
1709         return ctx->Polygon.OffsetLine;
1710      case GL_POLYGON_OFFSET_FILL:
1711         return ctx->Polygon.OffsetFill;
1712      case GL_RESCALE_NORMAL_EXT:
1713         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1714            goto invalid_enum_error;
1715         return ctx->Transform.RescaleNormals;
1716      case GL_SCISSOR_TEST:
1717         return ctx->Scissor.EnableFlags & 1;  /* return state for index 0 */
1718      case GL_STENCIL_TEST:
1719         return ctx->Stencil.Enabled;
1720      case GL_TEXTURE_1D:
1721         if (ctx->API != API_OPENGL_COMPAT)
1722            goto invalid_enum_error;
1723         return is_texture_enabled(ctx, TEXTURE_1D_BIT);
1724      case GL_TEXTURE_2D:
1725         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1726            goto invalid_enum_error;
1727         return is_texture_enabled(ctx, TEXTURE_2D_BIT);
1728      case GL_TEXTURE_3D:
1729         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1730            goto invalid_enum_error;
1731         return is_texture_enabled(ctx, TEXTURE_3D_BIT);
1732      case GL_TEXTURE_GEN_S:
1733      case GL_TEXTURE_GEN_T:
1734      case GL_TEXTURE_GEN_R:
1735      case GL_TEXTURE_GEN_Q:
1736         {
1737            const struct gl_fixedfunc_texture_unit *texUnit =
1738               get_texcoord_unit(ctx);
1739
1740            if (ctx->API != API_OPENGL_COMPAT)
1741               goto invalid_enum_error;
1742
1743            if (texUnit) {
1744               GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
1745               return (texUnit->TexGenEnabled & coordBit) ? GL_TRUE : GL_FALSE;
1746            }
1747         }
1748         return GL_FALSE;
1749      case GL_TEXTURE_GEN_STR_OES:
1750         {
1751            const struct gl_fixedfunc_texture_unit *texUnit =
1752               get_texcoord_unit(ctx);
1753
1754            if (ctx->API != API_OPENGLES)
1755               goto invalid_enum_error;
1756
1757            if (texUnit) {
1758               return (texUnit->TexGenEnabled & STR_BITS) == STR_BITS
1759                  ? GL_TRUE : GL_FALSE;
1760            }
1761
1762            return GL_FALSE;
1763         }
1764
1765      /* client-side state */
1766      case GL_VERTEX_ARRAY:
1767         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1768            goto invalid_enum_error;
1769         return !!(ctx->Array.VAO->Enabled & VERT_BIT_POS);
1770      case GL_NORMAL_ARRAY:
1771         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1772            goto invalid_enum_error;
1773         return !!(ctx->Array.VAO->Enabled & VERT_BIT_NORMAL);
1774      case GL_COLOR_ARRAY:
1775         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1776            goto invalid_enum_error;
1777         return !!(ctx->Array.VAO->Enabled & VERT_BIT_COLOR0);
1778      case GL_INDEX_ARRAY:
1779         if (ctx->API != API_OPENGL_COMPAT)
1780            goto invalid_enum_error;
1781         return !!(ctx->Array.VAO->Enabled & VERT_BIT_COLOR_INDEX);
1782      case GL_TEXTURE_COORD_ARRAY:
1783         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1784            goto invalid_enum_error;
1785         return !!(ctx->Array.VAO->Enabled &
1786                   VERT_BIT_TEX(ctx->Array.ActiveTexture));
1787      case GL_EDGE_FLAG_ARRAY:
1788         if (ctx->API != API_OPENGL_COMPAT)
1789            goto invalid_enum_error;
1790         return !!(ctx->Array.VAO->Enabled & VERT_BIT_EDGEFLAG);
1791      case GL_FOG_COORDINATE_ARRAY_EXT:
1792         if (ctx->API != API_OPENGL_COMPAT)
1793            goto invalid_enum_error;
1794         return !!(ctx->Array.VAO->Enabled & VERT_BIT_FOG);
1795      case GL_SECONDARY_COLOR_ARRAY_EXT:
1796         if (ctx->API != API_OPENGL_COMPAT)
1797            goto invalid_enum_error;
1798         return !!(ctx->Array.VAO->Enabled & VERT_BIT_COLOR1);
1799      case GL_POINT_SIZE_ARRAY_OES:
1800         if (ctx->API != API_OPENGLES)
1801            goto invalid_enum_error;
1802         return !!(ctx->Array.VAO->Enabled & VERT_BIT_POINT_SIZE);
1803
1804      /* GL_ARB_texture_cube_map */
1805      case GL_TEXTURE_CUBE_MAP:
1806         if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1807            goto invalid_enum_error;
1808         return is_texture_enabled(ctx, TEXTURE_CUBE_BIT);
1809
1810      /* GL_EXT_secondary_color */
1811      case GL_COLOR_SUM_EXT:
1812         if (ctx->API != API_OPENGL_COMPAT)
1813            goto invalid_enum_error;
1814         return ctx->Fog.ColorSumEnabled;
1815
1816      /* GL_ARB_multisample */
1817      case GL_MULTISAMPLE_ARB:
1818         if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1819            goto invalid_enum_error;
1820         return ctx->Multisample.Enabled;
1821      case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
1822         return ctx->Multisample.SampleAlphaToCoverage;
1823      case GL_SAMPLE_ALPHA_TO_ONE_ARB:
1824         if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1825            goto invalid_enum_error;
1826         return ctx->Multisample.SampleAlphaToOne;
1827      case GL_SAMPLE_COVERAGE_ARB:
1828         return ctx->Multisample.SampleCoverage;
1829      case GL_SAMPLE_COVERAGE_INVERT_ARB:
1830         if (!_mesa_is_desktop_gl(ctx))
1831            goto invalid_enum_error;
1832         return ctx->Multisample.SampleCoverageInvert;
1833
1834      /* GL_IBM_rasterpos_clip */
1835      case GL_RASTER_POSITION_UNCLIPPED_IBM:
1836         if (ctx->API != API_OPENGL_COMPAT)
1837            goto invalid_enum_error;
1838         return ctx->Transform.RasterPositionUnclipped;
1839
1840      /* GL_ARB_point_sprite */
1841      case GL_POINT_SPRITE:
1842         if (!(ctx->API == API_OPENGL_COMPAT &&
1843               _mesa_has_ARB_point_sprite(ctx)) &&
1844             !_mesa_has_OES_point_sprite(ctx))
1845            goto invalid_enum_error;
1846         return ctx->Point.PointSprite;
1847
1848      case GL_VERTEX_PROGRAM_ARB:
1849         if (!_mesa_has_ARB_vertex_program(ctx))
1850            goto invalid_enum_error;
1851         return ctx->VertexProgram.Enabled;
1852      case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
1853         /* This was added with ARB_vertex_program, but it is also used with
1854          * GLSL vertex shaders on desktop.
1855          */
1856         if (!_mesa_has_ARB_vertex_program(ctx) &&
1857             ctx->API != API_OPENGL_CORE)
1858            goto invalid_enum_error;
1859         return ctx->VertexProgram.PointSizeEnabled;
1860      case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
1861         if (!_mesa_has_ARB_vertex_program(ctx))
1862            goto invalid_enum_error;
1863         return ctx->VertexProgram.TwoSideEnabled;
1864
1865      /* GL_NV_texture_rectangle */
1866      case GL_TEXTURE_RECTANGLE_NV:
1867         if (!_mesa_has_NV_texture_rectangle(ctx))
1868            goto invalid_enum_error;
1869         return is_texture_enabled(ctx, TEXTURE_RECT_BIT);
1870
1871      /* GL_EXT_stencil_two_side */
1872      case GL_STENCIL_TEST_TWO_SIDE_EXT:
1873         if (!_mesa_has_EXT_stencil_two_side(ctx))
1874            goto invalid_enum_error;
1875         return ctx->Stencil.TestTwoSide;
1876
1877      case GL_FRAGMENT_PROGRAM_ARB:
1878         if (!_mesa_has_ARB_fragment_program(ctx))
1879            goto invalid_enum_error;
1880         return ctx->FragmentProgram.Enabled;
1881
1882      /* GL_EXT_depth_bounds_test */
1883      case GL_DEPTH_BOUNDS_TEST_EXT:
1884         if (!_mesa_has_EXT_depth_bounds_test(ctx))
1885            goto invalid_enum_error;
1886         return ctx->Depth.BoundsTest;
1887
1888      /* GL_ARB_depth_clamp */
1889      case GL_DEPTH_CLAMP:
1890         if (!_mesa_has_ARB_depth_clamp(ctx) &&
1891             !_mesa_has_EXT_depth_clamp(ctx))
1892            goto invalid_enum_error;
1893         return ctx->Transform.DepthClampNear ||
1894                ctx->Transform.DepthClampFar;
1895
1896      case GL_DEPTH_CLAMP_NEAR_AMD:
1897         if (!_mesa_has_AMD_depth_clamp_separate(ctx))
1898            goto invalid_enum_error;
1899         return ctx->Transform.DepthClampNear;
1900
1901      case GL_DEPTH_CLAMP_FAR_AMD:
1902         if (!_mesa_has_AMD_depth_clamp_separate(ctx))
1903            goto invalid_enum_error;
1904         return ctx->Transform.DepthClampFar;
1905
1906      case GL_FRAGMENT_SHADER_ATI:
1907         if (!_mesa_has_ATI_fragment_shader(ctx))
1908            goto invalid_enum_error;
1909         return ctx->ATIFragmentShader.Enabled;
1910
1911      case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1912         if (!_mesa_has_ARB_seamless_cube_map(ctx))
1913            goto invalid_enum_error;
1914         return ctx->Texture.CubeMapSeamless;
1915
1916      case GL_RASTERIZER_DISCARD:
1917         if (!(_mesa_has_EXT_transform_feedback(ctx) || _mesa_is_gles3(ctx)))
1918            goto invalid_enum_error;
1919         return ctx->RasterDiscard;
1920
1921      /* GL_NV_primitive_restart */
1922      case GL_PRIMITIVE_RESTART_NV:
1923         if (!_mesa_has_NV_primitive_restart(ctx))
1924            goto invalid_enum_error;
1925         return ctx->Array.PrimitiveRestart;
1926
1927      /* GL 3.1 primitive restart */
1928      case GL_PRIMITIVE_RESTART:
1929         if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
1930            goto invalid_enum_error;
1931         }
1932         return ctx->Array.PrimitiveRestart;
1933
1934      case GL_PRIMITIVE_RESTART_FIXED_INDEX:
1935         if (!_mesa_is_gles3(ctx) && !_mesa_has_ARB_ES3_compatibility(ctx))
1936            goto invalid_enum_error;
1937         return ctx->Array.PrimitiveRestartFixedIndex;
1938
1939      /* GL3.0 - GL_framebuffer_sRGB */
1940      case GL_FRAMEBUFFER_SRGB_EXT:
1941         if (!_mesa_has_EXT_framebuffer_sRGB(ctx) &&
1942             !_mesa_has_EXT_sRGB_write_control(ctx))
1943            goto invalid_enum_error;
1944         return ctx->Color.sRGBEnabled;
1945
1946      /* GL_OES_EGL_image_external */
1947      case GL_TEXTURE_EXTERNAL_OES:
1948         if (!_mesa_has_OES_EGL_image_external(ctx))
1949            goto invalid_enum_error;
1950         return is_texture_enabled(ctx, TEXTURE_EXTERNAL_BIT);
1951
1952      /* ARB_texture_multisample */
1953      case GL_SAMPLE_MASK:
1954         if (!_mesa_has_ARB_texture_multisample(ctx) && !_mesa_is_gles31(ctx))
1955            goto invalid_enum_error;
1956         return ctx->Multisample.SampleMask;
1957
1958      /* ARB_sample_shading */
1959      case GL_SAMPLE_SHADING:
1960         if (!_mesa_has_ARB_sample_shading(ctx) && !_mesa_is_gles3(ctx))
1961            goto invalid_enum_error;
1962         return ctx->Multisample.SampleShading;
1963
1964      case GL_BLEND_ADVANCED_COHERENT_KHR:
1965         if (!_mesa_has_KHR_blend_equation_advanced_coherent(ctx))
1966            goto invalid_enum_error;
1967         return ctx->Color.BlendCoherent;
1968
1969      case GL_CONSERVATIVE_RASTERIZATION_INTEL:
1970         if (!_mesa_has_INTEL_conservative_rasterization(ctx))
1971            goto invalid_enum_error;
1972         return ctx->IntelConservativeRasterization;
1973
1974      case GL_CONSERVATIVE_RASTERIZATION_NV:
1975         if (!_mesa_has_NV_conservative_raster(ctx))
1976            goto invalid_enum_error;
1977         return ctx->ConservativeRasterization;
1978
1979      case GL_TILE_RASTER_ORDER_FIXED_MESA:
1980         if (!_mesa_has_MESA_tile_raster_order(ctx))
1981            goto invalid_enum_error;
1982         return ctx->TileRasterOrderFixed;
1983
1984      case GL_TILE_RASTER_ORDER_INCREASING_X_MESA:
1985         if (!_mesa_has_MESA_tile_raster_order(ctx))
1986            goto invalid_enum_error;
1987         return ctx->TileRasterOrderIncreasingX;
1988
1989      case GL_TILE_RASTER_ORDER_INCREASING_Y_MESA:
1990         if (!_mesa_has_MESA_tile_raster_order(ctx))
1991            goto invalid_enum_error;
1992         return ctx->TileRasterOrderIncreasingY;
1993
1994      case GL_BLACKHOLE_RENDER_INTEL:
1995         if (!_mesa_has_INTEL_blackhole_render(ctx))
1996            goto invalid_enum_error;
1997         return ctx->IntelBlackholeRender;
1998
1999      default:
2000         goto invalid_enum_error;
2001   }
2002
2003   return GL_FALSE;
2004
2005invalid_enum_error:
2006   _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(%s)",
2007               _mesa_enum_to_string(cap));
2008   return GL_FALSE;
2009}
2010