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 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
37 #include "simple_list.h"
40 #include "api_arrayelt.h"
42 #include "drivers/common/meta.h"
46 #define CHECK_EXTENSION(EXTNAME, CAP) \
47 if (!ctx->Extensions.EXTNAME) { \
48 goto invalid_enum_error; \
53 update_derived_primitive_restart_state(struct gl_context
*ctx
)
55 /* Update derived primitive restart state.
57 ctx
->Array
._PrimitiveRestart
= ctx
->Array
.PrimitiveRestart
58 || ctx
->Array
.PrimitiveRestartFixedIndex
;
62 * Helper to enable/disable client-side state.
65 client_state(struct gl_context
*ctx
, GLenum cap
, GLboolean state
)
67 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
73 var
= &vao
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
;
77 var
= &vao
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
;
78 flag
= VERT_BIT_NORMAL
;
81 var
= &vao
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
;
82 flag
= VERT_BIT_COLOR0
;
85 var
= &vao
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
;
86 flag
= VERT_BIT_COLOR_INDEX
;
88 case GL_TEXTURE_COORD_ARRAY
:
89 var
= &vao
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Enabled
;
90 flag
= VERT_BIT_TEX(ctx
->Array
.ActiveTexture
);
92 case GL_EDGE_FLAG_ARRAY
:
93 var
= &vao
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
;
94 flag
= VERT_BIT_EDGEFLAG
;
96 case GL_FOG_COORDINATE_ARRAY_EXT
:
97 var
= &vao
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
;
100 case GL_SECONDARY_COLOR_ARRAY_EXT
:
101 var
= &vao
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
;
102 flag
= VERT_BIT_COLOR1
;
105 case GL_POINT_SIZE_ARRAY_OES
:
106 var
= &vao
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
;
107 flag
= VERT_BIT_POINT_SIZE
;
110 /* GL_NV_primitive_restart */
111 case GL_PRIMITIVE_RESTART_NV
:
112 if (!ctx
->Extensions
.NV_primitive_restart
) {
113 goto invalid_enum_error
;
115 var
= &ctx
->Array
.PrimitiveRestart
;
120 goto invalid_enum_error
;
126 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
128 _ae_invalidate_state(ctx
, _NEW_ARRAY
);
132 update_derived_primitive_restart_state(ctx
);
135 vao
->_Enabled
|= flag
;
137 vao
->_Enabled
&= ~flag
;
139 vao
->NewArrays
|= flag
;
141 if (ctx
->Driver
.Enable
) {
142 ctx
->Driver
.Enable( ctx
, cap
, state
);
148 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%sClientState(%s)",
149 state
? "Enable" : "Disable", _mesa_lookup_enum_by_nr(cap
));
154 * Enable GL capability.
155 * \param cap state to enable/disable.
157 * Get's the current context, assures that we're outside glBegin()/glEnd() and
158 * calls client_state().
161 _mesa_EnableClientState( GLenum cap
)
163 GET_CURRENT_CONTEXT(ctx
);
164 client_state( ctx
, cap
, GL_TRUE
);
169 * Disable GL capability.
170 * \param cap state to enable/disable.
172 * Get's the current context, assures that we're outside glBegin()/glEnd() and
173 * calls client_state().
176 _mesa_DisableClientState( GLenum cap
)
178 GET_CURRENT_CONTEXT(ctx
);
179 client_state( ctx
, cap
, GL_FALSE
);
183 #undef CHECK_EXTENSION
184 #define CHECK_EXTENSION(EXTNAME, CAP) \
185 if (!ctx->Extensions.EXTNAME) { \
186 goto invalid_enum_error; \
189 #define CHECK_EXTENSION2(EXT1, EXT2, CAP) \
190 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
191 goto invalid_enum_error; \
195 * Return pointer to current texture unit for setting/getting coordinate
197 * Note that we'll set GL_INVALID_OPERATION and return NULL if the active
198 * texture unit is higher than the number of supported coordinate units.
200 static struct gl_texture_unit
*
201 get_texcoord_unit(struct gl_context
*ctx
)
203 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
204 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glEnable/Disable(texcoord unit)");
208 return &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
214 * Helper function to enable or disable a texture target.
215 * \param bit one of the TEXTURE_x_BIT values
216 * \return GL_TRUE if state is changing or GL_FALSE if no change
219 enable_texture(struct gl_context
*ctx
, GLboolean state
, GLbitfield texBit
)
221 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
222 const GLbitfield newenabled
= state
223 ? (texUnit
->Enabled
| texBit
) : (texUnit
->Enabled
& ~texBit
);
225 if (texUnit
->Enabled
== newenabled
)
228 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
229 texUnit
->Enabled
= newenabled
;
235 * Helper function to enable or disable GL_MULTISAMPLE, skipping the check for
236 * whether the API supports it (GLES doesn't).
239 _mesa_set_multisample(struct gl_context
*ctx
, GLboolean state
)
241 if (ctx
->Multisample
.Enabled
== state
)
243 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
244 ctx
->Multisample
.Enabled
= state
;
246 if (ctx
->Driver
.Enable
) {
247 ctx
->Driver
.Enable(ctx
, GL_MULTISAMPLE
, state
);
252 * Helper function to enable or disable GL_FRAMEBUFFER_SRGB, skipping the
253 * check for whether the API supports it (GLES doesn't).
256 _mesa_set_framebuffer_srgb(struct gl_context
*ctx
, GLboolean state
)
258 if (ctx
->Color
.sRGBEnabled
== state
)
260 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
261 ctx
->Color
.sRGBEnabled
= state
;
263 if (ctx
->Driver
.Enable
) {
264 ctx
->Driver
.Enable(ctx
, GL_FRAMEBUFFER_SRGB
, state
);
269 * Helper function to enable or disable state.
271 * \param ctx GL context.
272 * \param cap the state to enable/disable
273 * \param state whether to enable or disable the specified capability.
275 * Updates the current context and flushes the vertices as needed. For
276 * capabilities associated with extensions it verifies that those extensions
277 * are effectivly present before updating. Notifies the driver via
278 * dd_function_table::Enable.
281 _mesa_set_enable(struct gl_context
*ctx
, GLenum cap
, GLboolean state
)
283 if (MESA_VERBOSE
& VERBOSE_API
)
284 _mesa_debug(ctx
, "%s %s (newstate is %x)\n",
285 state
? "glEnable" : "glDisable",
286 _mesa_lookup_enum_by_nr(cap
),
291 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
292 goto invalid_enum_error
;
293 if (ctx
->Color
.AlphaEnabled
== state
)
295 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
296 ctx
->Color
.AlphaEnabled
= state
;
299 if (ctx
->API
!= API_OPENGL_COMPAT
)
300 goto invalid_enum_error
;
301 if (ctx
->Eval
.AutoNormal
== state
)
303 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
304 ctx
->Eval
.AutoNormal
= state
;
308 GLbitfield newEnabled
=
309 state
* ((1 << ctx
->Const
.MaxDrawBuffers
) - 1);
310 if (newEnabled
!= ctx
->Color
.BlendEnabled
) {
311 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
312 ctx
->Color
.BlendEnabled
= newEnabled
;
316 case GL_CLIP_DISTANCE0
: /* aka GL_CLIP_PLANE0 */
317 case GL_CLIP_DISTANCE1
:
318 case GL_CLIP_DISTANCE2
:
319 case GL_CLIP_DISTANCE3
:
320 case GL_CLIP_DISTANCE4
:
321 case GL_CLIP_DISTANCE5
:
322 case GL_CLIP_DISTANCE6
:
323 case GL_CLIP_DISTANCE7
:
325 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
327 if (p
>= ctx
->Const
.MaxClipPlanes
)
328 goto invalid_enum_error
;
330 if ((ctx
->Transform
.ClipPlanesEnabled
& (1 << p
))
331 == ((GLuint
) state
<< p
))
334 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
337 ctx
->Transform
.ClipPlanesEnabled
|= (1 << p
);
338 _mesa_update_clip_plane(ctx
, p
);
341 ctx
->Transform
.ClipPlanesEnabled
&= ~(1 << p
);
345 case GL_COLOR_MATERIAL
:
346 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
347 goto invalid_enum_error
;
348 if (ctx
->Light
.ColorMaterialEnabled
== state
)
350 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
351 FLUSH_CURRENT(ctx
, 0);
352 ctx
->Light
.ColorMaterialEnabled
= state
;
354 _mesa_update_color_material( ctx
,
355 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
] );
359 if (ctx
->Polygon
.CullFlag
== state
)
361 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
362 ctx
->Polygon
.CullFlag
= state
;
365 if (ctx
->Depth
.Test
== state
)
367 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
368 ctx
->Depth
.Test
= state
;
370 case GL_DEBUG_OUTPUT
:
371 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
:
372 if (!_mesa_is_desktop_gl(ctx
))
373 goto invalid_enum_error
;
375 _mesa_set_debug_state_int(ctx
, cap
, state
);
378 if (ctx
->Color
.DitherFlag
== state
)
380 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
381 ctx
->Color
.DitherFlag
= state
;
384 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
385 goto invalid_enum_error
;
386 if (ctx
->Fog
.Enabled
== state
)
388 FLUSH_VERTICES(ctx
, _NEW_FOG
);
389 ctx
->Fog
.Enabled
= state
;
399 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
400 goto invalid_enum_error
;
401 if (ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
== state
)
403 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
404 ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
= state
;
406 insert_at_tail(&ctx
->Light
.EnabledList
,
407 &ctx
->Light
.Light
[cap
-GL_LIGHT0
]);
410 remove_from_list(&ctx
->Light
.Light
[cap
-GL_LIGHT0
]);
414 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
415 goto invalid_enum_error
;
416 if (ctx
->Light
.Enabled
== state
)
418 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
419 ctx
->Light
.Enabled
= state
;
422 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
423 goto invalid_enum_error
;
424 if (ctx
->Line
.SmoothFlag
== state
)
426 FLUSH_VERTICES(ctx
, _NEW_LINE
);
427 ctx
->Line
.SmoothFlag
= state
;
429 case GL_LINE_STIPPLE
:
430 if (ctx
->API
!= API_OPENGL_COMPAT
)
431 goto invalid_enum_error
;
432 if (ctx
->Line
.StippleFlag
== state
)
434 FLUSH_VERTICES(ctx
, _NEW_LINE
);
435 ctx
->Line
.StippleFlag
= state
;
437 case GL_INDEX_LOGIC_OP
:
438 if (ctx
->API
!= API_OPENGL_COMPAT
)
439 goto invalid_enum_error
;
440 if (ctx
->Color
.IndexLogicOpEnabled
== state
)
442 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
443 ctx
->Color
.IndexLogicOpEnabled
= state
;
445 case GL_COLOR_LOGIC_OP
:
446 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
447 goto invalid_enum_error
;
448 if (ctx
->Color
.ColorLogicOpEnabled
== state
)
450 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
451 ctx
->Color
.ColorLogicOpEnabled
= state
;
453 case GL_MAP1_COLOR_4
:
454 if (ctx
->API
!= API_OPENGL_COMPAT
)
455 goto invalid_enum_error
;
456 if (ctx
->Eval
.Map1Color4
== state
)
458 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
459 ctx
->Eval
.Map1Color4
= state
;
462 if (ctx
->API
!= API_OPENGL_COMPAT
)
463 goto invalid_enum_error
;
464 if (ctx
->Eval
.Map1Index
== state
)
466 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
467 ctx
->Eval
.Map1Index
= state
;
470 if (ctx
->API
!= API_OPENGL_COMPAT
)
471 goto invalid_enum_error
;
472 if (ctx
->Eval
.Map1Normal
== state
)
474 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
475 ctx
->Eval
.Map1Normal
= state
;
477 case GL_MAP1_TEXTURE_COORD_1
:
478 if (ctx
->API
!= API_OPENGL_COMPAT
)
479 goto invalid_enum_error
;
480 if (ctx
->Eval
.Map1TextureCoord1
== state
)
482 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
483 ctx
->Eval
.Map1TextureCoord1
= state
;
485 case GL_MAP1_TEXTURE_COORD_2
:
486 if (ctx
->API
!= API_OPENGL_COMPAT
)
487 goto invalid_enum_error
;
488 if (ctx
->Eval
.Map1TextureCoord2
== state
)
490 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
491 ctx
->Eval
.Map1TextureCoord2
= state
;
493 case GL_MAP1_TEXTURE_COORD_3
:
494 if (ctx
->API
!= API_OPENGL_COMPAT
)
495 goto invalid_enum_error
;
496 if (ctx
->Eval
.Map1TextureCoord3
== state
)
498 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
499 ctx
->Eval
.Map1TextureCoord3
= state
;
501 case GL_MAP1_TEXTURE_COORD_4
:
502 if (ctx
->API
!= API_OPENGL_COMPAT
)
503 goto invalid_enum_error
;
504 if (ctx
->Eval
.Map1TextureCoord4
== state
)
506 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
507 ctx
->Eval
.Map1TextureCoord4
= state
;
509 case GL_MAP1_VERTEX_3
:
510 if (ctx
->API
!= API_OPENGL_COMPAT
)
511 goto invalid_enum_error
;
512 if (ctx
->Eval
.Map1Vertex3
== state
)
514 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
515 ctx
->Eval
.Map1Vertex3
= state
;
517 case GL_MAP1_VERTEX_4
:
518 if (ctx
->API
!= API_OPENGL_COMPAT
)
519 goto invalid_enum_error
;
520 if (ctx
->Eval
.Map1Vertex4
== state
)
522 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
523 ctx
->Eval
.Map1Vertex4
= state
;
525 case GL_MAP2_COLOR_4
:
526 if (ctx
->API
!= API_OPENGL_COMPAT
)
527 goto invalid_enum_error
;
528 if (ctx
->Eval
.Map2Color4
== state
)
530 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
531 ctx
->Eval
.Map2Color4
= state
;
534 if (ctx
->API
!= API_OPENGL_COMPAT
)
535 goto invalid_enum_error
;
536 if (ctx
->Eval
.Map2Index
== state
)
538 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
539 ctx
->Eval
.Map2Index
= state
;
542 if (ctx
->API
!= API_OPENGL_COMPAT
)
543 goto invalid_enum_error
;
544 if (ctx
->Eval
.Map2Normal
== state
)
546 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
547 ctx
->Eval
.Map2Normal
= state
;
549 case GL_MAP2_TEXTURE_COORD_1
:
550 if (ctx
->API
!= API_OPENGL_COMPAT
)
551 goto invalid_enum_error
;
552 if (ctx
->Eval
.Map2TextureCoord1
== state
)
554 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
555 ctx
->Eval
.Map2TextureCoord1
= state
;
557 case GL_MAP2_TEXTURE_COORD_2
:
558 if (ctx
->API
!= API_OPENGL_COMPAT
)
559 goto invalid_enum_error
;
560 if (ctx
->Eval
.Map2TextureCoord2
== state
)
562 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
563 ctx
->Eval
.Map2TextureCoord2
= state
;
565 case GL_MAP2_TEXTURE_COORD_3
:
566 if (ctx
->API
!= API_OPENGL_COMPAT
)
567 goto invalid_enum_error
;
568 if (ctx
->Eval
.Map2TextureCoord3
== state
)
570 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
571 ctx
->Eval
.Map2TextureCoord3
= state
;
573 case GL_MAP2_TEXTURE_COORD_4
:
574 if (ctx
->API
!= API_OPENGL_COMPAT
)
575 goto invalid_enum_error
;
576 if (ctx
->Eval
.Map2TextureCoord4
== state
)
578 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
579 ctx
->Eval
.Map2TextureCoord4
= state
;
581 case GL_MAP2_VERTEX_3
:
582 if (ctx
->API
!= API_OPENGL_COMPAT
)
583 goto invalid_enum_error
;
584 if (ctx
->Eval
.Map2Vertex3
== state
)
586 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
587 ctx
->Eval
.Map2Vertex3
= state
;
589 case GL_MAP2_VERTEX_4
:
590 if (ctx
->API
!= API_OPENGL_COMPAT
)
591 goto invalid_enum_error
;
592 if (ctx
->Eval
.Map2Vertex4
== state
)
594 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
595 ctx
->Eval
.Map2Vertex4
= state
;
598 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
599 goto invalid_enum_error
;
600 if (ctx
->Transform
.Normalize
== state
)
602 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
603 ctx
->Transform
.Normalize
= state
;
605 case GL_POINT_SMOOTH
:
606 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
607 goto invalid_enum_error
;
608 if (ctx
->Point
.SmoothFlag
== state
)
610 FLUSH_VERTICES(ctx
, _NEW_POINT
);
611 ctx
->Point
.SmoothFlag
= state
;
613 case GL_POLYGON_SMOOTH
:
614 if (!_mesa_is_desktop_gl(ctx
))
615 goto invalid_enum_error
;
616 if (ctx
->Polygon
.SmoothFlag
== state
)
618 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
619 ctx
->Polygon
.SmoothFlag
= state
;
621 case GL_POLYGON_STIPPLE
:
622 if (ctx
->API
!= API_OPENGL_COMPAT
)
623 goto invalid_enum_error
;
624 if (ctx
->Polygon
.StippleFlag
== state
)
626 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
627 ctx
->Polygon
.StippleFlag
= state
;
629 case GL_POLYGON_OFFSET_POINT
:
630 if (!_mesa_is_desktop_gl(ctx
))
631 goto invalid_enum_error
;
632 if (ctx
->Polygon
.OffsetPoint
== state
)
634 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
635 ctx
->Polygon
.OffsetPoint
= state
;
637 case GL_POLYGON_OFFSET_LINE
:
638 if (!_mesa_is_desktop_gl(ctx
))
639 goto invalid_enum_error
;
640 if (ctx
->Polygon
.OffsetLine
== state
)
642 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
643 ctx
->Polygon
.OffsetLine
= state
;
645 case GL_POLYGON_OFFSET_FILL
:
646 if (ctx
->Polygon
.OffsetFill
== state
)
648 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
649 ctx
->Polygon
.OffsetFill
= state
;
651 case GL_RESCALE_NORMAL_EXT
:
652 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
653 goto invalid_enum_error
;
654 if (ctx
->Transform
.RescaleNormals
== state
)
656 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
657 ctx
->Transform
.RescaleNormals
= state
;
659 case GL_SCISSOR_TEST
:
661 /* Must expand glEnable to all scissors */
662 GLbitfield newEnabled
=
663 state
* ((1 << ctx
->Const
.MaxViewports
) - 1);
664 if (newEnabled
!= ctx
->Scissor
.EnableFlags
) {
665 FLUSH_VERTICES(ctx
, _NEW_SCISSOR
);
666 ctx
->Scissor
.EnableFlags
= newEnabled
;
670 case GL_STENCIL_TEST
:
671 if (ctx
->Stencil
.Enabled
== state
)
673 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
674 ctx
->Stencil
.Enabled
= state
;
677 if (ctx
->API
!= API_OPENGL_COMPAT
)
678 goto invalid_enum_error
;
679 if (!enable_texture(ctx
, state
, TEXTURE_1D_BIT
)) {
684 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
685 goto invalid_enum_error
;
686 if (!enable_texture(ctx
, state
, TEXTURE_2D_BIT
)) {
691 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
692 goto invalid_enum_error
;
693 if (!enable_texture(ctx
, state
, TEXTURE_3D_BIT
)) {
697 case GL_TEXTURE_GEN_S
:
698 case GL_TEXTURE_GEN_T
:
699 case GL_TEXTURE_GEN_R
:
700 case GL_TEXTURE_GEN_Q
:
702 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
704 if (ctx
->API
!= API_OPENGL_COMPAT
)
705 goto invalid_enum_error
;
708 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
709 GLbitfield newenabled
= texUnit
->TexGenEnabled
& ~coordBit
;
711 newenabled
|= coordBit
;
712 if (texUnit
->TexGenEnabled
== newenabled
)
714 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
715 texUnit
->TexGenEnabled
= newenabled
;
720 case GL_TEXTURE_GEN_STR_OES
:
721 /* disable S, T, and R at the same time */
723 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
725 if (ctx
->API
!= API_OPENGLES
)
726 goto invalid_enum_error
;
730 texUnit
->TexGenEnabled
& ~STR_BITS
;
732 newenabled
|= STR_BITS
;
733 if (texUnit
->TexGenEnabled
== newenabled
)
735 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
736 texUnit
->TexGenEnabled
= newenabled
;
741 /* client-side state */
742 case GL_VERTEX_ARRAY
:
743 case GL_NORMAL_ARRAY
:
746 case GL_TEXTURE_COORD_ARRAY
:
747 case GL_EDGE_FLAG_ARRAY
:
748 case GL_FOG_COORDINATE_ARRAY_EXT
:
749 case GL_SECONDARY_COLOR_ARRAY_EXT
:
750 case GL_POINT_SIZE_ARRAY_OES
:
751 client_state( ctx
, cap
, state
);
754 /* GL_ARB_texture_cube_map */
755 case GL_TEXTURE_CUBE_MAP_ARB
:
756 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
757 goto invalid_enum_error
;
758 CHECK_EXTENSION(ARB_texture_cube_map
, cap
);
759 if (!enable_texture(ctx
, state
, TEXTURE_CUBE_BIT
)) {
764 /* GL_EXT_secondary_color */
765 case GL_COLOR_SUM_EXT
:
766 if (ctx
->API
!= API_OPENGL_COMPAT
)
767 goto invalid_enum_error
;
768 if (ctx
->Fog
.ColorSumEnabled
== state
)
770 FLUSH_VERTICES(ctx
, _NEW_FOG
);
771 ctx
->Fog
.ColorSumEnabled
= state
;
774 /* GL_ARB_multisample */
775 case GL_MULTISAMPLE_ARB
:
776 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
777 goto invalid_enum_error
;
778 _mesa_set_multisample(ctx
, state
);
780 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
781 if (ctx
->Multisample
.SampleAlphaToCoverage
== state
)
783 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
784 ctx
->Multisample
.SampleAlphaToCoverage
= state
;
786 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
787 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
788 goto invalid_enum_error
;
789 if (ctx
->Multisample
.SampleAlphaToOne
== state
)
791 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
792 ctx
->Multisample
.SampleAlphaToOne
= state
;
794 case GL_SAMPLE_COVERAGE_ARB
:
795 if (ctx
->Multisample
.SampleCoverage
== state
)
797 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
798 ctx
->Multisample
.SampleCoverage
= state
;
800 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
801 if (!_mesa_is_desktop_gl(ctx
))
802 goto invalid_enum_error
;
803 if (ctx
->Multisample
.SampleCoverageInvert
== state
)
805 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
806 ctx
->Multisample
.SampleCoverageInvert
= state
;
809 /* GL_ARB_sample_shading */
810 case GL_SAMPLE_SHADING
:
811 if (!_mesa_is_desktop_gl(ctx
))
812 goto invalid_enum_error
;
813 CHECK_EXTENSION(ARB_sample_shading
, cap
);
814 if (ctx
->Multisample
.SampleShading
== state
)
816 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
817 ctx
->Multisample
.SampleShading
= state
;
820 /* GL_IBM_rasterpos_clip */
821 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
822 if (ctx
->API
!= API_OPENGL_COMPAT
)
823 goto invalid_enum_error
;
824 if (ctx
->Transform
.RasterPositionUnclipped
== state
)
826 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
827 ctx
->Transform
.RasterPositionUnclipped
= state
;
830 /* GL_NV_point_sprite */
831 case GL_POINT_SPRITE_NV
:
832 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
833 goto invalid_enum_error
;
834 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
, cap
);
835 if (ctx
->Point
.PointSprite
== state
)
837 FLUSH_VERTICES(ctx
, _NEW_POINT
);
838 ctx
->Point
.PointSprite
= state
;
841 case GL_VERTEX_PROGRAM_ARB
:
842 if (ctx
->API
!= API_OPENGL_COMPAT
)
843 goto invalid_enum_error
;
844 CHECK_EXTENSION(ARB_vertex_program
, cap
);
845 if (ctx
->VertexProgram
.Enabled
== state
)
847 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
848 ctx
->VertexProgram
.Enabled
= state
;
850 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
851 /* This was added with ARB_vertex_program, but it is also used with
852 * GLSL vertex shaders on desktop.
854 if (!_mesa_is_desktop_gl(ctx
))
855 goto invalid_enum_error
;
856 CHECK_EXTENSION(ARB_vertex_program
, cap
);
857 if (ctx
->VertexProgram
.PointSizeEnabled
== state
)
859 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
860 ctx
->VertexProgram
.PointSizeEnabled
= state
;
862 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
863 if (ctx
->API
!= API_OPENGL_COMPAT
)
864 goto invalid_enum_error
;
865 CHECK_EXTENSION(ARB_vertex_program
, cap
);
866 if (ctx
->VertexProgram
.TwoSideEnabled
== state
)
868 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
869 ctx
->VertexProgram
.TwoSideEnabled
= state
;
872 /* GL_NV_texture_rectangle */
873 case GL_TEXTURE_RECTANGLE_NV
:
874 if (ctx
->API
!= API_OPENGL_COMPAT
)
875 goto invalid_enum_error
;
876 CHECK_EXTENSION(NV_texture_rectangle
, cap
);
877 if (!enable_texture(ctx
, state
, TEXTURE_RECT_BIT
)) {
882 /* GL_EXT_stencil_two_side */
883 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
884 if (ctx
->API
!= API_OPENGL_COMPAT
)
885 goto invalid_enum_error
;
886 CHECK_EXTENSION(EXT_stencil_two_side
, cap
);
887 if (ctx
->Stencil
.TestTwoSide
== state
)
889 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
890 ctx
->Stencil
.TestTwoSide
= state
;
892 ctx
->Stencil
._BackFace
= 2;
894 ctx
->Stencil
._BackFace
= 1;
898 case GL_FRAGMENT_PROGRAM_ARB
:
899 if (ctx
->API
!= API_OPENGL_COMPAT
)
900 goto invalid_enum_error
;
901 CHECK_EXTENSION(ARB_fragment_program
, cap
);
902 if (ctx
->FragmentProgram
.Enabled
== state
)
904 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
905 ctx
->FragmentProgram
.Enabled
= state
;
908 /* GL_EXT_depth_bounds_test */
909 case GL_DEPTH_BOUNDS_TEST_EXT
:
910 if (!_mesa_is_desktop_gl(ctx
))
911 goto invalid_enum_error
;
912 CHECK_EXTENSION(EXT_depth_bounds_test
, cap
);
913 if (ctx
->Depth
.BoundsTest
== state
)
915 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
916 ctx
->Depth
.BoundsTest
= state
;
920 if (!_mesa_is_desktop_gl(ctx
))
921 goto invalid_enum_error
;
922 CHECK_EXTENSION(ARB_depth_clamp
, cap
);
923 if (ctx
->Transform
.DepthClamp
== state
)
925 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
926 ctx
->Transform
.DepthClamp
= state
;
929 case GL_FRAGMENT_SHADER_ATI
:
930 if (ctx
->API
!= API_OPENGL_COMPAT
)
931 goto invalid_enum_error
;
932 CHECK_EXTENSION(ATI_fragment_shader
, cap
);
933 if (ctx
->ATIFragmentShader
.Enabled
== state
)
935 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
936 ctx
->ATIFragmentShader
.Enabled
= state
;
939 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
940 if (!_mesa_is_desktop_gl(ctx
))
941 goto invalid_enum_error
;
942 CHECK_EXTENSION(ARB_seamless_cube_map
, cap
);
943 if (ctx
->Texture
.CubeMapSeamless
!= state
) {
944 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
945 ctx
->Texture
.CubeMapSeamless
= state
;
949 case GL_RASTERIZER_DISCARD
:
950 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
951 goto invalid_enum_error
;
952 CHECK_EXTENSION(EXT_transform_feedback
, cap
);
953 if (ctx
->RasterDiscard
!= state
) {
954 FLUSH_VERTICES(ctx
, 0);
955 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewRasterizerDiscard
;
956 ctx
->RasterDiscard
= state
;
960 /* GL 3.1 primitive restart. Note: this enum is different from
961 * GL_PRIMITIVE_RESTART_NV (which is client state).
963 case GL_PRIMITIVE_RESTART
:
964 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
965 goto invalid_enum_error
;
967 if (ctx
->Array
.PrimitiveRestart
!= state
) {
968 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
969 ctx
->Array
.PrimitiveRestart
= state
;
970 update_derived_primitive_restart_state(ctx
);
974 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
975 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
)
976 goto invalid_enum_error
;
977 if (ctx
->Array
.PrimitiveRestartFixedIndex
!= state
) {
978 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
979 ctx
->Array
.PrimitiveRestartFixedIndex
= state
;
980 update_derived_primitive_restart_state(ctx
);
984 /* GL3.0 - GL_framebuffer_sRGB */
985 case GL_FRAMEBUFFER_SRGB_EXT
:
986 if (!_mesa_is_desktop_gl(ctx
))
987 goto invalid_enum_error
;
988 CHECK_EXTENSION(EXT_framebuffer_sRGB
, cap
);
989 _mesa_set_framebuffer_srgb(ctx
, state
);
992 /* GL_OES_EGL_image_external */
993 case GL_TEXTURE_EXTERNAL_OES
:
994 if (!_mesa_is_gles(ctx
))
995 goto invalid_enum_error
;
996 CHECK_EXTENSION(OES_EGL_image_external
, cap
);
997 if (!enable_texture(ctx
, state
, TEXTURE_EXTERNAL_BIT
)) {
1002 /* ARB_texture_multisample */
1003 case GL_SAMPLE_MASK
:
1004 if (!_mesa_is_desktop_gl(ctx
))
1005 goto invalid_enum_error
;
1006 CHECK_EXTENSION(ARB_texture_multisample
, cap
);
1007 if (ctx
->Multisample
.SampleMask
== state
)
1009 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
1010 ctx
->Multisample
.SampleMask
= state
;
1014 goto invalid_enum_error
;
1017 if (ctx
->Driver
.Enable
) {
1018 ctx
->Driver
.Enable( ctx
, cap
, state
);
1024 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%s(%s)",
1025 state
? "Enable" : "Disable", _mesa_lookup_enum_by_nr(cap
));
1030 * Enable GL capability. Called by glEnable()
1031 * \param cap state to enable.
1034 _mesa_Enable( GLenum cap
)
1036 GET_CURRENT_CONTEXT(ctx
);
1038 _mesa_set_enable( ctx
, cap
, GL_TRUE
);
1043 * Disable GL capability. Called by glDisable()
1044 * \param cap state to disable.
1047 _mesa_Disable( GLenum cap
)
1049 GET_CURRENT_CONTEXT(ctx
);
1051 _mesa_set_enable( ctx
, cap
, GL_FALSE
);
1057 * Enable/disable an indexed state var.
1060 _mesa_set_enablei(struct gl_context
*ctx
, GLenum cap
,
1061 GLuint index
, GLboolean state
)
1063 ASSERT(state
== 0 || state
== 1);
1066 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
1067 goto invalid_enum_error
;
1069 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1070 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1071 state
? "glEnableIndexed" : "glDisableIndexed", index
);
1074 if (((ctx
->Color
.BlendEnabled
>> index
) & 1) != state
) {
1075 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
1077 ctx
->Color
.BlendEnabled
|= (1 << index
);
1079 ctx
->Color
.BlendEnabled
&= ~(1 << index
);
1082 case GL_SCISSOR_TEST
:
1083 if (index
>= ctx
->Const
.MaxViewports
) {
1084 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1085 state
? "glEnablei" : "glDisablei", index
);
1088 if (((ctx
->Scissor
.EnableFlags
>> index
) & 1) != state
) {
1089 FLUSH_VERTICES(ctx
, _NEW_SCISSOR
);
1091 ctx
->Scissor
.EnableFlags
|= (1 << index
);
1093 ctx
->Scissor
.EnableFlags
&= ~(1 << index
);
1097 goto invalid_enum_error
;
1102 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(cap=%s)",
1103 state
? "glEnablei" : "glDisablei",
1104 _mesa_lookup_enum_by_nr(cap
));
1109 _mesa_Disablei( GLenum cap
, GLuint index
)
1111 GET_CURRENT_CONTEXT(ctx
);
1112 _mesa_set_enablei(ctx
, cap
, index
, GL_FALSE
);
1117 _mesa_Enablei( GLenum cap
, GLuint index
)
1119 GET_CURRENT_CONTEXT(ctx
);
1120 _mesa_set_enablei(ctx
, cap
, index
, GL_TRUE
);
1124 GLboolean GLAPIENTRY
1125 _mesa_IsEnabledi( GLenum cap
, GLuint index
)
1127 GET_CURRENT_CONTEXT(ctx
);
1128 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1131 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1132 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1136 return (ctx
->Color
.BlendEnabled
>> index
) & 1;
1137 case GL_SCISSOR_TEST
:
1138 if (index
>= ctx
->Const
.MaxViewports
) {
1139 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1143 return (ctx
->Scissor
.EnableFlags
>> index
) & 1;
1145 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabledIndexed(cap=%s)",
1146 _mesa_lookup_enum_by_nr(cap
));
1154 #undef CHECK_EXTENSION
1155 #define CHECK_EXTENSION(EXTNAME) \
1156 if (!ctx->Extensions.EXTNAME) { \
1157 goto invalid_enum_error; \
1160 #undef CHECK_EXTENSION2
1161 #define CHECK_EXTENSION2(EXT1, EXT2) \
1162 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1163 goto invalid_enum_error; \
1168 * Helper function to determine whether a texture target is enabled.
1171 is_texture_enabled(struct gl_context
*ctx
, GLbitfield bit
)
1173 const struct gl_texture_unit
*const texUnit
=
1174 &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1175 return (texUnit
->Enabled
& bit
) ? GL_TRUE
: GL_FALSE
;
1180 * Return simple enable/disable state.
1182 * \param cap state variable to query.
1184 * Returns the state of the specified capability from the current GL context.
1185 * For the capabilities associated with extensions verifies that those
1186 * extensions are effectively present before reporting.
1188 GLboolean GLAPIENTRY
1189 _mesa_IsEnabled( GLenum cap
)
1191 GET_CURRENT_CONTEXT(ctx
);
1192 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1196 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1197 goto invalid_enum_error
;
1198 return ctx
->Color
.AlphaEnabled
;
1199 case GL_AUTO_NORMAL
:
1200 if (ctx
->API
!= API_OPENGL_COMPAT
)
1201 goto invalid_enum_error
;
1202 return ctx
->Eval
.AutoNormal
;
1204 return ctx
->Color
.BlendEnabled
& 1; /* return state for buffer[0] */
1205 case GL_CLIP_DISTANCE0
: /* aka GL_CLIP_PLANE0 */
1206 case GL_CLIP_DISTANCE1
:
1207 case GL_CLIP_DISTANCE2
:
1208 case GL_CLIP_DISTANCE3
:
1209 case GL_CLIP_DISTANCE4
:
1210 case GL_CLIP_DISTANCE5
:
1211 case GL_CLIP_DISTANCE6
:
1212 case GL_CLIP_DISTANCE7
: {
1213 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
1215 if (p
>= ctx
->Const
.MaxClipPlanes
)
1216 goto invalid_enum_error
;
1218 return (ctx
->Transform
.ClipPlanesEnabled
>> p
) & 1;
1220 case GL_COLOR_MATERIAL
:
1221 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1222 goto invalid_enum_error
;
1223 return ctx
->Light
.ColorMaterialEnabled
;
1225 return ctx
->Polygon
.CullFlag
;
1226 case GL_DEBUG_OUTPUT
:
1227 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
:
1228 if (!_mesa_is_desktop_gl(ctx
))
1229 goto invalid_enum_error
;
1231 return (GLboolean
) _mesa_get_debug_state_int(ctx
, cap
);
1233 return ctx
->Depth
.Test
;
1235 return ctx
->Color
.DitherFlag
;
1237 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1238 goto invalid_enum_error
;
1239 return ctx
->Fog
.Enabled
;
1241 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1242 goto invalid_enum_error
;
1243 return ctx
->Light
.Enabled
;
1252 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1253 goto invalid_enum_error
;
1254 return ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
;
1255 case GL_LINE_SMOOTH
:
1256 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1257 goto invalid_enum_error
;
1258 return ctx
->Line
.SmoothFlag
;
1259 case GL_LINE_STIPPLE
:
1260 if (ctx
->API
!= API_OPENGL_COMPAT
)
1261 goto invalid_enum_error
;
1262 return ctx
->Line
.StippleFlag
;
1263 case GL_INDEX_LOGIC_OP
:
1264 if (ctx
->API
!= API_OPENGL_COMPAT
)
1265 goto invalid_enum_error
;
1266 return ctx
->Color
.IndexLogicOpEnabled
;
1267 case GL_COLOR_LOGIC_OP
:
1268 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1269 goto invalid_enum_error
;
1270 return ctx
->Color
.ColorLogicOpEnabled
;
1271 case GL_MAP1_COLOR_4
:
1272 if (ctx
->API
!= API_OPENGL_COMPAT
)
1273 goto invalid_enum_error
;
1274 return ctx
->Eval
.Map1Color4
;
1276 if (ctx
->API
!= API_OPENGL_COMPAT
)
1277 goto invalid_enum_error
;
1278 return ctx
->Eval
.Map1Index
;
1279 case GL_MAP1_NORMAL
:
1280 if (ctx
->API
!= API_OPENGL_COMPAT
)
1281 goto invalid_enum_error
;
1282 return ctx
->Eval
.Map1Normal
;
1283 case GL_MAP1_TEXTURE_COORD_1
:
1284 if (ctx
->API
!= API_OPENGL_COMPAT
)
1285 goto invalid_enum_error
;
1286 return ctx
->Eval
.Map1TextureCoord1
;
1287 case GL_MAP1_TEXTURE_COORD_2
:
1288 if (ctx
->API
!= API_OPENGL_COMPAT
)
1289 goto invalid_enum_error
;
1290 return ctx
->Eval
.Map1TextureCoord2
;
1291 case GL_MAP1_TEXTURE_COORD_3
:
1292 if (ctx
->API
!= API_OPENGL_COMPAT
)
1293 goto invalid_enum_error
;
1294 return ctx
->Eval
.Map1TextureCoord3
;
1295 case GL_MAP1_TEXTURE_COORD_4
:
1296 if (ctx
->API
!= API_OPENGL_COMPAT
)
1297 goto invalid_enum_error
;
1298 return ctx
->Eval
.Map1TextureCoord4
;
1299 case GL_MAP1_VERTEX_3
:
1300 if (ctx
->API
!= API_OPENGL_COMPAT
)
1301 goto invalid_enum_error
;
1302 return ctx
->Eval
.Map1Vertex3
;
1303 case GL_MAP1_VERTEX_4
:
1304 if (ctx
->API
!= API_OPENGL_COMPAT
)
1305 goto invalid_enum_error
;
1306 return ctx
->Eval
.Map1Vertex4
;
1307 case GL_MAP2_COLOR_4
:
1308 if (ctx
->API
!= API_OPENGL_COMPAT
)
1309 goto invalid_enum_error
;
1310 return ctx
->Eval
.Map2Color4
;
1312 if (ctx
->API
!= API_OPENGL_COMPAT
)
1313 goto invalid_enum_error
;
1314 return ctx
->Eval
.Map2Index
;
1315 case GL_MAP2_NORMAL
:
1316 if (ctx
->API
!= API_OPENGL_COMPAT
)
1317 goto invalid_enum_error
;
1318 return ctx
->Eval
.Map2Normal
;
1319 case GL_MAP2_TEXTURE_COORD_1
:
1320 if (ctx
->API
!= API_OPENGL_COMPAT
)
1321 goto invalid_enum_error
;
1322 return ctx
->Eval
.Map2TextureCoord1
;
1323 case GL_MAP2_TEXTURE_COORD_2
:
1324 if (ctx
->API
!= API_OPENGL_COMPAT
)
1325 goto invalid_enum_error
;
1326 return ctx
->Eval
.Map2TextureCoord2
;
1327 case GL_MAP2_TEXTURE_COORD_3
:
1328 if (ctx
->API
!= API_OPENGL_COMPAT
)
1329 goto invalid_enum_error
;
1330 return ctx
->Eval
.Map2TextureCoord3
;
1331 case GL_MAP2_TEXTURE_COORD_4
:
1332 if (ctx
->API
!= API_OPENGL_COMPAT
)
1333 goto invalid_enum_error
;
1334 return ctx
->Eval
.Map2TextureCoord4
;
1335 case GL_MAP2_VERTEX_3
:
1336 if (ctx
->API
!= API_OPENGL_COMPAT
)
1337 goto invalid_enum_error
;
1338 return ctx
->Eval
.Map2Vertex3
;
1339 case GL_MAP2_VERTEX_4
:
1340 if (ctx
->API
!= API_OPENGL_COMPAT
)
1341 goto invalid_enum_error
;
1342 return ctx
->Eval
.Map2Vertex4
;
1344 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1345 goto invalid_enum_error
;
1346 return ctx
->Transform
.Normalize
;
1347 case GL_POINT_SMOOTH
:
1348 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1349 goto invalid_enum_error
;
1350 return ctx
->Point
.SmoothFlag
;
1351 case GL_POLYGON_SMOOTH
:
1352 if (!_mesa_is_desktop_gl(ctx
))
1353 goto invalid_enum_error
;
1354 return ctx
->Polygon
.SmoothFlag
;
1355 case GL_POLYGON_STIPPLE
:
1356 if (ctx
->API
!= API_OPENGL_COMPAT
)
1357 goto invalid_enum_error
;
1358 return ctx
->Polygon
.StippleFlag
;
1359 case GL_POLYGON_OFFSET_POINT
:
1360 if (!_mesa_is_desktop_gl(ctx
))
1361 goto invalid_enum_error
;
1362 return ctx
->Polygon
.OffsetPoint
;
1363 case GL_POLYGON_OFFSET_LINE
:
1364 if (!_mesa_is_desktop_gl(ctx
))
1365 goto invalid_enum_error
;
1366 return ctx
->Polygon
.OffsetLine
;
1367 case GL_POLYGON_OFFSET_FILL
:
1368 return ctx
->Polygon
.OffsetFill
;
1369 case GL_RESCALE_NORMAL_EXT
:
1370 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1371 goto invalid_enum_error
;
1372 return ctx
->Transform
.RescaleNormals
;
1373 case GL_SCISSOR_TEST
:
1374 return ctx
->Scissor
.EnableFlags
& 1; /* return state for index 0 */
1375 case GL_STENCIL_TEST
:
1376 return ctx
->Stencil
.Enabled
;
1378 if (ctx
->API
!= API_OPENGL_COMPAT
)
1379 goto invalid_enum_error
;
1380 return is_texture_enabled(ctx
, TEXTURE_1D_BIT
);
1382 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1383 goto invalid_enum_error
;
1384 return is_texture_enabled(ctx
, TEXTURE_2D_BIT
);
1386 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1387 goto invalid_enum_error
;
1388 return is_texture_enabled(ctx
, TEXTURE_3D_BIT
);
1389 case GL_TEXTURE_GEN_S
:
1390 case GL_TEXTURE_GEN_T
:
1391 case GL_TEXTURE_GEN_R
:
1392 case GL_TEXTURE_GEN_Q
:
1394 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1396 if (ctx
->API
!= API_OPENGL_COMPAT
)
1397 goto invalid_enum_error
;
1400 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
1401 return (texUnit
->TexGenEnabled
& coordBit
) ? GL_TRUE
: GL_FALSE
;
1405 case GL_TEXTURE_GEN_STR_OES
:
1407 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1409 if (ctx
->API
!= API_OPENGLES
)
1410 goto invalid_enum_error
;
1413 return (texUnit
->TexGenEnabled
& STR_BITS
) == STR_BITS
1414 ? GL_TRUE
: GL_FALSE
;
1418 /* client-side state */
1419 case GL_VERTEX_ARRAY
:
1420 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1421 goto invalid_enum_error
;
1422 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
;
1423 case GL_NORMAL_ARRAY
:
1424 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1425 goto invalid_enum_error
;
1426 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
;
1427 case GL_COLOR_ARRAY
:
1428 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1429 goto invalid_enum_error
;
1430 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
;
1431 case GL_INDEX_ARRAY
:
1432 if (ctx
->API
!= API_OPENGL_COMPAT
)
1433 goto invalid_enum_error
;
1434 return ctx
->Array
.VAO
->
1435 VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
;
1436 case GL_TEXTURE_COORD_ARRAY
:
1437 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1438 goto invalid_enum_error
;
1439 return ctx
->Array
.VAO
->
1440 VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Enabled
;
1441 case GL_EDGE_FLAG_ARRAY
:
1442 if (ctx
->API
!= API_OPENGL_COMPAT
)
1443 goto invalid_enum_error
;
1444 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
;
1445 case GL_FOG_COORDINATE_ARRAY_EXT
:
1446 if (ctx
->API
!= API_OPENGL_COMPAT
)
1447 goto invalid_enum_error
;
1448 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
;
1449 case GL_SECONDARY_COLOR_ARRAY_EXT
:
1450 if (ctx
->API
!= API_OPENGL_COMPAT
)
1451 goto invalid_enum_error
;
1452 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
;
1453 case GL_POINT_SIZE_ARRAY_OES
:
1454 if (ctx
->API
!= API_OPENGLES
)
1455 goto invalid_enum_error
;
1456 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
;
1458 /* GL_ARB_texture_cube_map */
1459 case GL_TEXTURE_CUBE_MAP_ARB
:
1460 CHECK_EXTENSION(ARB_texture_cube_map
);
1461 return is_texture_enabled(ctx
, TEXTURE_CUBE_BIT
);
1463 /* GL_EXT_secondary_color */
1464 case GL_COLOR_SUM_EXT
:
1465 if (ctx
->API
!= API_OPENGL_COMPAT
)
1466 goto invalid_enum_error
;
1467 return ctx
->Fog
.ColorSumEnabled
;
1469 /* GL_ARB_multisample */
1470 case GL_MULTISAMPLE_ARB
:
1471 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1472 goto invalid_enum_error
;
1473 return ctx
->Multisample
.Enabled
;
1474 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
1475 return ctx
->Multisample
.SampleAlphaToCoverage
;
1476 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
1477 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1478 goto invalid_enum_error
;
1479 return ctx
->Multisample
.SampleAlphaToOne
;
1480 case GL_SAMPLE_COVERAGE_ARB
:
1481 return ctx
->Multisample
.SampleCoverage
;
1482 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
1483 if (!_mesa_is_desktop_gl(ctx
))
1484 goto invalid_enum_error
;
1485 return ctx
->Multisample
.SampleCoverageInvert
;
1487 /* GL_IBM_rasterpos_clip */
1488 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
1489 if (ctx
->API
!= API_OPENGL_COMPAT
)
1490 goto invalid_enum_error
;
1491 return ctx
->Transform
.RasterPositionUnclipped
;
1493 /* GL_NV_point_sprite */
1494 case GL_POINT_SPRITE_NV
:
1495 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1496 goto invalid_enum_error
;
1497 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
)
1498 return ctx
->Point
.PointSprite
;
1500 case GL_VERTEX_PROGRAM_ARB
:
1501 if (ctx
->API
!= API_OPENGL_COMPAT
)
1502 goto invalid_enum_error
;
1503 CHECK_EXTENSION(ARB_vertex_program
);
1504 return ctx
->VertexProgram
.Enabled
;
1505 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
1506 /* This was added with ARB_vertex_program, but it is also used with
1507 * GLSL vertex shaders on desktop.
1509 if (!_mesa_is_desktop_gl(ctx
))
1510 goto invalid_enum_error
;
1511 CHECK_EXTENSION(ARB_vertex_program
);
1512 return ctx
->VertexProgram
.PointSizeEnabled
;
1513 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
1514 if (ctx
->API
!= API_OPENGL_COMPAT
)
1515 goto invalid_enum_error
;
1516 CHECK_EXTENSION(ARB_vertex_program
);
1517 return ctx
->VertexProgram
.TwoSideEnabled
;
1519 /* GL_NV_texture_rectangle */
1520 case GL_TEXTURE_RECTANGLE_NV
:
1521 if (ctx
->API
!= API_OPENGL_COMPAT
)
1522 goto invalid_enum_error
;
1523 CHECK_EXTENSION(NV_texture_rectangle
);
1524 return is_texture_enabled(ctx
, TEXTURE_RECT_BIT
);
1526 /* GL_EXT_stencil_two_side */
1527 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
1528 if (ctx
->API
!= API_OPENGL_COMPAT
)
1529 goto invalid_enum_error
;
1530 CHECK_EXTENSION(EXT_stencil_two_side
);
1531 return ctx
->Stencil
.TestTwoSide
;
1533 case GL_FRAGMENT_PROGRAM_ARB
:
1534 if (ctx
->API
!= API_OPENGL_COMPAT
)
1535 goto invalid_enum_error
;
1536 return ctx
->FragmentProgram
.Enabled
;
1538 /* GL_EXT_depth_bounds_test */
1539 case GL_DEPTH_BOUNDS_TEST_EXT
:
1540 if (!_mesa_is_desktop_gl(ctx
))
1541 goto invalid_enum_error
;
1542 CHECK_EXTENSION(EXT_depth_bounds_test
);
1543 return ctx
->Depth
.BoundsTest
;
1545 /* GL_ARB_depth_clamp */
1546 case GL_DEPTH_CLAMP
:
1547 if (!_mesa_is_desktop_gl(ctx
))
1548 goto invalid_enum_error
;
1549 CHECK_EXTENSION(ARB_depth_clamp
);
1550 return ctx
->Transform
.DepthClamp
;
1552 case GL_FRAGMENT_SHADER_ATI
:
1553 if (ctx
->API
!= API_OPENGL_COMPAT
)
1554 goto invalid_enum_error
;
1555 CHECK_EXTENSION(ATI_fragment_shader
);
1556 return ctx
->ATIFragmentShader
.Enabled
;
1558 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1559 if (!_mesa_is_desktop_gl(ctx
))
1560 goto invalid_enum_error
;
1561 CHECK_EXTENSION(ARB_seamless_cube_map
);
1562 return ctx
->Texture
.CubeMapSeamless
;
1564 case GL_RASTERIZER_DISCARD
:
1565 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1566 goto invalid_enum_error
;
1567 CHECK_EXTENSION(EXT_transform_feedback
);
1568 return ctx
->RasterDiscard
;
1570 /* GL_NV_primitive_restart */
1571 case GL_PRIMITIVE_RESTART_NV
:
1572 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.NV_primitive_restart
) {
1573 goto invalid_enum_error
;
1575 return ctx
->Array
.PrimitiveRestart
;
1577 /* GL 3.1 primitive restart */
1578 case GL_PRIMITIVE_RESTART
:
1579 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
1580 goto invalid_enum_error
;
1582 return ctx
->Array
.PrimitiveRestart
;
1584 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
1585 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
) {
1586 goto invalid_enum_error
;
1588 return ctx
->Array
.PrimitiveRestartFixedIndex
;
1590 /* GL3.0 - GL_framebuffer_sRGB */
1591 case GL_FRAMEBUFFER_SRGB_EXT
:
1592 if (!_mesa_is_desktop_gl(ctx
))
1593 goto invalid_enum_error
;
1594 CHECK_EXTENSION(EXT_framebuffer_sRGB
);
1595 return ctx
->Color
.sRGBEnabled
;
1597 /* GL_OES_EGL_image_external */
1598 case GL_TEXTURE_EXTERNAL_OES
:
1599 if (!_mesa_is_gles(ctx
))
1600 goto invalid_enum_error
;
1601 CHECK_EXTENSION(OES_EGL_image_external
);
1602 return is_texture_enabled(ctx
, TEXTURE_EXTERNAL_BIT
);
1604 /* ARB_texture_multisample */
1605 case GL_SAMPLE_MASK
:
1606 if (!_mesa_is_desktop_gl(ctx
))
1607 goto invalid_enum_error
;
1608 CHECK_EXTENSION(ARB_texture_multisample
);
1609 return ctx
->Multisample
.SampleMask
;
1611 /* ARB_sample_shading */
1612 case GL_SAMPLE_SHADING
:
1613 if (!_mesa_is_desktop_gl(ctx
))
1614 goto invalid_enum_error
;
1615 CHECK_EXTENSION(ARB_sample_shading
);
1616 return ctx
->Multisample
.SampleShading
;
1619 goto invalid_enum_error
;
1625 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabled(%s)",
1626 _mesa_lookup_enum_by_nr(cap
));