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_STATE
);
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
;
388 ctx
->Fog
._PackedEnabledMode
= state
? ctx
->Fog
._PackedMode
: FOG_NONE
;
398 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
399 goto invalid_enum_error
;
400 if (ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
== state
)
402 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
403 ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
= state
;
405 ctx
->Light
._EnabledLights
|= 1u << (cap
- GL_LIGHT0
);
408 ctx
->Light
._EnabledLights
&= ~(1u << (cap
- GL_LIGHT0
));
412 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
413 goto invalid_enum_error
;
414 if (ctx
->Light
.Enabled
== state
)
416 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
417 ctx
->Light
.Enabled
= state
;
420 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
421 goto invalid_enum_error
;
422 if (ctx
->Line
.SmoothFlag
== state
)
424 FLUSH_VERTICES(ctx
, _NEW_LINE
);
425 ctx
->Line
.SmoothFlag
= state
;
427 case GL_LINE_STIPPLE
:
428 if (ctx
->API
!= API_OPENGL_COMPAT
)
429 goto invalid_enum_error
;
430 if (ctx
->Line
.StippleFlag
== state
)
432 FLUSH_VERTICES(ctx
, _NEW_LINE
);
433 ctx
->Line
.StippleFlag
= state
;
435 case GL_INDEX_LOGIC_OP
:
436 if (ctx
->API
!= API_OPENGL_COMPAT
)
437 goto invalid_enum_error
;
438 if (ctx
->Color
.IndexLogicOpEnabled
== state
)
440 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
441 ctx
->Color
.IndexLogicOpEnabled
= state
;
443 case GL_CONSERVATIVE_RASTERIZATION_INTEL
:
444 if (!_mesa_has_INTEL_conservative_rasterization(ctx
))
445 goto invalid_enum_error
;
446 if (ctx
->IntelConservativeRasterization
== state
)
448 FLUSH_VERTICES(ctx
, 0);
449 ctx
->NewDriverState
|=
450 ctx
->DriverFlags
.NewIntelConservativeRasterization
;
451 ctx
->IntelConservativeRasterization
= state
;
453 case GL_COLOR_LOGIC_OP
:
454 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
455 goto invalid_enum_error
;
456 if (ctx
->Color
.ColorLogicOpEnabled
== state
)
458 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
459 ctx
->Color
.ColorLogicOpEnabled
= state
;
461 case GL_MAP1_COLOR_4
:
462 if (ctx
->API
!= API_OPENGL_COMPAT
)
463 goto invalid_enum_error
;
464 if (ctx
->Eval
.Map1Color4
== state
)
466 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
467 ctx
->Eval
.Map1Color4
= state
;
470 if (ctx
->API
!= API_OPENGL_COMPAT
)
471 goto invalid_enum_error
;
472 if (ctx
->Eval
.Map1Index
== state
)
474 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
475 ctx
->Eval
.Map1Index
= state
;
478 if (ctx
->API
!= API_OPENGL_COMPAT
)
479 goto invalid_enum_error
;
480 if (ctx
->Eval
.Map1Normal
== state
)
482 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
483 ctx
->Eval
.Map1Normal
= state
;
485 case GL_MAP1_TEXTURE_COORD_1
:
486 if (ctx
->API
!= API_OPENGL_COMPAT
)
487 goto invalid_enum_error
;
488 if (ctx
->Eval
.Map1TextureCoord1
== state
)
490 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
491 ctx
->Eval
.Map1TextureCoord1
= state
;
493 case GL_MAP1_TEXTURE_COORD_2
:
494 if (ctx
->API
!= API_OPENGL_COMPAT
)
495 goto invalid_enum_error
;
496 if (ctx
->Eval
.Map1TextureCoord2
== state
)
498 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
499 ctx
->Eval
.Map1TextureCoord2
= state
;
501 case GL_MAP1_TEXTURE_COORD_3
:
502 if (ctx
->API
!= API_OPENGL_COMPAT
)
503 goto invalid_enum_error
;
504 if (ctx
->Eval
.Map1TextureCoord3
== state
)
506 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
507 ctx
->Eval
.Map1TextureCoord3
= state
;
509 case GL_MAP1_TEXTURE_COORD_4
:
510 if (ctx
->API
!= API_OPENGL_COMPAT
)
511 goto invalid_enum_error
;
512 if (ctx
->Eval
.Map1TextureCoord4
== state
)
514 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
515 ctx
->Eval
.Map1TextureCoord4
= state
;
517 case GL_MAP1_VERTEX_3
:
518 if (ctx
->API
!= API_OPENGL_COMPAT
)
519 goto invalid_enum_error
;
520 if (ctx
->Eval
.Map1Vertex3
== state
)
522 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
523 ctx
->Eval
.Map1Vertex3
= state
;
525 case GL_MAP1_VERTEX_4
:
526 if (ctx
->API
!= API_OPENGL_COMPAT
)
527 goto invalid_enum_error
;
528 if (ctx
->Eval
.Map1Vertex4
== state
)
530 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
531 ctx
->Eval
.Map1Vertex4
= state
;
533 case GL_MAP2_COLOR_4
:
534 if (ctx
->API
!= API_OPENGL_COMPAT
)
535 goto invalid_enum_error
;
536 if (ctx
->Eval
.Map2Color4
== state
)
538 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
539 ctx
->Eval
.Map2Color4
= state
;
542 if (ctx
->API
!= API_OPENGL_COMPAT
)
543 goto invalid_enum_error
;
544 if (ctx
->Eval
.Map2Index
== state
)
546 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
547 ctx
->Eval
.Map2Index
= state
;
550 if (ctx
->API
!= API_OPENGL_COMPAT
)
551 goto invalid_enum_error
;
552 if (ctx
->Eval
.Map2Normal
== state
)
554 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
555 ctx
->Eval
.Map2Normal
= state
;
557 case GL_MAP2_TEXTURE_COORD_1
:
558 if (ctx
->API
!= API_OPENGL_COMPAT
)
559 goto invalid_enum_error
;
560 if (ctx
->Eval
.Map2TextureCoord1
== state
)
562 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
563 ctx
->Eval
.Map2TextureCoord1
= state
;
565 case GL_MAP2_TEXTURE_COORD_2
:
566 if (ctx
->API
!= API_OPENGL_COMPAT
)
567 goto invalid_enum_error
;
568 if (ctx
->Eval
.Map2TextureCoord2
== state
)
570 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
571 ctx
->Eval
.Map2TextureCoord2
= state
;
573 case GL_MAP2_TEXTURE_COORD_3
:
574 if (ctx
->API
!= API_OPENGL_COMPAT
)
575 goto invalid_enum_error
;
576 if (ctx
->Eval
.Map2TextureCoord3
== state
)
578 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
579 ctx
->Eval
.Map2TextureCoord3
= state
;
581 case GL_MAP2_TEXTURE_COORD_4
:
582 if (ctx
->API
!= API_OPENGL_COMPAT
)
583 goto invalid_enum_error
;
584 if (ctx
->Eval
.Map2TextureCoord4
== state
)
586 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
587 ctx
->Eval
.Map2TextureCoord4
= state
;
589 case GL_MAP2_VERTEX_3
:
590 if (ctx
->API
!= API_OPENGL_COMPAT
)
591 goto invalid_enum_error
;
592 if (ctx
->Eval
.Map2Vertex3
== state
)
594 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
595 ctx
->Eval
.Map2Vertex3
= state
;
597 case GL_MAP2_VERTEX_4
:
598 if (ctx
->API
!= API_OPENGL_COMPAT
)
599 goto invalid_enum_error
;
600 if (ctx
->Eval
.Map2Vertex4
== state
)
602 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
603 ctx
->Eval
.Map2Vertex4
= state
;
606 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
607 goto invalid_enum_error
;
608 if (ctx
->Transform
.Normalize
== state
)
610 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
611 ctx
->Transform
.Normalize
= state
;
613 case GL_POINT_SMOOTH
:
614 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
615 goto invalid_enum_error
;
616 if (ctx
->Point
.SmoothFlag
== state
)
618 FLUSH_VERTICES(ctx
, _NEW_POINT
);
619 ctx
->Point
.SmoothFlag
= state
;
621 case GL_POLYGON_SMOOTH
:
622 if (!_mesa_is_desktop_gl(ctx
))
623 goto invalid_enum_error
;
624 if (ctx
->Polygon
.SmoothFlag
== state
)
626 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
627 ctx
->Polygon
.SmoothFlag
= state
;
629 case GL_POLYGON_STIPPLE
:
630 if (ctx
->API
!= API_OPENGL_COMPAT
)
631 goto invalid_enum_error
;
632 if (ctx
->Polygon
.StippleFlag
== state
)
634 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
635 ctx
->Polygon
.StippleFlag
= state
;
637 case GL_POLYGON_OFFSET_POINT
:
638 if (!_mesa_is_desktop_gl(ctx
))
639 goto invalid_enum_error
;
640 if (ctx
->Polygon
.OffsetPoint
== state
)
642 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
643 ctx
->Polygon
.OffsetPoint
= state
;
645 case GL_POLYGON_OFFSET_LINE
:
646 if (!_mesa_is_desktop_gl(ctx
))
647 goto invalid_enum_error
;
648 if (ctx
->Polygon
.OffsetLine
== state
)
650 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
651 ctx
->Polygon
.OffsetLine
= state
;
653 case GL_POLYGON_OFFSET_FILL
:
654 if (ctx
->Polygon
.OffsetFill
== state
)
656 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
657 ctx
->Polygon
.OffsetFill
= state
;
659 case GL_RESCALE_NORMAL_EXT
:
660 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
661 goto invalid_enum_error
;
662 if (ctx
->Transform
.RescaleNormals
== state
)
664 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
665 ctx
->Transform
.RescaleNormals
= state
;
667 case GL_SCISSOR_TEST
:
669 /* Must expand glEnable to all scissors */
670 GLbitfield newEnabled
=
671 state
* ((1 << ctx
->Const
.MaxViewports
) - 1);
672 if (newEnabled
!= ctx
->Scissor
.EnableFlags
) {
673 FLUSH_VERTICES(ctx
, _NEW_SCISSOR
);
674 ctx
->Scissor
.EnableFlags
= newEnabled
;
678 case GL_STENCIL_TEST
:
679 if (ctx
->Stencil
.Enabled
== state
)
681 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
682 ctx
->Stencil
.Enabled
= state
;
685 if (ctx
->API
!= API_OPENGL_COMPAT
)
686 goto invalid_enum_error
;
687 if (!enable_texture(ctx
, state
, TEXTURE_1D_BIT
)) {
692 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
693 goto invalid_enum_error
;
694 if (!enable_texture(ctx
, state
, TEXTURE_2D_BIT
)) {
699 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
700 goto invalid_enum_error
;
701 if (!enable_texture(ctx
, state
, TEXTURE_3D_BIT
)) {
705 case GL_TEXTURE_GEN_S
:
706 case GL_TEXTURE_GEN_T
:
707 case GL_TEXTURE_GEN_R
:
708 case GL_TEXTURE_GEN_Q
:
710 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
712 if (ctx
->API
!= API_OPENGL_COMPAT
)
713 goto invalid_enum_error
;
716 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
717 GLbitfield newenabled
= texUnit
->TexGenEnabled
& ~coordBit
;
719 newenabled
|= coordBit
;
720 if (texUnit
->TexGenEnabled
== newenabled
)
722 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_STATE
);
723 texUnit
->TexGenEnabled
= newenabled
;
728 case GL_TEXTURE_GEN_STR_OES
:
729 /* disable S, T, and R at the same time */
731 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
733 if (ctx
->API
!= API_OPENGLES
)
734 goto invalid_enum_error
;
738 texUnit
->TexGenEnabled
& ~STR_BITS
;
740 newenabled
|= STR_BITS
;
741 if (texUnit
->TexGenEnabled
== newenabled
)
743 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_STATE
);
744 texUnit
->TexGenEnabled
= newenabled
;
749 /* client-side state */
750 case GL_VERTEX_ARRAY
:
751 case GL_NORMAL_ARRAY
:
753 case GL_TEXTURE_COORD_ARRAY
:
754 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
755 goto invalid_enum_error
;
756 client_state( ctx
, cap
, state
);
759 case GL_EDGE_FLAG_ARRAY
:
760 case GL_FOG_COORDINATE_ARRAY_EXT
:
761 case GL_SECONDARY_COLOR_ARRAY_EXT
:
762 if (ctx
->API
!= API_OPENGL_COMPAT
)
763 goto invalid_enum_error
;
764 client_state( ctx
, cap
, state
);
766 case GL_POINT_SIZE_ARRAY_OES
:
767 if (ctx
->API
!= API_OPENGLES
)
768 goto invalid_enum_error
;
769 client_state( ctx
, cap
, state
);
772 /* GL_ARB_texture_cube_map */
773 case GL_TEXTURE_CUBE_MAP
:
774 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
775 goto invalid_enum_error
;
776 CHECK_EXTENSION(ARB_texture_cube_map
, cap
);
777 if (!enable_texture(ctx
, state
, TEXTURE_CUBE_BIT
)) {
782 /* GL_EXT_secondary_color */
783 case GL_COLOR_SUM_EXT
:
784 if (ctx
->API
!= API_OPENGL_COMPAT
)
785 goto invalid_enum_error
;
786 if (ctx
->Fog
.ColorSumEnabled
== state
)
788 FLUSH_VERTICES(ctx
, _NEW_FOG
);
789 ctx
->Fog
.ColorSumEnabled
= state
;
792 /* GL_ARB_multisample */
793 case GL_MULTISAMPLE_ARB
:
794 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
795 goto invalid_enum_error
;
796 _mesa_set_multisample(ctx
, state
);
798 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
799 if (ctx
->Multisample
.SampleAlphaToCoverage
== state
)
801 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
802 ctx
->Multisample
.SampleAlphaToCoverage
= state
;
804 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
805 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
806 goto invalid_enum_error
;
807 if (ctx
->Multisample
.SampleAlphaToOne
== state
)
809 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
810 ctx
->Multisample
.SampleAlphaToOne
= state
;
812 case GL_SAMPLE_COVERAGE_ARB
:
813 if (ctx
->Multisample
.SampleCoverage
== state
)
815 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
816 ctx
->Multisample
.SampleCoverage
= state
;
818 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
819 if (!_mesa_is_desktop_gl(ctx
))
820 goto invalid_enum_error
;
821 if (ctx
->Multisample
.SampleCoverageInvert
== state
)
823 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
824 ctx
->Multisample
.SampleCoverageInvert
= state
;
827 /* GL_ARB_sample_shading */
828 case GL_SAMPLE_SHADING
:
829 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
830 goto invalid_enum_error
;
831 CHECK_EXTENSION(ARB_sample_shading
, cap
);
832 if (ctx
->Multisample
.SampleShading
== state
)
834 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
835 ctx
->Multisample
.SampleShading
= state
;
838 /* GL_IBM_rasterpos_clip */
839 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
840 if (ctx
->API
!= API_OPENGL_COMPAT
)
841 goto invalid_enum_error
;
842 if (ctx
->Transform
.RasterPositionUnclipped
== state
)
844 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
845 ctx
->Transform
.RasterPositionUnclipped
= state
;
848 /* GL_NV_point_sprite */
849 case GL_POINT_SPRITE_NV
:
850 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
851 goto invalid_enum_error
;
852 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
, cap
);
853 if (ctx
->Point
.PointSprite
== state
)
855 FLUSH_VERTICES(ctx
, _NEW_POINT
);
856 ctx
->Point
.PointSprite
= state
;
859 case GL_VERTEX_PROGRAM_ARB
:
860 if (ctx
->API
!= API_OPENGL_COMPAT
)
861 goto invalid_enum_error
;
862 CHECK_EXTENSION(ARB_vertex_program
, cap
);
863 if (ctx
->VertexProgram
.Enabled
== state
)
865 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
866 ctx
->VertexProgram
.Enabled
= state
;
868 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
869 /* This was added with ARB_vertex_program, but it is also used with
870 * GLSL vertex shaders on desktop.
872 if (!_mesa_is_desktop_gl(ctx
))
873 goto invalid_enum_error
;
874 CHECK_EXTENSION(ARB_vertex_program
, cap
);
875 if (ctx
->VertexProgram
.PointSizeEnabled
== state
)
877 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
878 ctx
->VertexProgram
.PointSizeEnabled
= state
;
880 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
881 if (ctx
->API
!= API_OPENGL_COMPAT
)
882 goto invalid_enum_error
;
883 CHECK_EXTENSION(ARB_vertex_program
, cap
);
884 if (ctx
->VertexProgram
.TwoSideEnabled
== state
)
886 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
887 ctx
->VertexProgram
.TwoSideEnabled
= state
;
890 /* GL_NV_texture_rectangle */
891 case GL_TEXTURE_RECTANGLE_NV
:
892 if (ctx
->API
!= API_OPENGL_COMPAT
)
893 goto invalid_enum_error
;
894 CHECK_EXTENSION(NV_texture_rectangle
, cap
);
895 if (!enable_texture(ctx
, state
, TEXTURE_RECT_BIT
)) {
900 /* GL_EXT_stencil_two_side */
901 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
902 if (ctx
->API
!= API_OPENGL_COMPAT
)
903 goto invalid_enum_error
;
904 CHECK_EXTENSION(EXT_stencil_two_side
, cap
);
905 if (ctx
->Stencil
.TestTwoSide
== state
)
907 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
908 ctx
->Stencil
.TestTwoSide
= state
;
910 ctx
->Stencil
._BackFace
= 2;
912 ctx
->Stencil
._BackFace
= 1;
916 case GL_FRAGMENT_PROGRAM_ARB
:
917 if (ctx
->API
!= API_OPENGL_COMPAT
)
918 goto invalid_enum_error
;
919 CHECK_EXTENSION(ARB_fragment_program
, cap
);
920 if (ctx
->FragmentProgram
.Enabled
== state
)
922 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
923 ctx
->FragmentProgram
.Enabled
= state
;
926 /* GL_EXT_depth_bounds_test */
927 case GL_DEPTH_BOUNDS_TEST_EXT
:
928 if (!_mesa_is_desktop_gl(ctx
))
929 goto invalid_enum_error
;
930 CHECK_EXTENSION(EXT_depth_bounds_test
, cap
);
931 if (ctx
->Depth
.BoundsTest
== state
)
933 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
934 ctx
->Depth
.BoundsTest
= state
;
938 if (!_mesa_is_desktop_gl(ctx
))
939 goto invalid_enum_error
;
940 CHECK_EXTENSION(ARB_depth_clamp
, cap
);
941 if (ctx
->Transform
.DepthClamp
== state
)
943 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
944 ctx
->Transform
.DepthClamp
= state
;
947 case GL_FRAGMENT_SHADER_ATI
:
948 if (ctx
->API
!= API_OPENGL_COMPAT
)
949 goto invalid_enum_error
;
950 CHECK_EXTENSION(ATI_fragment_shader
, cap
);
951 if (ctx
->ATIFragmentShader
.Enabled
== state
)
953 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
954 ctx
->ATIFragmentShader
.Enabled
= state
;
957 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
958 if (!_mesa_is_desktop_gl(ctx
))
959 goto invalid_enum_error
;
960 CHECK_EXTENSION(ARB_seamless_cube_map
, cap
);
961 if (ctx
->Texture
.CubeMapSeamless
!= state
) {
962 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_OBJECT
);
963 ctx
->Texture
.CubeMapSeamless
= state
;
967 case GL_RASTERIZER_DISCARD
:
968 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
969 goto invalid_enum_error
;
970 CHECK_EXTENSION(EXT_transform_feedback
, cap
);
971 if (ctx
->RasterDiscard
!= state
) {
972 FLUSH_VERTICES(ctx
, 0);
973 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewRasterizerDiscard
;
974 ctx
->RasterDiscard
= state
;
978 /* GL 3.1 primitive restart. Note: this enum is different from
979 * GL_PRIMITIVE_RESTART_NV (which is client state).
981 case GL_PRIMITIVE_RESTART
:
982 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
983 goto invalid_enum_error
;
985 if (ctx
->Array
.PrimitiveRestart
!= state
) {
986 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
987 ctx
->Array
.PrimitiveRestart
= state
;
988 update_derived_primitive_restart_state(ctx
);
992 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
993 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
)
994 goto invalid_enum_error
;
995 if (ctx
->Array
.PrimitiveRestartFixedIndex
!= state
) {
996 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
997 ctx
->Array
.PrimitiveRestartFixedIndex
= state
;
998 update_derived_primitive_restart_state(ctx
);
1002 /* GL3.0 - GL_framebuffer_sRGB */
1003 case GL_FRAMEBUFFER_SRGB_EXT
:
1004 if (!_mesa_is_desktop_gl(ctx
))
1005 goto invalid_enum_error
;
1006 CHECK_EXTENSION(EXT_framebuffer_sRGB
, cap
);
1007 _mesa_set_framebuffer_srgb(ctx
, state
);
1010 /* GL_OES_EGL_image_external */
1011 case GL_TEXTURE_EXTERNAL_OES
:
1012 if (!_mesa_is_gles(ctx
))
1013 goto invalid_enum_error
;
1014 CHECK_EXTENSION(OES_EGL_image_external
, cap
);
1015 if (!enable_texture(ctx
, state
, TEXTURE_EXTERNAL_BIT
)) {
1020 /* ARB_texture_multisample */
1021 case GL_SAMPLE_MASK
:
1022 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
1023 goto invalid_enum_error
;
1024 CHECK_EXTENSION(ARB_texture_multisample
, cap
);
1025 if (ctx
->Multisample
.SampleMask
== state
)
1027 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
1028 ctx
->Multisample
.SampleMask
= state
;
1031 case GL_BLEND_ADVANCED_COHERENT_KHR
:
1032 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent
, cap
);
1033 if (ctx
->Color
.BlendCoherent
== state
)
1035 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
1036 ctx
->Color
.BlendCoherent
= state
;
1040 goto invalid_enum_error
;
1043 if (ctx
->Driver
.Enable
) {
1044 ctx
->Driver
.Enable( ctx
, cap
, state
);
1050 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%s(%s)",
1051 state
? "Enable" : "Disable", _mesa_enum_to_string(cap
));
1056 * Enable GL capability. Called by glEnable()
1057 * \param cap state to enable.
1060 _mesa_Enable( GLenum cap
)
1062 GET_CURRENT_CONTEXT(ctx
);
1064 _mesa_set_enable( ctx
, cap
, GL_TRUE
);
1069 * Disable GL capability. Called by glDisable()
1070 * \param cap state to disable.
1073 _mesa_Disable( GLenum cap
)
1075 GET_CURRENT_CONTEXT(ctx
);
1077 _mesa_set_enable( ctx
, cap
, GL_FALSE
);
1083 * Enable/disable an indexed state var.
1086 _mesa_set_enablei(struct gl_context
*ctx
, GLenum cap
,
1087 GLuint index
, GLboolean state
)
1089 assert(state
== 0 || state
== 1);
1092 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
1093 goto invalid_enum_error
;
1095 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1096 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1097 state
? "glEnableIndexed" : "glDisableIndexed", index
);
1100 if (((ctx
->Color
.BlendEnabled
>> index
) & 1) != state
) {
1101 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
1103 ctx
->Color
.BlendEnabled
|= (1 << index
);
1105 ctx
->Color
.BlendEnabled
&= ~(1 << index
);
1108 case GL_SCISSOR_TEST
:
1109 if (index
>= ctx
->Const
.MaxViewports
) {
1110 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1111 state
? "glEnablei" : "glDisablei", index
);
1114 if (((ctx
->Scissor
.EnableFlags
>> index
) & 1) != state
) {
1115 FLUSH_VERTICES(ctx
, _NEW_SCISSOR
);
1117 ctx
->Scissor
.EnableFlags
|= (1 << index
);
1119 ctx
->Scissor
.EnableFlags
&= ~(1 << index
);
1123 goto invalid_enum_error
;
1128 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(cap=%s)",
1129 state
? "glEnablei" : "glDisablei",
1130 _mesa_enum_to_string(cap
));
1135 _mesa_Disablei( GLenum cap
, GLuint index
)
1137 GET_CURRENT_CONTEXT(ctx
);
1138 _mesa_set_enablei(ctx
, cap
, index
, GL_FALSE
);
1143 _mesa_Enablei( GLenum cap
, GLuint index
)
1145 GET_CURRENT_CONTEXT(ctx
);
1146 _mesa_set_enablei(ctx
, cap
, index
, GL_TRUE
);
1150 GLboolean GLAPIENTRY
1151 _mesa_IsEnabledi( GLenum cap
, GLuint index
)
1153 GET_CURRENT_CONTEXT(ctx
);
1154 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1157 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1158 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1162 return (ctx
->Color
.BlendEnabled
>> index
) & 1;
1163 case GL_SCISSOR_TEST
:
1164 if (index
>= ctx
->Const
.MaxViewports
) {
1165 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1169 return (ctx
->Scissor
.EnableFlags
>> index
) & 1;
1171 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabledIndexed(cap=%s)",
1172 _mesa_enum_to_string(cap
));
1180 #undef CHECK_EXTENSION
1181 #define CHECK_EXTENSION(EXTNAME) \
1182 if (!ctx->Extensions.EXTNAME) { \
1183 goto invalid_enum_error; \
1186 #undef CHECK_EXTENSION2
1187 #define CHECK_EXTENSION2(EXT1, EXT2) \
1188 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1189 goto invalid_enum_error; \
1194 * Helper function to determine whether a texture target is enabled.
1197 is_texture_enabled(struct gl_context
*ctx
, GLbitfield bit
)
1199 const struct gl_texture_unit
*const texUnit
=
1200 &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1201 return (texUnit
->Enabled
& bit
) ? GL_TRUE
: GL_FALSE
;
1206 * Return simple enable/disable state.
1208 * \param cap state variable to query.
1210 * Returns the state of the specified capability from the current GL context.
1211 * For the capabilities associated with extensions verifies that those
1212 * extensions are effectively present before reporting.
1214 GLboolean GLAPIENTRY
1215 _mesa_IsEnabled( GLenum cap
)
1217 GET_CURRENT_CONTEXT(ctx
);
1218 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1222 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1223 goto invalid_enum_error
;
1224 return ctx
->Color
.AlphaEnabled
;
1225 case GL_AUTO_NORMAL
:
1226 if (ctx
->API
!= API_OPENGL_COMPAT
)
1227 goto invalid_enum_error
;
1228 return ctx
->Eval
.AutoNormal
;
1230 return ctx
->Color
.BlendEnabled
& 1; /* return state for buffer[0] */
1231 case GL_CLIP_DISTANCE0
: /* aka GL_CLIP_PLANE0 */
1232 case GL_CLIP_DISTANCE1
:
1233 case GL_CLIP_DISTANCE2
:
1234 case GL_CLIP_DISTANCE3
:
1235 case GL_CLIP_DISTANCE4
:
1236 case GL_CLIP_DISTANCE5
:
1237 case GL_CLIP_DISTANCE6
:
1238 case GL_CLIP_DISTANCE7
: {
1239 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
1241 if (p
>= ctx
->Const
.MaxClipPlanes
)
1242 goto invalid_enum_error
;
1244 return (ctx
->Transform
.ClipPlanesEnabled
>> p
) & 1;
1246 case GL_COLOR_MATERIAL
:
1247 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1248 goto invalid_enum_error
;
1249 return ctx
->Light
.ColorMaterialEnabled
;
1251 return ctx
->Polygon
.CullFlag
;
1252 case GL_DEBUG_OUTPUT
:
1253 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
:
1254 return (GLboolean
) _mesa_get_debug_state_int(ctx
, cap
);
1256 return ctx
->Depth
.Test
;
1258 return ctx
->Color
.DitherFlag
;
1260 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1261 goto invalid_enum_error
;
1262 return ctx
->Fog
.Enabled
;
1264 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1265 goto invalid_enum_error
;
1266 return ctx
->Light
.Enabled
;
1275 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1276 goto invalid_enum_error
;
1277 return ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
;
1278 case GL_LINE_SMOOTH
:
1279 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1280 goto invalid_enum_error
;
1281 return ctx
->Line
.SmoothFlag
;
1282 case GL_LINE_STIPPLE
:
1283 if (ctx
->API
!= API_OPENGL_COMPAT
)
1284 goto invalid_enum_error
;
1285 return ctx
->Line
.StippleFlag
;
1286 case GL_INDEX_LOGIC_OP
:
1287 if (ctx
->API
!= API_OPENGL_COMPAT
)
1288 goto invalid_enum_error
;
1289 return ctx
->Color
.IndexLogicOpEnabled
;
1290 case GL_COLOR_LOGIC_OP
:
1291 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1292 goto invalid_enum_error
;
1293 return ctx
->Color
.ColorLogicOpEnabled
;
1294 case GL_MAP1_COLOR_4
:
1295 if (ctx
->API
!= API_OPENGL_COMPAT
)
1296 goto invalid_enum_error
;
1297 return ctx
->Eval
.Map1Color4
;
1299 if (ctx
->API
!= API_OPENGL_COMPAT
)
1300 goto invalid_enum_error
;
1301 return ctx
->Eval
.Map1Index
;
1302 case GL_MAP1_NORMAL
:
1303 if (ctx
->API
!= API_OPENGL_COMPAT
)
1304 goto invalid_enum_error
;
1305 return ctx
->Eval
.Map1Normal
;
1306 case GL_MAP1_TEXTURE_COORD_1
:
1307 if (ctx
->API
!= API_OPENGL_COMPAT
)
1308 goto invalid_enum_error
;
1309 return ctx
->Eval
.Map1TextureCoord1
;
1310 case GL_MAP1_TEXTURE_COORD_2
:
1311 if (ctx
->API
!= API_OPENGL_COMPAT
)
1312 goto invalid_enum_error
;
1313 return ctx
->Eval
.Map1TextureCoord2
;
1314 case GL_MAP1_TEXTURE_COORD_3
:
1315 if (ctx
->API
!= API_OPENGL_COMPAT
)
1316 goto invalid_enum_error
;
1317 return ctx
->Eval
.Map1TextureCoord3
;
1318 case GL_MAP1_TEXTURE_COORD_4
:
1319 if (ctx
->API
!= API_OPENGL_COMPAT
)
1320 goto invalid_enum_error
;
1321 return ctx
->Eval
.Map1TextureCoord4
;
1322 case GL_MAP1_VERTEX_3
:
1323 if (ctx
->API
!= API_OPENGL_COMPAT
)
1324 goto invalid_enum_error
;
1325 return ctx
->Eval
.Map1Vertex3
;
1326 case GL_MAP1_VERTEX_4
:
1327 if (ctx
->API
!= API_OPENGL_COMPAT
)
1328 goto invalid_enum_error
;
1329 return ctx
->Eval
.Map1Vertex4
;
1330 case GL_MAP2_COLOR_4
:
1331 if (ctx
->API
!= API_OPENGL_COMPAT
)
1332 goto invalid_enum_error
;
1333 return ctx
->Eval
.Map2Color4
;
1335 if (ctx
->API
!= API_OPENGL_COMPAT
)
1336 goto invalid_enum_error
;
1337 return ctx
->Eval
.Map2Index
;
1338 case GL_MAP2_NORMAL
:
1339 if (ctx
->API
!= API_OPENGL_COMPAT
)
1340 goto invalid_enum_error
;
1341 return ctx
->Eval
.Map2Normal
;
1342 case GL_MAP2_TEXTURE_COORD_1
:
1343 if (ctx
->API
!= API_OPENGL_COMPAT
)
1344 goto invalid_enum_error
;
1345 return ctx
->Eval
.Map2TextureCoord1
;
1346 case GL_MAP2_TEXTURE_COORD_2
:
1347 if (ctx
->API
!= API_OPENGL_COMPAT
)
1348 goto invalid_enum_error
;
1349 return ctx
->Eval
.Map2TextureCoord2
;
1350 case GL_MAP2_TEXTURE_COORD_3
:
1351 if (ctx
->API
!= API_OPENGL_COMPAT
)
1352 goto invalid_enum_error
;
1353 return ctx
->Eval
.Map2TextureCoord3
;
1354 case GL_MAP2_TEXTURE_COORD_4
:
1355 if (ctx
->API
!= API_OPENGL_COMPAT
)
1356 goto invalid_enum_error
;
1357 return ctx
->Eval
.Map2TextureCoord4
;
1358 case GL_MAP2_VERTEX_3
:
1359 if (ctx
->API
!= API_OPENGL_COMPAT
)
1360 goto invalid_enum_error
;
1361 return ctx
->Eval
.Map2Vertex3
;
1362 case GL_MAP2_VERTEX_4
:
1363 if (ctx
->API
!= API_OPENGL_COMPAT
)
1364 goto invalid_enum_error
;
1365 return ctx
->Eval
.Map2Vertex4
;
1367 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1368 goto invalid_enum_error
;
1369 return ctx
->Transform
.Normalize
;
1370 case GL_POINT_SMOOTH
:
1371 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1372 goto invalid_enum_error
;
1373 return ctx
->Point
.SmoothFlag
;
1374 case GL_POLYGON_SMOOTH
:
1375 if (!_mesa_is_desktop_gl(ctx
))
1376 goto invalid_enum_error
;
1377 return ctx
->Polygon
.SmoothFlag
;
1378 case GL_POLYGON_STIPPLE
:
1379 if (ctx
->API
!= API_OPENGL_COMPAT
)
1380 goto invalid_enum_error
;
1381 return ctx
->Polygon
.StippleFlag
;
1382 case GL_POLYGON_OFFSET_POINT
:
1383 if (!_mesa_is_desktop_gl(ctx
))
1384 goto invalid_enum_error
;
1385 return ctx
->Polygon
.OffsetPoint
;
1386 case GL_POLYGON_OFFSET_LINE
:
1387 if (!_mesa_is_desktop_gl(ctx
))
1388 goto invalid_enum_error
;
1389 return ctx
->Polygon
.OffsetLine
;
1390 case GL_POLYGON_OFFSET_FILL
:
1391 return ctx
->Polygon
.OffsetFill
;
1392 case GL_RESCALE_NORMAL_EXT
:
1393 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1394 goto invalid_enum_error
;
1395 return ctx
->Transform
.RescaleNormals
;
1396 case GL_SCISSOR_TEST
:
1397 return ctx
->Scissor
.EnableFlags
& 1; /* return state for index 0 */
1398 case GL_STENCIL_TEST
:
1399 return ctx
->Stencil
.Enabled
;
1401 if (ctx
->API
!= API_OPENGL_COMPAT
)
1402 goto invalid_enum_error
;
1403 return is_texture_enabled(ctx
, TEXTURE_1D_BIT
);
1405 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1406 goto invalid_enum_error
;
1407 return is_texture_enabled(ctx
, TEXTURE_2D_BIT
);
1409 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1410 goto invalid_enum_error
;
1411 return is_texture_enabled(ctx
, TEXTURE_3D_BIT
);
1412 case GL_TEXTURE_GEN_S
:
1413 case GL_TEXTURE_GEN_T
:
1414 case GL_TEXTURE_GEN_R
:
1415 case GL_TEXTURE_GEN_Q
:
1417 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1419 if (ctx
->API
!= API_OPENGL_COMPAT
)
1420 goto invalid_enum_error
;
1423 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
1424 return (texUnit
->TexGenEnabled
& coordBit
) ? GL_TRUE
: GL_FALSE
;
1428 case GL_TEXTURE_GEN_STR_OES
:
1430 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1432 if (ctx
->API
!= API_OPENGLES
)
1433 goto invalid_enum_error
;
1436 return (texUnit
->TexGenEnabled
& STR_BITS
) == STR_BITS
1437 ? GL_TRUE
: GL_FALSE
;
1441 /* client-side state */
1442 case GL_VERTEX_ARRAY
:
1443 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1444 goto invalid_enum_error
;
1445 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
;
1446 case GL_NORMAL_ARRAY
:
1447 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1448 goto invalid_enum_error
;
1449 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
;
1450 case GL_COLOR_ARRAY
:
1451 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1452 goto invalid_enum_error
;
1453 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
;
1454 case GL_INDEX_ARRAY
:
1455 if (ctx
->API
!= API_OPENGL_COMPAT
)
1456 goto invalid_enum_error
;
1457 return ctx
->Array
.VAO
->
1458 VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
;
1459 case GL_TEXTURE_COORD_ARRAY
:
1460 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1461 goto invalid_enum_error
;
1462 return ctx
->Array
.VAO
->
1463 VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Enabled
;
1464 case GL_EDGE_FLAG_ARRAY
:
1465 if (ctx
->API
!= API_OPENGL_COMPAT
)
1466 goto invalid_enum_error
;
1467 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
;
1468 case GL_FOG_COORDINATE_ARRAY_EXT
:
1469 if (ctx
->API
!= API_OPENGL_COMPAT
)
1470 goto invalid_enum_error
;
1471 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
;
1472 case GL_SECONDARY_COLOR_ARRAY_EXT
:
1473 if (ctx
->API
!= API_OPENGL_COMPAT
)
1474 goto invalid_enum_error
;
1475 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
;
1476 case GL_POINT_SIZE_ARRAY_OES
:
1477 if (ctx
->API
!= API_OPENGLES
)
1478 goto invalid_enum_error
;
1479 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
;
1481 /* GL_ARB_texture_cube_map */
1482 case GL_TEXTURE_CUBE_MAP
:
1483 CHECK_EXTENSION(ARB_texture_cube_map
);
1484 return is_texture_enabled(ctx
, TEXTURE_CUBE_BIT
);
1486 /* GL_EXT_secondary_color */
1487 case GL_COLOR_SUM_EXT
:
1488 if (ctx
->API
!= API_OPENGL_COMPAT
)
1489 goto invalid_enum_error
;
1490 return ctx
->Fog
.ColorSumEnabled
;
1492 /* GL_ARB_multisample */
1493 case GL_MULTISAMPLE_ARB
:
1494 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1495 goto invalid_enum_error
;
1496 return ctx
->Multisample
.Enabled
;
1497 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
1498 return ctx
->Multisample
.SampleAlphaToCoverage
;
1499 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
1500 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1501 goto invalid_enum_error
;
1502 return ctx
->Multisample
.SampleAlphaToOne
;
1503 case GL_SAMPLE_COVERAGE_ARB
:
1504 return ctx
->Multisample
.SampleCoverage
;
1505 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
1506 if (!_mesa_is_desktop_gl(ctx
))
1507 goto invalid_enum_error
;
1508 return ctx
->Multisample
.SampleCoverageInvert
;
1510 /* GL_IBM_rasterpos_clip */
1511 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
1512 if (ctx
->API
!= API_OPENGL_COMPAT
)
1513 goto invalid_enum_error
;
1514 return ctx
->Transform
.RasterPositionUnclipped
;
1516 /* GL_NV_point_sprite */
1517 case GL_POINT_SPRITE_NV
:
1518 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1519 goto invalid_enum_error
;
1520 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
)
1521 return ctx
->Point
.PointSprite
;
1523 case GL_VERTEX_PROGRAM_ARB
:
1524 if (ctx
->API
!= API_OPENGL_COMPAT
)
1525 goto invalid_enum_error
;
1526 CHECK_EXTENSION(ARB_vertex_program
);
1527 return ctx
->VertexProgram
.Enabled
;
1528 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
1529 /* This was added with ARB_vertex_program, but it is also used with
1530 * GLSL vertex shaders on desktop.
1532 if (!_mesa_is_desktop_gl(ctx
))
1533 goto invalid_enum_error
;
1534 CHECK_EXTENSION(ARB_vertex_program
);
1535 return ctx
->VertexProgram
.PointSizeEnabled
;
1536 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
1537 if (ctx
->API
!= API_OPENGL_COMPAT
)
1538 goto invalid_enum_error
;
1539 CHECK_EXTENSION(ARB_vertex_program
);
1540 return ctx
->VertexProgram
.TwoSideEnabled
;
1542 /* GL_NV_texture_rectangle */
1543 case GL_TEXTURE_RECTANGLE_NV
:
1544 if (ctx
->API
!= API_OPENGL_COMPAT
)
1545 goto invalid_enum_error
;
1546 CHECK_EXTENSION(NV_texture_rectangle
);
1547 return is_texture_enabled(ctx
, TEXTURE_RECT_BIT
);
1549 /* GL_EXT_stencil_two_side */
1550 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
1551 if (ctx
->API
!= API_OPENGL_COMPAT
)
1552 goto invalid_enum_error
;
1553 CHECK_EXTENSION(EXT_stencil_two_side
);
1554 return ctx
->Stencil
.TestTwoSide
;
1556 case GL_FRAGMENT_PROGRAM_ARB
:
1557 if (ctx
->API
!= API_OPENGL_COMPAT
)
1558 goto invalid_enum_error
;
1559 return ctx
->FragmentProgram
.Enabled
;
1561 /* GL_EXT_depth_bounds_test */
1562 case GL_DEPTH_BOUNDS_TEST_EXT
:
1563 if (!_mesa_is_desktop_gl(ctx
))
1564 goto invalid_enum_error
;
1565 CHECK_EXTENSION(EXT_depth_bounds_test
);
1566 return ctx
->Depth
.BoundsTest
;
1568 /* GL_ARB_depth_clamp */
1569 case GL_DEPTH_CLAMP
:
1570 if (!_mesa_is_desktop_gl(ctx
))
1571 goto invalid_enum_error
;
1572 CHECK_EXTENSION(ARB_depth_clamp
);
1573 return ctx
->Transform
.DepthClamp
;
1575 case GL_FRAGMENT_SHADER_ATI
:
1576 if (ctx
->API
!= API_OPENGL_COMPAT
)
1577 goto invalid_enum_error
;
1578 CHECK_EXTENSION(ATI_fragment_shader
);
1579 return ctx
->ATIFragmentShader
.Enabled
;
1581 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1582 if (!_mesa_is_desktop_gl(ctx
))
1583 goto invalid_enum_error
;
1584 CHECK_EXTENSION(ARB_seamless_cube_map
);
1585 return ctx
->Texture
.CubeMapSeamless
;
1587 case GL_RASTERIZER_DISCARD
:
1588 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1589 goto invalid_enum_error
;
1590 CHECK_EXTENSION(EXT_transform_feedback
);
1591 return ctx
->RasterDiscard
;
1593 /* GL_NV_primitive_restart */
1594 case GL_PRIMITIVE_RESTART_NV
:
1595 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.NV_primitive_restart
) {
1596 goto invalid_enum_error
;
1598 return ctx
->Array
.PrimitiveRestart
;
1600 /* GL 3.1 primitive restart */
1601 case GL_PRIMITIVE_RESTART
:
1602 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
1603 goto invalid_enum_error
;
1605 return ctx
->Array
.PrimitiveRestart
;
1607 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
1608 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
) {
1609 goto invalid_enum_error
;
1611 return ctx
->Array
.PrimitiveRestartFixedIndex
;
1613 /* GL3.0 - GL_framebuffer_sRGB */
1614 case GL_FRAMEBUFFER_SRGB_EXT
:
1615 if (!_mesa_is_desktop_gl(ctx
))
1616 goto invalid_enum_error
;
1617 CHECK_EXTENSION(EXT_framebuffer_sRGB
);
1618 return ctx
->Color
.sRGBEnabled
;
1620 /* GL_OES_EGL_image_external */
1621 case GL_TEXTURE_EXTERNAL_OES
:
1622 if (!_mesa_is_gles(ctx
))
1623 goto invalid_enum_error
;
1624 CHECK_EXTENSION(OES_EGL_image_external
);
1625 return is_texture_enabled(ctx
, TEXTURE_EXTERNAL_BIT
);
1627 /* ARB_texture_multisample */
1628 case GL_SAMPLE_MASK
:
1629 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
1630 goto invalid_enum_error
;
1631 CHECK_EXTENSION(ARB_texture_multisample
);
1632 return ctx
->Multisample
.SampleMask
;
1634 /* ARB_sample_shading */
1635 case GL_SAMPLE_SHADING
:
1636 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1637 goto invalid_enum_error
;
1638 CHECK_EXTENSION(ARB_sample_shading
);
1639 return ctx
->Multisample
.SampleShading
;
1641 case GL_BLEND_ADVANCED_COHERENT_KHR
:
1642 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent
);
1643 return ctx
->Color
.BlendCoherent
;
1645 case GL_CONSERVATIVE_RASTERIZATION_INTEL
:
1646 CHECK_EXTENSION(INTEL_conservative_rasterization
);
1647 return ctx
->IntelConservativeRasterization
;
1650 goto invalid_enum_error
;
1656 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabled(%s)",
1657 _mesa_enum_to_string(cap
));