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_CONSERVATIVE_RASTERIZATION_INTEL
:
443 if (!_mesa_has_INTEL_conservative_rasterization(ctx
))
444 goto invalid_enum_error
;
445 if (ctx
->IntelConservativeRasterization
== state
)
447 FLUSH_VERTICES(ctx
, 0);
448 ctx
->NewDriverState
|=
449 ctx
->DriverFlags
.NewIntelConservativeRasterization
;
450 ctx
->IntelConservativeRasterization
= state
;
452 case GL_COLOR_LOGIC_OP
:
453 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
454 goto invalid_enum_error
;
455 if (ctx
->Color
.ColorLogicOpEnabled
== state
)
457 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
458 ctx
->Color
.ColorLogicOpEnabled
= state
;
460 case GL_MAP1_COLOR_4
:
461 if (ctx
->API
!= API_OPENGL_COMPAT
)
462 goto invalid_enum_error
;
463 if (ctx
->Eval
.Map1Color4
== state
)
465 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
466 ctx
->Eval
.Map1Color4
= state
;
469 if (ctx
->API
!= API_OPENGL_COMPAT
)
470 goto invalid_enum_error
;
471 if (ctx
->Eval
.Map1Index
== state
)
473 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
474 ctx
->Eval
.Map1Index
= state
;
477 if (ctx
->API
!= API_OPENGL_COMPAT
)
478 goto invalid_enum_error
;
479 if (ctx
->Eval
.Map1Normal
== state
)
481 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
482 ctx
->Eval
.Map1Normal
= state
;
484 case GL_MAP1_TEXTURE_COORD_1
:
485 if (ctx
->API
!= API_OPENGL_COMPAT
)
486 goto invalid_enum_error
;
487 if (ctx
->Eval
.Map1TextureCoord1
== state
)
489 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
490 ctx
->Eval
.Map1TextureCoord1
= state
;
492 case GL_MAP1_TEXTURE_COORD_2
:
493 if (ctx
->API
!= API_OPENGL_COMPAT
)
494 goto invalid_enum_error
;
495 if (ctx
->Eval
.Map1TextureCoord2
== state
)
497 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
498 ctx
->Eval
.Map1TextureCoord2
= state
;
500 case GL_MAP1_TEXTURE_COORD_3
:
501 if (ctx
->API
!= API_OPENGL_COMPAT
)
502 goto invalid_enum_error
;
503 if (ctx
->Eval
.Map1TextureCoord3
== state
)
505 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
506 ctx
->Eval
.Map1TextureCoord3
= state
;
508 case GL_MAP1_TEXTURE_COORD_4
:
509 if (ctx
->API
!= API_OPENGL_COMPAT
)
510 goto invalid_enum_error
;
511 if (ctx
->Eval
.Map1TextureCoord4
== state
)
513 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
514 ctx
->Eval
.Map1TextureCoord4
= state
;
516 case GL_MAP1_VERTEX_3
:
517 if (ctx
->API
!= API_OPENGL_COMPAT
)
518 goto invalid_enum_error
;
519 if (ctx
->Eval
.Map1Vertex3
== state
)
521 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
522 ctx
->Eval
.Map1Vertex3
= state
;
524 case GL_MAP1_VERTEX_4
:
525 if (ctx
->API
!= API_OPENGL_COMPAT
)
526 goto invalid_enum_error
;
527 if (ctx
->Eval
.Map1Vertex4
== state
)
529 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
530 ctx
->Eval
.Map1Vertex4
= state
;
532 case GL_MAP2_COLOR_4
:
533 if (ctx
->API
!= API_OPENGL_COMPAT
)
534 goto invalid_enum_error
;
535 if (ctx
->Eval
.Map2Color4
== state
)
537 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
538 ctx
->Eval
.Map2Color4
= state
;
541 if (ctx
->API
!= API_OPENGL_COMPAT
)
542 goto invalid_enum_error
;
543 if (ctx
->Eval
.Map2Index
== state
)
545 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
546 ctx
->Eval
.Map2Index
= state
;
549 if (ctx
->API
!= API_OPENGL_COMPAT
)
550 goto invalid_enum_error
;
551 if (ctx
->Eval
.Map2Normal
== state
)
553 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
554 ctx
->Eval
.Map2Normal
= state
;
556 case GL_MAP2_TEXTURE_COORD_1
:
557 if (ctx
->API
!= API_OPENGL_COMPAT
)
558 goto invalid_enum_error
;
559 if (ctx
->Eval
.Map2TextureCoord1
== state
)
561 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
562 ctx
->Eval
.Map2TextureCoord1
= state
;
564 case GL_MAP2_TEXTURE_COORD_2
:
565 if (ctx
->API
!= API_OPENGL_COMPAT
)
566 goto invalid_enum_error
;
567 if (ctx
->Eval
.Map2TextureCoord2
== state
)
569 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
570 ctx
->Eval
.Map2TextureCoord2
= state
;
572 case GL_MAP2_TEXTURE_COORD_3
:
573 if (ctx
->API
!= API_OPENGL_COMPAT
)
574 goto invalid_enum_error
;
575 if (ctx
->Eval
.Map2TextureCoord3
== state
)
577 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
578 ctx
->Eval
.Map2TextureCoord3
= state
;
580 case GL_MAP2_TEXTURE_COORD_4
:
581 if (ctx
->API
!= API_OPENGL_COMPAT
)
582 goto invalid_enum_error
;
583 if (ctx
->Eval
.Map2TextureCoord4
== state
)
585 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
586 ctx
->Eval
.Map2TextureCoord4
= state
;
588 case GL_MAP2_VERTEX_3
:
589 if (ctx
->API
!= API_OPENGL_COMPAT
)
590 goto invalid_enum_error
;
591 if (ctx
->Eval
.Map2Vertex3
== state
)
593 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
594 ctx
->Eval
.Map2Vertex3
= state
;
596 case GL_MAP2_VERTEX_4
:
597 if (ctx
->API
!= API_OPENGL_COMPAT
)
598 goto invalid_enum_error
;
599 if (ctx
->Eval
.Map2Vertex4
== state
)
601 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
602 ctx
->Eval
.Map2Vertex4
= state
;
605 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
606 goto invalid_enum_error
;
607 if (ctx
->Transform
.Normalize
== state
)
609 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
610 ctx
->Transform
.Normalize
= state
;
612 case GL_POINT_SMOOTH
:
613 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
614 goto invalid_enum_error
;
615 if (ctx
->Point
.SmoothFlag
== state
)
617 FLUSH_VERTICES(ctx
, _NEW_POINT
);
618 ctx
->Point
.SmoothFlag
= state
;
620 case GL_POLYGON_SMOOTH
:
621 if (!_mesa_is_desktop_gl(ctx
))
622 goto invalid_enum_error
;
623 if (ctx
->Polygon
.SmoothFlag
== state
)
625 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
626 ctx
->Polygon
.SmoothFlag
= state
;
628 case GL_POLYGON_STIPPLE
:
629 if (ctx
->API
!= API_OPENGL_COMPAT
)
630 goto invalid_enum_error
;
631 if (ctx
->Polygon
.StippleFlag
== state
)
633 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
634 ctx
->Polygon
.StippleFlag
= state
;
636 case GL_POLYGON_OFFSET_POINT
:
637 if (!_mesa_is_desktop_gl(ctx
))
638 goto invalid_enum_error
;
639 if (ctx
->Polygon
.OffsetPoint
== state
)
641 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
642 ctx
->Polygon
.OffsetPoint
= state
;
644 case GL_POLYGON_OFFSET_LINE
:
645 if (!_mesa_is_desktop_gl(ctx
))
646 goto invalid_enum_error
;
647 if (ctx
->Polygon
.OffsetLine
== state
)
649 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
650 ctx
->Polygon
.OffsetLine
= state
;
652 case GL_POLYGON_OFFSET_FILL
:
653 if (ctx
->Polygon
.OffsetFill
== state
)
655 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
656 ctx
->Polygon
.OffsetFill
= state
;
658 case GL_RESCALE_NORMAL_EXT
:
659 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
660 goto invalid_enum_error
;
661 if (ctx
->Transform
.RescaleNormals
== state
)
663 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
664 ctx
->Transform
.RescaleNormals
= state
;
666 case GL_SCISSOR_TEST
:
668 /* Must expand glEnable to all scissors */
669 GLbitfield newEnabled
=
670 state
* ((1 << ctx
->Const
.MaxViewports
) - 1);
671 if (newEnabled
!= ctx
->Scissor
.EnableFlags
) {
672 FLUSH_VERTICES(ctx
, _NEW_SCISSOR
);
673 ctx
->Scissor
.EnableFlags
= newEnabled
;
677 case GL_STENCIL_TEST
:
678 if (ctx
->Stencil
.Enabled
== state
)
680 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
681 ctx
->Stencil
.Enabled
= state
;
684 if (ctx
->API
!= API_OPENGL_COMPAT
)
685 goto invalid_enum_error
;
686 if (!enable_texture(ctx
, state
, TEXTURE_1D_BIT
)) {
691 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
692 goto invalid_enum_error
;
693 if (!enable_texture(ctx
, state
, TEXTURE_2D_BIT
)) {
698 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
699 goto invalid_enum_error
;
700 if (!enable_texture(ctx
, state
, TEXTURE_3D_BIT
)) {
704 case GL_TEXTURE_GEN_S
:
705 case GL_TEXTURE_GEN_T
:
706 case GL_TEXTURE_GEN_R
:
707 case GL_TEXTURE_GEN_Q
:
709 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
711 if (ctx
->API
!= API_OPENGL_COMPAT
)
712 goto invalid_enum_error
;
715 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
716 GLbitfield newenabled
= texUnit
->TexGenEnabled
& ~coordBit
;
718 newenabled
|= coordBit
;
719 if (texUnit
->TexGenEnabled
== newenabled
)
721 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
722 texUnit
->TexGenEnabled
= newenabled
;
727 case GL_TEXTURE_GEN_STR_OES
:
728 /* disable S, T, and R at the same time */
730 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
732 if (ctx
->API
!= API_OPENGLES
)
733 goto invalid_enum_error
;
737 texUnit
->TexGenEnabled
& ~STR_BITS
;
739 newenabled
|= STR_BITS
;
740 if (texUnit
->TexGenEnabled
== newenabled
)
742 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
743 texUnit
->TexGenEnabled
= newenabled
;
748 /* client-side state */
749 case GL_VERTEX_ARRAY
:
750 case GL_NORMAL_ARRAY
:
752 case GL_TEXTURE_COORD_ARRAY
:
753 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
754 goto invalid_enum_error
;
755 client_state( ctx
, cap
, state
);
758 case GL_EDGE_FLAG_ARRAY
:
759 case GL_FOG_COORDINATE_ARRAY_EXT
:
760 case GL_SECONDARY_COLOR_ARRAY_EXT
:
761 if (ctx
->API
!= API_OPENGL_COMPAT
)
762 goto invalid_enum_error
;
763 client_state( ctx
, cap
, state
);
765 case GL_POINT_SIZE_ARRAY_OES
:
766 if (ctx
->API
!= API_OPENGLES
)
767 goto invalid_enum_error
;
768 client_state( ctx
, cap
, state
);
771 /* GL_ARB_texture_cube_map */
772 case GL_TEXTURE_CUBE_MAP
:
773 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
774 goto invalid_enum_error
;
775 CHECK_EXTENSION(ARB_texture_cube_map
, cap
);
776 if (!enable_texture(ctx
, state
, TEXTURE_CUBE_BIT
)) {
781 /* GL_EXT_secondary_color */
782 case GL_COLOR_SUM_EXT
:
783 if (ctx
->API
!= API_OPENGL_COMPAT
)
784 goto invalid_enum_error
;
785 if (ctx
->Fog
.ColorSumEnabled
== state
)
787 FLUSH_VERTICES(ctx
, _NEW_FOG
);
788 ctx
->Fog
.ColorSumEnabled
= state
;
791 /* GL_ARB_multisample */
792 case GL_MULTISAMPLE_ARB
:
793 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
794 goto invalid_enum_error
;
795 _mesa_set_multisample(ctx
, state
);
797 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
798 if (ctx
->Multisample
.SampleAlphaToCoverage
== state
)
800 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
801 ctx
->Multisample
.SampleAlphaToCoverage
= state
;
803 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
804 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
805 goto invalid_enum_error
;
806 if (ctx
->Multisample
.SampleAlphaToOne
== state
)
808 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
809 ctx
->Multisample
.SampleAlphaToOne
= state
;
811 case GL_SAMPLE_COVERAGE_ARB
:
812 if (ctx
->Multisample
.SampleCoverage
== state
)
814 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
815 ctx
->Multisample
.SampleCoverage
= state
;
817 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
818 if (!_mesa_is_desktop_gl(ctx
))
819 goto invalid_enum_error
;
820 if (ctx
->Multisample
.SampleCoverageInvert
== state
)
822 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
823 ctx
->Multisample
.SampleCoverageInvert
= state
;
826 /* GL_ARB_sample_shading */
827 case GL_SAMPLE_SHADING
:
828 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
829 goto invalid_enum_error
;
830 CHECK_EXTENSION(ARB_sample_shading
, cap
);
831 if (ctx
->Multisample
.SampleShading
== state
)
833 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
834 ctx
->Multisample
.SampleShading
= state
;
837 /* GL_IBM_rasterpos_clip */
838 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
839 if (ctx
->API
!= API_OPENGL_COMPAT
)
840 goto invalid_enum_error
;
841 if (ctx
->Transform
.RasterPositionUnclipped
== state
)
843 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
844 ctx
->Transform
.RasterPositionUnclipped
= state
;
847 /* GL_NV_point_sprite */
848 case GL_POINT_SPRITE_NV
:
849 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
850 goto invalid_enum_error
;
851 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
, cap
);
852 if (ctx
->Point
.PointSprite
== state
)
854 FLUSH_VERTICES(ctx
, _NEW_POINT
);
855 ctx
->Point
.PointSprite
= state
;
858 case GL_VERTEX_PROGRAM_ARB
:
859 if (ctx
->API
!= API_OPENGL_COMPAT
)
860 goto invalid_enum_error
;
861 CHECK_EXTENSION(ARB_vertex_program
, cap
);
862 if (ctx
->VertexProgram
.Enabled
== state
)
864 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
865 ctx
->VertexProgram
.Enabled
= state
;
867 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
868 /* This was added with ARB_vertex_program, but it is also used with
869 * GLSL vertex shaders on desktop.
871 if (!_mesa_is_desktop_gl(ctx
))
872 goto invalid_enum_error
;
873 CHECK_EXTENSION(ARB_vertex_program
, cap
);
874 if (ctx
->VertexProgram
.PointSizeEnabled
== state
)
876 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
877 ctx
->VertexProgram
.PointSizeEnabled
= state
;
879 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
880 if (ctx
->API
!= API_OPENGL_COMPAT
)
881 goto invalid_enum_error
;
882 CHECK_EXTENSION(ARB_vertex_program
, cap
);
883 if (ctx
->VertexProgram
.TwoSideEnabled
== state
)
885 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
886 ctx
->VertexProgram
.TwoSideEnabled
= state
;
889 /* GL_NV_texture_rectangle */
890 case GL_TEXTURE_RECTANGLE_NV
:
891 if (ctx
->API
!= API_OPENGL_COMPAT
)
892 goto invalid_enum_error
;
893 CHECK_EXTENSION(NV_texture_rectangle
, cap
);
894 if (!enable_texture(ctx
, state
, TEXTURE_RECT_BIT
)) {
899 /* GL_EXT_stencil_two_side */
900 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
901 if (ctx
->API
!= API_OPENGL_COMPAT
)
902 goto invalid_enum_error
;
903 CHECK_EXTENSION(EXT_stencil_two_side
, cap
);
904 if (ctx
->Stencil
.TestTwoSide
== state
)
906 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
907 ctx
->Stencil
.TestTwoSide
= state
;
909 ctx
->Stencil
._BackFace
= 2;
911 ctx
->Stencil
._BackFace
= 1;
915 case GL_FRAGMENT_PROGRAM_ARB
:
916 if (ctx
->API
!= API_OPENGL_COMPAT
)
917 goto invalid_enum_error
;
918 CHECK_EXTENSION(ARB_fragment_program
, cap
);
919 if (ctx
->FragmentProgram
.Enabled
== state
)
921 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
922 ctx
->FragmentProgram
.Enabled
= state
;
925 /* GL_EXT_depth_bounds_test */
926 case GL_DEPTH_BOUNDS_TEST_EXT
:
927 if (!_mesa_is_desktop_gl(ctx
))
928 goto invalid_enum_error
;
929 CHECK_EXTENSION(EXT_depth_bounds_test
, cap
);
930 if (ctx
->Depth
.BoundsTest
== state
)
932 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
933 ctx
->Depth
.BoundsTest
= state
;
937 if (!_mesa_is_desktop_gl(ctx
))
938 goto invalid_enum_error
;
939 CHECK_EXTENSION(ARB_depth_clamp
, cap
);
940 if (ctx
->Transform
.DepthClamp
== state
)
942 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
943 ctx
->Transform
.DepthClamp
= state
;
946 case GL_FRAGMENT_SHADER_ATI
:
947 if (ctx
->API
!= API_OPENGL_COMPAT
)
948 goto invalid_enum_error
;
949 CHECK_EXTENSION(ATI_fragment_shader
, cap
);
950 if (ctx
->ATIFragmentShader
.Enabled
== state
)
952 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
953 ctx
->ATIFragmentShader
.Enabled
= state
;
956 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
957 if (!_mesa_is_desktop_gl(ctx
))
958 goto invalid_enum_error
;
959 CHECK_EXTENSION(ARB_seamless_cube_map
, cap
);
960 if (ctx
->Texture
.CubeMapSeamless
!= state
) {
961 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
962 ctx
->Texture
.CubeMapSeamless
= state
;
966 case GL_RASTERIZER_DISCARD
:
967 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
968 goto invalid_enum_error
;
969 CHECK_EXTENSION(EXT_transform_feedback
, cap
);
970 if (ctx
->RasterDiscard
!= state
) {
971 FLUSH_VERTICES(ctx
, 0);
972 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewRasterizerDiscard
;
973 ctx
->RasterDiscard
= state
;
977 /* GL 3.1 primitive restart. Note: this enum is different from
978 * GL_PRIMITIVE_RESTART_NV (which is client state).
980 case GL_PRIMITIVE_RESTART
:
981 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
982 goto invalid_enum_error
;
984 if (ctx
->Array
.PrimitiveRestart
!= state
) {
985 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
986 ctx
->Array
.PrimitiveRestart
= state
;
987 update_derived_primitive_restart_state(ctx
);
991 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
992 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
)
993 goto invalid_enum_error
;
994 if (ctx
->Array
.PrimitiveRestartFixedIndex
!= state
) {
995 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
996 ctx
->Array
.PrimitiveRestartFixedIndex
= state
;
997 update_derived_primitive_restart_state(ctx
);
1001 /* GL3.0 - GL_framebuffer_sRGB */
1002 case GL_FRAMEBUFFER_SRGB_EXT
:
1003 if (!_mesa_is_desktop_gl(ctx
))
1004 goto invalid_enum_error
;
1005 CHECK_EXTENSION(EXT_framebuffer_sRGB
, cap
);
1006 _mesa_set_framebuffer_srgb(ctx
, state
);
1009 /* GL_OES_EGL_image_external */
1010 case GL_TEXTURE_EXTERNAL_OES
:
1011 if (!_mesa_is_gles(ctx
))
1012 goto invalid_enum_error
;
1013 CHECK_EXTENSION(OES_EGL_image_external
, cap
);
1014 if (!enable_texture(ctx
, state
, TEXTURE_EXTERNAL_BIT
)) {
1019 /* ARB_texture_multisample */
1020 case GL_SAMPLE_MASK
:
1021 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
1022 goto invalid_enum_error
;
1023 CHECK_EXTENSION(ARB_texture_multisample
, cap
);
1024 if (ctx
->Multisample
.SampleMask
== state
)
1026 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
1027 ctx
->Multisample
.SampleMask
= state
;
1030 case GL_BLEND_ADVANCED_COHERENT_KHR
:
1031 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent
, cap
);
1032 if (ctx
->Color
.BlendCoherent
== state
)
1034 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
1035 ctx
->Color
.BlendCoherent
= state
;
1039 goto invalid_enum_error
;
1042 if (ctx
->Driver
.Enable
) {
1043 ctx
->Driver
.Enable( ctx
, cap
, state
);
1049 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%s(%s)",
1050 state
? "Enable" : "Disable", _mesa_enum_to_string(cap
));
1055 * Enable GL capability. Called by glEnable()
1056 * \param cap state to enable.
1059 _mesa_Enable( GLenum cap
)
1061 GET_CURRENT_CONTEXT(ctx
);
1063 _mesa_set_enable( ctx
, cap
, GL_TRUE
);
1068 * Disable GL capability. Called by glDisable()
1069 * \param cap state to disable.
1072 _mesa_Disable( GLenum cap
)
1074 GET_CURRENT_CONTEXT(ctx
);
1076 _mesa_set_enable( ctx
, cap
, GL_FALSE
);
1082 * Enable/disable an indexed state var.
1085 _mesa_set_enablei(struct gl_context
*ctx
, GLenum cap
,
1086 GLuint index
, GLboolean state
)
1088 assert(state
== 0 || state
== 1);
1091 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
1092 goto invalid_enum_error
;
1094 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1095 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1096 state
? "glEnableIndexed" : "glDisableIndexed", index
);
1099 if (((ctx
->Color
.BlendEnabled
>> index
) & 1) != state
) {
1100 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
1102 ctx
->Color
.BlendEnabled
|= (1 << index
);
1104 ctx
->Color
.BlendEnabled
&= ~(1 << index
);
1107 case GL_SCISSOR_TEST
:
1108 if (index
>= ctx
->Const
.MaxViewports
) {
1109 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1110 state
? "glEnablei" : "glDisablei", index
);
1113 if (((ctx
->Scissor
.EnableFlags
>> index
) & 1) != state
) {
1114 FLUSH_VERTICES(ctx
, _NEW_SCISSOR
);
1116 ctx
->Scissor
.EnableFlags
|= (1 << index
);
1118 ctx
->Scissor
.EnableFlags
&= ~(1 << index
);
1122 goto invalid_enum_error
;
1127 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(cap=%s)",
1128 state
? "glEnablei" : "glDisablei",
1129 _mesa_enum_to_string(cap
));
1134 _mesa_Disablei( GLenum cap
, GLuint index
)
1136 GET_CURRENT_CONTEXT(ctx
);
1137 _mesa_set_enablei(ctx
, cap
, index
, GL_FALSE
);
1142 _mesa_Enablei( GLenum cap
, GLuint index
)
1144 GET_CURRENT_CONTEXT(ctx
);
1145 _mesa_set_enablei(ctx
, cap
, index
, GL_TRUE
);
1149 GLboolean GLAPIENTRY
1150 _mesa_IsEnabledi( GLenum cap
, GLuint index
)
1152 GET_CURRENT_CONTEXT(ctx
);
1153 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1156 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1157 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1161 return (ctx
->Color
.BlendEnabled
>> index
) & 1;
1162 case GL_SCISSOR_TEST
:
1163 if (index
>= ctx
->Const
.MaxViewports
) {
1164 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1168 return (ctx
->Scissor
.EnableFlags
>> index
) & 1;
1170 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabledIndexed(cap=%s)",
1171 _mesa_enum_to_string(cap
));
1179 #undef CHECK_EXTENSION
1180 #define CHECK_EXTENSION(EXTNAME) \
1181 if (!ctx->Extensions.EXTNAME) { \
1182 goto invalid_enum_error; \
1185 #undef CHECK_EXTENSION2
1186 #define CHECK_EXTENSION2(EXT1, EXT2) \
1187 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1188 goto invalid_enum_error; \
1193 * Helper function to determine whether a texture target is enabled.
1196 is_texture_enabled(struct gl_context
*ctx
, GLbitfield bit
)
1198 const struct gl_texture_unit
*const texUnit
=
1199 &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1200 return (texUnit
->Enabled
& bit
) ? GL_TRUE
: GL_FALSE
;
1205 * Return simple enable/disable state.
1207 * \param cap state variable to query.
1209 * Returns the state of the specified capability from the current GL context.
1210 * For the capabilities associated with extensions verifies that those
1211 * extensions are effectively present before reporting.
1213 GLboolean GLAPIENTRY
1214 _mesa_IsEnabled( GLenum cap
)
1216 GET_CURRENT_CONTEXT(ctx
);
1217 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1221 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1222 goto invalid_enum_error
;
1223 return ctx
->Color
.AlphaEnabled
;
1224 case GL_AUTO_NORMAL
:
1225 if (ctx
->API
!= API_OPENGL_COMPAT
)
1226 goto invalid_enum_error
;
1227 return ctx
->Eval
.AutoNormal
;
1229 return ctx
->Color
.BlendEnabled
& 1; /* return state for buffer[0] */
1230 case GL_CLIP_DISTANCE0
: /* aka GL_CLIP_PLANE0 */
1231 case GL_CLIP_DISTANCE1
:
1232 case GL_CLIP_DISTANCE2
:
1233 case GL_CLIP_DISTANCE3
:
1234 case GL_CLIP_DISTANCE4
:
1235 case GL_CLIP_DISTANCE5
:
1236 case GL_CLIP_DISTANCE6
:
1237 case GL_CLIP_DISTANCE7
: {
1238 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
1240 if (p
>= ctx
->Const
.MaxClipPlanes
)
1241 goto invalid_enum_error
;
1243 return (ctx
->Transform
.ClipPlanesEnabled
>> p
) & 1;
1245 case GL_COLOR_MATERIAL
:
1246 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1247 goto invalid_enum_error
;
1248 return ctx
->Light
.ColorMaterialEnabled
;
1250 return ctx
->Polygon
.CullFlag
;
1251 case GL_DEBUG_OUTPUT
:
1252 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
:
1253 return (GLboolean
) _mesa_get_debug_state_int(ctx
, cap
);
1255 return ctx
->Depth
.Test
;
1257 return ctx
->Color
.DitherFlag
;
1259 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1260 goto invalid_enum_error
;
1261 return ctx
->Fog
.Enabled
;
1263 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1264 goto invalid_enum_error
;
1265 return ctx
->Light
.Enabled
;
1274 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1275 goto invalid_enum_error
;
1276 return ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
;
1277 case GL_LINE_SMOOTH
:
1278 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1279 goto invalid_enum_error
;
1280 return ctx
->Line
.SmoothFlag
;
1281 case GL_LINE_STIPPLE
:
1282 if (ctx
->API
!= API_OPENGL_COMPAT
)
1283 goto invalid_enum_error
;
1284 return ctx
->Line
.StippleFlag
;
1285 case GL_INDEX_LOGIC_OP
:
1286 if (ctx
->API
!= API_OPENGL_COMPAT
)
1287 goto invalid_enum_error
;
1288 return ctx
->Color
.IndexLogicOpEnabled
;
1289 case GL_COLOR_LOGIC_OP
:
1290 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1291 goto invalid_enum_error
;
1292 return ctx
->Color
.ColorLogicOpEnabled
;
1293 case GL_MAP1_COLOR_4
:
1294 if (ctx
->API
!= API_OPENGL_COMPAT
)
1295 goto invalid_enum_error
;
1296 return ctx
->Eval
.Map1Color4
;
1298 if (ctx
->API
!= API_OPENGL_COMPAT
)
1299 goto invalid_enum_error
;
1300 return ctx
->Eval
.Map1Index
;
1301 case GL_MAP1_NORMAL
:
1302 if (ctx
->API
!= API_OPENGL_COMPAT
)
1303 goto invalid_enum_error
;
1304 return ctx
->Eval
.Map1Normal
;
1305 case GL_MAP1_TEXTURE_COORD_1
:
1306 if (ctx
->API
!= API_OPENGL_COMPAT
)
1307 goto invalid_enum_error
;
1308 return ctx
->Eval
.Map1TextureCoord1
;
1309 case GL_MAP1_TEXTURE_COORD_2
:
1310 if (ctx
->API
!= API_OPENGL_COMPAT
)
1311 goto invalid_enum_error
;
1312 return ctx
->Eval
.Map1TextureCoord2
;
1313 case GL_MAP1_TEXTURE_COORD_3
:
1314 if (ctx
->API
!= API_OPENGL_COMPAT
)
1315 goto invalid_enum_error
;
1316 return ctx
->Eval
.Map1TextureCoord3
;
1317 case GL_MAP1_TEXTURE_COORD_4
:
1318 if (ctx
->API
!= API_OPENGL_COMPAT
)
1319 goto invalid_enum_error
;
1320 return ctx
->Eval
.Map1TextureCoord4
;
1321 case GL_MAP1_VERTEX_3
:
1322 if (ctx
->API
!= API_OPENGL_COMPAT
)
1323 goto invalid_enum_error
;
1324 return ctx
->Eval
.Map1Vertex3
;
1325 case GL_MAP1_VERTEX_4
:
1326 if (ctx
->API
!= API_OPENGL_COMPAT
)
1327 goto invalid_enum_error
;
1328 return ctx
->Eval
.Map1Vertex4
;
1329 case GL_MAP2_COLOR_4
:
1330 if (ctx
->API
!= API_OPENGL_COMPAT
)
1331 goto invalid_enum_error
;
1332 return ctx
->Eval
.Map2Color4
;
1334 if (ctx
->API
!= API_OPENGL_COMPAT
)
1335 goto invalid_enum_error
;
1336 return ctx
->Eval
.Map2Index
;
1337 case GL_MAP2_NORMAL
:
1338 if (ctx
->API
!= API_OPENGL_COMPAT
)
1339 goto invalid_enum_error
;
1340 return ctx
->Eval
.Map2Normal
;
1341 case GL_MAP2_TEXTURE_COORD_1
:
1342 if (ctx
->API
!= API_OPENGL_COMPAT
)
1343 goto invalid_enum_error
;
1344 return ctx
->Eval
.Map2TextureCoord1
;
1345 case GL_MAP2_TEXTURE_COORD_2
:
1346 if (ctx
->API
!= API_OPENGL_COMPAT
)
1347 goto invalid_enum_error
;
1348 return ctx
->Eval
.Map2TextureCoord2
;
1349 case GL_MAP2_TEXTURE_COORD_3
:
1350 if (ctx
->API
!= API_OPENGL_COMPAT
)
1351 goto invalid_enum_error
;
1352 return ctx
->Eval
.Map2TextureCoord3
;
1353 case GL_MAP2_TEXTURE_COORD_4
:
1354 if (ctx
->API
!= API_OPENGL_COMPAT
)
1355 goto invalid_enum_error
;
1356 return ctx
->Eval
.Map2TextureCoord4
;
1357 case GL_MAP2_VERTEX_3
:
1358 if (ctx
->API
!= API_OPENGL_COMPAT
)
1359 goto invalid_enum_error
;
1360 return ctx
->Eval
.Map2Vertex3
;
1361 case GL_MAP2_VERTEX_4
:
1362 if (ctx
->API
!= API_OPENGL_COMPAT
)
1363 goto invalid_enum_error
;
1364 return ctx
->Eval
.Map2Vertex4
;
1366 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1367 goto invalid_enum_error
;
1368 return ctx
->Transform
.Normalize
;
1369 case GL_POINT_SMOOTH
:
1370 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1371 goto invalid_enum_error
;
1372 return ctx
->Point
.SmoothFlag
;
1373 case GL_POLYGON_SMOOTH
:
1374 if (!_mesa_is_desktop_gl(ctx
))
1375 goto invalid_enum_error
;
1376 return ctx
->Polygon
.SmoothFlag
;
1377 case GL_POLYGON_STIPPLE
:
1378 if (ctx
->API
!= API_OPENGL_COMPAT
)
1379 goto invalid_enum_error
;
1380 return ctx
->Polygon
.StippleFlag
;
1381 case GL_POLYGON_OFFSET_POINT
:
1382 if (!_mesa_is_desktop_gl(ctx
))
1383 goto invalid_enum_error
;
1384 return ctx
->Polygon
.OffsetPoint
;
1385 case GL_POLYGON_OFFSET_LINE
:
1386 if (!_mesa_is_desktop_gl(ctx
))
1387 goto invalid_enum_error
;
1388 return ctx
->Polygon
.OffsetLine
;
1389 case GL_POLYGON_OFFSET_FILL
:
1390 return ctx
->Polygon
.OffsetFill
;
1391 case GL_RESCALE_NORMAL_EXT
:
1392 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1393 goto invalid_enum_error
;
1394 return ctx
->Transform
.RescaleNormals
;
1395 case GL_SCISSOR_TEST
:
1396 return ctx
->Scissor
.EnableFlags
& 1; /* return state for index 0 */
1397 case GL_STENCIL_TEST
:
1398 return ctx
->Stencil
.Enabled
;
1400 if (ctx
->API
!= API_OPENGL_COMPAT
)
1401 goto invalid_enum_error
;
1402 return is_texture_enabled(ctx
, TEXTURE_1D_BIT
);
1404 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1405 goto invalid_enum_error
;
1406 return is_texture_enabled(ctx
, TEXTURE_2D_BIT
);
1408 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1409 goto invalid_enum_error
;
1410 return is_texture_enabled(ctx
, TEXTURE_3D_BIT
);
1411 case GL_TEXTURE_GEN_S
:
1412 case GL_TEXTURE_GEN_T
:
1413 case GL_TEXTURE_GEN_R
:
1414 case GL_TEXTURE_GEN_Q
:
1416 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1418 if (ctx
->API
!= API_OPENGL_COMPAT
)
1419 goto invalid_enum_error
;
1422 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
1423 return (texUnit
->TexGenEnabled
& coordBit
) ? GL_TRUE
: GL_FALSE
;
1427 case GL_TEXTURE_GEN_STR_OES
:
1429 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1431 if (ctx
->API
!= API_OPENGLES
)
1432 goto invalid_enum_error
;
1435 return (texUnit
->TexGenEnabled
& STR_BITS
) == STR_BITS
1436 ? GL_TRUE
: GL_FALSE
;
1440 /* client-side state */
1441 case GL_VERTEX_ARRAY
:
1442 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1443 goto invalid_enum_error
;
1444 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
;
1445 case GL_NORMAL_ARRAY
:
1446 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1447 goto invalid_enum_error
;
1448 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
;
1449 case GL_COLOR_ARRAY
:
1450 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1451 goto invalid_enum_error
;
1452 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
;
1453 case GL_INDEX_ARRAY
:
1454 if (ctx
->API
!= API_OPENGL_COMPAT
)
1455 goto invalid_enum_error
;
1456 return ctx
->Array
.VAO
->
1457 VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
;
1458 case GL_TEXTURE_COORD_ARRAY
:
1459 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1460 goto invalid_enum_error
;
1461 return ctx
->Array
.VAO
->
1462 VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Enabled
;
1463 case GL_EDGE_FLAG_ARRAY
:
1464 if (ctx
->API
!= API_OPENGL_COMPAT
)
1465 goto invalid_enum_error
;
1466 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
;
1467 case GL_FOG_COORDINATE_ARRAY_EXT
:
1468 if (ctx
->API
!= API_OPENGL_COMPAT
)
1469 goto invalid_enum_error
;
1470 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
;
1471 case GL_SECONDARY_COLOR_ARRAY_EXT
:
1472 if (ctx
->API
!= API_OPENGL_COMPAT
)
1473 goto invalid_enum_error
;
1474 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
;
1475 case GL_POINT_SIZE_ARRAY_OES
:
1476 if (ctx
->API
!= API_OPENGLES
)
1477 goto invalid_enum_error
;
1478 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
;
1480 /* GL_ARB_texture_cube_map */
1481 case GL_TEXTURE_CUBE_MAP
:
1482 CHECK_EXTENSION(ARB_texture_cube_map
);
1483 return is_texture_enabled(ctx
, TEXTURE_CUBE_BIT
);
1485 /* GL_EXT_secondary_color */
1486 case GL_COLOR_SUM_EXT
:
1487 if (ctx
->API
!= API_OPENGL_COMPAT
)
1488 goto invalid_enum_error
;
1489 return ctx
->Fog
.ColorSumEnabled
;
1491 /* GL_ARB_multisample */
1492 case GL_MULTISAMPLE_ARB
:
1493 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1494 goto invalid_enum_error
;
1495 return ctx
->Multisample
.Enabled
;
1496 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
1497 return ctx
->Multisample
.SampleAlphaToCoverage
;
1498 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
1499 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1500 goto invalid_enum_error
;
1501 return ctx
->Multisample
.SampleAlphaToOne
;
1502 case GL_SAMPLE_COVERAGE_ARB
:
1503 return ctx
->Multisample
.SampleCoverage
;
1504 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
1505 if (!_mesa_is_desktop_gl(ctx
))
1506 goto invalid_enum_error
;
1507 return ctx
->Multisample
.SampleCoverageInvert
;
1509 /* GL_IBM_rasterpos_clip */
1510 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
1511 if (ctx
->API
!= API_OPENGL_COMPAT
)
1512 goto invalid_enum_error
;
1513 return ctx
->Transform
.RasterPositionUnclipped
;
1515 /* GL_NV_point_sprite */
1516 case GL_POINT_SPRITE_NV
:
1517 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1518 goto invalid_enum_error
;
1519 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
)
1520 return ctx
->Point
.PointSprite
;
1522 case GL_VERTEX_PROGRAM_ARB
:
1523 if (ctx
->API
!= API_OPENGL_COMPAT
)
1524 goto invalid_enum_error
;
1525 CHECK_EXTENSION(ARB_vertex_program
);
1526 return ctx
->VertexProgram
.Enabled
;
1527 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
1528 /* This was added with ARB_vertex_program, but it is also used with
1529 * GLSL vertex shaders on desktop.
1531 if (!_mesa_is_desktop_gl(ctx
))
1532 goto invalid_enum_error
;
1533 CHECK_EXTENSION(ARB_vertex_program
);
1534 return ctx
->VertexProgram
.PointSizeEnabled
;
1535 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
1536 if (ctx
->API
!= API_OPENGL_COMPAT
)
1537 goto invalid_enum_error
;
1538 CHECK_EXTENSION(ARB_vertex_program
);
1539 return ctx
->VertexProgram
.TwoSideEnabled
;
1541 /* GL_NV_texture_rectangle */
1542 case GL_TEXTURE_RECTANGLE_NV
:
1543 if (ctx
->API
!= API_OPENGL_COMPAT
)
1544 goto invalid_enum_error
;
1545 CHECK_EXTENSION(NV_texture_rectangle
);
1546 return is_texture_enabled(ctx
, TEXTURE_RECT_BIT
);
1548 /* GL_EXT_stencil_two_side */
1549 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
1550 if (ctx
->API
!= API_OPENGL_COMPAT
)
1551 goto invalid_enum_error
;
1552 CHECK_EXTENSION(EXT_stencil_two_side
);
1553 return ctx
->Stencil
.TestTwoSide
;
1555 case GL_FRAGMENT_PROGRAM_ARB
:
1556 if (ctx
->API
!= API_OPENGL_COMPAT
)
1557 goto invalid_enum_error
;
1558 return ctx
->FragmentProgram
.Enabled
;
1560 /* GL_EXT_depth_bounds_test */
1561 case GL_DEPTH_BOUNDS_TEST_EXT
:
1562 if (!_mesa_is_desktop_gl(ctx
))
1563 goto invalid_enum_error
;
1564 CHECK_EXTENSION(EXT_depth_bounds_test
);
1565 return ctx
->Depth
.BoundsTest
;
1567 /* GL_ARB_depth_clamp */
1568 case GL_DEPTH_CLAMP
:
1569 if (!_mesa_is_desktop_gl(ctx
))
1570 goto invalid_enum_error
;
1571 CHECK_EXTENSION(ARB_depth_clamp
);
1572 return ctx
->Transform
.DepthClamp
;
1574 case GL_FRAGMENT_SHADER_ATI
:
1575 if (ctx
->API
!= API_OPENGL_COMPAT
)
1576 goto invalid_enum_error
;
1577 CHECK_EXTENSION(ATI_fragment_shader
);
1578 return ctx
->ATIFragmentShader
.Enabled
;
1580 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1581 if (!_mesa_is_desktop_gl(ctx
))
1582 goto invalid_enum_error
;
1583 CHECK_EXTENSION(ARB_seamless_cube_map
);
1584 return ctx
->Texture
.CubeMapSeamless
;
1586 case GL_RASTERIZER_DISCARD
:
1587 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1588 goto invalid_enum_error
;
1589 CHECK_EXTENSION(EXT_transform_feedback
);
1590 return ctx
->RasterDiscard
;
1592 /* GL_NV_primitive_restart */
1593 case GL_PRIMITIVE_RESTART_NV
:
1594 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.NV_primitive_restart
) {
1595 goto invalid_enum_error
;
1597 return ctx
->Array
.PrimitiveRestart
;
1599 /* GL 3.1 primitive restart */
1600 case GL_PRIMITIVE_RESTART
:
1601 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
1602 goto invalid_enum_error
;
1604 return ctx
->Array
.PrimitiveRestart
;
1606 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
1607 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
) {
1608 goto invalid_enum_error
;
1610 return ctx
->Array
.PrimitiveRestartFixedIndex
;
1612 /* GL3.0 - GL_framebuffer_sRGB */
1613 case GL_FRAMEBUFFER_SRGB_EXT
:
1614 if (!_mesa_is_desktop_gl(ctx
))
1615 goto invalid_enum_error
;
1616 CHECK_EXTENSION(EXT_framebuffer_sRGB
);
1617 return ctx
->Color
.sRGBEnabled
;
1619 /* GL_OES_EGL_image_external */
1620 case GL_TEXTURE_EXTERNAL_OES
:
1621 if (!_mesa_is_gles(ctx
))
1622 goto invalid_enum_error
;
1623 CHECK_EXTENSION(OES_EGL_image_external
);
1624 return is_texture_enabled(ctx
, TEXTURE_EXTERNAL_BIT
);
1626 /* ARB_texture_multisample */
1627 case GL_SAMPLE_MASK
:
1628 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
1629 goto invalid_enum_error
;
1630 CHECK_EXTENSION(ARB_texture_multisample
);
1631 return ctx
->Multisample
.SampleMask
;
1633 /* ARB_sample_shading */
1634 case GL_SAMPLE_SHADING
:
1635 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1636 goto invalid_enum_error
;
1637 CHECK_EXTENSION(ARB_sample_shading
);
1638 return ctx
->Multisample
.SampleShading
;
1640 case GL_BLEND_ADVANCED_COHERENT_KHR
:
1641 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent
);
1642 return ctx
->Color
.BlendCoherent
;
1644 case GL_CONSERVATIVE_RASTERIZATION_INTEL
:
1645 CHECK_EXTENSION(INTEL_conservative_rasterization
);
1646 return ctx
->IntelConservativeRasterization
;
1649 goto invalid_enum_error
;
1655 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabled(%s)",
1656 _mesa_enum_to_string(cap
));