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.
34 #include "debug_output.h"
40 #include "api_arrayelt.h"
45 #define CHECK_EXTENSION(EXTNAME, CAP) \
46 if (!ctx->Extensions.EXTNAME) { \
47 goto invalid_enum_error; \
52 update_derived_primitive_restart_state(struct gl_context
*ctx
)
54 /* Update derived primitive restart state.
56 ctx
->Array
._PrimitiveRestart
= ctx
->Array
.PrimitiveRestart
57 || ctx
->Array
.PrimitiveRestartFixedIndex
;
61 * Helper to enable/disable client-side state.
64 client_state(struct gl_context
*ctx
, GLenum cap
, GLboolean state
)
66 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
72 var
= &vao
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
;
76 var
= &vao
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
;
77 flag
= VERT_BIT_NORMAL
;
80 var
= &vao
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
;
81 flag
= VERT_BIT_COLOR0
;
84 var
= &vao
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
;
85 flag
= VERT_BIT_COLOR_INDEX
;
87 case GL_TEXTURE_COORD_ARRAY
:
88 var
= &vao
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Enabled
;
89 flag
= VERT_BIT_TEX(ctx
->Array
.ActiveTexture
);
91 case GL_EDGE_FLAG_ARRAY
:
92 var
= &vao
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
;
93 flag
= VERT_BIT_EDGEFLAG
;
95 case GL_FOG_COORDINATE_ARRAY_EXT
:
96 var
= &vao
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
;
99 case GL_SECONDARY_COLOR_ARRAY_EXT
:
100 var
= &vao
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
;
101 flag
= VERT_BIT_COLOR1
;
104 case GL_POINT_SIZE_ARRAY_OES
:
105 var
= &vao
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
;
106 flag
= VERT_BIT_POINT_SIZE
;
107 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
108 ctx
->VertexProgram
.PointSizeEnabled
= state
;
111 /* GL_NV_primitive_restart */
112 case GL_PRIMITIVE_RESTART_NV
:
113 if (!ctx
->Extensions
.NV_primitive_restart
) {
114 goto invalid_enum_error
;
116 var
= &ctx
->Array
.PrimitiveRestart
;
121 goto invalid_enum_error
;
127 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
129 _ae_invalidate_state(ctx
, _NEW_ARRAY
);
133 update_derived_primitive_restart_state(ctx
);
136 vao
->_Enabled
|= flag
;
138 vao
->_Enabled
&= ~flag
;
140 vao
->NewArrays
|= flag
;
142 if (ctx
->Driver
.Enable
) {
143 ctx
->Driver
.Enable( ctx
, cap
, state
);
149 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%sClientState(%s)",
150 state
? "Enable" : "Disable", _mesa_enum_to_string(cap
));
155 * Enable GL capability.
156 * \param cap state to enable/disable.
158 * Get's the current context, assures that we're outside glBegin()/glEnd() and
159 * calls client_state().
162 _mesa_EnableClientState( GLenum cap
)
164 GET_CURRENT_CONTEXT(ctx
);
165 client_state( ctx
, cap
, GL_TRUE
);
170 * Disable GL capability.
171 * \param cap state to enable/disable.
173 * Get's the current context, assures that we're outside glBegin()/glEnd() and
174 * calls client_state().
177 _mesa_DisableClientState( GLenum cap
)
179 GET_CURRENT_CONTEXT(ctx
);
180 client_state( ctx
, cap
, GL_FALSE
);
184 #undef CHECK_EXTENSION
185 #define CHECK_EXTENSION(EXTNAME, CAP) \
186 if (!ctx->Extensions.EXTNAME) { \
187 goto invalid_enum_error; \
190 #define CHECK_EXTENSION2(EXT1, EXT2, CAP) \
191 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
192 goto invalid_enum_error; \
196 * Return pointer to current texture unit for setting/getting coordinate
198 * Note that we'll set GL_INVALID_OPERATION and return NULL if the active
199 * texture unit is higher than the number of supported coordinate units.
201 static struct gl_texture_unit
*
202 get_texcoord_unit(struct gl_context
*ctx
)
204 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
205 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glEnable/Disable(texcoord unit)");
209 return &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
215 * Helper function to enable or disable a texture target.
216 * \param bit one of the TEXTURE_x_BIT values
217 * \return GL_TRUE if state is changing or GL_FALSE if no change
220 enable_texture(struct gl_context
*ctx
, GLboolean state
, GLbitfield texBit
)
222 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
223 const GLbitfield newenabled
= state
224 ? (texUnit
->Enabled
| texBit
) : (texUnit
->Enabled
& ~texBit
);
226 if (texUnit
->Enabled
== newenabled
)
229 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
230 texUnit
->Enabled
= newenabled
;
236 * Helper function to enable or disable GL_MULTISAMPLE, skipping the check for
237 * whether the API supports it (GLES doesn't).
240 _mesa_set_multisample(struct gl_context
*ctx
, GLboolean state
)
242 if (ctx
->Multisample
.Enabled
== state
)
244 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
245 ctx
->Multisample
.Enabled
= state
;
247 if (ctx
->Driver
.Enable
) {
248 ctx
->Driver
.Enable(ctx
, GL_MULTISAMPLE
, state
);
253 * Helper function to enable or disable GL_FRAMEBUFFER_SRGB, skipping the
254 * check for whether the API supports it (GLES doesn't).
257 _mesa_set_framebuffer_srgb(struct gl_context
*ctx
, GLboolean state
)
259 if (ctx
->Color
.sRGBEnabled
== state
)
261 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
262 ctx
->Color
.sRGBEnabled
= state
;
264 if (ctx
->Driver
.Enable
) {
265 ctx
->Driver
.Enable(ctx
, GL_FRAMEBUFFER_SRGB
, state
);
270 * Helper function to enable or disable state.
272 * \param ctx GL context.
273 * \param cap the state to enable/disable
274 * \param state whether to enable or disable the specified capability.
276 * Updates the current context and flushes the vertices as needed. For
277 * capabilities associated with extensions it verifies that those extensions
278 * are effectivly present before updating. Notifies the driver via
279 * dd_function_table::Enable.
282 _mesa_set_enable(struct gl_context
*ctx
, GLenum cap
, GLboolean state
)
284 if (MESA_VERBOSE
& VERBOSE_API
)
285 _mesa_debug(ctx
, "%s %s (newstate is %x)\n",
286 state
? "glEnable" : "glDisable",
287 _mesa_enum_to_string(cap
),
292 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
293 goto invalid_enum_error
;
294 if (ctx
->Color
.AlphaEnabled
== state
)
296 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
297 ctx
->Color
.AlphaEnabled
= state
;
300 if (ctx
->API
!= API_OPENGL_COMPAT
)
301 goto invalid_enum_error
;
302 if (ctx
->Eval
.AutoNormal
== state
)
304 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
305 ctx
->Eval
.AutoNormal
= state
;
309 GLbitfield newEnabled
=
310 state
* ((1 << ctx
->Const
.MaxDrawBuffers
) - 1);
311 if (newEnabled
!= ctx
->Color
.BlendEnabled
) {
312 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
313 ctx
->Color
.BlendEnabled
= newEnabled
;
317 case GL_CLIP_DISTANCE0
: /* aka GL_CLIP_PLANE0 */
318 case GL_CLIP_DISTANCE1
:
319 case GL_CLIP_DISTANCE2
:
320 case GL_CLIP_DISTANCE3
:
321 case GL_CLIP_DISTANCE4
:
322 case GL_CLIP_DISTANCE5
:
323 case GL_CLIP_DISTANCE6
:
324 case GL_CLIP_DISTANCE7
:
326 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
328 if (p
>= ctx
->Const
.MaxClipPlanes
)
329 goto invalid_enum_error
;
331 if ((ctx
->Transform
.ClipPlanesEnabled
& (1 << p
))
332 == ((GLuint
) state
<< p
))
335 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
338 ctx
->Transform
.ClipPlanesEnabled
|= (1 << p
);
339 _mesa_update_clip_plane(ctx
, p
);
342 ctx
->Transform
.ClipPlanesEnabled
&= ~(1 << p
);
346 case GL_COLOR_MATERIAL
:
347 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
348 goto invalid_enum_error
;
349 if (ctx
->Light
.ColorMaterialEnabled
== state
)
351 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
352 FLUSH_CURRENT(ctx
, 0);
353 ctx
->Light
.ColorMaterialEnabled
= state
;
355 _mesa_update_color_material( ctx
,
356 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
] );
360 if (ctx
->Polygon
.CullFlag
== state
)
362 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
363 ctx
->Polygon
.CullFlag
= state
;
366 if (ctx
->Depth
.Test
== state
)
368 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
369 ctx
->Depth
.Test
= state
;
371 case GL_DEBUG_OUTPUT
:
372 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
:
373 _mesa_set_debug_state_int(ctx
, cap
, state
);
376 if (ctx
->Color
.DitherFlag
== state
)
378 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
379 ctx
->Color
.DitherFlag
= state
;
382 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
383 goto invalid_enum_error
;
384 if (ctx
->Fog
.Enabled
== state
)
386 FLUSH_VERTICES(ctx
, _NEW_FOG
);
387 ctx
->Fog
.Enabled
= state
;
397 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
398 goto invalid_enum_error
;
399 if (ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
== state
)
401 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
402 ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
= state
;
404 ctx
->Light
._EnabledLights
|= 1u << (cap
- GL_LIGHT0
);
407 ctx
->Light
._EnabledLights
&= ~(1u << (cap
- GL_LIGHT0
));
411 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
412 goto invalid_enum_error
;
413 if (ctx
->Light
.Enabled
== state
)
415 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
416 ctx
->Light
.Enabled
= state
;
419 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
420 goto invalid_enum_error
;
421 if (ctx
->Line
.SmoothFlag
== state
)
423 FLUSH_VERTICES(ctx
, _NEW_LINE
);
424 ctx
->Line
.SmoothFlag
= state
;
426 case GL_LINE_STIPPLE
:
427 if (ctx
->API
!= API_OPENGL_COMPAT
)
428 goto invalid_enum_error
;
429 if (ctx
->Line
.StippleFlag
== state
)
431 FLUSH_VERTICES(ctx
, _NEW_LINE
);
432 ctx
->Line
.StippleFlag
= state
;
434 case GL_INDEX_LOGIC_OP
:
435 if (ctx
->API
!= API_OPENGL_COMPAT
)
436 goto invalid_enum_error
;
437 if (ctx
->Color
.IndexLogicOpEnabled
== state
)
439 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
440 ctx
->Color
.IndexLogicOpEnabled
= state
;
442 case GL_COLOR_LOGIC_OP
:
443 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
444 goto invalid_enum_error
;
445 if (ctx
->Color
.ColorLogicOpEnabled
== state
)
447 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
448 ctx
->Color
.ColorLogicOpEnabled
= state
;
450 case GL_MAP1_COLOR_4
:
451 if (ctx
->API
!= API_OPENGL_COMPAT
)
452 goto invalid_enum_error
;
453 if (ctx
->Eval
.Map1Color4
== state
)
455 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
456 ctx
->Eval
.Map1Color4
= state
;
459 if (ctx
->API
!= API_OPENGL_COMPAT
)
460 goto invalid_enum_error
;
461 if (ctx
->Eval
.Map1Index
== state
)
463 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
464 ctx
->Eval
.Map1Index
= state
;
467 if (ctx
->API
!= API_OPENGL_COMPAT
)
468 goto invalid_enum_error
;
469 if (ctx
->Eval
.Map1Normal
== state
)
471 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
472 ctx
->Eval
.Map1Normal
= state
;
474 case GL_MAP1_TEXTURE_COORD_1
:
475 if (ctx
->API
!= API_OPENGL_COMPAT
)
476 goto invalid_enum_error
;
477 if (ctx
->Eval
.Map1TextureCoord1
== state
)
479 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
480 ctx
->Eval
.Map1TextureCoord1
= state
;
482 case GL_MAP1_TEXTURE_COORD_2
:
483 if (ctx
->API
!= API_OPENGL_COMPAT
)
484 goto invalid_enum_error
;
485 if (ctx
->Eval
.Map1TextureCoord2
== state
)
487 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
488 ctx
->Eval
.Map1TextureCoord2
= state
;
490 case GL_MAP1_TEXTURE_COORD_3
:
491 if (ctx
->API
!= API_OPENGL_COMPAT
)
492 goto invalid_enum_error
;
493 if (ctx
->Eval
.Map1TextureCoord3
== state
)
495 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
496 ctx
->Eval
.Map1TextureCoord3
= state
;
498 case GL_MAP1_TEXTURE_COORD_4
:
499 if (ctx
->API
!= API_OPENGL_COMPAT
)
500 goto invalid_enum_error
;
501 if (ctx
->Eval
.Map1TextureCoord4
== state
)
503 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
504 ctx
->Eval
.Map1TextureCoord4
= state
;
506 case GL_MAP1_VERTEX_3
:
507 if (ctx
->API
!= API_OPENGL_COMPAT
)
508 goto invalid_enum_error
;
509 if (ctx
->Eval
.Map1Vertex3
== state
)
511 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
512 ctx
->Eval
.Map1Vertex3
= state
;
514 case GL_MAP1_VERTEX_4
:
515 if (ctx
->API
!= API_OPENGL_COMPAT
)
516 goto invalid_enum_error
;
517 if (ctx
->Eval
.Map1Vertex4
== state
)
519 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
520 ctx
->Eval
.Map1Vertex4
= state
;
522 case GL_MAP2_COLOR_4
:
523 if (ctx
->API
!= API_OPENGL_COMPAT
)
524 goto invalid_enum_error
;
525 if (ctx
->Eval
.Map2Color4
== state
)
527 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
528 ctx
->Eval
.Map2Color4
= state
;
531 if (ctx
->API
!= API_OPENGL_COMPAT
)
532 goto invalid_enum_error
;
533 if (ctx
->Eval
.Map2Index
== state
)
535 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
536 ctx
->Eval
.Map2Index
= state
;
539 if (ctx
->API
!= API_OPENGL_COMPAT
)
540 goto invalid_enum_error
;
541 if (ctx
->Eval
.Map2Normal
== state
)
543 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
544 ctx
->Eval
.Map2Normal
= state
;
546 case GL_MAP2_TEXTURE_COORD_1
:
547 if (ctx
->API
!= API_OPENGL_COMPAT
)
548 goto invalid_enum_error
;
549 if (ctx
->Eval
.Map2TextureCoord1
== state
)
551 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
552 ctx
->Eval
.Map2TextureCoord1
= state
;
554 case GL_MAP2_TEXTURE_COORD_2
:
555 if (ctx
->API
!= API_OPENGL_COMPAT
)
556 goto invalid_enum_error
;
557 if (ctx
->Eval
.Map2TextureCoord2
== state
)
559 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
560 ctx
->Eval
.Map2TextureCoord2
= state
;
562 case GL_MAP2_TEXTURE_COORD_3
:
563 if (ctx
->API
!= API_OPENGL_COMPAT
)
564 goto invalid_enum_error
;
565 if (ctx
->Eval
.Map2TextureCoord3
== state
)
567 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
568 ctx
->Eval
.Map2TextureCoord3
= state
;
570 case GL_MAP2_TEXTURE_COORD_4
:
571 if (ctx
->API
!= API_OPENGL_COMPAT
)
572 goto invalid_enum_error
;
573 if (ctx
->Eval
.Map2TextureCoord4
== state
)
575 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
576 ctx
->Eval
.Map2TextureCoord4
= state
;
578 case GL_MAP2_VERTEX_3
:
579 if (ctx
->API
!= API_OPENGL_COMPAT
)
580 goto invalid_enum_error
;
581 if (ctx
->Eval
.Map2Vertex3
== state
)
583 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
584 ctx
->Eval
.Map2Vertex3
= state
;
586 case GL_MAP2_VERTEX_4
:
587 if (ctx
->API
!= API_OPENGL_COMPAT
)
588 goto invalid_enum_error
;
589 if (ctx
->Eval
.Map2Vertex4
== state
)
591 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
592 ctx
->Eval
.Map2Vertex4
= state
;
595 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
596 goto invalid_enum_error
;
597 if (ctx
->Transform
.Normalize
== state
)
599 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
600 ctx
->Transform
.Normalize
= state
;
602 case GL_POINT_SMOOTH
:
603 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
604 goto invalid_enum_error
;
605 if (ctx
->Point
.SmoothFlag
== state
)
607 FLUSH_VERTICES(ctx
, _NEW_POINT
);
608 ctx
->Point
.SmoothFlag
= state
;
610 case GL_POLYGON_SMOOTH
:
611 if (!_mesa_is_desktop_gl(ctx
))
612 goto invalid_enum_error
;
613 if (ctx
->Polygon
.SmoothFlag
== state
)
615 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
616 ctx
->Polygon
.SmoothFlag
= state
;
618 case GL_POLYGON_STIPPLE
:
619 if (ctx
->API
!= API_OPENGL_COMPAT
)
620 goto invalid_enum_error
;
621 if (ctx
->Polygon
.StippleFlag
== state
)
623 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
624 ctx
->Polygon
.StippleFlag
= state
;
626 case GL_POLYGON_OFFSET_POINT
:
627 if (!_mesa_is_desktop_gl(ctx
))
628 goto invalid_enum_error
;
629 if (ctx
->Polygon
.OffsetPoint
== state
)
631 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
632 ctx
->Polygon
.OffsetPoint
= state
;
634 case GL_POLYGON_OFFSET_LINE
:
635 if (!_mesa_is_desktop_gl(ctx
))
636 goto invalid_enum_error
;
637 if (ctx
->Polygon
.OffsetLine
== state
)
639 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
640 ctx
->Polygon
.OffsetLine
= state
;
642 case GL_POLYGON_OFFSET_FILL
:
643 if (ctx
->Polygon
.OffsetFill
== state
)
645 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
646 ctx
->Polygon
.OffsetFill
= state
;
648 case GL_RESCALE_NORMAL_EXT
:
649 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
650 goto invalid_enum_error
;
651 if (ctx
->Transform
.RescaleNormals
== state
)
653 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
654 ctx
->Transform
.RescaleNormals
= state
;
656 case GL_SCISSOR_TEST
:
658 /* Must expand glEnable to all scissors */
659 GLbitfield newEnabled
=
660 state
* ((1 << ctx
->Const
.MaxViewports
) - 1);
661 if (newEnabled
!= ctx
->Scissor
.EnableFlags
) {
662 FLUSH_VERTICES(ctx
, _NEW_SCISSOR
);
663 ctx
->Scissor
.EnableFlags
= newEnabled
;
667 case GL_STENCIL_TEST
:
668 if (ctx
->Stencil
.Enabled
== state
)
670 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
671 ctx
->Stencil
.Enabled
= state
;
674 if (ctx
->API
!= API_OPENGL_COMPAT
)
675 goto invalid_enum_error
;
676 if (!enable_texture(ctx
, state
, TEXTURE_1D_BIT
)) {
681 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
682 goto invalid_enum_error
;
683 if (!enable_texture(ctx
, state
, TEXTURE_2D_BIT
)) {
688 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
689 goto invalid_enum_error
;
690 if (!enable_texture(ctx
, state
, TEXTURE_3D_BIT
)) {
694 case GL_TEXTURE_GEN_S
:
695 case GL_TEXTURE_GEN_T
:
696 case GL_TEXTURE_GEN_R
:
697 case GL_TEXTURE_GEN_Q
:
699 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
701 if (ctx
->API
!= API_OPENGL_COMPAT
)
702 goto invalid_enum_error
;
705 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
706 GLbitfield newenabled
= texUnit
->TexGenEnabled
& ~coordBit
;
708 newenabled
|= coordBit
;
709 if (texUnit
->TexGenEnabled
== newenabled
)
711 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
712 texUnit
->TexGenEnabled
= newenabled
;
717 case GL_TEXTURE_GEN_STR_OES
:
718 /* disable S, T, and R at the same time */
720 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
722 if (ctx
->API
!= API_OPENGLES
)
723 goto invalid_enum_error
;
727 texUnit
->TexGenEnabled
& ~STR_BITS
;
729 newenabled
|= STR_BITS
;
730 if (texUnit
->TexGenEnabled
== newenabled
)
732 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
733 texUnit
->TexGenEnabled
= newenabled
;
738 /* client-side state */
739 case GL_VERTEX_ARRAY
:
740 case GL_NORMAL_ARRAY
:
742 case GL_TEXTURE_COORD_ARRAY
:
743 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
744 goto invalid_enum_error
;
745 client_state( ctx
, cap
, state
);
748 case GL_EDGE_FLAG_ARRAY
:
749 case GL_FOG_COORDINATE_ARRAY_EXT
:
750 case GL_SECONDARY_COLOR_ARRAY_EXT
:
751 if (ctx
->API
!= API_OPENGL_COMPAT
)
752 goto invalid_enum_error
;
753 client_state( ctx
, cap
, state
);
755 case GL_POINT_SIZE_ARRAY_OES
:
756 if (ctx
->API
!= API_OPENGLES
)
757 goto invalid_enum_error
;
758 client_state( ctx
, cap
, state
);
761 /* GL_ARB_texture_cube_map */
762 case GL_TEXTURE_CUBE_MAP
:
763 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
764 goto invalid_enum_error
;
765 CHECK_EXTENSION(ARB_texture_cube_map
, cap
);
766 if (!enable_texture(ctx
, state
, TEXTURE_CUBE_BIT
)) {
771 /* GL_EXT_secondary_color */
772 case GL_COLOR_SUM_EXT
:
773 if (ctx
->API
!= API_OPENGL_COMPAT
)
774 goto invalid_enum_error
;
775 if (ctx
->Fog
.ColorSumEnabled
== state
)
777 FLUSH_VERTICES(ctx
, _NEW_FOG
);
778 ctx
->Fog
.ColorSumEnabled
= state
;
781 /* GL_ARB_multisample */
782 case GL_MULTISAMPLE_ARB
:
783 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
784 goto invalid_enum_error
;
785 _mesa_set_multisample(ctx
, state
);
787 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
788 if (ctx
->Multisample
.SampleAlphaToCoverage
== state
)
790 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
791 ctx
->Multisample
.SampleAlphaToCoverage
= state
;
793 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
794 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
795 goto invalid_enum_error
;
796 if (ctx
->Multisample
.SampleAlphaToOne
== state
)
798 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
799 ctx
->Multisample
.SampleAlphaToOne
= state
;
801 case GL_SAMPLE_COVERAGE_ARB
:
802 if (ctx
->Multisample
.SampleCoverage
== state
)
804 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
805 ctx
->Multisample
.SampleCoverage
= state
;
807 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
808 if (!_mesa_is_desktop_gl(ctx
))
809 goto invalid_enum_error
;
810 if (ctx
->Multisample
.SampleCoverageInvert
== state
)
812 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
813 ctx
->Multisample
.SampleCoverageInvert
= state
;
816 /* GL_ARB_sample_shading */
817 case GL_SAMPLE_SHADING
:
818 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
819 goto invalid_enum_error
;
820 CHECK_EXTENSION(ARB_sample_shading
, cap
);
821 if (ctx
->Multisample
.SampleShading
== state
)
823 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
824 ctx
->Multisample
.SampleShading
= state
;
827 /* GL_IBM_rasterpos_clip */
828 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
829 if (ctx
->API
!= API_OPENGL_COMPAT
)
830 goto invalid_enum_error
;
831 if (ctx
->Transform
.RasterPositionUnclipped
== state
)
833 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
834 ctx
->Transform
.RasterPositionUnclipped
= state
;
837 /* GL_NV_point_sprite */
838 case GL_POINT_SPRITE_NV
:
839 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
840 goto invalid_enum_error
;
841 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
, cap
);
842 if (ctx
->Point
.PointSprite
== state
)
844 FLUSH_VERTICES(ctx
, _NEW_POINT
);
845 ctx
->Point
.PointSprite
= state
;
848 case GL_VERTEX_PROGRAM_ARB
:
849 if (ctx
->API
!= API_OPENGL_COMPAT
)
850 goto invalid_enum_error
;
851 CHECK_EXTENSION(ARB_vertex_program
, cap
);
852 if (ctx
->VertexProgram
.Enabled
== state
)
854 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
855 ctx
->VertexProgram
.Enabled
= state
;
857 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
858 /* This was added with ARB_vertex_program, but it is also used with
859 * GLSL vertex shaders on desktop.
861 if (!_mesa_is_desktop_gl(ctx
))
862 goto invalid_enum_error
;
863 CHECK_EXTENSION(ARB_vertex_program
, cap
);
864 if (ctx
->VertexProgram
.PointSizeEnabled
== state
)
866 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
867 ctx
->VertexProgram
.PointSizeEnabled
= state
;
869 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
870 if (ctx
->API
!= API_OPENGL_COMPAT
)
871 goto invalid_enum_error
;
872 CHECK_EXTENSION(ARB_vertex_program
, cap
);
873 if (ctx
->VertexProgram
.TwoSideEnabled
== state
)
875 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
876 ctx
->VertexProgram
.TwoSideEnabled
= state
;
879 /* GL_NV_texture_rectangle */
880 case GL_TEXTURE_RECTANGLE_NV
:
881 if (ctx
->API
!= API_OPENGL_COMPAT
)
882 goto invalid_enum_error
;
883 CHECK_EXTENSION(NV_texture_rectangle
, cap
);
884 if (!enable_texture(ctx
, state
, TEXTURE_RECT_BIT
)) {
889 /* GL_EXT_stencil_two_side */
890 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
891 if (ctx
->API
!= API_OPENGL_COMPAT
)
892 goto invalid_enum_error
;
893 CHECK_EXTENSION(EXT_stencil_two_side
, cap
);
894 if (ctx
->Stencil
.TestTwoSide
== state
)
896 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
897 ctx
->Stencil
.TestTwoSide
= state
;
899 ctx
->Stencil
._BackFace
= 2;
901 ctx
->Stencil
._BackFace
= 1;
905 case GL_FRAGMENT_PROGRAM_ARB
:
906 if (ctx
->API
!= API_OPENGL_COMPAT
)
907 goto invalid_enum_error
;
908 CHECK_EXTENSION(ARB_fragment_program
, cap
);
909 if (ctx
->FragmentProgram
.Enabled
== state
)
911 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
912 ctx
->FragmentProgram
.Enabled
= state
;
915 /* GL_EXT_depth_bounds_test */
916 case GL_DEPTH_BOUNDS_TEST_EXT
:
917 if (!_mesa_is_desktop_gl(ctx
))
918 goto invalid_enum_error
;
919 CHECK_EXTENSION(EXT_depth_bounds_test
, cap
);
920 if (ctx
->Depth
.BoundsTest
== state
)
922 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
923 ctx
->Depth
.BoundsTest
= state
;
927 if (!_mesa_is_desktop_gl(ctx
))
928 goto invalid_enum_error
;
929 CHECK_EXTENSION(ARB_depth_clamp
, cap
);
930 if (ctx
->Transform
.DepthClamp
== state
)
932 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
933 ctx
->Transform
.DepthClamp
= state
;
936 case GL_FRAGMENT_SHADER_ATI
:
937 if (ctx
->API
!= API_OPENGL_COMPAT
)
938 goto invalid_enum_error
;
939 CHECK_EXTENSION(ATI_fragment_shader
, cap
);
940 if (ctx
->ATIFragmentShader
.Enabled
== state
)
942 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
943 ctx
->ATIFragmentShader
.Enabled
= state
;
946 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
947 if (!_mesa_is_desktop_gl(ctx
))
948 goto invalid_enum_error
;
949 CHECK_EXTENSION(ARB_seamless_cube_map
, cap
);
950 if (ctx
->Texture
.CubeMapSeamless
!= state
) {
951 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
952 ctx
->Texture
.CubeMapSeamless
= state
;
956 case GL_RASTERIZER_DISCARD
:
957 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
958 goto invalid_enum_error
;
959 CHECK_EXTENSION(EXT_transform_feedback
, cap
);
960 if (ctx
->RasterDiscard
!= state
) {
961 FLUSH_VERTICES(ctx
, 0);
962 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewRasterizerDiscard
;
963 ctx
->RasterDiscard
= state
;
967 /* GL 3.1 primitive restart. Note: this enum is different from
968 * GL_PRIMITIVE_RESTART_NV (which is client state).
970 case GL_PRIMITIVE_RESTART
:
971 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
972 goto invalid_enum_error
;
974 if (ctx
->Array
.PrimitiveRestart
!= state
) {
975 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
976 ctx
->Array
.PrimitiveRestart
= state
;
977 update_derived_primitive_restart_state(ctx
);
981 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
982 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
)
983 goto invalid_enum_error
;
984 if (ctx
->Array
.PrimitiveRestartFixedIndex
!= state
) {
985 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
986 ctx
->Array
.PrimitiveRestartFixedIndex
= state
;
987 update_derived_primitive_restart_state(ctx
);
991 /* GL3.0 - GL_framebuffer_sRGB */
992 case GL_FRAMEBUFFER_SRGB_EXT
:
993 if (!_mesa_is_desktop_gl(ctx
))
994 goto invalid_enum_error
;
995 CHECK_EXTENSION(EXT_framebuffer_sRGB
, cap
);
996 _mesa_set_framebuffer_srgb(ctx
, state
);
999 /* GL_OES_EGL_image_external */
1000 case GL_TEXTURE_EXTERNAL_OES
:
1001 if (!_mesa_is_gles(ctx
))
1002 goto invalid_enum_error
;
1003 CHECK_EXTENSION(OES_EGL_image_external
, cap
);
1004 if (!enable_texture(ctx
, state
, TEXTURE_EXTERNAL_BIT
)) {
1009 /* ARB_texture_multisample */
1010 case GL_SAMPLE_MASK
:
1011 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
1012 goto invalid_enum_error
;
1013 CHECK_EXTENSION(ARB_texture_multisample
, cap
);
1014 if (ctx
->Multisample
.SampleMask
== state
)
1016 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
1017 ctx
->Multisample
.SampleMask
= state
;
1020 case GL_BLEND_ADVANCED_COHERENT_KHR
:
1021 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent
, cap
);
1022 if (ctx
->Color
.BlendCoherent
== state
)
1024 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
1025 ctx
->Color
.BlendCoherent
= state
;
1029 goto invalid_enum_error
;
1032 if (ctx
->Driver
.Enable
) {
1033 ctx
->Driver
.Enable( ctx
, cap
, state
);
1039 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%s(%s)",
1040 state
? "Enable" : "Disable", _mesa_enum_to_string(cap
));
1045 * Enable GL capability. Called by glEnable()
1046 * \param cap state to enable.
1049 _mesa_Enable( GLenum cap
)
1051 GET_CURRENT_CONTEXT(ctx
);
1053 _mesa_set_enable( ctx
, cap
, GL_TRUE
);
1058 * Disable GL capability. Called by glDisable()
1059 * \param cap state to disable.
1062 _mesa_Disable( GLenum cap
)
1064 GET_CURRENT_CONTEXT(ctx
);
1066 _mesa_set_enable( ctx
, cap
, GL_FALSE
);
1072 * Enable/disable an indexed state var.
1075 _mesa_set_enablei(struct gl_context
*ctx
, GLenum cap
,
1076 GLuint index
, GLboolean state
)
1078 assert(state
== 0 || state
== 1);
1081 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
1082 goto invalid_enum_error
;
1084 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1085 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1086 state
? "glEnableIndexed" : "glDisableIndexed", index
);
1089 if (((ctx
->Color
.BlendEnabled
>> index
) & 1) != state
) {
1090 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
1092 ctx
->Color
.BlendEnabled
|= (1 << index
);
1094 ctx
->Color
.BlendEnabled
&= ~(1 << index
);
1097 case GL_SCISSOR_TEST
:
1098 if (index
>= ctx
->Const
.MaxViewports
) {
1099 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1100 state
? "glEnablei" : "glDisablei", index
);
1103 if (((ctx
->Scissor
.EnableFlags
>> index
) & 1) != state
) {
1104 FLUSH_VERTICES(ctx
, _NEW_SCISSOR
);
1106 ctx
->Scissor
.EnableFlags
|= (1 << index
);
1108 ctx
->Scissor
.EnableFlags
&= ~(1 << index
);
1112 goto invalid_enum_error
;
1117 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(cap=%s)",
1118 state
? "glEnablei" : "glDisablei",
1119 _mesa_enum_to_string(cap
));
1124 _mesa_Disablei( GLenum cap
, GLuint index
)
1126 GET_CURRENT_CONTEXT(ctx
);
1127 _mesa_set_enablei(ctx
, cap
, index
, GL_FALSE
);
1132 _mesa_Enablei( GLenum cap
, GLuint index
)
1134 GET_CURRENT_CONTEXT(ctx
);
1135 _mesa_set_enablei(ctx
, cap
, index
, GL_TRUE
);
1139 GLboolean GLAPIENTRY
1140 _mesa_IsEnabledi( GLenum cap
, GLuint index
)
1142 GET_CURRENT_CONTEXT(ctx
);
1143 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1146 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1147 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1151 return (ctx
->Color
.BlendEnabled
>> index
) & 1;
1152 case GL_SCISSOR_TEST
:
1153 if (index
>= ctx
->Const
.MaxViewports
) {
1154 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1158 return (ctx
->Scissor
.EnableFlags
>> index
) & 1;
1160 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabledIndexed(cap=%s)",
1161 _mesa_enum_to_string(cap
));
1169 #undef CHECK_EXTENSION
1170 #define CHECK_EXTENSION(EXTNAME) \
1171 if (!ctx->Extensions.EXTNAME) { \
1172 goto invalid_enum_error; \
1175 #undef CHECK_EXTENSION2
1176 #define CHECK_EXTENSION2(EXT1, EXT2) \
1177 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1178 goto invalid_enum_error; \
1183 * Helper function to determine whether a texture target is enabled.
1186 is_texture_enabled(struct gl_context
*ctx
, GLbitfield bit
)
1188 const struct gl_texture_unit
*const texUnit
=
1189 &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1190 return (texUnit
->Enabled
& bit
) ? GL_TRUE
: GL_FALSE
;
1195 * Return simple enable/disable state.
1197 * \param cap state variable to query.
1199 * Returns the state of the specified capability from the current GL context.
1200 * For the capabilities associated with extensions verifies that those
1201 * extensions are effectively present before reporting.
1203 GLboolean GLAPIENTRY
1204 _mesa_IsEnabled( GLenum cap
)
1206 GET_CURRENT_CONTEXT(ctx
);
1207 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1211 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1212 goto invalid_enum_error
;
1213 return ctx
->Color
.AlphaEnabled
;
1214 case GL_AUTO_NORMAL
:
1215 if (ctx
->API
!= API_OPENGL_COMPAT
)
1216 goto invalid_enum_error
;
1217 return ctx
->Eval
.AutoNormal
;
1219 return ctx
->Color
.BlendEnabled
& 1; /* return state for buffer[0] */
1220 case GL_CLIP_DISTANCE0
: /* aka GL_CLIP_PLANE0 */
1221 case GL_CLIP_DISTANCE1
:
1222 case GL_CLIP_DISTANCE2
:
1223 case GL_CLIP_DISTANCE3
:
1224 case GL_CLIP_DISTANCE4
:
1225 case GL_CLIP_DISTANCE5
:
1226 case GL_CLIP_DISTANCE6
:
1227 case GL_CLIP_DISTANCE7
: {
1228 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
1230 if (p
>= ctx
->Const
.MaxClipPlanes
)
1231 goto invalid_enum_error
;
1233 return (ctx
->Transform
.ClipPlanesEnabled
>> p
) & 1;
1235 case GL_COLOR_MATERIAL
:
1236 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1237 goto invalid_enum_error
;
1238 return ctx
->Light
.ColorMaterialEnabled
;
1240 return ctx
->Polygon
.CullFlag
;
1241 case GL_DEBUG_OUTPUT
:
1242 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
:
1243 return (GLboolean
) _mesa_get_debug_state_int(ctx
, cap
);
1245 return ctx
->Depth
.Test
;
1247 return ctx
->Color
.DitherFlag
;
1249 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1250 goto invalid_enum_error
;
1251 return ctx
->Fog
.Enabled
;
1253 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1254 goto invalid_enum_error
;
1255 return ctx
->Light
.Enabled
;
1264 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1265 goto invalid_enum_error
;
1266 return ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
;
1267 case GL_LINE_SMOOTH
:
1268 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1269 goto invalid_enum_error
;
1270 return ctx
->Line
.SmoothFlag
;
1271 case GL_LINE_STIPPLE
:
1272 if (ctx
->API
!= API_OPENGL_COMPAT
)
1273 goto invalid_enum_error
;
1274 return ctx
->Line
.StippleFlag
;
1275 case GL_INDEX_LOGIC_OP
:
1276 if (ctx
->API
!= API_OPENGL_COMPAT
)
1277 goto invalid_enum_error
;
1278 return ctx
->Color
.IndexLogicOpEnabled
;
1279 case GL_COLOR_LOGIC_OP
:
1280 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1281 goto invalid_enum_error
;
1282 return ctx
->Color
.ColorLogicOpEnabled
;
1283 case GL_MAP1_COLOR_4
:
1284 if (ctx
->API
!= API_OPENGL_COMPAT
)
1285 goto invalid_enum_error
;
1286 return ctx
->Eval
.Map1Color4
;
1288 if (ctx
->API
!= API_OPENGL_COMPAT
)
1289 goto invalid_enum_error
;
1290 return ctx
->Eval
.Map1Index
;
1291 case GL_MAP1_NORMAL
:
1292 if (ctx
->API
!= API_OPENGL_COMPAT
)
1293 goto invalid_enum_error
;
1294 return ctx
->Eval
.Map1Normal
;
1295 case GL_MAP1_TEXTURE_COORD_1
:
1296 if (ctx
->API
!= API_OPENGL_COMPAT
)
1297 goto invalid_enum_error
;
1298 return ctx
->Eval
.Map1TextureCoord1
;
1299 case GL_MAP1_TEXTURE_COORD_2
:
1300 if (ctx
->API
!= API_OPENGL_COMPAT
)
1301 goto invalid_enum_error
;
1302 return ctx
->Eval
.Map1TextureCoord2
;
1303 case GL_MAP1_TEXTURE_COORD_3
:
1304 if (ctx
->API
!= API_OPENGL_COMPAT
)
1305 goto invalid_enum_error
;
1306 return ctx
->Eval
.Map1TextureCoord3
;
1307 case GL_MAP1_TEXTURE_COORD_4
:
1308 if (ctx
->API
!= API_OPENGL_COMPAT
)
1309 goto invalid_enum_error
;
1310 return ctx
->Eval
.Map1TextureCoord4
;
1311 case GL_MAP1_VERTEX_3
:
1312 if (ctx
->API
!= API_OPENGL_COMPAT
)
1313 goto invalid_enum_error
;
1314 return ctx
->Eval
.Map1Vertex3
;
1315 case GL_MAP1_VERTEX_4
:
1316 if (ctx
->API
!= API_OPENGL_COMPAT
)
1317 goto invalid_enum_error
;
1318 return ctx
->Eval
.Map1Vertex4
;
1319 case GL_MAP2_COLOR_4
:
1320 if (ctx
->API
!= API_OPENGL_COMPAT
)
1321 goto invalid_enum_error
;
1322 return ctx
->Eval
.Map2Color4
;
1324 if (ctx
->API
!= API_OPENGL_COMPAT
)
1325 goto invalid_enum_error
;
1326 return ctx
->Eval
.Map2Index
;
1327 case GL_MAP2_NORMAL
:
1328 if (ctx
->API
!= API_OPENGL_COMPAT
)
1329 goto invalid_enum_error
;
1330 return ctx
->Eval
.Map2Normal
;
1331 case GL_MAP2_TEXTURE_COORD_1
:
1332 if (ctx
->API
!= API_OPENGL_COMPAT
)
1333 goto invalid_enum_error
;
1334 return ctx
->Eval
.Map2TextureCoord1
;
1335 case GL_MAP2_TEXTURE_COORD_2
:
1336 if (ctx
->API
!= API_OPENGL_COMPAT
)
1337 goto invalid_enum_error
;
1338 return ctx
->Eval
.Map2TextureCoord2
;
1339 case GL_MAP2_TEXTURE_COORD_3
:
1340 if (ctx
->API
!= API_OPENGL_COMPAT
)
1341 goto invalid_enum_error
;
1342 return ctx
->Eval
.Map2TextureCoord3
;
1343 case GL_MAP2_TEXTURE_COORD_4
:
1344 if (ctx
->API
!= API_OPENGL_COMPAT
)
1345 goto invalid_enum_error
;
1346 return ctx
->Eval
.Map2TextureCoord4
;
1347 case GL_MAP2_VERTEX_3
:
1348 if (ctx
->API
!= API_OPENGL_COMPAT
)
1349 goto invalid_enum_error
;
1350 return ctx
->Eval
.Map2Vertex3
;
1351 case GL_MAP2_VERTEX_4
:
1352 if (ctx
->API
!= API_OPENGL_COMPAT
)
1353 goto invalid_enum_error
;
1354 return ctx
->Eval
.Map2Vertex4
;
1356 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1357 goto invalid_enum_error
;
1358 return ctx
->Transform
.Normalize
;
1359 case GL_POINT_SMOOTH
:
1360 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1361 goto invalid_enum_error
;
1362 return ctx
->Point
.SmoothFlag
;
1363 case GL_POLYGON_SMOOTH
:
1364 if (!_mesa_is_desktop_gl(ctx
))
1365 goto invalid_enum_error
;
1366 return ctx
->Polygon
.SmoothFlag
;
1367 case GL_POLYGON_STIPPLE
:
1368 if (ctx
->API
!= API_OPENGL_COMPAT
)
1369 goto invalid_enum_error
;
1370 return ctx
->Polygon
.StippleFlag
;
1371 case GL_POLYGON_OFFSET_POINT
:
1372 if (!_mesa_is_desktop_gl(ctx
))
1373 goto invalid_enum_error
;
1374 return ctx
->Polygon
.OffsetPoint
;
1375 case GL_POLYGON_OFFSET_LINE
:
1376 if (!_mesa_is_desktop_gl(ctx
))
1377 goto invalid_enum_error
;
1378 return ctx
->Polygon
.OffsetLine
;
1379 case GL_POLYGON_OFFSET_FILL
:
1380 return ctx
->Polygon
.OffsetFill
;
1381 case GL_RESCALE_NORMAL_EXT
:
1382 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1383 goto invalid_enum_error
;
1384 return ctx
->Transform
.RescaleNormals
;
1385 case GL_SCISSOR_TEST
:
1386 return ctx
->Scissor
.EnableFlags
& 1; /* return state for index 0 */
1387 case GL_STENCIL_TEST
:
1388 return ctx
->Stencil
.Enabled
;
1390 if (ctx
->API
!= API_OPENGL_COMPAT
)
1391 goto invalid_enum_error
;
1392 return is_texture_enabled(ctx
, TEXTURE_1D_BIT
);
1394 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1395 goto invalid_enum_error
;
1396 return is_texture_enabled(ctx
, TEXTURE_2D_BIT
);
1398 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1399 goto invalid_enum_error
;
1400 return is_texture_enabled(ctx
, TEXTURE_3D_BIT
);
1401 case GL_TEXTURE_GEN_S
:
1402 case GL_TEXTURE_GEN_T
:
1403 case GL_TEXTURE_GEN_R
:
1404 case GL_TEXTURE_GEN_Q
:
1406 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1408 if (ctx
->API
!= API_OPENGL_COMPAT
)
1409 goto invalid_enum_error
;
1412 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
1413 return (texUnit
->TexGenEnabled
& coordBit
) ? GL_TRUE
: GL_FALSE
;
1417 case GL_TEXTURE_GEN_STR_OES
:
1419 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1421 if (ctx
->API
!= API_OPENGLES
)
1422 goto invalid_enum_error
;
1425 return (texUnit
->TexGenEnabled
& STR_BITS
) == STR_BITS
1426 ? GL_TRUE
: GL_FALSE
;
1430 /* client-side state */
1431 case GL_VERTEX_ARRAY
:
1432 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1433 goto invalid_enum_error
;
1434 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
;
1435 case GL_NORMAL_ARRAY
:
1436 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1437 goto invalid_enum_error
;
1438 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
;
1439 case GL_COLOR_ARRAY
:
1440 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1441 goto invalid_enum_error
;
1442 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
;
1443 case GL_INDEX_ARRAY
:
1444 if (ctx
->API
!= API_OPENGL_COMPAT
)
1445 goto invalid_enum_error
;
1446 return ctx
->Array
.VAO
->
1447 VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
;
1448 case GL_TEXTURE_COORD_ARRAY
:
1449 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1450 goto invalid_enum_error
;
1451 return ctx
->Array
.VAO
->
1452 VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Enabled
;
1453 case GL_EDGE_FLAG_ARRAY
:
1454 if (ctx
->API
!= API_OPENGL_COMPAT
)
1455 goto invalid_enum_error
;
1456 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
;
1457 case GL_FOG_COORDINATE_ARRAY_EXT
:
1458 if (ctx
->API
!= API_OPENGL_COMPAT
)
1459 goto invalid_enum_error
;
1460 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
;
1461 case GL_SECONDARY_COLOR_ARRAY_EXT
:
1462 if (ctx
->API
!= API_OPENGL_COMPAT
)
1463 goto invalid_enum_error
;
1464 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
;
1465 case GL_POINT_SIZE_ARRAY_OES
:
1466 if (ctx
->API
!= API_OPENGLES
)
1467 goto invalid_enum_error
;
1468 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
;
1470 /* GL_ARB_texture_cube_map */
1471 case GL_TEXTURE_CUBE_MAP
:
1472 CHECK_EXTENSION(ARB_texture_cube_map
);
1473 return is_texture_enabled(ctx
, TEXTURE_CUBE_BIT
);
1475 /* GL_EXT_secondary_color */
1476 case GL_COLOR_SUM_EXT
:
1477 if (ctx
->API
!= API_OPENGL_COMPAT
)
1478 goto invalid_enum_error
;
1479 return ctx
->Fog
.ColorSumEnabled
;
1481 /* GL_ARB_multisample */
1482 case GL_MULTISAMPLE_ARB
:
1483 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1484 goto invalid_enum_error
;
1485 return ctx
->Multisample
.Enabled
;
1486 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
1487 return ctx
->Multisample
.SampleAlphaToCoverage
;
1488 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
1489 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1490 goto invalid_enum_error
;
1491 return ctx
->Multisample
.SampleAlphaToOne
;
1492 case GL_SAMPLE_COVERAGE_ARB
:
1493 return ctx
->Multisample
.SampleCoverage
;
1494 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
1495 if (!_mesa_is_desktop_gl(ctx
))
1496 goto invalid_enum_error
;
1497 return ctx
->Multisample
.SampleCoverageInvert
;
1499 /* GL_IBM_rasterpos_clip */
1500 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
1501 if (ctx
->API
!= API_OPENGL_COMPAT
)
1502 goto invalid_enum_error
;
1503 return ctx
->Transform
.RasterPositionUnclipped
;
1505 /* GL_NV_point_sprite */
1506 case GL_POINT_SPRITE_NV
:
1507 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1508 goto invalid_enum_error
;
1509 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
)
1510 return ctx
->Point
.PointSprite
;
1512 case GL_VERTEX_PROGRAM_ARB
:
1513 if (ctx
->API
!= API_OPENGL_COMPAT
)
1514 goto invalid_enum_error
;
1515 CHECK_EXTENSION(ARB_vertex_program
);
1516 return ctx
->VertexProgram
.Enabled
;
1517 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
1518 /* This was added with ARB_vertex_program, but it is also used with
1519 * GLSL vertex shaders on desktop.
1521 if (!_mesa_is_desktop_gl(ctx
))
1522 goto invalid_enum_error
;
1523 CHECK_EXTENSION(ARB_vertex_program
);
1524 return ctx
->VertexProgram
.PointSizeEnabled
;
1525 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
1526 if (ctx
->API
!= API_OPENGL_COMPAT
)
1527 goto invalid_enum_error
;
1528 CHECK_EXTENSION(ARB_vertex_program
);
1529 return ctx
->VertexProgram
.TwoSideEnabled
;
1531 /* GL_NV_texture_rectangle */
1532 case GL_TEXTURE_RECTANGLE_NV
:
1533 if (ctx
->API
!= API_OPENGL_COMPAT
)
1534 goto invalid_enum_error
;
1535 CHECK_EXTENSION(NV_texture_rectangle
);
1536 return is_texture_enabled(ctx
, TEXTURE_RECT_BIT
);
1538 /* GL_EXT_stencil_two_side */
1539 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
1540 if (ctx
->API
!= API_OPENGL_COMPAT
)
1541 goto invalid_enum_error
;
1542 CHECK_EXTENSION(EXT_stencil_two_side
);
1543 return ctx
->Stencil
.TestTwoSide
;
1545 case GL_FRAGMENT_PROGRAM_ARB
:
1546 if (ctx
->API
!= API_OPENGL_COMPAT
)
1547 goto invalid_enum_error
;
1548 return ctx
->FragmentProgram
.Enabled
;
1550 /* GL_EXT_depth_bounds_test */
1551 case GL_DEPTH_BOUNDS_TEST_EXT
:
1552 if (!_mesa_is_desktop_gl(ctx
))
1553 goto invalid_enum_error
;
1554 CHECK_EXTENSION(EXT_depth_bounds_test
);
1555 return ctx
->Depth
.BoundsTest
;
1557 /* GL_ARB_depth_clamp */
1558 case GL_DEPTH_CLAMP
:
1559 if (!_mesa_is_desktop_gl(ctx
))
1560 goto invalid_enum_error
;
1561 CHECK_EXTENSION(ARB_depth_clamp
);
1562 return ctx
->Transform
.DepthClamp
;
1564 case GL_FRAGMENT_SHADER_ATI
:
1565 if (ctx
->API
!= API_OPENGL_COMPAT
)
1566 goto invalid_enum_error
;
1567 CHECK_EXTENSION(ATI_fragment_shader
);
1568 return ctx
->ATIFragmentShader
.Enabled
;
1570 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1571 if (!_mesa_is_desktop_gl(ctx
))
1572 goto invalid_enum_error
;
1573 CHECK_EXTENSION(ARB_seamless_cube_map
);
1574 return ctx
->Texture
.CubeMapSeamless
;
1576 case GL_RASTERIZER_DISCARD
:
1577 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1578 goto invalid_enum_error
;
1579 CHECK_EXTENSION(EXT_transform_feedback
);
1580 return ctx
->RasterDiscard
;
1582 /* GL_NV_primitive_restart */
1583 case GL_PRIMITIVE_RESTART_NV
:
1584 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.NV_primitive_restart
) {
1585 goto invalid_enum_error
;
1587 return ctx
->Array
.PrimitiveRestart
;
1589 /* GL 3.1 primitive restart */
1590 case GL_PRIMITIVE_RESTART
:
1591 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
1592 goto invalid_enum_error
;
1594 return ctx
->Array
.PrimitiveRestart
;
1596 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
1597 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
) {
1598 goto invalid_enum_error
;
1600 return ctx
->Array
.PrimitiveRestartFixedIndex
;
1602 /* GL3.0 - GL_framebuffer_sRGB */
1603 case GL_FRAMEBUFFER_SRGB_EXT
:
1604 if (!_mesa_is_desktop_gl(ctx
))
1605 goto invalid_enum_error
;
1606 CHECK_EXTENSION(EXT_framebuffer_sRGB
);
1607 return ctx
->Color
.sRGBEnabled
;
1609 /* GL_OES_EGL_image_external */
1610 case GL_TEXTURE_EXTERNAL_OES
:
1611 if (!_mesa_is_gles(ctx
))
1612 goto invalid_enum_error
;
1613 CHECK_EXTENSION(OES_EGL_image_external
);
1614 return is_texture_enabled(ctx
, TEXTURE_EXTERNAL_BIT
);
1616 /* ARB_texture_multisample */
1617 case GL_SAMPLE_MASK
:
1618 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
1619 goto invalid_enum_error
;
1620 CHECK_EXTENSION(ARB_texture_multisample
);
1621 return ctx
->Multisample
.SampleMask
;
1623 /* ARB_sample_shading */
1624 case GL_SAMPLE_SHADING
:
1625 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1626 goto invalid_enum_error
;
1627 CHECK_EXTENSION(ARB_sample_shading
);
1628 return ctx
->Multisample
.SampleShading
;
1630 case GL_BLEND_ADVANCED_COHERENT_KHR
:
1631 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent
);
1632 return ctx
->Color
.BlendCoherent
;
1635 goto invalid_enum_error
;
1641 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabled(%s)",
1642 _mesa_enum_to_string(cap
));