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"
44 #define CHECK_EXTENSION(EXTNAME, CAP) \
45 if (!ctx->Extensions.EXTNAME) { \
46 goto invalid_enum_error; \
51 update_derived_primitive_restart_state(struct gl_context
*ctx
)
53 /* Update derived primitive restart state.
55 ctx
->Array
._PrimitiveRestart
= ctx
->Array
.PrimitiveRestart
56 || ctx
->Array
.PrimitiveRestartFixedIndex
;
60 * Helper to enable/disable client-side state.
63 client_state(struct gl_context
*ctx
, GLenum cap
, GLboolean state
)
65 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
71 var
= &vao
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
;
75 var
= &vao
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
;
76 flag
= VERT_BIT_NORMAL
;
79 var
= &vao
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
;
80 flag
= VERT_BIT_COLOR0
;
83 var
= &vao
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
;
84 flag
= VERT_BIT_COLOR_INDEX
;
86 case GL_TEXTURE_COORD_ARRAY
:
87 var
= &vao
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Enabled
;
88 flag
= VERT_BIT_TEX(ctx
->Array
.ActiveTexture
);
90 case GL_EDGE_FLAG_ARRAY
:
91 var
= &vao
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
;
92 flag
= VERT_BIT_EDGEFLAG
;
94 case GL_FOG_COORDINATE_ARRAY_EXT
:
95 var
= &vao
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
;
98 case GL_SECONDARY_COLOR_ARRAY_EXT
:
99 var
= &vao
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
;
100 flag
= VERT_BIT_COLOR1
;
103 case GL_POINT_SIZE_ARRAY_OES
:
104 var
= &vao
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
;
105 flag
= VERT_BIT_POINT_SIZE
;
106 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
107 ctx
->VertexProgram
.PointSizeEnabled
= state
;
110 /* GL_NV_primitive_restart */
111 case GL_PRIMITIVE_RESTART_NV
:
112 if (!ctx
->Extensions
.NV_primitive_restart
) {
113 goto invalid_enum_error
;
115 var
= &ctx
->Array
.PrimitiveRestart
;
120 goto invalid_enum_error
;
126 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
130 update_derived_primitive_restart_state(ctx
);
133 vao
->_Enabled
|= flag
;
135 vao
->_Enabled
&= ~flag
;
137 vao
->NewArrays
|= flag
;
139 if (ctx
->Driver
.Enable
) {
140 ctx
->Driver
.Enable( ctx
, cap
, state
);
146 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%sClientState(%s)",
147 state
? "Enable" : "Disable", _mesa_enum_to_string(cap
));
152 * Enable GL capability.
153 * \param cap state to enable/disable.
155 * Get's the current context, assures that we're outside glBegin()/glEnd() and
156 * calls client_state().
159 _mesa_EnableClientState( GLenum cap
)
161 GET_CURRENT_CONTEXT(ctx
);
162 client_state( ctx
, cap
, GL_TRUE
);
167 * Disable GL capability.
168 * \param cap state to enable/disable.
170 * Get's the current context, assures that we're outside glBegin()/glEnd() and
171 * calls client_state().
174 _mesa_DisableClientState( GLenum cap
)
176 GET_CURRENT_CONTEXT(ctx
);
177 client_state( ctx
, cap
, GL_FALSE
);
181 #undef CHECK_EXTENSION
182 #define CHECK_EXTENSION(EXTNAME, CAP) \
183 if (!ctx->Extensions.EXTNAME) { \
184 goto invalid_enum_error; \
187 #define CHECK_EXTENSION2(EXT1, EXT2, CAP) \
188 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
189 goto invalid_enum_error; \
193 * Return pointer to current texture unit for setting/getting coordinate
195 * Note that we'll set GL_INVALID_OPERATION and return NULL if the active
196 * texture unit is higher than the number of supported coordinate units.
198 static struct gl_texture_unit
*
199 get_texcoord_unit(struct gl_context
*ctx
)
201 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
202 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glEnable/Disable(texcoord unit)");
206 return &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
212 * Helper function to enable or disable a texture target.
213 * \param bit one of the TEXTURE_x_BIT values
214 * \return GL_TRUE if state is changing or GL_FALSE if no change
217 enable_texture(struct gl_context
*ctx
, GLboolean state
, GLbitfield texBit
)
219 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
220 const GLbitfield newenabled
= state
221 ? (texUnit
->Enabled
| texBit
) : (texUnit
->Enabled
& ~texBit
);
223 if (texUnit
->Enabled
== newenabled
)
226 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_STATE
);
227 texUnit
->Enabled
= newenabled
;
233 * Helper function to enable or disable GL_MULTISAMPLE, skipping the check for
234 * whether the API supports it (GLES doesn't).
237 _mesa_set_multisample(struct gl_context
*ctx
, GLboolean state
)
239 if (ctx
->Multisample
.Enabled
== state
)
241 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
242 ctx
->Multisample
.Enabled
= state
;
244 if (ctx
->Driver
.Enable
) {
245 ctx
->Driver
.Enable(ctx
, GL_MULTISAMPLE
, state
);
250 * Helper function to enable or disable GL_FRAMEBUFFER_SRGB, skipping the
251 * check for whether the API supports it (GLES doesn't).
254 _mesa_set_framebuffer_srgb(struct gl_context
*ctx
, GLboolean state
)
256 if (ctx
->Color
.sRGBEnabled
== state
)
259 /* TODO: Switch i965 to the new flag and remove the conditional */
260 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewFramebufferSRGB
? 0 : _NEW_BUFFERS
);
261 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewFramebufferSRGB
;
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
->NewDriverState
|= ctx
->DriverFlags
.NewScissorTest
;
675 ctx
->Scissor
.EnableFlags
= newEnabled
;
679 case GL_STENCIL_TEST
:
680 if (ctx
->Stencil
.Enabled
== state
)
682 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewStencil
? 0 : _NEW_STENCIL
);
683 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewStencil
;
684 ctx
->Stencil
.Enabled
= state
;
687 if (ctx
->API
!= API_OPENGL_COMPAT
)
688 goto invalid_enum_error
;
689 if (!enable_texture(ctx
, state
, TEXTURE_1D_BIT
)) {
694 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
695 goto invalid_enum_error
;
696 if (!enable_texture(ctx
, state
, TEXTURE_2D_BIT
)) {
701 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
702 goto invalid_enum_error
;
703 if (!enable_texture(ctx
, state
, TEXTURE_3D_BIT
)) {
707 case GL_TEXTURE_GEN_S
:
708 case GL_TEXTURE_GEN_T
:
709 case GL_TEXTURE_GEN_R
:
710 case GL_TEXTURE_GEN_Q
:
712 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
714 if (ctx
->API
!= API_OPENGL_COMPAT
)
715 goto invalid_enum_error
;
718 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
719 GLbitfield newenabled
= texUnit
->TexGenEnabled
& ~coordBit
;
721 newenabled
|= coordBit
;
722 if (texUnit
->TexGenEnabled
== newenabled
)
724 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_STATE
);
725 texUnit
->TexGenEnabled
= newenabled
;
730 case GL_TEXTURE_GEN_STR_OES
:
731 /* disable S, T, and R at the same time */
733 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
735 if (ctx
->API
!= API_OPENGLES
)
736 goto invalid_enum_error
;
740 texUnit
->TexGenEnabled
& ~STR_BITS
;
742 newenabled
|= STR_BITS
;
743 if (texUnit
->TexGenEnabled
== newenabled
)
745 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_STATE
);
746 texUnit
->TexGenEnabled
= newenabled
;
751 /* client-side state */
752 case GL_VERTEX_ARRAY
:
753 case GL_NORMAL_ARRAY
:
755 case GL_TEXTURE_COORD_ARRAY
:
756 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
757 goto invalid_enum_error
;
758 client_state( ctx
, cap
, state
);
761 case GL_EDGE_FLAG_ARRAY
:
762 case GL_FOG_COORDINATE_ARRAY_EXT
:
763 case GL_SECONDARY_COLOR_ARRAY_EXT
:
764 if (ctx
->API
!= API_OPENGL_COMPAT
)
765 goto invalid_enum_error
;
766 client_state( ctx
, cap
, state
);
768 case GL_POINT_SIZE_ARRAY_OES
:
769 if (ctx
->API
!= API_OPENGLES
)
770 goto invalid_enum_error
;
771 client_state( ctx
, cap
, state
);
774 /* GL_ARB_texture_cube_map */
775 case GL_TEXTURE_CUBE_MAP
:
776 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
777 goto invalid_enum_error
;
778 CHECK_EXTENSION(ARB_texture_cube_map
, cap
);
779 if (!enable_texture(ctx
, state
, TEXTURE_CUBE_BIT
)) {
784 /* GL_EXT_secondary_color */
785 case GL_COLOR_SUM_EXT
:
786 if (ctx
->API
!= API_OPENGL_COMPAT
)
787 goto invalid_enum_error
;
788 if (ctx
->Fog
.ColorSumEnabled
== state
)
790 FLUSH_VERTICES(ctx
, _NEW_FOG
);
791 ctx
->Fog
.ColorSumEnabled
= state
;
794 /* GL_ARB_multisample */
795 case GL_MULTISAMPLE_ARB
:
796 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
797 goto invalid_enum_error
;
798 _mesa_set_multisample(ctx
, state
);
800 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
801 if (ctx
->Multisample
.SampleAlphaToCoverage
== state
)
803 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
804 ctx
->Multisample
.SampleAlphaToCoverage
= state
;
806 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
807 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
808 goto invalid_enum_error
;
809 if (ctx
->Multisample
.SampleAlphaToOne
== state
)
811 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
812 ctx
->Multisample
.SampleAlphaToOne
= state
;
814 case GL_SAMPLE_COVERAGE_ARB
:
815 if (ctx
->Multisample
.SampleCoverage
== state
)
817 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
818 ctx
->Multisample
.SampleCoverage
= state
;
820 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
821 if (!_mesa_is_desktop_gl(ctx
))
822 goto invalid_enum_error
;
823 if (ctx
->Multisample
.SampleCoverageInvert
== state
)
825 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
826 ctx
->Multisample
.SampleCoverageInvert
= state
;
829 /* GL_ARB_sample_shading */
830 case GL_SAMPLE_SHADING
:
831 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
832 goto invalid_enum_error
;
833 CHECK_EXTENSION(ARB_sample_shading
, cap
);
834 if (ctx
->Multisample
.SampleShading
== state
)
836 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
837 ctx
->Multisample
.SampleShading
= state
;
840 /* GL_IBM_rasterpos_clip */
841 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
842 if (ctx
->API
!= API_OPENGL_COMPAT
)
843 goto invalid_enum_error
;
844 if (ctx
->Transform
.RasterPositionUnclipped
== state
)
846 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
847 ctx
->Transform
.RasterPositionUnclipped
= state
;
850 /* GL_NV_point_sprite */
851 case GL_POINT_SPRITE_NV
:
852 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
853 goto invalid_enum_error
;
854 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
, cap
);
855 if (ctx
->Point
.PointSprite
== state
)
857 FLUSH_VERTICES(ctx
, _NEW_POINT
);
858 ctx
->Point
.PointSprite
= state
;
861 case GL_VERTEX_PROGRAM_ARB
:
862 if (ctx
->API
!= API_OPENGL_COMPAT
)
863 goto invalid_enum_error
;
864 CHECK_EXTENSION(ARB_vertex_program
, cap
);
865 if (ctx
->VertexProgram
.Enabled
== state
)
867 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
868 ctx
->VertexProgram
.Enabled
= state
;
870 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
871 /* This was added with ARB_vertex_program, but it is also used with
872 * GLSL vertex shaders on desktop.
874 if (!_mesa_is_desktop_gl(ctx
))
875 goto invalid_enum_error
;
876 CHECK_EXTENSION(ARB_vertex_program
, cap
);
877 if (ctx
->VertexProgram
.PointSizeEnabled
== state
)
879 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
880 ctx
->VertexProgram
.PointSizeEnabled
= state
;
882 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
883 if (ctx
->API
!= API_OPENGL_COMPAT
)
884 goto invalid_enum_error
;
885 CHECK_EXTENSION(ARB_vertex_program
, cap
);
886 if (ctx
->VertexProgram
.TwoSideEnabled
== state
)
888 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
889 ctx
->VertexProgram
.TwoSideEnabled
= state
;
892 /* GL_NV_texture_rectangle */
893 case GL_TEXTURE_RECTANGLE_NV
:
894 if (ctx
->API
!= API_OPENGL_COMPAT
)
895 goto invalid_enum_error
;
896 CHECK_EXTENSION(NV_texture_rectangle
, cap
);
897 if (!enable_texture(ctx
, state
, TEXTURE_RECT_BIT
)) {
902 /* GL_EXT_stencil_two_side */
903 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
904 if (ctx
->API
!= API_OPENGL_COMPAT
)
905 goto invalid_enum_error
;
906 CHECK_EXTENSION(EXT_stencil_two_side
, cap
);
907 if (ctx
->Stencil
.TestTwoSide
== state
)
909 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewStencil
? 0 : _NEW_STENCIL
);
910 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewStencil
;
911 ctx
->Stencil
.TestTwoSide
= state
;
913 ctx
->Stencil
._BackFace
= 2;
915 ctx
->Stencil
._BackFace
= 1;
919 case GL_FRAGMENT_PROGRAM_ARB
:
920 if (ctx
->API
!= API_OPENGL_COMPAT
)
921 goto invalid_enum_error
;
922 CHECK_EXTENSION(ARB_fragment_program
, cap
);
923 if (ctx
->FragmentProgram
.Enabled
== state
)
925 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
926 ctx
->FragmentProgram
.Enabled
= state
;
929 /* GL_EXT_depth_bounds_test */
930 case GL_DEPTH_BOUNDS_TEST_EXT
:
931 if (!_mesa_is_desktop_gl(ctx
))
932 goto invalid_enum_error
;
933 CHECK_EXTENSION(EXT_depth_bounds_test
, cap
);
934 if (ctx
->Depth
.BoundsTest
== state
)
936 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
937 ctx
->Depth
.BoundsTest
= state
;
941 if (!_mesa_is_desktop_gl(ctx
))
942 goto invalid_enum_error
;
943 CHECK_EXTENSION(ARB_depth_clamp
, cap
);
944 if (ctx
->Transform
.DepthClamp
== state
)
946 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
947 ctx
->Transform
.DepthClamp
= state
;
950 case GL_FRAGMENT_SHADER_ATI
:
951 if (ctx
->API
!= API_OPENGL_COMPAT
)
952 goto invalid_enum_error
;
953 CHECK_EXTENSION(ATI_fragment_shader
, cap
);
954 if (ctx
->ATIFragmentShader
.Enabled
== state
)
956 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
957 ctx
->ATIFragmentShader
.Enabled
= state
;
960 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
961 if (!_mesa_is_desktop_gl(ctx
))
962 goto invalid_enum_error
;
963 CHECK_EXTENSION(ARB_seamless_cube_map
, cap
);
964 if (ctx
->Texture
.CubeMapSeamless
!= state
) {
965 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_OBJECT
);
966 ctx
->Texture
.CubeMapSeamless
= state
;
970 case GL_RASTERIZER_DISCARD
:
971 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
972 goto invalid_enum_error
;
973 CHECK_EXTENSION(EXT_transform_feedback
, cap
);
974 if (ctx
->RasterDiscard
!= state
) {
975 FLUSH_VERTICES(ctx
, 0);
976 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewRasterizerDiscard
;
977 ctx
->RasterDiscard
= state
;
981 /* GL 3.1 primitive restart. Note: this enum is different from
982 * GL_PRIMITIVE_RESTART_NV (which is client state).
984 case GL_PRIMITIVE_RESTART
:
985 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
986 goto invalid_enum_error
;
988 if (ctx
->Array
.PrimitiveRestart
!= state
) {
989 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
990 ctx
->Array
.PrimitiveRestart
= state
;
991 update_derived_primitive_restart_state(ctx
);
995 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
996 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
)
997 goto invalid_enum_error
;
998 if (ctx
->Array
.PrimitiveRestartFixedIndex
!= state
) {
999 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1000 ctx
->Array
.PrimitiveRestartFixedIndex
= state
;
1001 update_derived_primitive_restart_state(ctx
);
1005 /* GL3.0 - GL_framebuffer_sRGB */
1006 case GL_FRAMEBUFFER_SRGB_EXT
:
1007 if (!_mesa_is_desktop_gl(ctx
))
1008 goto invalid_enum_error
;
1009 CHECK_EXTENSION(EXT_framebuffer_sRGB
, cap
);
1010 _mesa_set_framebuffer_srgb(ctx
, state
);
1013 /* GL_OES_EGL_image_external */
1014 case GL_TEXTURE_EXTERNAL_OES
:
1015 if (!_mesa_is_gles(ctx
))
1016 goto invalid_enum_error
;
1017 CHECK_EXTENSION(OES_EGL_image_external
, cap
);
1018 if (!enable_texture(ctx
, state
, TEXTURE_EXTERNAL_BIT
)) {
1023 /* ARB_texture_multisample */
1024 case GL_SAMPLE_MASK
:
1025 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
1026 goto invalid_enum_error
;
1027 CHECK_EXTENSION(ARB_texture_multisample
, cap
);
1028 if (ctx
->Multisample
.SampleMask
== state
)
1030 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
1031 ctx
->Multisample
.SampleMask
= state
;
1034 case GL_BLEND_ADVANCED_COHERENT_KHR
:
1035 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent
, cap
);
1036 if (ctx
->Color
.BlendCoherent
== state
)
1038 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
1039 ctx
->Color
.BlendCoherent
= state
;
1043 goto invalid_enum_error
;
1046 if (ctx
->Driver
.Enable
) {
1047 ctx
->Driver
.Enable( ctx
, cap
, state
);
1053 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%s(%s)",
1054 state
? "Enable" : "Disable", _mesa_enum_to_string(cap
));
1059 * Enable GL capability. Called by glEnable()
1060 * \param cap state to enable.
1063 _mesa_Enable( GLenum cap
)
1065 GET_CURRENT_CONTEXT(ctx
);
1067 _mesa_set_enable( ctx
, cap
, GL_TRUE
);
1072 * Disable GL capability. Called by glDisable()
1073 * \param cap state to disable.
1076 _mesa_Disable( GLenum cap
)
1078 GET_CURRENT_CONTEXT(ctx
);
1080 _mesa_set_enable( ctx
, cap
, GL_FALSE
);
1086 * Enable/disable an indexed state var.
1089 _mesa_set_enablei(struct gl_context
*ctx
, GLenum cap
,
1090 GLuint index
, GLboolean state
)
1092 assert(state
== 0 || state
== 1);
1095 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
1096 goto invalid_enum_error
;
1098 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1099 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1100 state
? "glEnableIndexed" : "glDisableIndexed", index
);
1103 if (((ctx
->Color
.BlendEnabled
>> index
) & 1) != state
) {
1104 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
1106 ctx
->Color
.BlendEnabled
|= (1 << index
);
1108 ctx
->Color
.BlendEnabled
&= ~(1 << index
);
1111 case GL_SCISSOR_TEST
:
1112 if (index
>= ctx
->Const
.MaxViewports
) {
1113 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1114 state
? "glEnablei" : "glDisablei", index
);
1117 if (((ctx
->Scissor
.EnableFlags
>> index
) & 1) != state
) {
1118 FLUSH_VERTICES(ctx
, _NEW_SCISSOR
);
1119 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewScissorTest
;
1121 ctx
->Scissor
.EnableFlags
|= (1 << index
);
1123 ctx
->Scissor
.EnableFlags
&= ~(1 << index
);
1127 goto invalid_enum_error
;
1132 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(cap=%s)",
1133 state
? "glEnablei" : "glDisablei",
1134 _mesa_enum_to_string(cap
));
1139 _mesa_Disablei( GLenum cap
, GLuint index
)
1141 GET_CURRENT_CONTEXT(ctx
);
1142 _mesa_set_enablei(ctx
, cap
, index
, GL_FALSE
);
1147 _mesa_Enablei( GLenum cap
, GLuint index
)
1149 GET_CURRENT_CONTEXT(ctx
);
1150 _mesa_set_enablei(ctx
, cap
, index
, GL_TRUE
);
1154 GLboolean GLAPIENTRY
1155 _mesa_IsEnabledi( GLenum cap
, GLuint index
)
1157 GET_CURRENT_CONTEXT(ctx
);
1158 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1161 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1162 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1166 return (ctx
->Color
.BlendEnabled
>> index
) & 1;
1167 case GL_SCISSOR_TEST
:
1168 if (index
>= ctx
->Const
.MaxViewports
) {
1169 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1173 return (ctx
->Scissor
.EnableFlags
>> index
) & 1;
1175 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabledIndexed(cap=%s)",
1176 _mesa_enum_to_string(cap
));
1184 #undef CHECK_EXTENSION
1185 #define CHECK_EXTENSION(EXTNAME) \
1186 if (!ctx->Extensions.EXTNAME) { \
1187 goto invalid_enum_error; \
1190 #undef CHECK_EXTENSION2
1191 #define CHECK_EXTENSION2(EXT1, EXT2) \
1192 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1193 goto invalid_enum_error; \
1198 * Helper function to determine whether a texture target is enabled.
1201 is_texture_enabled(struct gl_context
*ctx
, GLbitfield bit
)
1203 const struct gl_texture_unit
*const texUnit
=
1204 &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1205 return (texUnit
->Enabled
& bit
) ? GL_TRUE
: GL_FALSE
;
1210 * Return simple enable/disable state.
1212 * \param cap state variable to query.
1214 * Returns the state of the specified capability from the current GL context.
1215 * For the capabilities associated with extensions verifies that those
1216 * extensions are effectively present before reporting.
1218 GLboolean GLAPIENTRY
1219 _mesa_IsEnabled( GLenum cap
)
1221 GET_CURRENT_CONTEXT(ctx
);
1222 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1226 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1227 goto invalid_enum_error
;
1228 return ctx
->Color
.AlphaEnabled
;
1229 case GL_AUTO_NORMAL
:
1230 if (ctx
->API
!= API_OPENGL_COMPAT
)
1231 goto invalid_enum_error
;
1232 return ctx
->Eval
.AutoNormal
;
1234 return ctx
->Color
.BlendEnabled
& 1; /* return state for buffer[0] */
1235 case GL_CLIP_DISTANCE0
: /* aka GL_CLIP_PLANE0 */
1236 case GL_CLIP_DISTANCE1
:
1237 case GL_CLIP_DISTANCE2
:
1238 case GL_CLIP_DISTANCE3
:
1239 case GL_CLIP_DISTANCE4
:
1240 case GL_CLIP_DISTANCE5
:
1241 case GL_CLIP_DISTANCE6
:
1242 case GL_CLIP_DISTANCE7
: {
1243 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
1245 if (p
>= ctx
->Const
.MaxClipPlanes
)
1246 goto invalid_enum_error
;
1248 return (ctx
->Transform
.ClipPlanesEnabled
>> p
) & 1;
1250 case GL_COLOR_MATERIAL
:
1251 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1252 goto invalid_enum_error
;
1253 return ctx
->Light
.ColorMaterialEnabled
;
1255 return ctx
->Polygon
.CullFlag
;
1256 case GL_DEBUG_OUTPUT
:
1257 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
:
1258 return (GLboolean
) _mesa_get_debug_state_int(ctx
, cap
);
1260 return ctx
->Depth
.Test
;
1262 return ctx
->Color
.DitherFlag
;
1264 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1265 goto invalid_enum_error
;
1266 return ctx
->Fog
.Enabled
;
1268 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1269 goto invalid_enum_error
;
1270 return ctx
->Light
.Enabled
;
1279 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1280 goto invalid_enum_error
;
1281 return ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
;
1282 case GL_LINE_SMOOTH
:
1283 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1284 goto invalid_enum_error
;
1285 return ctx
->Line
.SmoothFlag
;
1286 case GL_LINE_STIPPLE
:
1287 if (ctx
->API
!= API_OPENGL_COMPAT
)
1288 goto invalid_enum_error
;
1289 return ctx
->Line
.StippleFlag
;
1290 case GL_INDEX_LOGIC_OP
:
1291 if (ctx
->API
!= API_OPENGL_COMPAT
)
1292 goto invalid_enum_error
;
1293 return ctx
->Color
.IndexLogicOpEnabled
;
1294 case GL_COLOR_LOGIC_OP
:
1295 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1296 goto invalid_enum_error
;
1297 return ctx
->Color
.ColorLogicOpEnabled
;
1298 case GL_MAP1_COLOR_4
:
1299 if (ctx
->API
!= API_OPENGL_COMPAT
)
1300 goto invalid_enum_error
;
1301 return ctx
->Eval
.Map1Color4
;
1303 if (ctx
->API
!= API_OPENGL_COMPAT
)
1304 goto invalid_enum_error
;
1305 return ctx
->Eval
.Map1Index
;
1306 case GL_MAP1_NORMAL
:
1307 if (ctx
->API
!= API_OPENGL_COMPAT
)
1308 goto invalid_enum_error
;
1309 return ctx
->Eval
.Map1Normal
;
1310 case GL_MAP1_TEXTURE_COORD_1
:
1311 if (ctx
->API
!= API_OPENGL_COMPAT
)
1312 goto invalid_enum_error
;
1313 return ctx
->Eval
.Map1TextureCoord1
;
1314 case GL_MAP1_TEXTURE_COORD_2
:
1315 if (ctx
->API
!= API_OPENGL_COMPAT
)
1316 goto invalid_enum_error
;
1317 return ctx
->Eval
.Map1TextureCoord2
;
1318 case GL_MAP1_TEXTURE_COORD_3
:
1319 if (ctx
->API
!= API_OPENGL_COMPAT
)
1320 goto invalid_enum_error
;
1321 return ctx
->Eval
.Map1TextureCoord3
;
1322 case GL_MAP1_TEXTURE_COORD_4
:
1323 if (ctx
->API
!= API_OPENGL_COMPAT
)
1324 goto invalid_enum_error
;
1325 return ctx
->Eval
.Map1TextureCoord4
;
1326 case GL_MAP1_VERTEX_3
:
1327 if (ctx
->API
!= API_OPENGL_COMPAT
)
1328 goto invalid_enum_error
;
1329 return ctx
->Eval
.Map1Vertex3
;
1330 case GL_MAP1_VERTEX_4
:
1331 if (ctx
->API
!= API_OPENGL_COMPAT
)
1332 goto invalid_enum_error
;
1333 return ctx
->Eval
.Map1Vertex4
;
1334 case GL_MAP2_COLOR_4
:
1335 if (ctx
->API
!= API_OPENGL_COMPAT
)
1336 goto invalid_enum_error
;
1337 return ctx
->Eval
.Map2Color4
;
1339 if (ctx
->API
!= API_OPENGL_COMPAT
)
1340 goto invalid_enum_error
;
1341 return ctx
->Eval
.Map2Index
;
1342 case GL_MAP2_NORMAL
:
1343 if (ctx
->API
!= API_OPENGL_COMPAT
)
1344 goto invalid_enum_error
;
1345 return ctx
->Eval
.Map2Normal
;
1346 case GL_MAP2_TEXTURE_COORD_1
:
1347 if (ctx
->API
!= API_OPENGL_COMPAT
)
1348 goto invalid_enum_error
;
1349 return ctx
->Eval
.Map2TextureCoord1
;
1350 case GL_MAP2_TEXTURE_COORD_2
:
1351 if (ctx
->API
!= API_OPENGL_COMPAT
)
1352 goto invalid_enum_error
;
1353 return ctx
->Eval
.Map2TextureCoord2
;
1354 case GL_MAP2_TEXTURE_COORD_3
:
1355 if (ctx
->API
!= API_OPENGL_COMPAT
)
1356 goto invalid_enum_error
;
1357 return ctx
->Eval
.Map2TextureCoord3
;
1358 case GL_MAP2_TEXTURE_COORD_4
:
1359 if (ctx
->API
!= API_OPENGL_COMPAT
)
1360 goto invalid_enum_error
;
1361 return ctx
->Eval
.Map2TextureCoord4
;
1362 case GL_MAP2_VERTEX_3
:
1363 if (ctx
->API
!= API_OPENGL_COMPAT
)
1364 goto invalid_enum_error
;
1365 return ctx
->Eval
.Map2Vertex3
;
1366 case GL_MAP2_VERTEX_4
:
1367 if (ctx
->API
!= API_OPENGL_COMPAT
)
1368 goto invalid_enum_error
;
1369 return ctx
->Eval
.Map2Vertex4
;
1371 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1372 goto invalid_enum_error
;
1373 return ctx
->Transform
.Normalize
;
1374 case GL_POINT_SMOOTH
:
1375 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1376 goto invalid_enum_error
;
1377 return ctx
->Point
.SmoothFlag
;
1378 case GL_POLYGON_SMOOTH
:
1379 if (!_mesa_is_desktop_gl(ctx
))
1380 goto invalid_enum_error
;
1381 return ctx
->Polygon
.SmoothFlag
;
1382 case GL_POLYGON_STIPPLE
:
1383 if (ctx
->API
!= API_OPENGL_COMPAT
)
1384 goto invalid_enum_error
;
1385 return ctx
->Polygon
.StippleFlag
;
1386 case GL_POLYGON_OFFSET_POINT
:
1387 if (!_mesa_is_desktop_gl(ctx
))
1388 goto invalid_enum_error
;
1389 return ctx
->Polygon
.OffsetPoint
;
1390 case GL_POLYGON_OFFSET_LINE
:
1391 if (!_mesa_is_desktop_gl(ctx
))
1392 goto invalid_enum_error
;
1393 return ctx
->Polygon
.OffsetLine
;
1394 case GL_POLYGON_OFFSET_FILL
:
1395 return ctx
->Polygon
.OffsetFill
;
1396 case GL_RESCALE_NORMAL_EXT
:
1397 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1398 goto invalid_enum_error
;
1399 return ctx
->Transform
.RescaleNormals
;
1400 case GL_SCISSOR_TEST
:
1401 return ctx
->Scissor
.EnableFlags
& 1; /* return state for index 0 */
1402 case GL_STENCIL_TEST
:
1403 return ctx
->Stencil
.Enabled
;
1405 if (ctx
->API
!= API_OPENGL_COMPAT
)
1406 goto invalid_enum_error
;
1407 return is_texture_enabled(ctx
, TEXTURE_1D_BIT
);
1409 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1410 goto invalid_enum_error
;
1411 return is_texture_enabled(ctx
, TEXTURE_2D_BIT
);
1413 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1414 goto invalid_enum_error
;
1415 return is_texture_enabled(ctx
, TEXTURE_3D_BIT
);
1416 case GL_TEXTURE_GEN_S
:
1417 case GL_TEXTURE_GEN_T
:
1418 case GL_TEXTURE_GEN_R
:
1419 case GL_TEXTURE_GEN_Q
:
1421 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1423 if (ctx
->API
!= API_OPENGL_COMPAT
)
1424 goto invalid_enum_error
;
1427 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
1428 return (texUnit
->TexGenEnabled
& coordBit
) ? GL_TRUE
: GL_FALSE
;
1432 case GL_TEXTURE_GEN_STR_OES
:
1434 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1436 if (ctx
->API
!= API_OPENGLES
)
1437 goto invalid_enum_error
;
1440 return (texUnit
->TexGenEnabled
& STR_BITS
) == STR_BITS
1441 ? GL_TRUE
: GL_FALSE
;
1445 /* client-side state */
1446 case GL_VERTEX_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_POS
].Enabled
;
1450 case GL_NORMAL_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_NORMAL
].Enabled
;
1454 case GL_COLOR_ARRAY
:
1455 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1456 goto invalid_enum_error
;
1457 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
;
1458 case GL_INDEX_ARRAY
:
1459 if (ctx
->API
!= API_OPENGL_COMPAT
)
1460 goto invalid_enum_error
;
1461 return ctx
->Array
.VAO
->
1462 VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
;
1463 case GL_TEXTURE_COORD_ARRAY
:
1464 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1465 goto invalid_enum_error
;
1466 return ctx
->Array
.VAO
->
1467 VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Enabled
;
1468 case GL_EDGE_FLAG_ARRAY
:
1469 if (ctx
->API
!= API_OPENGL_COMPAT
)
1470 goto invalid_enum_error
;
1471 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
;
1472 case GL_FOG_COORDINATE_ARRAY_EXT
:
1473 if (ctx
->API
!= API_OPENGL_COMPAT
)
1474 goto invalid_enum_error
;
1475 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
;
1476 case GL_SECONDARY_COLOR_ARRAY_EXT
:
1477 if (ctx
->API
!= API_OPENGL_COMPAT
)
1478 goto invalid_enum_error
;
1479 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
;
1480 case GL_POINT_SIZE_ARRAY_OES
:
1481 if (ctx
->API
!= API_OPENGLES
)
1482 goto invalid_enum_error
;
1483 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
;
1485 /* GL_ARB_texture_cube_map */
1486 case GL_TEXTURE_CUBE_MAP
:
1487 CHECK_EXTENSION(ARB_texture_cube_map
);
1488 return is_texture_enabled(ctx
, TEXTURE_CUBE_BIT
);
1490 /* GL_EXT_secondary_color */
1491 case GL_COLOR_SUM_EXT
:
1492 if (ctx
->API
!= API_OPENGL_COMPAT
)
1493 goto invalid_enum_error
;
1494 return ctx
->Fog
.ColorSumEnabled
;
1496 /* GL_ARB_multisample */
1497 case GL_MULTISAMPLE_ARB
:
1498 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1499 goto invalid_enum_error
;
1500 return ctx
->Multisample
.Enabled
;
1501 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
1502 return ctx
->Multisample
.SampleAlphaToCoverage
;
1503 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
1504 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1505 goto invalid_enum_error
;
1506 return ctx
->Multisample
.SampleAlphaToOne
;
1507 case GL_SAMPLE_COVERAGE_ARB
:
1508 return ctx
->Multisample
.SampleCoverage
;
1509 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
1510 if (!_mesa_is_desktop_gl(ctx
))
1511 goto invalid_enum_error
;
1512 return ctx
->Multisample
.SampleCoverageInvert
;
1514 /* GL_IBM_rasterpos_clip */
1515 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
1516 if (ctx
->API
!= API_OPENGL_COMPAT
)
1517 goto invalid_enum_error
;
1518 return ctx
->Transform
.RasterPositionUnclipped
;
1520 /* GL_NV_point_sprite */
1521 case GL_POINT_SPRITE_NV
:
1522 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1523 goto invalid_enum_error
;
1524 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
)
1525 return ctx
->Point
.PointSprite
;
1527 case GL_VERTEX_PROGRAM_ARB
:
1528 if (ctx
->API
!= API_OPENGL_COMPAT
)
1529 goto invalid_enum_error
;
1530 CHECK_EXTENSION(ARB_vertex_program
);
1531 return ctx
->VertexProgram
.Enabled
;
1532 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
1533 /* This was added with ARB_vertex_program, but it is also used with
1534 * GLSL vertex shaders on desktop.
1536 if (!_mesa_is_desktop_gl(ctx
))
1537 goto invalid_enum_error
;
1538 CHECK_EXTENSION(ARB_vertex_program
);
1539 return ctx
->VertexProgram
.PointSizeEnabled
;
1540 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
1541 if (ctx
->API
!= API_OPENGL_COMPAT
)
1542 goto invalid_enum_error
;
1543 CHECK_EXTENSION(ARB_vertex_program
);
1544 return ctx
->VertexProgram
.TwoSideEnabled
;
1546 /* GL_NV_texture_rectangle */
1547 case GL_TEXTURE_RECTANGLE_NV
:
1548 if (ctx
->API
!= API_OPENGL_COMPAT
)
1549 goto invalid_enum_error
;
1550 CHECK_EXTENSION(NV_texture_rectangle
);
1551 return is_texture_enabled(ctx
, TEXTURE_RECT_BIT
);
1553 /* GL_EXT_stencil_two_side */
1554 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
1555 if (ctx
->API
!= API_OPENGL_COMPAT
)
1556 goto invalid_enum_error
;
1557 CHECK_EXTENSION(EXT_stencil_two_side
);
1558 return ctx
->Stencil
.TestTwoSide
;
1560 case GL_FRAGMENT_PROGRAM_ARB
:
1561 if (ctx
->API
!= API_OPENGL_COMPAT
)
1562 goto invalid_enum_error
;
1563 return ctx
->FragmentProgram
.Enabled
;
1565 /* GL_EXT_depth_bounds_test */
1566 case GL_DEPTH_BOUNDS_TEST_EXT
:
1567 if (!_mesa_is_desktop_gl(ctx
))
1568 goto invalid_enum_error
;
1569 CHECK_EXTENSION(EXT_depth_bounds_test
);
1570 return ctx
->Depth
.BoundsTest
;
1572 /* GL_ARB_depth_clamp */
1573 case GL_DEPTH_CLAMP
:
1574 if (!_mesa_is_desktop_gl(ctx
))
1575 goto invalid_enum_error
;
1576 CHECK_EXTENSION(ARB_depth_clamp
);
1577 return ctx
->Transform
.DepthClamp
;
1579 case GL_FRAGMENT_SHADER_ATI
:
1580 if (ctx
->API
!= API_OPENGL_COMPAT
)
1581 goto invalid_enum_error
;
1582 CHECK_EXTENSION(ATI_fragment_shader
);
1583 return ctx
->ATIFragmentShader
.Enabled
;
1585 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1586 if (!_mesa_is_desktop_gl(ctx
))
1587 goto invalid_enum_error
;
1588 CHECK_EXTENSION(ARB_seamless_cube_map
);
1589 return ctx
->Texture
.CubeMapSeamless
;
1591 case GL_RASTERIZER_DISCARD
:
1592 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1593 goto invalid_enum_error
;
1594 CHECK_EXTENSION(EXT_transform_feedback
);
1595 return ctx
->RasterDiscard
;
1597 /* GL_NV_primitive_restart */
1598 case GL_PRIMITIVE_RESTART_NV
:
1599 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.NV_primitive_restart
) {
1600 goto invalid_enum_error
;
1602 return ctx
->Array
.PrimitiveRestart
;
1604 /* GL 3.1 primitive restart */
1605 case GL_PRIMITIVE_RESTART
:
1606 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
1607 goto invalid_enum_error
;
1609 return ctx
->Array
.PrimitiveRestart
;
1611 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
1612 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
) {
1613 goto invalid_enum_error
;
1615 return ctx
->Array
.PrimitiveRestartFixedIndex
;
1617 /* GL3.0 - GL_framebuffer_sRGB */
1618 case GL_FRAMEBUFFER_SRGB_EXT
:
1619 if (!_mesa_is_desktop_gl(ctx
))
1620 goto invalid_enum_error
;
1621 CHECK_EXTENSION(EXT_framebuffer_sRGB
);
1622 return ctx
->Color
.sRGBEnabled
;
1624 /* GL_OES_EGL_image_external */
1625 case GL_TEXTURE_EXTERNAL_OES
:
1626 if (!_mesa_is_gles(ctx
))
1627 goto invalid_enum_error
;
1628 CHECK_EXTENSION(OES_EGL_image_external
);
1629 return is_texture_enabled(ctx
, TEXTURE_EXTERNAL_BIT
);
1631 /* ARB_texture_multisample */
1632 case GL_SAMPLE_MASK
:
1633 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
1634 goto invalid_enum_error
;
1635 CHECK_EXTENSION(ARB_texture_multisample
);
1636 return ctx
->Multisample
.SampleMask
;
1638 /* ARB_sample_shading */
1639 case GL_SAMPLE_SHADING
:
1640 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1641 goto invalid_enum_error
;
1642 CHECK_EXTENSION(ARB_sample_shading
);
1643 return ctx
->Multisample
.SampleShading
;
1645 case GL_BLEND_ADVANCED_COHERENT_KHR
:
1646 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent
);
1647 return ctx
->Color
.BlendCoherent
;
1649 case GL_CONSERVATIVE_RASTERIZATION_INTEL
:
1650 CHECK_EXTENSION(INTEL_conservative_rasterization
);
1651 return ctx
->IntelConservativeRasterization
;
1654 goto invalid_enum_error
;
1660 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabled(%s)",
1661 _mesa_enum_to_string(cap
));