3 * Enable/disable/query GL capabilities.
7 * Mesa 3-D graphics library
9 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
25 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #define CHECK_EXTENSION(EXTNAME, CAP) \
33 if (!ctx->Extensions.EXTNAME) { \
34 goto invalid_enum_error; \
39 * Helper to enable/disable client-side state.
42 client_state(struct gl_context
*ctx
, GLenum cap
, GLboolean state
)
49 var
= &ctx
->Array
.VertexAttrib
[VERT_ATTRIB_POS
].Enabled
;
53 var
= &ctx
->Array
.VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
;
54 flag
= VERT_BIT_NORMAL
;
57 var
= &ctx
->Array
.VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
;
58 flag
= VERT_BIT_COLOR0
;
61 var
= &ctx
->Array
.VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
;
62 flag
= VERT_BIT_COLOR_INDEX
;
64 case GL_TEXTURE_COORD_ARRAY
:
65 var
= &ctx
->Array
.VertexAttrib
[VERT_ATTRIB_TEX
].Enabled
;
68 case GL_EDGE_FLAG_ARRAY
:
69 var
= &ctx
->Array
.VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
;
70 flag
= VERT_BIT_EDGEFLAG
;
72 case GL_FOG_COORDINATE_ARRAY_EXT
:
73 var
= &ctx
->Array
.VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
;
76 case GL_SECONDARY_COLOR_ARRAY_EXT
:
77 var
= &ctx
->Array
.VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
;
78 flag
= VERT_BIT_COLOR1
;
81 #if FEATURE_point_size_array
82 case GL_POINT_SIZE_ARRAY_OES
:
83 var
= &ctx
->Array
.VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
;
84 flag
= VERT_BIT_POINT_SIZE
;
89 goto invalid_enum_error
;
95 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
96 ctx
->Array
.NewState
|= flag
;
98 _ae_invalidate_state(ctx
, _NEW_ARRAY
);
103 ctx
->Array
._Enabled
|= flag
;
105 ctx
->Array
._Enabled
&= ~flag
;
107 if (ctx
->Driver
.Enable
) {
108 ctx
->Driver
.Enable( ctx
, cap
, state
);
114 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%sClientState(0x%x)",
115 state
? "Enable" : "Disable", cap
);
120 * Enable GL capability.
121 * \param cap state to enable/disable.
123 * Get's the current context, assures that we're outside glBegin()/glEnd() and
124 * calls client_state().
127 _mesa_EnableClientState( GLenum cap
)
129 GET_CURRENT_CONTEXT(ctx
);
130 ASSERT_OUTSIDE_BEGIN_END(ctx
);
131 client_state( ctx
, cap
, GL_TRUE
);
136 * Disable GL capability.
137 * \param cap state to enable/disable.
139 * Get's the current context, assures that we're outside glBegin()/glEnd() and
140 * calls client_state().
143 _mesa_DisableClientState( GLenum cap
)
145 GET_CURRENT_CONTEXT(ctx
);
146 ASSERT_OUTSIDE_BEGIN_END(ctx
);
147 client_state( ctx
, cap
, GL_FALSE
);
151 #undef CHECK_EXTENSION
152 #define CHECK_EXTENSION(EXTNAME, CAP) \
153 if (!ctx->Extensions.EXTNAME) { \
154 goto invalid_enum_error; \
157 #define CHECK_EXTENSION2(EXT1, EXT2, CAP) \
158 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
159 goto invalid_enum_error; \
165 * Return pointer to current texture unit for setting/getting coordinate
167 * Note that we'll set GL_INVALID_OPERATION and return NULL if the active
168 * texture unit is higher than the number of supported coordinate units.
170 static inline struct gl_texture_unit
*
171 get_texcoord_unit(struct gl_context
*ctx
)
173 return &ctx
->Texture
.Unit
;
178 * Helper function to enable or disable a texture target.
179 * \param bit one of the TEXTURE_x_BIT values
180 * \return GL_TRUE if state is changing or GL_FALSE if no change
183 enable_texture(struct gl_context
*ctx
, GLboolean state
, GLbitfield texBit
)
185 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
;
186 const GLbitfield newenabled
= state
187 ? (texUnit
->Enabled
| texBit
) : (texUnit
->Enabled
& ~texBit
);
189 if (texUnit
->Enabled
== newenabled
)
192 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
193 texUnit
->Enabled
= newenabled
;
199 * Helper function to enable or disable state.
201 * \param ctx GL context.
202 * \param cap the state to enable/disable
203 * \param state whether to enable or disable the specified capability.
205 * Updates the current context and flushes the vertices as needed. For
206 * capabilities associated with extensions it verifies that those extensions
207 * are effectivly present before updating. Notifies the driver via
208 * dd_function_table::Enable.
211 _mesa_set_enable(struct gl_context
*ctx
, GLenum cap
, GLboolean state
)
213 if (MESA_VERBOSE
& VERBOSE_API
)
214 _mesa_debug(ctx
, "%s %s (newstate is %x)\n",
215 state
? "glEnable" : "glDisable",
216 _mesa_lookup_enum_by_nr(cap
),
221 if (ctx
->Color
.AlphaEnabled
== state
)
223 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
224 ctx
->Color
.AlphaEnabled
= state
;
227 if (ctx
->Eval
.AutoNormal
== state
)
229 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
230 ctx
->Eval
.AutoNormal
= state
;
234 if (state
!= ctx
->Color
.BlendEnabled
) {
235 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
236 ctx
->Color
.BlendEnabled
= state
;
241 case GL_CLIP_DISTANCE0
:
242 case GL_CLIP_DISTANCE1
:
243 case GL_CLIP_DISTANCE2
:
244 case GL_CLIP_DISTANCE3
:
245 case GL_CLIP_DISTANCE4
:
246 case GL_CLIP_DISTANCE5
:
247 case GL_CLIP_DISTANCE6
:
248 case GL_CLIP_DISTANCE7
:
250 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
252 if (p
>= ctx
->Const
.MaxClipPlanes
)
253 goto invalid_enum_error
;
255 if ((ctx
->Transform
.ClipPlanesEnabled
& (1 << p
))
256 == ((GLuint
) state
<< p
))
259 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
262 ctx
->Transform
.ClipPlanesEnabled
|= (1 << p
);
263 _mesa_update_clip_plane(ctx
, p
);
266 ctx
->Transform
.ClipPlanesEnabled
&= ~(1 << p
);
271 case GL_COLOR_MATERIAL
:
272 if (ctx
->Light
.ColorMaterialEnabled
== state
)
274 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
275 FLUSH_CURRENT(ctx
, 0);
276 ctx
->Light
.ColorMaterialEnabled
= state
;
278 _mesa_update_color_material( ctx
,
279 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
] );
283 if (ctx
->Polygon
.CullFlag
== state
)
285 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
286 ctx
->Polygon
.CullFlag
= state
;
289 if (ctx
->Depth
.Test
== state
)
291 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
292 ctx
->Depth
.Test
= state
;
295 if (ctx
->Color
.DitherFlag
== state
)
297 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
298 ctx
->Color
.DitherFlag
= state
;
301 if (ctx
->Fog
.Enabled
== state
)
303 FLUSH_VERTICES(ctx
, _NEW_FOG
);
304 ctx
->Fog
.Enabled
= state
;
314 if (ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
== state
)
316 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
317 ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
= state
;
319 insert_at_tail(&ctx
->Light
.EnabledList
,
320 &ctx
->Light
.Light
[cap
-GL_LIGHT0
]);
323 remove_from_list(&ctx
->Light
.Light
[cap
-GL_LIGHT0
]);
327 if (ctx
->Light
.Enabled
== state
)
329 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
330 ctx
->Light
.Enabled
= state
;
331 if (ctx
->Light
.Enabled
&& ctx
->Light
.Model
.TwoSide
)
332 ctx
->_TriangleCaps
|= DD_TRI_LIGHT_TWOSIDE
;
334 ctx
->_TriangleCaps
&= ~DD_TRI_LIGHT_TWOSIDE
;
337 if (ctx
->Line
.SmoothFlag
== state
)
339 FLUSH_VERTICES(ctx
, _NEW_LINE
);
340 ctx
->Line
.SmoothFlag
= state
;
341 ctx
->_TriangleCaps
^= DD_LINE_SMOOTH
;
343 case GL_LINE_STIPPLE
:
344 if (ctx
->Line
.StippleFlag
== state
)
346 FLUSH_VERTICES(ctx
, _NEW_LINE
);
347 ctx
->Line
.StippleFlag
= state
;
348 ctx
->_TriangleCaps
^= DD_LINE_STIPPLE
;
350 case GL_INDEX_LOGIC_OP
:
351 if (ctx
->Color
.IndexLogicOpEnabled
== state
)
353 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
354 ctx
->Color
.IndexLogicOpEnabled
= state
;
356 case GL_COLOR_LOGIC_OP
:
357 if (ctx
->Color
.ColorLogicOpEnabled
== state
)
359 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
360 ctx
->Color
.ColorLogicOpEnabled
= state
;
362 case GL_MAP1_COLOR_4
:
363 if (ctx
->Eval
.Map1Color4
== state
)
365 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
366 ctx
->Eval
.Map1Color4
= state
;
369 if (ctx
->Eval
.Map1Index
== state
)
371 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
372 ctx
->Eval
.Map1Index
= state
;
375 if (ctx
->Eval
.Map1Normal
== state
)
377 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
378 ctx
->Eval
.Map1Normal
= state
;
380 case GL_MAP1_TEXTURE_COORD_1
:
381 if (ctx
->Eval
.Map1TextureCoord1
== state
)
383 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
384 ctx
->Eval
.Map1TextureCoord1
= state
;
386 case GL_MAP1_TEXTURE_COORD_2
:
387 if (ctx
->Eval
.Map1TextureCoord2
== state
)
389 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
390 ctx
->Eval
.Map1TextureCoord2
= state
;
392 case GL_MAP1_TEXTURE_COORD_3
:
393 if (ctx
->Eval
.Map1TextureCoord3
== state
)
395 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
396 ctx
->Eval
.Map1TextureCoord3
= state
;
398 case GL_MAP1_TEXTURE_COORD_4
:
399 if (ctx
->Eval
.Map1TextureCoord4
== state
)
401 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
402 ctx
->Eval
.Map1TextureCoord4
= state
;
404 case GL_MAP1_VERTEX_3
:
405 if (ctx
->Eval
.Map1Vertex3
== state
)
407 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
408 ctx
->Eval
.Map1Vertex3
= state
;
410 case GL_MAP1_VERTEX_4
:
411 if (ctx
->Eval
.Map1Vertex4
== state
)
413 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
414 ctx
->Eval
.Map1Vertex4
= state
;
416 case GL_MAP2_COLOR_4
:
417 if (ctx
->Eval
.Map2Color4
== state
)
419 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
420 ctx
->Eval
.Map2Color4
= state
;
423 if (ctx
->Eval
.Map2Index
== state
)
425 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
426 ctx
->Eval
.Map2Index
= state
;
429 if (ctx
->Eval
.Map2Normal
== state
)
431 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
432 ctx
->Eval
.Map2Normal
= state
;
434 case GL_MAP2_TEXTURE_COORD_1
:
435 if (ctx
->Eval
.Map2TextureCoord1
== state
)
437 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
438 ctx
->Eval
.Map2TextureCoord1
= state
;
440 case GL_MAP2_TEXTURE_COORD_2
:
441 if (ctx
->Eval
.Map2TextureCoord2
== state
)
443 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
444 ctx
->Eval
.Map2TextureCoord2
= state
;
446 case GL_MAP2_TEXTURE_COORD_3
:
447 if (ctx
->Eval
.Map2TextureCoord3
== state
)
449 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
450 ctx
->Eval
.Map2TextureCoord3
= state
;
452 case GL_MAP2_TEXTURE_COORD_4
:
453 if (ctx
->Eval
.Map2TextureCoord4
== state
)
455 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
456 ctx
->Eval
.Map2TextureCoord4
= state
;
458 case GL_MAP2_VERTEX_3
:
459 if (ctx
->Eval
.Map2Vertex3
== state
)
461 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
462 ctx
->Eval
.Map2Vertex3
= state
;
464 case GL_MAP2_VERTEX_4
:
465 if (ctx
->Eval
.Map2Vertex4
== state
)
467 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
468 ctx
->Eval
.Map2Vertex4
= state
;
471 if (ctx
->Transform
.Normalize
== state
)
473 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
474 ctx
->Transform
.Normalize
= state
;
476 case GL_POINT_SMOOTH
:
477 if (ctx
->Point
.SmoothFlag
== state
)
479 FLUSH_VERTICES(ctx
, _NEW_POINT
);
480 ctx
->Point
.SmoothFlag
= state
;
481 ctx
->_TriangleCaps
^= DD_POINT_SMOOTH
;
483 case GL_POLYGON_SMOOTH
:
484 if (ctx
->Polygon
.SmoothFlag
== state
)
486 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
487 ctx
->Polygon
.SmoothFlag
= state
;
488 ctx
->_TriangleCaps
^= DD_TRI_SMOOTH
;
490 case GL_POLYGON_STIPPLE
:
491 if (ctx
->Polygon
.StippleFlag
== state
)
493 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
494 ctx
->Polygon
.StippleFlag
= state
;
495 ctx
->_TriangleCaps
^= DD_TRI_STIPPLE
;
497 case GL_POLYGON_OFFSET_POINT
:
498 if (ctx
->Polygon
.OffsetPoint
== state
)
500 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
501 ctx
->Polygon
.OffsetPoint
= state
;
503 case GL_POLYGON_OFFSET_LINE
:
504 if (ctx
->Polygon
.OffsetLine
== state
)
506 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
507 ctx
->Polygon
.OffsetLine
= state
;
509 case GL_POLYGON_OFFSET_FILL
:
510 if (ctx
->Polygon
.OffsetFill
== state
)
512 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
513 ctx
->Polygon
.OffsetFill
= state
;
515 case GL_RESCALE_NORMAL_EXT
:
516 if (ctx
->Transform
.RescaleNormals
== state
)
518 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
519 ctx
->Transform
.RescaleNormals
= state
;
521 case GL_SCISSOR_TEST
:
522 if (ctx
->Scissor
.Enabled
== state
)
524 FLUSH_VERTICES(ctx
, _NEW_SCISSOR
);
525 ctx
->Scissor
.Enabled
= state
;
527 case GL_STENCIL_TEST
:
528 if (ctx
->Stencil
.Enabled
== state
)
530 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
531 ctx
->Stencil
.Enabled
= state
;
534 if (!enable_texture(ctx
, state
, TEXTURE_1D_BIT
)) {
539 if (!enable_texture(ctx
, state
, TEXTURE_2D_BIT
)) {
543 case GL_TEXTURE_GEN_S
:
544 case GL_TEXTURE_GEN_T
:
545 case GL_TEXTURE_GEN_R
:
546 case GL_TEXTURE_GEN_Q
:
548 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
550 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
551 GLbitfield newenabled
= texUnit
->TexGenEnabled
& ~coordBit
;
553 newenabled
|= coordBit
;
554 if (texUnit
->TexGenEnabled
== newenabled
)
556 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
557 texUnit
->TexGenEnabled
= newenabled
;
563 case GL_TEXTURE_GEN_STR_OES
:
564 /* disable S, T, and R at the same time */
566 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
569 texUnit
->TexGenEnabled
& ~STR_BITS
;
571 newenabled
|= STR_BITS
;
572 if (texUnit
->TexGenEnabled
== newenabled
)
574 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
575 texUnit
->TexGenEnabled
= newenabled
;
581 /* client-side state */
582 case GL_VERTEX_ARRAY
:
583 case GL_NORMAL_ARRAY
:
586 case GL_TEXTURE_COORD_ARRAY
:
587 case GL_EDGE_FLAG_ARRAY
:
588 case GL_FOG_COORDINATE_ARRAY_EXT
:
589 case GL_SECONDARY_COLOR_ARRAY_EXT
:
590 case GL_POINT_SIZE_ARRAY_OES
:
591 client_state( ctx
, cap
, state
);
594 /* GL_ARB_texture_cube_map */
595 case GL_TEXTURE_CUBE_MAP_ARB
:
596 CHECK_EXTENSION(ARB_texture_cube_map
, cap
);
597 if (!enable_texture(ctx
, state
, TEXTURE_CUBE_BIT
)) {
602 /* GL_ARB_multisample */
603 case GL_MULTISAMPLE_ARB
:
604 if (ctx
->Multisample
.Enabled
== state
)
606 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
607 ctx
->Multisample
.Enabled
= state
;
609 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
610 if (ctx
->Multisample
.SampleAlphaToCoverage
== state
)
612 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
613 ctx
->Multisample
.SampleAlphaToCoverage
= state
;
615 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
616 if (ctx
->Multisample
.SampleAlphaToOne
== state
)
618 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
619 ctx
->Multisample
.SampleAlphaToOne
= state
;
621 case GL_SAMPLE_COVERAGE_ARB
:
622 if (ctx
->Multisample
.SampleCoverage
== state
)
624 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
625 ctx
->Multisample
.SampleCoverage
= state
;
627 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
628 if (ctx
->Multisample
.SampleCoverageInvert
== state
)
630 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
631 ctx
->Multisample
.SampleCoverageInvert
= state
;
634 /* GL_IBM_rasterpos_clip */
635 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
636 CHECK_EXTENSION(IBM_rasterpos_clip
, cap
);
637 if (ctx
->Transform
.RasterPositionUnclipped
== state
)
639 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
640 ctx
->Transform
.RasterPositionUnclipped
= state
;
643 /* GL_NV_point_sprite */
644 case GL_POINT_SPRITE_NV
:
645 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
, cap
);
646 if (ctx
->Point
.PointSprite
== state
)
648 FLUSH_VERTICES(ctx
, _NEW_POINT
);
649 ctx
->Point
.PointSprite
= state
;
652 /* GL_EXT_depth_bounds_test */
653 case GL_DEPTH_BOUNDS_TEST_EXT
:
654 CHECK_EXTENSION(EXT_depth_bounds_test
, cap
);
655 if (ctx
->Depth
.BoundsTest
== state
)
657 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
658 ctx
->Depth
.BoundsTest
= state
;
662 goto invalid_enum_error
;
665 if (ctx
->Driver
.Enable
) {
666 ctx
->Driver
.Enable( ctx
, cap
, state
);
672 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%s(0x%x)",
673 state
? "Enable" : "Disable", cap
);
678 * Enable GL capability. Called by glEnable()
679 * \param cap state to enable.
682 _mesa_Enable( GLenum cap
)
684 GET_CURRENT_CONTEXT(ctx
);
685 ASSERT_OUTSIDE_BEGIN_END(ctx
);
687 _mesa_set_enable( ctx
, cap
, GL_TRUE
);
692 * Disable GL capability. Called by glDisable()
693 * \param cap state to disable.
696 _mesa_Disable( GLenum cap
)
698 GET_CURRENT_CONTEXT(ctx
);
699 ASSERT_OUTSIDE_BEGIN_END(ctx
);
701 _mesa_set_enable( ctx
, cap
, GL_FALSE
);
705 #undef CHECK_EXTENSION
706 #define CHECK_EXTENSION(EXTNAME) \
707 if (!ctx->Extensions.EXTNAME) { \
708 goto invalid_enum_error; \
711 #undef CHECK_EXTENSION2
712 #define CHECK_EXTENSION2(EXT1, EXT2) \
713 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
714 goto invalid_enum_error; \
719 * Helper function to determine whether a texture target is enabled.
722 is_texture_enabled(struct gl_context
*ctx
, GLbitfield bit
)
724 const struct gl_texture_unit
*const texUnit
=
726 return (texUnit
->Enabled
& bit
) ? GL_TRUE
: GL_FALSE
;
731 * Return simple enable/disable state.
733 * \param cap state variable to query.
735 * Returns the state of the specified capability from the current GL context.
736 * For the capabilities associated with extensions verifies that those
737 * extensions are effectively present before reporting.
740 _mesa_IsEnabled( GLenum cap
)
742 GET_CURRENT_CONTEXT(ctx
);
743 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
747 return ctx
->Color
.AlphaEnabled
;
749 return ctx
->Eval
.AutoNormal
;
751 return ctx
->Color
.BlendEnabled
& 1; /* return state for buffer[0] */
752 case GL_CLIP_DISTANCE0
:
753 case GL_CLIP_DISTANCE1
:
754 case GL_CLIP_DISTANCE2
:
755 case GL_CLIP_DISTANCE3
:
756 case GL_CLIP_DISTANCE4
:
757 case GL_CLIP_DISTANCE5
:
758 case GL_CLIP_DISTANCE6
:
759 case GL_CLIP_DISTANCE7
: {
760 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
762 if (p
>= ctx
->Const
.MaxClipPlanes
)
763 goto invalid_enum_error
;
765 return (ctx
->Transform
.ClipPlanesEnabled
>> p
) & 1;
767 case GL_COLOR_MATERIAL
:
768 return ctx
->Light
.ColorMaterialEnabled
;
770 return ctx
->Polygon
.CullFlag
;
772 return ctx
->Depth
.Test
;
774 return ctx
->Color
.DitherFlag
;
776 return ctx
->Fog
.Enabled
;
778 return ctx
->Light
.Enabled
;
787 return ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
;
789 return ctx
->Line
.SmoothFlag
;
790 case GL_LINE_STIPPLE
:
791 return ctx
->Line
.StippleFlag
;
792 case GL_INDEX_LOGIC_OP
:
793 return ctx
->Color
.IndexLogicOpEnabled
;
794 case GL_COLOR_LOGIC_OP
:
795 return ctx
->Color
.ColorLogicOpEnabled
;
796 case GL_MAP1_COLOR_4
:
797 return ctx
->Eval
.Map1Color4
;
799 return ctx
->Eval
.Map1Index
;
801 return ctx
->Eval
.Map1Normal
;
802 case GL_MAP1_TEXTURE_COORD_1
:
803 return ctx
->Eval
.Map1TextureCoord1
;
804 case GL_MAP1_TEXTURE_COORD_2
:
805 return ctx
->Eval
.Map1TextureCoord2
;
806 case GL_MAP1_TEXTURE_COORD_3
:
807 return ctx
->Eval
.Map1TextureCoord3
;
808 case GL_MAP1_TEXTURE_COORD_4
:
809 return ctx
->Eval
.Map1TextureCoord4
;
810 case GL_MAP1_VERTEX_3
:
811 return ctx
->Eval
.Map1Vertex3
;
812 case GL_MAP1_VERTEX_4
:
813 return ctx
->Eval
.Map1Vertex4
;
814 case GL_MAP2_COLOR_4
:
815 return ctx
->Eval
.Map2Color4
;
817 return ctx
->Eval
.Map2Index
;
819 return ctx
->Eval
.Map2Normal
;
820 case GL_MAP2_TEXTURE_COORD_1
:
821 return ctx
->Eval
.Map2TextureCoord1
;
822 case GL_MAP2_TEXTURE_COORD_2
:
823 return ctx
->Eval
.Map2TextureCoord2
;
824 case GL_MAP2_TEXTURE_COORD_3
:
825 return ctx
->Eval
.Map2TextureCoord3
;
826 case GL_MAP2_TEXTURE_COORD_4
:
827 return ctx
->Eval
.Map2TextureCoord4
;
828 case GL_MAP2_VERTEX_3
:
829 return ctx
->Eval
.Map2Vertex3
;
830 case GL_MAP2_VERTEX_4
:
831 return ctx
->Eval
.Map2Vertex4
;
833 return ctx
->Transform
.Normalize
;
834 case GL_POINT_SMOOTH
:
835 return ctx
->Point
.SmoothFlag
;
836 case GL_POLYGON_SMOOTH
:
837 return ctx
->Polygon
.SmoothFlag
;
838 case GL_POLYGON_STIPPLE
:
839 return ctx
->Polygon
.StippleFlag
;
840 case GL_POLYGON_OFFSET_POINT
:
841 return ctx
->Polygon
.OffsetPoint
;
842 case GL_POLYGON_OFFSET_LINE
:
843 return ctx
->Polygon
.OffsetLine
;
844 case GL_POLYGON_OFFSET_FILL
:
845 return ctx
->Polygon
.OffsetFill
;
846 case GL_RESCALE_NORMAL_EXT
:
847 return ctx
->Transform
.RescaleNormals
;
848 case GL_SCISSOR_TEST
:
849 return ctx
->Scissor
.Enabled
;
850 case GL_STENCIL_TEST
:
851 return ctx
->Stencil
.Enabled
;
853 return is_texture_enabled(ctx
, TEXTURE_1D_BIT
);
855 return is_texture_enabled(ctx
, TEXTURE_2D_BIT
);
856 case GL_TEXTURE_GEN_S
:
857 case GL_TEXTURE_GEN_T
:
858 case GL_TEXTURE_GEN_R
:
859 case GL_TEXTURE_GEN_Q
:
861 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
863 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
864 return (texUnit
->TexGenEnabled
& coordBit
) ? GL_TRUE
: GL_FALSE
;
869 case GL_TEXTURE_GEN_STR_OES
:
871 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
873 return (texUnit
->TexGenEnabled
& STR_BITS
) == STR_BITS
874 ? GL_TRUE
: GL_FALSE
;
879 /* client-side state */
880 case GL_VERTEX_ARRAY
:
881 return (ctx
->Array
.VertexAttrib
[VERT_ATTRIB_POS
].Enabled
!= 0);
882 case GL_NORMAL_ARRAY
:
883 return (ctx
->Array
.VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
!= 0);
885 return (ctx
->Array
.VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
!= 0);
887 return (ctx
->Array
.VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
!= 0);
888 case GL_TEXTURE_COORD_ARRAY
:
889 return (ctx
->Array
.VertexAttrib
[VERT_ATTRIB_TEX
]
891 case GL_EDGE_FLAG_ARRAY
:
892 return (ctx
->Array
.VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
!= 0);
893 case GL_FOG_COORDINATE_ARRAY_EXT
:
894 CHECK_EXTENSION(EXT_fog_coord
);
895 return (ctx
->Array
.VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
!= 0);
896 case GL_SECONDARY_COLOR_ARRAY_EXT
:
897 CHECK_EXTENSION(EXT_secondary_color
);
898 return (ctx
->Array
.VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
!= 0);
899 #if FEATURE_point_size_array
900 case GL_POINT_SIZE_ARRAY_OES
:
901 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
!= 0);
904 /* GL_ARB_texture_cube_map */
905 case GL_TEXTURE_CUBE_MAP_ARB
:
906 CHECK_EXTENSION(ARB_texture_cube_map
);
907 return is_texture_enabled(ctx
, TEXTURE_CUBE_BIT
);
909 /* GL_ARB_multisample */
910 case GL_MULTISAMPLE_ARB
:
911 return ctx
->Multisample
.Enabled
;
912 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
913 return ctx
->Multisample
.SampleAlphaToCoverage
;
914 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
915 return ctx
->Multisample
.SampleAlphaToOne
;
916 case GL_SAMPLE_COVERAGE_ARB
:
917 return ctx
->Multisample
.SampleCoverage
;
918 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
919 return ctx
->Multisample
.SampleCoverageInvert
;
921 /* GL_IBM_rasterpos_clip */
922 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
923 CHECK_EXTENSION(IBM_rasterpos_clip
);
924 return ctx
->Transform
.RasterPositionUnclipped
;
926 /* GL_NV_point_sprite */
927 case GL_POINT_SPRITE_NV
:
928 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
)
929 return ctx
->Point
.PointSprite
;
931 /* GL_EXT_depth_bounds_test */
932 case GL_DEPTH_BOUNDS_TEST_EXT
:
933 CHECK_EXTENSION(EXT_depth_bounds_test
);
934 return ctx
->Depth
.BoundsTest
;
937 goto invalid_enum_error
;
943 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabled(0x%x)", (int) cap
);