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.
35 #include "debug_output.h"
45 #define CHECK_EXTENSION(EXTNAME, CAP) \
46 if (!ctx->Extensions.EXTNAME) { \
47 goto invalid_enum_error; \
52 update_derived_primitive_restart_state(struct gl_context
*ctx
)
54 /* Update derived primitive restart state.
56 ctx
->Array
._PrimitiveRestart
= ctx
->Array
.PrimitiveRestart
57 || ctx
->Array
.PrimitiveRestartFixedIndex
;
61 * Helper to enable/disable client-side state.
64 client_state(struct gl_context
*ctx
, GLenum cap
, GLboolean state
)
66 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
72 var
= &vao
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
;
76 var
= &vao
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
;
77 flag
= VERT_BIT_NORMAL
;
80 var
= &vao
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
;
81 flag
= VERT_BIT_COLOR0
;
84 var
= &vao
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
;
85 flag
= VERT_BIT_COLOR_INDEX
;
87 case GL_TEXTURE_COORD_ARRAY
:
88 var
= &vao
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Enabled
;
89 flag
= VERT_BIT_TEX(ctx
->Array
.ActiveTexture
);
91 case GL_EDGE_FLAG_ARRAY
:
92 var
= &vao
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
;
93 flag
= VERT_BIT_EDGEFLAG
;
95 case GL_FOG_COORDINATE_ARRAY_EXT
:
96 var
= &vao
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
;
99 case GL_SECONDARY_COLOR_ARRAY_EXT
:
100 var
= &vao
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
;
101 flag
= VERT_BIT_COLOR1
;
104 case GL_POINT_SIZE_ARRAY_OES
:
105 var
= &vao
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
;
106 flag
= VERT_BIT_POINT_SIZE
;
107 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
108 ctx
->VertexProgram
.PointSizeEnabled
= state
;
111 /* GL_NV_primitive_restart */
112 case GL_PRIMITIVE_RESTART_NV
:
113 if (!ctx
->Extensions
.NV_primitive_restart
) {
114 goto invalid_enum_error
;
116 var
= &ctx
->Array
.PrimitiveRestart
;
121 goto invalid_enum_error
;
127 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
131 update_derived_primitive_restart_state(ctx
);
134 vao
->_Enabled
|= flag
;
136 vao
->_Enabled
&= ~flag
;
138 vao
->NewArrays
|= flag
;
140 if (ctx
->Driver
.Enable
) {
141 ctx
->Driver
.Enable( ctx
, cap
, state
);
147 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%sClientState(%s)",
148 state
? "Enable" : "Disable", _mesa_enum_to_string(cap
));
153 * Enable GL capability.
154 * \param cap state to enable/disable.
156 * Get's the current context, assures that we're outside glBegin()/glEnd() and
157 * calls client_state().
160 _mesa_EnableClientState( GLenum cap
)
162 GET_CURRENT_CONTEXT(ctx
);
163 client_state( ctx
, cap
, GL_TRUE
);
168 * Disable GL capability.
169 * \param cap state to enable/disable.
171 * Get's the current context, assures that we're outside glBegin()/glEnd() and
172 * calls client_state().
175 _mesa_DisableClientState( GLenum cap
)
177 GET_CURRENT_CONTEXT(ctx
);
178 client_state( ctx
, cap
, GL_FALSE
);
182 #undef CHECK_EXTENSION
183 #define CHECK_EXTENSION(EXTNAME, CAP) \
184 if (!ctx->Extensions.EXTNAME) { \
185 goto invalid_enum_error; \
188 #define CHECK_EXTENSION2(EXT1, EXT2, CAP) \
189 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
190 goto invalid_enum_error; \
194 * Return pointer to current texture unit for setting/getting coordinate
196 * Note that we'll set GL_INVALID_OPERATION and return NULL if the active
197 * texture unit is higher than the number of supported coordinate units.
199 static struct gl_texture_unit
*
200 get_texcoord_unit(struct gl_context
*ctx
)
202 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
203 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glEnable/Disable(texcoord unit)");
207 return &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
213 * Helper function to enable or disable a texture target.
214 * \param bit one of the TEXTURE_x_BIT values
215 * \return GL_TRUE if state is changing or GL_FALSE if no change
218 enable_texture(struct gl_context
*ctx
, GLboolean state
, GLbitfield texBit
)
220 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
221 const GLbitfield newenabled
= state
222 ? (texUnit
->Enabled
| texBit
) : (texUnit
->Enabled
& ~texBit
);
224 if (texUnit
->Enabled
== newenabled
)
227 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_STATE
);
228 texUnit
->Enabled
= newenabled
;
234 * Helper function to enable or disable GL_MULTISAMPLE, skipping the check for
235 * whether the API supports it (GLES doesn't).
238 _mesa_set_multisample(struct gl_context
*ctx
, GLboolean state
)
240 if (ctx
->Multisample
.Enabled
== state
)
243 /* GL compatibility needs Multisample.Enable to determine program state
246 if (ctx
->API
== API_OPENGL_COMPAT
|| ctx
->API
== API_OPENGLES
||
247 !ctx
->DriverFlags
.NewMultisampleEnable
) {
248 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
250 FLUSH_VERTICES(ctx
, 0);
253 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewMultisampleEnable
;
254 ctx
->Multisample
.Enabled
= state
;
256 if (ctx
->Driver
.Enable
) {
257 ctx
->Driver
.Enable(ctx
, GL_MULTISAMPLE
, state
);
262 * Helper function to enable or disable GL_FRAMEBUFFER_SRGB, skipping the
263 * check for whether the API supports it (GLES doesn't).
266 _mesa_set_framebuffer_srgb(struct gl_context
*ctx
, GLboolean state
)
268 if (ctx
->Color
.sRGBEnabled
== state
)
271 /* TODO: Switch i965 to the new flag and remove the conditional */
272 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewFramebufferSRGB
? 0 : _NEW_BUFFERS
);
273 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewFramebufferSRGB
;
274 ctx
->Color
.sRGBEnabled
= state
;
276 if (ctx
->Driver
.Enable
) {
277 ctx
->Driver
.Enable(ctx
, GL_FRAMEBUFFER_SRGB
, state
);
282 * Helper function to enable or disable state.
284 * \param ctx GL context.
285 * \param cap the state to enable/disable
286 * \param state whether to enable or disable the specified capability.
288 * Updates the current context and flushes the vertices as needed. For
289 * capabilities associated with extensions it verifies that those extensions
290 * are effectivly present before updating. Notifies the driver via
291 * dd_function_table::Enable.
294 _mesa_set_enable(struct gl_context
*ctx
, GLenum cap
, GLboolean state
)
296 if (MESA_VERBOSE
& VERBOSE_API
)
297 _mesa_debug(ctx
, "%s %s (newstate is %x)\n",
298 state
? "glEnable" : "glDisable",
299 _mesa_enum_to_string(cap
),
304 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
305 goto invalid_enum_error
;
306 if (ctx
->Color
.AlphaEnabled
== state
)
308 /* AlphaEnabled is used by the fixed-func fragment program */
309 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
310 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewAlphaTest
;
311 ctx
->Color
.AlphaEnabled
= state
;
314 if (ctx
->API
!= API_OPENGL_COMPAT
)
315 goto invalid_enum_error
;
316 if (ctx
->Eval
.AutoNormal
== state
)
318 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
319 ctx
->Eval
.AutoNormal
= state
;
323 GLbitfield newEnabled
=
324 state
* ((1 << ctx
->Const
.MaxDrawBuffers
) - 1);
325 if (newEnabled
!= ctx
->Color
.BlendEnabled
) {
326 _mesa_flush_vertices_for_blend_state(ctx
);
327 ctx
->Color
.BlendEnabled
= newEnabled
;
331 case GL_CLIP_DISTANCE0
: /* aka GL_CLIP_PLANE0 */
332 case GL_CLIP_DISTANCE1
:
333 case GL_CLIP_DISTANCE2
:
334 case GL_CLIP_DISTANCE3
:
335 case GL_CLIP_DISTANCE4
:
336 case GL_CLIP_DISTANCE5
:
337 case GL_CLIP_DISTANCE6
:
338 case GL_CLIP_DISTANCE7
:
340 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
342 if (p
>= ctx
->Const
.MaxClipPlanes
)
343 goto invalid_enum_error
;
345 if ((ctx
->Transform
.ClipPlanesEnabled
& (1 << p
))
346 == ((GLuint
) state
<< p
))
349 /* The compatibility profile needs _NEW_TRANSFORM to transform
350 * clip planes according to the projection matrix.
352 if (ctx
->API
== API_OPENGL_COMPAT
|| ctx
->API
== API_OPENGLES
||
353 !ctx
->DriverFlags
.NewClipPlaneEnable
) {
354 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
356 FLUSH_VERTICES(ctx
, 0);
358 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewClipPlaneEnable
;
361 ctx
->Transform
.ClipPlanesEnabled
|= (1 << p
);
362 _mesa_update_clip_plane(ctx
, p
);
365 ctx
->Transform
.ClipPlanesEnabled
&= ~(1 << p
);
369 case GL_COLOR_MATERIAL
:
370 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
371 goto invalid_enum_error
;
372 if (ctx
->Light
.ColorMaterialEnabled
== state
)
374 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
375 FLUSH_CURRENT(ctx
, 0);
376 ctx
->Light
.ColorMaterialEnabled
= state
;
378 _mesa_update_color_material( ctx
,
379 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
] );
383 if (ctx
->Polygon
.CullFlag
== state
)
385 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
386 ctx
->Polygon
.CullFlag
= state
;
389 if (ctx
->Depth
.Test
== state
)
391 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewDepth
? 0 : _NEW_DEPTH
);
392 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewDepth
;
393 ctx
->Depth
.Test
= state
;
395 case GL_DEBUG_OUTPUT
:
396 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
:
397 _mesa_set_debug_state_int(ctx
, cap
, state
);
400 if (ctx
->Color
.DitherFlag
== state
)
402 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewBlend
? 0 : _NEW_COLOR
);
403 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewBlend
;
404 ctx
->Color
.DitherFlag
= state
;
407 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
408 goto invalid_enum_error
;
409 if (ctx
->Fog
.Enabled
== state
)
411 FLUSH_VERTICES(ctx
, _NEW_FOG
);
412 ctx
->Fog
.Enabled
= state
;
413 ctx
->Fog
._PackedEnabledMode
= state
? ctx
->Fog
._PackedMode
: FOG_NONE
;
423 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
424 goto invalid_enum_error
;
425 if (ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
== state
)
427 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
428 ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
= state
;
430 ctx
->Light
._EnabledLights
|= 1u << (cap
- GL_LIGHT0
);
433 ctx
->Light
._EnabledLights
&= ~(1u << (cap
- GL_LIGHT0
));
437 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
438 goto invalid_enum_error
;
439 if (ctx
->Light
.Enabled
== state
)
441 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
442 ctx
->Light
.Enabled
= state
;
445 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
446 goto invalid_enum_error
;
447 if (ctx
->Line
.SmoothFlag
== state
)
449 FLUSH_VERTICES(ctx
, _NEW_LINE
);
450 ctx
->Line
.SmoothFlag
= state
;
452 case GL_LINE_STIPPLE
:
453 if (ctx
->API
!= API_OPENGL_COMPAT
)
454 goto invalid_enum_error
;
455 if (ctx
->Line
.StippleFlag
== state
)
457 FLUSH_VERTICES(ctx
, _NEW_LINE
);
458 ctx
->Line
.StippleFlag
= state
;
460 case GL_INDEX_LOGIC_OP
:
461 if (ctx
->API
!= API_OPENGL_COMPAT
)
462 goto invalid_enum_error
;
463 if (ctx
->Color
.IndexLogicOpEnabled
== state
)
465 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewLogicOp
? 0 : _NEW_COLOR
);
466 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewLogicOp
;
467 ctx
->Color
.IndexLogicOpEnabled
= state
;
469 case GL_CONSERVATIVE_RASTERIZATION_INTEL
:
470 if (!_mesa_has_INTEL_conservative_rasterization(ctx
))
471 goto invalid_enum_error
;
472 if (ctx
->IntelConservativeRasterization
== state
)
474 FLUSH_VERTICES(ctx
, 0);
475 ctx
->NewDriverState
|=
476 ctx
->DriverFlags
.NewIntelConservativeRasterization
;
477 ctx
->IntelConservativeRasterization
= state
;
479 case GL_COLOR_LOGIC_OP
:
480 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
481 goto invalid_enum_error
;
482 if (ctx
->Color
.ColorLogicOpEnabled
== state
)
484 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewLogicOp
? 0 : _NEW_COLOR
);
485 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewLogicOp
;
486 ctx
->Color
.ColorLogicOpEnabled
= state
;
488 case GL_MAP1_COLOR_4
:
489 if (ctx
->API
!= API_OPENGL_COMPAT
)
490 goto invalid_enum_error
;
491 if (ctx
->Eval
.Map1Color4
== state
)
493 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
494 ctx
->Eval
.Map1Color4
= state
;
497 if (ctx
->API
!= API_OPENGL_COMPAT
)
498 goto invalid_enum_error
;
499 if (ctx
->Eval
.Map1Index
== state
)
501 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
502 ctx
->Eval
.Map1Index
= state
;
505 if (ctx
->API
!= API_OPENGL_COMPAT
)
506 goto invalid_enum_error
;
507 if (ctx
->Eval
.Map1Normal
== state
)
509 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
510 ctx
->Eval
.Map1Normal
= state
;
512 case GL_MAP1_TEXTURE_COORD_1
:
513 if (ctx
->API
!= API_OPENGL_COMPAT
)
514 goto invalid_enum_error
;
515 if (ctx
->Eval
.Map1TextureCoord1
== state
)
517 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
518 ctx
->Eval
.Map1TextureCoord1
= state
;
520 case GL_MAP1_TEXTURE_COORD_2
:
521 if (ctx
->API
!= API_OPENGL_COMPAT
)
522 goto invalid_enum_error
;
523 if (ctx
->Eval
.Map1TextureCoord2
== state
)
525 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
526 ctx
->Eval
.Map1TextureCoord2
= state
;
528 case GL_MAP1_TEXTURE_COORD_3
:
529 if (ctx
->API
!= API_OPENGL_COMPAT
)
530 goto invalid_enum_error
;
531 if (ctx
->Eval
.Map1TextureCoord3
== state
)
533 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
534 ctx
->Eval
.Map1TextureCoord3
= state
;
536 case GL_MAP1_TEXTURE_COORD_4
:
537 if (ctx
->API
!= API_OPENGL_COMPAT
)
538 goto invalid_enum_error
;
539 if (ctx
->Eval
.Map1TextureCoord4
== state
)
541 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
542 ctx
->Eval
.Map1TextureCoord4
= state
;
544 case GL_MAP1_VERTEX_3
:
545 if (ctx
->API
!= API_OPENGL_COMPAT
)
546 goto invalid_enum_error
;
547 if (ctx
->Eval
.Map1Vertex3
== state
)
549 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
550 ctx
->Eval
.Map1Vertex3
= state
;
552 case GL_MAP1_VERTEX_4
:
553 if (ctx
->API
!= API_OPENGL_COMPAT
)
554 goto invalid_enum_error
;
555 if (ctx
->Eval
.Map1Vertex4
== state
)
557 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
558 ctx
->Eval
.Map1Vertex4
= state
;
560 case GL_MAP2_COLOR_4
:
561 if (ctx
->API
!= API_OPENGL_COMPAT
)
562 goto invalid_enum_error
;
563 if (ctx
->Eval
.Map2Color4
== state
)
565 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
566 ctx
->Eval
.Map2Color4
= state
;
569 if (ctx
->API
!= API_OPENGL_COMPAT
)
570 goto invalid_enum_error
;
571 if (ctx
->Eval
.Map2Index
== state
)
573 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
574 ctx
->Eval
.Map2Index
= state
;
577 if (ctx
->API
!= API_OPENGL_COMPAT
)
578 goto invalid_enum_error
;
579 if (ctx
->Eval
.Map2Normal
== state
)
581 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
582 ctx
->Eval
.Map2Normal
= state
;
584 case GL_MAP2_TEXTURE_COORD_1
:
585 if (ctx
->API
!= API_OPENGL_COMPAT
)
586 goto invalid_enum_error
;
587 if (ctx
->Eval
.Map2TextureCoord1
== state
)
589 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
590 ctx
->Eval
.Map2TextureCoord1
= state
;
592 case GL_MAP2_TEXTURE_COORD_2
:
593 if (ctx
->API
!= API_OPENGL_COMPAT
)
594 goto invalid_enum_error
;
595 if (ctx
->Eval
.Map2TextureCoord2
== state
)
597 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
598 ctx
->Eval
.Map2TextureCoord2
= state
;
600 case GL_MAP2_TEXTURE_COORD_3
:
601 if (ctx
->API
!= API_OPENGL_COMPAT
)
602 goto invalid_enum_error
;
603 if (ctx
->Eval
.Map2TextureCoord3
== state
)
605 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
606 ctx
->Eval
.Map2TextureCoord3
= state
;
608 case GL_MAP2_TEXTURE_COORD_4
:
609 if (ctx
->API
!= API_OPENGL_COMPAT
)
610 goto invalid_enum_error
;
611 if (ctx
->Eval
.Map2TextureCoord4
== state
)
613 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
614 ctx
->Eval
.Map2TextureCoord4
= state
;
616 case GL_MAP2_VERTEX_3
:
617 if (ctx
->API
!= API_OPENGL_COMPAT
)
618 goto invalid_enum_error
;
619 if (ctx
->Eval
.Map2Vertex3
== state
)
621 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
622 ctx
->Eval
.Map2Vertex3
= state
;
624 case GL_MAP2_VERTEX_4
:
625 if (ctx
->API
!= API_OPENGL_COMPAT
)
626 goto invalid_enum_error
;
627 if (ctx
->Eval
.Map2Vertex4
== state
)
629 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
630 ctx
->Eval
.Map2Vertex4
= state
;
633 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
634 goto invalid_enum_error
;
635 if (ctx
->Transform
.Normalize
== state
)
637 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
638 ctx
->Transform
.Normalize
= state
;
640 case GL_POINT_SMOOTH
:
641 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
642 goto invalid_enum_error
;
643 if (ctx
->Point
.SmoothFlag
== state
)
645 FLUSH_VERTICES(ctx
, _NEW_POINT
);
646 ctx
->Point
.SmoothFlag
= state
;
648 case GL_POLYGON_SMOOTH
:
649 if (!_mesa_is_desktop_gl(ctx
))
650 goto invalid_enum_error
;
651 if (ctx
->Polygon
.SmoothFlag
== state
)
653 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
654 ctx
->Polygon
.SmoothFlag
= state
;
656 case GL_POLYGON_STIPPLE
:
657 if (ctx
->API
!= API_OPENGL_COMPAT
)
658 goto invalid_enum_error
;
659 if (ctx
->Polygon
.StippleFlag
== state
)
661 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
662 ctx
->Polygon
.StippleFlag
= state
;
664 case GL_POLYGON_OFFSET_POINT
:
665 if (!_mesa_is_desktop_gl(ctx
))
666 goto invalid_enum_error
;
667 if (ctx
->Polygon
.OffsetPoint
== state
)
669 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
670 ctx
->Polygon
.OffsetPoint
= state
;
672 case GL_POLYGON_OFFSET_LINE
:
673 if (!_mesa_is_desktop_gl(ctx
))
674 goto invalid_enum_error
;
675 if (ctx
->Polygon
.OffsetLine
== state
)
677 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
678 ctx
->Polygon
.OffsetLine
= state
;
680 case GL_POLYGON_OFFSET_FILL
:
681 if (ctx
->Polygon
.OffsetFill
== state
)
683 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
684 ctx
->Polygon
.OffsetFill
= state
;
686 case GL_RESCALE_NORMAL_EXT
:
687 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
688 goto invalid_enum_error
;
689 if (ctx
->Transform
.RescaleNormals
== state
)
691 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
692 ctx
->Transform
.RescaleNormals
= state
;
694 case GL_SCISSOR_TEST
:
696 /* Must expand glEnable to all scissors */
697 GLbitfield newEnabled
=
698 state
* ((1 << ctx
->Const
.MaxViewports
) - 1);
699 if (newEnabled
!= ctx
->Scissor
.EnableFlags
) {
700 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewScissorTest
? 0 :
702 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewScissorTest
;
703 ctx
->Scissor
.EnableFlags
= newEnabled
;
707 case GL_STENCIL_TEST
:
708 if (ctx
->Stencil
.Enabled
== state
)
710 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewStencil
? 0 : _NEW_STENCIL
);
711 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewStencil
;
712 ctx
->Stencil
.Enabled
= state
;
715 if (ctx
->API
!= API_OPENGL_COMPAT
)
716 goto invalid_enum_error
;
717 if (!enable_texture(ctx
, state
, TEXTURE_1D_BIT
)) {
722 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
723 goto invalid_enum_error
;
724 if (!enable_texture(ctx
, state
, TEXTURE_2D_BIT
)) {
729 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
730 goto invalid_enum_error
;
731 if (!enable_texture(ctx
, state
, TEXTURE_3D_BIT
)) {
735 case GL_TEXTURE_GEN_S
:
736 case GL_TEXTURE_GEN_T
:
737 case GL_TEXTURE_GEN_R
:
738 case GL_TEXTURE_GEN_Q
:
740 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
742 if (ctx
->API
!= API_OPENGL_COMPAT
)
743 goto invalid_enum_error
;
746 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
747 GLbitfield newenabled
= texUnit
->TexGenEnabled
& ~coordBit
;
749 newenabled
|= coordBit
;
750 if (texUnit
->TexGenEnabled
== newenabled
)
752 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_STATE
);
753 texUnit
->TexGenEnabled
= newenabled
;
758 case GL_TEXTURE_GEN_STR_OES
:
759 /* disable S, T, and R at the same time */
761 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
763 if (ctx
->API
!= API_OPENGLES
)
764 goto invalid_enum_error
;
768 texUnit
->TexGenEnabled
& ~STR_BITS
;
770 newenabled
|= STR_BITS
;
771 if (texUnit
->TexGenEnabled
== newenabled
)
773 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_STATE
);
774 texUnit
->TexGenEnabled
= newenabled
;
779 /* client-side state */
780 case GL_VERTEX_ARRAY
:
781 case GL_NORMAL_ARRAY
:
783 case GL_TEXTURE_COORD_ARRAY
:
784 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
785 goto invalid_enum_error
;
786 client_state( ctx
, cap
, state
);
789 case GL_EDGE_FLAG_ARRAY
:
790 case GL_FOG_COORDINATE_ARRAY_EXT
:
791 case GL_SECONDARY_COLOR_ARRAY_EXT
:
792 if (ctx
->API
!= API_OPENGL_COMPAT
)
793 goto invalid_enum_error
;
794 client_state( ctx
, cap
, state
);
796 case GL_POINT_SIZE_ARRAY_OES
:
797 if (ctx
->API
!= API_OPENGLES
)
798 goto invalid_enum_error
;
799 client_state( ctx
, cap
, state
);
802 /* GL_ARB_texture_cube_map */
803 case GL_TEXTURE_CUBE_MAP
:
804 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
805 goto invalid_enum_error
;
806 CHECK_EXTENSION(ARB_texture_cube_map
, cap
);
807 if (!enable_texture(ctx
, state
, TEXTURE_CUBE_BIT
)) {
812 /* GL_EXT_secondary_color */
813 case GL_COLOR_SUM_EXT
:
814 if (ctx
->API
!= API_OPENGL_COMPAT
)
815 goto invalid_enum_error
;
816 if (ctx
->Fog
.ColorSumEnabled
== state
)
818 FLUSH_VERTICES(ctx
, _NEW_FOG
);
819 ctx
->Fog
.ColorSumEnabled
= state
;
822 /* GL_ARB_multisample */
823 case GL_MULTISAMPLE_ARB
:
824 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
825 goto invalid_enum_error
;
826 _mesa_set_multisample(ctx
, state
);
828 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
829 if (ctx
->Multisample
.SampleAlphaToCoverage
== state
)
831 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewSampleAlphaToXEnable
? 0 :
833 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewSampleAlphaToXEnable
;
834 ctx
->Multisample
.SampleAlphaToCoverage
= state
;
836 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
837 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
838 goto invalid_enum_error
;
839 if (ctx
->Multisample
.SampleAlphaToOne
== state
)
841 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewSampleAlphaToXEnable
? 0 :
843 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewSampleAlphaToXEnable
;
844 ctx
->Multisample
.SampleAlphaToOne
= state
;
846 case GL_SAMPLE_COVERAGE_ARB
:
847 if (ctx
->Multisample
.SampleCoverage
== state
)
849 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewSampleMask
? 0 :
851 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewSampleMask
;
852 ctx
->Multisample
.SampleCoverage
= state
;
854 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
855 if (!_mesa_is_desktop_gl(ctx
))
856 goto invalid_enum_error
;
857 if (ctx
->Multisample
.SampleCoverageInvert
== state
)
859 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewSampleMask
? 0 :
861 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewSampleMask
;
862 ctx
->Multisample
.SampleCoverageInvert
= state
;
865 /* GL_ARB_sample_shading */
866 case GL_SAMPLE_SHADING
:
867 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
868 goto invalid_enum_error
;
869 CHECK_EXTENSION(ARB_sample_shading
, cap
);
870 if (ctx
->Multisample
.SampleShading
== state
)
872 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewSampleShading
? 0 :
874 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewSampleShading
;
875 ctx
->Multisample
.SampleShading
= state
;
878 /* GL_IBM_rasterpos_clip */
879 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
880 if (ctx
->API
!= API_OPENGL_COMPAT
)
881 goto invalid_enum_error
;
882 if (ctx
->Transform
.RasterPositionUnclipped
== state
)
884 FLUSH_VERTICES(ctx
, 0);
885 ctx
->Transform
.RasterPositionUnclipped
= state
;
888 /* GL_NV_point_sprite */
889 case GL_POINT_SPRITE_NV
:
890 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
891 goto invalid_enum_error
;
892 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
, cap
);
893 if (ctx
->Point
.PointSprite
== state
)
895 FLUSH_VERTICES(ctx
, _NEW_POINT
);
896 ctx
->Point
.PointSprite
= state
;
899 case GL_VERTEX_PROGRAM_ARB
:
900 if (ctx
->API
!= API_OPENGL_COMPAT
)
901 goto invalid_enum_error
;
902 CHECK_EXTENSION(ARB_vertex_program
, cap
);
903 if (ctx
->VertexProgram
.Enabled
== state
)
905 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
906 ctx
->VertexProgram
.Enabled
= state
;
908 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
909 /* This was added with ARB_vertex_program, but it is also used with
910 * GLSL vertex shaders on desktop.
912 if (!_mesa_is_desktop_gl(ctx
))
913 goto invalid_enum_error
;
914 CHECK_EXTENSION(ARB_vertex_program
, cap
);
915 if (ctx
->VertexProgram
.PointSizeEnabled
== state
)
917 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
918 ctx
->VertexProgram
.PointSizeEnabled
= state
;
920 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
921 if (ctx
->API
!= API_OPENGL_COMPAT
)
922 goto invalid_enum_error
;
923 CHECK_EXTENSION(ARB_vertex_program
, cap
);
924 if (ctx
->VertexProgram
.TwoSideEnabled
== state
)
926 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
927 ctx
->VertexProgram
.TwoSideEnabled
= state
;
930 /* GL_NV_texture_rectangle */
931 case GL_TEXTURE_RECTANGLE_NV
:
932 if (ctx
->API
!= API_OPENGL_COMPAT
)
933 goto invalid_enum_error
;
934 CHECK_EXTENSION(NV_texture_rectangle
, cap
);
935 if (!enable_texture(ctx
, state
, TEXTURE_RECT_BIT
)) {
940 /* GL_EXT_stencil_two_side */
941 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
942 if (ctx
->API
!= API_OPENGL_COMPAT
)
943 goto invalid_enum_error
;
944 CHECK_EXTENSION(EXT_stencil_two_side
, cap
);
945 if (ctx
->Stencil
.TestTwoSide
== state
)
947 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewStencil
? 0 : _NEW_STENCIL
);
948 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewStencil
;
949 ctx
->Stencil
.TestTwoSide
= state
;
951 ctx
->Stencil
._BackFace
= 2;
953 ctx
->Stencil
._BackFace
= 1;
957 case GL_FRAGMENT_PROGRAM_ARB
:
958 if (ctx
->API
!= API_OPENGL_COMPAT
)
959 goto invalid_enum_error
;
960 CHECK_EXTENSION(ARB_fragment_program
, cap
);
961 if (ctx
->FragmentProgram
.Enabled
== state
)
963 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
964 ctx
->FragmentProgram
.Enabled
= state
;
967 /* GL_EXT_depth_bounds_test */
968 case GL_DEPTH_BOUNDS_TEST_EXT
:
969 if (!_mesa_is_desktop_gl(ctx
))
970 goto invalid_enum_error
;
971 CHECK_EXTENSION(EXT_depth_bounds_test
, cap
);
972 if (ctx
->Depth
.BoundsTest
== state
)
974 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewDepth
? 0 : _NEW_DEPTH
);
975 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewDepth
;
976 ctx
->Depth
.BoundsTest
= state
;
980 if (!_mesa_is_desktop_gl(ctx
))
981 goto invalid_enum_error
;
982 CHECK_EXTENSION(ARB_depth_clamp
, cap
);
983 if (ctx
->Transform
.DepthClamp
== state
)
985 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewDepthClamp
? 0 :
987 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewDepthClamp
;
988 ctx
->Transform
.DepthClamp
= state
;
991 case GL_FRAGMENT_SHADER_ATI
:
992 if (ctx
->API
!= API_OPENGL_COMPAT
)
993 goto invalid_enum_error
;
994 CHECK_EXTENSION(ATI_fragment_shader
, cap
);
995 if (ctx
->ATIFragmentShader
.Enabled
== state
)
997 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
998 ctx
->ATIFragmentShader
.Enabled
= state
;
1001 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1002 if (!_mesa_is_desktop_gl(ctx
))
1003 goto invalid_enum_error
;
1004 CHECK_EXTENSION(ARB_seamless_cube_map
, cap
);
1005 if (ctx
->Texture
.CubeMapSeamless
!= state
) {
1006 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_OBJECT
);
1007 ctx
->Texture
.CubeMapSeamless
= state
;
1011 case GL_RASTERIZER_DISCARD
:
1012 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1013 goto invalid_enum_error
;
1014 CHECK_EXTENSION(EXT_transform_feedback
, cap
);
1015 if (ctx
->RasterDiscard
!= state
) {
1016 FLUSH_VERTICES(ctx
, 0);
1017 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewRasterizerDiscard
;
1018 ctx
->RasterDiscard
= state
;
1022 /* GL 3.1 primitive restart. Note: this enum is different from
1023 * GL_PRIMITIVE_RESTART_NV (which is client state).
1025 case GL_PRIMITIVE_RESTART
:
1026 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
1027 goto invalid_enum_error
;
1029 if (ctx
->Array
.PrimitiveRestart
!= state
) {
1030 FLUSH_VERTICES(ctx
, 0);
1031 ctx
->Array
.PrimitiveRestart
= state
;
1032 update_derived_primitive_restart_state(ctx
);
1036 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
1037 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
)
1038 goto invalid_enum_error
;
1039 if (ctx
->Array
.PrimitiveRestartFixedIndex
!= state
) {
1040 FLUSH_VERTICES(ctx
, 0);
1041 ctx
->Array
.PrimitiveRestartFixedIndex
= state
;
1042 update_derived_primitive_restart_state(ctx
);
1046 /* GL3.0 - GL_framebuffer_sRGB */
1047 case GL_FRAMEBUFFER_SRGB_EXT
:
1048 if (!_mesa_is_desktop_gl(ctx
))
1049 goto invalid_enum_error
;
1050 CHECK_EXTENSION(EXT_framebuffer_sRGB
, cap
);
1051 _mesa_set_framebuffer_srgb(ctx
, state
);
1054 /* GL_OES_EGL_image_external */
1055 case GL_TEXTURE_EXTERNAL_OES
:
1056 if (!_mesa_is_gles(ctx
))
1057 goto invalid_enum_error
;
1058 CHECK_EXTENSION(OES_EGL_image_external
, cap
);
1059 if (!enable_texture(ctx
, state
, TEXTURE_EXTERNAL_BIT
)) {
1064 /* ARB_texture_multisample */
1065 case GL_SAMPLE_MASK
:
1066 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
1067 goto invalid_enum_error
;
1068 CHECK_EXTENSION(ARB_texture_multisample
, cap
);
1069 if (ctx
->Multisample
.SampleMask
== state
)
1071 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewSampleMask
? 0 :
1073 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewSampleMask
;
1074 ctx
->Multisample
.SampleMask
= state
;
1077 case GL_BLEND_ADVANCED_COHERENT_KHR
:
1078 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent
, cap
);
1079 if (ctx
->Color
.BlendCoherent
== state
)
1081 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewBlend
? 0 : _NEW_COLOR
);
1082 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewBlend
;
1083 ctx
->Color
.BlendCoherent
= state
;
1087 goto invalid_enum_error
;
1090 if (ctx
->Driver
.Enable
) {
1091 ctx
->Driver
.Enable( ctx
, cap
, state
);
1097 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%s(%s)",
1098 state
? "Enable" : "Disable", _mesa_enum_to_string(cap
));
1103 * Enable GL capability. Called by glEnable()
1104 * \param cap state to enable.
1107 _mesa_Enable( GLenum cap
)
1109 GET_CURRENT_CONTEXT(ctx
);
1111 _mesa_set_enable( ctx
, cap
, GL_TRUE
);
1116 * Disable GL capability. Called by glDisable()
1117 * \param cap state to disable.
1120 _mesa_Disable( GLenum cap
)
1122 GET_CURRENT_CONTEXT(ctx
);
1124 _mesa_set_enable( ctx
, cap
, GL_FALSE
);
1130 * Enable/disable an indexed state var.
1133 _mesa_set_enablei(struct gl_context
*ctx
, GLenum cap
,
1134 GLuint index
, GLboolean state
)
1136 assert(state
== 0 || state
== 1);
1139 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
1140 goto invalid_enum_error
;
1142 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1143 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1144 state
? "glEnableIndexed" : "glDisableIndexed", index
);
1147 if (((ctx
->Color
.BlendEnabled
>> index
) & 1) != state
) {
1148 _mesa_flush_vertices_for_blend_state(ctx
);
1150 ctx
->Color
.BlendEnabled
|= (1 << index
);
1152 ctx
->Color
.BlendEnabled
&= ~(1 << index
);
1155 case GL_SCISSOR_TEST
:
1156 if (index
>= ctx
->Const
.MaxViewports
) {
1157 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1158 state
? "glEnablei" : "glDisablei", index
);
1161 if (((ctx
->Scissor
.EnableFlags
>> index
) & 1) != state
) {
1163 ctx
->DriverFlags
.NewScissorTest
? 0 : _NEW_SCISSOR
);
1164 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewScissorTest
;
1166 ctx
->Scissor
.EnableFlags
|= (1 << index
);
1168 ctx
->Scissor
.EnableFlags
&= ~(1 << index
);
1172 goto invalid_enum_error
;
1177 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(cap=%s)",
1178 state
? "glEnablei" : "glDisablei",
1179 _mesa_enum_to_string(cap
));
1184 _mesa_Disablei( GLenum cap
, GLuint index
)
1186 GET_CURRENT_CONTEXT(ctx
);
1187 _mesa_set_enablei(ctx
, cap
, index
, GL_FALSE
);
1192 _mesa_Enablei( GLenum cap
, GLuint index
)
1194 GET_CURRENT_CONTEXT(ctx
);
1195 _mesa_set_enablei(ctx
, cap
, index
, GL_TRUE
);
1199 GLboolean GLAPIENTRY
1200 _mesa_IsEnabledi( GLenum cap
, GLuint index
)
1202 GET_CURRENT_CONTEXT(ctx
);
1203 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1206 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1207 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1211 return (ctx
->Color
.BlendEnabled
>> index
) & 1;
1212 case GL_SCISSOR_TEST
:
1213 if (index
>= ctx
->Const
.MaxViewports
) {
1214 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1218 return (ctx
->Scissor
.EnableFlags
>> index
) & 1;
1220 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabledIndexed(cap=%s)",
1221 _mesa_enum_to_string(cap
));
1229 #undef CHECK_EXTENSION
1230 #define CHECK_EXTENSION(EXTNAME) \
1231 if (!ctx->Extensions.EXTNAME) { \
1232 goto invalid_enum_error; \
1235 #undef CHECK_EXTENSION2
1236 #define CHECK_EXTENSION2(EXT1, EXT2) \
1237 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1238 goto invalid_enum_error; \
1243 * Helper function to determine whether a texture target is enabled.
1246 is_texture_enabled(struct gl_context
*ctx
, GLbitfield bit
)
1248 const struct gl_texture_unit
*const texUnit
=
1249 &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1250 return (texUnit
->Enabled
& bit
) ? GL_TRUE
: GL_FALSE
;
1255 * Return simple enable/disable state.
1257 * \param cap state variable to query.
1259 * Returns the state of the specified capability from the current GL context.
1260 * For the capabilities associated with extensions verifies that those
1261 * extensions are effectively present before reporting.
1263 GLboolean GLAPIENTRY
1264 _mesa_IsEnabled( GLenum cap
)
1266 GET_CURRENT_CONTEXT(ctx
);
1267 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1271 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1272 goto invalid_enum_error
;
1273 return ctx
->Color
.AlphaEnabled
;
1274 case GL_AUTO_NORMAL
:
1275 if (ctx
->API
!= API_OPENGL_COMPAT
)
1276 goto invalid_enum_error
;
1277 return ctx
->Eval
.AutoNormal
;
1279 return ctx
->Color
.BlendEnabled
& 1; /* return state for buffer[0] */
1280 case GL_CLIP_DISTANCE0
: /* aka GL_CLIP_PLANE0 */
1281 case GL_CLIP_DISTANCE1
:
1282 case GL_CLIP_DISTANCE2
:
1283 case GL_CLIP_DISTANCE3
:
1284 case GL_CLIP_DISTANCE4
:
1285 case GL_CLIP_DISTANCE5
:
1286 case GL_CLIP_DISTANCE6
:
1287 case GL_CLIP_DISTANCE7
: {
1288 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
1290 if (p
>= ctx
->Const
.MaxClipPlanes
)
1291 goto invalid_enum_error
;
1293 return (ctx
->Transform
.ClipPlanesEnabled
>> p
) & 1;
1295 case GL_COLOR_MATERIAL
:
1296 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1297 goto invalid_enum_error
;
1298 return ctx
->Light
.ColorMaterialEnabled
;
1300 return ctx
->Polygon
.CullFlag
;
1301 case GL_DEBUG_OUTPUT
:
1302 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
:
1303 return (GLboolean
) _mesa_get_debug_state_int(ctx
, cap
);
1305 return ctx
->Depth
.Test
;
1307 return ctx
->Color
.DitherFlag
;
1309 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1310 goto invalid_enum_error
;
1311 return ctx
->Fog
.Enabled
;
1313 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1314 goto invalid_enum_error
;
1315 return ctx
->Light
.Enabled
;
1324 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1325 goto invalid_enum_error
;
1326 return ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
;
1327 case GL_LINE_SMOOTH
:
1328 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1329 goto invalid_enum_error
;
1330 return ctx
->Line
.SmoothFlag
;
1331 case GL_LINE_STIPPLE
:
1332 if (ctx
->API
!= API_OPENGL_COMPAT
)
1333 goto invalid_enum_error
;
1334 return ctx
->Line
.StippleFlag
;
1335 case GL_INDEX_LOGIC_OP
:
1336 if (ctx
->API
!= API_OPENGL_COMPAT
)
1337 goto invalid_enum_error
;
1338 return ctx
->Color
.IndexLogicOpEnabled
;
1339 case GL_COLOR_LOGIC_OP
:
1340 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1341 goto invalid_enum_error
;
1342 return ctx
->Color
.ColorLogicOpEnabled
;
1343 case GL_MAP1_COLOR_4
:
1344 if (ctx
->API
!= API_OPENGL_COMPAT
)
1345 goto invalid_enum_error
;
1346 return ctx
->Eval
.Map1Color4
;
1348 if (ctx
->API
!= API_OPENGL_COMPAT
)
1349 goto invalid_enum_error
;
1350 return ctx
->Eval
.Map1Index
;
1351 case GL_MAP1_NORMAL
:
1352 if (ctx
->API
!= API_OPENGL_COMPAT
)
1353 goto invalid_enum_error
;
1354 return ctx
->Eval
.Map1Normal
;
1355 case GL_MAP1_TEXTURE_COORD_1
:
1356 if (ctx
->API
!= API_OPENGL_COMPAT
)
1357 goto invalid_enum_error
;
1358 return ctx
->Eval
.Map1TextureCoord1
;
1359 case GL_MAP1_TEXTURE_COORD_2
:
1360 if (ctx
->API
!= API_OPENGL_COMPAT
)
1361 goto invalid_enum_error
;
1362 return ctx
->Eval
.Map1TextureCoord2
;
1363 case GL_MAP1_TEXTURE_COORD_3
:
1364 if (ctx
->API
!= API_OPENGL_COMPAT
)
1365 goto invalid_enum_error
;
1366 return ctx
->Eval
.Map1TextureCoord3
;
1367 case GL_MAP1_TEXTURE_COORD_4
:
1368 if (ctx
->API
!= API_OPENGL_COMPAT
)
1369 goto invalid_enum_error
;
1370 return ctx
->Eval
.Map1TextureCoord4
;
1371 case GL_MAP1_VERTEX_3
:
1372 if (ctx
->API
!= API_OPENGL_COMPAT
)
1373 goto invalid_enum_error
;
1374 return ctx
->Eval
.Map1Vertex3
;
1375 case GL_MAP1_VERTEX_4
:
1376 if (ctx
->API
!= API_OPENGL_COMPAT
)
1377 goto invalid_enum_error
;
1378 return ctx
->Eval
.Map1Vertex4
;
1379 case GL_MAP2_COLOR_4
:
1380 if (ctx
->API
!= API_OPENGL_COMPAT
)
1381 goto invalid_enum_error
;
1382 return ctx
->Eval
.Map2Color4
;
1384 if (ctx
->API
!= API_OPENGL_COMPAT
)
1385 goto invalid_enum_error
;
1386 return ctx
->Eval
.Map2Index
;
1387 case GL_MAP2_NORMAL
:
1388 if (ctx
->API
!= API_OPENGL_COMPAT
)
1389 goto invalid_enum_error
;
1390 return ctx
->Eval
.Map2Normal
;
1391 case GL_MAP2_TEXTURE_COORD_1
:
1392 if (ctx
->API
!= API_OPENGL_COMPAT
)
1393 goto invalid_enum_error
;
1394 return ctx
->Eval
.Map2TextureCoord1
;
1395 case GL_MAP2_TEXTURE_COORD_2
:
1396 if (ctx
->API
!= API_OPENGL_COMPAT
)
1397 goto invalid_enum_error
;
1398 return ctx
->Eval
.Map2TextureCoord2
;
1399 case GL_MAP2_TEXTURE_COORD_3
:
1400 if (ctx
->API
!= API_OPENGL_COMPAT
)
1401 goto invalid_enum_error
;
1402 return ctx
->Eval
.Map2TextureCoord3
;
1403 case GL_MAP2_TEXTURE_COORD_4
:
1404 if (ctx
->API
!= API_OPENGL_COMPAT
)
1405 goto invalid_enum_error
;
1406 return ctx
->Eval
.Map2TextureCoord4
;
1407 case GL_MAP2_VERTEX_3
:
1408 if (ctx
->API
!= API_OPENGL_COMPAT
)
1409 goto invalid_enum_error
;
1410 return ctx
->Eval
.Map2Vertex3
;
1411 case GL_MAP2_VERTEX_4
:
1412 if (ctx
->API
!= API_OPENGL_COMPAT
)
1413 goto invalid_enum_error
;
1414 return ctx
->Eval
.Map2Vertex4
;
1416 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1417 goto invalid_enum_error
;
1418 return ctx
->Transform
.Normalize
;
1419 case GL_POINT_SMOOTH
:
1420 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1421 goto invalid_enum_error
;
1422 return ctx
->Point
.SmoothFlag
;
1423 case GL_POLYGON_SMOOTH
:
1424 if (!_mesa_is_desktop_gl(ctx
))
1425 goto invalid_enum_error
;
1426 return ctx
->Polygon
.SmoothFlag
;
1427 case GL_POLYGON_STIPPLE
:
1428 if (ctx
->API
!= API_OPENGL_COMPAT
)
1429 goto invalid_enum_error
;
1430 return ctx
->Polygon
.StippleFlag
;
1431 case GL_POLYGON_OFFSET_POINT
:
1432 if (!_mesa_is_desktop_gl(ctx
))
1433 goto invalid_enum_error
;
1434 return ctx
->Polygon
.OffsetPoint
;
1435 case GL_POLYGON_OFFSET_LINE
:
1436 if (!_mesa_is_desktop_gl(ctx
))
1437 goto invalid_enum_error
;
1438 return ctx
->Polygon
.OffsetLine
;
1439 case GL_POLYGON_OFFSET_FILL
:
1440 return ctx
->Polygon
.OffsetFill
;
1441 case GL_RESCALE_NORMAL_EXT
:
1442 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1443 goto invalid_enum_error
;
1444 return ctx
->Transform
.RescaleNormals
;
1445 case GL_SCISSOR_TEST
:
1446 return ctx
->Scissor
.EnableFlags
& 1; /* return state for index 0 */
1447 case GL_STENCIL_TEST
:
1448 return ctx
->Stencil
.Enabled
;
1450 if (ctx
->API
!= API_OPENGL_COMPAT
)
1451 goto invalid_enum_error
;
1452 return is_texture_enabled(ctx
, TEXTURE_1D_BIT
);
1454 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1455 goto invalid_enum_error
;
1456 return is_texture_enabled(ctx
, TEXTURE_2D_BIT
);
1458 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1459 goto invalid_enum_error
;
1460 return is_texture_enabled(ctx
, TEXTURE_3D_BIT
);
1461 case GL_TEXTURE_GEN_S
:
1462 case GL_TEXTURE_GEN_T
:
1463 case GL_TEXTURE_GEN_R
:
1464 case GL_TEXTURE_GEN_Q
:
1466 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1468 if (ctx
->API
!= API_OPENGL_COMPAT
)
1469 goto invalid_enum_error
;
1472 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
1473 return (texUnit
->TexGenEnabled
& coordBit
) ? GL_TRUE
: GL_FALSE
;
1477 case GL_TEXTURE_GEN_STR_OES
:
1479 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1481 if (ctx
->API
!= API_OPENGLES
)
1482 goto invalid_enum_error
;
1485 return (texUnit
->TexGenEnabled
& STR_BITS
) == STR_BITS
1486 ? GL_TRUE
: GL_FALSE
;
1490 /* client-side state */
1491 case GL_VERTEX_ARRAY
:
1492 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1493 goto invalid_enum_error
;
1494 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
;
1495 case GL_NORMAL_ARRAY
:
1496 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1497 goto invalid_enum_error
;
1498 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
;
1499 case GL_COLOR_ARRAY
:
1500 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1501 goto invalid_enum_error
;
1502 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
;
1503 case GL_INDEX_ARRAY
:
1504 if (ctx
->API
!= API_OPENGL_COMPAT
)
1505 goto invalid_enum_error
;
1506 return ctx
->Array
.VAO
->
1507 VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
;
1508 case GL_TEXTURE_COORD_ARRAY
:
1509 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1510 goto invalid_enum_error
;
1511 return ctx
->Array
.VAO
->
1512 VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Enabled
;
1513 case GL_EDGE_FLAG_ARRAY
:
1514 if (ctx
->API
!= API_OPENGL_COMPAT
)
1515 goto invalid_enum_error
;
1516 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
;
1517 case GL_FOG_COORDINATE_ARRAY_EXT
:
1518 if (ctx
->API
!= API_OPENGL_COMPAT
)
1519 goto invalid_enum_error
;
1520 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
;
1521 case GL_SECONDARY_COLOR_ARRAY_EXT
:
1522 if (ctx
->API
!= API_OPENGL_COMPAT
)
1523 goto invalid_enum_error
;
1524 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
;
1525 case GL_POINT_SIZE_ARRAY_OES
:
1526 if (ctx
->API
!= API_OPENGLES
)
1527 goto invalid_enum_error
;
1528 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
;
1530 /* GL_ARB_texture_cube_map */
1531 case GL_TEXTURE_CUBE_MAP
:
1532 CHECK_EXTENSION(ARB_texture_cube_map
);
1533 return is_texture_enabled(ctx
, TEXTURE_CUBE_BIT
);
1535 /* GL_EXT_secondary_color */
1536 case GL_COLOR_SUM_EXT
:
1537 if (ctx
->API
!= API_OPENGL_COMPAT
)
1538 goto invalid_enum_error
;
1539 return ctx
->Fog
.ColorSumEnabled
;
1541 /* GL_ARB_multisample */
1542 case GL_MULTISAMPLE_ARB
:
1543 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1544 goto invalid_enum_error
;
1545 return ctx
->Multisample
.Enabled
;
1546 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
1547 return ctx
->Multisample
.SampleAlphaToCoverage
;
1548 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
1549 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1550 goto invalid_enum_error
;
1551 return ctx
->Multisample
.SampleAlphaToOne
;
1552 case GL_SAMPLE_COVERAGE_ARB
:
1553 return ctx
->Multisample
.SampleCoverage
;
1554 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
1555 if (!_mesa_is_desktop_gl(ctx
))
1556 goto invalid_enum_error
;
1557 return ctx
->Multisample
.SampleCoverageInvert
;
1559 /* GL_IBM_rasterpos_clip */
1560 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
1561 if (ctx
->API
!= API_OPENGL_COMPAT
)
1562 goto invalid_enum_error
;
1563 return ctx
->Transform
.RasterPositionUnclipped
;
1565 /* GL_NV_point_sprite */
1566 case GL_POINT_SPRITE_NV
:
1567 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1568 goto invalid_enum_error
;
1569 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
)
1570 return ctx
->Point
.PointSprite
;
1572 case GL_VERTEX_PROGRAM_ARB
:
1573 if (ctx
->API
!= API_OPENGL_COMPAT
)
1574 goto invalid_enum_error
;
1575 CHECK_EXTENSION(ARB_vertex_program
);
1576 return ctx
->VertexProgram
.Enabled
;
1577 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
1578 /* This was added with ARB_vertex_program, but it is also used with
1579 * GLSL vertex shaders on desktop.
1581 if (!_mesa_is_desktop_gl(ctx
))
1582 goto invalid_enum_error
;
1583 CHECK_EXTENSION(ARB_vertex_program
);
1584 return ctx
->VertexProgram
.PointSizeEnabled
;
1585 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
1586 if (ctx
->API
!= API_OPENGL_COMPAT
)
1587 goto invalid_enum_error
;
1588 CHECK_EXTENSION(ARB_vertex_program
);
1589 return ctx
->VertexProgram
.TwoSideEnabled
;
1591 /* GL_NV_texture_rectangle */
1592 case GL_TEXTURE_RECTANGLE_NV
:
1593 if (ctx
->API
!= API_OPENGL_COMPAT
)
1594 goto invalid_enum_error
;
1595 CHECK_EXTENSION(NV_texture_rectangle
);
1596 return is_texture_enabled(ctx
, TEXTURE_RECT_BIT
);
1598 /* GL_EXT_stencil_two_side */
1599 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
1600 if (ctx
->API
!= API_OPENGL_COMPAT
)
1601 goto invalid_enum_error
;
1602 CHECK_EXTENSION(EXT_stencil_two_side
);
1603 return ctx
->Stencil
.TestTwoSide
;
1605 case GL_FRAGMENT_PROGRAM_ARB
:
1606 if (ctx
->API
!= API_OPENGL_COMPAT
)
1607 goto invalid_enum_error
;
1608 return ctx
->FragmentProgram
.Enabled
;
1610 /* GL_EXT_depth_bounds_test */
1611 case GL_DEPTH_BOUNDS_TEST_EXT
:
1612 if (!_mesa_is_desktop_gl(ctx
))
1613 goto invalid_enum_error
;
1614 CHECK_EXTENSION(EXT_depth_bounds_test
);
1615 return ctx
->Depth
.BoundsTest
;
1617 /* GL_ARB_depth_clamp */
1618 case GL_DEPTH_CLAMP
:
1619 if (!_mesa_is_desktop_gl(ctx
))
1620 goto invalid_enum_error
;
1621 CHECK_EXTENSION(ARB_depth_clamp
);
1622 return ctx
->Transform
.DepthClamp
;
1624 case GL_FRAGMENT_SHADER_ATI
:
1625 if (ctx
->API
!= API_OPENGL_COMPAT
)
1626 goto invalid_enum_error
;
1627 CHECK_EXTENSION(ATI_fragment_shader
);
1628 return ctx
->ATIFragmentShader
.Enabled
;
1630 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1631 if (!_mesa_is_desktop_gl(ctx
))
1632 goto invalid_enum_error
;
1633 CHECK_EXTENSION(ARB_seamless_cube_map
);
1634 return ctx
->Texture
.CubeMapSeamless
;
1636 case GL_RASTERIZER_DISCARD
:
1637 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1638 goto invalid_enum_error
;
1639 CHECK_EXTENSION(EXT_transform_feedback
);
1640 return ctx
->RasterDiscard
;
1642 /* GL_NV_primitive_restart */
1643 case GL_PRIMITIVE_RESTART_NV
:
1644 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.NV_primitive_restart
) {
1645 goto invalid_enum_error
;
1647 return ctx
->Array
.PrimitiveRestart
;
1649 /* GL 3.1 primitive restart */
1650 case GL_PRIMITIVE_RESTART
:
1651 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
1652 goto invalid_enum_error
;
1654 return ctx
->Array
.PrimitiveRestart
;
1656 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
1657 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
) {
1658 goto invalid_enum_error
;
1660 return ctx
->Array
.PrimitiveRestartFixedIndex
;
1662 /* GL3.0 - GL_framebuffer_sRGB */
1663 case GL_FRAMEBUFFER_SRGB_EXT
:
1664 if (!_mesa_is_desktop_gl(ctx
))
1665 goto invalid_enum_error
;
1666 CHECK_EXTENSION(EXT_framebuffer_sRGB
);
1667 return ctx
->Color
.sRGBEnabled
;
1669 /* GL_OES_EGL_image_external */
1670 case GL_TEXTURE_EXTERNAL_OES
:
1671 if (!_mesa_is_gles(ctx
))
1672 goto invalid_enum_error
;
1673 CHECK_EXTENSION(OES_EGL_image_external
);
1674 return is_texture_enabled(ctx
, TEXTURE_EXTERNAL_BIT
);
1676 /* ARB_texture_multisample */
1677 case GL_SAMPLE_MASK
:
1678 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
1679 goto invalid_enum_error
;
1680 CHECK_EXTENSION(ARB_texture_multisample
);
1681 return ctx
->Multisample
.SampleMask
;
1683 /* ARB_sample_shading */
1684 case GL_SAMPLE_SHADING
:
1685 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1686 goto invalid_enum_error
;
1687 CHECK_EXTENSION(ARB_sample_shading
);
1688 return ctx
->Multisample
.SampleShading
;
1690 case GL_BLEND_ADVANCED_COHERENT_KHR
:
1691 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent
);
1692 return ctx
->Color
.BlendCoherent
;
1694 case GL_CONSERVATIVE_RASTERIZATION_INTEL
:
1695 CHECK_EXTENSION(INTEL_conservative_rasterization
);
1696 return ctx
->IntelConservativeRasterization
;
1699 goto invalid_enum_error
;
1705 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabled(%s)",
1706 _mesa_enum_to_string(cap
));