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_COLOR
].Enabled
;
58 flag
= VERT_BIT_COLOR
;
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
;
78 goto invalid_enum_error
;
84 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
85 ctx
->Array
.NewState
|= flag
;
87 _ae_invalidate_state(ctx
, _NEW_ARRAY
);
92 ctx
->Array
._Enabled
|= flag
;
94 ctx
->Array
._Enabled
&= ~flag
;
96 if (ctx
->Driver
.Enable
) {
97 ctx
->Driver
.Enable( ctx
, cap
, state
);
103 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%sClientState(0x%x)",
104 state
? "Enable" : "Disable", cap
);
109 * Enable GL capability.
110 * \param cap state to enable/disable.
112 * Get's the current context, assures that we're outside glBegin()/glEnd() and
113 * calls client_state().
116 _mesa_EnableClientState( GLenum cap
)
118 GET_CURRENT_CONTEXT(ctx
);
119 ASSERT_OUTSIDE_BEGIN_END(ctx
);
120 client_state( ctx
, cap
, GL_TRUE
);
125 * Disable GL capability.
126 * \param cap state to enable/disable.
128 * Get's the current context, assures that we're outside glBegin()/glEnd() and
129 * calls client_state().
132 _mesa_DisableClientState( GLenum cap
)
134 GET_CURRENT_CONTEXT(ctx
);
135 ASSERT_OUTSIDE_BEGIN_END(ctx
);
136 client_state( ctx
, cap
, GL_FALSE
);
140 #undef CHECK_EXTENSION
141 #define CHECK_EXTENSION(EXTNAME, CAP) \
142 if (!ctx->Extensions.EXTNAME) { \
143 goto invalid_enum_error; \
146 #define CHECK_EXTENSION2(EXT1, EXT2, CAP) \
147 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
148 goto invalid_enum_error; \
154 * Return pointer to current texture unit for setting/getting coordinate
156 * Note that we'll set GL_INVALID_OPERATION and return NULL if the active
157 * texture unit is higher than the number of supported coordinate units.
159 static inline struct gl_texture_unit
*
160 get_texcoord_unit(struct gl_context
*ctx
)
162 return &ctx
->Texture
.Unit
;
167 * Helper function to enable or disable a texture target.
168 * \param bit one of the TEXTURE_x_BIT values
169 * \return GL_TRUE if state is changing or GL_FALSE if no change
172 enable_texture(struct gl_context
*ctx
, GLboolean state
, GLbitfield texBit
)
174 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
;
175 const GLbitfield newenabled
= state
176 ? (texUnit
->Enabled
| texBit
) : (texUnit
->Enabled
& ~texBit
);
178 if (texUnit
->Enabled
== newenabled
)
181 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
182 texUnit
->Enabled
= newenabled
;
188 * Helper function to enable or disable state.
190 * \param ctx GL context.
191 * \param cap the state to enable/disable
192 * \param state whether to enable or disable the specified capability.
194 * Updates the current context and flushes the vertices as needed. For
195 * capabilities associated with extensions it verifies that those extensions
196 * are effectivly present before updating. Notifies the driver via
197 * dd_function_table::Enable.
200 _mesa_set_enable(struct gl_context
*ctx
, GLenum cap
, GLboolean state
)
202 if (MESA_VERBOSE
& VERBOSE_API
)
203 _mesa_debug(ctx
, "%s %s (newstate is %x)\n",
204 state
? "glEnable" : "glDisable",
205 _mesa_lookup_enum_by_nr(cap
),
210 if (ctx
->Color
.AlphaEnabled
== state
)
212 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
213 ctx
->Color
.AlphaEnabled
= state
;
216 if (ctx
->Eval
.AutoNormal
== state
)
218 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
219 ctx
->Eval
.AutoNormal
= state
;
223 if (state
!= ctx
->Color
.BlendEnabled
) {
224 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
225 ctx
->Color
.BlendEnabled
= state
;
230 case GL_CLIP_DISTANCE0
:
231 case GL_CLIP_DISTANCE1
:
232 case GL_CLIP_DISTANCE2
:
233 case GL_CLIP_DISTANCE3
:
234 case GL_CLIP_DISTANCE4
:
235 case GL_CLIP_DISTANCE5
:
236 case GL_CLIP_DISTANCE6
:
237 case GL_CLIP_DISTANCE7
:
239 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
241 if (p
>= ctx
->Const
.MaxClipPlanes
)
242 goto invalid_enum_error
;
244 if ((ctx
->Transform
.ClipPlanesEnabled
& (1 << p
))
245 == ((GLuint
) state
<< p
))
248 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
251 ctx
->Transform
.ClipPlanesEnabled
|= (1 << p
);
252 _mesa_update_clip_plane(ctx
, p
);
255 ctx
->Transform
.ClipPlanesEnabled
&= ~(1 << p
);
260 case GL_COLOR_MATERIAL
:
261 if (ctx
->Light
.ColorMaterialEnabled
== state
)
263 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
264 FLUSH_CURRENT(ctx
, 0);
265 ctx
->Light
.ColorMaterialEnabled
= state
;
267 _mesa_update_color_material( ctx
,
268 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR
] );
272 if (ctx
->Polygon
.CullFlag
== state
)
274 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
275 ctx
->Polygon
.CullFlag
= state
;
278 if (ctx
->Depth
.Test
== state
)
280 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
281 ctx
->Depth
.Test
= state
;
284 if (ctx
->Color
.DitherFlag
== state
)
286 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
287 ctx
->Color
.DitherFlag
= state
;
290 if (ctx
->Fog
.Enabled
== state
)
292 FLUSH_VERTICES(ctx
, _NEW_FOG
);
293 ctx
->Fog
.Enabled
= state
;
303 if (ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
== state
)
305 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
306 ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
= state
;
308 insert_at_tail(&ctx
->Light
.EnabledList
,
309 &ctx
->Light
.Light
[cap
-GL_LIGHT0
]);
312 remove_from_list(&ctx
->Light
.Light
[cap
-GL_LIGHT0
]);
316 if (ctx
->Light
.Enabled
== state
)
318 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
319 ctx
->Light
.Enabled
= state
;
320 if (ctx
->Light
.Enabled
&& ctx
->Light
.Model
.TwoSide
)
321 ctx
->_TriangleCaps
|= DD_TRI_LIGHT_TWOSIDE
;
323 ctx
->_TriangleCaps
&= ~DD_TRI_LIGHT_TWOSIDE
;
326 if (ctx
->Line
.SmoothFlag
== state
)
328 FLUSH_VERTICES(ctx
, _NEW_LINE
);
329 ctx
->Line
.SmoothFlag
= state
;
330 ctx
->_TriangleCaps
^= DD_LINE_SMOOTH
;
332 case GL_LINE_STIPPLE
:
333 if (ctx
->Line
.StippleFlag
== state
)
335 FLUSH_VERTICES(ctx
, _NEW_LINE
);
336 ctx
->Line
.StippleFlag
= state
;
337 ctx
->_TriangleCaps
^= DD_LINE_STIPPLE
;
339 case GL_INDEX_LOGIC_OP
:
340 if (ctx
->Color
.IndexLogicOpEnabled
== state
)
342 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
343 ctx
->Color
.IndexLogicOpEnabled
= state
;
345 case GL_COLOR_LOGIC_OP
:
346 if (ctx
->Color
.ColorLogicOpEnabled
== state
)
348 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
349 ctx
->Color
.ColorLogicOpEnabled
= state
;
351 case GL_MAP1_COLOR_4
:
352 if (ctx
->Eval
.Map1Color4
== state
)
354 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
355 ctx
->Eval
.Map1Color4
= state
;
358 if (ctx
->Eval
.Map1Index
== state
)
360 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
361 ctx
->Eval
.Map1Index
= state
;
364 if (ctx
->Eval
.Map1Normal
== state
)
366 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
367 ctx
->Eval
.Map1Normal
= state
;
369 case GL_MAP1_TEXTURE_COORD_1
:
370 if (ctx
->Eval
.Map1TextureCoord1
== state
)
372 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
373 ctx
->Eval
.Map1TextureCoord1
= state
;
375 case GL_MAP1_TEXTURE_COORD_2
:
376 if (ctx
->Eval
.Map1TextureCoord2
== state
)
378 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
379 ctx
->Eval
.Map1TextureCoord2
= state
;
381 case GL_MAP1_TEXTURE_COORD_3
:
382 if (ctx
->Eval
.Map1TextureCoord3
== state
)
384 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
385 ctx
->Eval
.Map1TextureCoord3
= state
;
387 case GL_MAP1_TEXTURE_COORD_4
:
388 if (ctx
->Eval
.Map1TextureCoord4
== state
)
390 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
391 ctx
->Eval
.Map1TextureCoord4
= state
;
393 case GL_MAP1_VERTEX_3
:
394 if (ctx
->Eval
.Map1Vertex3
== state
)
396 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
397 ctx
->Eval
.Map1Vertex3
= state
;
399 case GL_MAP1_VERTEX_4
:
400 if (ctx
->Eval
.Map1Vertex4
== state
)
402 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
403 ctx
->Eval
.Map1Vertex4
= state
;
405 case GL_MAP2_COLOR_4
:
406 if (ctx
->Eval
.Map2Color4
== state
)
408 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
409 ctx
->Eval
.Map2Color4
= state
;
412 if (ctx
->Eval
.Map2Index
== state
)
414 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
415 ctx
->Eval
.Map2Index
= state
;
418 if (ctx
->Eval
.Map2Normal
== state
)
420 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
421 ctx
->Eval
.Map2Normal
= state
;
423 case GL_MAP2_TEXTURE_COORD_1
:
424 if (ctx
->Eval
.Map2TextureCoord1
== state
)
426 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
427 ctx
->Eval
.Map2TextureCoord1
= state
;
429 case GL_MAP2_TEXTURE_COORD_2
:
430 if (ctx
->Eval
.Map2TextureCoord2
== state
)
432 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
433 ctx
->Eval
.Map2TextureCoord2
= state
;
435 case GL_MAP2_TEXTURE_COORD_3
:
436 if (ctx
->Eval
.Map2TextureCoord3
== state
)
438 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
439 ctx
->Eval
.Map2TextureCoord3
= state
;
441 case GL_MAP2_TEXTURE_COORD_4
:
442 if (ctx
->Eval
.Map2TextureCoord4
== state
)
444 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
445 ctx
->Eval
.Map2TextureCoord4
= state
;
447 case GL_MAP2_VERTEX_3
:
448 if (ctx
->Eval
.Map2Vertex3
== state
)
450 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
451 ctx
->Eval
.Map2Vertex3
= state
;
453 case GL_MAP2_VERTEX_4
:
454 if (ctx
->Eval
.Map2Vertex4
== state
)
456 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
457 ctx
->Eval
.Map2Vertex4
= state
;
460 if (ctx
->Transform
.Normalize
== state
)
462 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
463 ctx
->Transform
.Normalize
= state
;
465 case GL_POINT_SMOOTH
:
466 if (ctx
->Point
.SmoothFlag
== state
)
468 FLUSH_VERTICES(ctx
, _NEW_POINT
);
469 ctx
->Point
.SmoothFlag
= state
;
470 ctx
->_TriangleCaps
^= DD_POINT_SMOOTH
;
472 case GL_POLYGON_SMOOTH
:
473 if (ctx
->Polygon
.SmoothFlag
== state
)
475 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
476 ctx
->Polygon
.SmoothFlag
= state
;
477 ctx
->_TriangleCaps
^= DD_TRI_SMOOTH
;
479 case GL_POLYGON_STIPPLE
:
480 if (ctx
->Polygon
.StippleFlag
== state
)
482 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
483 ctx
->Polygon
.StippleFlag
= state
;
484 ctx
->_TriangleCaps
^= DD_TRI_STIPPLE
;
486 case GL_POLYGON_OFFSET_POINT
:
487 if (ctx
->Polygon
.OffsetPoint
== state
)
489 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
490 ctx
->Polygon
.OffsetPoint
= state
;
492 case GL_POLYGON_OFFSET_LINE
:
493 if (ctx
->Polygon
.OffsetLine
== state
)
495 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
496 ctx
->Polygon
.OffsetLine
= state
;
498 case GL_POLYGON_OFFSET_FILL
:
499 if (ctx
->Polygon
.OffsetFill
== state
)
501 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
502 ctx
->Polygon
.OffsetFill
= state
;
504 case GL_RESCALE_NORMAL_EXT
:
505 if (ctx
->Transform
.RescaleNormals
== state
)
507 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
508 ctx
->Transform
.RescaleNormals
= state
;
510 case GL_SCISSOR_TEST
:
511 if (ctx
->Scissor
.Enabled
== state
)
513 FLUSH_VERTICES(ctx
, _NEW_SCISSOR
);
514 ctx
->Scissor
.Enabled
= state
;
516 case GL_STENCIL_TEST
:
517 if (ctx
->Stencil
.Enabled
== state
)
519 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
520 ctx
->Stencil
.Enabled
= state
;
523 if (!enable_texture(ctx
, state
, TEXTURE_1D_BIT
)) {
528 if (!enable_texture(ctx
, state
, TEXTURE_2D_BIT
)) {
532 case GL_TEXTURE_GEN_S
:
533 case GL_TEXTURE_GEN_T
:
534 case GL_TEXTURE_GEN_R
:
535 case GL_TEXTURE_GEN_Q
:
537 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
539 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
540 GLbitfield newenabled
= texUnit
->TexGenEnabled
& ~coordBit
;
542 newenabled
|= coordBit
;
543 if (texUnit
->TexGenEnabled
== newenabled
)
545 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
546 texUnit
->TexGenEnabled
= newenabled
;
552 case GL_TEXTURE_GEN_STR_OES
:
553 /* disable S, T, and R at the same time */
555 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
558 texUnit
->TexGenEnabled
& ~STR_BITS
;
560 newenabled
|= STR_BITS
;
561 if (texUnit
->TexGenEnabled
== newenabled
)
563 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
564 texUnit
->TexGenEnabled
= newenabled
;
570 /* client-side state */
571 case GL_VERTEX_ARRAY
:
572 case GL_NORMAL_ARRAY
:
575 case GL_TEXTURE_COORD_ARRAY
:
576 case GL_EDGE_FLAG_ARRAY
:
577 case GL_FOG_COORDINATE_ARRAY_EXT
:
578 case GL_SECONDARY_COLOR_ARRAY_EXT
:
579 case GL_POINT_SIZE_ARRAY_OES
:
580 client_state( ctx
, cap
, state
);
583 /* GL_ARB_texture_cube_map */
584 case GL_TEXTURE_CUBE_MAP_ARB
:
585 CHECK_EXTENSION(ARB_texture_cube_map
, cap
);
586 if (!enable_texture(ctx
, state
, TEXTURE_CUBE_BIT
)) {
591 /* GL_ARB_multisample */
592 case GL_MULTISAMPLE_ARB
:
593 if (ctx
->Multisample
.Enabled
== state
)
595 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
596 ctx
->Multisample
.Enabled
= state
;
598 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
599 if (ctx
->Multisample
.SampleAlphaToCoverage
== state
)
601 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
602 ctx
->Multisample
.SampleAlphaToCoverage
= state
;
604 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
605 if (ctx
->Multisample
.SampleAlphaToOne
== state
)
607 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
608 ctx
->Multisample
.SampleAlphaToOne
= state
;
610 case GL_SAMPLE_COVERAGE_ARB
:
611 if (ctx
->Multisample
.SampleCoverage
== state
)
613 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
614 ctx
->Multisample
.SampleCoverage
= state
;
616 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
617 if (ctx
->Multisample
.SampleCoverageInvert
== state
)
619 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
620 ctx
->Multisample
.SampleCoverageInvert
= state
;
623 /* GL_IBM_rasterpos_clip */
624 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
625 CHECK_EXTENSION(IBM_rasterpos_clip
, cap
);
626 if (ctx
->Transform
.RasterPositionUnclipped
== state
)
628 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
629 ctx
->Transform
.RasterPositionUnclipped
= state
;
632 /* GL_NV_point_sprite */
633 case GL_POINT_SPRITE_NV
:
634 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
, cap
);
635 if (ctx
->Point
.PointSprite
== state
)
637 FLUSH_VERTICES(ctx
, _NEW_POINT
);
638 ctx
->Point
.PointSprite
= state
;
641 /* GL_EXT_depth_bounds_test */
642 case GL_DEPTH_BOUNDS_TEST_EXT
:
643 CHECK_EXTENSION(EXT_depth_bounds_test
, cap
);
644 if (ctx
->Depth
.BoundsTest
== state
)
646 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
647 ctx
->Depth
.BoundsTest
= state
;
651 goto invalid_enum_error
;
654 if (ctx
->Driver
.Enable
) {
655 ctx
->Driver
.Enable( ctx
, cap
, state
);
661 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%s(0x%x)",
662 state
? "Enable" : "Disable", cap
);
667 * Enable GL capability. Called by glEnable()
668 * \param cap state to enable.
671 _mesa_Enable( GLenum cap
)
673 GET_CURRENT_CONTEXT(ctx
);
674 ASSERT_OUTSIDE_BEGIN_END(ctx
);
676 _mesa_set_enable( ctx
, cap
, GL_TRUE
);
681 * Disable GL capability. Called by glDisable()
682 * \param cap state to disable.
685 _mesa_Disable( GLenum cap
)
687 GET_CURRENT_CONTEXT(ctx
);
688 ASSERT_OUTSIDE_BEGIN_END(ctx
);
690 _mesa_set_enable( ctx
, cap
, GL_FALSE
);
694 #undef CHECK_EXTENSION
695 #define CHECK_EXTENSION(EXTNAME) \
696 if (!ctx->Extensions.EXTNAME) { \
697 goto invalid_enum_error; \
700 #undef CHECK_EXTENSION2
701 #define CHECK_EXTENSION2(EXT1, EXT2) \
702 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
703 goto invalid_enum_error; \
708 * Helper function to determine whether a texture target is enabled.
711 is_texture_enabled(struct gl_context
*ctx
, GLbitfield bit
)
713 const struct gl_texture_unit
*const texUnit
=
715 return (texUnit
->Enabled
& bit
) ? GL_TRUE
: GL_FALSE
;
720 * Return simple enable/disable state.
722 * \param cap state variable to query.
724 * Returns the state of the specified capability from the current GL context.
725 * For the capabilities associated with extensions verifies that those
726 * extensions are effectively present before reporting.
729 _mesa_IsEnabled( GLenum cap
)
731 GET_CURRENT_CONTEXT(ctx
);
732 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
736 return ctx
->Color
.AlphaEnabled
;
738 return ctx
->Eval
.AutoNormal
;
740 return ctx
->Color
.BlendEnabled
& 1; /* return state for buffer[0] */
741 case GL_CLIP_DISTANCE0
:
742 case GL_CLIP_DISTANCE1
:
743 case GL_CLIP_DISTANCE2
:
744 case GL_CLIP_DISTANCE3
:
745 case GL_CLIP_DISTANCE4
:
746 case GL_CLIP_DISTANCE5
:
747 case GL_CLIP_DISTANCE6
:
748 case GL_CLIP_DISTANCE7
: {
749 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
751 if (p
>= ctx
->Const
.MaxClipPlanes
)
752 goto invalid_enum_error
;
754 return (ctx
->Transform
.ClipPlanesEnabled
>> p
) & 1;
756 case GL_COLOR_MATERIAL
:
757 return ctx
->Light
.ColorMaterialEnabled
;
759 return ctx
->Polygon
.CullFlag
;
761 return ctx
->Depth
.Test
;
763 return ctx
->Color
.DitherFlag
;
765 return ctx
->Fog
.Enabled
;
767 return ctx
->Light
.Enabled
;
776 return ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
;
778 return ctx
->Line
.SmoothFlag
;
779 case GL_LINE_STIPPLE
:
780 return ctx
->Line
.StippleFlag
;
781 case GL_INDEX_LOGIC_OP
:
782 return ctx
->Color
.IndexLogicOpEnabled
;
783 case GL_COLOR_LOGIC_OP
:
784 return ctx
->Color
.ColorLogicOpEnabled
;
785 case GL_MAP1_COLOR_4
:
786 return ctx
->Eval
.Map1Color4
;
788 return ctx
->Eval
.Map1Index
;
790 return ctx
->Eval
.Map1Normal
;
791 case GL_MAP1_TEXTURE_COORD_1
:
792 return ctx
->Eval
.Map1TextureCoord1
;
793 case GL_MAP1_TEXTURE_COORD_2
:
794 return ctx
->Eval
.Map1TextureCoord2
;
795 case GL_MAP1_TEXTURE_COORD_3
:
796 return ctx
->Eval
.Map1TextureCoord3
;
797 case GL_MAP1_TEXTURE_COORD_4
:
798 return ctx
->Eval
.Map1TextureCoord4
;
799 case GL_MAP1_VERTEX_3
:
800 return ctx
->Eval
.Map1Vertex3
;
801 case GL_MAP1_VERTEX_4
:
802 return ctx
->Eval
.Map1Vertex4
;
803 case GL_MAP2_COLOR_4
:
804 return ctx
->Eval
.Map2Color4
;
806 return ctx
->Eval
.Map2Index
;
808 return ctx
->Eval
.Map2Normal
;
809 case GL_MAP2_TEXTURE_COORD_1
:
810 return ctx
->Eval
.Map2TextureCoord1
;
811 case GL_MAP2_TEXTURE_COORD_2
:
812 return ctx
->Eval
.Map2TextureCoord2
;
813 case GL_MAP2_TEXTURE_COORD_3
:
814 return ctx
->Eval
.Map2TextureCoord3
;
815 case GL_MAP2_TEXTURE_COORD_4
:
816 return ctx
->Eval
.Map2TextureCoord4
;
817 case GL_MAP2_VERTEX_3
:
818 return ctx
->Eval
.Map2Vertex3
;
819 case GL_MAP2_VERTEX_4
:
820 return ctx
->Eval
.Map2Vertex4
;
822 return ctx
->Transform
.Normalize
;
823 case GL_POINT_SMOOTH
:
824 return ctx
->Point
.SmoothFlag
;
825 case GL_POLYGON_SMOOTH
:
826 return ctx
->Polygon
.SmoothFlag
;
827 case GL_POLYGON_STIPPLE
:
828 return ctx
->Polygon
.StippleFlag
;
829 case GL_POLYGON_OFFSET_POINT
:
830 return ctx
->Polygon
.OffsetPoint
;
831 case GL_POLYGON_OFFSET_LINE
:
832 return ctx
->Polygon
.OffsetLine
;
833 case GL_POLYGON_OFFSET_FILL
:
834 return ctx
->Polygon
.OffsetFill
;
835 case GL_RESCALE_NORMAL_EXT
:
836 return ctx
->Transform
.RescaleNormals
;
837 case GL_SCISSOR_TEST
:
838 return ctx
->Scissor
.Enabled
;
839 case GL_STENCIL_TEST
:
840 return ctx
->Stencil
.Enabled
;
842 return is_texture_enabled(ctx
, TEXTURE_1D_BIT
);
844 return is_texture_enabled(ctx
, TEXTURE_2D_BIT
);
845 case GL_TEXTURE_GEN_S
:
846 case GL_TEXTURE_GEN_T
:
847 case GL_TEXTURE_GEN_R
:
848 case GL_TEXTURE_GEN_Q
:
850 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
852 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
853 return (texUnit
->TexGenEnabled
& coordBit
) ? GL_TRUE
: GL_FALSE
;
858 case GL_TEXTURE_GEN_STR_OES
:
860 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
862 return (texUnit
->TexGenEnabled
& STR_BITS
) == STR_BITS
863 ? GL_TRUE
: GL_FALSE
;
868 /* client-side state */
869 case GL_VERTEX_ARRAY
:
870 return (ctx
->Array
.VertexAttrib
[VERT_ATTRIB_POS
].Enabled
!= 0);
871 case GL_NORMAL_ARRAY
:
872 return (ctx
->Array
.VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
!= 0);
874 return (ctx
->Array
.VertexAttrib
[VERT_ATTRIB_COLOR
].Enabled
!= 0);
876 return (ctx
->Array
.VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
!= 0);
877 case GL_TEXTURE_COORD_ARRAY
:
878 return (ctx
->Array
.VertexAttrib
[VERT_ATTRIB_TEX
]
880 case GL_EDGE_FLAG_ARRAY
:
881 return (ctx
->Array
.VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
!= 0);
882 case GL_FOG_COORDINATE_ARRAY_EXT
:
883 CHECK_EXTENSION(EXT_fog_coord
);
884 return (ctx
->Array
.VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
!= 0);
885 #if FEATURE_point_size_array
886 case GL_POINT_SIZE_ARRAY_OES
:
887 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
!= 0);
890 /* GL_ARB_texture_cube_map */
891 case GL_TEXTURE_CUBE_MAP_ARB
:
892 CHECK_EXTENSION(ARB_texture_cube_map
);
893 return is_texture_enabled(ctx
, TEXTURE_CUBE_BIT
);
895 /* GL_ARB_multisample */
896 case GL_MULTISAMPLE_ARB
:
897 return ctx
->Multisample
.Enabled
;
898 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
899 return ctx
->Multisample
.SampleAlphaToCoverage
;
900 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
901 return ctx
->Multisample
.SampleAlphaToOne
;
902 case GL_SAMPLE_COVERAGE_ARB
:
903 return ctx
->Multisample
.SampleCoverage
;
904 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
905 return ctx
->Multisample
.SampleCoverageInvert
;
907 /* GL_IBM_rasterpos_clip */
908 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
909 CHECK_EXTENSION(IBM_rasterpos_clip
);
910 return ctx
->Transform
.RasterPositionUnclipped
;
912 /* GL_NV_point_sprite */
913 case GL_POINT_SPRITE_NV
:
914 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
)
915 return ctx
->Point
.PointSprite
;
917 /* GL_EXT_depth_bounds_test */
918 case GL_DEPTH_BOUNDS_TEST_EXT
:
919 CHECK_EXTENSION(EXT_depth_bounds_test
);
920 return ctx
->Depth
.BoundsTest
;
923 goto invalid_enum_error
;
929 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabled(0x%x)", (int) cap
);