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
)
44 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
50 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
;
54 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
;
55 flag
= VERT_BIT_NORMAL
;
58 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
;
59 flag
= VERT_BIT_COLOR0
;
62 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
;
63 flag
= VERT_BIT_COLOR_INDEX
;
65 case GL_TEXTURE_COORD_ARRAY
:
66 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_TEX
].Enabled
;
69 case GL_EDGE_FLAG_ARRAY
:
70 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
;
71 flag
= VERT_BIT_EDGEFLAG
;
73 case GL_FOG_COORDINATE_ARRAY_EXT
:
74 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
;
77 case GL_SECONDARY_COLOR_ARRAY_EXT
:
78 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
;
79 flag
= VERT_BIT_COLOR1
;
82 #if FEATURE_point_size_array
83 case GL_POINT_SIZE_ARRAY_OES
:
84 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
;
85 flag
= VERT_BIT_POINT_SIZE
;
89 #if FEATURE_NV_vertex_program
90 case GL_VERTEX_ATTRIB_ARRAY0_NV
:
91 case GL_VERTEX_ATTRIB_ARRAY1_NV
:
92 case GL_VERTEX_ATTRIB_ARRAY2_NV
:
93 case GL_VERTEX_ATTRIB_ARRAY3_NV
:
94 case GL_VERTEX_ATTRIB_ARRAY4_NV
:
95 case GL_VERTEX_ATTRIB_ARRAY5_NV
:
96 case GL_VERTEX_ATTRIB_ARRAY6_NV
:
97 case GL_VERTEX_ATTRIB_ARRAY7_NV
:
98 case GL_VERTEX_ATTRIB_ARRAY8_NV
:
99 case GL_VERTEX_ATTRIB_ARRAY9_NV
:
100 case GL_VERTEX_ATTRIB_ARRAY10_NV
:
101 case GL_VERTEX_ATTRIB_ARRAY11_NV
:
102 case GL_VERTEX_ATTRIB_ARRAY12_NV
:
103 case GL_VERTEX_ATTRIB_ARRAY13_NV
:
104 case GL_VERTEX_ATTRIB_ARRAY14_NV
:
105 case GL_VERTEX_ATTRIB_ARRAY15_NV
:
106 CHECK_EXTENSION(NV_vertex_program
, cap
);
108 GLint n
= (GLint
) cap
- GL_VERTEX_ATTRIB_ARRAY0_NV
;
109 ASSERT(VERT_ATTRIB_GENERIC(n
) < Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
110 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(n
)].Enabled
;
111 flag
= VERT_BIT_GENERIC(n
);
114 #endif /* FEATURE_NV_vertex_program */
117 goto invalid_enum_error
;
123 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
124 ctx
->Array
.NewState
|= flag
;
126 _ae_invalidate_state(ctx
, _NEW_ARRAY
);
131 ctx
->Array
.ArrayObj
->_Enabled
|= flag
;
133 ctx
->Array
.ArrayObj
->_Enabled
&= ~flag
;
135 if (ctx
->Driver
.Enable
) {
136 ctx
->Driver
.Enable( ctx
, cap
, state
);
142 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%sClientState(0x%x)",
143 state
? "Enable" : "Disable", cap
);
148 * Enable GL capability.
149 * \param cap state to enable/disable.
151 * Get's the current context, assures that we're outside glBegin()/glEnd() and
152 * calls client_state().
155 _mesa_EnableClientState( GLenum cap
)
157 GET_CURRENT_CONTEXT(ctx
);
158 ASSERT_OUTSIDE_BEGIN_END(ctx
);
159 client_state( ctx
, cap
, GL_TRUE
);
164 * Disable GL capability.
165 * \param cap state to enable/disable.
167 * Get's the current context, assures that we're outside glBegin()/glEnd() and
168 * calls client_state().
171 _mesa_DisableClientState( GLenum cap
)
173 GET_CURRENT_CONTEXT(ctx
);
174 ASSERT_OUTSIDE_BEGIN_END(ctx
);
175 client_state( ctx
, cap
, GL_FALSE
);
179 #undef CHECK_EXTENSION
180 #define CHECK_EXTENSION(EXTNAME, CAP) \
181 if (!ctx->Extensions.EXTNAME) { \
182 goto invalid_enum_error; \
185 #define CHECK_EXTENSION2(EXT1, EXT2, CAP) \
186 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
187 goto invalid_enum_error; \
193 * Return pointer to current texture unit for setting/getting coordinate
195 * Note that we'll set GL_INVALID_OPERATION and return NULL if the active
196 * texture unit is higher than the number of supported coordinate units.
198 static inline struct gl_texture_unit
*
199 get_texcoord_unit(struct gl_context
*ctx
)
201 return &ctx
->Texture
.Unit
;
206 * Helper function to enable or disable a texture target.
207 * \param bit one of the TEXTURE_x_BIT values
208 * \return GL_TRUE if state is changing or GL_FALSE if no change
211 enable_texture(struct gl_context
*ctx
, GLboolean state
, GLbitfield texBit
)
213 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
;
214 const GLbitfield newenabled
= state
215 ? (texUnit
->Enabled
| texBit
) : (texUnit
->Enabled
& ~texBit
);
217 if (texUnit
->Enabled
== newenabled
)
220 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
221 texUnit
->Enabled
= newenabled
;
227 * Helper function to enable or disable state.
229 * \param ctx GL context.
230 * \param cap the state to enable/disable
231 * \param state whether to enable or disable the specified capability.
233 * Updates the current context and flushes the vertices as needed. For
234 * capabilities associated with extensions it verifies that those extensions
235 * are effectivly present before updating. Notifies the driver via
236 * dd_function_table::Enable.
239 _mesa_set_enable(struct gl_context
*ctx
, GLenum cap
, GLboolean state
)
241 if (MESA_VERBOSE
& VERBOSE_API
)
242 _mesa_debug(ctx
, "%s %s (newstate is %x)\n",
243 state
? "glEnable" : "glDisable",
244 _mesa_lookup_enum_by_nr(cap
),
249 if (ctx
->Color
.AlphaEnabled
== state
)
251 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
252 ctx
->Color
.AlphaEnabled
= state
;
255 if (ctx
->Eval
.AutoNormal
== state
)
257 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
258 ctx
->Eval
.AutoNormal
= state
;
262 if (state
!= ctx
->Color
.BlendEnabled
) {
263 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
264 ctx
->Color
.BlendEnabled
= state
;
269 case GL_CLIP_DISTANCE0
:
270 case GL_CLIP_DISTANCE1
:
271 case GL_CLIP_DISTANCE2
:
272 case GL_CLIP_DISTANCE3
:
273 case GL_CLIP_DISTANCE4
:
274 case GL_CLIP_DISTANCE5
:
275 case GL_CLIP_DISTANCE6
:
276 case GL_CLIP_DISTANCE7
:
278 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
280 if (p
>= ctx
->Const
.MaxClipPlanes
)
281 goto invalid_enum_error
;
283 if ((ctx
->Transform
.ClipPlanesEnabled
& (1 << p
))
284 == ((GLuint
) state
<< p
))
287 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
290 ctx
->Transform
.ClipPlanesEnabled
|= (1 << p
);
291 _mesa_update_clip_plane(ctx
, p
);
294 ctx
->Transform
.ClipPlanesEnabled
&= ~(1 << p
);
299 case GL_COLOR_MATERIAL
:
300 if (ctx
->Light
.ColorMaterialEnabled
== state
)
302 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
303 FLUSH_CURRENT(ctx
, 0);
304 ctx
->Light
.ColorMaterialEnabled
= state
;
306 _mesa_update_color_material( ctx
,
307 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
] );
311 if (ctx
->Polygon
.CullFlag
== state
)
313 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
314 ctx
->Polygon
.CullFlag
= state
;
317 if (ctx
->Depth
.Test
== state
)
319 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
320 ctx
->Depth
.Test
= state
;
323 if (ctx
->Color
.DitherFlag
== state
)
325 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
326 ctx
->Color
.DitherFlag
= state
;
329 if (ctx
->Fog
.Enabled
== state
)
331 FLUSH_VERTICES(ctx
, _NEW_FOG
);
332 ctx
->Fog
.Enabled
= state
;
342 if (ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
== state
)
344 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
345 ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
= state
;
347 insert_at_tail(&ctx
->Light
.EnabledList
,
348 &ctx
->Light
.Light
[cap
-GL_LIGHT0
]);
351 remove_from_list(&ctx
->Light
.Light
[cap
-GL_LIGHT0
]);
355 if (ctx
->Light
.Enabled
== state
)
357 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
358 ctx
->Light
.Enabled
= state
;
359 if (ctx
->Light
.Enabled
&& ctx
->Light
.Model
.TwoSide
)
360 ctx
->_TriangleCaps
|= DD_TRI_LIGHT_TWOSIDE
;
362 ctx
->_TriangleCaps
&= ~DD_TRI_LIGHT_TWOSIDE
;
365 if (ctx
->Line
.SmoothFlag
== state
)
367 FLUSH_VERTICES(ctx
, _NEW_LINE
);
368 ctx
->Line
.SmoothFlag
= state
;
369 ctx
->_TriangleCaps
^= DD_LINE_SMOOTH
;
371 case GL_LINE_STIPPLE
:
372 if (ctx
->Line
.StippleFlag
== state
)
374 FLUSH_VERTICES(ctx
, _NEW_LINE
);
375 ctx
->Line
.StippleFlag
= state
;
376 ctx
->_TriangleCaps
^= DD_LINE_STIPPLE
;
378 case GL_INDEX_LOGIC_OP
:
379 if (ctx
->Color
.IndexLogicOpEnabled
== state
)
381 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
382 ctx
->Color
.IndexLogicOpEnabled
= state
;
384 case GL_COLOR_LOGIC_OP
:
385 if (ctx
->Color
.ColorLogicOpEnabled
== state
)
387 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
388 ctx
->Color
.ColorLogicOpEnabled
= state
;
390 case GL_MAP1_COLOR_4
:
391 if (ctx
->Eval
.Map1Color4
== state
)
393 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
394 ctx
->Eval
.Map1Color4
= state
;
397 if (ctx
->Eval
.Map1Index
== state
)
399 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
400 ctx
->Eval
.Map1Index
= state
;
403 if (ctx
->Eval
.Map1Normal
== state
)
405 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
406 ctx
->Eval
.Map1Normal
= state
;
408 case GL_MAP1_TEXTURE_COORD_1
:
409 if (ctx
->Eval
.Map1TextureCoord1
== state
)
411 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
412 ctx
->Eval
.Map1TextureCoord1
= state
;
414 case GL_MAP1_TEXTURE_COORD_2
:
415 if (ctx
->Eval
.Map1TextureCoord2
== state
)
417 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
418 ctx
->Eval
.Map1TextureCoord2
= state
;
420 case GL_MAP1_TEXTURE_COORD_3
:
421 if (ctx
->Eval
.Map1TextureCoord3
== state
)
423 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
424 ctx
->Eval
.Map1TextureCoord3
= state
;
426 case GL_MAP1_TEXTURE_COORD_4
:
427 if (ctx
->Eval
.Map1TextureCoord4
== state
)
429 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
430 ctx
->Eval
.Map1TextureCoord4
= state
;
432 case GL_MAP1_VERTEX_3
:
433 if (ctx
->Eval
.Map1Vertex3
== state
)
435 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
436 ctx
->Eval
.Map1Vertex3
= state
;
438 case GL_MAP1_VERTEX_4
:
439 if (ctx
->Eval
.Map1Vertex4
== state
)
441 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
442 ctx
->Eval
.Map1Vertex4
= state
;
444 case GL_MAP2_COLOR_4
:
445 if (ctx
->Eval
.Map2Color4
== state
)
447 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
448 ctx
->Eval
.Map2Color4
= state
;
451 if (ctx
->Eval
.Map2Index
== state
)
453 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
454 ctx
->Eval
.Map2Index
= state
;
457 if (ctx
->Eval
.Map2Normal
== state
)
459 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
460 ctx
->Eval
.Map2Normal
= state
;
462 case GL_MAP2_TEXTURE_COORD_1
:
463 if (ctx
->Eval
.Map2TextureCoord1
== state
)
465 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
466 ctx
->Eval
.Map2TextureCoord1
= state
;
468 case GL_MAP2_TEXTURE_COORD_2
:
469 if (ctx
->Eval
.Map2TextureCoord2
== state
)
471 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
472 ctx
->Eval
.Map2TextureCoord2
= state
;
474 case GL_MAP2_TEXTURE_COORD_3
:
475 if (ctx
->Eval
.Map2TextureCoord3
== state
)
477 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
478 ctx
->Eval
.Map2TextureCoord3
= state
;
480 case GL_MAP2_TEXTURE_COORD_4
:
481 if (ctx
->Eval
.Map2TextureCoord4
== state
)
483 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
484 ctx
->Eval
.Map2TextureCoord4
= state
;
486 case GL_MAP2_VERTEX_3
:
487 if (ctx
->Eval
.Map2Vertex3
== state
)
489 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
490 ctx
->Eval
.Map2Vertex3
= state
;
492 case GL_MAP2_VERTEX_4
:
493 if (ctx
->Eval
.Map2Vertex4
== state
)
495 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
496 ctx
->Eval
.Map2Vertex4
= state
;
499 if (ctx
->Transform
.Normalize
== state
)
501 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
502 ctx
->Transform
.Normalize
= state
;
504 case GL_POINT_SMOOTH
:
505 if (ctx
->Point
.SmoothFlag
== state
)
507 FLUSH_VERTICES(ctx
, _NEW_POINT
);
508 ctx
->Point
.SmoothFlag
= state
;
509 ctx
->_TriangleCaps
^= DD_POINT_SMOOTH
;
511 case GL_POLYGON_SMOOTH
:
512 if (ctx
->Polygon
.SmoothFlag
== state
)
514 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
515 ctx
->Polygon
.SmoothFlag
= state
;
516 ctx
->_TriangleCaps
^= DD_TRI_SMOOTH
;
518 case GL_POLYGON_STIPPLE
:
519 if (ctx
->Polygon
.StippleFlag
== state
)
521 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
522 ctx
->Polygon
.StippleFlag
= state
;
523 ctx
->_TriangleCaps
^= DD_TRI_STIPPLE
;
525 case GL_POLYGON_OFFSET_POINT
:
526 if (ctx
->Polygon
.OffsetPoint
== state
)
528 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
529 ctx
->Polygon
.OffsetPoint
= state
;
531 case GL_POLYGON_OFFSET_LINE
:
532 if (ctx
->Polygon
.OffsetLine
== state
)
534 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
535 ctx
->Polygon
.OffsetLine
= state
;
537 case GL_POLYGON_OFFSET_FILL
:
538 if (ctx
->Polygon
.OffsetFill
== state
)
540 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
541 ctx
->Polygon
.OffsetFill
= state
;
543 case GL_RESCALE_NORMAL_EXT
:
544 if (ctx
->Transform
.RescaleNormals
== state
)
546 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
547 ctx
->Transform
.RescaleNormals
= state
;
549 case GL_SCISSOR_TEST
:
550 if (ctx
->Scissor
.Enabled
== state
)
552 FLUSH_VERTICES(ctx
, _NEW_SCISSOR
);
553 ctx
->Scissor
.Enabled
= state
;
555 case GL_STENCIL_TEST
:
556 if (ctx
->Stencil
.Enabled
== state
)
558 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
559 ctx
->Stencil
.Enabled
= state
;
562 if (!enable_texture(ctx
, state
, TEXTURE_1D_BIT
)) {
567 if (!enable_texture(ctx
, state
, TEXTURE_2D_BIT
)) {
571 case GL_TEXTURE_GEN_S
:
572 case GL_TEXTURE_GEN_T
:
573 case GL_TEXTURE_GEN_R
:
574 case GL_TEXTURE_GEN_Q
:
576 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
578 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
579 GLbitfield newenabled
= texUnit
->TexGenEnabled
& ~coordBit
;
581 newenabled
|= coordBit
;
582 if (texUnit
->TexGenEnabled
== newenabled
)
584 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
585 texUnit
->TexGenEnabled
= newenabled
;
591 case GL_TEXTURE_GEN_STR_OES
:
592 /* disable S, T, and R at the same time */
594 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
597 texUnit
->TexGenEnabled
& ~STR_BITS
;
599 newenabled
|= STR_BITS
;
600 if (texUnit
->TexGenEnabled
== newenabled
)
602 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
603 texUnit
->TexGenEnabled
= newenabled
;
609 /* client-side state */
610 case GL_VERTEX_ARRAY
:
611 case GL_NORMAL_ARRAY
:
614 case GL_TEXTURE_COORD_ARRAY
:
615 case GL_EDGE_FLAG_ARRAY
:
616 case GL_FOG_COORDINATE_ARRAY_EXT
:
617 case GL_SECONDARY_COLOR_ARRAY_EXT
:
618 case GL_POINT_SIZE_ARRAY_OES
:
619 client_state( ctx
, cap
, state
);
622 /* GL_ARB_texture_cube_map */
623 case GL_TEXTURE_CUBE_MAP_ARB
:
624 CHECK_EXTENSION(ARB_texture_cube_map
, cap
);
625 if (!enable_texture(ctx
, state
, TEXTURE_CUBE_BIT
)) {
630 /* GL_ARB_multisample */
631 case GL_MULTISAMPLE_ARB
:
632 if (ctx
->Multisample
.Enabled
== state
)
634 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
635 ctx
->Multisample
.Enabled
= state
;
637 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
638 if (ctx
->Multisample
.SampleAlphaToCoverage
== state
)
640 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
641 ctx
->Multisample
.SampleAlphaToCoverage
= state
;
643 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
644 if (ctx
->Multisample
.SampleAlphaToOne
== state
)
646 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
647 ctx
->Multisample
.SampleAlphaToOne
= state
;
649 case GL_SAMPLE_COVERAGE_ARB
:
650 if (ctx
->Multisample
.SampleCoverage
== state
)
652 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
653 ctx
->Multisample
.SampleCoverage
= state
;
655 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
656 if (ctx
->Multisample
.SampleCoverageInvert
== state
)
658 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
659 ctx
->Multisample
.SampleCoverageInvert
= state
;
662 /* GL_IBM_rasterpos_clip */
663 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
664 CHECK_EXTENSION(IBM_rasterpos_clip
, cap
);
665 if (ctx
->Transform
.RasterPositionUnclipped
== state
)
667 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
668 ctx
->Transform
.RasterPositionUnclipped
= state
;
671 /* GL_NV_point_sprite */
672 case GL_POINT_SPRITE_NV
:
673 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
, cap
);
674 if (ctx
->Point
.PointSprite
== state
)
676 FLUSH_VERTICES(ctx
, _NEW_POINT
);
677 ctx
->Point
.PointSprite
= state
;
680 /* GL_EXT_depth_bounds_test */
681 case GL_DEPTH_BOUNDS_TEST_EXT
:
682 CHECK_EXTENSION(EXT_depth_bounds_test
, cap
);
683 if (ctx
->Depth
.BoundsTest
== state
)
685 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
686 ctx
->Depth
.BoundsTest
= state
;
690 goto invalid_enum_error
;
693 if (ctx
->Driver
.Enable
) {
694 ctx
->Driver
.Enable( ctx
, cap
, state
);
700 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%s(0x%x)",
701 state
? "Enable" : "Disable", cap
);
706 * Enable GL capability. Called by glEnable()
707 * \param cap state to enable.
710 _mesa_Enable( GLenum cap
)
712 GET_CURRENT_CONTEXT(ctx
);
713 ASSERT_OUTSIDE_BEGIN_END(ctx
);
715 _mesa_set_enable( ctx
, cap
, GL_TRUE
);
720 * Disable GL capability. Called by glDisable()
721 * \param cap state to disable.
724 _mesa_Disable( GLenum cap
)
726 GET_CURRENT_CONTEXT(ctx
);
727 ASSERT_OUTSIDE_BEGIN_END(ctx
);
729 _mesa_set_enable( ctx
, cap
, GL_FALSE
);
733 #undef CHECK_EXTENSION
734 #define CHECK_EXTENSION(EXTNAME) \
735 if (!ctx->Extensions.EXTNAME) { \
736 goto invalid_enum_error; \
739 #undef CHECK_EXTENSION2
740 #define CHECK_EXTENSION2(EXT1, EXT2) \
741 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
742 goto invalid_enum_error; \
747 * Helper function to determine whether a texture target is enabled.
750 is_texture_enabled(struct gl_context
*ctx
, GLbitfield bit
)
752 const struct gl_texture_unit
*const texUnit
=
754 return (texUnit
->Enabled
& bit
) ? GL_TRUE
: GL_FALSE
;
759 * Return simple enable/disable state.
761 * \param cap state variable to query.
763 * Returns the state of the specified capability from the current GL context.
764 * For the capabilities associated with extensions verifies that those
765 * extensions are effectively present before reporting.
768 _mesa_IsEnabled( GLenum cap
)
770 GET_CURRENT_CONTEXT(ctx
);
771 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
775 return ctx
->Color
.AlphaEnabled
;
777 return ctx
->Eval
.AutoNormal
;
779 return ctx
->Color
.BlendEnabled
& 1; /* return state for buffer[0] */
780 case GL_CLIP_DISTANCE0
:
781 case GL_CLIP_DISTANCE1
:
782 case GL_CLIP_DISTANCE2
:
783 case GL_CLIP_DISTANCE3
:
784 case GL_CLIP_DISTANCE4
:
785 case GL_CLIP_DISTANCE5
:
786 case GL_CLIP_DISTANCE6
:
787 case GL_CLIP_DISTANCE7
: {
788 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
790 if (p
>= ctx
->Const
.MaxClipPlanes
)
791 goto invalid_enum_error
;
793 return (ctx
->Transform
.ClipPlanesEnabled
>> p
) & 1;
795 case GL_COLOR_MATERIAL
:
796 return ctx
->Light
.ColorMaterialEnabled
;
798 return ctx
->Polygon
.CullFlag
;
800 return ctx
->Depth
.Test
;
802 return ctx
->Color
.DitherFlag
;
804 return ctx
->Fog
.Enabled
;
806 return ctx
->Light
.Enabled
;
815 return ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
;
817 return ctx
->Line
.SmoothFlag
;
818 case GL_LINE_STIPPLE
:
819 return ctx
->Line
.StippleFlag
;
820 case GL_INDEX_LOGIC_OP
:
821 return ctx
->Color
.IndexLogicOpEnabled
;
822 case GL_COLOR_LOGIC_OP
:
823 return ctx
->Color
.ColorLogicOpEnabled
;
824 case GL_MAP1_COLOR_4
:
825 return ctx
->Eval
.Map1Color4
;
827 return ctx
->Eval
.Map1Index
;
829 return ctx
->Eval
.Map1Normal
;
830 case GL_MAP1_TEXTURE_COORD_1
:
831 return ctx
->Eval
.Map1TextureCoord1
;
832 case GL_MAP1_TEXTURE_COORD_2
:
833 return ctx
->Eval
.Map1TextureCoord2
;
834 case GL_MAP1_TEXTURE_COORD_3
:
835 return ctx
->Eval
.Map1TextureCoord3
;
836 case GL_MAP1_TEXTURE_COORD_4
:
837 return ctx
->Eval
.Map1TextureCoord4
;
838 case GL_MAP1_VERTEX_3
:
839 return ctx
->Eval
.Map1Vertex3
;
840 case GL_MAP1_VERTEX_4
:
841 return ctx
->Eval
.Map1Vertex4
;
842 case GL_MAP2_COLOR_4
:
843 return ctx
->Eval
.Map2Color4
;
845 return ctx
->Eval
.Map2Index
;
847 return ctx
->Eval
.Map2Normal
;
848 case GL_MAP2_TEXTURE_COORD_1
:
849 return ctx
->Eval
.Map2TextureCoord1
;
850 case GL_MAP2_TEXTURE_COORD_2
:
851 return ctx
->Eval
.Map2TextureCoord2
;
852 case GL_MAP2_TEXTURE_COORD_3
:
853 return ctx
->Eval
.Map2TextureCoord3
;
854 case GL_MAP2_TEXTURE_COORD_4
:
855 return ctx
->Eval
.Map2TextureCoord4
;
856 case GL_MAP2_VERTEX_3
:
857 return ctx
->Eval
.Map2Vertex3
;
858 case GL_MAP2_VERTEX_4
:
859 return ctx
->Eval
.Map2Vertex4
;
861 return ctx
->Transform
.Normalize
;
862 case GL_POINT_SMOOTH
:
863 return ctx
->Point
.SmoothFlag
;
864 case GL_POLYGON_SMOOTH
:
865 return ctx
->Polygon
.SmoothFlag
;
866 case GL_POLYGON_STIPPLE
:
867 return ctx
->Polygon
.StippleFlag
;
868 case GL_POLYGON_OFFSET_POINT
:
869 return ctx
->Polygon
.OffsetPoint
;
870 case GL_POLYGON_OFFSET_LINE
:
871 return ctx
->Polygon
.OffsetLine
;
872 case GL_POLYGON_OFFSET_FILL
:
873 return ctx
->Polygon
.OffsetFill
;
874 case GL_RESCALE_NORMAL_EXT
:
875 return ctx
->Transform
.RescaleNormals
;
876 case GL_SCISSOR_TEST
:
877 return ctx
->Scissor
.Enabled
;
878 case GL_STENCIL_TEST
:
879 return ctx
->Stencil
.Enabled
;
881 return is_texture_enabled(ctx
, TEXTURE_1D_BIT
);
883 return is_texture_enabled(ctx
, TEXTURE_2D_BIT
);
884 case GL_TEXTURE_GEN_S
:
885 case GL_TEXTURE_GEN_T
:
886 case GL_TEXTURE_GEN_R
:
887 case GL_TEXTURE_GEN_Q
:
889 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
891 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
892 return (texUnit
->TexGenEnabled
& coordBit
) ? GL_TRUE
: GL_FALSE
;
897 case GL_TEXTURE_GEN_STR_OES
:
899 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
901 return (texUnit
->TexGenEnabled
& STR_BITS
) == STR_BITS
902 ? GL_TRUE
: GL_FALSE
;
907 /* client-side state */
908 case GL_VERTEX_ARRAY
:
909 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
!= 0);
910 case GL_NORMAL_ARRAY
:
911 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
!= 0);
913 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
!= 0);
915 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
!= 0);
916 case GL_TEXTURE_COORD_ARRAY
:
917 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_TEX
]
919 case GL_EDGE_FLAG_ARRAY
:
920 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
!= 0);
921 case GL_FOG_COORDINATE_ARRAY_EXT
:
922 CHECK_EXTENSION(EXT_fog_coord
);
923 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
!= 0);
924 case GL_SECONDARY_COLOR_ARRAY_EXT
:
925 CHECK_EXTENSION(EXT_secondary_color
);
926 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
!= 0);
927 #if FEATURE_point_size_array
928 case GL_POINT_SIZE_ARRAY_OES
:
929 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
!= 0);
932 /* GL_ARB_texture_cube_map */
933 case GL_TEXTURE_CUBE_MAP_ARB
:
934 CHECK_EXTENSION(ARB_texture_cube_map
);
935 return is_texture_enabled(ctx
, TEXTURE_CUBE_BIT
);
937 /* GL_ARB_multisample */
938 case GL_MULTISAMPLE_ARB
:
939 return ctx
->Multisample
.Enabled
;
940 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
941 return ctx
->Multisample
.SampleAlphaToCoverage
;
942 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
943 return ctx
->Multisample
.SampleAlphaToOne
;
944 case GL_SAMPLE_COVERAGE_ARB
:
945 return ctx
->Multisample
.SampleCoverage
;
946 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
947 return ctx
->Multisample
.SampleCoverageInvert
;
949 /* GL_IBM_rasterpos_clip */
950 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
951 CHECK_EXTENSION(IBM_rasterpos_clip
);
952 return ctx
->Transform
.RasterPositionUnclipped
;
954 /* GL_NV_point_sprite */
955 case GL_POINT_SPRITE_NV
:
956 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
)
957 return ctx
->Point
.PointSprite
;
959 /* GL_EXT_depth_bounds_test */
960 case GL_DEPTH_BOUNDS_TEST_EXT
:
961 CHECK_EXTENSION(EXT_depth_bounds_test
);
962 return ctx
->Depth
.BoundsTest
;
965 goto invalid_enum_error
;
971 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabled(0x%x)", (int) cap
);