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
)) {
572 if (!enable_texture(ctx
, state
, TEXTURE_3D_BIT
)) {
576 case GL_TEXTURE_GEN_S
:
577 case GL_TEXTURE_GEN_T
:
578 case GL_TEXTURE_GEN_R
:
579 case GL_TEXTURE_GEN_Q
:
581 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
583 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
584 GLbitfield newenabled
= texUnit
->TexGenEnabled
& ~coordBit
;
586 newenabled
|= coordBit
;
587 if (texUnit
->TexGenEnabled
== newenabled
)
589 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
590 texUnit
->TexGenEnabled
= newenabled
;
596 case GL_TEXTURE_GEN_STR_OES
:
597 /* disable S, T, and R at the same time */
599 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
602 texUnit
->TexGenEnabled
& ~STR_BITS
;
604 newenabled
|= STR_BITS
;
605 if (texUnit
->TexGenEnabled
== newenabled
)
607 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
608 texUnit
->TexGenEnabled
= newenabled
;
614 /* client-side state */
615 case GL_VERTEX_ARRAY
:
616 case GL_NORMAL_ARRAY
:
619 case GL_TEXTURE_COORD_ARRAY
:
620 case GL_EDGE_FLAG_ARRAY
:
621 case GL_FOG_COORDINATE_ARRAY_EXT
:
622 case GL_SECONDARY_COLOR_ARRAY_EXT
:
623 case GL_POINT_SIZE_ARRAY_OES
:
624 client_state( ctx
, cap
, state
);
627 /* GL_ARB_texture_cube_map */
628 case GL_TEXTURE_CUBE_MAP_ARB
:
629 CHECK_EXTENSION(ARB_texture_cube_map
, cap
);
630 if (!enable_texture(ctx
, state
, TEXTURE_CUBE_BIT
)) {
635 /* GL_ARB_multisample */
636 case GL_MULTISAMPLE_ARB
:
637 if (ctx
->Multisample
.Enabled
== state
)
639 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
640 ctx
->Multisample
.Enabled
= state
;
642 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
643 if (ctx
->Multisample
.SampleAlphaToCoverage
== state
)
645 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
646 ctx
->Multisample
.SampleAlphaToCoverage
= state
;
648 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
649 if (ctx
->Multisample
.SampleAlphaToOne
== state
)
651 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
652 ctx
->Multisample
.SampleAlphaToOne
= state
;
654 case GL_SAMPLE_COVERAGE_ARB
:
655 if (ctx
->Multisample
.SampleCoverage
== state
)
657 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
658 ctx
->Multisample
.SampleCoverage
= state
;
660 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
661 if (ctx
->Multisample
.SampleCoverageInvert
== state
)
663 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
664 ctx
->Multisample
.SampleCoverageInvert
= state
;
667 /* GL_IBM_rasterpos_clip */
668 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
669 CHECK_EXTENSION(IBM_rasterpos_clip
, cap
);
670 if (ctx
->Transform
.RasterPositionUnclipped
== state
)
672 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
673 ctx
->Transform
.RasterPositionUnclipped
= state
;
676 /* GL_NV_point_sprite */
677 case GL_POINT_SPRITE_NV
:
678 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
, cap
);
679 if (ctx
->Point
.PointSprite
== state
)
681 FLUSH_VERTICES(ctx
, _NEW_POINT
);
682 ctx
->Point
.PointSprite
= state
;
685 /* GL_EXT_depth_bounds_test */
686 case GL_DEPTH_BOUNDS_TEST_EXT
:
687 CHECK_EXTENSION(EXT_depth_bounds_test
, cap
);
688 if (ctx
->Depth
.BoundsTest
== state
)
690 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
691 ctx
->Depth
.BoundsTest
= state
;
695 goto invalid_enum_error
;
698 if (ctx
->Driver
.Enable
) {
699 ctx
->Driver
.Enable( ctx
, cap
, state
);
705 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%s(0x%x)",
706 state
? "Enable" : "Disable", cap
);
711 * Enable GL capability. Called by glEnable()
712 * \param cap state to enable.
715 _mesa_Enable( GLenum cap
)
717 GET_CURRENT_CONTEXT(ctx
);
718 ASSERT_OUTSIDE_BEGIN_END(ctx
);
720 _mesa_set_enable( ctx
, cap
, GL_TRUE
);
725 * Disable GL capability. Called by glDisable()
726 * \param cap state to disable.
729 _mesa_Disable( GLenum cap
)
731 GET_CURRENT_CONTEXT(ctx
);
732 ASSERT_OUTSIDE_BEGIN_END(ctx
);
734 _mesa_set_enable( ctx
, cap
, GL_FALSE
);
738 #undef CHECK_EXTENSION
739 #define CHECK_EXTENSION(EXTNAME) \
740 if (!ctx->Extensions.EXTNAME) { \
741 goto invalid_enum_error; \
744 #undef CHECK_EXTENSION2
745 #define CHECK_EXTENSION2(EXT1, EXT2) \
746 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
747 goto invalid_enum_error; \
752 * Helper function to determine whether a texture target is enabled.
755 is_texture_enabled(struct gl_context
*ctx
, GLbitfield bit
)
757 const struct gl_texture_unit
*const texUnit
=
759 return (texUnit
->Enabled
& bit
) ? GL_TRUE
: GL_FALSE
;
764 * Return simple enable/disable state.
766 * \param cap state variable to query.
768 * Returns the state of the specified capability from the current GL context.
769 * For the capabilities associated with extensions verifies that those
770 * extensions are effectively present before reporting.
773 _mesa_IsEnabled( GLenum cap
)
775 GET_CURRENT_CONTEXT(ctx
);
776 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
780 return ctx
->Color
.AlphaEnabled
;
782 return ctx
->Eval
.AutoNormal
;
784 return ctx
->Color
.BlendEnabled
& 1; /* return state for buffer[0] */
785 case GL_CLIP_DISTANCE0
:
786 case GL_CLIP_DISTANCE1
:
787 case GL_CLIP_DISTANCE2
:
788 case GL_CLIP_DISTANCE3
:
789 case GL_CLIP_DISTANCE4
:
790 case GL_CLIP_DISTANCE5
:
791 case GL_CLIP_DISTANCE6
:
792 case GL_CLIP_DISTANCE7
: {
793 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
795 if (p
>= ctx
->Const
.MaxClipPlanes
)
796 goto invalid_enum_error
;
798 return (ctx
->Transform
.ClipPlanesEnabled
>> p
) & 1;
800 case GL_COLOR_MATERIAL
:
801 return ctx
->Light
.ColorMaterialEnabled
;
803 return ctx
->Polygon
.CullFlag
;
805 return ctx
->Depth
.Test
;
807 return ctx
->Color
.DitherFlag
;
809 return ctx
->Fog
.Enabled
;
811 return ctx
->Light
.Enabled
;
820 return ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
;
822 return ctx
->Line
.SmoothFlag
;
823 case GL_LINE_STIPPLE
:
824 return ctx
->Line
.StippleFlag
;
825 case GL_INDEX_LOGIC_OP
:
826 return ctx
->Color
.IndexLogicOpEnabled
;
827 case GL_COLOR_LOGIC_OP
:
828 return ctx
->Color
.ColorLogicOpEnabled
;
829 case GL_MAP1_COLOR_4
:
830 return ctx
->Eval
.Map1Color4
;
832 return ctx
->Eval
.Map1Index
;
834 return ctx
->Eval
.Map1Normal
;
835 case GL_MAP1_TEXTURE_COORD_1
:
836 return ctx
->Eval
.Map1TextureCoord1
;
837 case GL_MAP1_TEXTURE_COORD_2
:
838 return ctx
->Eval
.Map1TextureCoord2
;
839 case GL_MAP1_TEXTURE_COORD_3
:
840 return ctx
->Eval
.Map1TextureCoord3
;
841 case GL_MAP1_TEXTURE_COORD_4
:
842 return ctx
->Eval
.Map1TextureCoord4
;
843 case GL_MAP1_VERTEX_3
:
844 return ctx
->Eval
.Map1Vertex3
;
845 case GL_MAP1_VERTEX_4
:
846 return ctx
->Eval
.Map1Vertex4
;
847 case GL_MAP2_COLOR_4
:
848 return ctx
->Eval
.Map2Color4
;
850 return ctx
->Eval
.Map2Index
;
852 return ctx
->Eval
.Map2Normal
;
853 case GL_MAP2_TEXTURE_COORD_1
:
854 return ctx
->Eval
.Map2TextureCoord1
;
855 case GL_MAP2_TEXTURE_COORD_2
:
856 return ctx
->Eval
.Map2TextureCoord2
;
857 case GL_MAP2_TEXTURE_COORD_3
:
858 return ctx
->Eval
.Map2TextureCoord3
;
859 case GL_MAP2_TEXTURE_COORD_4
:
860 return ctx
->Eval
.Map2TextureCoord4
;
861 case GL_MAP2_VERTEX_3
:
862 return ctx
->Eval
.Map2Vertex3
;
863 case GL_MAP2_VERTEX_4
:
864 return ctx
->Eval
.Map2Vertex4
;
866 return ctx
->Transform
.Normalize
;
867 case GL_POINT_SMOOTH
:
868 return ctx
->Point
.SmoothFlag
;
869 case GL_POLYGON_SMOOTH
:
870 return ctx
->Polygon
.SmoothFlag
;
871 case GL_POLYGON_STIPPLE
:
872 return ctx
->Polygon
.StippleFlag
;
873 case GL_POLYGON_OFFSET_POINT
:
874 return ctx
->Polygon
.OffsetPoint
;
875 case GL_POLYGON_OFFSET_LINE
:
876 return ctx
->Polygon
.OffsetLine
;
877 case GL_POLYGON_OFFSET_FILL
:
878 return ctx
->Polygon
.OffsetFill
;
879 case GL_RESCALE_NORMAL_EXT
:
880 return ctx
->Transform
.RescaleNormals
;
881 case GL_SCISSOR_TEST
:
882 return ctx
->Scissor
.Enabled
;
883 case GL_STENCIL_TEST
:
884 return ctx
->Stencil
.Enabled
;
886 return is_texture_enabled(ctx
, TEXTURE_1D_BIT
);
888 return is_texture_enabled(ctx
, TEXTURE_2D_BIT
);
890 return is_texture_enabled(ctx
, TEXTURE_3D_BIT
);
891 case GL_TEXTURE_GEN_S
:
892 case GL_TEXTURE_GEN_T
:
893 case GL_TEXTURE_GEN_R
:
894 case GL_TEXTURE_GEN_Q
:
896 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
898 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
899 return (texUnit
->TexGenEnabled
& coordBit
) ? GL_TRUE
: GL_FALSE
;
904 case GL_TEXTURE_GEN_STR_OES
:
906 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
908 return (texUnit
->TexGenEnabled
& STR_BITS
) == STR_BITS
909 ? GL_TRUE
: GL_FALSE
;
914 /* client-side state */
915 case GL_VERTEX_ARRAY
:
916 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
!= 0);
917 case GL_NORMAL_ARRAY
:
918 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
!= 0);
920 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
!= 0);
922 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
!= 0);
923 case GL_TEXTURE_COORD_ARRAY
:
924 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_TEX
]
926 case GL_EDGE_FLAG_ARRAY
:
927 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
!= 0);
928 case GL_FOG_COORDINATE_ARRAY_EXT
:
929 CHECK_EXTENSION(EXT_fog_coord
);
930 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
!= 0);
931 case GL_SECONDARY_COLOR_ARRAY_EXT
:
932 CHECK_EXTENSION(EXT_secondary_color
);
933 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
!= 0);
934 #if FEATURE_point_size_array
935 case GL_POINT_SIZE_ARRAY_OES
:
936 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
!= 0);
939 /* GL_ARB_texture_cube_map */
940 case GL_TEXTURE_CUBE_MAP_ARB
:
941 CHECK_EXTENSION(ARB_texture_cube_map
);
942 return is_texture_enabled(ctx
, TEXTURE_CUBE_BIT
);
944 /* GL_ARB_multisample */
945 case GL_MULTISAMPLE_ARB
:
946 return ctx
->Multisample
.Enabled
;
947 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
948 return ctx
->Multisample
.SampleAlphaToCoverage
;
949 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
950 return ctx
->Multisample
.SampleAlphaToOne
;
951 case GL_SAMPLE_COVERAGE_ARB
:
952 return ctx
->Multisample
.SampleCoverage
;
953 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
954 return ctx
->Multisample
.SampleCoverageInvert
;
956 /* GL_IBM_rasterpos_clip */
957 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
958 CHECK_EXTENSION(IBM_rasterpos_clip
);
959 return ctx
->Transform
.RasterPositionUnclipped
;
961 /* GL_NV_point_sprite */
962 case GL_POINT_SPRITE_NV
:
963 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
)
964 return ctx
->Point
.PointSprite
;
966 /* GL_EXT_depth_bounds_test */
967 case GL_DEPTH_BOUNDS_TEST_EXT
:
968 CHECK_EXTENSION(EXT_depth_bounds_test
);
969 return ctx
->Depth
.BoundsTest
;
972 goto invalid_enum_error
;
978 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabled(0x%x)", (int) cap
);