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.
36 #include "simple_list.h"
39 #include "api_arrayelt.h"
41 #include "drivers/common/meta.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_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
72 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
;
76 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
;
77 flag
= VERT_BIT_NORMAL
;
80 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
;
81 flag
= VERT_BIT_COLOR0
;
84 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
;
85 flag
= VERT_BIT_COLOR_INDEX
;
87 case GL_TEXTURE_COORD_ARRAY
:
88 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Enabled
;
89 flag
= VERT_BIT_TEX(ctx
->Array
.ActiveTexture
);
91 case GL_EDGE_FLAG_ARRAY
:
92 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
;
93 flag
= VERT_BIT_EDGEFLAG
;
95 case GL_FOG_COORDINATE_ARRAY_EXT
:
96 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
;
99 case GL_SECONDARY_COLOR_ARRAY_EXT
:
100 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
;
101 flag
= VERT_BIT_COLOR1
;
104 case GL_POINT_SIZE_ARRAY_OES
:
105 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
;
106 flag
= VERT_BIT_POINT_SIZE
;
109 /* GL_NV_primitive_restart */
110 case GL_PRIMITIVE_RESTART_NV
:
111 if (!ctx
->Extensions
.NV_primitive_restart
) {
112 goto invalid_enum_error
;
114 var
= &ctx
->Array
.PrimitiveRestart
;
119 goto invalid_enum_error
;
125 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
127 _ae_invalidate_state(ctx
, _NEW_ARRAY
);
131 update_derived_primitive_restart_state(ctx
);
134 arrayObj
->_Enabled
|= flag
;
136 arrayObj
->_Enabled
&= ~flag
;
138 if (ctx
->Driver
.Enable
) {
139 ctx
->Driver
.Enable( ctx
, cap
, state
);
145 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%sClientState(%s)",
146 state
? "Enable" : "Disable", _mesa_lookup_enum_by_nr(cap
));
151 * Enable GL capability.
152 * \param cap state to enable/disable.
154 * Get's the current context, assures that we're outside glBegin()/glEnd() and
155 * calls client_state().
158 _mesa_EnableClientState( GLenum cap
)
160 GET_CURRENT_CONTEXT(ctx
);
161 client_state( ctx
, cap
, GL_TRUE
);
166 * Disable GL capability.
167 * \param cap state to enable/disable.
169 * Get's the current context, assures that we're outside glBegin()/glEnd() and
170 * calls client_state().
173 _mesa_DisableClientState( GLenum cap
)
175 GET_CURRENT_CONTEXT(ctx
);
176 client_state( ctx
, cap
, GL_FALSE
);
180 #undef CHECK_EXTENSION
181 #define CHECK_EXTENSION(EXTNAME, CAP) \
182 if (!ctx->Extensions.EXTNAME) { \
183 goto invalid_enum_error; \
186 #define CHECK_EXTENSION2(EXT1, EXT2, CAP) \
187 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
188 goto invalid_enum_error; \
192 * Return pointer to current texture unit for setting/getting coordinate
194 * Note that we'll set GL_INVALID_OPERATION and return NULL if the active
195 * texture unit is higher than the number of supported coordinate units.
197 static struct gl_texture_unit
*
198 get_texcoord_unit(struct gl_context
*ctx
)
200 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
201 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glEnable/Disable(texcoord unit)");
205 return &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
211 * Helper function to enable or disable a texture target.
212 * \param bit one of the TEXTURE_x_BIT values
213 * \return GL_TRUE if state is changing or GL_FALSE if no change
216 enable_texture(struct gl_context
*ctx
, GLboolean state
, GLbitfield texBit
)
218 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
219 const GLbitfield newenabled
= state
220 ? (texUnit
->Enabled
| texBit
) : (texUnit
->Enabled
& ~texBit
);
222 if (texUnit
->Enabled
== newenabled
)
225 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
226 texUnit
->Enabled
= newenabled
;
232 * Helper function to enable or disable GL_MULTISAMPLE, skipping the check for
233 * whether the API supports it (GLES doesn't).
236 _mesa_set_multisample(struct gl_context
*ctx
, GLboolean state
)
238 if (ctx
->Multisample
.Enabled
== state
)
240 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
241 ctx
->Multisample
.Enabled
= state
;
243 if (ctx
->Driver
.Enable
) {
244 ctx
->Driver
.Enable(ctx
, GL_MULTISAMPLE
, state
);
249 * Helper function to enable or disable GL_FRAMEBUFFER_SRGB, skipping the
250 * check for whether the API supports it (GLES doesn't).
253 _mesa_set_framebuffer_srgb(struct gl_context
*ctx
, GLboolean state
)
255 if (ctx
->Color
.sRGBEnabled
== state
)
257 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
258 ctx
->Color
.sRGBEnabled
= state
;
260 if (ctx
->Driver
.Enable
) {
261 ctx
->Driver
.Enable(ctx
, GL_FRAMEBUFFER_SRGB
, state
);
266 * Helper function to enable or disable state.
268 * \param ctx GL context.
269 * \param cap the state to enable/disable
270 * \param state whether to enable or disable the specified capability.
272 * Updates the current context and flushes the vertices as needed. For
273 * capabilities associated with extensions it verifies that those extensions
274 * are effectivly present before updating. Notifies the driver via
275 * dd_function_table::Enable.
278 _mesa_set_enable(struct gl_context
*ctx
, GLenum cap
, GLboolean state
)
280 if (MESA_VERBOSE
& VERBOSE_API
)
281 _mesa_debug(ctx
, "%s %s (newstate is %x)\n",
282 state
? "glEnable" : "glDisable",
283 _mesa_lookup_enum_by_nr(cap
),
288 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
289 goto invalid_enum_error
;
290 if (ctx
->Color
.AlphaEnabled
== state
)
292 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
293 ctx
->Color
.AlphaEnabled
= state
;
296 if (ctx
->API
!= API_OPENGL_COMPAT
)
297 goto invalid_enum_error
;
298 if (ctx
->Eval
.AutoNormal
== state
)
300 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
301 ctx
->Eval
.AutoNormal
= state
;
305 GLbitfield newEnabled
=
306 state
* ((1 << ctx
->Const
.MaxDrawBuffers
) - 1);
307 if (newEnabled
!= ctx
->Color
.BlendEnabled
) {
308 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
309 ctx
->Color
.BlendEnabled
= newEnabled
;
313 case GL_CLIP_DISTANCE0
:
314 case GL_CLIP_DISTANCE1
:
315 case GL_CLIP_DISTANCE2
:
316 case GL_CLIP_DISTANCE3
:
317 case GL_CLIP_DISTANCE4
:
318 case GL_CLIP_DISTANCE5
:
319 case GL_CLIP_DISTANCE6
:
320 case GL_CLIP_DISTANCE7
:
322 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
324 if (p
>= ctx
->Const
.MaxClipPlanes
)
325 goto invalid_enum_error
;
327 if ((ctx
->Transform
.ClipPlanesEnabled
& (1 << p
))
328 == ((GLuint
) state
<< p
))
331 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
334 ctx
->Transform
.ClipPlanesEnabled
|= (1 << p
);
335 _mesa_update_clip_plane(ctx
, p
);
338 ctx
->Transform
.ClipPlanesEnabled
&= ~(1 << p
);
342 case GL_COLOR_MATERIAL
:
343 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
344 goto invalid_enum_error
;
345 if (ctx
->Light
.ColorMaterialEnabled
== state
)
347 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
348 FLUSH_CURRENT(ctx
, 0);
349 ctx
->Light
.ColorMaterialEnabled
= state
;
351 _mesa_update_color_material( ctx
,
352 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
] );
356 if (ctx
->Polygon
.CullFlag
== state
)
358 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
359 ctx
->Polygon
.CullFlag
= state
;
362 if (ctx
->Depth
.Test
== state
)
364 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
365 ctx
->Depth
.Test
= state
;
367 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
:
368 if (!_mesa_is_desktop_gl(ctx
))
369 goto invalid_enum_error
;
370 ctx
->Debug
.SyncOutput
= state
;
373 if (ctx
->Color
.DitherFlag
== state
)
375 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
376 ctx
->Color
.DitherFlag
= state
;
379 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
380 goto invalid_enum_error
;
381 if (ctx
->Fog
.Enabled
== state
)
383 FLUSH_VERTICES(ctx
, _NEW_FOG
);
384 ctx
->Fog
.Enabled
= state
;
394 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
395 goto invalid_enum_error
;
396 if (ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
== state
)
398 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
399 ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
= state
;
401 insert_at_tail(&ctx
->Light
.EnabledList
,
402 &ctx
->Light
.Light
[cap
-GL_LIGHT0
]);
405 remove_from_list(&ctx
->Light
.Light
[cap
-GL_LIGHT0
]);
409 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
410 goto invalid_enum_error
;
411 if (ctx
->Light
.Enabled
== state
)
413 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
414 ctx
->Light
.Enabled
= state
;
417 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
418 goto invalid_enum_error
;
419 if (ctx
->Line
.SmoothFlag
== state
)
421 FLUSH_VERTICES(ctx
, _NEW_LINE
);
422 ctx
->Line
.SmoothFlag
= state
;
424 case GL_LINE_STIPPLE
:
425 if (ctx
->API
!= API_OPENGL_COMPAT
)
426 goto invalid_enum_error
;
427 if (ctx
->Line
.StippleFlag
== state
)
429 FLUSH_VERTICES(ctx
, _NEW_LINE
);
430 ctx
->Line
.StippleFlag
= state
;
432 case GL_INDEX_LOGIC_OP
:
433 if (ctx
->API
!= API_OPENGL_COMPAT
)
434 goto invalid_enum_error
;
435 if (ctx
->Color
.IndexLogicOpEnabled
== state
)
437 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
438 ctx
->Color
.IndexLogicOpEnabled
= state
;
440 case GL_COLOR_LOGIC_OP
:
441 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
442 goto invalid_enum_error
;
443 if (ctx
->Color
.ColorLogicOpEnabled
== state
)
445 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
446 ctx
->Color
.ColorLogicOpEnabled
= state
;
448 case GL_MAP1_COLOR_4
:
449 if (ctx
->API
!= API_OPENGL_COMPAT
)
450 goto invalid_enum_error
;
451 if (ctx
->Eval
.Map1Color4
== state
)
453 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
454 ctx
->Eval
.Map1Color4
= state
;
457 if (ctx
->API
!= API_OPENGL_COMPAT
)
458 goto invalid_enum_error
;
459 if (ctx
->Eval
.Map1Index
== state
)
461 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
462 ctx
->Eval
.Map1Index
= state
;
465 if (ctx
->API
!= API_OPENGL_COMPAT
)
466 goto invalid_enum_error
;
467 if (ctx
->Eval
.Map1Normal
== state
)
469 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
470 ctx
->Eval
.Map1Normal
= state
;
472 case GL_MAP1_TEXTURE_COORD_1
:
473 if (ctx
->API
!= API_OPENGL_COMPAT
)
474 goto invalid_enum_error
;
475 if (ctx
->Eval
.Map1TextureCoord1
== state
)
477 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
478 ctx
->Eval
.Map1TextureCoord1
= state
;
480 case GL_MAP1_TEXTURE_COORD_2
:
481 if (ctx
->API
!= API_OPENGL_COMPAT
)
482 goto invalid_enum_error
;
483 if (ctx
->Eval
.Map1TextureCoord2
== state
)
485 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
486 ctx
->Eval
.Map1TextureCoord2
= state
;
488 case GL_MAP1_TEXTURE_COORD_3
:
489 if (ctx
->API
!= API_OPENGL_COMPAT
)
490 goto invalid_enum_error
;
491 if (ctx
->Eval
.Map1TextureCoord3
== state
)
493 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
494 ctx
->Eval
.Map1TextureCoord3
= state
;
496 case GL_MAP1_TEXTURE_COORD_4
:
497 if (ctx
->API
!= API_OPENGL_COMPAT
)
498 goto invalid_enum_error
;
499 if (ctx
->Eval
.Map1TextureCoord4
== state
)
501 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
502 ctx
->Eval
.Map1TextureCoord4
= state
;
504 case GL_MAP1_VERTEX_3
:
505 if (ctx
->API
!= API_OPENGL_COMPAT
)
506 goto invalid_enum_error
;
507 if (ctx
->Eval
.Map1Vertex3
== state
)
509 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
510 ctx
->Eval
.Map1Vertex3
= state
;
512 case GL_MAP1_VERTEX_4
:
513 if (ctx
->API
!= API_OPENGL_COMPAT
)
514 goto invalid_enum_error
;
515 if (ctx
->Eval
.Map1Vertex4
== state
)
517 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
518 ctx
->Eval
.Map1Vertex4
= state
;
520 case GL_MAP2_COLOR_4
:
521 if (ctx
->API
!= API_OPENGL_COMPAT
)
522 goto invalid_enum_error
;
523 if (ctx
->Eval
.Map2Color4
== state
)
525 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
526 ctx
->Eval
.Map2Color4
= state
;
529 if (ctx
->API
!= API_OPENGL_COMPAT
)
530 goto invalid_enum_error
;
531 if (ctx
->Eval
.Map2Index
== state
)
533 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
534 ctx
->Eval
.Map2Index
= state
;
537 if (ctx
->API
!= API_OPENGL_COMPAT
)
538 goto invalid_enum_error
;
539 if (ctx
->Eval
.Map2Normal
== state
)
541 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
542 ctx
->Eval
.Map2Normal
= state
;
544 case GL_MAP2_TEXTURE_COORD_1
:
545 if (ctx
->API
!= API_OPENGL_COMPAT
)
546 goto invalid_enum_error
;
547 if (ctx
->Eval
.Map2TextureCoord1
== state
)
549 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
550 ctx
->Eval
.Map2TextureCoord1
= state
;
552 case GL_MAP2_TEXTURE_COORD_2
:
553 if (ctx
->API
!= API_OPENGL_COMPAT
)
554 goto invalid_enum_error
;
555 if (ctx
->Eval
.Map2TextureCoord2
== state
)
557 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
558 ctx
->Eval
.Map2TextureCoord2
= state
;
560 case GL_MAP2_TEXTURE_COORD_3
:
561 if (ctx
->API
!= API_OPENGL_COMPAT
)
562 goto invalid_enum_error
;
563 if (ctx
->Eval
.Map2TextureCoord3
== state
)
565 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
566 ctx
->Eval
.Map2TextureCoord3
= state
;
568 case GL_MAP2_TEXTURE_COORD_4
:
569 if (ctx
->API
!= API_OPENGL_COMPAT
)
570 goto invalid_enum_error
;
571 if (ctx
->Eval
.Map2TextureCoord4
== state
)
573 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
574 ctx
->Eval
.Map2TextureCoord4
= state
;
576 case GL_MAP2_VERTEX_3
:
577 if (ctx
->API
!= API_OPENGL_COMPAT
)
578 goto invalid_enum_error
;
579 if (ctx
->Eval
.Map2Vertex3
== state
)
581 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
582 ctx
->Eval
.Map2Vertex3
= state
;
584 case GL_MAP2_VERTEX_4
:
585 if (ctx
->API
!= API_OPENGL_COMPAT
)
586 goto invalid_enum_error
;
587 if (ctx
->Eval
.Map2Vertex4
== state
)
589 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
590 ctx
->Eval
.Map2Vertex4
= state
;
593 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
594 goto invalid_enum_error
;
595 if (ctx
->Transform
.Normalize
== state
)
597 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
598 ctx
->Transform
.Normalize
= state
;
600 case GL_POINT_SMOOTH
:
601 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
602 goto invalid_enum_error
;
603 if (ctx
->Point
.SmoothFlag
== state
)
605 FLUSH_VERTICES(ctx
, _NEW_POINT
);
606 ctx
->Point
.SmoothFlag
= state
;
608 case GL_POLYGON_SMOOTH
:
609 if (!_mesa_is_desktop_gl(ctx
))
610 goto invalid_enum_error
;
611 if (ctx
->Polygon
.SmoothFlag
== state
)
613 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
614 ctx
->Polygon
.SmoothFlag
= state
;
616 case GL_POLYGON_STIPPLE
:
617 if (ctx
->API
!= API_OPENGL_COMPAT
)
618 goto invalid_enum_error
;
619 if (ctx
->Polygon
.StippleFlag
== state
)
621 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
622 ctx
->Polygon
.StippleFlag
= state
;
624 case GL_POLYGON_OFFSET_POINT
:
625 if (!_mesa_is_desktop_gl(ctx
))
626 goto invalid_enum_error
;
627 if (ctx
->Polygon
.OffsetPoint
== state
)
629 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
630 ctx
->Polygon
.OffsetPoint
= state
;
632 case GL_POLYGON_OFFSET_LINE
:
633 if (!_mesa_is_desktop_gl(ctx
))
634 goto invalid_enum_error
;
635 if (ctx
->Polygon
.OffsetLine
== state
)
637 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
638 ctx
->Polygon
.OffsetLine
= state
;
640 case GL_POLYGON_OFFSET_FILL
:
641 if (ctx
->Polygon
.OffsetFill
== state
)
643 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
644 ctx
->Polygon
.OffsetFill
= state
;
646 case GL_RESCALE_NORMAL_EXT
:
647 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
648 goto invalid_enum_error
;
649 if (ctx
->Transform
.RescaleNormals
== state
)
651 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
652 ctx
->Transform
.RescaleNormals
= state
;
654 case GL_SCISSOR_TEST
:
655 if (ctx
->Scissor
.Enabled
== state
)
657 FLUSH_VERTICES(ctx
, _NEW_SCISSOR
);
658 ctx
->Scissor
.Enabled
= state
;
660 case GL_STENCIL_TEST
:
661 if (ctx
->Stencil
.Enabled
== state
)
663 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
664 ctx
->Stencil
.Enabled
= state
;
667 if (ctx
->API
!= API_OPENGL_COMPAT
)
668 goto invalid_enum_error
;
669 if (!enable_texture(ctx
, state
, TEXTURE_1D_BIT
)) {
674 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
675 goto invalid_enum_error
;
676 if (!enable_texture(ctx
, state
, TEXTURE_2D_BIT
)) {
681 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
682 goto invalid_enum_error
;
683 if (!enable_texture(ctx
, state
, TEXTURE_3D_BIT
)) {
687 case GL_TEXTURE_GEN_S
:
688 case GL_TEXTURE_GEN_T
:
689 case GL_TEXTURE_GEN_R
:
690 case GL_TEXTURE_GEN_Q
:
692 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
694 if (ctx
->API
!= API_OPENGL_COMPAT
)
695 goto invalid_enum_error
;
698 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
699 GLbitfield newenabled
= texUnit
->TexGenEnabled
& ~coordBit
;
701 newenabled
|= coordBit
;
702 if (texUnit
->TexGenEnabled
== newenabled
)
704 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
705 texUnit
->TexGenEnabled
= newenabled
;
710 case GL_TEXTURE_GEN_STR_OES
:
711 /* disable S, T, and R at the same time */
713 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
715 if (ctx
->API
!= API_OPENGLES
)
716 goto invalid_enum_error
;
720 texUnit
->TexGenEnabled
& ~STR_BITS
;
722 newenabled
|= STR_BITS
;
723 if (texUnit
->TexGenEnabled
== newenabled
)
725 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
726 texUnit
->TexGenEnabled
= newenabled
;
731 /* client-side state */
732 case GL_VERTEX_ARRAY
:
733 case GL_NORMAL_ARRAY
:
736 case GL_TEXTURE_COORD_ARRAY
:
737 case GL_EDGE_FLAG_ARRAY
:
738 case GL_FOG_COORDINATE_ARRAY_EXT
:
739 case GL_SECONDARY_COLOR_ARRAY_EXT
:
740 case GL_POINT_SIZE_ARRAY_OES
:
741 client_state( ctx
, cap
, state
);
744 /* GL_ARB_texture_cube_map */
745 case GL_TEXTURE_CUBE_MAP_ARB
:
746 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
747 goto invalid_enum_error
;
748 CHECK_EXTENSION(ARB_texture_cube_map
, cap
);
749 if (!enable_texture(ctx
, state
, TEXTURE_CUBE_BIT
)) {
754 /* GL_EXT_secondary_color */
755 case GL_COLOR_SUM_EXT
:
756 if (ctx
->API
!= API_OPENGL_COMPAT
)
757 goto invalid_enum_error
;
758 CHECK_EXTENSION2(EXT_secondary_color
, ARB_vertex_program
, cap
);
759 if (ctx
->Fog
.ColorSumEnabled
== state
)
761 FLUSH_VERTICES(ctx
, _NEW_FOG
);
762 ctx
->Fog
.ColorSumEnabled
= state
;
765 /* GL_ARB_multisample */
766 case GL_MULTISAMPLE_ARB
:
767 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
768 goto invalid_enum_error
;
769 _mesa_set_multisample(ctx
, state
);
771 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
772 if (ctx
->Multisample
.SampleAlphaToCoverage
== state
)
774 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
775 ctx
->Multisample
.SampleAlphaToCoverage
= state
;
777 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
778 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
779 goto invalid_enum_error
;
780 if (ctx
->Multisample
.SampleAlphaToOne
== state
)
782 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
783 ctx
->Multisample
.SampleAlphaToOne
= state
;
785 case GL_SAMPLE_COVERAGE_ARB
:
786 if (ctx
->Multisample
.SampleCoverage
== state
)
788 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
789 ctx
->Multisample
.SampleCoverage
= state
;
791 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
792 if (!_mesa_is_desktop_gl(ctx
))
793 goto invalid_enum_error
;
794 if (ctx
->Multisample
.SampleCoverageInvert
== state
)
796 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
797 ctx
->Multisample
.SampleCoverageInvert
= state
;
800 /* GL_IBM_rasterpos_clip */
801 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
802 if (ctx
->API
!= API_OPENGL_COMPAT
)
803 goto invalid_enum_error
;
804 if (ctx
->Transform
.RasterPositionUnclipped
== state
)
806 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
807 ctx
->Transform
.RasterPositionUnclipped
= state
;
810 /* GL_NV_point_sprite */
811 case GL_POINT_SPRITE_NV
:
812 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
813 goto invalid_enum_error
;
814 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
, cap
);
815 if (ctx
->Point
.PointSprite
== state
)
817 FLUSH_VERTICES(ctx
, _NEW_POINT
);
818 ctx
->Point
.PointSprite
= state
;
821 case GL_VERTEX_PROGRAM_ARB
:
822 if (ctx
->API
!= API_OPENGL_COMPAT
)
823 goto invalid_enum_error
;
824 CHECK_EXTENSION(ARB_vertex_program
, cap
);
825 if (ctx
->VertexProgram
.Enabled
== state
)
827 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
828 ctx
->VertexProgram
.Enabled
= state
;
830 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
831 /* This was added with ARB_vertex_program, but it is also used with
832 * GLSL vertex shaders on desktop.
834 if (!_mesa_is_desktop_gl(ctx
))
835 goto invalid_enum_error
;
836 CHECK_EXTENSION(ARB_vertex_program
, cap
);
837 if (ctx
->VertexProgram
.PointSizeEnabled
== state
)
839 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
840 ctx
->VertexProgram
.PointSizeEnabled
= state
;
842 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
843 if (ctx
->API
!= API_OPENGL_COMPAT
)
844 goto invalid_enum_error
;
845 CHECK_EXTENSION(ARB_vertex_program
, cap
);
846 if (ctx
->VertexProgram
.TwoSideEnabled
== state
)
848 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
849 ctx
->VertexProgram
.TwoSideEnabled
= state
;
852 /* GL_NV_texture_rectangle */
853 case GL_TEXTURE_RECTANGLE_NV
:
854 if (ctx
->API
!= API_OPENGL_COMPAT
)
855 goto invalid_enum_error
;
856 CHECK_EXTENSION(NV_texture_rectangle
, cap
);
857 if (!enable_texture(ctx
, state
, TEXTURE_RECT_BIT
)) {
862 /* GL_EXT_stencil_two_side */
863 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
864 if (ctx
->API
!= API_OPENGL_COMPAT
)
865 goto invalid_enum_error
;
866 CHECK_EXTENSION(EXT_stencil_two_side
, cap
);
867 if (ctx
->Stencil
.TestTwoSide
== state
)
869 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
870 ctx
->Stencil
.TestTwoSide
= state
;
872 ctx
->Stencil
._BackFace
= 2;
874 ctx
->Stencil
._BackFace
= 1;
878 case GL_FRAGMENT_PROGRAM_ARB
:
879 if (ctx
->API
!= API_OPENGL_COMPAT
)
880 goto invalid_enum_error
;
881 CHECK_EXTENSION(ARB_fragment_program
, cap
);
882 if (ctx
->FragmentProgram
.Enabled
== state
)
884 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
885 ctx
->FragmentProgram
.Enabled
= state
;
888 /* GL_EXT_depth_bounds_test */
889 case GL_DEPTH_BOUNDS_TEST_EXT
:
890 if (!_mesa_is_desktop_gl(ctx
))
891 goto invalid_enum_error
;
892 CHECK_EXTENSION(EXT_depth_bounds_test
, cap
);
893 if (ctx
->Depth
.BoundsTest
== state
)
895 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
896 ctx
->Depth
.BoundsTest
= state
;
900 if (!_mesa_is_desktop_gl(ctx
))
901 goto invalid_enum_error
;
902 CHECK_EXTENSION(ARB_depth_clamp
, cap
);
903 if (ctx
->Transform
.DepthClamp
== state
)
905 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
906 ctx
->Transform
.DepthClamp
= state
;
909 case GL_FRAGMENT_SHADER_ATI
:
910 if (ctx
->API
!= API_OPENGL_COMPAT
)
911 goto invalid_enum_error
;
912 CHECK_EXTENSION(ATI_fragment_shader
, cap
);
913 if (ctx
->ATIFragmentShader
.Enabled
== state
)
915 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
916 ctx
->ATIFragmentShader
.Enabled
= state
;
919 /* GL_MESA_texture_array */
920 case GL_TEXTURE_1D_ARRAY_EXT
:
921 if (ctx
->API
!= API_OPENGL_COMPAT
)
922 goto invalid_enum_error
;
923 CHECK_EXTENSION(MESA_texture_array
, cap
);
924 if (!enable_texture(ctx
, state
, TEXTURE_1D_ARRAY_BIT
)) {
929 case GL_TEXTURE_2D_ARRAY_EXT
:
930 if (ctx
->API
!= API_OPENGL_COMPAT
)
931 goto invalid_enum_error
;
932 CHECK_EXTENSION(MESA_texture_array
, cap
);
933 if (!enable_texture(ctx
, state
, TEXTURE_2D_ARRAY_BIT
)) {
938 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
939 if (!_mesa_is_desktop_gl(ctx
))
940 goto invalid_enum_error
;
941 CHECK_EXTENSION(ARB_seamless_cube_map
, cap
);
942 if (ctx
->Texture
.CubeMapSeamless
!= state
) {
943 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
944 ctx
->Texture
.CubeMapSeamless
= state
;
948 case GL_RASTERIZER_DISCARD
:
949 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
950 goto invalid_enum_error
;
951 CHECK_EXTENSION(EXT_transform_feedback
, cap
);
952 if (ctx
->RasterDiscard
!= state
) {
953 FLUSH_VERTICES(ctx
, 0);
954 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewRasterizerDiscard
;
955 ctx
->RasterDiscard
= state
;
959 /* GL 3.1 primitive restart. Note: this enum is different from
960 * GL_PRIMITIVE_RESTART_NV (which is client state).
962 case GL_PRIMITIVE_RESTART
:
963 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
964 goto invalid_enum_error
;
966 if (ctx
->Array
.PrimitiveRestart
!= state
) {
967 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
968 ctx
->Array
.PrimitiveRestart
= state
;
969 update_derived_primitive_restart_state(ctx
);
973 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
974 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
)
975 goto invalid_enum_error
;
976 if (ctx
->Array
.PrimitiveRestartFixedIndex
!= state
) {
977 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
978 ctx
->Array
.PrimitiveRestartFixedIndex
= state
;
979 update_derived_primitive_restart_state(ctx
);
983 /* GL3.0 - GL_framebuffer_sRGB */
984 case GL_FRAMEBUFFER_SRGB_EXT
:
985 if (!_mesa_is_desktop_gl(ctx
))
986 goto invalid_enum_error
;
987 CHECK_EXTENSION(EXT_framebuffer_sRGB
, cap
);
988 _mesa_set_framebuffer_srgb(ctx
, state
);
991 /* GL_OES_EGL_image_external */
992 case GL_TEXTURE_EXTERNAL_OES
:
993 if (!_mesa_is_gles(ctx
))
994 goto invalid_enum_error
;
995 CHECK_EXTENSION(OES_EGL_image_external
, cap
);
996 if (!enable_texture(ctx
, state
, TEXTURE_EXTERNAL_BIT
)) {
1001 /* ARB_texture_multisample */
1002 case GL_SAMPLE_MASK
:
1003 if (!_mesa_is_desktop_gl(ctx
))
1004 goto invalid_enum_error
;
1005 CHECK_EXTENSION(ARB_texture_multisample
, cap
);
1006 if (ctx
->Multisample
.SampleMask
== state
)
1008 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
1009 ctx
->Multisample
.SampleMask
= state
;
1013 goto invalid_enum_error
;
1016 if (ctx
->Driver
.Enable
) {
1017 ctx
->Driver
.Enable( ctx
, cap
, state
);
1023 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%s(%s)",
1024 state
? "Enable" : "Disable", _mesa_lookup_enum_by_nr(cap
));
1029 * Enable GL capability. Called by glEnable()
1030 * \param cap state to enable.
1033 _mesa_Enable( GLenum cap
)
1035 GET_CURRENT_CONTEXT(ctx
);
1037 _mesa_set_enable( ctx
, cap
, GL_TRUE
);
1042 * Disable GL capability. Called by glDisable()
1043 * \param cap state to disable.
1046 _mesa_Disable( GLenum cap
)
1048 GET_CURRENT_CONTEXT(ctx
);
1050 _mesa_set_enable( ctx
, cap
, GL_FALSE
);
1056 * Enable/disable an indexed state var.
1059 _mesa_set_enablei(struct gl_context
*ctx
, GLenum cap
,
1060 GLuint index
, GLboolean state
)
1062 ASSERT(state
== 0 || state
== 1);
1065 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
1066 goto invalid_enum_error
;
1068 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1069 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1070 state
? "glEnableIndexed" : "glDisableIndexed", index
);
1073 if (((ctx
->Color
.BlendEnabled
>> index
) & 1) != state
) {
1074 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
1076 ctx
->Color
.BlendEnabled
|= (1 << index
);
1078 ctx
->Color
.BlendEnabled
&= ~(1 << index
);
1082 goto invalid_enum_error
;
1087 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(cap=%s)",
1088 state
? "glEnablei" : "glDisablei",
1089 _mesa_lookup_enum_by_nr(cap
));
1094 _mesa_Disablei( GLenum cap
, GLuint index
)
1096 GET_CURRENT_CONTEXT(ctx
);
1097 _mesa_set_enablei(ctx
, cap
, index
, GL_FALSE
);
1102 _mesa_Enablei( GLenum cap
, GLuint index
)
1104 GET_CURRENT_CONTEXT(ctx
);
1105 _mesa_set_enablei(ctx
, cap
, index
, GL_TRUE
);
1109 GLboolean GLAPIENTRY
1110 _mesa_IsEnabledi( GLenum cap
, GLuint index
)
1112 GET_CURRENT_CONTEXT(ctx
);
1113 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1116 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1117 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1121 return (ctx
->Color
.BlendEnabled
>> index
) & 1;
1123 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabledIndexed(cap=%s)",
1124 _mesa_lookup_enum_by_nr(cap
));
1132 #undef CHECK_EXTENSION
1133 #define CHECK_EXTENSION(EXTNAME) \
1134 if (!ctx->Extensions.EXTNAME) { \
1135 goto invalid_enum_error; \
1138 #undef CHECK_EXTENSION2
1139 #define CHECK_EXTENSION2(EXT1, EXT2) \
1140 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1141 goto invalid_enum_error; \
1146 * Helper function to determine whether a texture target is enabled.
1149 is_texture_enabled(struct gl_context
*ctx
, GLbitfield bit
)
1151 const struct gl_texture_unit
*const texUnit
=
1152 &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1153 return (texUnit
->Enabled
& bit
) ? GL_TRUE
: GL_FALSE
;
1158 * Return simple enable/disable state.
1160 * \param cap state variable to query.
1162 * Returns the state of the specified capability from the current GL context.
1163 * For the capabilities associated with extensions verifies that those
1164 * extensions are effectively present before reporting.
1166 GLboolean GLAPIENTRY
1167 _mesa_IsEnabled( GLenum cap
)
1169 GET_CURRENT_CONTEXT(ctx
);
1170 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1174 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1175 goto invalid_enum_error
;
1176 return ctx
->Color
.AlphaEnabled
;
1177 case GL_AUTO_NORMAL
:
1178 if (ctx
->API
!= API_OPENGL_COMPAT
)
1179 goto invalid_enum_error
;
1180 return ctx
->Eval
.AutoNormal
;
1182 return ctx
->Color
.BlendEnabled
& 1; /* return state for buffer[0] */
1183 case GL_CLIP_DISTANCE0
:
1184 case GL_CLIP_DISTANCE1
:
1185 case GL_CLIP_DISTANCE2
:
1186 case GL_CLIP_DISTANCE3
:
1187 case GL_CLIP_DISTANCE4
:
1188 case GL_CLIP_DISTANCE5
:
1189 case GL_CLIP_DISTANCE6
:
1190 case GL_CLIP_DISTANCE7
: {
1191 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
1193 if (p
>= ctx
->Const
.MaxClipPlanes
)
1194 goto invalid_enum_error
;
1196 return (ctx
->Transform
.ClipPlanesEnabled
>> p
) & 1;
1198 case GL_COLOR_MATERIAL
:
1199 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1200 goto invalid_enum_error
;
1201 return ctx
->Light
.ColorMaterialEnabled
;
1203 return ctx
->Polygon
.CullFlag
;
1204 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
:
1205 if (!_mesa_is_desktop_gl(ctx
))
1206 goto invalid_enum_error
;
1207 return ctx
->Debug
.SyncOutput
;
1209 return ctx
->Depth
.Test
;
1211 return ctx
->Color
.DitherFlag
;
1213 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1214 goto invalid_enum_error
;
1215 return ctx
->Fog
.Enabled
;
1217 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1218 goto invalid_enum_error
;
1219 return ctx
->Light
.Enabled
;
1228 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1229 goto invalid_enum_error
;
1230 return ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
;
1231 case GL_LINE_SMOOTH
:
1232 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1233 goto invalid_enum_error
;
1234 return ctx
->Line
.SmoothFlag
;
1235 case GL_LINE_STIPPLE
:
1236 if (ctx
->API
!= API_OPENGL_COMPAT
)
1237 goto invalid_enum_error
;
1238 return ctx
->Line
.StippleFlag
;
1239 case GL_INDEX_LOGIC_OP
:
1240 if (ctx
->API
!= API_OPENGL_COMPAT
)
1241 goto invalid_enum_error
;
1242 return ctx
->Color
.IndexLogicOpEnabled
;
1243 case GL_COLOR_LOGIC_OP
:
1244 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1245 goto invalid_enum_error
;
1246 return ctx
->Color
.ColorLogicOpEnabled
;
1247 case GL_MAP1_COLOR_4
:
1248 if (ctx
->API
!= API_OPENGL_COMPAT
)
1249 goto invalid_enum_error
;
1250 return ctx
->Eval
.Map1Color4
;
1252 if (ctx
->API
!= API_OPENGL_COMPAT
)
1253 goto invalid_enum_error
;
1254 return ctx
->Eval
.Map1Index
;
1255 case GL_MAP1_NORMAL
:
1256 if (ctx
->API
!= API_OPENGL_COMPAT
)
1257 goto invalid_enum_error
;
1258 return ctx
->Eval
.Map1Normal
;
1259 case GL_MAP1_TEXTURE_COORD_1
:
1260 if (ctx
->API
!= API_OPENGL_COMPAT
)
1261 goto invalid_enum_error
;
1262 return ctx
->Eval
.Map1TextureCoord1
;
1263 case GL_MAP1_TEXTURE_COORD_2
:
1264 if (ctx
->API
!= API_OPENGL_COMPAT
)
1265 goto invalid_enum_error
;
1266 return ctx
->Eval
.Map1TextureCoord2
;
1267 case GL_MAP1_TEXTURE_COORD_3
:
1268 if (ctx
->API
!= API_OPENGL_COMPAT
)
1269 goto invalid_enum_error
;
1270 return ctx
->Eval
.Map1TextureCoord3
;
1271 case GL_MAP1_TEXTURE_COORD_4
:
1272 if (ctx
->API
!= API_OPENGL_COMPAT
)
1273 goto invalid_enum_error
;
1274 return ctx
->Eval
.Map1TextureCoord4
;
1275 case GL_MAP1_VERTEX_3
:
1276 if (ctx
->API
!= API_OPENGL_COMPAT
)
1277 goto invalid_enum_error
;
1278 return ctx
->Eval
.Map1Vertex3
;
1279 case GL_MAP1_VERTEX_4
:
1280 if (ctx
->API
!= API_OPENGL_COMPAT
)
1281 goto invalid_enum_error
;
1282 return ctx
->Eval
.Map1Vertex4
;
1283 case GL_MAP2_COLOR_4
:
1284 if (ctx
->API
!= API_OPENGL_COMPAT
)
1285 goto invalid_enum_error
;
1286 return ctx
->Eval
.Map2Color4
;
1288 if (ctx
->API
!= API_OPENGL_COMPAT
)
1289 goto invalid_enum_error
;
1290 return ctx
->Eval
.Map2Index
;
1291 case GL_MAP2_NORMAL
:
1292 if (ctx
->API
!= API_OPENGL_COMPAT
)
1293 goto invalid_enum_error
;
1294 return ctx
->Eval
.Map2Normal
;
1295 case GL_MAP2_TEXTURE_COORD_1
:
1296 if (ctx
->API
!= API_OPENGL_COMPAT
)
1297 goto invalid_enum_error
;
1298 return ctx
->Eval
.Map2TextureCoord1
;
1299 case GL_MAP2_TEXTURE_COORD_2
:
1300 if (ctx
->API
!= API_OPENGL_COMPAT
)
1301 goto invalid_enum_error
;
1302 return ctx
->Eval
.Map2TextureCoord2
;
1303 case GL_MAP2_TEXTURE_COORD_3
:
1304 if (ctx
->API
!= API_OPENGL_COMPAT
)
1305 goto invalid_enum_error
;
1306 return ctx
->Eval
.Map2TextureCoord3
;
1307 case GL_MAP2_TEXTURE_COORD_4
:
1308 if (ctx
->API
!= API_OPENGL_COMPAT
)
1309 goto invalid_enum_error
;
1310 return ctx
->Eval
.Map2TextureCoord4
;
1311 case GL_MAP2_VERTEX_3
:
1312 if (ctx
->API
!= API_OPENGL_COMPAT
)
1313 goto invalid_enum_error
;
1314 return ctx
->Eval
.Map2Vertex3
;
1315 case GL_MAP2_VERTEX_4
:
1316 if (ctx
->API
!= API_OPENGL_COMPAT
)
1317 goto invalid_enum_error
;
1318 return ctx
->Eval
.Map2Vertex4
;
1320 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1321 goto invalid_enum_error
;
1322 return ctx
->Transform
.Normalize
;
1323 case GL_POINT_SMOOTH
:
1324 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1325 goto invalid_enum_error
;
1326 return ctx
->Point
.SmoothFlag
;
1327 case GL_POLYGON_SMOOTH
:
1328 if (!_mesa_is_desktop_gl(ctx
))
1329 goto invalid_enum_error
;
1330 return ctx
->Polygon
.SmoothFlag
;
1331 case GL_POLYGON_STIPPLE
:
1332 if (ctx
->API
!= API_OPENGL_COMPAT
)
1333 goto invalid_enum_error
;
1334 return ctx
->Polygon
.StippleFlag
;
1335 case GL_POLYGON_OFFSET_POINT
:
1336 if (!_mesa_is_desktop_gl(ctx
))
1337 goto invalid_enum_error
;
1338 return ctx
->Polygon
.OffsetPoint
;
1339 case GL_POLYGON_OFFSET_LINE
:
1340 if (!_mesa_is_desktop_gl(ctx
))
1341 goto invalid_enum_error
;
1342 return ctx
->Polygon
.OffsetLine
;
1343 case GL_POLYGON_OFFSET_FILL
:
1344 return ctx
->Polygon
.OffsetFill
;
1345 case GL_RESCALE_NORMAL_EXT
:
1346 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1347 goto invalid_enum_error
;
1348 return ctx
->Transform
.RescaleNormals
;
1349 case GL_SCISSOR_TEST
:
1350 return ctx
->Scissor
.Enabled
;
1351 case GL_STENCIL_TEST
:
1352 return ctx
->Stencil
.Enabled
;
1354 if (ctx
->API
!= API_OPENGL_COMPAT
)
1355 goto invalid_enum_error
;
1356 return is_texture_enabled(ctx
, TEXTURE_1D_BIT
);
1358 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1359 goto invalid_enum_error
;
1360 return is_texture_enabled(ctx
, TEXTURE_2D_BIT
);
1362 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1363 goto invalid_enum_error
;
1364 return is_texture_enabled(ctx
, TEXTURE_3D_BIT
);
1365 case GL_TEXTURE_GEN_S
:
1366 case GL_TEXTURE_GEN_T
:
1367 case GL_TEXTURE_GEN_R
:
1368 case GL_TEXTURE_GEN_Q
:
1370 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1372 if (ctx
->API
!= API_OPENGL_COMPAT
)
1373 goto invalid_enum_error
;
1376 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
1377 return (texUnit
->TexGenEnabled
& coordBit
) ? GL_TRUE
: GL_FALSE
;
1381 case GL_TEXTURE_GEN_STR_OES
:
1383 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1385 if (ctx
->API
!= API_OPENGLES
)
1386 goto invalid_enum_error
;
1389 return (texUnit
->TexGenEnabled
& STR_BITS
) == STR_BITS
1390 ? GL_TRUE
: GL_FALSE
;
1394 /* client-side state */
1395 case GL_VERTEX_ARRAY
:
1396 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1397 goto invalid_enum_error
;
1398 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
!= 0);
1399 case GL_NORMAL_ARRAY
:
1400 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1401 goto invalid_enum_error
;
1402 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
!= 0);
1403 case GL_COLOR_ARRAY
:
1404 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1405 goto invalid_enum_error
;
1406 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
!= 0);
1407 case GL_INDEX_ARRAY
:
1408 if (ctx
->API
!= API_OPENGL_COMPAT
)
1409 goto invalid_enum_error
;
1410 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
!= 0);
1411 case GL_TEXTURE_COORD_ARRAY
:
1412 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1413 goto invalid_enum_error
;
1414 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)]
1416 case GL_EDGE_FLAG_ARRAY
:
1417 if (ctx
->API
!= API_OPENGL_COMPAT
)
1418 goto invalid_enum_error
;
1419 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
!= 0);
1420 case GL_FOG_COORDINATE_ARRAY_EXT
:
1421 if (ctx
->API
!= API_OPENGL_COMPAT
)
1422 goto invalid_enum_error
;
1423 CHECK_EXTENSION(EXT_fog_coord
);
1424 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
!= 0);
1425 case GL_SECONDARY_COLOR_ARRAY_EXT
:
1426 if (ctx
->API
!= API_OPENGL_COMPAT
)
1427 goto invalid_enum_error
;
1428 CHECK_EXTENSION(EXT_secondary_color
);
1429 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
!= 0);
1430 case GL_POINT_SIZE_ARRAY_OES
:
1431 if (ctx
->API
!= API_OPENGLES
)
1432 goto invalid_enum_error
;
1433 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
!= 0);
1435 /* GL_ARB_texture_cube_map */
1436 case GL_TEXTURE_CUBE_MAP_ARB
:
1437 CHECK_EXTENSION(ARB_texture_cube_map
);
1438 return is_texture_enabled(ctx
, TEXTURE_CUBE_BIT
);
1440 /* GL_EXT_secondary_color */
1441 case GL_COLOR_SUM_EXT
:
1442 if (ctx
->API
!= API_OPENGL_COMPAT
)
1443 goto invalid_enum_error
;
1444 CHECK_EXTENSION2(EXT_secondary_color
, ARB_vertex_program
);
1445 return ctx
->Fog
.ColorSumEnabled
;
1447 /* GL_ARB_multisample */
1448 case GL_MULTISAMPLE_ARB
:
1449 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1450 goto invalid_enum_error
;
1451 return ctx
->Multisample
.Enabled
;
1452 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
1453 return ctx
->Multisample
.SampleAlphaToCoverage
;
1454 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
1455 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1456 goto invalid_enum_error
;
1457 return ctx
->Multisample
.SampleAlphaToOne
;
1458 case GL_SAMPLE_COVERAGE_ARB
:
1459 return ctx
->Multisample
.SampleCoverage
;
1460 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
1461 if (!_mesa_is_desktop_gl(ctx
))
1462 goto invalid_enum_error
;
1463 return ctx
->Multisample
.SampleCoverageInvert
;
1465 /* GL_IBM_rasterpos_clip */
1466 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
1467 if (ctx
->API
!= API_OPENGL_COMPAT
)
1468 goto invalid_enum_error
;
1469 return ctx
->Transform
.RasterPositionUnclipped
;
1471 /* GL_NV_point_sprite */
1472 case GL_POINT_SPRITE_NV
:
1473 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1474 goto invalid_enum_error
;
1475 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
)
1476 return ctx
->Point
.PointSprite
;
1478 case GL_VERTEX_PROGRAM_ARB
:
1479 if (ctx
->API
!= API_OPENGL_COMPAT
)
1480 goto invalid_enum_error
;
1481 CHECK_EXTENSION(ARB_vertex_program
);
1482 return ctx
->VertexProgram
.Enabled
;
1483 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
1484 /* This was added with ARB_vertex_program, but it is also used with
1485 * GLSL vertex shaders on desktop.
1487 if (!_mesa_is_desktop_gl(ctx
))
1488 goto invalid_enum_error
;
1489 CHECK_EXTENSION(ARB_vertex_program
);
1490 return ctx
->VertexProgram
.PointSizeEnabled
;
1491 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
1492 if (ctx
->API
!= API_OPENGL_COMPAT
)
1493 goto invalid_enum_error
;
1494 CHECK_EXTENSION(ARB_vertex_program
);
1495 return ctx
->VertexProgram
.TwoSideEnabled
;
1497 /* GL_NV_texture_rectangle */
1498 case GL_TEXTURE_RECTANGLE_NV
:
1499 if (ctx
->API
!= API_OPENGL_COMPAT
)
1500 goto invalid_enum_error
;
1501 CHECK_EXTENSION(NV_texture_rectangle
);
1502 return is_texture_enabled(ctx
, TEXTURE_RECT_BIT
);
1504 /* GL_EXT_stencil_two_side */
1505 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
1506 if (ctx
->API
!= API_OPENGL_COMPAT
)
1507 goto invalid_enum_error
;
1508 CHECK_EXTENSION(EXT_stencil_two_side
);
1509 return ctx
->Stencil
.TestTwoSide
;
1511 case GL_FRAGMENT_PROGRAM_ARB
:
1512 if (ctx
->API
!= API_OPENGL_COMPAT
)
1513 goto invalid_enum_error
;
1514 return ctx
->FragmentProgram
.Enabled
;
1516 /* GL_EXT_depth_bounds_test */
1517 case GL_DEPTH_BOUNDS_TEST_EXT
:
1518 if (!_mesa_is_desktop_gl(ctx
))
1519 goto invalid_enum_error
;
1520 CHECK_EXTENSION(EXT_depth_bounds_test
);
1521 return ctx
->Depth
.BoundsTest
;
1523 /* GL_ARB_depth_clamp */
1524 case GL_DEPTH_CLAMP
:
1525 if (!_mesa_is_desktop_gl(ctx
))
1526 goto invalid_enum_error
;
1527 CHECK_EXTENSION(ARB_depth_clamp
);
1528 return ctx
->Transform
.DepthClamp
;
1530 case GL_FRAGMENT_SHADER_ATI
:
1531 if (ctx
->API
!= API_OPENGL_COMPAT
)
1532 goto invalid_enum_error
;
1533 CHECK_EXTENSION(ATI_fragment_shader
);
1534 return ctx
->ATIFragmentShader
.Enabled
;
1536 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1537 if (!_mesa_is_desktop_gl(ctx
))
1538 goto invalid_enum_error
;
1539 CHECK_EXTENSION(ARB_seamless_cube_map
);
1540 return ctx
->Texture
.CubeMapSeamless
;
1542 case GL_RASTERIZER_DISCARD
:
1543 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1544 goto invalid_enum_error
;
1545 CHECK_EXTENSION(EXT_transform_feedback
);
1546 return ctx
->RasterDiscard
;
1548 /* GL_NV_primitive_restart */
1549 case GL_PRIMITIVE_RESTART_NV
:
1550 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.NV_primitive_restart
) {
1551 goto invalid_enum_error
;
1553 return ctx
->Array
.PrimitiveRestart
;
1555 /* GL 3.1 primitive restart */
1556 case GL_PRIMITIVE_RESTART
:
1557 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
1558 goto invalid_enum_error
;
1560 return ctx
->Array
.PrimitiveRestart
;
1562 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
1563 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
) {
1564 goto invalid_enum_error
;
1566 return ctx
->Array
.PrimitiveRestartFixedIndex
;
1568 /* GL3.0 - GL_framebuffer_sRGB */
1569 case GL_FRAMEBUFFER_SRGB_EXT
:
1570 if (!_mesa_is_desktop_gl(ctx
))
1571 goto invalid_enum_error
;
1572 CHECK_EXTENSION(EXT_framebuffer_sRGB
);
1573 return ctx
->Color
.sRGBEnabled
;
1575 /* GL_OES_EGL_image_external */
1576 case GL_TEXTURE_EXTERNAL_OES
:
1577 if (!_mesa_is_gles(ctx
))
1578 goto invalid_enum_error
;
1579 CHECK_EXTENSION(OES_EGL_image_external
);
1580 return is_texture_enabled(ctx
, TEXTURE_EXTERNAL_BIT
);
1582 /* ARB_texture_multisample */
1583 case GL_SAMPLE_MASK
:
1584 if (!_mesa_is_desktop_gl(ctx
))
1585 goto invalid_enum_error
;
1586 CHECK_EXTENSION(ARB_texture_multisample
);
1587 return ctx
->Multisample
.SampleMask
;
1590 goto invalid_enum_error
;
1596 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabled(%s)",
1597 _mesa_lookup_enum_by_nr(cap
));