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
*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_lookup_enum_by_nr(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_lookup_enum_by_nr(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
:
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 if (!_mesa_is_desktop_gl(ctx
))
371 goto invalid_enum_error
;
372 ctx
->Debug
.DebugOutput
= state
;
374 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
:
375 if (!_mesa_is_desktop_gl(ctx
))
376 goto invalid_enum_error
;
377 ctx
->Debug
.SyncOutput
= state
;
380 if (ctx
->Color
.DitherFlag
== state
)
382 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
383 ctx
->Color
.DitherFlag
= state
;
386 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
387 goto invalid_enum_error
;
388 if (ctx
->Fog
.Enabled
== state
)
390 FLUSH_VERTICES(ctx
, _NEW_FOG
);
391 ctx
->Fog
.Enabled
= state
;
401 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
402 goto invalid_enum_error
;
403 if (ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
== state
)
405 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
406 ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
= state
;
408 insert_at_tail(&ctx
->Light
.EnabledList
,
409 &ctx
->Light
.Light
[cap
-GL_LIGHT0
]);
412 remove_from_list(&ctx
->Light
.Light
[cap
-GL_LIGHT0
]);
416 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
417 goto invalid_enum_error
;
418 if (ctx
->Light
.Enabled
== state
)
420 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
421 ctx
->Light
.Enabled
= state
;
424 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
425 goto invalid_enum_error
;
426 if (ctx
->Line
.SmoothFlag
== state
)
428 FLUSH_VERTICES(ctx
, _NEW_LINE
);
429 ctx
->Line
.SmoothFlag
= state
;
431 case GL_LINE_STIPPLE
:
432 if (ctx
->API
!= API_OPENGL_COMPAT
)
433 goto invalid_enum_error
;
434 if (ctx
->Line
.StippleFlag
== state
)
436 FLUSH_VERTICES(ctx
, _NEW_LINE
);
437 ctx
->Line
.StippleFlag
= state
;
439 case GL_INDEX_LOGIC_OP
:
440 if (ctx
->API
!= API_OPENGL_COMPAT
)
441 goto invalid_enum_error
;
442 if (ctx
->Color
.IndexLogicOpEnabled
== state
)
444 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
445 ctx
->Color
.IndexLogicOpEnabled
= state
;
447 case GL_COLOR_LOGIC_OP
:
448 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
449 goto invalid_enum_error
;
450 if (ctx
->Color
.ColorLogicOpEnabled
== state
)
452 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
453 ctx
->Color
.ColorLogicOpEnabled
= state
;
455 case GL_MAP1_COLOR_4
:
456 if (ctx
->API
!= API_OPENGL_COMPAT
)
457 goto invalid_enum_error
;
458 if (ctx
->Eval
.Map1Color4
== state
)
460 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
461 ctx
->Eval
.Map1Color4
= state
;
464 if (ctx
->API
!= API_OPENGL_COMPAT
)
465 goto invalid_enum_error
;
466 if (ctx
->Eval
.Map1Index
== state
)
468 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
469 ctx
->Eval
.Map1Index
= state
;
472 if (ctx
->API
!= API_OPENGL_COMPAT
)
473 goto invalid_enum_error
;
474 if (ctx
->Eval
.Map1Normal
== state
)
476 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
477 ctx
->Eval
.Map1Normal
= state
;
479 case GL_MAP1_TEXTURE_COORD_1
:
480 if (ctx
->API
!= API_OPENGL_COMPAT
)
481 goto invalid_enum_error
;
482 if (ctx
->Eval
.Map1TextureCoord1
== state
)
484 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
485 ctx
->Eval
.Map1TextureCoord1
= state
;
487 case GL_MAP1_TEXTURE_COORD_2
:
488 if (ctx
->API
!= API_OPENGL_COMPAT
)
489 goto invalid_enum_error
;
490 if (ctx
->Eval
.Map1TextureCoord2
== state
)
492 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
493 ctx
->Eval
.Map1TextureCoord2
= state
;
495 case GL_MAP1_TEXTURE_COORD_3
:
496 if (ctx
->API
!= API_OPENGL_COMPAT
)
497 goto invalid_enum_error
;
498 if (ctx
->Eval
.Map1TextureCoord3
== state
)
500 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
501 ctx
->Eval
.Map1TextureCoord3
= state
;
503 case GL_MAP1_TEXTURE_COORD_4
:
504 if (ctx
->API
!= API_OPENGL_COMPAT
)
505 goto invalid_enum_error
;
506 if (ctx
->Eval
.Map1TextureCoord4
== state
)
508 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
509 ctx
->Eval
.Map1TextureCoord4
= state
;
511 case GL_MAP1_VERTEX_3
:
512 if (ctx
->API
!= API_OPENGL_COMPAT
)
513 goto invalid_enum_error
;
514 if (ctx
->Eval
.Map1Vertex3
== state
)
516 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
517 ctx
->Eval
.Map1Vertex3
= state
;
519 case GL_MAP1_VERTEX_4
:
520 if (ctx
->API
!= API_OPENGL_COMPAT
)
521 goto invalid_enum_error
;
522 if (ctx
->Eval
.Map1Vertex4
== state
)
524 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
525 ctx
->Eval
.Map1Vertex4
= state
;
527 case GL_MAP2_COLOR_4
:
528 if (ctx
->API
!= API_OPENGL_COMPAT
)
529 goto invalid_enum_error
;
530 if (ctx
->Eval
.Map2Color4
== state
)
532 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
533 ctx
->Eval
.Map2Color4
= state
;
536 if (ctx
->API
!= API_OPENGL_COMPAT
)
537 goto invalid_enum_error
;
538 if (ctx
->Eval
.Map2Index
== state
)
540 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
541 ctx
->Eval
.Map2Index
= state
;
544 if (ctx
->API
!= API_OPENGL_COMPAT
)
545 goto invalid_enum_error
;
546 if (ctx
->Eval
.Map2Normal
== state
)
548 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
549 ctx
->Eval
.Map2Normal
= state
;
551 case GL_MAP2_TEXTURE_COORD_1
:
552 if (ctx
->API
!= API_OPENGL_COMPAT
)
553 goto invalid_enum_error
;
554 if (ctx
->Eval
.Map2TextureCoord1
== state
)
556 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
557 ctx
->Eval
.Map2TextureCoord1
= state
;
559 case GL_MAP2_TEXTURE_COORD_2
:
560 if (ctx
->API
!= API_OPENGL_COMPAT
)
561 goto invalid_enum_error
;
562 if (ctx
->Eval
.Map2TextureCoord2
== state
)
564 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
565 ctx
->Eval
.Map2TextureCoord2
= state
;
567 case GL_MAP2_TEXTURE_COORD_3
:
568 if (ctx
->API
!= API_OPENGL_COMPAT
)
569 goto invalid_enum_error
;
570 if (ctx
->Eval
.Map2TextureCoord3
== state
)
572 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
573 ctx
->Eval
.Map2TextureCoord3
= state
;
575 case GL_MAP2_TEXTURE_COORD_4
:
576 if (ctx
->API
!= API_OPENGL_COMPAT
)
577 goto invalid_enum_error
;
578 if (ctx
->Eval
.Map2TextureCoord4
== state
)
580 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
581 ctx
->Eval
.Map2TextureCoord4
= state
;
583 case GL_MAP2_VERTEX_3
:
584 if (ctx
->API
!= API_OPENGL_COMPAT
)
585 goto invalid_enum_error
;
586 if (ctx
->Eval
.Map2Vertex3
== state
)
588 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
589 ctx
->Eval
.Map2Vertex3
= state
;
591 case GL_MAP2_VERTEX_4
:
592 if (ctx
->API
!= API_OPENGL_COMPAT
)
593 goto invalid_enum_error
;
594 if (ctx
->Eval
.Map2Vertex4
== state
)
596 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
597 ctx
->Eval
.Map2Vertex4
= state
;
600 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
601 goto invalid_enum_error
;
602 if (ctx
->Transform
.Normalize
== state
)
604 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
605 ctx
->Transform
.Normalize
= state
;
607 case GL_POINT_SMOOTH
:
608 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
609 goto invalid_enum_error
;
610 if (ctx
->Point
.SmoothFlag
== state
)
612 FLUSH_VERTICES(ctx
, _NEW_POINT
);
613 ctx
->Point
.SmoothFlag
= state
;
615 case GL_POLYGON_SMOOTH
:
616 if (!_mesa_is_desktop_gl(ctx
))
617 goto invalid_enum_error
;
618 if (ctx
->Polygon
.SmoothFlag
== state
)
620 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
621 ctx
->Polygon
.SmoothFlag
= state
;
623 case GL_POLYGON_STIPPLE
:
624 if (ctx
->API
!= API_OPENGL_COMPAT
)
625 goto invalid_enum_error
;
626 if (ctx
->Polygon
.StippleFlag
== state
)
628 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
629 ctx
->Polygon
.StippleFlag
= state
;
631 case GL_POLYGON_OFFSET_POINT
:
632 if (!_mesa_is_desktop_gl(ctx
))
633 goto invalid_enum_error
;
634 if (ctx
->Polygon
.OffsetPoint
== state
)
636 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
637 ctx
->Polygon
.OffsetPoint
= state
;
639 case GL_POLYGON_OFFSET_LINE
:
640 if (!_mesa_is_desktop_gl(ctx
))
641 goto invalid_enum_error
;
642 if (ctx
->Polygon
.OffsetLine
== state
)
644 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
645 ctx
->Polygon
.OffsetLine
= state
;
647 case GL_POLYGON_OFFSET_FILL
:
648 if (ctx
->Polygon
.OffsetFill
== state
)
650 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
651 ctx
->Polygon
.OffsetFill
= state
;
653 case GL_RESCALE_NORMAL_EXT
:
654 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
655 goto invalid_enum_error
;
656 if (ctx
->Transform
.RescaleNormals
== state
)
658 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
659 ctx
->Transform
.RescaleNormals
= state
;
661 case GL_SCISSOR_TEST
:
663 /* Must expand glEnable to all scissors */
664 GLbitfield newEnabled
=
665 state
* ((1 << ctx
->Const
.MaxViewports
) - 1);
666 if (newEnabled
!= ctx
->Scissor
.EnableFlags
) {
667 FLUSH_VERTICES(ctx
, _NEW_SCISSOR
);
668 ctx
->Scissor
.EnableFlags
= newEnabled
;
672 case GL_STENCIL_TEST
:
673 if (ctx
->Stencil
.Enabled
== state
)
675 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
676 ctx
->Stencil
.Enabled
= state
;
679 if (ctx
->API
!= API_OPENGL_COMPAT
)
680 goto invalid_enum_error
;
681 if (!enable_texture(ctx
, state
, TEXTURE_1D_BIT
)) {
686 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
687 goto invalid_enum_error
;
688 if (!enable_texture(ctx
, state
, TEXTURE_2D_BIT
)) {
693 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
694 goto invalid_enum_error
;
695 if (!enable_texture(ctx
, state
, TEXTURE_3D_BIT
)) {
699 case GL_TEXTURE_GEN_S
:
700 case GL_TEXTURE_GEN_T
:
701 case GL_TEXTURE_GEN_R
:
702 case GL_TEXTURE_GEN_Q
:
704 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
706 if (ctx
->API
!= API_OPENGL_COMPAT
)
707 goto invalid_enum_error
;
710 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
711 GLbitfield newenabled
= texUnit
->TexGenEnabled
& ~coordBit
;
713 newenabled
|= coordBit
;
714 if (texUnit
->TexGenEnabled
== newenabled
)
716 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
717 texUnit
->TexGenEnabled
= newenabled
;
722 case GL_TEXTURE_GEN_STR_OES
:
723 /* disable S, T, and R at the same time */
725 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
727 if (ctx
->API
!= API_OPENGLES
)
728 goto invalid_enum_error
;
732 texUnit
->TexGenEnabled
& ~STR_BITS
;
734 newenabled
|= STR_BITS
;
735 if (texUnit
->TexGenEnabled
== newenabled
)
737 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
738 texUnit
->TexGenEnabled
= newenabled
;
743 /* client-side state */
744 case GL_VERTEX_ARRAY
:
745 case GL_NORMAL_ARRAY
:
748 case GL_TEXTURE_COORD_ARRAY
:
749 case GL_EDGE_FLAG_ARRAY
:
750 case GL_FOG_COORDINATE_ARRAY_EXT
:
751 case GL_SECONDARY_COLOR_ARRAY_EXT
:
752 case GL_POINT_SIZE_ARRAY_OES
:
753 client_state( ctx
, cap
, state
);
756 /* GL_ARB_texture_cube_map */
757 case GL_TEXTURE_CUBE_MAP_ARB
:
758 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
759 goto invalid_enum_error
;
760 CHECK_EXTENSION(ARB_texture_cube_map
, cap
);
761 if (!enable_texture(ctx
, state
, TEXTURE_CUBE_BIT
)) {
766 /* GL_EXT_secondary_color */
767 case GL_COLOR_SUM_EXT
:
768 if (ctx
->API
!= API_OPENGL_COMPAT
)
769 goto invalid_enum_error
;
770 if (ctx
->Fog
.ColorSumEnabled
== state
)
772 FLUSH_VERTICES(ctx
, _NEW_FOG
);
773 ctx
->Fog
.ColorSumEnabled
= state
;
776 /* GL_ARB_multisample */
777 case GL_MULTISAMPLE_ARB
:
778 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
779 goto invalid_enum_error
;
780 _mesa_set_multisample(ctx
, state
);
782 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
783 if (ctx
->Multisample
.SampleAlphaToCoverage
== state
)
785 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
786 ctx
->Multisample
.SampleAlphaToCoverage
= state
;
788 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
789 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
790 goto invalid_enum_error
;
791 if (ctx
->Multisample
.SampleAlphaToOne
== state
)
793 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
794 ctx
->Multisample
.SampleAlphaToOne
= state
;
796 case GL_SAMPLE_COVERAGE_ARB
:
797 if (ctx
->Multisample
.SampleCoverage
== state
)
799 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
800 ctx
->Multisample
.SampleCoverage
= state
;
802 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
803 if (!_mesa_is_desktop_gl(ctx
))
804 goto invalid_enum_error
;
805 if (ctx
->Multisample
.SampleCoverageInvert
== state
)
807 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
808 ctx
->Multisample
.SampleCoverageInvert
= state
;
811 /* GL_ARB_sample_shading */
812 case GL_SAMPLE_SHADING
:
813 if (!_mesa_is_desktop_gl(ctx
))
814 goto invalid_enum_error
;
815 CHECK_EXTENSION(ARB_sample_shading
, cap
);
816 if (ctx
->Multisample
.SampleShading
== state
)
818 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
819 ctx
->Multisample
.SampleShading
= state
;
822 /* GL_IBM_rasterpos_clip */
823 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
824 if (ctx
->API
!= API_OPENGL_COMPAT
)
825 goto invalid_enum_error
;
826 if (ctx
->Transform
.RasterPositionUnclipped
== state
)
828 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
829 ctx
->Transform
.RasterPositionUnclipped
= state
;
832 /* GL_NV_point_sprite */
833 case GL_POINT_SPRITE_NV
:
834 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
835 goto invalid_enum_error
;
836 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
, cap
);
837 if (ctx
->Point
.PointSprite
== state
)
839 FLUSH_VERTICES(ctx
, _NEW_POINT
);
840 ctx
->Point
.PointSprite
= state
;
843 case GL_VERTEX_PROGRAM_ARB
:
844 if (ctx
->API
!= API_OPENGL_COMPAT
)
845 goto invalid_enum_error
;
846 CHECK_EXTENSION(ARB_vertex_program
, cap
);
847 if (ctx
->VertexProgram
.Enabled
== state
)
849 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
850 ctx
->VertexProgram
.Enabled
= state
;
852 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
853 /* This was added with ARB_vertex_program, but it is also used with
854 * GLSL vertex shaders on desktop.
856 if (!_mesa_is_desktop_gl(ctx
))
857 goto invalid_enum_error
;
858 CHECK_EXTENSION(ARB_vertex_program
, cap
);
859 if (ctx
->VertexProgram
.PointSizeEnabled
== state
)
861 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
862 ctx
->VertexProgram
.PointSizeEnabled
= state
;
864 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
865 if (ctx
->API
!= API_OPENGL_COMPAT
)
866 goto invalid_enum_error
;
867 CHECK_EXTENSION(ARB_vertex_program
, cap
);
868 if (ctx
->VertexProgram
.TwoSideEnabled
== state
)
870 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
871 ctx
->VertexProgram
.TwoSideEnabled
= state
;
874 /* GL_NV_texture_rectangle */
875 case GL_TEXTURE_RECTANGLE_NV
:
876 if (ctx
->API
!= API_OPENGL_COMPAT
)
877 goto invalid_enum_error
;
878 CHECK_EXTENSION(NV_texture_rectangle
, cap
);
879 if (!enable_texture(ctx
, state
, TEXTURE_RECT_BIT
)) {
884 /* GL_EXT_stencil_two_side */
885 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
886 if (ctx
->API
!= API_OPENGL_COMPAT
)
887 goto invalid_enum_error
;
888 CHECK_EXTENSION(EXT_stencil_two_side
, cap
);
889 if (ctx
->Stencil
.TestTwoSide
== state
)
891 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
892 ctx
->Stencil
.TestTwoSide
= state
;
894 ctx
->Stencil
._BackFace
= 2;
896 ctx
->Stencil
._BackFace
= 1;
900 case GL_FRAGMENT_PROGRAM_ARB
:
901 if (ctx
->API
!= API_OPENGL_COMPAT
)
902 goto invalid_enum_error
;
903 CHECK_EXTENSION(ARB_fragment_program
, cap
);
904 if (ctx
->FragmentProgram
.Enabled
== state
)
906 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
907 ctx
->FragmentProgram
.Enabled
= state
;
910 /* GL_EXT_depth_bounds_test */
911 case GL_DEPTH_BOUNDS_TEST_EXT
:
912 if (!_mesa_is_desktop_gl(ctx
))
913 goto invalid_enum_error
;
914 CHECK_EXTENSION(EXT_depth_bounds_test
, cap
);
915 if (ctx
->Depth
.BoundsTest
== state
)
917 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
918 ctx
->Depth
.BoundsTest
= state
;
922 if (!_mesa_is_desktop_gl(ctx
))
923 goto invalid_enum_error
;
924 CHECK_EXTENSION(ARB_depth_clamp
, cap
);
925 if (ctx
->Transform
.DepthClamp
== state
)
927 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
928 ctx
->Transform
.DepthClamp
= state
;
931 case GL_FRAGMENT_SHADER_ATI
:
932 if (ctx
->API
!= API_OPENGL_COMPAT
)
933 goto invalid_enum_error
;
934 CHECK_EXTENSION(ATI_fragment_shader
, cap
);
935 if (ctx
->ATIFragmentShader
.Enabled
== state
)
937 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
938 ctx
->ATIFragmentShader
.Enabled
= state
;
941 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
942 if (!_mesa_is_desktop_gl(ctx
))
943 goto invalid_enum_error
;
944 CHECK_EXTENSION(ARB_seamless_cube_map
, cap
);
945 if (ctx
->Texture
.CubeMapSeamless
!= state
) {
946 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
947 ctx
->Texture
.CubeMapSeamless
= state
;
951 case GL_RASTERIZER_DISCARD
:
952 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
953 goto invalid_enum_error
;
954 CHECK_EXTENSION(EXT_transform_feedback
, cap
);
955 if (ctx
->RasterDiscard
!= state
) {
956 FLUSH_VERTICES(ctx
, 0);
957 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewRasterizerDiscard
;
958 ctx
->RasterDiscard
= state
;
962 /* GL 3.1 primitive restart. Note: this enum is different from
963 * GL_PRIMITIVE_RESTART_NV (which is client state).
965 case GL_PRIMITIVE_RESTART
:
966 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
967 goto invalid_enum_error
;
969 if (ctx
->Array
.PrimitiveRestart
!= state
) {
970 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
971 ctx
->Array
.PrimitiveRestart
= state
;
972 update_derived_primitive_restart_state(ctx
);
976 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
977 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
)
978 goto invalid_enum_error
;
979 if (ctx
->Array
.PrimitiveRestartFixedIndex
!= state
) {
980 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
981 ctx
->Array
.PrimitiveRestartFixedIndex
= state
;
982 update_derived_primitive_restart_state(ctx
);
986 /* GL3.0 - GL_framebuffer_sRGB */
987 case GL_FRAMEBUFFER_SRGB_EXT
:
988 if (!_mesa_is_desktop_gl(ctx
))
989 goto invalid_enum_error
;
990 CHECK_EXTENSION(EXT_framebuffer_sRGB
, cap
);
991 _mesa_set_framebuffer_srgb(ctx
, state
);
994 /* GL_OES_EGL_image_external */
995 case GL_TEXTURE_EXTERNAL_OES
:
996 if (!_mesa_is_gles(ctx
))
997 goto invalid_enum_error
;
998 CHECK_EXTENSION(OES_EGL_image_external
, cap
);
999 if (!enable_texture(ctx
, state
, TEXTURE_EXTERNAL_BIT
)) {
1004 /* ARB_texture_multisample */
1005 case GL_SAMPLE_MASK
:
1006 if (!_mesa_is_desktop_gl(ctx
))
1007 goto invalid_enum_error
;
1008 CHECK_EXTENSION(ARB_texture_multisample
, cap
);
1009 if (ctx
->Multisample
.SampleMask
== state
)
1011 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
1012 ctx
->Multisample
.SampleMask
= state
;
1016 goto invalid_enum_error
;
1019 if (ctx
->Driver
.Enable
) {
1020 ctx
->Driver
.Enable( ctx
, cap
, state
);
1026 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%s(%s)",
1027 state
? "Enable" : "Disable", _mesa_lookup_enum_by_nr(cap
));
1032 * Enable GL capability. Called by glEnable()
1033 * \param cap state to enable.
1036 _mesa_Enable( GLenum cap
)
1038 GET_CURRENT_CONTEXT(ctx
);
1040 _mesa_set_enable( ctx
, cap
, GL_TRUE
);
1045 * Disable GL capability. Called by glDisable()
1046 * \param cap state to disable.
1049 _mesa_Disable( GLenum cap
)
1051 GET_CURRENT_CONTEXT(ctx
);
1053 _mesa_set_enable( ctx
, cap
, GL_FALSE
);
1059 * Enable/disable an indexed state var.
1062 _mesa_set_enablei(struct gl_context
*ctx
, GLenum cap
,
1063 GLuint index
, GLboolean state
)
1065 ASSERT(state
== 0 || state
== 1);
1068 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
1069 goto invalid_enum_error
;
1071 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1072 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1073 state
? "glEnableIndexed" : "glDisableIndexed", index
);
1076 if (((ctx
->Color
.BlendEnabled
>> index
) & 1) != state
) {
1077 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
1079 ctx
->Color
.BlendEnabled
|= (1 << index
);
1081 ctx
->Color
.BlendEnabled
&= ~(1 << index
);
1084 case GL_SCISSOR_TEST
:
1085 if (index
>= ctx
->Const
.MaxViewports
) {
1086 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1087 state
? "glEnablei" : "glDisablei", index
);
1090 if (((ctx
->Scissor
.EnableFlags
>> index
) & 1) != state
) {
1091 FLUSH_VERTICES(ctx
, _NEW_SCISSOR
);
1093 ctx
->Scissor
.EnableFlags
|= (1 << index
);
1095 ctx
->Scissor
.EnableFlags
&= ~(1 << index
);
1099 goto invalid_enum_error
;
1104 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(cap=%s)",
1105 state
? "glEnablei" : "glDisablei",
1106 _mesa_lookup_enum_by_nr(cap
));
1111 _mesa_Disablei( GLenum cap
, GLuint index
)
1113 GET_CURRENT_CONTEXT(ctx
);
1114 _mesa_set_enablei(ctx
, cap
, index
, GL_FALSE
);
1119 _mesa_Enablei( GLenum cap
, GLuint index
)
1121 GET_CURRENT_CONTEXT(ctx
);
1122 _mesa_set_enablei(ctx
, cap
, index
, GL_TRUE
);
1126 GLboolean GLAPIENTRY
1127 _mesa_IsEnabledi( GLenum cap
, GLuint index
)
1129 GET_CURRENT_CONTEXT(ctx
);
1130 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1133 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1134 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1138 return (ctx
->Color
.BlendEnabled
>> index
) & 1;
1139 case GL_SCISSOR_TEST
:
1140 if (index
>= ctx
->Const
.MaxViewports
) {
1141 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1145 return (ctx
->Scissor
.EnableFlags
>> index
) & 1;
1147 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabledIndexed(cap=%s)",
1148 _mesa_lookup_enum_by_nr(cap
));
1156 #undef CHECK_EXTENSION
1157 #define CHECK_EXTENSION(EXTNAME) \
1158 if (!ctx->Extensions.EXTNAME) { \
1159 goto invalid_enum_error; \
1162 #undef CHECK_EXTENSION2
1163 #define CHECK_EXTENSION2(EXT1, EXT2) \
1164 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1165 goto invalid_enum_error; \
1170 * Helper function to determine whether a texture target is enabled.
1173 is_texture_enabled(struct gl_context
*ctx
, GLbitfield bit
)
1175 const struct gl_texture_unit
*const texUnit
=
1176 &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1177 return (texUnit
->Enabled
& bit
) ? GL_TRUE
: GL_FALSE
;
1182 * Return simple enable/disable state.
1184 * \param cap state variable to query.
1186 * Returns the state of the specified capability from the current GL context.
1187 * For the capabilities associated with extensions verifies that those
1188 * extensions are effectively present before reporting.
1190 GLboolean GLAPIENTRY
1191 _mesa_IsEnabled( GLenum cap
)
1193 GET_CURRENT_CONTEXT(ctx
);
1194 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1198 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1199 goto invalid_enum_error
;
1200 return ctx
->Color
.AlphaEnabled
;
1201 case GL_AUTO_NORMAL
:
1202 if (ctx
->API
!= API_OPENGL_COMPAT
)
1203 goto invalid_enum_error
;
1204 return ctx
->Eval
.AutoNormal
;
1206 return ctx
->Color
.BlendEnabled
& 1; /* return state for buffer[0] */
1207 case GL_CLIP_DISTANCE0
:
1208 case GL_CLIP_DISTANCE1
:
1209 case GL_CLIP_DISTANCE2
:
1210 case GL_CLIP_DISTANCE3
:
1211 case GL_CLIP_DISTANCE4
:
1212 case GL_CLIP_DISTANCE5
:
1213 case GL_CLIP_DISTANCE6
:
1214 case GL_CLIP_DISTANCE7
: {
1215 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
1217 if (p
>= ctx
->Const
.MaxClipPlanes
)
1218 goto invalid_enum_error
;
1220 return (ctx
->Transform
.ClipPlanesEnabled
>> p
) & 1;
1222 case GL_COLOR_MATERIAL
:
1223 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1224 goto invalid_enum_error
;
1225 return ctx
->Light
.ColorMaterialEnabled
;
1227 return ctx
->Polygon
.CullFlag
;
1228 case GL_DEBUG_OUTPUT
:
1229 if (!_mesa_is_desktop_gl(ctx
))
1230 goto invalid_enum_error
;
1231 return ctx
->Debug
.DebugOutput
;
1232 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
:
1233 if (!_mesa_is_desktop_gl(ctx
))
1234 goto invalid_enum_error
;
1235 return ctx
->Debug
.SyncOutput
;
1237 return ctx
->Depth
.Test
;
1239 return ctx
->Color
.DitherFlag
;
1241 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1242 goto invalid_enum_error
;
1243 return ctx
->Fog
.Enabled
;
1245 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1246 goto invalid_enum_error
;
1247 return ctx
->Light
.Enabled
;
1256 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1257 goto invalid_enum_error
;
1258 return ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
;
1259 case GL_LINE_SMOOTH
:
1260 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1261 goto invalid_enum_error
;
1262 return ctx
->Line
.SmoothFlag
;
1263 case GL_LINE_STIPPLE
:
1264 if (ctx
->API
!= API_OPENGL_COMPAT
)
1265 goto invalid_enum_error
;
1266 return ctx
->Line
.StippleFlag
;
1267 case GL_INDEX_LOGIC_OP
:
1268 if (ctx
->API
!= API_OPENGL_COMPAT
)
1269 goto invalid_enum_error
;
1270 return ctx
->Color
.IndexLogicOpEnabled
;
1271 case GL_COLOR_LOGIC_OP
:
1272 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1273 goto invalid_enum_error
;
1274 return ctx
->Color
.ColorLogicOpEnabled
;
1275 case GL_MAP1_COLOR_4
:
1276 if (ctx
->API
!= API_OPENGL_COMPAT
)
1277 goto invalid_enum_error
;
1278 return ctx
->Eval
.Map1Color4
;
1280 if (ctx
->API
!= API_OPENGL_COMPAT
)
1281 goto invalid_enum_error
;
1282 return ctx
->Eval
.Map1Index
;
1283 case GL_MAP1_NORMAL
:
1284 if (ctx
->API
!= API_OPENGL_COMPAT
)
1285 goto invalid_enum_error
;
1286 return ctx
->Eval
.Map1Normal
;
1287 case GL_MAP1_TEXTURE_COORD_1
:
1288 if (ctx
->API
!= API_OPENGL_COMPAT
)
1289 goto invalid_enum_error
;
1290 return ctx
->Eval
.Map1TextureCoord1
;
1291 case GL_MAP1_TEXTURE_COORD_2
:
1292 if (ctx
->API
!= API_OPENGL_COMPAT
)
1293 goto invalid_enum_error
;
1294 return ctx
->Eval
.Map1TextureCoord2
;
1295 case GL_MAP1_TEXTURE_COORD_3
:
1296 if (ctx
->API
!= API_OPENGL_COMPAT
)
1297 goto invalid_enum_error
;
1298 return ctx
->Eval
.Map1TextureCoord3
;
1299 case GL_MAP1_TEXTURE_COORD_4
:
1300 if (ctx
->API
!= API_OPENGL_COMPAT
)
1301 goto invalid_enum_error
;
1302 return ctx
->Eval
.Map1TextureCoord4
;
1303 case GL_MAP1_VERTEX_3
:
1304 if (ctx
->API
!= API_OPENGL_COMPAT
)
1305 goto invalid_enum_error
;
1306 return ctx
->Eval
.Map1Vertex3
;
1307 case GL_MAP1_VERTEX_4
:
1308 if (ctx
->API
!= API_OPENGL_COMPAT
)
1309 goto invalid_enum_error
;
1310 return ctx
->Eval
.Map1Vertex4
;
1311 case GL_MAP2_COLOR_4
:
1312 if (ctx
->API
!= API_OPENGL_COMPAT
)
1313 goto invalid_enum_error
;
1314 return ctx
->Eval
.Map2Color4
;
1316 if (ctx
->API
!= API_OPENGL_COMPAT
)
1317 goto invalid_enum_error
;
1318 return ctx
->Eval
.Map2Index
;
1319 case GL_MAP2_NORMAL
:
1320 if (ctx
->API
!= API_OPENGL_COMPAT
)
1321 goto invalid_enum_error
;
1322 return ctx
->Eval
.Map2Normal
;
1323 case GL_MAP2_TEXTURE_COORD_1
:
1324 if (ctx
->API
!= API_OPENGL_COMPAT
)
1325 goto invalid_enum_error
;
1326 return ctx
->Eval
.Map2TextureCoord1
;
1327 case GL_MAP2_TEXTURE_COORD_2
:
1328 if (ctx
->API
!= API_OPENGL_COMPAT
)
1329 goto invalid_enum_error
;
1330 return ctx
->Eval
.Map2TextureCoord2
;
1331 case GL_MAP2_TEXTURE_COORD_3
:
1332 if (ctx
->API
!= API_OPENGL_COMPAT
)
1333 goto invalid_enum_error
;
1334 return ctx
->Eval
.Map2TextureCoord3
;
1335 case GL_MAP2_TEXTURE_COORD_4
:
1336 if (ctx
->API
!= API_OPENGL_COMPAT
)
1337 goto invalid_enum_error
;
1338 return ctx
->Eval
.Map2TextureCoord4
;
1339 case GL_MAP2_VERTEX_3
:
1340 if (ctx
->API
!= API_OPENGL_COMPAT
)
1341 goto invalid_enum_error
;
1342 return ctx
->Eval
.Map2Vertex3
;
1343 case GL_MAP2_VERTEX_4
:
1344 if (ctx
->API
!= API_OPENGL_COMPAT
)
1345 goto invalid_enum_error
;
1346 return ctx
->Eval
.Map2Vertex4
;
1348 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1349 goto invalid_enum_error
;
1350 return ctx
->Transform
.Normalize
;
1351 case GL_POINT_SMOOTH
:
1352 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1353 goto invalid_enum_error
;
1354 return ctx
->Point
.SmoothFlag
;
1355 case GL_POLYGON_SMOOTH
:
1356 if (!_mesa_is_desktop_gl(ctx
))
1357 goto invalid_enum_error
;
1358 return ctx
->Polygon
.SmoothFlag
;
1359 case GL_POLYGON_STIPPLE
:
1360 if (ctx
->API
!= API_OPENGL_COMPAT
)
1361 goto invalid_enum_error
;
1362 return ctx
->Polygon
.StippleFlag
;
1363 case GL_POLYGON_OFFSET_POINT
:
1364 if (!_mesa_is_desktop_gl(ctx
))
1365 goto invalid_enum_error
;
1366 return ctx
->Polygon
.OffsetPoint
;
1367 case GL_POLYGON_OFFSET_LINE
:
1368 if (!_mesa_is_desktop_gl(ctx
))
1369 goto invalid_enum_error
;
1370 return ctx
->Polygon
.OffsetLine
;
1371 case GL_POLYGON_OFFSET_FILL
:
1372 return ctx
->Polygon
.OffsetFill
;
1373 case GL_RESCALE_NORMAL_EXT
:
1374 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1375 goto invalid_enum_error
;
1376 return ctx
->Transform
.RescaleNormals
;
1377 case GL_SCISSOR_TEST
:
1378 return ctx
->Scissor
.EnableFlags
& 1; /* return state for index 0 */
1379 case GL_STENCIL_TEST
:
1380 return ctx
->Stencil
.Enabled
;
1382 if (ctx
->API
!= API_OPENGL_COMPAT
)
1383 goto invalid_enum_error
;
1384 return is_texture_enabled(ctx
, TEXTURE_1D_BIT
);
1386 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1387 goto invalid_enum_error
;
1388 return is_texture_enabled(ctx
, TEXTURE_2D_BIT
);
1390 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1391 goto invalid_enum_error
;
1392 return is_texture_enabled(ctx
, TEXTURE_3D_BIT
);
1393 case GL_TEXTURE_GEN_S
:
1394 case GL_TEXTURE_GEN_T
:
1395 case GL_TEXTURE_GEN_R
:
1396 case GL_TEXTURE_GEN_Q
:
1398 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1400 if (ctx
->API
!= API_OPENGL_COMPAT
)
1401 goto invalid_enum_error
;
1404 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
1405 return (texUnit
->TexGenEnabled
& coordBit
) ? GL_TRUE
: GL_FALSE
;
1409 case GL_TEXTURE_GEN_STR_OES
:
1411 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1413 if (ctx
->API
!= API_OPENGLES
)
1414 goto invalid_enum_error
;
1417 return (texUnit
->TexGenEnabled
& STR_BITS
) == STR_BITS
1418 ? GL_TRUE
: GL_FALSE
;
1422 /* client-side state */
1423 case GL_VERTEX_ARRAY
:
1424 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1425 goto invalid_enum_error
;
1426 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
;
1427 case GL_NORMAL_ARRAY
:
1428 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1429 goto invalid_enum_error
;
1430 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
;
1431 case GL_COLOR_ARRAY
:
1432 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1433 goto invalid_enum_error
;
1434 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
;
1435 case GL_INDEX_ARRAY
:
1436 if (ctx
->API
!= API_OPENGL_COMPAT
)
1437 goto invalid_enum_error
;
1438 return ctx
->Array
.VAO
->
1439 VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
;
1440 case GL_TEXTURE_COORD_ARRAY
:
1441 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1442 goto invalid_enum_error
;
1443 return ctx
->Array
.VAO
->
1444 VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Enabled
;
1445 case GL_EDGE_FLAG_ARRAY
:
1446 if (ctx
->API
!= API_OPENGL_COMPAT
)
1447 goto invalid_enum_error
;
1448 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
;
1449 case GL_FOG_COORDINATE_ARRAY_EXT
:
1450 if (ctx
->API
!= API_OPENGL_COMPAT
)
1451 goto invalid_enum_error
;
1452 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
;
1453 case GL_SECONDARY_COLOR_ARRAY_EXT
:
1454 if (ctx
->API
!= API_OPENGL_COMPAT
)
1455 goto invalid_enum_error
;
1456 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
;
1457 case GL_POINT_SIZE_ARRAY_OES
:
1458 if (ctx
->API
!= API_OPENGLES
)
1459 goto invalid_enum_error
;
1460 return ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
;
1462 /* GL_ARB_texture_cube_map */
1463 case GL_TEXTURE_CUBE_MAP_ARB
:
1464 CHECK_EXTENSION(ARB_texture_cube_map
);
1465 return is_texture_enabled(ctx
, TEXTURE_CUBE_BIT
);
1467 /* GL_EXT_secondary_color */
1468 case GL_COLOR_SUM_EXT
:
1469 if (ctx
->API
!= API_OPENGL_COMPAT
)
1470 goto invalid_enum_error
;
1471 return ctx
->Fog
.ColorSumEnabled
;
1473 /* GL_ARB_multisample */
1474 case GL_MULTISAMPLE_ARB
:
1475 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1476 goto invalid_enum_error
;
1477 return ctx
->Multisample
.Enabled
;
1478 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
1479 return ctx
->Multisample
.SampleAlphaToCoverage
;
1480 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
1481 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1482 goto invalid_enum_error
;
1483 return ctx
->Multisample
.SampleAlphaToOne
;
1484 case GL_SAMPLE_COVERAGE_ARB
:
1485 return ctx
->Multisample
.SampleCoverage
;
1486 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
1487 if (!_mesa_is_desktop_gl(ctx
))
1488 goto invalid_enum_error
;
1489 return ctx
->Multisample
.SampleCoverageInvert
;
1491 /* GL_IBM_rasterpos_clip */
1492 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
1493 if (ctx
->API
!= API_OPENGL_COMPAT
)
1494 goto invalid_enum_error
;
1495 return ctx
->Transform
.RasterPositionUnclipped
;
1497 /* GL_NV_point_sprite */
1498 case GL_POINT_SPRITE_NV
:
1499 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1500 goto invalid_enum_error
;
1501 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
)
1502 return ctx
->Point
.PointSprite
;
1504 case GL_VERTEX_PROGRAM_ARB
:
1505 if (ctx
->API
!= API_OPENGL_COMPAT
)
1506 goto invalid_enum_error
;
1507 CHECK_EXTENSION(ARB_vertex_program
);
1508 return ctx
->VertexProgram
.Enabled
;
1509 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
1510 /* This was added with ARB_vertex_program, but it is also used with
1511 * GLSL vertex shaders on desktop.
1513 if (!_mesa_is_desktop_gl(ctx
))
1514 goto invalid_enum_error
;
1515 CHECK_EXTENSION(ARB_vertex_program
);
1516 return ctx
->VertexProgram
.PointSizeEnabled
;
1517 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
1518 if (ctx
->API
!= API_OPENGL_COMPAT
)
1519 goto invalid_enum_error
;
1520 CHECK_EXTENSION(ARB_vertex_program
);
1521 return ctx
->VertexProgram
.TwoSideEnabled
;
1523 /* GL_NV_texture_rectangle */
1524 case GL_TEXTURE_RECTANGLE_NV
:
1525 if (ctx
->API
!= API_OPENGL_COMPAT
)
1526 goto invalid_enum_error
;
1527 CHECK_EXTENSION(NV_texture_rectangle
);
1528 return is_texture_enabled(ctx
, TEXTURE_RECT_BIT
);
1530 /* GL_EXT_stencil_two_side */
1531 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
1532 if (ctx
->API
!= API_OPENGL_COMPAT
)
1533 goto invalid_enum_error
;
1534 CHECK_EXTENSION(EXT_stencil_two_side
);
1535 return ctx
->Stencil
.TestTwoSide
;
1537 case GL_FRAGMENT_PROGRAM_ARB
:
1538 if (ctx
->API
!= API_OPENGL_COMPAT
)
1539 goto invalid_enum_error
;
1540 return ctx
->FragmentProgram
.Enabled
;
1542 /* GL_EXT_depth_bounds_test */
1543 case GL_DEPTH_BOUNDS_TEST_EXT
:
1544 if (!_mesa_is_desktop_gl(ctx
))
1545 goto invalid_enum_error
;
1546 CHECK_EXTENSION(EXT_depth_bounds_test
);
1547 return ctx
->Depth
.BoundsTest
;
1549 /* GL_ARB_depth_clamp */
1550 case GL_DEPTH_CLAMP
:
1551 if (!_mesa_is_desktop_gl(ctx
))
1552 goto invalid_enum_error
;
1553 CHECK_EXTENSION(ARB_depth_clamp
);
1554 return ctx
->Transform
.DepthClamp
;
1556 case GL_FRAGMENT_SHADER_ATI
:
1557 if (ctx
->API
!= API_OPENGL_COMPAT
)
1558 goto invalid_enum_error
;
1559 CHECK_EXTENSION(ATI_fragment_shader
);
1560 return ctx
->ATIFragmentShader
.Enabled
;
1562 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1563 if (!_mesa_is_desktop_gl(ctx
))
1564 goto invalid_enum_error
;
1565 CHECK_EXTENSION(ARB_seamless_cube_map
);
1566 return ctx
->Texture
.CubeMapSeamless
;
1568 case GL_RASTERIZER_DISCARD
:
1569 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1570 goto invalid_enum_error
;
1571 CHECK_EXTENSION(EXT_transform_feedback
);
1572 return ctx
->RasterDiscard
;
1574 /* GL_NV_primitive_restart */
1575 case GL_PRIMITIVE_RESTART_NV
:
1576 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.NV_primitive_restart
) {
1577 goto invalid_enum_error
;
1579 return ctx
->Array
.PrimitiveRestart
;
1581 /* GL 3.1 primitive restart */
1582 case GL_PRIMITIVE_RESTART
:
1583 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
1584 goto invalid_enum_error
;
1586 return ctx
->Array
.PrimitiveRestart
;
1588 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
1589 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
) {
1590 goto invalid_enum_error
;
1592 return ctx
->Array
.PrimitiveRestartFixedIndex
;
1594 /* GL3.0 - GL_framebuffer_sRGB */
1595 case GL_FRAMEBUFFER_SRGB_EXT
:
1596 if (!_mesa_is_desktop_gl(ctx
))
1597 goto invalid_enum_error
;
1598 CHECK_EXTENSION(EXT_framebuffer_sRGB
);
1599 return ctx
->Color
.sRGBEnabled
;
1601 /* GL_OES_EGL_image_external */
1602 case GL_TEXTURE_EXTERNAL_OES
:
1603 if (!_mesa_is_gles(ctx
))
1604 goto invalid_enum_error
;
1605 CHECK_EXTENSION(OES_EGL_image_external
);
1606 return is_texture_enabled(ctx
, TEXTURE_EXTERNAL_BIT
);
1608 /* ARB_texture_multisample */
1609 case GL_SAMPLE_MASK
:
1610 if (!_mesa_is_desktop_gl(ctx
))
1611 goto invalid_enum_error
;
1612 CHECK_EXTENSION(ARB_texture_multisample
);
1613 return ctx
->Multisample
.SampleMask
;
1615 /* ARB_sample_shading */
1616 case GL_SAMPLE_SHADING
:
1617 if (!_mesa_is_desktop_gl(ctx
))
1618 goto invalid_enum_error
;
1619 CHECK_EXTENSION(ARB_sample_shading
);
1620 return ctx
->Multisample
.SampleShading
;
1623 goto invalid_enum_error
;
1629 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabled(%s)",
1630 _mesa_lookup_enum_by_nr(cap
));