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