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 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 client_state( ctx
, cap
, GL_TRUE
);
173 * Disable GL capability.
174 * \param cap state to enable/disable.
176 * Get's the current context, assures that we're outside glBegin()/glEnd() and
177 * calls client_state().
180 _mesa_DisableClientState( GLenum cap
)
182 GET_CURRENT_CONTEXT(ctx
);
183 client_state( ctx
, cap
, GL_FALSE
);
187 #undef CHECK_EXTENSION
188 #define CHECK_EXTENSION(EXTNAME, CAP) \
189 if (!ctx->Extensions.EXTNAME) { \
190 goto invalid_enum_error; \
193 #define CHECK_EXTENSION2(EXT1, EXT2, CAP) \
194 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
195 goto invalid_enum_error; \
199 * Return pointer to current texture unit for setting/getting coordinate
201 * Note that we'll set GL_INVALID_OPERATION and return NULL if the active
202 * texture unit is higher than the number of supported coordinate units.
204 static struct gl_texture_unit
*
205 get_texcoord_unit(struct gl_context
*ctx
)
207 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
208 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glEnable/Disable(texcoord unit)");
212 return &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
218 * Helper function to enable or disable a texture target.
219 * \param bit one of the TEXTURE_x_BIT values
220 * \return GL_TRUE if state is changing or GL_FALSE if no change
223 enable_texture(struct gl_context
*ctx
, GLboolean state
, GLbitfield texBit
)
225 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
226 const GLbitfield newenabled
= state
227 ? (texUnit
->Enabled
| texBit
) : (texUnit
->Enabled
& ~texBit
);
229 if (texUnit
->Enabled
== newenabled
)
232 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
233 texUnit
->Enabled
= newenabled
;
239 * Helper function to enable or disable GL_MULTISAMPLE, skipping the check for
240 * whether the API supports it (GLES doesn't).
243 _mesa_set_multisample(struct gl_context
*ctx
, GLboolean state
)
245 if (ctx
->Multisample
.Enabled
== state
)
247 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
248 ctx
->Multisample
.Enabled
= state
;
250 if (ctx
->Driver
.Enable
) {
251 ctx
->Driver
.Enable(ctx
, GL_MULTISAMPLE
, state
);
256 * Helper function to enable or disable GL_FRAMEBUFFER_SRGB, skipping the
257 * check for whether the API supports it (GLES doesn't).
260 _mesa_set_framebuffer_srgb(struct gl_context
*ctx
, GLboolean state
)
262 if (ctx
->Color
.sRGBEnabled
== state
)
264 FLUSH_VERTICES(ctx
, _NEW_BUFFERS
);
265 ctx
->Color
.sRGBEnabled
= state
;
267 if (ctx
->Driver
.Enable
) {
268 ctx
->Driver
.Enable(ctx
, GL_FRAMEBUFFER_SRGB
, state
);
273 * Helper function to enable or disable state.
275 * \param ctx GL context.
276 * \param cap the state to enable/disable
277 * \param state whether to enable or disable the specified capability.
279 * Updates the current context and flushes the vertices as needed. For
280 * capabilities associated with extensions it verifies that those extensions
281 * are effectivly present before updating. Notifies the driver via
282 * dd_function_table::Enable.
285 _mesa_set_enable(struct gl_context
*ctx
, GLenum cap
, GLboolean state
)
287 if (MESA_VERBOSE
& VERBOSE_API
)
288 _mesa_debug(ctx
, "%s %s (newstate is %x)\n",
289 state
? "glEnable" : "glDisable",
290 _mesa_lookup_enum_by_nr(cap
),
295 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
296 goto invalid_enum_error
;
297 if (ctx
->Color
.AlphaEnabled
== state
)
299 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
300 ctx
->Color
.AlphaEnabled
= state
;
303 if (ctx
->API
!= API_OPENGL_COMPAT
)
304 goto invalid_enum_error
;
305 if (ctx
->Eval
.AutoNormal
== state
)
307 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
308 ctx
->Eval
.AutoNormal
= state
;
312 GLbitfield newEnabled
=
313 state
* ((1 << ctx
->Const
.MaxDrawBuffers
) - 1);
314 if (newEnabled
!= ctx
->Color
.BlendEnabled
) {
315 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
316 ctx
->Color
.BlendEnabled
= newEnabled
;
320 case GL_CLIP_DISTANCE0
:
321 case GL_CLIP_DISTANCE1
:
322 case GL_CLIP_DISTANCE2
:
323 case GL_CLIP_DISTANCE3
:
324 case GL_CLIP_DISTANCE4
:
325 case GL_CLIP_DISTANCE5
:
326 case GL_CLIP_DISTANCE6
:
327 case GL_CLIP_DISTANCE7
:
329 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
331 if (p
>= ctx
->Const
.MaxClipPlanes
)
332 goto invalid_enum_error
;
334 if ((ctx
->Transform
.ClipPlanesEnabled
& (1 << p
))
335 == ((GLuint
) state
<< p
))
338 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
341 ctx
->Transform
.ClipPlanesEnabled
|= (1 << p
);
342 _mesa_update_clip_plane(ctx
, p
);
345 ctx
->Transform
.ClipPlanesEnabled
&= ~(1 << p
);
349 case GL_COLOR_MATERIAL
:
350 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
351 goto invalid_enum_error
;
352 if (ctx
->Light
.ColorMaterialEnabled
== state
)
354 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
355 FLUSH_CURRENT(ctx
, 0);
356 ctx
->Light
.ColorMaterialEnabled
= state
;
358 _mesa_update_color_material( ctx
,
359 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
] );
363 if (ctx
->Polygon
.CullFlag
== state
)
365 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
366 ctx
->Polygon
.CullFlag
= state
;
369 if (ctx
->Depth
.Test
== state
)
371 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
372 ctx
->Depth
.Test
= 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
:
662 if (ctx
->Scissor
.Enabled
== state
)
664 FLUSH_VERTICES(ctx
, _NEW_SCISSOR
);
665 ctx
->Scissor
.Enabled
= state
;
667 case GL_STENCIL_TEST
:
668 if (ctx
->Stencil
.Enabled
== state
)
670 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
671 ctx
->Stencil
.Enabled
= state
;
674 if (ctx
->API
!= API_OPENGL_COMPAT
)
675 goto invalid_enum_error
;
676 if (!enable_texture(ctx
, state
, TEXTURE_1D_BIT
)) {
681 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
682 goto invalid_enum_error
;
683 if (!enable_texture(ctx
, state
, TEXTURE_2D_BIT
)) {
688 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
689 goto invalid_enum_error
;
690 if (!enable_texture(ctx
, state
, TEXTURE_3D_BIT
)) {
694 case GL_TEXTURE_GEN_S
:
695 case GL_TEXTURE_GEN_T
:
696 case GL_TEXTURE_GEN_R
:
697 case GL_TEXTURE_GEN_Q
:
699 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
701 if (ctx
->API
!= API_OPENGL_COMPAT
)
702 goto invalid_enum_error
;
705 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
706 GLbitfield newenabled
= texUnit
->TexGenEnabled
& ~coordBit
;
708 newenabled
|= coordBit
;
709 if (texUnit
->TexGenEnabled
== newenabled
)
711 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
712 texUnit
->TexGenEnabled
= newenabled
;
717 case GL_TEXTURE_GEN_STR_OES
:
718 /* disable S, T, and R at the same time */
720 struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
722 if (ctx
->API
!= API_OPENGLES
)
723 goto invalid_enum_error
;
727 texUnit
->TexGenEnabled
& ~STR_BITS
;
729 newenabled
|= STR_BITS
;
730 if (texUnit
->TexGenEnabled
== newenabled
)
732 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
733 texUnit
->TexGenEnabled
= newenabled
;
738 /* client-side state */
739 case GL_VERTEX_ARRAY
:
740 case GL_NORMAL_ARRAY
:
743 case GL_TEXTURE_COORD_ARRAY
:
744 case GL_EDGE_FLAG_ARRAY
:
745 case GL_FOG_COORDINATE_ARRAY_EXT
:
746 case GL_SECONDARY_COLOR_ARRAY_EXT
:
747 case GL_POINT_SIZE_ARRAY_OES
:
748 client_state( ctx
, cap
, state
);
751 /* GL_ARB_texture_cube_map */
752 case GL_TEXTURE_CUBE_MAP_ARB
:
753 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
754 goto invalid_enum_error
;
755 CHECK_EXTENSION(ARB_texture_cube_map
, cap
);
756 if (!enable_texture(ctx
, state
, TEXTURE_CUBE_BIT
)) {
761 /* GL_EXT_secondary_color */
762 case GL_COLOR_SUM_EXT
:
763 if (ctx
->API
!= API_OPENGL_COMPAT
)
764 goto invalid_enum_error
;
765 CHECK_EXTENSION2(EXT_secondary_color
, ARB_vertex_program
, cap
);
766 if (ctx
->Fog
.ColorSumEnabled
== state
)
768 FLUSH_VERTICES(ctx
, _NEW_FOG
);
769 ctx
->Fog
.ColorSumEnabled
= state
;
772 /* GL_ARB_multisample */
773 case GL_MULTISAMPLE_ARB
:
774 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
775 goto invalid_enum_error
;
776 _mesa_set_multisample(ctx
, state
);
778 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
779 if (ctx
->Multisample
.SampleAlphaToCoverage
== state
)
781 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
782 ctx
->Multisample
.SampleAlphaToCoverage
= state
;
784 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
785 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
786 goto invalid_enum_error
;
787 if (ctx
->Multisample
.SampleAlphaToOne
== state
)
789 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
790 ctx
->Multisample
.SampleAlphaToOne
= state
;
792 case GL_SAMPLE_COVERAGE_ARB
:
793 if (ctx
->Multisample
.SampleCoverage
== state
)
795 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
796 ctx
->Multisample
.SampleCoverage
= state
;
798 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
799 if (!_mesa_is_desktop_gl(ctx
))
800 goto invalid_enum_error
;
801 if (ctx
->Multisample
.SampleCoverageInvert
== state
)
803 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
804 ctx
->Multisample
.SampleCoverageInvert
= state
;
807 /* GL_IBM_rasterpos_clip */
808 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
809 if (ctx
->API
!= API_OPENGL_COMPAT
)
810 goto invalid_enum_error
;
811 if (ctx
->Transform
.RasterPositionUnclipped
== state
)
813 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
814 ctx
->Transform
.RasterPositionUnclipped
= state
;
817 /* GL_NV_point_sprite */
818 case GL_POINT_SPRITE_NV
:
819 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
820 goto invalid_enum_error
;
821 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
, cap
);
822 if (ctx
->Point
.PointSprite
== state
)
824 FLUSH_VERTICES(ctx
, _NEW_POINT
);
825 ctx
->Point
.PointSprite
= state
;
828 case GL_VERTEX_PROGRAM_ARB
:
829 if (ctx
->API
!= API_OPENGL_COMPAT
)
830 goto invalid_enum_error
;
831 CHECK_EXTENSION(ARB_vertex_program
, cap
);
832 if (ctx
->VertexProgram
.Enabled
== state
)
834 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
835 ctx
->VertexProgram
.Enabled
= state
;
837 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
838 /* This was added with ARB_vertex_program, but it is also used with
839 * GLSL vertex shaders on desktop.
841 if (!_mesa_is_desktop_gl(ctx
))
842 goto invalid_enum_error
;
843 CHECK_EXTENSION(ARB_vertex_program
, cap
);
844 if (ctx
->VertexProgram
.PointSizeEnabled
== state
)
846 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
847 ctx
->VertexProgram
.PointSizeEnabled
= state
;
849 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
850 if (ctx
->API
!= API_OPENGL_COMPAT
)
851 goto invalid_enum_error
;
852 CHECK_EXTENSION(ARB_vertex_program
, cap
);
853 if (ctx
->VertexProgram
.TwoSideEnabled
== state
)
855 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
856 ctx
->VertexProgram
.TwoSideEnabled
= state
;
859 /* GL_NV_texture_rectangle */
860 case GL_TEXTURE_RECTANGLE_NV
:
861 if (ctx
->API
!= API_OPENGL_COMPAT
)
862 goto invalid_enum_error
;
863 CHECK_EXTENSION(NV_texture_rectangle
, cap
);
864 if (!enable_texture(ctx
, state
, TEXTURE_RECT_BIT
)) {
869 /* GL_EXT_stencil_two_side */
870 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
871 if (ctx
->API
!= API_OPENGL_COMPAT
)
872 goto invalid_enum_error
;
873 CHECK_EXTENSION(EXT_stencil_two_side
, cap
);
874 if (ctx
->Stencil
.TestTwoSide
== state
)
876 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
877 ctx
->Stencil
.TestTwoSide
= state
;
879 ctx
->Stencil
._BackFace
= 2;
881 ctx
->Stencil
._BackFace
= 1;
885 case GL_FRAGMENT_PROGRAM_ARB
:
886 if (ctx
->API
!= API_OPENGL_COMPAT
)
887 goto invalid_enum_error
;
888 CHECK_EXTENSION(ARB_fragment_program
, cap
);
889 if (ctx
->FragmentProgram
.Enabled
== state
)
891 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
892 ctx
->FragmentProgram
.Enabled
= state
;
895 /* GL_EXT_depth_bounds_test */
896 case GL_DEPTH_BOUNDS_TEST_EXT
:
897 if (!_mesa_is_desktop_gl(ctx
))
898 goto invalid_enum_error
;
899 CHECK_EXTENSION(EXT_depth_bounds_test
, cap
);
900 if (ctx
->Depth
.BoundsTest
== state
)
902 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
903 ctx
->Depth
.BoundsTest
= state
;
907 if (!_mesa_is_desktop_gl(ctx
))
908 goto invalid_enum_error
;
909 CHECK_EXTENSION(ARB_depth_clamp
, cap
);
910 if (ctx
->Transform
.DepthClamp
== state
)
912 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
913 ctx
->Transform
.DepthClamp
= state
;
916 case GL_FRAGMENT_SHADER_ATI
:
917 if (ctx
->API
!= API_OPENGL_COMPAT
)
918 goto invalid_enum_error
;
919 CHECK_EXTENSION(ATI_fragment_shader
, cap
);
920 if (ctx
->ATIFragmentShader
.Enabled
== state
)
922 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
923 ctx
->ATIFragmentShader
.Enabled
= state
;
926 /* GL_MESA_texture_array */
927 case GL_TEXTURE_1D_ARRAY_EXT
:
928 if (ctx
->API
!= API_OPENGL_COMPAT
)
929 goto invalid_enum_error
;
930 CHECK_EXTENSION(MESA_texture_array
, cap
);
931 if (!enable_texture(ctx
, state
, TEXTURE_1D_ARRAY_BIT
)) {
936 case GL_TEXTURE_2D_ARRAY_EXT
:
937 if (ctx
->API
!= API_OPENGL_COMPAT
)
938 goto invalid_enum_error
;
939 CHECK_EXTENSION(MESA_texture_array
, cap
);
940 if (!enable_texture(ctx
, state
, TEXTURE_2D_ARRAY_BIT
)) {
945 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
946 if (!_mesa_is_desktop_gl(ctx
))
947 goto invalid_enum_error
;
948 CHECK_EXTENSION(ARB_seamless_cube_map
, cap
);
949 if (ctx
->Texture
.CubeMapSeamless
!= state
) {
950 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
951 ctx
->Texture
.CubeMapSeamless
= state
;
955 case GL_RASTERIZER_DISCARD
:
956 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
957 goto invalid_enum_error
;
958 CHECK_EXTENSION(EXT_transform_feedback
, cap
);
959 if (ctx
->RasterDiscard
!= state
) {
960 FLUSH_VERTICES(ctx
, 0);
961 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewRasterizerDiscard
;
962 ctx
->RasterDiscard
= state
;
966 /* GL 3.1 primitive restart. Note: this enum is different from
967 * GL_PRIMITIVE_RESTART_NV (which is client state).
969 case GL_PRIMITIVE_RESTART
:
970 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
971 goto invalid_enum_error
;
973 if (ctx
->Array
.PrimitiveRestart
!= state
) {
974 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
975 ctx
->Array
.PrimitiveRestart
= state
;
976 update_derived_primitive_restart_state(ctx
);
980 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
981 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
)
982 goto invalid_enum_error
;
983 if (ctx
->Array
.PrimitiveRestartFixedIndex
!= state
) {
984 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
985 ctx
->Array
.PrimitiveRestartFixedIndex
= state
;
986 update_derived_primitive_restart_state(ctx
);
990 /* GL3.0 - GL_framebuffer_sRGB */
991 case GL_FRAMEBUFFER_SRGB_EXT
:
992 if (!_mesa_is_desktop_gl(ctx
))
993 goto invalid_enum_error
;
994 CHECK_EXTENSION(EXT_framebuffer_sRGB
, cap
);
995 _mesa_set_framebuffer_srgb(ctx
, state
);
998 /* GL_OES_EGL_image_external */
999 case GL_TEXTURE_EXTERNAL_OES
:
1000 if (!_mesa_is_gles(ctx
))
1001 goto invalid_enum_error
;
1002 CHECK_EXTENSION(OES_EGL_image_external
, cap
);
1003 if (!enable_texture(ctx
, state
, TEXTURE_EXTERNAL_BIT
)) {
1008 /* ARB_texture_multisample */
1009 case GL_SAMPLE_MASK
:
1010 if (!_mesa_is_desktop_gl(ctx
))
1011 goto invalid_enum_error
;
1012 CHECK_EXTENSION(ARB_texture_multisample
, cap
);
1013 if (ctx
->Multisample
.SampleMask
== state
)
1015 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
1016 ctx
->Multisample
.SampleMask
= state
;
1020 goto invalid_enum_error
;
1023 if (ctx
->Driver
.Enable
) {
1024 ctx
->Driver
.Enable( ctx
, cap
, state
);
1030 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%s(%s)",
1031 state
? "Enable" : "Disable", _mesa_lookup_enum_by_nr(cap
));
1036 * Enable GL capability. Called by glEnable()
1037 * \param cap state to enable.
1040 _mesa_Enable( GLenum cap
)
1042 GET_CURRENT_CONTEXT(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
);
1057 _mesa_set_enable( ctx
, cap
, GL_FALSE
);
1063 * Enable/disable an indexed state var.
1066 _mesa_set_enablei(struct gl_context
*ctx
, GLenum cap
,
1067 GLuint index
, GLboolean state
)
1069 ASSERT(state
== 0 || state
== 1);
1072 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
1073 goto invalid_enum_error
;
1075 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1076 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1077 state
? "glEnableIndexed" : "glDisableIndexed", index
);
1080 if (((ctx
->Color
.BlendEnabled
>> index
) & 1) != state
) {
1081 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
1083 ctx
->Color
.BlendEnabled
|= (1 << index
);
1085 ctx
->Color
.BlendEnabled
&= ~(1 << index
);
1089 goto invalid_enum_error
;
1094 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(cap=%s)",
1095 state
? "glEnablei" : "glDisablei",
1096 _mesa_lookup_enum_by_nr(cap
));
1101 _mesa_Disablei( GLenum cap
, GLuint index
)
1103 GET_CURRENT_CONTEXT(ctx
);
1104 _mesa_set_enablei(ctx
, cap
, index
, GL_FALSE
);
1109 _mesa_Enablei( GLenum cap
, GLuint index
)
1111 GET_CURRENT_CONTEXT(ctx
);
1112 _mesa_set_enablei(ctx
, cap
, index
, GL_TRUE
);
1116 GLboolean GLAPIENTRY
1117 _mesa_IsEnabledi( GLenum cap
, GLuint index
)
1119 GET_CURRENT_CONTEXT(ctx
);
1120 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1123 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1124 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1128 return (ctx
->Color
.BlendEnabled
>> index
) & 1;
1130 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabledIndexed(cap=%s)",
1131 _mesa_lookup_enum_by_nr(cap
));
1139 #undef CHECK_EXTENSION
1140 #define CHECK_EXTENSION(EXTNAME) \
1141 if (!ctx->Extensions.EXTNAME) { \
1142 goto invalid_enum_error; \
1145 #undef CHECK_EXTENSION2
1146 #define CHECK_EXTENSION2(EXT1, EXT2) \
1147 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1148 goto invalid_enum_error; \
1153 * Helper function to determine whether a texture target is enabled.
1156 is_texture_enabled(struct gl_context
*ctx
, GLbitfield bit
)
1158 const struct gl_texture_unit
*const texUnit
=
1159 &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1160 return (texUnit
->Enabled
& bit
) ? GL_TRUE
: GL_FALSE
;
1165 * Return simple enable/disable state.
1167 * \param cap state variable to query.
1169 * Returns the state of the specified capability from the current GL context.
1170 * For the capabilities associated with extensions verifies that those
1171 * extensions are effectively present before reporting.
1173 GLboolean GLAPIENTRY
1174 _mesa_IsEnabled( GLenum cap
)
1176 GET_CURRENT_CONTEXT(ctx
);
1177 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1181 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1182 goto invalid_enum_error
;
1183 return ctx
->Color
.AlphaEnabled
;
1184 case GL_AUTO_NORMAL
:
1185 if (ctx
->API
!= API_OPENGL_COMPAT
)
1186 goto invalid_enum_error
;
1187 return ctx
->Eval
.AutoNormal
;
1189 return ctx
->Color
.BlendEnabled
& 1; /* return state for buffer[0] */
1190 case GL_CLIP_DISTANCE0
:
1191 case GL_CLIP_DISTANCE1
:
1192 case GL_CLIP_DISTANCE2
:
1193 case GL_CLIP_DISTANCE3
:
1194 case GL_CLIP_DISTANCE4
:
1195 case GL_CLIP_DISTANCE5
:
1196 case GL_CLIP_DISTANCE6
:
1197 case GL_CLIP_DISTANCE7
: {
1198 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
1200 if (p
>= ctx
->Const
.MaxClipPlanes
)
1201 goto invalid_enum_error
;
1203 return (ctx
->Transform
.ClipPlanesEnabled
>> p
) & 1;
1205 case GL_COLOR_MATERIAL
:
1206 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1207 goto invalid_enum_error
;
1208 return ctx
->Light
.ColorMaterialEnabled
;
1210 return ctx
->Polygon
.CullFlag
;
1211 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
:
1212 if (!_mesa_is_desktop_gl(ctx
))
1213 goto invalid_enum_error
;
1214 return ctx
->Debug
.SyncOutput
;
1216 return ctx
->Depth
.Test
;
1218 return ctx
->Color
.DitherFlag
;
1220 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1221 goto invalid_enum_error
;
1222 return ctx
->Fog
.Enabled
;
1224 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1225 goto invalid_enum_error
;
1226 return ctx
->Light
.Enabled
;
1235 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1236 goto invalid_enum_error
;
1237 return ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
;
1238 case GL_LINE_SMOOTH
:
1239 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1240 goto invalid_enum_error
;
1241 return ctx
->Line
.SmoothFlag
;
1242 case GL_LINE_STIPPLE
:
1243 if (ctx
->API
!= API_OPENGL_COMPAT
)
1244 goto invalid_enum_error
;
1245 return ctx
->Line
.StippleFlag
;
1246 case GL_INDEX_LOGIC_OP
:
1247 if (ctx
->API
!= API_OPENGL_COMPAT
)
1248 goto invalid_enum_error
;
1249 return ctx
->Color
.IndexLogicOpEnabled
;
1250 case GL_COLOR_LOGIC_OP
:
1251 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1252 goto invalid_enum_error
;
1253 return ctx
->Color
.ColorLogicOpEnabled
;
1254 case GL_MAP1_COLOR_4
:
1255 if (ctx
->API
!= API_OPENGL_COMPAT
)
1256 goto invalid_enum_error
;
1257 return ctx
->Eval
.Map1Color4
;
1259 if (ctx
->API
!= API_OPENGL_COMPAT
)
1260 goto invalid_enum_error
;
1261 return ctx
->Eval
.Map1Index
;
1262 case GL_MAP1_NORMAL
:
1263 if (ctx
->API
!= API_OPENGL_COMPAT
)
1264 goto invalid_enum_error
;
1265 return ctx
->Eval
.Map1Normal
;
1266 case GL_MAP1_TEXTURE_COORD_1
:
1267 if (ctx
->API
!= API_OPENGL_COMPAT
)
1268 goto invalid_enum_error
;
1269 return ctx
->Eval
.Map1TextureCoord1
;
1270 case GL_MAP1_TEXTURE_COORD_2
:
1271 if (ctx
->API
!= API_OPENGL_COMPAT
)
1272 goto invalid_enum_error
;
1273 return ctx
->Eval
.Map1TextureCoord2
;
1274 case GL_MAP1_TEXTURE_COORD_3
:
1275 if (ctx
->API
!= API_OPENGL_COMPAT
)
1276 goto invalid_enum_error
;
1277 return ctx
->Eval
.Map1TextureCoord3
;
1278 case GL_MAP1_TEXTURE_COORD_4
:
1279 if (ctx
->API
!= API_OPENGL_COMPAT
)
1280 goto invalid_enum_error
;
1281 return ctx
->Eval
.Map1TextureCoord4
;
1282 case GL_MAP1_VERTEX_3
:
1283 if (ctx
->API
!= API_OPENGL_COMPAT
)
1284 goto invalid_enum_error
;
1285 return ctx
->Eval
.Map1Vertex3
;
1286 case GL_MAP1_VERTEX_4
:
1287 if (ctx
->API
!= API_OPENGL_COMPAT
)
1288 goto invalid_enum_error
;
1289 return ctx
->Eval
.Map1Vertex4
;
1290 case GL_MAP2_COLOR_4
:
1291 if (ctx
->API
!= API_OPENGL_COMPAT
)
1292 goto invalid_enum_error
;
1293 return ctx
->Eval
.Map2Color4
;
1295 if (ctx
->API
!= API_OPENGL_COMPAT
)
1296 goto invalid_enum_error
;
1297 return ctx
->Eval
.Map2Index
;
1298 case GL_MAP2_NORMAL
:
1299 if (ctx
->API
!= API_OPENGL_COMPAT
)
1300 goto invalid_enum_error
;
1301 return ctx
->Eval
.Map2Normal
;
1302 case GL_MAP2_TEXTURE_COORD_1
:
1303 if (ctx
->API
!= API_OPENGL_COMPAT
)
1304 goto invalid_enum_error
;
1305 return ctx
->Eval
.Map2TextureCoord1
;
1306 case GL_MAP2_TEXTURE_COORD_2
:
1307 if (ctx
->API
!= API_OPENGL_COMPAT
)
1308 goto invalid_enum_error
;
1309 return ctx
->Eval
.Map2TextureCoord2
;
1310 case GL_MAP2_TEXTURE_COORD_3
:
1311 if (ctx
->API
!= API_OPENGL_COMPAT
)
1312 goto invalid_enum_error
;
1313 return ctx
->Eval
.Map2TextureCoord3
;
1314 case GL_MAP2_TEXTURE_COORD_4
:
1315 if (ctx
->API
!= API_OPENGL_COMPAT
)
1316 goto invalid_enum_error
;
1317 return ctx
->Eval
.Map2TextureCoord4
;
1318 case GL_MAP2_VERTEX_3
:
1319 if (ctx
->API
!= API_OPENGL_COMPAT
)
1320 goto invalid_enum_error
;
1321 return ctx
->Eval
.Map2Vertex3
;
1322 case GL_MAP2_VERTEX_4
:
1323 if (ctx
->API
!= API_OPENGL_COMPAT
)
1324 goto invalid_enum_error
;
1325 return ctx
->Eval
.Map2Vertex4
;
1327 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1328 goto invalid_enum_error
;
1329 return ctx
->Transform
.Normalize
;
1330 case GL_POINT_SMOOTH
:
1331 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1332 goto invalid_enum_error
;
1333 return ctx
->Point
.SmoothFlag
;
1334 case GL_POLYGON_SMOOTH
:
1335 if (!_mesa_is_desktop_gl(ctx
))
1336 goto invalid_enum_error
;
1337 return ctx
->Polygon
.SmoothFlag
;
1338 case GL_POLYGON_STIPPLE
:
1339 if (ctx
->API
!= API_OPENGL_COMPAT
)
1340 goto invalid_enum_error
;
1341 return ctx
->Polygon
.StippleFlag
;
1342 case GL_POLYGON_OFFSET_POINT
:
1343 if (!_mesa_is_desktop_gl(ctx
))
1344 goto invalid_enum_error
;
1345 return ctx
->Polygon
.OffsetPoint
;
1346 case GL_POLYGON_OFFSET_LINE
:
1347 if (!_mesa_is_desktop_gl(ctx
))
1348 goto invalid_enum_error
;
1349 return ctx
->Polygon
.OffsetLine
;
1350 case GL_POLYGON_OFFSET_FILL
:
1351 return ctx
->Polygon
.OffsetFill
;
1352 case GL_RESCALE_NORMAL_EXT
:
1353 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1354 goto invalid_enum_error
;
1355 return ctx
->Transform
.RescaleNormals
;
1356 case GL_SCISSOR_TEST
:
1357 return ctx
->Scissor
.Enabled
;
1358 case GL_STENCIL_TEST
:
1359 return ctx
->Stencil
.Enabled
;
1361 if (ctx
->API
!= API_OPENGL_COMPAT
)
1362 goto invalid_enum_error
;
1363 return is_texture_enabled(ctx
, TEXTURE_1D_BIT
);
1365 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1366 goto invalid_enum_error
;
1367 return is_texture_enabled(ctx
, TEXTURE_2D_BIT
);
1369 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1370 goto invalid_enum_error
;
1371 return is_texture_enabled(ctx
, TEXTURE_3D_BIT
);
1372 case GL_TEXTURE_GEN_S
:
1373 case GL_TEXTURE_GEN_T
:
1374 case GL_TEXTURE_GEN_R
:
1375 case GL_TEXTURE_GEN_Q
:
1377 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1379 if (ctx
->API
!= API_OPENGL_COMPAT
)
1380 goto invalid_enum_error
;
1383 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
1384 return (texUnit
->TexGenEnabled
& coordBit
) ? GL_TRUE
: GL_FALSE
;
1388 case GL_TEXTURE_GEN_STR_OES
:
1390 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1392 if (ctx
->API
!= API_OPENGLES
)
1393 goto invalid_enum_error
;
1396 return (texUnit
->TexGenEnabled
& STR_BITS
) == STR_BITS
1397 ? GL_TRUE
: GL_FALSE
;
1401 /* client-side state */
1402 case GL_VERTEX_ARRAY
:
1403 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1404 goto invalid_enum_error
;
1405 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
!= 0);
1406 case GL_NORMAL_ARRAY
:
1407 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1408 goto invalid_enum_error
;
1409 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
!= 0);
1410 case GL_COLOR_ARRAY
:
1411 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1412 goto invalid_enum_error
;
1413 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
!= 0);
1414 case GL_INDEX_ARRAY
:
1415 if (ctx
->API
!= API_OPENGL_COMPAT
)
1416 goto invalid_enum_error
;
1417 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
!= 0);
1418 case GL_TEXTURE_COORD_ARRAY
:
1419 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1420 goto invalid_enum_error
;
1421 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)]
1423 case GL_EDGE_FLAG_ARRAY
:
1424 if (ctx
->API
!= API_OPENGL_COMPAT
)
1425 goto invalid_enum_error
;
1426 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
!= 0);
1427 case GL_FOG_COORDINATE_ARRAY_EXT
:
1428 if (ctx
->API
!= API_OPENGL_COMPAT
)
1429 goto invalid_enum_error
;
1430 CHECK_EXTENSION(EXT_fog_coord
);
1431 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
!= 0);
1432 case GL_SECONDARY_COLOR_ARRAY_EXT
:
1433 if (ctx
->API
!= API_OPENGL_COMPAT
)
1434 goto invalid_enum_error
;
1435 CHECK_EXTENSION(EXT_secondary_color
);
1436 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
!= 0);
1437 case GL_POINT_SIZE_ARRAY_OES
:
1438 if (ctx
->API
!= API_OPENGLES
)
1439 goto invalid_enum_error
;
1440 return (ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
!= 0);
1442 /* GL_ARB_texture_cube_map */
1443 case GL_TEXTURE_CUBE_MAP_ARB
:
1444 CHECK_EXTENSION(ARB_texture_cube_map
);
1445 return is_texture_enabled(ctx
, TEXTURE_CUBE_BIT
);
1447 /* GL_EXT_secondary_color */
1448 case GL_COLOR_SUM_EXT
:
1449 if (ctx
->API
!= API_OPENGL_COMPAT
)
1450 goto invalid_enum_error
;
1451 CHECK_EXTENSION2(EXT_secondary_color
, ARB_vertex_program
);
1452 return ctx
->Fog
.ColorSumEnabled
;
1454 /* GL_ARB_multisample */
1455 case GL_MULTISAMPLE_ARB
:
1456 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1457 goto invalid_enum_error
;
1458 return ctx
->Multisample
.Enabled
;
1459 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
1460 return ctx
->Multisample
.SampleAlphaToCoverage
;
1461 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
1462 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1463 goto invalid_enum_error
;
1464 return ctx
->Multisample
.SampleAlphaToOne
;
1465 case GL_SAMPLE_COVERAGE_ARB
:
1466 return ctx
->Multisample
.SampleCoverage
;
1467 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
1468 if (!_mesa_is_desktop_gl(ctx
))
1469 goto invalid_enum_error
;
1470 return ctx
->Multisample
.SampleCoverageInvert
;
1472 /* GL_IBM_rasterpos_clip */
1473 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
1474 if (ctx
->API
!= API_OPENGL_COMPAT
)
1475 goto invalid_enum_error
;
1476 return ctx
->Transform
.RasterPositionUnclipped
;
1478 /* GL_NV_point_sprite */
1479 case GL_POINT_SPRITE_NV
:
1480 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1481 goto invalid_enum_error
;
1482 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
)
1483 return ctx
->Point
.PointSprite
;
1485 case GL_VERTEX_PROGRAM_ARB
:
1486 if (ctx
->API
!= API_OPENGL_COMPAT
)
1487 goto invalid_enum_error
;
1488 CHECK_EXTENSION(ARB_vertex_program
);
1489 return ctx
->VertexProgram
.Enabled
;
1490 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
1491 /* This was added with ARB_vertex_program, but it is also used with
1492 * GLSL vertex shaders on desktop.
1494 if (!_mesa_is_desktop_gl(ctx
))
1495 goto invalid_enum_error
;
1496 CHECK_EXTENSION(ARB_vertex_program
);
1497 return ctx
->VertexProgram
.PointSizeEnabled
;
1498 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
1499 if (ctx
->API
!= API_OPENGL_COMPAT
)
1500 goto invalid_enum_error
;
1501 CHECK_EXTENSION(ARB_vertex_program
);
1502 return ctx
->VertexProgram
.TwoSideEnabled
;
1504 /* GL_NV_texture_rectangle */
1505 case GL_TEXTURE_RECTANGLE_NV
:
1506 if (ctx
->API
!= API_OPENGL_COMPAT
)
1507 goto invalid_enum_error
;
1508 CHECK_EXTENSION(NV_texture_rectangle
);
1509 return is_texture_enabled(ctx
, TEXTURE_RECT_BIT
);
1511 /* GL_EXT_stencil_two_side */
1512 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
1513 if (ctx
->API
!= API_OPENGL_COMPAT
)
1514 goto invalid_enum_error
;
1515 CHECK_EXTENSION(EXT_stencil_two_side
);
1516 return ctx
->Stencil
.TestTwoSide
;
1518 case GL_FRAGMENT_PROGRAM_ARB
:
1519 if (ctx
->API
!= API_OPENGL_COMPAT
)
1520 goto invalid_enum_error
;
1521 return ctx
->FragmentProgram
.Enabled
;
1523 /* GL_EXT_depth_bounds_test */
1524 case GL_DEPTH_BOUNDS_TEST_EXT
:
1525 if (!_mesa_is_desktop_gl(ctx
))
1526 goto invalid_enum_error
;
1527 CHECK_EXTENSION(EXT_depth_bounds_test
);
1528 return ctx
->Depth
.BoundsTest
;
1530 /* GL_ARB_depth_clamp */
1531 case GL_DEPTH_CLAMP
:
1532 if (!_mesa_is_desktop_gl(ctx
))
1533 goto invalid_enum_error
;
1534 CHECK_EXTENSION(ARB_depth_clamp
);
1535 return ctx
->Transform
.DepthClamp
;
1537 case GL_FRAGMENT_SHADER_ATI
:
1538 if (ctx
->API
!= API_OPENGL_COMPAT
)
1539 goto invalid_enum_error
;
1540 CHECK_EXTENSION(ATI_fragment_shader
);
1541 return ctx
->ATIFragmentShader
.Enabled
;
1543 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1544 if (!_mesa_is_desktop_gl(ctx
))
1545 goto invalid_enum_error
;
1546 CHECK_EXTENSION(ARB_seamless_cube_map
);
1547 return ctx
->Texture
.CubeMapSeamless
;
1549 case GL_RASTERIZER_DISCARD
:
1550 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1551 goto invalid_enum_error
;
1552 CHECK_EXTENSION(EXT_transform_feedback
);
1553 return ctx
->RasterDiscard
;
1555 /* GL_NV_primitive_restart */
1556 case GL_PRIMITIVE_RESTART_NV
:
1557 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.NV_primitive_restart
) {
1558 goto invalid_enum_error
;
1560 return ctx
->Array
.PrimitiveRestart
;
1562 /* GL 3.1 primitive restart */
1563 case GL_PRIMITIVE_RESTART
:
1564 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
1565 goto invalid_enum_error
;
1567 return ctx
->Array
.PrimitiveRestart
;
1569 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
1570 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
) {
1571 goto invalid_enum_error
;
1573 return ctx
->Array
.PrimitiveRestartFixedIndex
;
1575 /* GL3.0 - GL_framebuffer_sRGB */
1576 case GL_FRAMEBUFFER_SRGB_EXT
:
1577 if (!_mesa_is_desktop_gl(ctx
))
1578 goto invalid_enum_error
;
1579 CHECK_EXTENSION(EXT_framebuffer_sRGB
);
1580 return ctx
->Color
.sRGBEnabled
;
1582 /* GL_OES_EGL_image_external */
1583 case GL_TEXTURE_EXTERNAL_OES
:
1584 if (!_mesa_is_gles(ctx
))
1585 goto invalid_enum_error
;
1586 CHECK_EXTENSION(OES_EGL_image_external
);
1587 return is_texture_enabled(ctx
, TEXTURE_EXTERNAL_BIT
);
1589 /* ARB_texture_multisample */
1590 case GL_SAMPLE_MASK
:
1591 if (!_mesa_is_desktop_gl(ctx
))
1592 goto invalid_enum_error
;
1593 CHECK_EXTENSION(ARB_texture_multisample
);
1594 return ctx
->Multisample
.SampleMask
;
1597 goto invalid_enum_error
;
1603 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabled(%s)",
1604 _mesa_lookup_enum_by_nr(cap
));