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_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
444 goto invalid_enum_error
;
445 if (ctx
->IntelConservativeRasterization
== state
)
447 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
448 ctx
->IntelConservativeRasterization
= state
;
450 case GL_COLOR_LOGIC_OP
:
451 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
452 goto invalid_enum_error
;
453 if (ctx
->Color
.ColorLogicOpEnabled
== state
)
455 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
456 ctx
->Color
.ColorLogicOpEnabled
= state
;
458 case GL_MAP1_COLOR_4
:
459 if (ctx
->API
!= API_OPENGL_COMPAT
)
460 goto invalid_enum_error
;
461 if (ctx
->Eval
.Map1Color4
== state
)
463 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
464 ctx
->Eval
.Map1Color4
= state
;
467 if (ctx
->API
!= API_OPENGL_COMPAT
)
468 goto invalid_enum_error
;
469 if (ctx
->Eval
.Map1Index
== state
)
471 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
472 ctx
->Eval
.Map1Index
= state
;
475 if (ctx
->API
!= API_OPENGL_COMPAT
)
476 goto invalid_enum_error
;
477 if (ctx
->Eval
.Map1Normal
== state
)
479 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
480 ctx
->Eval
.Map1Normal
= state
;
482 case GL_MAP1_TEXTURE_COORD_1
:
483 if (ctx
->API
!= API_OPENGL_COMPAT
)
484 goto invalid_enum_error
;
485 if (ctx
->Eval
.Map1TextureCoord1
== state
)
487 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
488 ctx
->Eval
.Map1TextureCoord1
= state
;
490 case GL_MAP1_TEXTURE_COORD_2
:
491 if (ctx
->API
!= API_OPENGL_COMPAT
)
492 goto invalid_enum_error
;
493 if (ctx
->Eval
.Map1TextureCoord2
== state
)
495 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
496 ctx
->Eval
.Map1TextureCoord2
= state
;
498 case GL_MAP1_TEXTURE_COORD_3
:
499 if (ctx
->API
!= API_OPENGL_COMPAT
)
500 goto invalid_enum_error
;
501 if (ctx
->Eval
.Map1TextureCoord3
== state
)
503 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
504 ctx
->Eval
.Map1TextureCoord3
= state
;
506 case GL_MAP1_TEXTURE_COORD_4
:
507 if (ctx
->API
!= API_OPENGL_COMPAT
)
508 goto invalid_enum_error
;
509 if (ctx
->Eval
.Map1TextureCoord4
== state
)
511 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
512 ctx
->Eval
.Map1TextureCoord4
= state
;
514 case GL_MAP1_VERTEX_3
:
515 if (ctx
->API
!= API_OPENGL_COMPAT
)
516 goto invalid_enum_error
;
517 if (ctx
->Eval
.Map1Vertex3
== state
)
519 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
520 ctx
->Eval
.Map1Vertex3
= state
;
522 case GL_MAP1_VERTEX_4
:
523 if (ctx
->API
!= API_OPENGL_COMPAT
)
524 goto invalid_enum_error
;
525 if (ctx
->Eval
.Map1Vertex4
== state
)
527 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
528 ctx
->Eval
.Map1Vertex4
= state
;
530 case GL_MAP2_COLOR_4
:
531 if (ctx
->API
!= API_OPENGL_COMPAT
)
532 goto invalid_enum_error
;
533 if (ctx
->Eval
.Map2Color4
== state
)
535 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
536 ctx
->Eval
.Map2Color4
= state
;
539 if (ctx
->API
!= API_OPENGL_COMPAT
)
540 goto invalid_enum_error
;
541 if (ctx
->Eval
.Map2Index
== state
)
543 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
544 ctx
->Eval
.Map2Index
= state
;
547 if (ctx
->API
!= API_OPENGL_COMPAT
)
548 goto invalid_enum_error
;
549 if (ctx
->Eval
.Map2Normal
== state
)
551 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
552 ctx
->Eval
.Map2Normal
= state
;
554 case GL_MAP2_TEXTURE_COORD_1
:
555 if (ctx
->API
!= API_OPENGL_COMPAT
)
556 goto invalid_enum_error
;
557 if (ctx
->Eval
.Map2TextureCoord1
== state
)
559 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
560 ctx
->Eval
.Map2TextureCoord1
= state
;
562 case GL_MAP2_TEXTURE_COORD_2
:
563 if (ctx
->API
!= API_OPENGL_COMPAT
)
564 goto invalid_enum_error
;
565 if (ctx
->Eval
.Map2TextureCoord2
== state
)
567 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
568 ctx
->Eval
.Map2TextureCoord2
= state
;
570 case GL_MAP2_TEXTURE_COORD_3
:
571 if (ctx
->API
!= API_OPENGL_COMPAT
)
572 goto invalid_enum_error
;
573 if (ctx
->Eval
.Map2TextureCoord3
== state
)
575 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
576 ctx
->Eval
.Map2TextureCoord3
= state
;
578 case GL_MAP2_TEXTURE_COORD_4
:
579 if (ctx
->API
!= API_OPENGL_COMPAT
)
580 goto invalid_enum_error
;
581 if (ctx
->Eval
.Map2TextureCoord4
== state
)
583 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
584 ctx
->Eval
.Map2TextureCoord4
= state
;
586 case GL_MAP2_VERTEX_3
:
587 if (ctx
->API
!= API_OPENGL_COMPAT
)
588 goto invalid_enum_error
;
589 if (ctx
->Eval
.Map2Vertex3
== state
)
591 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
592 ctx
->Eval
.Map2Vertex3
= state
;
594 case GL_MAP2_VERTEX_4
:
595 if (ctx
->API
!= API_OPENGL_COMPAT
)
596 goto invalid_enum_error
;
597 if (ctx
->Eval
.Map2Vertex4
== state
)
599 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
600 ctx
->Eval
.Map2Vertex4
= state
;
603 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
604 goto invalid_enum_error
;
605 if (ctx
->Transform
.Normalize
== state
)
607 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
608 ctx
->Transform
.Normalize
= state
;
610 case GL_POINT_SMOOTH
:
611 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
612 goto invalid_enum_error
;
613 if (ctx
->Point
.SmoothFlag
== state
)
615 FLUSH_VERTICES(ctx
, _NEW_POINT
);
616 ctx
->Point
.SmoothFlag
= state
;
618 case GL_POLYGON_SMOOTH
:
619 if (!_mesa_is_desktop_gl(ctx
))
620 goto invalid_enum_error
;
621 if (ctx
->Polygon
.SmoothFlag
== state
)
623 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
624 ctx
->Polygon
.SmoothFlag
= state
;
626 case GL_POLYGON_STIPPLE
:
627 if (ctx
->API
!= API_OPENGL_COMPAT
)
628 goto invalid_enum_error
;
629 if (ctx
->Polygon
.StippleFlag
== state
)
631 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
632 ctx
->Polygon
.StippleFlag
= state
;
634 case GL_POLYGON_OFFSET_POINT
:
635 if (!_mesa_is_desktop_gl(ctx
))
636 goto invalid_enum_error
;
637 if (ctx
->Polygon
.OffsetPoint
== state
)
639 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
640 ctx
->Polygon
.OffsetPoint
= state
;
642 case GL_POLYGON_OFFSET_LINE
:
643 if (!_mesa_is_desktop_gl(ctx
))
644 goto invalid_enum_error
;
645 if (ctx
->Polygon
.OffsetLine
== state
)
647 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
648 ctx
->Polygon
.OffsetLine
= state
;
650 case GL_POLYGON_OFFSET_FILL
:
651 if (ctx
->Polygon
.OffsetFill
== state
)
653 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
654 ctx
->Polygon
.OffsetFill
= state
;
656 case GL_RESCALE_NORMAL_EXT
:
657 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
658 goto invalid_enum_error
;
659 if (ctx
->Transform
.RescaleNormals
== state
)
661 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
662 ctx
->Transform
.RescaleNormals
= state
;
664 case GL_SCISSOR_TEST
:
666 /* Must expand glEnable to all scissors */
667 GLbitfield newEnabled
=
668 state
* ((1 << ctx
->Const
.MaxViewports
) - 1);
669 if (newEnabled
!= ctx
->Scissor
.EnableFlags
) {
670 FLUSH_VERTICES(ctx
, _NEW_SCISSOR
);
671 ctx
->Scissor
.EnableFlags
= newEnabled
;
675 case GL_STENCIL_TEST
:
676 if (ctx
->Stencil
.Enabled
== state
)
678 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
679 ctx
->Stencil
.Enabled
= state
;
682 if (ctx
->API
!= API_OPENGL_COMPAT
)
683 goto invalid_enum_error
;
684 if (!enable_texture(ctx
, state
, TEXTURE_1D_BIT
)) {
689 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
690 goto invalid_enum_error
;
691 if (!enable_texture(ctx
, state
, TEXTURE_2D_BIT
)) {
696 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
697 goto invalid_enum_error
;
698 if (!enable_texture(ctx
, state
, TEXTURE_3D_BIT
)) {
702 case GL_TEXTURE_GEN_S
:
703 case GL_TEXTURE_GEN_T
:
704 case GL_TEXTURE_GEN_R
:
705 case GL_TEXTURE_GEN_Q
:
707 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
709 if (ctx
->API
!= API_OPENGL_COMPAT
)
710 goto invalid_enum_error
;
713 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
714 GLbitfield newenabled
= texUnit
->TexGenEnabled
& ~coordBit
;
716 newenabled
|= coordBit
;
717 if (texUnit
->TexGenEnabled
== newenabled
)
719 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
720 texUnit
->TexGenEnabled
= newenabled
;
725 case GL_TEXTURE_GEN_STR_OES
:
726 /* disable S, T, and R at the same time */
728 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
730 if (ctx
->API
!= API_OPENGLES
)
731 goto invalid_enum_error
;
735 texUnit
->TexGenEnabled
& ~STR_BITS
;
737 newenabled
|= STR_BITS
;
738 if (texUnit
->TexGenEnabled
== newenabled
)
740 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
741 texUnit
->TexGenEnabled
= newenabled
;
746 /* client-side state */
747 case GL_VERTEX_ARRAY
:
748 case GL_NORMAL_ARRAY
:
750 case GL_TEXTURE_COORD_ARRAY
:
751 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
752 goto invalid_enum_error
;
753 client_state( ctx
, cap
, state
);
756 case GL_EDGE_FLAG_ARRAY
:
757 case GL_FOG_COORDINATE_ARRAY_EXT
:
758 case GL_SECONDARY_COLOR_ARRAY_EXT
:
759 if (ctx
->API
!= API_OPENGL_COMPAT
)
760 goto invalid_enum_error
;
761 client_state( ctx
, cap
, state
);
763 case GL_POINT_SIZE_ARRAY_OES
:
764 if (ctx
->API
!= API_OPENGLES
)
765 goto invalid_enum_error
;
766 client_state( ctx
, cap
, state
);
769 /* GL_ARB_texture_cube_map */
770 case GL_TEXTURE_CUBE_MAP
:
771 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
772 goto invalid_enum_error
;
773 CHECK_EXTENSION(ARB_texture_cube_map
, cap
);
774 if (!enable_texture(ctx
, state
, TEXTURE_CUBE_BIT
)) {
779 /* GL_EXT_secondary_color */
780 case GL_COLOR_SUM_EXT
:
781 if (ctx
->API
!= API_OPENGL_COMPAT
)
782 goto invalid_enum_error
;
783 if (ctx
->Fog
.ColorSumEnabled
== state
)
785 FLUSH_VERTICES(ctx
, _NEW_FOG
);
786 ctx
->Fog
.ColorSumEnabled
= state
;
789 /* GL_ARB_multisample */
790 case GL_MULTISAMPLE_ARB
:
791 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
792 goto invalid_enum_error
;
793 _mesa_set_multisample(ctx
, state
);
795 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
796 if (ctx
->Multisample
.SampleAlphaToCoverage
== state
)
798 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
799 ctx
->Multisample
.SampleAlphaToCoverage
= state
;
801 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
802 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
803 goto invalid_enum_error
;
804 if (ctx
->Multisample
.SampleAlphaToOne
== state
)
806 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
807 ctx
->Multisample
.SampleAlphaToOne
= state
;
809 case GL_SAMPLE_COVERAGE_ARB
:
810 if (ctx
->Multisample
.SampleCoverage
== state
)
812 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
813 ctx
->Multisample
.SampleCoverage
= state
;
815 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
816 if (!_mesa_is_desktop_gl(ctx
))
817 goto invalid_enum_error
;
818 if (ctx
->Multisample
.SampleCoverageInvert
== state
)
820 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
821 ctx
->Multisample
.SampleCoverageInvert
= state
;
824 /* GL_ARB_sample_shading */
825 case GL_SAMPLE_SHADING
:
826 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
827 goto invalid_enum_error
;
828 CHECK_EXTENSION(ARB_sample_shading
, cap
);
829 if (ctx
->Multisample
.SampleShading
== state
)
831 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
832 ctx
->Multisample
.SampleShading
= state
;
835 /* GL_IBM_rasterpos_clip */
836 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
837 if (ctx
->API
!= API_OPENGL_COMPAT
)
838 goto invalid_enum_error
;
839 if (ctx
->Transform
.RasterPositionUnclipped
== state
)
841 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
842 ctx
->Transform
.RasterPositionUnclipped
= state
;
845 /* GL_NV_point_sprite */
846 case GL_POINT_SPRITE_NV
:
847 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
848 goto invalid_enum_error
;
849 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
, cap
);
850 if (ctx
->Point
.PointSprite
== state
)
852 FLUSH_VERTICES(ctx
, _NEW_POINT
);
853 ctx
->Point
.PointSprite
= state
;
856 case GL_VERTEX_PROGRAM_ARB
:
857 if (ctx
->API
!= API_OPENGL_COMPAT
)
858 goto invalid_enum_error
;
859 CHECK_EXTENSION(ARB_vertex_program
, cap
);
860 if (ctx
->VertexProgram
.Enabled
== state
)
862 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
863 ctx
->VertexProgram
.Enabled
= state
;
865 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
866 /* This was added with ARB_vertex_program, but it is also used with
867 * GLSL vertex shaders on desktop.
869 if (!_mesa_is_desktop_gl(ctx
))
870 goto invalid_enum_error
;
871 CHECK_EXTENSION(ARB_vertex_program
, cap
);
872 if (ctx
->VertexProgram
.PointSizeEnabled
== state
)
874 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
875 ctx
->VertexProgram
.PointSizeEnabled
= state
;
877 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
878 if (ctx
->API
!= API_OPENGL_COMPAT
)
879 goto invalid_enum_error
;
880 CHECK_EXTENSION(ARB_vertex_program
, cap
);
881 if (ctx
->VertexProgram
.TwoSideEnabled
== state
)
883 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
884 ctx
->VertexProgram
.TwoSideEnabled
= state
;
887 /* GL_NV_texture_rectangle */
888 case GL_TEXTURE_RECTANGLE_NV
:
889 if (ctx
->API
!= API_OPENGL_COMPAT
)
890 goto invalid_enum_error
;
891 CHECK_EXTENSION(NV_texture_rectangle
, cap
);
892 if (!enable_texture(ctx
, state
, TEXTURE_RECT_BIT
)) {
897 /* GL_EXT_stencil_two_side */
898 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
899 if (ctx
->API
!= API_OPENGL_COMPAT
)
900 goto invalid_enum_error
;
901 CHECK_EXTENSION(EXT_stencil_two_side
, cap
);
902 if (ctx
->Stencil
.TestTwoSide
== state
)
904 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
905 ctx
->Stencil
.TestTwoSide
= state
;
907 ctx
->Stencil
._BackFace
= 2;
909 ctx
->Stencil
._BackFace
= 1;
913 case GL_FRAGMENT_PROGRAM_ARB
:
914 if (ctx
->API
!= API_OPENGL_COMPAT
)
915 goto invalid_enum_error
;
916 CHECK_EXTENSION(ARB_fragment_program
, cap
);
917 if (ctx
->FragmentProgram
.Enabled
== state
)
919 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
920 ctx
->FragmentProgram
.Enabled
= state
;
923 /* GL_EXT_depth_bounds_test */
924 case GL_DEPTH_BOUNDS_TEST_EXT
:
925 if (!_mesa_is_desktop_gl(ctx
))
926 goto invalid_enum_error
;
927 CHECK_EXTENSION(EXT_depth_bounds_test
, cap
);
928 if (ctx
->Depth
.BoundsTest
== state
)
930 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
931 ctx
->Depth
.BoundsTest
= state
;
935 if (!_mesa_is_desktop_gl(ctx
))
936 goto invalid_enum_error
;
937 CHECK_EXTENSION(ARB_depth_clamp
, cap
);
938 if (ctx
->Transform
.DepthClamp
== state
)
940 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
941 ctx
->Transform
.DepthClamp
= state
;
944 case GL_FRAGMENT_SHADER_ATI
:
945 if (ctx
->API
!= API_OPENGL_COMPAT
)
946 goto invalid_enum_error
;
947 CHECK_EXTENSION(ATI_fragment_shader
, cap
);
948 if (ctx
->ATIFragmentShader
.Enabled
== state
)
950 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
951 ctx
->ATIFragmentShader
.Enabled
= state
;
954 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
955 if (!_mesa_is_desktop_gl(ctx
))
956 goto invalid_enum_error
;
957 CHECK_EXTENSION(ARB_seamless_cube_map
, cap
);
958 if (ctx
->Texture
.CubeMapSeamless
!= state
) {
959 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
960 ctx
->Texture
.CubeMapSeamless
= state
;
964 case GL_RASTERIZER_DISCARD
:
965 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
966 goto invalid_enum_error
;
967 CHECK_EXTENSION(EXT_transform_feedback
, cap
);
968 if (ctx
->RasterDiscard
!= state
) {
969 FLUSH_VERTICES(ctx
, 0);
970 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewRasterizerDiscard
;
971 ctx
->RasterDiscard
= state
;
975 /* GL 3.1 primitive restart. Note: this enum is different from
976 * GL_PRIMITIVE_RESTART_NV (which is client state).
978 case GL_PRIMITIVE_RESTART
:
979 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
980 goto invalid_enum_error
;
982 if (ctx
->Array
.PrimitiveRestart
!= state
) {
983 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
984 ctx
->Array
.PrimitiveRestart
= state
;
985 update_derived_primitive_restart_state(ctx
);
989 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
990 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
)
991 goto invalid_enum_error
;
992 if (ctx
->Array
.PrimitiveRestartFixedIndex
!= state
) {
993 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
994 ctx
->Array
.PrimitiveRestartFixedIndex
= state
;
995 update_derived_primitive_restart_state(ctx
);
999 /* GL3.0 - GL_framebuffer_sRGB */
1000 case GL_FRAMEBUFFER_SRGB_EXT
:
1001 if (!_mesa_is_desktop_gl(ctx
))
1002 goto invalid_enum_error
;
1003 CHECK_EXTENSION(EXT_framebuffer_sRGB
, cap
);
1004 _mesa_set_framebuffer_srgb(ctx
, state
);
1007 /* GL_OES_EGL_image_external */
1008 case GL_TEXTURE_EXTERNAL_OES
:
1009 if (!_mesa_is_gles(ctx
))
1010 goto invalid_enum_error
;
1011 CHECK_EXTENSION(OES_EGL_image_external
, cap
);
1012 if (!enable_texture(ctx
, state
, TEXTURE_EXTERNAL_BIT
)) {
1017 /* ARB_texture_multisample */
1018 case GL_SAMPLE_MASK
:
1019 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
1020 goto invalid_enum_error
;
1021 CHECK_EXTENSION(ARB_texture_multisample
, cap
);
1022 if (ctx
->Multisample
.SampleMask
== state
)
1024 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
1025 ctx
->Multisample
.SampleMask
= state
;
1028 case GL_BLEND_ADVANCED_COHERENT_KHR
:
1029 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent
, cap
);
1030 if (ctx
->Color
.BlendCoherent
== state
)
1032 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
1033 ctx
->Color
.BlendCoherent
= state
;
1037 goto invalid_enum_error
;
1040 if (ctx
->Driver
.Enable
) {
1041 ctx
->Driver
.Enable( ctx
, cap
, state
);
1047 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%s(%s)",
1048 state
? "Enable" : "Disable", _mesa_enum_to_string(cap
));
1053 * Enable GL capability. Called by glEnable()
1054 * \param cap state to enable.
1057 _mesa_Enable( GLenum cap
)
1059 GET_CURRENT_CONTEXT(ctx
);
1061 _mesa_set_enable( ctx
, cap
, GL_TRUE
);
1066 * Disable GL capability. Called by glDisable()
1067 * \param cap state to disable.
1070 _mesa_Disable( GLenum cap
)
1072 GET_CURRENT_CONTEXT(ctx
);
1074 _mesa_set_enable( ctx
, cap
, GL_FALSE
);
1080 * Enable/disable an indexed state var.
1083 _mesa_set_enablei(struct gl_context
*ctx
, GLenum cap
,
1084 GLuint index
, GLboolean state
)
1086 assert(state
== 0 || state
== 1);
1089 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
1090 goto invalid_enum_error
;
1092 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1093 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1094 state
? "glEnableIndexed" : "glDisableIndexed", index
);
1097 if (((ctx
->Color
.BlendEnabled
>> index
) & 1) != state
) {
1098 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
1100 ctx
->Color
.BlendEnabled
|= (1 << index
);
1102 ctx
->Color
.BlendEnabled
&= ~(1 << index
);
1105 case GL_SCISSOR_TEST
:
1106 if (index
>= ctx
->Const
.MaxViewports
) {
1107 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1108 state
? "glEnablei" : "glDisablei", index
);
1111 if (((ctx
->Scissor
.EnableFlags
>> index
) & 1) != state
) {
1112 FLUSH_VERTICES(ctx
, _NEW_SCISSOR
);
1114 ctx
->Scissor
.EnableFlags
|= (1 << index
);
1116 ctx
->Scissor
.EnableFlags
&= ~(1 << index
);
1120 goto invalid_enum_error
;
1125 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(cap=%s)",
1126 state
? "glEnablei" : "glDisablei",
1127 _mesa_enum_to_string(cap
));
1132 _mesa_Disablei( GLenum cap
, GLuint index
)
1134 GET_CURRENT_CONTEXT(ctx
);
1135 _mesa_set_enablei(ctx
, cap
, index
, GL_FALSE
);
1140 _mesa_Enablei( GLenum cap
, GLuint index
)
1142 GET_CURRENT_CONTEXT(ctx
);
1143 _mesa_set_enablei(ctx
, cap
, index
, GL_TRUE
);
1147 GLboolean GLAPIENTRY
1148 _mesa_IsEnabledi( GLenum cap
, GLuint index
)
1150 GET_CURRENT_CONTEXT(ctx
);
1151 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1154 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1155 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1159 return (ctx
->Color
.BlendEnabled
>> index
) & 1;
1160 case GL_SCISSOR_TEST
:
1161 if (index
>= ctx
->Const
.MaxViewports
) {
1162 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1166 return (ctx
->Scissor
.EnableFlags
>> index
) & 1;
1168 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabledIndexed(cap=%s)",
1169 _mesa_enum_to_string(cap
));
1177 #undef CHECK_EXTENSION
1178 #define CHECK_EXTENSION(EXTNAME) \
1179 if (!ctx->Extensions.EXTNAME) { \
1180 goto invalid_enum_error; \
1183 #undef CHECK_EXTENSION2
1184 #define CHECK_EXTENSION2(EXT1, EXT2) \
1185 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1186 goto invalid_enum_error; \
1191 * Helper function to determine whether a texture target is enabled.
1194 is_texture_enabled(struct gl_context
*ctx
, GLbitfield bit
)
1196 const struct gl_texture_unit
*const texUnit
=
1197 &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1198 return (texUnit
->Enabled
& bit
) ? GL_TRUE
: GL_FALSE
;
1203 * Return simple enable/disable state.
1205 * \param cap state variable to query.
1207 * Returns the state of the specified capability from the current GL context.
1208 * For the capabilities associated with extensions verifies that those
1209 * extensions are effectively present before reporting.
1211 GLboolean GLAPIENTRY
1212 _mesa_IsEnabled( GLenum cap
)
1214 GET_CURRENT_CONTEXT(ctx
);
1215 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1219 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1220 goto invalid_enum_error
;
1221 return ctx
->Color
.AlphaEnabled
;
1222 case GL_AUTO_NORMAL
:
1223 if (ctx
->API
!= API_OPENGL_COMPAT
)
1224 goto invalid_enum_error
;
1225 return ctx
->Eval
.AutoNormal
;
1227 return ctx
->Color
.BlendEnabled
& 1; /* return state for buffer[0] */
1228 case GL_CLIP_DISTANCE0
: /* aka GL_CLIP_PLANE0 */
1229 case GL_CLIP_DISTANCE1
:
1230 case GL_CLIP_DISTANCE2
:
1231 case GL_CLIP_DISTANCE3
:
1232 case GL_CLIP_DISTANCE4
:
1233 case GL_CLIP_DISTANCE5
:
1234 case GL_CLIP_DISTANCE6
:
1235 case GL_CLIP_DISTANCE7
: {
1236 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
1238 if (p
>= ctx
->Const
.MaxClipPlanes
)
1239 goto invalid_enum_error
;
1241 return (ctx
->Transform
.ClipPlanesEnabled
>> p
) & 1;
1243 case GL_COLOR_MATERIAL
:
1244 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1245 goto invalid_enum_error
;
1246 return ctx
->Light
.ColorMaterialEnabled
;
1248 return ctx
->Polygon
.CullFlag
;
1249 case GL_DEBUG_OUTPUT
:
1250 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
:
1251 return (GLboolean
) _mesa_get_debug_state_int(ctx
, cap
);
1253 return ctx
->Depth
.Test
;
1255 return ctx
->Color
.DitherFlag
;
1257 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1258 goto invalid_enum_error
;
1259 return ctx
->Fog
.Enabled
;
1261 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1262 goto invalid_enum_error
;
1263 return ctx
->Light
.Enabled
;
1272 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1273 goto invalid_enum_error
;
1274 return ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
;
1275 case GL_LINE_SMOOTH
:
1276 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1277 goto invalid_enum_error
;
1278 return ctx
->Line
.SmoothFlag
;
1279 case GL_LINE_STIPPLE
:
1280 if (ctx
->API
!= API_OPENGL_COMPAT
)
1281 goto invalid_enum_error
;
1282 return ctx
->Line
.StippleFlag
;
1283 case GL_INDEX_LOGIC_OP
:
1284 if (ctx
->API
!= API_OPENGL_COMPAT
)
1285 goto invalid_enum_error
;
1286 return ctx
->Color
.IndexLogicOpEnabled
;
1287 case GL_COLOR_LOGIC_OP
:
1288 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1289 goto invalid_enum_error
;
1290 return ctx
->Color
.ColorLogicOpEnabled
;
1291 case GL_MAP1_COLOR_4
:
1292 if (ctx
->API
!= API_OPENGL_COMPAT
)
1293 goto invalid_enum_error
;
1294 return ctx
->Eval
.Map1Color4
;
1296 if (ctx
->API
!= API_OPENGL_COMPAT
)
1297 goto invalid_enum_error
;
1298 return ctx
->Eval
.Map1Index
;
1299 case GL_MAP1_NORMAL
:
1300 if (ctx
->API
!= API_OPENGL_COMPAT
)
1301 goto invalid_enum_error
;
1302 return ctx
->Eval
.Map1Normal
;
1303 case GL_MAP1_TEXTURE_COORD_1
:
1304 if (ctx
->API
!= API_OPENGL_COMPAT
)
1305 goto invalid_enum_error
;
1306 return ctx
->Eval
.Map1TextureCoord1
;
1307 case GL_MAP1_TEXTURE_COORD_2
:
1308 if (ctx
->API
!= API_OPENGL_COMPAT
)
1309 goto invalid_enum_error
;
1310 return ctx
->Eval
.Map1TextureCoord2
;
1311 case GL_MAP1_TEXTURE_COORD_3
:
1312 if (ctx
->API
!= API_OPENGL_COMPAT
)
1313 goto invalid_enum_error
;
1314 return ctx
->Eval
.Map1TextureCoord3
;
1315 case GL_MAP1_TEXTURE_COORD_4
:
1316 if (ctx
->API
!= API_OPENGL_COMPAT
)
1317 goto invalid_enum_error
;
1318 return ctx
->Eval
.Map1TextureCoord4
;
1319 case GL_MAP1_VERTEX_3
:
1320 if (ctx
->API
!= API_OPENGL_COMPAT
)
1321 goto invalid_enum_error
;
1322 return ctx
->Eval
.Map1Vertex3
;
1323 case GL_MAP1_VERTEX_4
:
1324 if (ctx
->API
!= API_OPENGL_COMPAT
)
1325 goto invalid_enum_error
;
1326 return ctx
->Eval
.Map1Vertex4
;
1327 case GL_MAP2_COLOR_4
:
1328 if (ctx
->API
!= API_OPENGL_COMPAT
)
1329 goto invalid_enum_error
;
1330 return ctx
->Eval
.Map2Color4
;
1332 if (ctx
->API
!= API_OPENGL_COMPAT
)
1333 goto invalid_enum_error
;
1334 return ctx
->Eval
.Map2Index
;
1335 case GL_MAP2_NORMAL
:
1336 if (ctx
->API
!= API_OPENGL_COMPAT
)
1337 goto invalid_enum_error
;
1338 return ctx
->Eval
.Map2Normal
;
1339 case GL_MAP2_TEXTURE_COORD_1
:
1340 if (ctx
->API
!= API_OPENGL_COMPAT
)
1341 goto invalid_enum_error
;
1342 return ctx
->Eval
.Map2TextureCoord1
;
1343 case GL_MAP2_TEXTURE_COORD_2
:
1344 if (ctx
->API
!= API_OPENGL_COMPAT
)
1345 goto invalid_enum_error
;
1346 return ctx
->Eval
.Map2TextureCoord2
;
1347 case GL_MAP2_TEXTURE_COORD_3
:
1348 if (ctx
->API
!= API_OPENGL_COMPAT
)
1349 goto invalid_enum_error
;
1350 return ctx
->Eval
.Map2TextureCoord3
;
1351 case GL_MAP2_TEXTURE_COORD_4
:
1352 if (ctx
->API
!= API_OPENGL_COMPAT
)
1353 goto invalid_enum_error
;
1354 return ctx
->Eval
.Map2TextureCoord4
;
1355 case GL_MAP2_VERTEX_3
:
1356 if (ctx
->API
!= API_OPENGL_COMPAT
)
1357 goto invalid_enum_error
;
1358 return ctx
->Eval
.Map2Vertex3
;
1359 case GL_MAP2_VERTEX_4
:
1360 if (ctx
->API
!= API_OPENGL_COMPAT
)
1361 goto invalid_enum_error
;
1362 return ctx
->Eval
.Map2Vertex4
;
1364 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1365 goto invalid_enum_error
;
1366 return ctx
->Transform
.Normalize
;
1367 case GL_POINT_SMOOTH
:
1368 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1369 goto invalid_enum_error
;
1370 return ctx
->Point
.SmoothFlag
;
1371 case GL_POLYGON_SMOOTH
:
1372 if (!_mesa_is_desktop_gl(ctx
))
1373 goto invalid_enum_error
;
1374 return ctx
->Polygon
.SmoothFlag
;
1375 case GL_POLYGON_STIPPLE
:
1376 if (ctx
->API
!= API_OPENGL_COMPAT
)
1377 goto invalid_enum_error
;
1378 return ctx
->Polygon
.StippleFlag
;
1379 case GL_POLYGON_OFFSET_POINT
:
1380 if (!_mesa_is_desktop_gl(ctx
))
1381 goto invalid_enum_error
;
1382 return ctx
->Polygon
.OffsetPoint
;
1383 case GL_POLYGON_OFFSET_LINE
:
1384 if (!_mesa_is_desktop_gl(ctx
))
1385 goto invalid_enum_error
;
1386 return ctx
->Polygon
.OffsetLine
;
1387 case GL_POLYGON_OFFSET_FILL
:
1388 return ctx
->Polygon
.OffsetFill
;
1389 case GL_RESCALE_NORMAL_EXT
:
1390 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1391 goto invalid_enum_error
;
1392 return ctx
->Transform
.RescaleNormals
;
1393 case GL_SCISSOR_TEST
:
1394 return ctx
->Scissor
.EnableFlags
& 1; /* return state for index 0 */
1395 case GL_STENCIL_TEST
:
1396 return ctx
->Stencil
.Enabled
;
1398 if (ctx
->API
!= API_OPENGL_COMPAT
)
1399 goto invalid_enum_error
;
1400 return is_texture_enabled(ctx
, TEXTURE_1D_BIT
);
1402 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1403 goto invalid_enum_error
;
1404 return is_texture_enabled(ctx
, TEXTURE_2D_BIT
);
1406 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1407 goto invalid_enum_error
;
1408 return is_texture_enabled(ctx
, TEXTURE_3D_BIT
);
1409 case GL_TEXTURE_GEN_S
:
1410 case GL_TEXTURE_GEN_T
:
1411 case GL_TEXTURE_GEN_R
:
1412 case GL_TEXTURE_GEN_Q
:
1414 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1416 if (ctx
->API
!= API_OPENGL_COMPAT
)
1417 goto invalid_enum_error
;
1420 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
1421 return (texUnit
->TexGenEnabled
& coordBit
) ? GL_TRUE
: GL_FALSE
;
1425 case GL_TEXTURE_GEN_STR_OES
:
1427 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1429 if (ctx
->API
!= API_OPENGLES
)
1430 goto invalid_enum_error
;
1433 return (texUnit
->TexGenEnabled
& STR_BITS
) == STR_BITS
1434 ? GL_TRUE
: GL_FALSE
;
1438 /* client-side state */
1439 case GL_VERTEX_ARRAY
:
1440 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1441 goto invalid_enum_error
;
1442 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
;
1443 case GL_NORMAL_ARRAY
:
1444 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1445 goto invalid_enum_error
;
1446 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
;
1447 case GL_COLOR_ARRAY
:
1448 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1449 goto invalid_enum_error
;
1450 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
;
1451 case GL_INDEX_ARRAY
:
1452 if (ctx
->API
!= API_OPENGL_COMPAT
)
1453 goto invalid_enum_error
;
1454 return ctx
->Array
.VAO
->
1455 VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
;
1456 case GL_TEXTURE_COORD_ARRAY
:
1457 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1458 goto invalid_enum_error
;
1459 return ctx
->Array
.VAO
->
1460 VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Enabled
;
1461 case GL_EDGE_FLAG_ARRAY
:
1462 if (ctx
->API
!= API_OPENGL_COMPAT
)
1463 goto invalid_enum_error
;
1464 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
;
1465 case GL_FOG_COORDINATE_ARRAY_EXT
:
1466 if (ctx
->API
!= API_OPENGL_COMPAT
)
1467 goto invalid_enum_error
;
1468 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
;
1469 case GL_SECONDARY_COLOR_ARRAY_EXT
:
1470 if (ctx
->API
!= API_OPENGL_COMPAT
)
1471 goto invalid_enum_error
;
1472 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
;
1473 case GL_POINT_SIZE_ARRAY_OES
:
1474 if (ctx
->API
!= API_OPENGLES
)
1475 goto invalid_enum_error
;
1476 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
;
1478 /* GL_ARB_texture_cube_map */
1479 case GL_TEXTURE_CUBE_MAP
:
1480 CHECK_EXTENSION(ARB_texture_cube_map
);
1481 return is_texture_enabled(ctx
, TEXTURE_CUBE_BIT
);
1483 /* GL_EXT_secondary_color */
1484 case GL_COLOR_SUM_EXT
:
1485 if (ctx
->API
!= API_OPENGL_COMPAT
)
1486 goto invalid_enum_error
;
1487 return ctx
->Fog
.ColorSumEnabled
;
1489 /* GL_ARB_multisample */
1490 case GL_MULTISAMPLE_ARB
:
1491 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1492 goto invalid_enum_error
;
1493 return ctx
->Multisample
.Enabled
;
1494 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
1495 return ctx
->Multisample
.SampleAlphaToCoverage
;
1496 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
1497 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1498 goto invalid_enum_error
;
1499 return ctx
->Multisample
.SampleAlphaToOne
;
1500 case GL_SAMPLE_COVERAGE_ARB
:
1501 return ctx
->Multisample
.SampleCoverage
;
1502 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
1503 if (!_mesa_is_desktop_gl(ctx
))
1504 goto invalid_enum_error
;
1505 return ctx
->Multisample
.SampleCoverageInvert
;
1507 /* GL_IBM_rasterpos_clip */
1508 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
1509 if (ctx
->API
!= API_OPENGL_COMPAT
)
1510 goto invalid_enum_error
;
1511 return ctx
->Transform
.RasterPositionUnclipped
;
1513 /* GL_NV_point_sprite */
1514 case GL_POINT_SPRITE_NV
:
1515 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1516 goto invalid_enum_error
;
1517 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
)
1518 return ctx
->Point
.PointSprite
;
1520 case GL_VERTEX_PROGRAM_ARB
:
1521 if (ctx
->API
!= API_OPENGL_COMPAT
)
1522 goto invalid_enum_error
;
1523 CHECK_EXTENSION(ARB_vertex_program
);
1524 return ctx
->VertexProgram
.Enabled
;
1525 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
1526 /* This was added with ARB_vertex_program, but it is also used with
1527 * GLSL vertex shaders on desktop.
1529 if (!_mesa_is_desktop_gl(ctx
))
1530 goto invalid_enum_error
;
1531 CHECK_EXTENSION(ARB_vertex_program
);
1532 return ctx
->VertexProgram
.PointSizeEnabled
;
1533 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
1534 if (ctx
->API
!= API_OPENGL_COMPAT
)
1535 goto invalid_enum_error
;
1536 CHECK_EXTENSION(ARB_vertex_program
);
1537 return ctx
->VertexProgram
.TwoSideEnabled
;
1539 /* GL_NV_texture_rectangle */
1540 case GL_TEXTURE_RECTANGLE_NV
:
1541 if (ctx
->API
!= API_OPENGL_COMPAT
)
1542 goto invalid_enum_error
;
1543 CHECK_EXTENSION(NV_texture_rectangle
);
1544 return is_texture_enabled(ctx
, TEXTURE_RECT_BIT
);
1546 /* GL_EXT_stencil_two_side */
1547 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
1548 if (ctx
->API
!= API_OPENGL_COMPAT
)
1549 goto invalid_enum_error
;
1550 CHECK_EXTENSION(EXT_stencil_two_side
);
1551 return ctx
->Stencil
.TestTwoSide
;
1553 case GL_FRAGMENT_PROGRAM_ARB
:
1554 if (ctx
->API
!= API_OPENGL_COMPAT
)
1555 goto invalid_enum_error
;
1556 return ctx
->FragmentProgram
.Enabled
;
1558 /* GL_EXT_depth_bounds_test */
1559 case GL_DEPTH_BOUNDS_TEST_EXT
:
1560 if (!_mesa_is_desktop_gl(ctx
))
1561 goto invalid_enum_error
;
1562 CHECK_EXTENSION(EXT_depth_bounds_test
);
1563 return ctx
->Depth
.BoundsTest
;
1565 /* GL_ARB_depth_clamp */
1566 case GL_DEPTH_CLAMP
:
1567 if (!_mesa_is_desktop_gl(ctx
))
1568 goto invalid_enum_error
;
1569 CHECK_EXTENSION(ARB_depth_clamp
);
1570 return ctx
->Transform
.DepthClamp
;
1572 case GL_FRAGMENT_SHADER_ATI
:
1573 if (ctx
->API
!= API_OPENGL_COMPAT
)
1574 goto invalid_enum_error
;
1575 CHECK_EXTENSION(ATI_fragment_shader
);
1576 return ctx
->ATIFragmentShader
.Enabled
;
1578 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1579 if (!_mesa_is_desktop_gl(ctx
))
1580 goto invalid_enum_error
;
1581 CHECK_EXTENSION(ARB_seamless_cube_map
);
1582 return ctx
->Texture
.CubeMapSeamless
;
1584 case GL_RASTERIZER_DISCARD
:
1585 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1586 goto invalid_enum_error
;
1587 CHECK_EXTENSION(EXT_transform_feedback
);
1588 return ctx
->RasterDiscard
;
1590 /* GL_NV_primitive_restart */
1591 case GL_PRIMITIVE_RESTART_NV
:
1592 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.NV_primitive_restart
) {
1593 goto invalid_enum_error
;
1595 return ctx
->Array
.PrimitiveRestart
;
1597 /* GL 3.1 primitive restart */
1598 case GL_PRIMITIVE_RESTART
:
1599 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
1600 goto invalid_enum_error
;
1602 return ctx
->Array
.PrimitiveRestart
;
1604 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
1605 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
) {
1606 goto invalid_enum_error
;
1608 return ctx
->Array
.PrimitiveRestartFixedIndex
;
1610 /* GL3.0 - GL_framebuffer_sRGB */
1611 case GL_FRAMEBUFFER_SRGB_EXT
:
1612 if (!_mesa_is_desktop_gl(ctx
))
1613 goto invalid_enum_error
;
1614 CHECK_EXTENSION(EXT_framebuffer_sRGB
);
1615 return ctx
->Color
.sRGBEnabled
;
1617 /* GL_OES_EGL_image_external */
1618 case GL_TEXTURE_EXTERNAL_OES
:
1619 if (!_mesa_is_gles(ctx
))
1620 goto invalid_enum_error
;
1621 CHECK_EXTENSION(OES_EGL_image_external
);
1622 return is_texture_enabled(ctx
, TEXTURE_EXTERNAL_BIT
);
1624 /* ARB_texture_multisample */
1625 case GL_SAMPLE_MASK
:
1626 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
1627 goto invalid_enum_error
;
1628 CHECK_EXTENSION(ARB_texture_multisample
);
1629 return ctx
->Multisample
.SampleMask
;
1631 /* ARB_sample_shading */
1632 case GL_SAMPLE_SHADING
:
1633 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1634 goto invalid_enum_error
;
1635 CHECK_EXTENSION(ARB_sample_shading
);
1636 return ctx
->Multisample
.SampleShading
;
1638 case GL_BLEND_ADVANCED_COHERENT_KHR
:
1639 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent
);
1640 return ctx
->Color
.BlendCoherent
;
1642 case GL_CONSERVATIVE_RASTERIZATION_INTEL
:
1643 CHECK_EXTENSION(INTEL_conservative_rasterization
);
1644 return ctx
->IntelConservativeRasterization
;
1647 goto invalid_enum_error
;
1653 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabled(%s)",
1654 _mesa_enum_to_string(cap
));