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
, ctx
->DriverFlags
.NewScissorTest
? 0 :
675 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewScissorTest
;
676 ctx
->Scissor
.EnableFlags
= newEnabled
;
680 case GL_STENCIL_TEST
:
681 if (ctx
->Stencil
.Enabled
== state
)
683 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewStencil
? 0 : _NEW_STENCIL
);
684 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewStencil
;
685 ctx
->Stencil
.Enabled
= state
;
688 if (ctx
->API
!= API_OPENGL_COMPAT
)
689 goto invalid_enum_error
;
690 if (!enable_texture(ctx
, state
, TEXTURE_1D_BIT
)) {
695 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
696 goto invalid_enum_error
;
697 if (!enable_texture(ctx
, state
, TEXTURE_2D_BIT
)) {
702 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
703 goto invalid_enum_error
;
704 if (!enable_texture(ctx
, state
, TEXTURE_3D_BIT
)) {
708 case GL_TEXTURE_GEN_S
:
709 case GL_TEXTURE_GEN_T
:
710 case GL_TEXTURE_GEN_R
:
711 case GL_TEXTURE_GEN_Q
:
713 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
715 if (ctx
->API
!= API_OPENGL_COMPAT
)
716 goto invalid_enum_error
;
719 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
720 GLbitfield newenabled
= texUnit
->TexGenEnabled
& ~coordBit
;
722 newenabled
|= coordBit
;
723 if (texUnit
->TexGenEnabled
== newenabled
)
725 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_STATE
);
726 texUnit
->TexGenEnabled
= newenabled
;
731 case GL_TEXTURE_GEN_STR_OES
:
732 /* disable S, T, and R at the same time */
734 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
736 if (ctx
->API
!= API_OPENGLES
)
737 goto invalid_enum_error
;
741 texUnit
->TexGenEnabled
& ~STR_BITS
;
743 newenabled
|= STR_BITS
;
744 if (texUnit
->TexGenEnabled
== newenabled
)
746 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_STATE
);
747 texUnit
->TexGenEnabled
= newenabled
;
752 /* client-side state */
753 case GL_VERTEX_ARRAY
:
754 case GL_NORMAL_ARRAY
:
756 case GL_TEXTURE_COORD_ARRAY
:
757 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
758 goto invalid_enum_error
;
759 client_state( ctx
, cap
, state
);
762 case GL_EDGE_FLAG_ARRAY
:
763 case GL_FOG_COORDINATE_ARRAY_EXT
:
764 case GL_SECONDARY_COLOR_ARRAY_EXT
:
765 if (ctx
->API
!= API_OPENGL_COMPAT
)
766 goto invalid_enum_error
;
767 client_state( ctx
, cap
, state
);
769 case GL_POINT_SIZE_ARRAY_OES
:
770 if (ctx
->API
!= API_OPENGLES
)
771 goto invalid_enum_error
;
772 client_state( ctx
, cap
, state
);
775 /* GL_ARB_texture_cube_map */
776 case GL_TEXTURE_CUBE_MAP
:
777 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
778 goto invalid_enum_error
;
779 CHECK_EXTENSION(ARB_texture_cube_map
, cap
);
780 if (!enable_texture(ctx
, state
, TEXTURE_CUBE_BIT
)) {
785 /* GL_EXT_secondary_color */
786 case GL_COLOR_SUM_EXT
:
787 if (ctx
->API
!= API_OPENGL_COMPAT
)
788 goto invalid_enum_error
;
789 if (ctx
->Fog
.ColorSumEnabled
== state
)
791 FLUSH_VERTICES(ctx
, _NEW_FOG
);
792 ctx
->Fog
.ColorSumEnabled
= state
;
795 /* GL_ARB_multisample */
796 case GL_MULTISAMPLE_ARB
:
797 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
798 goto invalid_enum_error
;
799 _mesa_set_multisample(ctx
, state
);
801 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
802 if (ctx
->Multisample
.SampleAlphaToCoverage
== state
)
804 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
805 ctx
->Multisample
.SampleAlphaToCoverage
= state
;
807 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
808 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
809 goto invalid_enum_error
;
810 if (ctx
->Multisample
.SampleAlphaToOne
== state
)
812 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
813 ctx
->Multisample
.SampleAlphaToOne
= state
;
815 case GL_SAMPLE_COVERAGE_ARB
:
816 if (ctx
->Multisample
.SampleCoverage
== state
)
818 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
819 ctx
->Multisample
.SampleCoverage
= state
;
821 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
822 if (!_mesa_is_desktop_gl(ctx
))
823 goto invalid_enum_error
;
824 if (ctx
->Multisample
.SampleCoverageInvert
== state
)
826 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
827 ctx
->Multisample
.SampleCoverageInvert
= state
;
830 /* GL_ARB_sample_shading */
831 case GL_SAMPLE_SHADING
:
832 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
833 goto invalid_enum_error
;
834 CHECK_EXTENSION(ARB_sample_shading
, cap
);
835 if (ctx
->Multisample
.SampleShading
== state
)
837 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
838 ctx
->Multisample
.SampleShading
= state
;
841 /* GL_IBM_rasterpos_clip */
842 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
843 if (ctx
->API
!= API_OPENGL_COMPAT
)
844 goto invalid_enum_error
;
845 if (ctx
->Transform
.RasterPositionUnclipped
== state
)
847 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
848 ctx
->Transform
.RasterPositionUnclipped
= state
;
851 /* GL_NV_point_sprite */
852 case GL_POINT_SPRITE_NV
:
853 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
854 goto invalid_enum_error
;
855 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
, cap
);
856 if (ctx
->Point
.PointSprite
== state
)
858 FLUSH_VERTICES(ctx
, _NEW_POINT
);
859 ctx
->Point
.PointSprite
= state
;
862 case GL_VERTEX_PROGRAM_ARB
:
863 if (ctx
->API
!= API_OPENGL_COMPAT
)
864 goto invalid_enum_error
;
865 CHECK_EXTENSION(ARB_vertex_program
, cap
);
866 if (ctx
->VertexProgram
.Enabled
== state
)
868 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
869 ctx
->VertexProgram
.Enabled
= state
;
871 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
872 /* This was added with ARB_vertex_program, but it is also used with
873 * GLSL vertex shaders on desktop.
875 if (!_mesa_is_desktop_gl(ctx
))
876 goto invalid_enum_error
;
877 CHECK_EXTENSION(ARB_vertex_program
, cap
);
878 if (ctx
->VertexProgram
.PointSizeEnabled
== state
)
880 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
881 ctx
->VertexProgram
.PointSizeEnabled
= state
;
883 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
884 if (ctx
->API
!= API_OPENGL_COMPAT
)
885 goto invalid_enum_error
;
886 CHECK_EXTENSION(ARB_vertex_program
, cap
);
887 if (ctx
->VertexProgram
.TwoSideEnabled
== state
)
889 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
890 ctx
->VertexProgram
.TwoSideEnabled
= state
;
893 /* GL_NV_texture_rectangle */
894 case GL_TEXTURE_RECTANGLE_NV
:
895 if (ctx
->API
!= API_OPENGL_COMPAT
)
896 goto invalid_enum_error
;
897 CHECK_EXTENSION(NV_texture_rectangle
, cap
);
898 if (!enable_texture(ctx
, state
, TEXTURE_RECT_BIT
)) {
903 /* GL_EXT_stencil_two_side */
904 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
905 if (ctx
->API
!= API_OPENGL_COMPAT
)
906 goto invalid_enum_error
;
907 CHECK_EXTENSION(EXT_stencil_two_side
, cap
);
908 if (ctx
->Stencil
.TestTwoSide
== state
)
910 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewStencil
? 0 : _NEW_STENCIL
);
911 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewStencil
;
912 ctx
->Stencil
.TestTwoSide
= state
;
914 ctx
->Stencil
._BackFace
= 2;
916 ctx
->Stencil
._BackFace
= 1;
920 case GL_FRAGMENT_PROGRAM_ARB
:
921 if (ctx
->API
!= API_OPENGL_COMPAT
)
922 goto invalid_enum_error
;
923 CHECK_EXTENSION(ARB_fragment_program
, cap
);
924 if (ctx
->FragmentProgram
.Enabled
== state
)
926 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
927 ctx
->FragmentProgram
.Enabled
= state
;
930 /* GL_EXT_depth_bounds_test */
931 case GL_DEPTH_BOUNDS_TEST_EXT
:
932 if (!_mesa_is_desktop_gl(ctx
))
933 goto invalid_enum_error
;
934 CHECK_EXTENSION(EXT_depth_bounds_test
, cap
);
935 if (ctx
->Depth
.BoundsTest
== state
)
937 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
938 ctx
->Depth
.BoundsTest
= state
;
942 if (!_mesa_is_desktop_gl(ctx
))
943 goto invalid_enum_error
;
944 CHECK_EXTENSION(ARB_depth_clamp
, cap
);
945 if (ctx
->Transform
.DepthClamp
== state
)
947 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
948 ctx
->Transform
.DepthClamp
= state
;
951 case GL_FRAGMENT_SHADER_ATI
:
952 if (ctx
->API
!= API_OPENGL_COMPAT
)
953 goto invalid_enum_error
;
954 CHECK_EXTENSION(ATI_fragment_shader
, cap
);
955 if (ctx
->ATIFragmentShader
.Enabled
== state
)
957 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
958 ctx
->ATIFragmentShader
.Enabled
= state
;
961 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
962 if (!_mesa_is_desktop_gl(ctx
))
963 goto invalid_enum_error
;
964 CHECK_EXTENSION(ARB_seamless_cube_map
, cap
);
965 if (ctx
->Texture
.CubeMapSeamless
!= state
) {
966 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_OBJECT
);
967 ctx
->Texture
.CubeMapSeamless
= state
;
971 case GL_RASTERIZER_DISCARD
:
972 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
973 goto invalid_enum_error
;
974 CHECK_EXTENSION(EXT_transform_feedback
, cap
);
975 if (ctx
->RasterDiscard
!= state
) {
976 FLUSH_VERTICES(ctx
, 0);
977 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewRasterizerDiscard
;
978 ctx
->RasterDiscard
= state
;
982 /* GL 3.1 primitive restart. Note: this enum is different from
983 * GL_PRIMITIVE_RESTART_NV (which is client state).
985 case GL_PRIMITIVE_RESTART
:
986 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
987 goto invalid_enum_error
;
989 if (ctx
->Array
.PrimitiveRestart
!= state
) {
990 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
991 ctx
->Array
.PrimitiveRestart
= state
;
992 update_derived_primitive_restart_state(ctx
);
996 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
997 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
)
998 goto invalid_enum_error
;
999 if (ctx
->Array
.PrimitiveRestartFixedIndex
!= state
) {
1000 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1001 ctx
->Array
.PrimitiveRestartFixedIndex
= state
;
1002 update_derived_primitive_restart_state(ctx
);
1006 /* GL3.0 - GL_framebuffer_sRGB */
1007 case GL_FRAMEBUFFER_SRGB_EXT
:
1008 if (!_mesa_is_desktop_gl(ctx
))
1009 goto invalid_enum_error
;
1010 CHECK_EXTENSION(EXT_framebuffer_sRGB
, cap
);
1011 _mesa_set_framebuffer_srgb(ctx
, state
);
1014 /* GL_OES_EGL_image_external */
1015 case GL_TEXTURE_EXTERNAL_OES
:
1016 if (!_mesa_is_gles(ctx
))
1017 goto invalid_enum_error
;
1018 CHECK_EXTENSION(OES_EGL_image_external
, cap
);
1019 if (!enable_texture(ctx
, state
, TEXTURE_EXTERNAL_BIT
)) {
1024 /* ARB_texture_multisample */
1025 case GL_SAMPLE_MASK
:
1026 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
1027 goto invalid_enum_error
;
1028 CHECK_EXTENSION(ARB_texture_multisample
, cap
);
1029 if (ctx
->Multisample
.SampleMask
== state
)
1031 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
1032 ctx
->Multisample
.SampleMask
= state
;
1035 case GL_BLEND_ADVANCED_COHERENT_KHR
:
1036 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent
, cap
);
1037 if (ctx
->Color
.BlendCoherent
== state
)
1039 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
1040 ctx
->Color
.BlendCoherent
= state
;
1044 goto invalid_enum_error
;
1047 if (ctx
->Driver
.Enable
) {
1048 ctx
->Driver
.Enable( ctx
, cap
, state
);
1054 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%s(%s)",
1055 state
? "Enable" : "Disable", _mesa_enum_to_string(cap
));
1060 * Enable GL capability. Called by glEnable()
1061 * \param cap state to enable.
1064 _mesa_Enable( GLenum cap
)
1066 GET_CURRENT_CONTEXT(ctx
);
1068 _mesa_set_enable( ctx
, cap
, GL_TRUE
);
1073 * Disable GL capability. Called by glDisable()
1074 * \param cap state to disable.
1077 _mesa_Disable( GLenum cap
)
1079 GET_CURRENT_CONTEXT(ctx
);
1081 _mesa_set_enable( ctx
, cap
, GL_FALSE
);
1087 * Enable/disable an indexed state var.
1090 _mesa_set_enablei(struct gl_context
*ctx
, GLenum cap
,
1091 GLuint index
, GLboolean state
)
1093 assert(state
== 0 || state
== 1);
1096 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
1097 goto invalid_enum_error
;
1099 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1100 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1101 state
? "glEnableIndexed" : "glDisableIndexed", index
);
1104 if (((ctx
->Color
.BlendEnabled
>> index
) & 1) != state
) {
1105 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
1107 ctx
->Color
.BlendEnabled
|= (1 << index
);
1109 ctx
->Color
.BlendEnabled
&= ~(1 << index
);
1112 case GL_SCISSOR_TEST
:
1113 if (index
>= ctx
->Const
.MaxViewports
) {
1114 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1115 state
? "glEnablei" : "glDisablei", index
);
1118 if (((ctx
->Scissor
.EnableFlags
>> index
) & 1) != state
) {
1120 ctx
->DriverFlags
.NewScissorTest
? 0 : _NEW_SCISSOR
);
1121 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewScissorTest
;
1123 ctx
->Scissor
.EnableFlags
|= (1 << index
);
1125 ctx
->Scissor
.EnableFlags
&= ~(1 << index
);
1129 goto invalid_enum_error
;
1134 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(cap=%s)",
1135 state
? "glEnablei" : "glDisablei",
1136 _mesa_enum_to_string(cap
));
1141 _mesa_Disablei( GLenum cap
, GLuint index
)
1143 GET_CURRENT_CONTEXT(ctx
);
1144 _mesa_set_enablei(ctx
, cap
, index
, GL_FALSE
);
1149 _mesa_Enablei( GLenum cap
, GLuint index
)
1151 GET_CURRENT_CONTEXT(ctx
);
1152 _mesa_set_enablei(ctx
, cap
, index
, GL_TRUE
);
1156 GLboolean GLAPIENTRY
1157 _mesa_IsEnabledi( GLenum cap
, GLuint index
)
1159 GET_CURRENT_CONTEXT(ctx
);
1160 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1163 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1164 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1168 return (ctx
->Color
.BlendEnabled
>> index
) & 1;
1169 case GL_SCISSOR_TEST
:
1170 if (index
>= ctx
->Const
.MaxViewports
) {
1171 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1175 return (ctx
->Scissor
.EnableFlags
>> index
) & 1;
1177 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabledIndexed(cap=%s)",
1178 _mesa_enum_to_string(cap
));
1186 #undef CHECK_EXTENSION
1187 #define CHECK_EXTENSION(EXTNAME) \
1188 if (!ctx->Extensions.EXTNAME) { \
1189 goto invalid_enum_error; \
1192 #undef CHECK_EXTENSION2
1193 #define CHECK_EXTENSION2(EXT1, EXT2) \
1194 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1195 goto invalid_enum_error; \
1200 * Helper function to determine whether a texture target is enabled.
1203 is_texture_enabled(struct gl_context
*ctx
, GLbitfield bit
)
1205 const struct gl_texture_unit
*const texUnit
=
1206 &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1207 return (texUnit
->Enabled
& bit
) ? GL_TRUE
: GL_FALSE
;
1212 * Return simple enable/disable state.
1214 * \param cap state variable to query.
1216 * Returns the state of the specified capability from the current GL context.
1217 * For the capabilities associated with extensions verifies that those
1218 * extensions are effectively present before reporting.
1220 GLboolean GLAPIENTRY
1221 _mesa_IsEnabled( GLenum cap
)
1223 GET_CURRENT_CONTEXT(ctx
);
1224 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1228 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1229 goto invalid_enum_error
;
1230 return ctx
->Color
.AlphaEnabled
;
1231 case GL_AUTO_NORMAL
:
1232 if (ctx
->API
!= API_OPENGL_COMPAT
)
1233 goto invalid_enum_error
;
1234 return ctx
->Eval
.AutoNormal
;
1236 return ctx
->Color
.BlendEnabled
& 1; /* return state for buffer[0] */
1237 case GL_CLIP_DISTANCE0
: /* aka GL_CLIP_PLANE0 */
1238 case GL_CLIP_DISTANCE1
:
1239 case GL_CLIP_DISTANCE2
:
1240 case GL_CLIP_DISTANCE3
:
1241 case GL_CLIP_DISTANCE4
:
1242 case GL_CLIP_DISTANCE5
:
1243 case GL_CLIP_DISTANCE6
:
1244 case GL_CLIP_DISTANCE7
: {
1245 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
1247 if (p
>= ctx
->Const
.MaxClipPlanes
)
1248 goto invalid_enum_error
;
1250 return (ctx
->Transform
.ClipPlanesEnabled
>> p
) & 1;
1252 case GL_COLOR_MATERIAL
:
1253 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1254 goto invalid_enum_error
;
1255 return ctx
->Light
.ColorMaterialEnabled
;
1257 return ctx
->Polygon
.CullFlag
;
1258 case GL_DEBUG_OUTPUT
:
1259 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
:
1260 return (GLboolean
) _mesa_get_debug_state_int(ctx
, cap
);
1262 return ctx
->Depth
.Test
;
1264 return ctx
->Color
.DitherFlag
;
1266 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1267 goto invalid_enum_error
;
1268 return ctx
->Fog
.Enabled
;
1270 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1271 goto invalid_enum_error
;
1272 return ctx
->Light
.Enabled
;
1281 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1282 goto invalid_enum_error
;
1283 return ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
;
1284 case GL_LINE_SMOOTH
:
1285 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1286 goto invalid_enum_error
;
1287 return ctx
->Line
.SmoothFlag
;
1288 case GL_LINE_STIPPLE
:
1289 if (ctx
->API
!= API_OPENGL_COMPAT
)
1290 goto invalid_enum_error
;
1291 return ctx
->Line
.StippleFlag
;
1292 case GL_INDEX_LOGIC_OP
:
1293 if (ctx
->API
!= API_OPENGL_COMPAT
)
1294 goto invalid_enum_error
;
1295 return ctx
->Color
.IndexLogicOpEnabled
;
1296 case GL_COLOR_LOGIC_OP
:
1297 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1298 goto invalid_enum_error
;
1299 return ctx
->Color
.ColorLogicOpEnabled
;
1300 case GL_MAP1_COLOR_4
:
1301 if (ctx
->API
!= API_OPENGL_COMPAT
)
1302 goto invalid_enum_error
;
1303 return ctx
->Eval
.Map1Color4
;
1305 if (ctx
->API
!= API_OPENGL_COMPAT
)
1306 goto invalid_enum_error
;
1307 return ctx
->Eval
.Map1Index
;
1308 case GL_MAP1_NORMAL
:
1309 if (ctx
->API
!= API_OPENGL_COMPAT
)
1310 goto invalid_enum_error
;
1311 return ctx
->Eval
.Map1Normal
;
1312 case GL_MAP1_TEXTURE_COORD_1
:
1313 if (ctx
->API
!= API_OPENGL_COMPAT
)
1314 goto invalid_enum_error
;
1315 return ctx
->Eval
.Map1TextureCoord1
;
1316 case GL_MAP1_TEXTURE_COORD_2
:
1317 if (ctx
->API
!= API_OPENGL_COMPAT
)
1318 goto invalid_enum_error
;
1319 return ctx
->Eval
.Map1TextureCoord2
;
1320 case GL_MAP1_TEXTURE_COORD_3
:
1321 if (ctx
->API
!= API_OPENGL_COMPAT
)
1322 goto invalid_enum_error
;
1323 return ctx
->Eval
.Map1TextureCoord3
;
1324 case GL_MAP1_TEXTURE_COORD_4
:
1325 if (ctx
->API
!= API_OPENGL_COMPAT
)
1326 goto invalid_enum_error
;
1327 return ctx
->Eval
.Map1TextureCoord4
;
1328 case GL_MAP1_VERTEX_3
:
1329 if (ctx
->API
!= API_OPENGL_COMPAT
)
1330 goto invalid_enum_error
;
1331 return ctx
->Eval
.Map1Vertex3
;
1332 case GL_MAP1_VERTEX_4
:
1333 if (ctx
->API
!= API_OPENGL_COMPAT
)
1334 goto invalid_enum_error
;
1335 return ctx
->Eval
.Map1Vertex4
;
1336 case GL_MAP2_COLOR_4
:
1337 if (ctx
->API
!= API_OPENGL_COMPAT
)
1338 goto invalid_enum_error
;
1339 return ctx
->Eval
.Map2Color4
;
1341 if (ctx
->API
!= API_OPENGL_COMPAT
)
1342 goto invalid_enum_error
;
1343 return ctx
->Eval
.Map2Index
;
1344 case GL_MAP2_NORMAL
:
1345 if (ctx
->API
!= API_OPENGL_COMPAT
)
1346 goto invalid_enum_error
;
1347 return ctx
->Eval
.Map2Normal
;
1348 case GL_MAP2_TEXTURE_COORD_1
:
1349 if (ctx
->API
!= API_OPENGL_COMPAT
)
1350 goto invalid_enum_error
;
1351 return ctx
->Eval
.Map2TextureCoord1
;
1352 case GL_MAP2_TEXTURE_COORD_2
:
1353 if (ctx
->API
!= API_OPENGL_COMPAT
)
1354 goto invalid_enum_error
;
1355 return ctx
->Eval
.Map2TextureCoord2
;
1356 case GL_MAP2_TEXTURE_COORD_3
:
1357 if (ctx
->API
!= API_OPENGL_COMPAT
)
1358 goto invalid_enum_error
;
1359 return ctx
->Eval
.Map2TextureCoord3
;
1360 case GL_MAP2_TEXTURE_COORD_4
:
1361 if (ctx
->API
!= API_OPENGL_COMPAT
)
1362 goto invalid_enum_error
;
1363 return ctx
->Eval
.Map2TextureCoord4
;
1364 case GL_MAP2_VERTEX_3
:
1365 if (ctx
->API
!= API_OPENGL_COMPAT
)
1366 goto invalid_enum_error
;
1367 return ctx
->Eval
.Map2Vertex3
;
1368 case GL_MAP2_VERTEX_4
:
1369 if (ctx
->API
!= API_OPENGL_COMPAT
)
1370 goto invalid_enum_error
;
1371 return ctx
->Eval
.Map2Vertex4
;
1373 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1374 goto invalid_enum_error
;
1375 return ctx
->Transform
.Normalize
;
1376 case GL_POINT_SMOOTH
:
1377 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1378 goto invalid_enum_error
;
1379 return ctx
->Point
.SmoothFlag
;
1380 case GL_POLYGON_SMOOTH
:
1381 if (!_mesa_is_desktop_gl(ctx
))
1382 goto invalid_enum_error
;
1383 return ctx
->Polygon
.SmoothFlag
;
1384 case GL_POLYGON_STIPPLE
:
1385 if (ctx
->API
!= API_OPENGL_COMPAT
)
1386 goto invalid_enum_error
;
1387 return ctx
->Polygon
.StippleFlag
;
1388 case GL_POLYGON_OFFSET_POINT
:
1389 if (!_mesa_is_desktop_gl(ctx
))
1390 goto invalid_enum_error
;
1391 return ctx
->Polygon
.OffsetPoint
;
1392 case GL_POLYGON_OFFSET_LINE
:
1393 if (!_mesa_is_desktop_gl(ctx
))
1394 goto invalid_enum_error
;
1395 return ctx
->Polygon
.OffsetLine
;
1396 case GL_POLYGON_OFFSET_FILL
:
1397 return ctx
->Polygon
.OffsetFill
;
1398 case GL_RESCALE_NORMAL_EXT
:
1399 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1400 goto invalid_enum_error
;
1401 return ctx
->Transform
.RescaleNormals
;
1402 case GL_SCISSOR_TEST
:
1403 return ctx
->Scissor
.EnableFlags
& 1; /* return state for index 0 */
1404 case GL_STENCIL_TEST
:
1405 return ctx
->Stencil
.Enabled
;
1407 if (ctx
->API
!= API_OPENGL_COMPAT
)
1408 goto invalid_enum_error
;
1409 return is_texture_enabled(ctx
, TEXTURE_1D_BIT
);
1411 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1412 goto invalid_enum_error
;
1413 return is_texture_enabled(ctx
, TEXTURE_2D_BIT
);
1415 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1416 goto invalid_enum_error
;
1417 return is_texture_enabled(ctx
, TEXTURE_3D_BIT
);
1418 case GL_TEXTURE_GEN_S
:
1419 case GL_TEXTURE_GEN_T
:
1420 case GL_TEXTURE_GEN_R
:
1421 case GL_TEXTURE_GEN_Q
:
1423 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1425 if (ctx
->API
!= API_OPENGL_COMPAT
)
1426 goto invalid_enum_error
;
1429 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
1430 return (texUnit
->TexGenEnabled
& coordBit
) ? GL_TRUE
: GL_FALSE
;
1434 case GL_TEXTURE_GEN_STR_OES
:
1436 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1438 if (ctx
->API
!= API_OPENGLES
)
1439 goto invalid_enum_error
;
1442 return (texUnit
->TexGenEnabled
& STR_BITS
) == STR_BITS
1443 ? GL_TRUE
: GL_FALSE
;
1447 /* client-side state */
1448 case GL_VERTEX_ARRAY
:
1449 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1450 goto invalid_enum_error
;
1451 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
;
1452 case GL_NORMAL_ARRAY
:
1453 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1454 goto invalid_enum_error
;
1455 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
;
1456 case GL_COLOR_ARRAY
:
1457 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1458 goto invalid_enum_error
;
1459 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
;
1460 case GL_INDEX_ARRAY
:
1461 if (ctx
->API
!= API_OPENGL_COMPAT
)
1462 goto invalid_enum_error
;
1463 return ctx
->Array
.VAO
->
1464 VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
;
1465 case GL_TEXTURE_COORD_ARRAY
:
1466 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1467 goto invalid_enum_error
;
1468 return ctx
->Array
.VAO
->
1469 VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Enabled
;
1470 case GL_EDGE_FLAG_ARRAY
:
1471 if (ctx
->API
!= API_OPENGL_COMPAT
)
1472 goto invalid_enum_error
;
1473 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
;
1474 case GL_FOG_COORDINATE_ARRAY_EXT
:
1475 if (ctx
->API
!= API_OPENGL_COMPAT
)
1476 goto invalid_enum_error
;
1477 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
;
1478 case GL_SECONDARY_COLOR_ARRAY_EXT
:
1479 if (ctx
->API
!= API_OPENGL_COMPAT
)
1480 goto invalid_enum_error
;
1481 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
;
1482 case GL_POINT_SIZE_ARRAY_OES
:
1483 if (ctx
->API
!= API_OPENGLES
)
1484 goto invalid_enum_error
;
1485 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
;
1487 /* GL_ARB_texture_cube_map */
1488 case GL_TEXTURE_CUBE_MAP
:
1489 CHECK_EXTENSION(ARB_texture_cube_map
);
1490 return is_texture_enabled(ctx
, TEXTURE_CUBE_BIT
);
1492 /* GL_EXT_secondary_color */
1493 case GL_COLOR_SUM_EXT
:
1494 if (ctx
->API
!= API_OPENGL_COMPAT
)
1495 goto invalid_enum_error
;
1496 return ctx
->Fog
.ColorSumEnabled
;
1498 /* GL_ARB_multisample */
1499 case GL_MULTISAMPLE_ARB
:
1500 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1501 goto invalid_enum_error
;
1502 return ctx
->Multisample
.Enabled
;
1503 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
1504 return ctx
->Multisample
.SampleAlphaToCoverage
;
1505 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
1506 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1507 goto invalid_enum_error
;
1508 return ctx
->Multisample
.SampleAlphaToOne
;
1509 case GL_SAMPLE_COVERAGE_ARB
:
1510 return ctx
->Multisample
.SampleCoverage
;
1511 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
1512 if (!_mesa_is_desktop_gl(ctx
))
1513 goto invalid_enum_error
;
1514 return ctx
->Multisample
.SampleCoverageInvert
;
1516 /* GL_IBM_rasterpos_clip */
1517 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
1518 if (ctx
->API
!= API_OPENGL_COMPAT
)
1519 goto invalid_enum_error
;
1520 return ctx
->Transform
.RasterPositionUnclipped
;
1522 /* GL_NV_point_sprite */
1523 case GL_POINT_SPRITE_NV
:
1524 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1525 goto invalid_enum_error
;
1526 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
)
1527 return ctx
->Point
.PointSprite
;
1529 case GL_VERTEX_PROGRAM_ARB
:
1530 if (ctx
->API
!= API_OPENGL_COMPAT
)
1531 goto invalid_enum_error
;
1532 CHECK_EXTENSION(ARB_vertex_program
);
1533 return ctx
->VertexProgram
.Enabled
;
1534 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
1535 /* This was added with ARB_vertex_program, but it is also used with
1536 * GLSL vertex shaders on desktop.
1538 if (!_mesa_is_desktop_gl(ctx
))
1539 goto invalid_enum_error
;
1540 CHECK_EXTENSION(ARB_vertex_program
);
1541 return ctx
->VertexProgram
.PointSizeEnabled
;
1542 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
1543 if (ctx
->API
!= API_OPENGL_COMPAT
)
1544 goto invalid_enum_error
;
1545 CHECK_EXTENSION(ARB_vertex_program
);
1546 return ctx
->VertexProgram
.TwoSideEnabled
;
1548 /* GL_NV_texture_rectangle */
1549 case GL_TEXTURE_RECTANGLE_NV
:
1550 if (ctx
->API
!= API_OPENGL_COMPAT
)
1551 goto invalid_enum_error
;
1552 CHECK_EXTENSION(NV_texture_rectangle
);
1553 return is_texture_enabled(ctx
, TEXTURE_RECT_BIT
);
1555 /* GL_EXT_stencil_two_side */
1556 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
1557 if (ctx
->API
!= API_OPENGL_COMPAT
)
1558 goto invalid_enum_error
;
1559 CHECK_EXTENSION(EXT_stencil_two_side
);
1560 return ctx
->Stencil
.TestTwoSide
;
1562 case GL_FRAGMENT_PROGRAM_ARB
:
1563 if (ctx
->API
!= API_OPENGL_COMPAT
)
1564 goto invalid_enum_error
;
1565 return ctx
->FragmentProgram
.Enabled
;
1567 /* GL_EXT_depth_bounds_test */
1568 case GL_DEPTH_BOUNDS_TEST_EXT
:
1569 if (!_mesa_is_desktop_gl(ctx
))
1570 goto invalid_enum_error
;
1571 CHECK_EXTENSION(EXT_depth_bounds_test
);
1572 return ctx
->Depth
.BoundsTest
;
1574 /* GL_ARB_depth_clamp */
1575 case GL_DEPTH_CLAMP
:
1576 if (!_mesa_is_desktop_gl(ctx
))
1577 goto invalid_enum_error
;
1578 CHECK_EXTENSION(ARB_depth_clamp
);
1579 return ctx
->Transform
.DepthClamp
;
1581 case GL_FRAGMENT_SHADER_ATI
:
1582 if (ctx
->API
!= API_OPENGL_COMPAT
)
1583 goto invalid_enum_error
;
1584 CHECK_EXTENSION(ATI_fragment_shader
);
1585 return ctx
->ATIFragmentShader
.Enabled
;
1587 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1588 if (!_mesa_is_desktop_gl(ctx
))
1589 goto invalid_enum_error
;
1590 CHECK_EXTENSION(ARB_seamless_cube_map
);
1591 return ctx
->Texture
.CubeMapSeamless
;
1593 case GL_RASTERIZER_DISCARD
:
1594 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1595 goto invalid_enum_error
;
1596 CHECK_EXTENSION(EXT_transform_feedback
);
1597 return ctx
->RasterDiscard
;
1599 /* GL_NV_primitive_restart */
1600 case GL_PRIMITIVE_RESTART_NV
:
1601 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.NV_primitive_restart
) {
1602 goto invalid_enum_error
;
1604 return ctx
->Array
.PrimitiveRestart
;
1606 /* GL 3.1 primitive restart */
1607 case GL_PRIMITIVE_RESTART
:
1608 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
1609 goto invalid_enum_error
;
1611 return ctx
->Array
.PrimitiveRestart
;
1613 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
1614 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
) {
1615 goto invalid_enum_error
;
1617 return ctx
->Array
.PrimitiveRestartFixedIndex
;
1619 /* GL3.0 - GL_framebuffer_sRGB */
1620 case GL_FRAMEBUFFER_SRGB_EXT
:
1621 if (!_mesa_is_desktop_gl(ctx
))
1622 goto invalid_enum_error
;
1623 CHECK_EXTENSION(EXT_framebuffer_sRGB
);
1624 return ctx
->Color
.sRGBEnabled
;
1626 /* GL_OES_EGL_image_external */
1627 case GL_TEXTURE_EXTERNAL_OES
:
1628 if (!_mesa_is_gles(ctx
))
1629 goto invalid_enum_error
;
1630 CHECK_EXTENSION(OES_EGL_image_external
);
1631 return is_texture_enabled(ctx
, TEXTURE_EXTERNAL_BIT
);
1633 /* ARB_texture_multisample */
1634 case GL_SAMPLE_MASK
:
1635 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
1636 goto invalid_enum_error
;
1637 CHECK_EXTENSION(ARB_texture_multisample
);
1638 return ctx
->Multisample
.SampleMask
;
1640 /* ARB_sample_shading */
1641 case GL_SAMPLE_SHADING
:
1642 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1643 goto invalid_enum_error
;
1644 CHECK_EXTENSION(ARB_sample_shading
);
1645 return ctx
->Multisample
.SampleShading
;
1647 case GL_BLEND_ADVANCED_COHERENT_KHR
:
1648 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent
);
1649 return ctx
->Color
.BlendCoherent
;
1651 case GL_CONSERVATIVE_RASTERIZATION_INTEL
:
1652 CHECK_EXTENSION(INTEL_conservative_rasterization
);
1653 return ctx
->IntelConservativeRasterization
;
1656 goto invalid_enum_error
;
1662 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabled(%s)",
1663 _mesa_enum_to_string(cap
));