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