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.
37 #include "util/simple_list.h"
40 #include "api_arrayelt.h"
45 #define CHECK_EXTENSION(EXTNAME, CAP) \
46 if (!ctx->Extensions.EXTNAME) { \
47 goto invalid_enum_error; \
52 update_derived_primitive_restart_state(struct gl_context
*ctx
)
54 /* Update derived primitive restart state.
56 ctx
->Array
._PrimitiveRestart
= ctx
->Array
.PrimitiveRestart
57 || ctx
->Array
.PrimitiveRestartFixedIndex
;
61 * Helper to enable/disable client-side state.
64 client_state(struct gl_context
*ctx
, GLenum cap
, GLboolean state
)
66 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
72 var
= &vao
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
;
76 var
= &vao
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
;
77 flag
= VERT_BIT_NORMAL
;
80 var
= &vao
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
;
81 flag
= VERT_BIT_COLOR0
;
84 var
= &vao
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
;
85 flag
= VERT_BIT_COLOR_INDEX
;
87 case GL_TEXTURE_COORD_ARRAY
:
88 var
= &vao
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Enabled
;
89 flag
= VERT_BIT_TEX(ctx
->Array
.ActiveTexture
);
91 case GL_EDGE_FLAG_ARRAY
:
92 var
= &vao
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
;
93 flag
= VERT_BIT_EDGEFLAG
;
95 case GL_FOG_COORDINATE_ARRAY_EXT
:
96 var
= &vao
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
;
99 case GL_SECONDARY_COLOR_ARRAY_EXT
:
100 var
= &vao
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
;
101 flag
= VERT_BIT_COLOR1
;
104 case GL_POINT_SIZE_ARRAY_OES
:
105 var
= &vao
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
;
106 flag
= VERT_BIT_POINT_SIZE
;
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 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
);
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
)
242 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
243 ctx
->Multisample
.Enabled
= state
;
245 if (ctx
->Driver
.Enable
) {
246 ctx
->Driver
.Enable(ctx
, GL_MULTISAMPLE
, state
);
251 * Helper function to enable or disable GL_FRAMEBUFFER_SRGB, skipping the
252 * check for whether the API supports it (GLES doesn't).
255 _mesa_set_framebuffer_srgb(struct gl_context
*ctx
, GLboolean state
)
257 if (ctx
->Color
.sRGBEnabled
== state
)
259 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
260 ctx
->Color
.sRGBEnabled
= state
;
262 if (ctx
->Driver
.Enable
) {
263 ctx
->Driver
.Enable(ctx
, GL_FRAMEBUFFER_SRGB
, state
);
268 * Helper function to enable or disable state.
270 * \param ctx GL context.
271 * \param cap the state to enable/disable
272 * \param state whether to enable or disable the specified capability.
274 * Updates the current context and flushes the vertices as needed. For
275 * capabilities associated with extensions it verifies that those extensions
276 * are effectivly present before updating. Notifies the driver via
277 * dd_function_table::Enable.
280 _mesa_set_enable(struct gl_context
*ctx
, GLenum cap
, GLboolean state
)
282 if (MESA_VERBOSE
& VERBOSE_API
)
283 _mesa_debug(ctx
, "%s %s (newstate is %x)\n",
284 state
? "glEnable" : "glDisable",
285 _mesa_enum_to_string(cap
),
290 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
291 goto invalid_enum_error
;
292 if (ctx
->Color
.AlphaEnabled
== state
)
294 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
295 ctx
->Color
.AlphaEnabled
= state
;
298 if (ctx
->API
!= API_OPENGL_COMPAT
)
299 goto invalid_enum_error
;
300 if (ctx
->Eval
.AutoNormal
== state
)
302 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
303 ctx
->Eval
.AutoNormal
= state
;
307 GLbitfield newEnabled
=
308 state
* ((1 << ctx
->Const
.MaxDrawBuffers
) - 1);
309 if (newEnabled
!= ctx
->Color
.BlendEnabled
) {
310 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
311 ctx
->Color
.BlendEnabled
= newEnabled
;
315 case GL_CLIP_DISTANCE0
: /* aka GL_CLIP_PLANE0 */
316 case GL_CLIP_DISTANCE1
:
317 case GL_CLIP_DISTANCE2
:
318 case GL_CLIP_DISTANCE3
:
319 case GL_CLIP_DISTANCE4
:
320 case GL_CLIP_DISTANCE5
:
321 case GL_CLIP_DISTANCE6
:
322 case GL_CLIP_DISTANCE7
:
324 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
326 if (p
>= ctx
->Const
.MaxClipPlanes
)
327 goto invalid_enum_error
;
329 if ((ctx
->Transform
.ClipPlanesEnabled
& (1 << p
))
330 == ((GLuint
) state
<< p
))
333 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
336 ctx
->Transform
.ClipPlanesEnabled
|= (1 << p
);
337 _mesa_update_clip_plane(ctx
, p
);
340 ctx
->Transform
.ClipPlanesEnabled
&= ~(1 << p
);
344 case GL_COLOR_MATERIAL
:
345 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
346 goto invalid_enum_error
;
347 if (ctx
->Light
.ColorMaterialEnabled
== state
)
349 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
350 FLUSH_CURRENT(ctx
, 0);
351 ctx
->Light
.ColorMaterialEnabled
= state
;
353 _mesa_update_color_material( ctx
,
354 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
] );
358 if (ctx
->Polygon
.CullFlag
== state
)
360 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
361 ctx
->Polygon
.CullFlag
= state
;
364 if (ctx
->Depth
.Test
== state
)
366 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
367 ctx
->Depth
.Test
= state
;
369 case GL_DEBUG_OUTPUT
:
370 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
:
371 _mesa_set_debug_state_int(ctx
, cap
, state
);
374 if (ctx
->Color
.DitherFlag
== state
)
376 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
377 ctx
->Color
.DitherFlag
= state
;
380 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
381 goto invalid_enum_error
;
382 if (ctx
->Fog
.Enabled
== state
)
384 FLUSH_VERTICES(ctx
, _NEW_FOG
);
385 ctx
->Fog
.Enabled
= state
;
395 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
396 goto invalid_enum_error
;
397 if (ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
== state
)
399 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
400 ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
= state
;
402 insert_at_tail(&ctx
->Light
.EnabledList
,
403 &ctx
->Light
.Light
[cap
-GL_LIGHT0
]);
406 remove_from_list(&ctx
->Light
.Light
[cap
-GL_LIGHT0
]);
410 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
411 goto invalid_enum_error
;
412 if (ctx
->Light
.Enabled
== state
)
414 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
415 ctx
->Light
.Enabled
= state
;
418 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
419 goto invalid_enum_error
;
420 if (ctx
->Line
.SmoothFlag
== state
)
422 FLUSH_VERTICES(ctx
, _NEW_LINE
);
423 ctx
->Line
.SmoothFlag
= state
;
425 case GL_LINE_STIPPLE
:
426 if (ctx
->API
!= API_OPENGL_COMPAT
)
427 goto invalid_enum_error
;
428 if (ctx
->Line
.StippleFlag
== state
)
430 FLUSH_VERTICES(ctx
, _NEW_LINE
);
431 ctx
->Line
.StippleFlag
= state
;
433 case GL_INDEX_LOGIC_OP
:
434 if (ctx
->API
!= API_OPENGL_COMPAT
)
435 goto invalid_enum_error
;
436 if (ctx
->Color
.IndexLogicOpEnabled
== state
)
438 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
439 ctx
->Color
.IndexLogicOpEnabled
= state
;
441 case GL_COLOR_LOGIC_OP
:
442 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
443 goto invalid_enum_error
;
444 if (ctx
->Color
.ColorLogicOpEnabled
== state
)
446 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
447 ctx
->Color
.ColorLogicOpEnabled
= state
;
449 case GL_MAP1_COLOR_4
:
450 if (ctx
->API
!= API_OPENGL_COMPAT
)
451 goto invalid_enum_error
;
452 if (ctx
->Eval
.Map1Color4
== state
)
454 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
455 ctx
->Eval
.Map1Color4
= state
;
458 if (ctx
->API
!= API_OPENGL_COMPAT
)
459 goto invalid_enum_error
;
460 if (ctx
->Eval
.Map1Index
== state
)
462 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
463 ctx
->Eval
.Map1Index
= state
;
466 if (ctx
->API
!= API_OPENGL_COMPAT
)
467 goto invalid_enum_error
;
468 if (ctx
->Eval
.Map1Normal
== state
)
470 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
471 ctx
->Eval
.Map1Normal
= state
;
473 case GL_MAP1_TEXTURE_COORD_1
:
474 if (ctx
->API
!= API_OPENGL_COMPAT
)
475 goto invalid_enum_error
;
476 if (ctx
->Eval
.Map1TextureCoord1
== state
)
478 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
479 ctx
->Eval
.Map1TextureCoord1
= state
;
481 case GL_MAP1_TEXTURE_COORD_2
:
482 if (ctx
->API
!= API_OPENGL_COMPAT
)
483 goto invalid_enum_error
;
484 if (ctx
->Eval
.Map1TextureCoord2
== state
)
486 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
487 ctx
->Eval
.Map1TextureCoord2
= state
;
489 case GL_MAP1_TEXTURE_COORD_3
:
490 if (ctx
->API
!= API_OPENGL_COMPAT
)
491 goto invalid_enum_error
;
492 if (ctx
->Eval
.Map1TextureCoord3
== state
)
494 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
495 ctx
->Eval
.Map1TextureCoord3
= state
;
497 case GL_MAP1_TEXTURE_COORD_4
:
498 if (ctx
->API
!= API_OPENGL_COMPAT
)
499 goto invalid_enum_error
;
500 if (ctx
->Eval
.Map1TextureCoord4
== state
)
502 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
503 ctx
->Eval
.Map1TextureCoord4
= state
;
505 case GL_MAP1_VERTEX_3
:
506 if (ctx
->API
!= API_OPENGL_COMPAT
)
507 goto invalid_enum_error
;
508 if (ctx
->Eval
.Map1Vertex3
== state
)
510 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
511 ctx
->Eval
.Map1Vertex3
= state
;
513 case GL_MAP1_VERTEX_4
:
514 if (ctx
->API
!= API_OPENGL_COMPAT
)
515 goto invalid_enum_error
;
516 if (ctx
->Eval
.Map1Vertex4
== state
)
518 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
519 ctx
->Eval
.Map1Vertex4
= state
;
521 case GL_MAP2_COLOR_4
:
522 if (ctx
->API
!= API_OPENGL_COMPAT
)
523 goto invalid_enum_error
;
524 if (ctx
->Eval
.Map2Color4
== state
)
526 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
527 ctx
->Eval
.Map2Color4
= state
;
530 if (ctx
->API
!= API_OPENGL_COMPAT
)
531 goto invalid_enum_error
;
532 if (ctx
->Eval
.Map2Index
== state
)
534 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
535 ctx
->Eval
.Map2Index
= state
;
538 if (ctx
->API
!= API_OPENGL_COMPAT
)
539 goto invalid_enum_error
;
540 if (ctx
->Eval
.Map2Normal
== state
)
542 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
543 ctx
->Eval
.Map2Normal
= state
;
545 case GL_MAP2_TEXTURE_COORD_1
:
546 if (ctx
->API
!= API_OPENGL_COMPAT
)
547 goto invalid_enum_error
;
548 if (ctx
->Eval
.Map2TextureCoord1
== state
)
550 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
551 ctx
->Eval
.Map2TextureCoord1
= state
;
553 case GL_MAP2_TEXTURE_COORD_2
:
554 if (ctx
->API
!= API_OPENGL_COMPAT
)
555 goto invalid_enum_error
;
556 if (ctx
->Eval
.Map2TextureCoord2
== state
)
558 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
559 ctx
->Eval
.Map2TextureCoord2
= state
;
561 case GL_MAP2_TEXTURE_COORD_3
:
562 if (ctx
->API
!= API_OPENGL_COMPAT
)
563 goto invalid_enum_error
;
564 if (ctx
->Eval
.Map2TextureCoord3
== state
)
566 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
567 ctx
->Eval
.Map2TextureCoord3
= state
;
569 case GL_MAP2_TEXTURE_COORD_4
:
570 if (ctx
->API
!= API_OPENGL_COMPAT
)
571 goto invalid_enum_error
;
572 if (ctx
->Eval
.Map2TextureCoord4
== state
)
574 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
575 ctx
->Eval
.Map2TextureCoord4
= state
;
577 case GL_MAP2_VERTEX_3
:
578 if (ctx
->API
!= API_OPENGL_COMPAT
)
579 goto invalid_enum_error
;
580 if (ctx
->Eval
.Map2Vertex3
== state
)
582 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
583 ctx
->Eval
.Map2Vertex3
= state
;
585 case GL_MAP2_VERTEX_4
:
586 if (ctx
->API
!= API_OPENGL_COMPAT
)
587 goto invalid_enum_error
;
588 if (ctx
->Eval
.Map2Vertex4
== state
)
590 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
591 ctx
->Eval
.Map2Vertex4
= state
;
594 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
595 goto invalid_enum_error
;
596 if (ctx
->Transform
.Normalize
== state
)
598 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
599 ctx
->Transform
.Normalize
= state
;
601 case GL_POINT_SMOOTH
:
602 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
603 goto invalid_enum_error
;
604 if (ctx
->Point
.SmoothFlag
== state
)
606 FLUSH_VERTICES(ctx
, _NEW_POINT
);
607 ctx
->Point
.SmoothFlag
= state
;
609 case GL_POLYGON_SMOOTH
:
610 if (!_mesa_is_desktop_gl(ctx
))
611 goto invalid_enum_error
;
612 if (ctx
->Polygon
.SmoothFlag
== state
)
614 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
615 ctx
->Polygon
.SmoothFlag
= state
;
617 case GL_POLYGON_STIPPLE
:
618 if (ctx
->API
!= API_OPENGL_COMPAT
)
619 goto invalid_enum_error
;
620 if (ctx
->Polygon
.StippleFlag
== state
)
622 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
623 ctx
->Polygon
.StippleFlag
= state
;
625 case GL_POLYGON_OFFSET_POINT
:
626 if (!_mesa_is_desktop_gl(ctx
))
627 goto invalid_enum_error
;
628 if (ctx
->Polygon
.OffsetPoint
== state
)
630 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
631 ctx
->Polygon
.OffsetPoint
= state
;
633 case GL_POLYGON_OFFSET_LINE
:
634 if (!_mesa_is_desktop_gl(ctx
))
635 goto invalid_enum_error
;
636 if (ctx
->Polygon
.OffsetLine
== state
)
638 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
639 ctx
->Polygon
.OffsetLine
= state
;
641 case GL_POLYGON_OFFSET_FILL
:
642 if (ctx
->Polygon
.OffsetFill
== state
)
644 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
645 ctx
->Polygon
.OffsetFill
= state
;
647 case GL_RESCALE_NORMAL_EXT
:
648 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
649 goto invalid_enum_error
;
650 if (ctx
->Transform
.RescaleNormals
== state
)
652 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
653 ctx
->Transform
.RescaleNormals
= state
;
655 case GL_SCISSOR_TEST
:
657 /* Must expand glEnable to all scissors */
658 GLbitfield newEnabled
=
659 state
* ((1 << ctx
->Const
.MaxViewports
) - 1);
660 if (newEnabled
!= ctx
->Scissor
.EnableFlags
) {
661 FLUSH_VERTICES(ctx
, _NEW_SCISSOR
);
662 ctx
->Scissor
.EnableFlags
= newEnabled
;
666 case GL_STENCIL_TEST
:
667 if (ctx
->Stencil
.Enabled
== state
)
669 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
670 ctx
->Stencil
.Enabled
= state
;
673 if (ctx
->API
!= API_OPENGL_COMPAT
)
674 goto invalid_enum_error
;
675 if (!enable_texture(ctx
, state
, TEXTURE_1D_BIT
)) {
680 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
681 goto invalid_enum_error
;
682 if (!enable_texture(ctx
, state
, TEXTURE_2D_BIT
)) {
687 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
688 goto invalid_enum_error
;
689 if (!enable_texture(ctx
, state
, TEXTURE_3D_BIT
)) {
693 case GL_TEXTURE_GEN_S
:
694 case GL_TEXTURE_GEN_T
:
695 case GL_TEXTURE_GEN_R
:
696 case GL_TEXTURE_GEN_Q
:
698 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
700 if (ctx
->API
!= API_OPENGL_COMPAT
)
701 goto invalid_enum_error
;
704 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
705 GLbitfield newenabled
= texUnit
->TexGenEnabled
& ~coordBit
;
707 newenabled
|= coordBit
;
708 if (texUnit
->TexGenEnabled
== newenabled
)
710 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
711 texUnit
->TexGenEnabled
= newenabled
;
716 case GL_TEXTURE_GEN_STR_OES
:
717 /* disable S, T, and R at the same time */
719 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
721 if (ctx
->API
!= API_OPENGLES
)
722 goto invalid_enum_error
;
726 texUnit
->TexGenEnabled
& ~STR_BITS
;
728 newenabled
|= STR_BITS
;
729 if (texUnit
->TexGenEnabled
== newenabled
)
731 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
732 texUnit
->TexGenEnabled
= newenabled
;
737 /* client-side state */
738 case GL_VERTEX_ARRAY
:
739 case GL_NORMAL_ARRAY
:
742 case GL_TEXTURE_COORD_ARRAY
:
743 case GL_EDGE_FLAG_ARRAY
:
744 case GL_FOG_COORDINATE_ARRAY_EXT
:
745 case GL_SECONDARY_COLOR_ARRAY_EXT
:
746 case GL_POINT_SIZE_ARRAY_OES
:
747 client_state( ctx
, cap
, state
);
750 /* GL_ARB_texture_cube_map */
751 case GL_TEXTURE_CUBE_MAP_ARB
:
752 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
753 goto invalid_enum_error
;
754 CHECK_EXTENSION(ARB_texture_cube_map
, cap
);
755 if (!enable_texture(ctx
, state
, TEXTURE_CUBE_BIT
)) {
760 /* GL_EXT_secondary_color */
761 case GL_COLOR_SUM_EXT
:
762 if (ctx
->API
!= API_OPENGL_COMPAT
)
763 goto invalid_enum_error
;
764 if (ctx
->Fog
.ColorSumEnabled
== state
)
766 FLUSH_VERTICES(ctx
, _NEW_FOG
);
767 ctx
->Fog
.ColorSumEnabled
= state
;
770 /* GL_ARB_multisample */
771 case GL_MULTISAMPLE_ARB
:
772 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
773 goto invalid_enum_error
;
774 _mesa_set_multisample(ctx
, state
);
776 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
777 if (ctx
->Multisample
.SampleAlphaToCoverage
== state
)
779 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
780 ctx
->Multisample
.SampleAlphaToCoverage
= state
;
782 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
783 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
784 goto invalid_enum_error
;
785 if (ctx
->Multisample
.SampleAlphaToOne
== state
)
787 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
788 ctx
->Multisample
.SampleAlphaToOne
= state
;
790 case GL_SAMPLE_COVERAGE_ARB
:
791 if (ctx
->Multisample
.SampleCoverage
== state
)
793 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
794 ctx
->Multisample
.SampleCoverage
= state
;
796 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
797 if (!_mesa_is_desktop_gl(ctx
))
798 goto invalid_enum_error
;
799 if (ctx
->Multisample
.SampleCoverageInvert
== state
)
801 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
802 ctx
->Multisample
.SampleCoverageInvert
= state
;
805 /* GL_ARB_sample_shading */
806 case GL_SAMPLE_SHADING
:
807 if (!_mesa_is_desktop_gl(ctx
))
808 goto invalid_enum_error
;
809 CHECK_EXTENSION(ARB_sample_shading
, cap
);
810 if (ctx
->Multisample
.SampleShading
== state
)
812 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
813 ctx
->Multisample
.SampleShading
= state
;
816 /* GL_IBM_rasterpos_clip */
817 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
818 if (ctx
->API
!= API_OPENGL_COMPAT
)
819 goto invalid_enum_error
;
820 if (ctx
->Transform
.RasterPositionUnclipped
== state
)
822 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
823 ctx
->Transform
.RasterPositionUnclipped
= state
;
826 /* GL_NV_point_sprite */
827 case GL_POINT_SPRITE_NV
:
828 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
829 goto invalid_enum_error
;
830 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
, cap
);
831 if (ctx
->Point
.PointSprite
== state
)
833 FLUSH_VERTICES(ctx
, _NEW_POINT
);
834 ctx
->Point
.PointSprite
= state
;
837 case GL_VERTEX_PROGRAM_ARB
:
838 if (ctx
->API
!= API_OPENGL_COMPAT
)
839 goto invalid_enum_error
;
840 CHECK_EXTENSION(ARB_vertex_program
, cap
);
841 if (ctx
->VertexProgram
.Enabled
== state
)
843 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
844 ctx
->VertexProgram
.Enabled
= state
;
846 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
847 /* This was added with ARB_vertex_program, but it is also used with
848 * GLSL vertex shaders on desktop.
850 if (!_mesa_is_desktop_gl(ctx
))
851 goto invalid_enum_error
;
852 CHECK_EXTENSION(ARB_vertex_program
, cap
);
853 if (ctx
->VertexProgram
.PointSizeEnabled
== state
)
855 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
856 ctx
->VertexProgram
.PointSizeEnabled
= state
;
858 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
859 if (ctx
->API
!= API_OPENGL_COMPAT
)
860 goto invalid_enum_error
;
861 CHECK_EXTENSION(ARB_vertex_program
, cap
);
862 if (ctx
->VertexProgram
.TwoSideEnabled
== state
)
864 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
865 ctx
->VertexProgram
.TwoSideEnabled
= state
;
868 /* GL_NV_texture_rectangle */
869 case GL_TEXTURE_RECTANGLE_NV
:
870 if (ctx
->API
!= API_OPENGL_COMPAT
)
871 goto invalid_enum_error
;
872 CHECK_EXTENSION(NV_texture_rectangle
, cap
);
873 if (!enable_texture(ctx
, state
, TEXTURE_RECT_BIT
)) {
878 /* GL_EXT_stencil_two_side */
879 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
880 if (ctx
->API
!= API_OPENGL_COMPAT
)
881 goto invalid_enum_error
;
882 CHECK_EXTENSION(EXT_stencil_two_side
, cap
);
883 if (ctx
->Stencil
.TestTwoSide
== state
)
885 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
886 ctx
->Stencil
.TestTwoSide
= state
;
888 ctx
->Stencil
._BackFace
= 2;
890 ctx
->Stencil
._BackFace
= 1;
894 case GL_FRAGMENT_PROGRAM_ARB
:
895 if (ctx
->API
!= API_OPENGL_COMPAT
)
896 goto invalid_enum_error
;
897 CHECK_EXTENSION(ARB_fragment_program
, cap
);
898 if (ctx
->FragmentProgram
.Enabled
== state
)
900 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
901 ctx
->FragmentProgram
.Enabled
= state
;
904 /* GL_EXT_depth_bounds_test */
905 case GL_DEPTH_BOUNDS_TEST_EXT
:
906 if (!_mesa_is_desktop_gl(ctx
))
907 goto invalid_enum_error
;
908 CHECK_EXTENSION(EXT_depth_bounds_test
, cap
);
909 if (ctx
->Depth
.BoundsTest
== state
)
911 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
912 ctx
->Depth
.BoundsTest
= state
;
916 if (!_mesa_is_desktop_gl(ctx
))
917 goto invalid_enum_error
;
918 CHECK_EXTENSION(ARB_depth_clamp
, cap
);
919 if (ctx
->Transform
.DepthClamp
== state
)
921 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
922 ctx
->Transform
.DepthClamp
= state
;
925 case GL_FRAGMENT_SHADER_ATI
:
926 if (ctx
->API
!= API_OPENGL_COMPAT
)
927 goto invalid_enum_error
;
928 CHECK_EXTENSION(ATI_fragment_shader
, cap
);
929 if (ctx
->ATIFragmentShader
.Enabled
== state
)
931 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
932 ctx
->ATIFragmentShader
.Enabled
= state
;
935 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
936 if (!_mesa_is_desktop_gl(ctx
))
937 goto invalid_enum_error
;
938 CHECK_EXTENSION(ARB_seamless_cube_map
, cap
);
939 if (ctx
->Texture
.CubeMapSeamless
!= state
) {
940 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
941 ctx
->Texture
.CubeMapSeamless
= state
;
945 case GL_RASTERIZER_DISCARD
:
946 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
947 goto invalid_enum_error
;
948 CHECK_EXTENSION(EXT_transform_feedback
, cap
);
949 if (ctx
->RasterDiscard
!= state
) {
950 FLUSH_VERTICES(ctx
, 0);
951 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewRasterizerDiscard
;
952 ctx
->RasterDiscard
= state
;
956 /* GL 3.1 primitive restart. Note: this enum is different from
957 * GL_PRIMITIVE_RESTART_NV (which is client state).
959 case GL_PRIMITIVE_RESTART
:
960 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
961 goto invalid_enum_error
;
963 if (ctx
->Array
.PrimitiveRestart
!= state
) {
964 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
965 ctx
->Array
.PrimitiveRestart
= state
;
966 update_derived_primitive_restart_state(ctx
);
970 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
971 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
)
972 goto invalid_enum_error
;
973 if (ctx
->Array
.PrimitiveRestartFixedIndex
!= state
) {
974 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
975 ctx
->Array
.PrimitiveRestartFixedIndex
= state
;
976 update_derived_primitive_restart_state(ctx
);
980 /* GL3.0 - GL_framebuffer_sRGB */
981 case GL_FRAMEBUFFER_SRGB_EXT
:
982 if (!_mesa_is_desktop_gl(ctx
))
983 goto invalid_enum_error
;
984 CHECK_EXTENSION(EXT_framebuffer_sRGB
, cap
);
985 _mesa_set_framebuffer_srgb(ctx
, state
);
988 /* GL_OES_EGL_image_external */
989 case GL_TEXTURE_EXTERNAL_OES
:
990 if (!_mesa_is_gles(ctx
))
991 goto invalid_enum_error
;
992 CHECK_EXTENSION(OES_EGL_image_external
, cap
);
993 if (!enable_texture(ctx
, state
, TEXTURE_EXTERNAL_BIT
)) {
998 /* ARB_texture_multisample */
1000 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
1001 goto invalid_enum_error
;
1002 CHECK_EXTENSION(ARB_texture_multisample
, cap
);
1003 if (ctx
->Multisample
.SampleMask
== state
)
1005 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
1006 ctx
->Multisample
.SampleMask
= state
;
1010 goto invalid_enum_error
;
1013 if (ctx
->Driver
.Enable
) {
1014 ctx
->Driver
.Enable( ctx
, cap
, state
);
1020 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%s(%s)",
1021 state
? "Enable" : "Disable", _mesa_enum_to_string(cap
));
1026 * Enable GL capability. Called by glEnable()
1027 * \param cap state to enable.
1030 _mesa_Enable( GLenum cap
)
1032 GET_CURRENT_CONTEXT(ctx
);
1034 _mesa_set_enable( ctx
, cap
, GL_TRUE
);
1039 * Disable GL capability. Called by glDisable()
1040 * \param cap state to disable.
1043 _mesa_Disable( GLenum cap
)
1045 GET_CURRENT_CONTEXT(ctx
);
1047 _mesa_set_enable( ctx
, cap
, GL_FALSE
);
1053 * Enable/disable an indexed state var.
1056 _mesa_set_enablei(struct gl_context
*ctx
, GLenum cap
,
1057 GLuint index
, GLboolean state
)
1059 assert(state
== 0 || state
== 1);
1062 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
1063 goto invalid_enum_error
;
1065 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1066 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1067 state
? "glEnableIndexed" : "glDisableIndexed", index
);
1070 if (((ctx
->Color
.BlendEnabled
>> index
) & 1) != state
) {
1071 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
1073 ctx
->Color
.BlendEnabled
|= (1 << index
);
1075 ctx
->Color
.BlendEnabled
&= ~(1 << index
);
1078 case GL_SCISSOR_TEST
:
1079 if (index
>= ctx
->Const
.MaxViewports
) {
1080 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1081 state
? "glEnablei" : "glDisablei", index
);
1084 if (((ctx
->Scissor
.EnableFlags
>> index
) & 1) != state
) {
1085 FLUSH_VERTICES(ctx
, _NEW_SCISSOR
);
1087 ctx
->Scissor
.EnableFlags
|= (1 << index
);
1089 ctx
->Scissor
.EnableFlags
&= ~(1 << index
);
1093 goto invalid_enum_error
;
1098 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(cap=%s)",
1099 state
? "glEnablei" : "glDisablei",
1100 _mesa_enum_to_string(cap
));
1105 _mesa_Disablei( GLenum cap
, GLuint index
)
1107 GET_CURRENT_CONTEXT(ctx
);
1108 _mesa_set_enablei(ctx
, cap
, index
, GL_FALSE
);
1113 _mesa_Enablei( GLenum cap
, GLuint index
)
1115 GET_CURRENT_CONTEXT(ctx
);
1116 _mesa_set_enablei(ctx
, cap
, index
, GL_TRUE
);
1120 GLboolean GLAPIENTRY
1121 _mesa_IsEnabledi( GLenum cap
, GLuint index
)
1123 GET_CURRENT_CONTEXT(ctx
);
1124 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1127 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1128 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1132 return (ctx
->Color
.BlendEnabled
>> index
) & 1;
1133 case GL_SCISSOR_TEST
:
1134 if (index
>= ctx
->Const
.MaxViewports
) {
1135 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1139 return (ctx
->Scissor
.EnableFlags
>> index
) & 1;
1141 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabledIndexed(cap=%s)",
1142 _mesa_enum_to_string(cap
));
1150 #undef CHECK_EXTENSION
1151 #define CHECK_EXTENSION(EXTNAME) \
1152 if (!ctx->Extensions.EXTNAME) { \
1153 goto invalid_enum_error; \
1156 #undef CHECK_EXTENSION2
1157 #define CHECK_EXTENSION2(EXT1, EXT2) \
1158 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1159 goto invalid_enum_error; \
1164 * Helper function to determine whether a texture target is enabled.
1167 is_texture_enabled(struct gl_context
*ctx
, GLbitfield bit
)
1169 const struct gl_texture_unit
*const texUnit
=
1170 &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1171 return (texUnit
->Enabled
& bit
) ? GL_TRUE
: GL_FALSE
;
1176 * Return simple enable/disable state.
1178 * \param cap state variable to query.
1180 * Returns the state of the specified capability from the current GL context.
1181 * For the capabilities associated with extensions verifies that those
1182 * extensions are effectively present before reporting.
1184 GLboolean GLAPIENTRY
1185 _mesa_IsEnabled( GLenum cap
)
1187 GET_CURRENT_CONTEXT(ctx
);
1188 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1192 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1193 goto invalid_enum_error
;
1194 return ctx
->Color
.AlphaEnabled
;
1195 case GL_AUTO_NORMAL
:
1196 if (ctx
->API
!= API_OPENGL_COMPAT
)
1197 goto invalid_enum_error
;
1198 return ctx
->Eval
.AutoNormal
;
1200 return ctx
->Color
.BlendEnabled
& 1; /* return state for buffer[0] */
1201 case GL_CLIP_DISTANCE0
: /* aka GL_CLIP_PLANE0 */
1202 case GL_CLIP_DISTANCE1
:
1203 case GL_CLIP_DISTANCE2
:
1204 case GL_CLIP_DISTANCE3
:
1205 case GL_CLIP_DISTANCE4
:
1206 case GL_CLIP_DISTANCE5
:
1207 case GL_CLIP_DISTANCE6
:
1208 case GL_CLIP_DISTANCE7
: {
1209 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
1211 if (p
>= ctx
->Const
.MaxClipPlanes
)
1212 goto invalid_enum_error
;
1214 return (ctx
->Transform
.ClipPlanesEnabled
>> p
) & 1;
1216 case GL_COLOR_MATERIAL
:
1217 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1218 goto invalid_enum_error
;
1219 return ctx
->Light
.ColorMaterialEnabled
;
1221 return ctx
->Polygon
.CullFlag
;
1222 case GL_DEBUG_OUTPUT
:
1223 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
:
1224 return (GLboolean
) _mesa_get_debug_state_int(ctx
, cap
);
1226 return ctx
->Depth
.Test
;
1228 return ctx
->Color
.DitherFlag
;
1230 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1231 goto invalid_enum_error
;
1232 return ctx
->Fog
.Enabled
;
1234 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1235 goto invalid_enum_error
;
1236 return ctx
->Light
.Enabled
;
1245 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1246 goto invalid_enum_error
;
1247 return ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
;
1248 case GL_LINE_SMOOTH
:
1249 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1250 goto invalid_enum_error
;
1251 return ctx
->Line
.SmoothFlag
;
1252 case GL_LINE_STIPPLE
:
1253 if (ctx
->API
!= API_OPENGL_COMPAT
)
1254 goto invalid_enum_error
;
1255 return ctx
->Line
.StippleFlag
;
1256 case GL_INDEX_LOGIC_OP
:
1257 if (ctx
->API
!= API_OPENGL_COMPAT
)
1258 goto invalid_enum_error
;
1259 return ctx
->Color
.IndexLogicOpEnabled
;
1260 case GL_COLOR_LOGIC_OP
:
1261 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1262 goto invalid_enum_error
;
1263 return ctx
->Color
.ColorLogicOpEnabled
;
1264 case GL_MAP1_COLOR_4
:
1265 if (ctx
->API
!= API_OPENGL_COMPAT
)
1266 goto invalid_enum_error
;
1267 return ctx
->Eval
.Map1Color4
;
1269 if (ctx
->API
!= API_OPENGL_COMPAT
)
1270 goto invalid_enum_error
;
1271 return ctx
->Eval
.Map1Index
;
1272 case GL_MAP1_NORMAL
:
1273 if (ctx
->API
!= API_OPENGL_COMPAT
)
1274 goto invalid_enum_error
;
1275 return ctx
->Eval
.Map1Normal
;
1276 case GL_MAP1_TEXTURE_COORD_1
:
1277 if (ctx
->API
!= API_OPENGL_COMPAT
)
1278 goto invalid_enum_error
;
1279 return ctx
->Eval
.Map1TextureCoord1
;
1280 case GL_MAP1_TEXTURE_COORD_2
:
1281 if (ctx
->API
!= API_OPENGL_COMPAT
)
1282 goto invalid_enum_error
;
1283 return ctx
->Eval
.Map1TextureCoord2
;
1284 case GL_MAP1_TEXTURE_COORD_3
:
1285 if (ctx
->API
!= API_OPENGL_COMPAT
)
1286 goto invalid_enum_error
;
1287 return ctx
->Eval
.Map1TextureCoord3
;
1288 case GL_MAP1_TEXTURE_COORD_4
:
1289 if (ctx
->API
!= API_OPENGL_COMPAT
)
1290 goto invalid_enum_error
;
1291 return ctx
->Eval
.Map1TextureCoord4
;
1292 case GL_MAP1_VERTEX_3
:
1293 if (ctx
->API
!= API_OPENGL_COMPAT
)
1294 goto invalid_enum_error
;
1295 return ctx
->Eval
.Map1Vertex3
;
1296 case GL_MAP1_VERTEX_4
:
1297 if (ctx
->API
!= API_OPENGL_COMPAT
)
1298 goto invalid_enum_error
;
1299 return ctx
->Eval
.Map1Vertex4
;
1300 case GL_MAP2_COLOR_4
:
1301 if (ctx
->API
!= API_OPENGL_COMPAT
)
1302 goto invalid_enum_error
;
1303 return ctx
->Eval
.Map2Color4
;
1305 if (ctx
->API
!= API_OPENGL_COMPAT
)
1306 goto invalid_enum_error
;
1307 return ctx
->Eval
.Map2Index
;
1308 case GL_MAP2_NORMAL
:
1309 if (ctx
->API
!= API_OPENGL_COMPAT
)
1310 goto invalid_enum_error
;
1311 return ctx
->Eval
.Map2Normal
;
1312 case GL_MAP2_TEXTURE_COORD_1
:
1313 if (ctx
->API
!= API_OPENGL_COMPAT
)
1314 goto invalid_enum_error
;
1315 return ctx
->Eval
.Map2TextureCoord1
;
1316 case GL_MAP2_TEXTURE_COORD_2
:
1317 if (ctx
->API
!= API_OPENGL_COMPAT
)
1318 goto invalid_enum_error
;
1319 return ctx
->Eval
.Map2TextureCoord2
;
1320 case GL_MAP2_TEXTURE_COORD_3
:
1321 if (ctx
->API
!= API_OPENGL_COMPAT
)
1322 goto invalid_enum_error
;
1323 return ctx
->Eval
.Map2TextureCoord3
;
1324 case GL_MAP2_TEXTURE_COORD_4
:
1325 if (ctx
->API
!= API_OPENGL_COMPAT
)
1326 goto invalid_enum_error
;
1327 return ctx
->Eval
.Map2TextureCoord4
;
1328 case GL_MAP2_VERTEX_3
:
1329 if (ctx
->API
!= API_OPENGL_COMPAT
)
1330 goto invalid_enum_error
;
1331 return ctx
->Eval
.Map2Vertex3
;
1332 case GL_MAP2_VERTEX_4
:
1333 if (ctx
->API
!= API_OPENGL_COMPAT
)
1334 goto invalid_enum_error
;
1335 return ctx
->Eval
.Map2Vertex4
;
1337 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1338 goto invalid_enum_error
;
1339 return ctx
->Transform
.Normalize
;
1340 case GL_POINT_SMOOTH
:
1341 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1342 goto invalid_enum_error
;
1343 return ctx
->Point
.SmoothFlag
;
1344 case GL_POLYGON_SMOOTH
:
1345 if (!_mesa_is_desktop_gl(ctx
))
1346 goto invalid_enum_error
;
1347 return ctx
->Polygon
.SmoothFlag
;
1348 case GL_POLYGON_STIPPLE
:
1349 if (ctx
->API
!= API_OPENGL_COMPAT
)
1350 goto invalid_enum_error
;
1351 return ctx
->Polygon
.StippleFlag
;
1352 case GL_POLYGON_OFFSET_POINT
:
1353 if (!_mesa_is_desktop_gl(ctx
))
1354 goto invalid_enum_error
;
1355 return ctx
->Polygon
.OffsetPoint
;
1356 case GL_POLYGON_OFFSET_LINE
:
1357 if (!_mesa_is_desktop_gl(ctx
))
1358 goto invalid_enum_error
;
1359 return ctx
->Polygon
.OffsetLine
;
1360 case GL_POLYGON_OFFSET_FILL
:
1361 return ctx
->Polygon
.OffsetFill
;
1362 case GL_RESCALE_NORMAL_EXT
:
1363 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1364 goto invalid_enum_error
;
1365 return ctx
->Transform
.RescaleNormals
;
1366 case GL_SCISSOR_TEST
:
1367 return ctx
->Scissor
.EnableFlags
& 1; /* return state for index 0 */
1368 case GL_STENCIL_TEST
:
1369 return ctx
->Stencil
.Enabled
;
1371 if (ctx
->API
!= API_OPENGL_COMPAT
)
1372 goto invalid_enum_error
;
1373 return is_texture_enabled(ctx
, TEXTURE_1D_BIT
);
1375 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1376 goto invalid_enum_error
;
1377 return is_texture_enabled(ctx
, TEXTURE_2D_BIT
);
1379 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1380 goto invalid_enum_error
;
1381 return is_texture_enabled(ctx
, TEXTURE_3D_BIT
);
1382 case GL_TEXTURE_GEN_S
:
1383 case GL_TEXTURE_GEN_T
:
1384 case GL_TEXTURE_GEN_R
:
1385 case GL_TEXTURE_GEN_Q
:
1387 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1389 if (ctx
->API
!= API_OPENGL_COMPAT
)
1390 goto invalid_enum_error
;
1393 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
1394 return (texUnit
->TexGenEnabled
& coordBit
) ? GL_TRUE
: GL_FALSE
;
1398 case GL_TEXTURE_GEN_STR_OES
:
1400 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1402 if (ctx
->API
!= API_OPENGLES
)
1403 goto invalid_enum_error
;
1406 return (texUnit
->TexGenEnabled
& STR_BITS
) == STR_BITS
1407 ? GL_TRUE
: GL_FALSE
;
1411 /* client-side state */
1412 case GL_VERTEX_ARRAY
:
1413 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1414 goto invalid_enum_error
;
1415 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
;
1416 case GL_NORMAL_ARRAY
:
1417 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1418 goto invalid_enum_error
;
1419 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
;
1420 case GL_COLOR_ARRAY
:
1421 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1422 goto invalid_enum_error
;
1423 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
;
1424 case GL_INDEX_ARRAY
:
1425 if (ctx
->API
!= API_OPENGL_COMPAT
)
1426 goto invalid_enum_error
;
1427 return ctx
->Array
.VAO
->
1428 VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
;
1429 case GL_TEXTURE_COORD_ARRAY
:
1430 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1431 goto invalid_enum_error
;
1432 return ctx
->Array
.VAO
->
1433 VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Enabled
;
1434 case GL_EDGE_FLAG_ARRAY
:
1435 if (ctx
->API
!= API_OPENGL_COMPAT
)
1436 goto invalid_enum_error
;
1437 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
;
1438 case GL_FOG_COORDINATE_ARRAY_EXT
:
1439 if (ctx
->API
!= API_OPENGL_COMPAT
)
1440 goto invalid_enum_error
;
1441 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
;
1442 case GL_SECONDARY_COLOR_ARRAY_EXT
:
1443 if (ctx
->API
!= API_OPENGL_COMPAT
)
1444 goto invalid_enum_error
;
1445 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
;
1446 case GL_POINT_SIZE_ARRAY_OES
:
1447 if (ctx
->API
!= API_OPENGLES
)
1448 goto invalid_enum_error
;
1449 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
;
1451 /* GL_ARB_texture_cube_map */
1452 case GL_TEXTURE_CUBE_MAP_ARB
:
1453 CHECK_EXTENSION(ARB_texture_cube_map
);
1454 return is_texture_enabled(ctx
, TEXTURE_CUBE_BIT
);
1456 /* GL_EXT_secondary_color */
1457 case GL_COLOR_SUM_EXT
:
1458 if (ctx
->API
!= API_OPENGL_COMPAT
)
1459 goto invalid_enum_error
;
1460 return ctx
->Fog
.ColorSumEnabled
;
1462 /* GL_ARB_multisample */
1463 case GL_MULTISAMPLE_ARB
:
1464 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1465 goto invalid_enum_error
;
1466 return ctx
->Multisample
.Enabled
;
1467 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
1468 return ctx
->Multisample
.SampleAlphaToCoverage
;
1469 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
1470 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1471 goto invalid_enum_error
;
1472 return ctx
->Multisample
.SampleAlphaToOne
;
1473 case GL_SAMPLE_COVERAGE_ARB
:
1474 return ctx
->Multisample
.SampleCoverage
;
1475 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
1476 if (!_mesa_is_desktop_gl(ctx
))
1477 goto invalid_enum_error
;
1478 return ctx
->Multisample
.SampleCoverageInvert
;
1480 /* GL_IBM_rasterpos_clip */
1481 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
1482 if (ctx
->API
!= API_OPENGL_COMPAT
)
1483 goto invalid_enum_error
;
1484 return ctx
->Transform
.RasterPositionUnclipped
;
1486 /* GL_NV_point_sprite */
1487 case GL_POINT_SPRITE_NV
:
1488 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1489 goto invalid_enum_error
;
1490 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
)
1491 return ctx
->Point
.PointSprite
;
1493 case GL_VERTEX_PROGRAM_ARB
:
1494 if (ctx
->API
!= API_OPENGL_COMPAT
)
1495 goto invalid_enum_error
;
1496 CHECK_EXTENSION(ARB_vertex_program
);
1497 return ctx
->VertexProgram
.Enabled
;
1498 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
1499 /* This was added with ARB_vertex_program, but it is also used with
1500 * GLSL vertex shaders on desktop.
1502 if (!_mesa_is_desktop_gl(ctx
))
1503 goto invalid_enum_error
;
1504 CHECK_EXTENSION(ARB_vertex_program
);
1505 return ctx
->VertexProgram
.PointSizeEnabled
;
1506 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
1507 if (ctx
->API
!= API_OPENGL_COMPAT
)
1508 goto invalid_enum_error
;
1509 CHECK_EXTENSION(ARB_vertex_program
);
1510 return ctx
->VertexProgram
.TwoSideEnabled
;
1512 /* GL_NV_texture_rectangle */
1513 case GL_TEXTURE_RECTANGLE_NV
:
1514 if (ctx
->API
!= API_OPENGL_COMPAT
)
1515 goto invalid_enum_error
;
1516 CHECK_EXTENSION(NV_texture_rectangle
);
1517 return is_texture_enabled(ctx
, TEXTURE_RECT_BIT
);
1519 /* GL_EXT_stencil_two_side */
1520 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
1521 if (ctx
->API
!= API_OPENGL_COMPAT
)
1522 goto invalid_enum_error
;
1523 CHECK_EXTENSION(EXT_stencil_two_side
);
1524 return ctx
->Stencil
.TestTwoSide
;
1526 case GL_FRAGMENT_PROGRAM_ARB
:
1527 if (ctx
->API
!= API_OPENGL_COMPAT
)
1528 goto invalid_enum_error
;
1529 return ctx
->FragmentProgram
.Enabled
;
1531 /* GL_EXT_depth_bounds_test */
1532 case GL_DEPTH_BOUNDS_TEST_EXT
:
1533 if (!_mesa_is_desktop_gl(ctx
))
1534 goto invalid_enum_error
;
1535 CHECK_EXTENSION(EXT_depth_bounds_test
);
1536 return ctx
->Depth
.BoundsTest
;
1538 /* GL_ARB_depth_clamp */
1539 case GL_DEPTH_CLAMP
:
1540 if (!_mesa_is_desktop_gl(ctx
))
1541 goto invalid_enum_error
;
1542 CHECK_EXTENSION(ARB_depth_clamp
);
1543 return ctx
->Transform
.DepthClamp
;
1545 case GL_FRAGMENT_SHADER_ATI
:
1546 if (ctx
->API
!= API_OPENGL_COMPAT
)
1547 goto invalid_enum_error
;
1548 CHECK_EXTENSION(ATI_fragment_shader
);
1549 return ctx
->ATIFragmentShader
.Enabled
;
1551 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1552 if (!_mesa_is_desktop_gl(ctx
))
1553 goto invalid_enum_error
;
1554 CHECK_EXTENSION(ARB_seamless_cube_map
);
1555 return ctx
->Texture
.CubeMapSeamless
;
1557 case GL_RASTERIZER_DISCARD
:
1558 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1559 goto invalid_enum_error
;
1560 CHECK_EXTENSION(EXT_transform_feedback
);
1561 return ctx
->RasterDiscard
;
1563 /* GL_NV_primitive_restart */
1564 case GL_PRIMITIVE_RESTART_NV
:
1565 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.NV_primitive_restart
) {
1566 goto invalid_enum_error
;
1568 return ctx
->Array
.PrimitiveRestart
;
1570 /* GL 3.1 primitive restart */
1571 case GL_PRIMITIVE_RESTART
:
1572 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
1573 goto invalid_enum_error
;
1575 return ctx
->Array
.PrimitiveRestart
;
1577 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
1578 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
) {
1579 goto invalid_enum_error
;
1581 return ctx
->Array
.PrimitiveRestartFixedIndex
;
1583 /* GL3.0 - GL_framebuffer_sRGB */
1584 case GL_FRAMEBUFFER_SRGB_EXT
:
1585 if (!_mesa_is_desktop_gl(ctx
))
1586 goto invalid_enum_error
;
1587 CHECK_EXTENSION(EXT_framebuffer_sRGB
);
1588 return ctx
->Color
.sRGBEnabled
;
1590 /* GL_OES_EGL_image_external */
1591 case GL_TEXTURE_EXTERNAL_OES
:
1592 if (!_mesa_is_gles(ctx
))
1593 goto invalid_enum_error
;
1594 CHECK_EXTENSION(OES_EGL_image_external
);
1595 return is_texture_enabled(ctx
, TEXTURE_EXTERNAL_BIT
);
1597 /* ARB_texture_multisample */
1598 case GL_SAMPLE_MASK
:
1599 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
1600 goto invalid_enum_error
;
1601 CHECK_EXTENSION(ARB_texture_multisample
);
1602 return ctx
->Multisample
.SampleMask
;
1604 /* ARB_sample_shading */
1605 case GL_SAMPLE_SHADING
:
1606 if (!_mesa_is_desktop_gl(ctx
))
1607 goto invalid_enum_error
;
1608 CHECK_EXTENSION(ARB_sample_shading
);
1609 return ctx
->Multisample
.SampleShading
;
1612 goto invalid_enum_error
;
1618 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabled(%s)",
1619 _mesa_enum_to_string(cap
));