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 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
25 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 #include "simple_list.h"
36 #include "mfeatures.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 if (ctx
->Array
.PrimitiveRestart
)
57 ctx
->Array
._RestartIndex
= ctx
->Array
.RestartIndex
;
59 ctx
->Array
._RestartIndex
= ~0;
61 ctx
->Array
._PrimitiveRestart
= ctx
->Array
.PrimitiveRestart
62 || ctx
->Array
.PrimitiveRestartFixedIndex
;
66 * Helper to enable/disable client-side state.
69 client_state(struct gl_context
*ctx
, GLenum cap
, GLboolean state
)
71 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
77 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
;
81 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
;
82 flag
= VERT_BIT_NORMAL
;
85 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
;
86 flag
= VERT_BIT_COLOR0
;
89 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
;
90 flag
= VERT_BIT_COLOR_INDEX
;
92 case GL_TEXTURE_COORD_ARRAY
:
93 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Enabled
;
94 flag
= VERT_BIT_TEX(ctx
->Array
.ActiveTexture
);
96 case GL_EDGE_FLAG_ARRAY
:
97 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
;
98 flag
= VERT_BIT_EDGEFLAG
;
100 case GL_FOG_COORDINATE_ARRAY_EXT
:
101 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
;
104 case GL_SECONDARY_COLOR_ARRAY_EXT
:
105 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
;
106 flag
= VERT_BIT_COLOR1
;
109 case GL_POINT_SIZE_ARRAY_OES
:
110 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
;
111 flag
= VERT_BIT_POINT_SIZE
;
114 /* GL_NV_primitive_restart */
115 case GL_PRIMITIVE_RESTART_NV
:
116 if (!ctx
->Extensions
.NV_primitive_restart
) {
117 goto invalid_enum_error
;
119 var
= &ctx
->Array
.PrimitiveRestart
;
124 goto invalid_enum_error
;
130 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
132 _ae_invalidate_state(ctx
, _NEW_ARRAY
);
136 update_derived_primitive_restart_state(ctx
);
139 arrayObj
->_Enabled
|= flag
;
141 arrayObj
->_Enabled
&= ~flag
;
143 arrayObj
->NewArrays
|= flag
;
145 if (ctx
->Driver
.Enable
) {
146 ctx
->Driver
.Enable( ctx
, cap
, state
);
152 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%sClientState(%s)",
153 state
? "Enable" : "Disable", _mesa_lookup_enum_by_nr(cap
));
158 * Enable GL capability.
159 * \param cap state to enable/disable.
161 * Get's the current context, assures that we're outside glBegin()/glEnd() and
162 * calls client_state().
165 _mesa_EnableClientState( GLenum cap
)
167 GET_CURRENT_CONTEXT(ctx
);
168 ASSERT_OUTSIDE_BEGIN_END(ctx
);
169 client_state( ctx
, cap
, GL_TRUE
);
174 * Disable GL capability.
175 * \param cap state to enable/disable.
177 * Get's the current context, assures that we're outside glBegin()/glEnd() and
178 * calls client_state().
181 _mesa_DisableClientState( GLenum cap
)
183 GET_CURRENT_CONTEXT(ctx
);
184 ASSERT_OUTSIDE_BEGIN_END(ctx
);
185 client_state( ctx
, cap
, GL_FALSE
);
189 #undef CHECK_EXTENSION
190 #define CHECK_EXTENSION(EXTNAME, CAP) \
191 if (!ctx->Extensions.EXTNAME) { \
192 goto invalid_enum_error; \
195 #define CHECK_EXTENSION2(EXT1, EXT2, CAP) \
196 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
197 goto invalid_enum_error; \
201 * Return pointer to current texture unit for setting/getting coordinate
203 * Note that we'll set GL_INVALID_OPERATION and return NULL if the active
204 * texture unit is higher than the number of supported coordinate units.
206 static struct gl_texture_unit
*
207 get_texcoord_unit(struct gl_context
*ctx
)
209 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
210 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glEnable/Disable(texcoord unit)");
214 return &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
220 * Helper function to enable or disable a texture target.
221 * \param bit one of the TEXTURE_x_BIT values
222 * \return GL_TRUE if state is changing or GL_FALSE if no change
225 enable_texture(struct gl_context
*ctx
, GLboolean state
, GLbitfield texBit
)
227 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
228 const GLbitfield newenabled
= state
229 ? (texUnit
->Enabled
| texBit
) : (texUnit
->Enabled
& ~texBit
);
231 if (texUnit
->Enabled
== newenabled
)
234 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
235 texUnit
->Enabled
= newenabled
;
241 * Helper function to enable or disable GL_MULTISAMPLE, skipping the check for
242 * whether the API supports it (GLES doesn't).
245 _mesa_set_multisample(struct gl_context
*ctx
, GLboolean state
)
247 if (ctx
->Multisample
.Enabled
== state
)
249 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
250 ctx
->Multisample
.Enabled
= state
;
252 if (ctx
->Driver
.Enable
) {
253 ctx
->Driver
.Enable(ctx
, GL_MULTISAMPLE
, state
);
258 * Helper function to enable or disable GL_FRAMEBUFFER_SRGB, skipping the
259 * check for whether the API supports it (GLES doesn't).
262 _mesa_set_framebuffer_srgb(struct gl_context
*ctx
, GLboolean state
)
264 if (ctx
->Color
.sRGBEnabled
== state
)
266 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
267 ctx
->Color
.sRGBEnabled
= state
;
269 if (ctx
->Driver
.Enable
) {
270 ctx
->Driver
.Enable(ctx
, GL_FRAMEBUFFER_SRGB
, state
);
275 * Helper function to enable or disable state.
277 * \param ctx GL context.
278 * \param cap the state to enable/disable
279 * \param state whether to enable or disable the specified capability.
281 * Updates the current context and flushes the vertices as needed. For
282 * capabilities associated with extensions it verifies that those extensions
283 * are effectivly present before updating. Notifies the driver via
284 * dd_function_table::Enable.
287 _mesa_set_enable(struct gl_context
*ctx
, GLenum cap
, GLboolean state
)
289 if (MESA_VERBOSE
& VERBOSE_API
)
290 _mesa_debug(ctx
, "%s %s (newstate is %x)\n",
291 state
? "glEnable" : "glDisable",
292 _mesa_lookup_enum_by_nr(cap
),
297 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
298 goto invalid_enum_error
;
299 if (ctx
->Color
.AlphaEnabled
== state
)
301 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
302 ctx
->Color
.AlphaEnabled
= state
;
305 if (ctx
->API
!= API_OPENGL_COMPAT
)
306 goto invalid_enum_error
;
307 if (ctx
->Eval
.AutoNormal
== state
)
309 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
310 ctx
->Eval
.AutoNormal
= state
;
314 GLbitfield newEnabled
=
315 state
* ((1 << ctx
->Const
.MaxDrawBuffers
) - 1);
316 if (newEnabled
!= ctx
->Color
.BlendEnabled
) {
317 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
318 ctx
->Color
.BlendEnabled
= newEnabled
;
322 case GL_CLIP_DISTANCE0
:
323 case GL_CLIP_DISTANCE1
:
324 case GL_CLIP_DISTANCE2
:
325 case GL_CLIP_DISTANCE3
:
326 case GL_CLIP_DISTANCE4
:
327 case GL_CLIP_DISTANCE5
:
328 case GL_CLIP_DISTANCE6
:
329 case GL_CLIP_DISTANCE7
:
331 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
333 if (p
>= ctx
->Const
.MaxClipPlanes
)
334 goto invalid_enum_error
;
336 if ((ctx
->Transform
.ClipPlanesEnabled
& (1 << p
))
337 == ((GLuint
) state
<< p
))
340 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
343 ctx
->Transform
.ClipPlanesEnabled
|= (1 << p
);
344 _mesa_update_clip_plane(ctx
, p
);
347 ctx
->Transform
.ClipPlanesEnabled
&= ~(1 << p
);
351 case GL_COLOR_MATERIAL
:
352 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
353 goto invalid_enum_error
;
354 if (ctx
->Light
.ColorMaterialEnabled
== state
)
356 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
357 FLUSH_CURRENT(ctx
, 0);
358 ctx
->Light
.ColorMaterialEnabled
= state
;
360 _mesa_update_color_material( ctx
,
361 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
] );
365 if (ctx
->Polygon
.CullFlag
== state
)
367 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
368 ctx
->Polygon
.CullFlag
= state
;
371 if (ctx
->Depth
.Test
== state
)
373 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
374 ctx
->Depth
.Test
= state
;
376 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
:
377 if (!_mesa_is_desktop_gl(ctx
))
378 goto invalid_enum_error
;
379 ctx
->Debug
.SyncOutput
= state
;
382 if (ctx
->Color
.DitherFlag
== state
)
384 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
385 ctx
->Color
.DitherFlag
= state
;
388 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
389 goto invalid_enum_error
;
390 if (ctx
->Fog
.Enabled
== state
)
392 FLUSH_VERTICES(ctx
, _NEW_FOG
);
393 ctx
->Fog
.Enabled
= state
;
403 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
404 goto invalid_enum_error
;
405 if (ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
== state
)
407 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
408 ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
= state
;
410 insert_at_tail(&ctx
->Light
.EnabledList
,
411 &ctx
->Light
.Light
[cap
-GL_LIGHT0
]);
414 remove_from_list(&ctx
->Light
.Light
[cap
-GL_LIGHT0
]);
418 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
419 goto invalid_enum_error
;
420 if (ctx
->Light
.Enabled
== state
)
422 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
423 ctx
->Light
.Enabled
= state
;
424 if (ctx
->Light
.Enabled
&& ctx
->Light
.Model
.TwoSide
)
425 ctx
->_TriangleCaps
|= DD_TRI_LIGHT_TWOSIDE
;
427 ctx
->_TriangleCaps
&= ~DD_TRI_LIGHT_TWOSIDE
;
430 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
431 goto invalid_enum_error
;
432 if (ctx
->Line
.SmoothFlag
== state
)
434 FLUSH_VERTICES(ctx
, _NEW_LINE
);
435 ctx
->Line
.SmoothFlag
= state
;
436 ctx
->_TriangleCaps
^= DD_LINE_SMOOTH
;
438 case GL_LINE_STIPPLE
:
439 if (ctx
->API
!= API_OPENGL_COMPAT
)
440 goto invalid_enum_error
;
441 if (ctx
->Line
.StippleFlag
== state
)
443 FLUSH_VERTICES(ctx
, _NEW_LINE
);
444 ctx
->Line
.StippleFlag
= state
;
445 ctx
->_TriangleCaps
^= DD_LINE_STIPPLE
;
447 case GL_INDEX_LOGIC_OP
:
448 if (ctx
->API
!= API_OPENGL_COMPAT
)
449 goto invalid_enum_error
;
450 if (ctx
->Color
.IndexLogicOpEnabled
== state
)
452 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
453 ctx
->Color
.IndexLogicOpEnabled
= state
;
455 case GL_COLOR_LOGIC_OP
:
456 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
457 goto invalid_enum_error
;
458 if (ctx
->Color
.ColorLogicOpEnabled
== state
)
460 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
461 ctx
->Color
.ColorLogicOpEnabled
= state
;
463 case GL_MAP1_COLOR_4
:
464 if (ctx
->API
!= API_OPENGL_COMPAT
)
465 goto invalid_enum_error
;
466 if (ctx
->Eval
.Map1Color4
== state
)
468 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
469 ctx
->Eval
.Map1Color4
= state
;
472 if (ctx
->API
!= API_OPENGL_COMPAT
)
473 goto invalid_enum_error
;
474 if (ctx
->Eval
.Map1Index
== state
)
476 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
477 ctx
->Eval
.Map1Index
= state
;
480 if (ctx
->API
!= API_OPENGL_COMPAT
)
481 goto invalid_enum_error
;
482 if (ctx
->Eval
.Map1Normal
== state
)
484 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
485 ctx
->Eval
.Map1Normal
= state
;
487 case GL_MAP1_TEXTURE_COORD_1
:
488 if (ctx
->API
!= API_OPENGL_COMPAT
)
489 goto invalid_enum_error
;
490 if (ctx
->Eval
.Map1TextureCoord1
== state
)
492 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
493 ctx
->Eval
.Map1TextureCoord1
= state
;
495 case GL_MAP1_TEXTURE_COORD_2
:
496 if (ctx
->API
!= API_OPENGL_COMPAT
)
497 goto invalid_enum_error
;
498 if (ctx
->Eval
.Map1TextureCoord2
== state
)
500 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
501 ctx
->Eval
.Map1TextureCoord2
= state
;
503 case GL_MAP1_TEXTURE_COORD_3
:
504 if (ctx
->API
!= API_OPENGL_COMPAT
)
505 goto invalid_enum_error
;
506 if (ctx
->Eval
.Map1TextureCoord3
== state
)
508 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
509 ctx
->Eval
.Map1TextureCoord3
= state
;
511 case GL_MAP1_TEXTURE_COORD_4
:
512 if (ctx
->API
!= API_OPENGL_COMPAT
)
513 goto invalid_enum_error
;
514 if (ctx
->Eval
.Map1TextureCoord4
== state
)
516 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
517 ctx
->Eval
.Map1TextureCoord4
= state
;
519 case GL_MAP1_VERTEX_3
:
520 if (ctx
->API
!= API_OPENGL_COMPAT
)
521 goto invalid_enum_error
;
522 if (ctx
->Eval
.Map1Vertex3
== state
)
524 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
525 ctx
->Eval
.Map1Vertex3
= state
;
527 case GL_MAP1_VERTEX_4
:
528 if (ctx
->API
!= API_OPENGL_COMPAT
)
529 goto invalid_enum_error
;
530 if (ctx
->Eval
.Map1Vertex4
== state
)
532 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
533 ctx
->Eval
.Map1Vertex4
= state
;
535 case GL_MAP2_COLOR_4
:
536 if (ctx
->API
!= API_OPENGL_COMPAT
)
537 goto invalid_enum_error
;
538 if (ctx
->Eval
.Map2Color4
== state
)
540 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
541 ctx
->Eval
.Map2Color4
= state
;
544 if (ctx
->API
!= API_OPENGL_COMPAT
)
545 goto invalid_enum_error
;
546 if (ctx
->Eval
.Map2Index
== state
)
548 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
549 ctx
->Eval
.Map2Index
= state
;
552 if (ctx
->API
!= API_OPENGL_COMPAT
)
553 goto invalid_enum_error
;
554 if (ctx
->Eval
.Map2Normal
== state
)
556 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
557 ctx
->Eval
.Map2Normal
= state
;
559 case GL_MAP2_TEXTURE_COORD_1
:
560 if (ctx
->API
!= API_OPENGL_COMPAT
)
561 goto invalid_enum_error
;
562 if (ctx
->Eval
.Map2TextureCoord1
== state
)
564 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
565 ctx
->Eval
.Map2TextureCoord1
= state
;
567 case GL_MAP2_TEXTURE_COORD_2
:
568 if (ctx
->API
!= API_OPENGL_COMPAT
)
569 goto invalid_enum_error
;
570 if (ctx
->Eval
.Map2TextureCoord2
== state
)
572 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
573 ctx
->Eval
.Map2TextureCoord2
= state
;
575 case GL_MAP2_TEXTURE_COORD_3
:
576 if (ctx
->API
!= API_OPENGL_COMPAT
)
577 goto invalid_enum_error
;
578 if (ctx
->Eval
.Map2TextureCoord3
== state
)
580 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
581 ctx
->Eval
.Map2TextureCoord3
= state
;
583 case GL_MAP2_TEXTURE_COORD_4
:
584 if (ctx
->API
!= API_OPENGL_COMPAT
)
585 goto invalid_enum_error
;
586 if (ctx
->Eval
.Map2TextureCoord4
== state
)
588 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
589 ctx
->Eval
.Map2TextureCoord4
= state
;
591 case GL_MAP2_VERTEX_3
:
592 if (ctx
->API
!= API_OPENGL_COMPAT
)
593 goto invalid_enum_error
;
594 if (ctx
->Eval
.Map2Vertex3
== state
)
596 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
597 ctx
->Eval
.Map2Vertex3
= state
;
599 case GL_MAP2_VERTEX_4
:
600 if (ctx
->API
!= API_OPENGL_COMPAT
)
601 goto invalid_enum_error
;
602 if (ctx
->Eval
.Map2Vertex4
== state
)
604 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
605 ctx
->Eval
.Map2Vertex4
= state
;
608 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
609 goto invalid_enum_error
;
610 if (ctx
->Transform
.Normalize
== state
)
612 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
613 ctx
->Transform
.Normalize
= state
;
615 case GL_POINT_SMOOTH
:
616 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
617 goto invalid_enum_error
;
618 if (ctx
->Point
.SmoothFlag
== state
)
620 FLUSH_VERTICES(ctx
, _NEW_POINT
);
621 ctx
->Point
.SmoothFlag
= state
;
622 ctx
->_TriangleCaps
^= DD_POINT_SMOOTH
;
624 case GL_POLYGON_SMOOTH
:
625 if (!_mesa_is_desktop_gl(ctx
))
626 goto invalid_enum_error
;
627 if (ctx
->Polygon
.SmoothFlag
== state
)
629 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
630 ctx
->Polygon
.SmoothFlag
= state
;
631 ctx
->_TriangleCaps
^= DD_TRI_SMOOTH
;
633 case GL_POLYGON_STIPPLE
:
634 if (ctx
->API
!= API_OPENGL_COMPAT
)
635 goto invalid_enum_error
;
636 if (ctx
->Polygon
.StippleFlag
== state
)
638 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
639 ctx
->Polygon
.StippleFlag
= state
;
640 ctx
->_TriangleCaps
^= DD_TRI_STIPPLE
;
642 case GL_POLYGON_OFFSET_POINT
:
643 if (!_mesa_is_desktop_gl(ctx
))
644 goto invalid_enum_error
;
645 if (ctx
->Polygon
.OffsetPoint
== state
)
647 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
648 ctx
->Polygon
.OffsetPoint
= state
;
650 case GL_POLYGON_OFFSET_LINE
:
651 if (!_mesa_is_desktop_gl(ctx
))
652 goto invalid_enum_error
;
653 if (ctx
->Polygon
.OffsetLine
== state
)
655 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
656 ctx
->Polygon
.OffsetLine
= state
;
658 case GL_POLYGON_OFFSET_FILL
:
659 if (ctx
->Polygon
.OffsetFill
== state
)
661 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
662 ctx
->Polygon
.OffsetFill
= state
;
664 case GL_RESCALE_NORMAL_EXT
:
665 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
666 goto invalid_enum_error
;
667 if (ctx
->Transform
.RescaleNormals
== state
)
669 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
670 ctx
->Transform
.RescaleNormals
= state
;
672 case GL_SCISSOR_TEST
:
673 if (ctx
->Scissor
.Enabled
== state
)
675 FLUSH_VERTICES(ctx
, _NEW_SCISSOR
);
676 ctx
->Scissor
.Enabled
= state
;
678 case GL_STENCIL_TEST
:
679 if (ctx
->Stencil
.Enabled
== state
)
681 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
682 ctx
->Stencil
.Enabled
= state
;
685 if (ctx
->API
!= API_OPENGL_COMPAT
)
686 goto invalid_enum_error
;
687 if (!enable_texture(ctx
, state
, TEXTURE_1D_BIT
)) {
692 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
693 goto invalid_enum_error
;
694 if (!enable_texture(ctx
, state
, TEXTURE_2D_BIT
)) {
699 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
700 goto invalid_enum_error
;
701 if (!enable_texture(ctx
, state
, TEXTURE_3D_BIT
)) {
705 case GL_TEXTURE_GEN_S
:
706 case GL_TEXTURE_GEN_T
:
707 case GL_TEXTURE_GEN_R
:
708 case GL_TEXTURE_GEN_Q
:
710 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
712 if (ctx
->API
!= API_OPENGL_COMPAT
)
713 goto invalid_enum_error
;
716 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
717 GLbitfield newenabled
= texUnit
->TexGenEnabled
& ~coordBit
;
719 newenabled
|= coordBit
;
720 if (texUnit
->TexGenEnabled
== newenabled
)
722 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
723 texUnit
->TexGenEnabled
= newenabled
;
728 case GL_TEXTURE_GEN_STR_OES
:
729 /* disable S, T, and R at the same time */
731 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
733 if (ctx
->API
!= API_OPENGLES
)
734 goto invalid_enum_error
;
738 texUnit
->TexGenEnabled
& ~STR_BITS
;
740 newenabled
|= STR_BITS
;
741 if (texUnit
->TexGenEnabled
== newenabled
)
743 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
744 texUnit
->TexGenEnabled
= newenabled
;
749 /* client-side state */
750 case GL_VERTEX_ARRAY
:
751 case GL_NORMAL_ARRAY
:
754 case GL_TEXTURE_COORD_ARRAY
:
755 case GL_EDGE_FLAG_ARRAY
:
756 case GL_FOG_COORDINATE_ARRAY_EXT
:
757 case GL_SECONDARY_COLOR_ARRAY_EXT
:
758 case GL_POINT_SIZE_ARRAY_OES
:
759 client_state( ctx
, cap
, state
);
762 /* GL_ARB_texture_cube_map */
763 case GL_TEXTURE_CUBE_MAP_ARB
:
764 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
765 goto invalid_enum_error
;
766 CHECK_EXTENSION(ARB_texture_cube_map
, cap
);
767 if (!enable_texture(ctx
, state
, TEXTURE_CUBE_BIT
)) {
772 /* GL_EXT_secondary_color */
773 case GL_COLOR_SUM_EXT
:
774 if (ctx
->API
!= API_OPENGL_COMPAT
)
775 goto invalid_enum_error
;
776 CHECK_EXTENSION2(EXT_secondary_color
, ARB_vertex_program
, cap
);
777 if (ctx
->Fog
.ColorSumEnabled
== state
)
779 FLUSH_VERTICES(ctx
, _NEW_FOG
);
780 ctx
->Fog
.ColorSumEnabled
= state
;
783 /* GL_ARB_multisample */
784 case GL_MULTISAMPLE_ARB
:
785 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
786 goto invalid_enum_error
;
787 _mesa_set_multisample(ctx
, state
);
789 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
790 if (ctx
->Multisample
.SampleAlphaToCoverage
== state
)
792 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
793 ctx
->Multisample
.SampleAlphaToCoverage
= state
;
795 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
796 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
797 goto invalid_enum_error
;
798 if (ctx
->Multisample
.SampleAlphaToOne
== state
)
800 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
801 ctx
->Multisample
.SampleAlphaToOne
= state
;
803 case GL_SAMPLE_COVERAGE_ARB
:
804 if (ctx
->Multisample
.SampleCoverage
== state
)
806 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
807 ctx
->Multisample
.SampleCoverage
= state
;
809 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
810 if (!_mesa_is_desktop_gl(ctx
))
811 goto invalid_enum_error
;
812 if (ctx
->Multisample
.SampleCoverageInvert
== state
)
814 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
815 ctx
->Multisample
.SampleCoverageInvert
= state
;
818 /* GL_IBM_rasterpos_clip */
819 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
820 if (ctx
->API
!= API_OPENGL_COMPAT
)
821 goto invalid_enum_error
;
822 if (ctx
->Transform
.RasterPositionUnclipped
== state
)
824 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
825 ctx
->Transform
.RasterPositionUnclipped
= state
;
828 /* GL_NV_point_sprite */
829 case GL_POINT_SPRITE_NV
:
830 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
831 goto invalid_enum_error
;
832 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
, cap
);
833 if (ctx
->Point
.PointSprite
== state
)
835 FLUSH_VERTICES(ctx
, _NEW_POINT
);
836 ctx
->Point
.PointSprite
= state
;
839 case GL_VERTEX_PROGRAM_ARB
:
840 if (ctx
->API
!= API_OPENGL_COMPAT
)
841 goto invalid_enum_error
;
842 CHECK_EXTENSION(ARB_vertex_program
, cap
);
843 if (ctx
->VertexProgram
.Enabled
== state
)
845 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
846 ctx
->VertexProgram
.Enabled
= state
;
848 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
849 /* This was added with ARB_vertex_program, but it is also used with
850 * GLSL vertex shaders on desktop.
852 if (!_mesa_is_desktop_gl(ctx
))
853 goto invalid_enum_error
;
854 CHECK_EXTENSION(ARB_vertex_program
, cap
);
855 if (ctx
->VertexProgram
.PointSizeEnabled
== state
)
857 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
858 ctx
->VertexProgram
.PointSizeEnabled
= state
;
860 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
861 if (ctx
->API
!= API_OPENGL_COMPAT
)
862 goto invalid_enum_error
;
863 CHECK_EXTENSION(ARB_vertex_program
, cap
);
864 if (ctx
->VertexProgram
.TwoSideEnabled
== state
)
866 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
867 ctx
->VertexProgram
.TwoSideEnabled
= state
;
870 /* GL_NV_texture_rectangle */
871 case GL_TEXTURE_RECTANGLE_NV
:
872 if (ctx
->API
!= API_OPENGL_COMPAT
)
873 goto invalid_enum_error
;
874 CHECK_EXTENSION(NV_texture_rectangle
, cap
);
875 if (!enable_texture(ctx
, state
, TEXTURE_RECT_BIT
)) {
880 /* GL_EXT_stencil_two_side */
881 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
882 if (ctx
->API
!= API_OPENGL_COMPAT
)
883 goto invalid_enum_error
;
884 CHECK_EXTENSION(EXT_stencil_two_side
, cap
);
885 if (ctx
->Stencil
.TestTwoSide
== state
)
887 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
888 ctx
->Stencil
.TestTwoSide
= state
;
890 ctx
->Stencil
._BackFace
= 2;
892 ctx
->Stencil
._BackFace
= 1;
896 case GL_FRAGMENT_PROGRAM_ARB
:
897 if (ctx
->API
!= API_OPENGL_COMPAT
)
898 goto invalid_enum_error
;
899 CHECK_EXTENSION(ARB_fragment_program
, cap
);
900 if (ctx
->FragmentProgram
.Enabled
== state
)
902 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
903 ctx
->FragmentProgram
.Enabled
= state
;
906 /* GL_EXT_depth_bounds_test */
907 case GL_DEPTH_BOUNDS_TEST_EXT
:
908 if (!_mesa_is_desktop_gl(ctx
))
909 goto invalid_enum_error
;
910 CHECK_EXTENSION(EXT_depth_bounds_test
, cap
);
911 if (ctx
->Depth
.BoundsTest
== state
)
913 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
914 ctx
->Depth
.BoundsTest
= state
;
918 if (!_mesa_is_desktop_gl(ctx
))
919 goto invalid_enum_error
;
920 CHECK_EXTENSION(ARB_depth_clamp
, cap
);
921 if (ctx
->Transform
.DepthClamp
== state
)
923 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
924 ctx
->Transform
.DepthClamp
= state
;
927 case GL_FRAGMENT_SHADER_ATI
:
928 if (ctx
->API
!= API_OPENGL_COMPAT
)
929 goto invalid_enum_error
;
930 CHECK_EXTENSION(ATI_fragment_shader
, cap
);
931 if (ctx
->ATIFragmentShader
.Enabled
== state
)
933 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
934 ctx
->ATIFragmentShader
.Enabled
= state
;
937 /* GL_MESA_texture_array */
938 case GL_TEXTURE_1D_ARRAY_EXT
:
939 if (ctx
->API
!= API_OPENGL_COMPAT
)
940 goto invalid_enum_error
;
941 CHECK_EXTENSION(MESA_texture_array
, cap
);
942 if (!enable_texture(ctx
, state
, TEXTURE_1D_ARRAY_BIT
)) {
947 case GL_TEXTURE_2D_ARRAY_EXT
:
948 if (ctx
->API
!= API_OPENGL_COMPAT
)
949 goto invalid_enum_error
;
950 CHECK_EXTENSION(MESA_texture_array
, cap
);
951 if (!enable_texture(ctx
, state
, TEXTURE_2D_ARRAY_BIT
)) {
956 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
957 if (!_mesa_is_desktop_gl(ctx
))
958 goto invalid_enum_error
;
959 CHECK_EXTENSION(ARB_seamless_cube_map
, cap
);
960 if (ctx
->Texture
.CubeMapSeamless
!= state
) {
961 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
962 ctx
->Texture
.CubeMapSeamless
= state
;
966 case GL_RASTERIZER_DISCARD
:
967 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
968 goto invalid_enum_error
;
969 CHECK_EXTENSION(EXT_transform_feedback
, cap
);
970 if (ctx
->RasterDiscard
!= state
) {
971 FLUSH_VERTICES(ctx
, _NEW_RASTERIZER_DISCARD
);
972 ctx
->RasterDiscard
= state
;
976 /* GL 3.1 primitive restart. Note: this enum is different from
977 * GL_PRIMITIVE_RESTART_NV (which is client state).
979 case GL_PRIMITIVE_RESTART
:
980 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
981 goto invalid_enum_error
;
983 if (ctx
->Array
.PrimitiveRestart
!= state
) {
984 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
985 ctx
->Array
.PrimitiveRestart
= state
;
986 update_derived_primitive_restart_state(ctx
);
990 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
991 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
)
992 goto invalid_enum_error
;
993 if (ctx
->Array
.PrimitiveRestartFixedIndex
!= state
) {
994 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
995 ctx
->Array
.PrimitiveRestartFixedIndex
= state
;
996 update_derived_primitive_restart_state(ctx
);
1000 /* GL3.0 - GL_framebuffer_sRGB */
1001 case GL_FRAMEBUFFER_SRGB_EXT
:
1002 if (!_mesa_is_desktop_gl(ctx
))
1003 goto invalid_enum_error
;
1004 CHECK_EXTENSION(EXT_framebuffer_sRGB
, cap
);
1005 _mesa_set_framebuffer_srgb(ctx
, state
);
1008 /* GL_OES_EGL_image_external */
1009 case GL_TEXTURE_EXTERNAL_OES
:
1010 if (!_mesa_is_gles(ctx
))
1011 goto invalid_enum_error
;
1012 CHECK_EXTENSION(OES_EGL_image_external
, cap
);
1013 if (!enable_texture(ctx
, state
, TEXTURE_EXTERNAL_BIT
)) {
1019 goto invalid_enum_error
;
1022 if (ctx
->Driver
.Enable
) {
1023 ctx
->Driver
.Enable( ctx
, cap
, state
);
1029 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%s(%s)",
1030 state
? "Enable" : "Disable", _mesa_lookup_enum_by_nr(cap
));
1035 * Enable GL capability. Called by glEnable()
1036 * \param cap state to enable.
1039 _mesa_Enable( GLenum cap
)
1041 GET_CURRENT_CONTEXT(ctx
);
1042 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1044 _mesa_set_enable( ctx
, cap
, GL_TRUE
);
1049 * Disable GL capability. Called by glDisable()
1050 * \param cap state to disable.
1053 _mesa_Disable( GLenum cap
)
1055 GET_CURRENT_CONTEXT(ctx
);
1056 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1058 _mesa_set_enable( ctx
, cap
, GL_FALSE
);
1064 * Enable/disable an indexed state var.
1067 _mesa_set_enablei(struct gl_context
*ctx
, GLenum cap
,
1068 GLuint index
, GLboolean state
)
1070 ASSERT(state
== 0 || state
== 1);
1073 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
1074 goto invalid_enum_error
;
1076 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1077 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1078 state
? "glEnableIndexed" : "glDisableIndexed", index
);
1081 if (((ctx
->Color
.BlendEnabled
>> index
) & 1) != state
) {
1082 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
1084 ctx
->Color
.BlendEnabled
|= (1 << index
);
1086 ctx
->Color
.BlendEnabled
&= ~(1 << index
);
1090 goto invalid_enum_error
;
1095 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(cap=%s)",
1096 state
? "glEnablei" : "glDisablei",
1097 _mesa_lookup_enum_by_nr(cap
));
1102 _mesa_Disablei( GLenum cap
, GLuint index
)
1104 GET_CURRENT_CONTEXT(ctx
);
1105 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1106 _mesa_set_enablei(ctx
, cap
, index
, GL_FALSE
);
1111 _mesa_Enablei( GLenum cap
, GLuint index
)
1113 GET_CURRENT_CONTEXT(ctx
);
1114 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1115 _mesa_set_enablei(ctx
, cap
, index
, GL_TRUE
);
1119 GLboolean GLAPIENTRY
1120 _mesa_IsEnabledi( GLenum cap
, GLuint index
)
1122 GET_CURRENT_CONTEXT(ctx
);
1123 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1126 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1127 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1131 return (ctx
->Color
.BlendEnabled
>> index
) & 1;
1133 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabledIndexed(cap=%s)",
1134 _mesa_lookup_enum_by_nr(cap
));
1142 #undef CHECK_EXTENSION
1143 #define CHECK_EXTENSION(EXTNAME) \
1144 if (!ctx->Extensions.EXTNAME) { \
1145 goto invalid_enum_error; \
1148 #undef CHECK_EXTENSION2
1149 #define CHECK_EXTENSION2(EXT1, EXT2) \
1150 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1151 goto invalid_enum_error; \
1156 * Helper function to determine whether a texture target is enabled.
1159 is_texture_enabled(struct gl_context
*ctx
, GLbitfield bit
)
1161 const struct gl_texture_unit
*const texUnit
=
1162 &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1163 return (texUnit
->Enabled
& bit
) ? GL_TRUE
: GL_FALSE
;
1168 * Return simple enable/disable state.
1170 * \param cap state variable to query.
1172 * Returns the state of the specified capability from the current GL context.
1173 * For the capabilities associated with extensions verifies that those
1174 * extensions are effectively present before reporting.
1176 GLboolean GLAPIENTRY
1177 _mesa_IsEnabled( GLenum cap
)
1179 GET_CURRENT_CONTEXT(ctx
);
1180 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1184 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1185 goto invalid_enum_error
;
1186 return ctx
->Color
.AlphaEnabled
;
1187 case GL_AUTO_NORMAL
:
1188 if (ctx
->API
!= API_OPENGL_COMPAT
)
1189 goto invalid_enum_error
;
1190 return ctx
->Eval
.AutoNormal
;
1192 return ctx
->Color
.BlendEnabled
& 1; /* return state for buffer[0] */
1193 case GL_CLIP_DISTANCE0
:
1194 case GL_CLIP_DISTANCE1
:
1195 case GL_CLIP_DISTANCE2
:
1196 case GL_CLIP_DISTANCE3
:
1197 case GL_CLIP_DISTANCE4
:
1198 case GL_CLIP_DISTANCE5
:
1199 case GL_CLIP_DISTANCE6
:
1200 case GL_CLIP_DISTANCE7
: {
1201 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
1203 if (p
>= ctx
->Const
.MaxClipPlanes
)
1204 goto invalid_enum_error
;
1206 return (ctx
->Transform
.ClipPlanesEnabled
>> p
) & 1;
1208 case GL_COLOR_MATERIAL
:
1209 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1210 goto invalid_enum_error
;
1211 return ctx
->Light
.ColorMaterialEnabled
;
1213 return ctx
->Polygon
.CullFlag
;
1214 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
:
1215 if (!_mesa_is_desktop_gl(ctx
))
1216 goto invalid_enum_error
;
1217 return ctx
->Debug
.SyncOutput
;
1219 return ctx
->Depth
.Test
;
1221 return ctx
->Color
.DitherFlag
;
1223 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1224 goto invalid_enum_error
;
1225 return ctx
->Fog
.Enabled
;
1227 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1228 goto invalid_enum_error
;
1229 return ctx
->Light
.Enabled
;
1238 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1239 goto invalid_enum_error
;
1240 return ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
;
1241 case GL_LINE_SMOOTH
:
1242 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1243 goto invalid_enum_error
;
1244 return ctx
->Line
.SmoothFlag
;
1245 case GL_LINE_STIPPLE
:
1246 if (ctx
->API
!= API_OPENGL_COMPAT
)
1247 goto invalid_enum_error
;
1248 return ctx
->Line
.StippleFlag
;
1249 case GL_INDEX_LOGIC_OP
:
1250 if (ctx
->API
!= API_OPENGL_COMPAT
)
1251 goto invalid_enum_error
;
1252 return ctx
->Color
.IndexLogicOpEnabled
;
1253 case GL_COLOR_LOGIC_OP
:
1254 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1255 goto invalid_enum_error
;
1256 return ctx
->Color
.ColorLogicOpEnabled
;
1257 case GL_MAP1_COLOR_4
:
1258 if (ctx
->API
!= API_OPENGL_COMPAT
)
1259 goto invalid_enum_error
;
1260 return ctx
->Eval
.Map1Color4
;
1262 if (ctx
->API
!= API_OPENGL_COMPAT
)
1263 goto invalid_enum_error
;
1264 return ctx
->Eval
.Map1Index
;
1265 case GL_MAP1_NORMAL
:
1266 if (ctx
->API
!= API_OPENGL_COMPAT
)
1267 goto invalid_enum_error
;
1268 return ctx
->Eval
.Map1Normal
;
1269 case GL_MAP1_TEXTURE_COORD_1
:
1270 if (ctx
->API
!= API_OPENGL_COMPAT
)
1271 goto invalid_enum_error
;
1272 return ctx
->Eval
.Map1TextureCoord1
;
1273 case GL_MAP1_TEXTURE_COORD_2
:
1274 if (ctx
->API
!= API_OPENGL_COMPAT
)
1275 goto invalid_enum_error
;
1276 return ctx
->Eval
.Map1TextureCoord2
;
1277 case GL_MAP1_TEXTURE_COORD_3
:
1278 if (ctx
->API
!= API_OPENGL_COMPAT
)
1279 goto invalid_enum_error
;
1280 return ctx
->Eval
.Map1TextureCoord3
;
1281 case GL_MAP1_TEXTURE_COORD_4
:
1282 if (ctx
->API
!= API_OPENGL_COMPAT
)
1283 goto invalid_enum_error
;
1284 return ctx
->Eval
.Map1TextureCoord4
;
1285 case GL_MAP1_VERTEX_3
:
1286 if (ctx
->API
!= API_OPENGL_COMPAT
)
1287 goto invalid_enum_error
;
1288 return ctx
->Eval
.Map1Vertex3
;
1289 case GL_MAP1_VERTEX_4
:
1290 if (ctx
->API
!= API_OPENGL_COMPAT
)
1291 goto invalid_enum_error
;
1292 return ctx
->Eval
.Map1Vertex4
;
1293 case GL_MAP2_COLOR_4
:
1294 if (ctx
->API
!= API_OPENGL_COMPAT
)
1295 goto invalid_enum_error
;
1296 return ctx
->Eval
.Map2Color4
;
1298 if (ctx
->API
!= API_OPENGL_COMPAT
)
1299 goto invalid_enum_error
;
1300 return ctx
->Eval
.Map2Index
;
1301 case GL_MAP2_NORMAL
:
1302 if (ctx
->API
!= API_OPENGL_COMPAT
)
1303 goto invalid_enum_error
;
1304 return ctx
->Eval
.Map2Normal
;
1305 case GL_MAP2_TEXTURE_COORD_1
:
1306 if (ctx
->API
!= API_OPENGL_COMPAT
)
1307 goto invalid_enum_error
;
1308 return ctx
->Eval
.Map2TextureCoord1
;
1309 case GL_MAP2_TEXTURE_COORD_2
:
1310 if (ctx
->API
!= API_OPENGL_COMPAT
)
1311 goto invalid_enum_error
;
1312 return ctx
->Eval
.Map2TextureCoord2
;
1313 case GL_MAP2_TEXTURE_COORD_3
:
1314 if (ctx
->API
!= API_OPENGL_COMPAT
)
1315 goto invalid_enum_error
;
1316 return ctx
->Eval
.Map2TextureCoord3
;
1317 case GL_MAP2_TEXTURE_COORD_4
:
1318 if (ctx
->API
!= API_OPENGL_COMPAT
)
1319 goto invalid_enum_error
;
1320 return ctx
->Eval
.Map2TextureCoord4
;
1321 case GL_MAP2_VERTEX_3
:
1322 if (ctx
->API
!= API_OPENGL_COMPAT
)
1323 goto invalid_enum_error
;
1324 return ctx
->Eval
.Map2Vertex3
;
1325 case GL_MAP2_VERTEX_4
:
1326 if (ctx
->API
!= API_OPENGL_COMPAT
)
1327 goto invalid_enum_error
;
1328 return ctx
->Eval
.Map2Vertex4
;
1330 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1331 goto invalid_enum_error
;
1332 return ctx
->Transform
.Normalize
;
1333 case GL_POINT_SMOOTH
:
1334 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1335 goto invalid_enum_error
;
1336 return ctx
->Point
.SmoothFlag
;
1337 case GL_POLYGON_SMOOTH
:
1338 if (!_mesa_is_desktop_gl(ctx
))
1339 goto invalid_enum_error
;
1340 return ctx
->Polygon
.SmoothFlag
;
1341 case GL_POLYGON_STIPPLE
:
1342 if (ctx
->API
!= API_OPENGL_COMPAT
)
1343 goto invalid_enum_error
;
1344 return ctx
->Polygon
.StippleFlag
;
1345 case GL_POLYGON_OFFSET_POINT
:
1346 if (!_mesa_is_desktop_gl(ctx
))
1347 goto invalid_enum_error
;
1348 return ctx
->Polygon
.OffsetPoint
;
1349 case GL_POLYGON_OFFSET_LINE
:
1350 if (!_mesa_is_desktop_gl(ctx
))
1351 goto invalid_enum_error
;
1352 return ctx
->Polygon
.OffsetLine
;
1353 case GL_POLYGON_OFFSET_FILL
:
1354 return ctx
->Polygon
.OffsetFill
;
1355 case GL_RESCALE_NORMAL_EXT
:
1356 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1357 goto invalid_enum_error
;
1358 return ctx
->Transform
.RescaleNormals
;
1359 case GL_SCISSOR_TEST
:
1360 return ctx
->Scissor
.Enabled
;
1361 case GL_STENCIL_TEST
:
1362 return ctx
->Stencil
.Enabled
;
1364 if (ctx
->API
!= API_OPENGL_COMPAT
)
1365 goto invalid_enum_error
;
1366 return is_texture_enabled(ctx
, TEXTURE_1D_BIT
);
1368 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1369 goto invalid_enum_error
;
1370 return is_texture_enabled(ctx
, TEXTURE_2D_BIT
);
1372 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1373 goto invalid_enum_error
;
1374 return is_texture_enabled(ctx
, TEXTURE_3D_BIT
);
1375 case GL_TEXTURE_GEN_S
:
1376 case GL_TEXTURE_GEN_T
:
1377 case GL_TEXTURE_GEN_R
:
1378 case GL_TEXTURE_GEN_Q
:
1380 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1382 if (ctx
->API
!= API_OPENGL_COMPAT
)
1383 goto invalid_enum_error
;
1386 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
1387 return (texUnit
->TexGenEnabled
& coordBit
) ? GL_TRUE
: GL_FALSE
;
1391 case GL_TEXTURE_GEN_STR_OES
:
1393 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1395 if (ctx
->API
!= API_OPENGLES
)
1396 goto invalid_enum_error
;
1399 return (texUnit
->TexGenEnabled
& STR_BITS
) == STR_BITS
1400 ? GL_TRUE
: GL_FALSE
;
1404 /* client-side state */
1405 case GL_VERTEX_ARRAY
:
1406 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1407 goto invalid_enum_error
;
1408 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
!= 0);
1409 case GL_NORMAL_ARRAY
:
1410 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1411 goto invalid_enum_error
;
1412 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
!= 0);
1413 case GL_COLOR_ARRAY
:
1414 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1415 goto invalid_enum_error
;
1416 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
!= 0);
1417 case GL_INDEX_ARRAY
:
1418 if (ctx
->API
!= API_OPENGL_COMPAT
)
1419 goto invalid_enum_error
;
1420 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
!= 0);
1421 case GL_TEXTURE_COORD_ARRAY
:
1422 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1423 goto invalid_enum_error
;
1424 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)]
1426 case GL_EDGE_FLAG_ARRAY
:
1427 if (ctx
->API
!= API_OPENGL_COMPAT
)
1428 goto invalid_enum_error
;
1429 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
!= 0);
1430 case GL_FOG_COORDINATE_ARRAY_EXT
:
1431 if (ctx
->API
!= API_OPENGL_COMPAT
)
1432 goto invalid_enum_error
;
1433 CHECK_EXTENSION(EXT_fog_coord
);
1434 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
!= 0);
1435 case GL_SECONDARY_COLOR_ARRAY_EXT
:
1436 if (ctx
->API
!= API_OPENGL_COMPAT
)
1437 goto invalid_enum_error
;
1438 CHECK_EXTENSION(EXT_secondary_color
);
1439 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
!= 0);
1440 case GL_POINT_SIZE_ARRAY_OES
:
1441 if (ctx
->API
!= API_OPENGLES
)
1442 goto invalid_enum_error
;
1443 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
!= 0);
1445 /* GL_ARB_texture_cube_map */
1446 case GL_TEXTURE_CUBE_MAP_ARB
:
1447 CHECK_EXTENSION(ARB_texture_cube_map
);
1448 return is_texture_enabled(ctx
, TEXTURE_CUBE_BIT
);
1450 /* GL_EXT_secondary_color */
1451 case GL_COLOR_SUM_EXT
:
1452 if (ctx
->API
!= API_OPENGL_COMPAT
)
1453 goto invalid_enum_error
;
1454 CHECK_EXTENSION2(EXT_secondary_color
, ARB_vertex_program
);
1455 return ctx
->Fog
.ColorSumEnabled
;
1457 /* GL_ARB_multisample */
1458 case GL_MULTISAMPLE_ARB
:
1459 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1460 goto invalid_enum_error
;
1461 return ctx
->Multisample
.Enabled
;
1462 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
1463 return ctx
->Multisample
.SampleAlphaToCoverage
;
1464 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
1465 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1466 goto invalid_enum_error
;
1467 return ctx
->Multisample
.SampleAlphaToOne
;
1468 case GL_SAMPLE_COVERAGE_ARB
:
1469 return ctx
->Multisample
.SampleCoverage
;
1470 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
1471 if (!_mesa_is_desktop_gl(ctx
))
1472 goto invalid_enum_error
;
1473 return ctx
->Multisample
.SampleCoverageInvert
;
1475 /* GL_IBM_rasterpos_clip */
1476 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
1477 if (ctx
->API
!= API_OPENGL_COMPAT
)
1478 goto invalid_enum_error
;
1479 return ctx
->Transform
.RasterPositionUnclipped
;
1481 /* GL_NV_point_sprite */
1482 case GL_POINT_SPRITE_NV
:
1483 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1484 goto invalid_enum_error
;
1485 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
)
1486 return ctx
->Point
.PointSprite
;
1488 case GL_VERTEX_PROGRAM_ARB
:
1489 if (ctx
->API
!= API_OPENGL_COMPAT
)
1490 goto invalid_enum_error
;
1491 CHECK_EXTENSION(ARB_vertex_program
);
1492 return ctx
->VertexProgram
.Enabled
;
1493 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
1494 /* This was added with ARB_vertex_program, but it is also used with
1495 * GLSL vertex shaders on desktop.
1497 if (!_mesa_is_desktop_gl(ctx
))
1498 goto invalid_enum_error
;
1499 CHECK_EXTENSION(ARB_vertex_program
);
1500 return ctx
->VertexProgram
.PointSizeEnabled
;
1501 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
1502 if (ctx
->API
!= API_OPENGL_COMPAT
)
1503 goto invalid_enum_error
;
1504 CHECK_EXTENSION(ARB_vertex_program
);
1505 return ctx
->VertexProgram
.TwoSideEnabled
;
1507 /* GL_NV_texture_rectangle */
1508 case GL_TEXTURE_RECTANGLE_NV
:
1509 if (ctx
->API
!= API_OPENGL_COMPAT
)
1510 goto invalid_enum_error
;
1511 CHECK_EXTENSION(NV_texture_rectangle
);
1512 return is_texture_enabled(ctx
, TEXTURE_RECT_BIT
);
1514 /* GL_EXT_stencil_two_side */
1515 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
1516 if (ctx
->API
!= API_OPENGL_COMPAT
)
1517 goto invalid_enum_error
;
1518 CHECK_EXTENSION(EXT_stencil_two_side
);
1519 return ctx
->Stencil
.TestTwoSide
;
1521 case GL_FRAGMENT_PROGRAM_ARB
:
1522 if (ctx
->API
!= API_OPENGL_COMPAT
)
1523 goto invalid_enum_error
;
1524 return ctx
->FragmentProgram
.Enabled
;
1526 /* GL_EXT_depth_bounds_test */
1527 case GL_DEPTH_BOUNDS_TEST_EXT
:
1528 if (!_mesa_is_desktop_gl(ctx
))
1529 goto invalid_enum_error
;
1530 CHECK_EXTENSION(EXT_depth_bounds_test
);
1531 return ctx
->Depth
.BoundsTest
;
1533 /* GL_ARB_depth_clamp */
1534 case GL_DEPTH_CLAMP
:
1535 if (!_mesa_is_desktop_gl(ctx
))
1536 goto invalid_enum_error
;
1537 CHECK_EXTENSION(ARB_depth_clamp
);
1538 return ctx
->Transform
.DepthClamp
;
1540 case GL_FRAGMENT_SHADER_ATI
:
1541 if (ctx
->API
!= API_OPENGL_COMPAT
)
1542 goto invalid_enum_error
;
1543 CHECK_EXTENSION(ATI_fragment_shader
);
1544 return ctx
->ATIFragmentShader
.Enabled
;
1546 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1547 if (!_mesa_is_desktop_gl(ctx
))
1548 goto invalid_enum_error
;
1549 CHECK_EXTENSION(ARB_seamless_cube_map
);
1550 return ctx
->Texture
.CubeMapSeamless
;
1552 case GL_RASTERIZER_DISCARD
:
1553 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1554 goto invalid_enum_error
;
1555 CHECK_EXTENSION(EXT_transform_feedback
);
1556 return ctx
->RasterDiscard
;
1558 /* GL_NV_primitive_restart */
1559 case GL_PRIMITIVE_RESTART_NV
:
1560 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.NV_primitive_restart
) {
1561 goto invalid_enum_error
;
1563 return ctx
->Array
.PrimitiveRestart
;
1565 /* GL 3.1 primitive restart */
1566 case GL_PRIMITIVE_RESTART
:
1567 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
1568 goto invalid_enum_error
;
1570 return ctx
->Array
.PrimitiveRestart
;
1572 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
1573 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
) {
1574 goto invalid_enum_error
;
1576 return ctx
->Array
.PrimitiveRestartFixedIndex
;
1578 /* GL3.0 - GL_framebuffer_sRGB */
1579 case GL_FRAMEBUFFER_SRGB_EXT
:
1580 if (!_mesa_is_desktop_gl(ctx
))
1581 goto invalid_enum_error
;
1582 CHECK_EXTENSION(EXT_framebuffer_sRGB
);
1583 return ctx
->Color
.sRGBEnabled
;
1585 /* GL_OES_EGL_image_external */
1586 case GL_TEXTURE_EXTERNAL_OES
:
1587 if (!_mesa_is_gles(ctx
))
1588 goto invalid_enum_error
;
1589 CHECK_EXTENSION(OES_EGL_image_external
);
1590 return is_texture_enabled(ctx
, TEXTURE_EXTERNAL_BIT
);
1593 goto invalid_enum_error
;
1599 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabled(%s)",
1600 _mesa_lookup_enum_by_nr(cap
));