3 * Enable/disable/query GL capabilities.
7 * Mesa 3-D graphics library
9 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
36 #include "simple_list.h"
39 #include "api_arrayelt.h"
41 #include "drivers/common/meta.h"
45 #define CHECK_EXTENSION(EXTNAME, CAP) \
46 if (!ctx->Extensions.EXTNAME) { \
47 goto invalid_enum_error; \
52 update_derived_primitive_restart_state(struct gl_context
*ctx
)
54 /* Update derived primitive restart state.
56 ctx
->Array
._PrimitiveRestart
= ctx
->Array
.PrimitiveRestart
57 || ctx
->Array
.PrimitiveRestartFixedIndex
;
61 * Helper to enable/disable client-side state.
64 client_state(struct gl_context
*ctx
, GLenum cap
, GLboolean state
)
66 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
72 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
;
76 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
;
77 flag
= VERT_BIT_NORMAL
;
80 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
;
81 flag
= VERT_BIT_COLOR0
;
84 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
;
85 flag
= VERT_BIT_COLOR_INDEX
;
87 case GL_TEXTURE_COORD_ARRAY
:
88 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Enabled
;
89 flag
= VERT_BIT_TEX(ctx
->Array
.ActiveTexture
);
91 case GL_EDGE_FLAG_ARRAY
:
92 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
;
93 flag
= VERT_BIT_EDGEFLAG
;
95 case GL_FOG_COORDINATE_ARRAY_EXT
:
96 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
;
99 case GL_SECONDARY_COLOR_ARRAY_EXT
:
100 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
;
101 flag
= VERT_BIT_COLOR1
;
104 case GL_POINT_SIZE_ARRAY_OES
:
105 var
= &arrayObj
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
;
106 flag
= VERT_BIT_POINT_SIZE
;
109 /* GL_NV_primitive_restart */
110 case GL_PRIMITIVE_RESTART_NV
:
111 if (!ctx
->Extensions
.NV_primitive_restart
) {
112 goto invalid_enum_error
;
114 var
= &ctx
->Array
.PrimitiveRestart
;
119 goto invalid_enum_error
;
125 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
127 _ae_invalidate_state(ctx
, _NEW_ARRAY
);
131 update_derived_primitive_restart_state(ctx
);
134 arrayObj
->_Enabled
|= flag
;
136 arrayObj
->_Enabled
&= ~flag
;
138 arrayObj
->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
:
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 if (ctx
->Fog
.ColorSumEnabled
== state
)
767 FLUSH_VERTICES(ctx
, _NEW_FOG
);
768 ctx
->Fog
.ColorSumEnabled
= state
;
771 /* GL_ARB_multisample */
772 case GL_MULTISAMPLE_ARB
:
773 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
774 goto invalid_enum_error
;
775 _mesa_set_multisample(ctx
, state
);
777 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
778 if (ctx
->Multisample
.SampleAlphaToCoverage
== state
)
780 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
781 ctx
->Multisample
.SampleAlphaToCoverage
= state
;
783 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
784 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
785 goto invalid_enum_error
;
786 if (ctx
->Multisample
.SampleAlphaToOne
== state
)
788 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
789 ctx
->Multisample
.SampleAlphaToOne
= state
;
791 case GL_SAMPLE_COVERAGE_ARB
:
792 if (ctx
->Multisample
.SampleCoverage
== state
)
794 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
795 ctx
->Multisample
.SampleCoverage
= state
;
797 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
798 if (!_mesa_is_desktop_gl(ctx
))
799 goto invalid_enum_error
;
800 if (ctx
->Multisample
.SampleCoverageInvert
== state
)
802 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
803 ctx
->Multisample
.SampleCoverageInvert
= state
;
806 /* GL_ARB_sample_shading */
807 case GL_SAMPLE_SHADING
:
808 if (!_mesa_is_desktop_gl(ctx
))
809 goto invalid_enum_error
;
810 CHECK_EXTENSION(ARB_sample_shading
, cap
);
811 if (ctx
->Multisample
.SampleShading
== state
)
813 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
814 ctx
->Multisample
.SampleShading
= state
;
817 /* GL_IBM_rasterpos_clip */
818 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
819 if (ctx
->API
!= API_OPENGL_COMPAT
)
820 goto invalid_enum_error
;
821 if (ctx
->Transform
.RasterPositionUnclipped
== state
)
823 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
824 ctx
->Transform
.RasterPositionUnclipped
= state
;
827 /* GL_NV_point_sprite */
828 case GL_POINT_SPRITE_NV
:
829 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
830 goto invalid_enum_error
;
831 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
, cap
);
832 if (ctx
->Point
.PointSprite
== state
)
834 FLUSH_VERTICES(ctx
, _NEW_POINT
);
835 ctx
->Point
.PointSprite
= state
;
838 case GL_VERTEX_PROGRAM_ARB
:
839 if (ctx
->API
!= API_OPENGL_COMPAT
)
840 goto invalid_enum_error
;
841 CHECK_EXTENSION(ARB_vertex_program
, cap
);
842 if (ctx
->VertexProgram
.Enabled
== state
)
844 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
845 ctx
->VertexProgram
.Enabled
= state
;
847 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
848 /* This was added with ARB_vertex_program, but it is also used with
849 * GLSL vertex shaders on desktop.
851 if (!_mesa_is_desktop_gl(ctx
))
852 goto invalid_enum_error
;
853 CHECK_EXTENSION(ARB_vertex_program
, cap
);
854 if (ctx
->VertexProgram
.PointSizeEnabled
== state
)
856 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
857 ctx
->VertexProgram
.PointSizeEnabled
= state
;
859 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
860 if (ctx
->API
!= API_OPENGL_COMPAT
)
861 goto invalid_enum_error
;
862 CHECK_EXTENSION(ARB_vertex_program
, cap
);
863 if (ctx
->VertexProgram
.TwoSideEnabled
== state
)
865 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
866 ctx
->VertexProgram
.TwoSideEnabled
= state
;
869 /* GL_NV_texture_rectangle */
870 case GL_TEXTURE_RECTANGLE_NV
:
871 if (ctx
->API
!= API_OPENGL_COMPAT
)
872 goto invalid_enum_error
;
873 CHECK_EXTENSION(NV_texture_rectangle
, cap
);
874 if (!enable_texture(ctx
, state
, TEXTURE_RECT_BIT
)) {
879 /* GL_EXT_stencil_two_side */
880 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
881 if (ctx
->API
!= API_OPENGL_COMPAT
)
882 goto invalid_enum_error
;
883 CHECK_EXTENSION(EXT_stencil_two_side
, cap
);
884 if (ctx
->Stencil
.TestTwoSide
== state
)
886 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
887 ctx
->Stencil
.TestTwoSide
= state
;
889 ctx
->Stencil
._BackFace
= 2;
891 ctx
->Stencil
._BackFace
= 1;
895 case GL_FRAGMENT_PROGRAM_ARB
:
896 if (ctx
->API
!= API_OPENGL_COMPAT
)
897 goto invalid_enum_error
;
898 CHECK_EXTENSION(ARB_fragment_program
, cap
);
899 if (ctx
->FragmentProgram
.Enabled
== state
)
901 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
902 ctx
->FragmentProgram
.Enabled
= state
;
905 /* GL_EXT_depth_bounds_test */
906 case GL_DEPTH_BOUNDS_TEST_EXT
:
907 if (!_mesa_is_desktop_gl(ctx
))
908 goto invalid_enum_error
;
909 CHECK_EXTENSION(EXT_depth_bounds_test
, cap
);
910 if (ctx
->Depth
.BoundsTest
== state
)
912 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
913 ctx
->Depth
.BoundsTest
= state
;
917 if (!_mesa_is_desktop_gl(ctx
))
918 goto invalid_enum_error
;
919 CHECK_EXTENSION(ARB_depth_clamp
, cap
);
920 if (ctx
->Transform
.DepthClamp
== state
)
922 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
923 ctx
->Transform
.DepthClamp
= state
;
926 case GL_FRAGMENT_SHADER_ATI
:
927 if (ctx
->API
!= API_OPENGL_COMPAT
)
928 goto invalid_enum_error
;
929 CHECK_EXTENSION(ATI_fragment_shader
, cap
);
930 if (ctx
->ATIFragmentShader
.Enabled
== state
)
932 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
933 ctx
->ATIFragmentShader
.Enabled
= state
;
936 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
937 if (!_mesa_is_desktop_gl(ctx
))
938 goto invalid_enum_error
;
939 CHECK_EXTENSION(ARB_seamless_cube_map
, cap
);
940 if (ctx
->Texture
.CubeMapSeamless
!= state
) {
941 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
942 ctx
->Texture
.CubeMapSeamless
= state
;
946 case GL_RASTERIZER_DISCARD
:
947 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
948 goto invalid_enum_error
;
949 CHECK_EXTENSION(EXT_transform_feedback
, cap
);
950 if (ctx
->RasterDiscard
!= state
) {
951 FLUSH_VERTICES(ctx
, 0);
952 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewRasterizerDiscard
;
953 ctx
->RasterDiscard
= state
;
957 /* GL 3.1 primitive restart. Note: this enum is different from
958 * GL_PRIMITIVE_RESTART_NV (which is client state).
960 case GL_PRIMITIVE_RESTART
:
961 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
962 goto invalid_enum_error
;
964 if (ctx
->Array
.PrimitiveRestart
!= state
) {
965 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
966 ctx
->Array
.PrimitiveRestart
= state
;
967 update_derived_primitive_restart_state(ctx
);
971 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
972 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
)
973 goto invalid_enum_error
;
974 if (ctx
->Array
.PrimitiveRestartFixedIndex
!= state
) {
975 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
976 ctx
->Array
.PrimitiveRestartFixedIndex
= state
;
977 update_derived_primitive_restart_state(ctx
);
981 /* GL3.0 - GL_framebuffer_sRGB */
982 case GL_FRAMEBUFFER_SRGB_EXT
:
983 if (!_mesa_is_desktop_gl(ctx
))
984 goto invalid_enum_error
;
985 CHECK_EXTENSION(EXT_framebuffer_sRGB
, cap
);
986 _mesa_set_framebuffer_srgb(ctx
, state
);
989 /* GL_OES_EGL_image_external */
990 case GL_TEXTURE_EXTERNAL_OES
:
991 if (!_mesa_is_gles(ctx
))
992 goto invalid_enum_error
;
993 CHECK_EXTENSION(OES_EGL_image_external
, cap
);
994 if (!enable_texture(ctx
, state
, TEXTURE_EXTERNAL_BIT
)) {
999 /* ARB_texture_multisample */
1000 case GL_SAMPLE_MASK
:
1001 if (!_mesa_is_desktop_gl(ctx
))
1002 goto invalid_enum_error
;
1003 CHECK_EXTENSION(ARB_texture_multisample
, cap
);
1004 if (ctx
->Multisample
.SampleMask
== state
)
1006 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
1007 ctx
->Multisample
.SampleMask
= state
;
1011 goto invalid_enum_error
;
1014 if (ctx
->Driver
.Enable
) {
1015 ctx
->Driver
.Enable( ctx
, cap
, state
);
1021 _mesa_error(ctx
, GL_INVALID_ENUM
, "gl%s(%s)",
1022 state
? "Enable" : "Disable", _mesa_lookup_enum_by_nr(cap
));
1027 * Enable GL capability. Called by glEnable()
1028 * \param cap state to enable.
1031 _mesa_Enable( GLenum cap
)
1033 GET_CURRENT_CONTEXT(ctx
);
1035 _mesa_set_enable( ctx
, cap
, GL_TRUE
);
1040 * Disable GL capability. Called by glDisable()
1041 * \param cap state to disable.
1044 _mesa_Disable( GLenum cap
)
1046 GET_CURRENT_CONTEXT(ctx
);
1048 _mesa_set_enable( ctx
, cap
, GL_FALSE
);
1054 * Enable/disable an indexed state var.
1057 _mesa_set_enablei(struct gl_context
*ctx
, GLenum cap
,
1058 GLuint index
, GLboolean state
)
1060 ASSERT(state
== 0 || state
== 1);
1063 if (!ctx
->Extensions
.EXT_draw_buffers2
) {
1064 goto invalid_enum_error
;
1066 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1067 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)",
1068 state
? "glEnableIndexed" : "glDisableIndexed", index
);
1071 if (((ctx
->Color
.BlendEnabled
>> index
) & 1) != state
) {
1072 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
1074 ctx
->Color
.BlendEnabled
|= (1 << index
);
1076 ctx
->Color
.BlendEnabled
&= ~(1 << index
);
1080 goto invalid_enum_error
;
1085 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(cap=%s)",
1086 state
? "glEnablei" : "glDisablei",
1087 _mesa_lookup_enum_by_nr(cap
));
1092 _mesa_Disablei( GLenum cap
, GLuint index
)
1094 GET_CURRENT_CONTEXT(ctx
);
1095 _mesa_set_enablei(ctx
, cap
, index
, GL_FALSE
);
1100 _mesa_Enablei( GLenum cap
, GLuint index
)
1102 GET_CURRENT_CONTEXT(ctx
);
1103 _mesa_set_enablei(ctx
, cap
, index
, GL_TRUE
);
1107 GLboolean GLAPIENTRY
1108 _mesa_IsEnabledi( GLenum cap
, GLuint index
)
1110 GET_CURRENT_CONTEXT(ctx
);
1111 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1114 if (index
>= ctx
->Const
.MaxDrawBuffers
) {
1115 _mesa_error(ctx
, GL_INVALID_VALUE
, "glIsEnabledIndexed(index=%u)",
1119 return (ctx
->Color
.BlendEnabled
>> index
) & 1;
1121 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabledIndexed(cap=%s)",
1122 _mesa_lookup_enum_by_nr(cap
));
1130 #undef CHECK_EXTENSION
1131 #define CHECK_EXTENSION(EXTNAME) \
1132 if (!ctx->Extensions.EXTNAME) { \
1133 goto invalid_enum_error; \
1136 #undef CHECK_EXTENSION2
1137 #define CHECK_EXTENSION2(EXT1, EXT2) \
1138 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1139 goto invalid_enum_error; \
1144 * Helper function to determine whether a texture target is enabled.
1147 is_texture_enabled(struct gl_context
*ctx
, GLbitfield bit
)
1149 const struct gl_texture_unit
*const texUnit
=
1150 &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1151 return (texUnit
->Enabled
& bit
) ? GL_TRUE
: GL_FALSE
;
1156 * Return simple enable/disable state.
1158 * \param cap state variable to query.
1160 * Returns the state of the specified capability from the current GL context.
1161 * For the capabilities associated with extensions verifies that those
1162 * extensions are effectively present before reporting.
1164 GLboolean GLAPIENTRY
1165 _mesa_IsEnabled( GLenum cap
)
1167 GET_CURRENT_CONTEXT(ctx
);
1168 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, 0);
1172 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1173 goto invalid_enum_error
;
1174 return ctx
->Color
.AlphaEnabled
;
1175 case GL_AUTO_NORMAL
:
1176 if (ctx
->API
!= API_OPENGL_COMPAT
)
1177 goto invalid_enum_error
;
1178 return ctx
->Eval
.AutoNormal
;
1180 return ctx
->Color
.BlendEnabled
& 1; /* return state for buffer[0] */
1181 case GL_CLIP_DISTANCE0
:
1182 case GL_CLIP_DISTANCE1
:
1183 case GL_CLIP_DISTANCE2
:
1184 case GL_CLIP_DISTANCE3
:
1185 case GL_CLIP_DISTANCE4
:
1186 case GL_CLIP_DISTANCE5
:
1187 case GL_CLIP_DISTANCE6
:
1188 case GL_CLIP_DISTANCE7
: {
1189 const GLuint p
= cap
- GL_CLIP_DISTANCE0
;
1191 if (p
>= ctx
->Const
.MaxClipPlanes
)
1192 goto invalid_enum_error
;
1194 return (ctx
->Transform
.ClipPlanesEnabled
>> p
) & 1;
1196 case GL_COLOR_MATERIAL
:
1197 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1198 goto invalid_enum_error
;
1199 return ctx
->Light
.ColorMaterialEnabled
;
1201 return ctx
->Polygon
.CullFlag
;
1202 case GL_DEBUG_OUTPUT
:
1203 if (!_mesa_is_desktop_gl(ctx
))
1204 goto invalid_enum_error
;
1205 return ctx
->Debug
.DebugOutput
;
1206 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
:
1207 if (!_mesa_is_desktop_gl(ctx
))
1208 goto invalid_enum_error
;
1209 return ctx
->Debug
.SyncOutput
;
1211 return ctx
->Depth
.Test
;
1213 return ctx
->Color
.DitherFlag
;
1215 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1216 goto invalid_enum_error
;
1217 return ctx
->Fog
.Enabled
;
1219 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1220 goto invalid_enum_error
;
1221 return ctx
->Light
.Enabled
;
1230 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1231 goto invalid_enum_error
;
1232 return ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
;
1233 case GL_LINE_SMOOTH
:
1234 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1235 goto invalid_enum_error
;
1236 return ctx
->Line
.SmoothFlag
;
1237 case GL_LINE_STIPPLE
:
1238 if (ctx
->API
!= API_OPENGL_COMPAT
)
1239 goto invalid_enum_error
;
1240 return ctx
->Line
.StippleFlag
;
1241 case GL_INDEX_LOGIC_OP
:
1242 if (ctx
->API
!= API_OPENGL_COMPAT
)
1243 goto invalid_enum_error
;
1244 return ctx
->Color
.IndexLogicOpEnabled
;
1245 case GL_COLOR_LOGIC_OP
:
1246 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1247 goto invalid_enum_error
;
1248 return ctx
->Color
.ColorLogicOpEnabled
;
1249 case GL_MAP1_COLOR_4
:
1250 if (ctx
->API
!= API_OPENGL_COMPAT
)
1251 goto invalid_enum_error
;
1252 return ctx
->Eval
.Map1Color4
;
1254 if (ctx
->API
!= API_OPENGL_COMPAT
)
1255 goto invalid_enum_error
;
1256 return ctx
->Eval
.Map1Index
;
1257 case GL_MAP1_NORMAL
:
1258 if (ctx
->API
!= API_OPENGL_COMPAT
)
1259 goto invalid_enum_error
;
1260 return ctx
->Eval
.Map1Normal
;
1261 case GL_MAP1_TEXTURE_COORD_1
:
1262 if (ctx
->API
!= API_OPENGL_COMPAT
)
1263 goto invalid_enum_error
;
1264 return ctx
->Eval
.Map1TextureCoord1
;
1265 case GL_MAP1_TEXTURE_COORD_2
:
1266 if (ctx
->API
!= API_OPENGL_COMPAT
)
1267 goto invalid_enum_error
;
1268 return ctx
->Eval
.Map1TextureCoord2
;
1269 case GL_MAP1_TEXTURE_COORD_3
:
1270 if (ctx
->API
!= API_OPENGL_COMPAT
)
1271 goto invalid_enum_error
;
1272 return ctx
->Eval
.Map1TextureCoord3
;
1273 case GL_MAP1_TEXTURE_COORD_4
:
1274 if (ctx
->API
!= API_OPENGL_COMPAT
)
1275 goto invalid_enum_error
;
1276 return ctx
->Eval
.Map1TextureCoord4
;
1277 case GL_MAP1_VERTEX_3
:
1278 if (ctx
->API
!= API_OPENGL_COMPAT
)
1279 goto invalid_enum_error
;
1280 return ctx
->Eval
.Map1Vertex3
;
1281 case GL_MAP1_VERTEX_4
:
1282 if (ctx
->API
!= API_OPENGL_COMPAT
)
1283 goto invalid_enum_error
;
1284 return ctx
->Eval
.Map1Vertex4
;
1285 case GL_MAP2_COLOR_4
:
1286 if (ctx
->API
!= API_OPENGL_COMPAT
)
1287 goto invalid_enum_error
;
1288 return ctx
->Eval
.Map2Color4
;
1290 if (ctx
->API
!= API_OPENGL_COMPAT
)
1291 goto invalid_enum_error
;
1292 return ctx
->Eval
.Map2Index
;
1293 case GL_MAP2_NORMAL
:
1294 if (ctx
->API
!= API_OPENGL_COMPAT
)
1295 goto invalid_enum_error
;
1296 return ctx
->Eval
.Map2Normal
;
1297 case GL_MAP2_TEXTURE_COORD_1
:
1298 if (ctx
->API
!= API_OPENGL_COMPAT
)
1299 goto invalid_enum_error
;
1300 return ctx
->Eval
.Map2TextureCoord1
;
1301 case GL_MAP2_TEXTURE_COORD_2
:
1302 if (ctx
->API
!= API_OPENGL_COMPAT
)
1303 goto invalid_enum_error
;
1304 return ctx
->Eval
.Map2TextureCoord2
;
1305 case GL_MAP2_TEXTURE_COORD_3
:
1306 if (ctx
->API
!= API_OPENGL_COMPAT
)
1307 goto invalid_enum_error
;
1308 return ctx
->Eval
.Map2TextureCoord3
;
1309 case GL_MAP2_TEXTURE_COORD_4
:
1310 if (ctx
->API
!= API_OPENGL_COMPAT
)
1311 goto invalid_enum_error
;
1312 return ctx
->Eval
.Map2TextureCoord4
;
1313 case GL_MAP2_VERTEX_3
:
1314 if (ctx
->API
!= API_OPENGL_COMPAT
)
1315 goto invalid_enum_error
;
1316 return ctx
->Eval
.Map2Vertex3
;
1317 case GL_MAP2_VERTEX_4
:
1318 if (ctx
->API
!= API_OPENGL_COMPAT
)
1319 goto invalid_enum_error
;
1320 return ctx
->Eval
.Map2Vertex4
;
1322 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1323 goto invalid_enum_error
;
1324 return ctx
->Transform
.Normalize
;
1325 case GL_POINT_SMOOTH
:
1326 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1327 goto invalid_enum_error
;
1328 return ctx
->Point
.SmoothFlag
;
1329 case GL_POLYGON_SMOOTH
:
1330 if (!_mesa_is_desktop_gl(ctx
))
1331 goto invalid_enum_error
;
1332 return ctx
->Polygon
.SmoothFlag
;
1333 case GL_POLYGON_STIPPLE
:
1334 if (ctx
->API
!= API_OPENGL_COMPAT
)
1335 goto invalid_enum_error
;
1336 return ctx
->Polygon
.StippleFlag
;
1337 case GL_POLYGON_OFFSET_POINT
:
1338 if (!_mesa_is_desktop_gl(ctx
))
1339 goto invalid_enum_error
;
1340 return ctx
->Polygon
.OffsetPoint
;
1341 case GL_POLYGON_OFFSET_LINE
:
1342 if (!_mesa_is_desktop_gl(ctx
))
1343 goto invalid_enum_error
;
1344 return ctx
->Polygon
.OffsetLine
;
1345 case GL_POLYGON_OFFSET_FILL
:
1346 return ctx
->Polygon
.OffsetFill
;
1347 case GL_RESCALE_NORMAL_EXT
:
1348 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1349 goto invalid_enum_error
;
1350 return ctx
->Transform
.RescaleNormals
;
1351 case GL_SCISSOR_TEST
:
1352 return ctx
->Scissor
.Enabled
;
1353 case GL_STENCIL_TEST
:
1354 return ctx
->Stencil
.Enabled
;
1356 if (ctx
->API
!= API_OPENGL_COMPAT
)
1357 goto invalid_enum_error
;
1358 return is_texture_enabled(ctx
, TEXTURE_1D_BIT
);
1360 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1361 goto invalid_enum_error
;
1362 return is_texture_enabled(ctx
, TEXTURE_2D_BIT
);
1364 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1365 goto invalid_enum_error
;
1366 return is_texture_enabled(ctx
, TEXTURE_3D_BIT
);
1367 case GL_TEXTURE_GEN_S
:
1368 case GL_TEXTURE_GEN_T
:
1369 case GL_TEXTURE_GEN_R
:
1370 case GL_TEXTURE_GEN_Q
:
1372 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1374 if (ctx
->API
!= API_OPENGL_COMPAT
)
1375 goto invalid_enum_error
;
1378 GLbitfield coordBit
= S_BIT
<< (cap
- GL_TEXTURE_GEN_S
);
1379 return (texUnit
->TexGenEnabled
& coordBit
) ? GL_TRUE
: GL_FALSE
;
1383 case GL_TEXTURE_GEN_STR_OES
:
1385 const struct gl_texture_unit
*texUnit
= get_texcoord_unit(ctx
);
1387 if (ctx
->API
!= API_OPENGLES
)
1388 goto invalid_enum_error
;
1391 return (texUnit
->TexGenEnabled
& STR_BITS
) == STR_BITS
1392 ? GL_TRUE
: GL_FALSE
;
1396 /* client-side state */
1397 case GL_VERTEX_ARRAY
:
1398 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1399 goto invalid_enum_error
;
1400 return ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
;
1401 case GL_NORMAL_ARRAY
:
1402 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1403 goto invalid_enum_error
;
1404 return ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
;
1405 case GL_COLOR_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_COLOR0
].Enabled
;
1409 case GL_INDEX_ARRAY
:
1410 if (ctx
->API
!= API_OPENGL_COMPAT
)
1411 goto invalid_enum_error
;
1412 return ctx
->Array
.ArrayObj
->
1413 VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
;
1414 case GL_TEXTURE_COORD_ARRAY
:
1415 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1416 goto invalid_enum_error
;
1417 return ctx
->Array
.ArrayObj
->
1418 VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Enabled
;
1419 case GL_EDGE_FLAG_ARRAY
:
1420 if (ctx
->API
!= API_OPENGL_COMPAT
)
1421 goto invalid_enum_error
;
1422 return ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
;
1423 case GL_FOG_COORDINATE_ARRAY_EXT
:
1424 if (ctx
->API
!= API_OPENGL_COMPAT
)
1425 goto invalid_enum_error
;
1426 return ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
;
1427 case GL_SECONDARY_COLOR_ARRAY_EXT
:
1428 if (ctx
->API
!= API_OPENGL_COMPAT
)
1429 goto invalid_enum_error
;
1430 return ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
;
1431 case GL_POINT_SIZE_ARRAY_OES
:
1432 if (ctx
->API
!= API_OPENGLES
)
1433 goto invalid_enum_error
;
1434 return ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_POINT_SIZE
].Enabled
;
1436 /* GL_ARB_texture_cube_map */
1437 case GL_TEXTURE_CUBE_MAP_ARB
:
1438 CHECK_EXTENSION(ARB_texture_cube_map
);
1439 return is_texture_enabled(ctx
, TEXTURE_CUBE_BIT
);
1441 /* GL_EXT_secondary_color */
1442 case GL_COLOR_SUM_EXT
:
1443 if (ctx
->API
!= API_OPENGL_COMPAT
)
1444 goto invalid_enum_error
;
1445 return ctx
->Fog
.ColorSumEnabled
;
1447 /* GL_ARB_multisample */
1448 case GL_MULTISAMPLE_ARB
:
1449 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1450 goto invalid_enum_error
;
1451 return ctx
->Multisample
.Enabled
;
1452 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
:
1453 return ctx
->Multisample
.SampleAlphaToCoverage
;
1454 case GL_SAMPLE_ALPHA_TO_ONE_ARB
:
1455 if (!_mesa_is_desktop_gl(ctx
) && ctx
->API
!= API_OPENGLES
)
1456 goto invalid_enum_error
;
1457 return ctx
->Multisample
.SampleAlphaToOne
;
1458 case GL_SAMPLE_COVERAGE_ARB
:
1459 return ctx
->Multisample
.SampleCoverage
;
1460 case GL_SAMPLE_COVERAGE_INVERT_ARB
:
1461 if (!_mesa_is_desktop_gl(ctx
))
1462 goto invalid_enum_error
;
1463 return ctx
->Multisample
.SampleCoverageInvert
;
1465 /* GL_IBM_rasterpos_clip */
1466 case GL_RASTER_POSITION_UNCLIPPED_IBM
:
1467 if (ctx
->API
!= API_OPENGL_COMPAT
)
1468 goto invalid_enum_error
;
1469 return ctx
->Transform
.RasterPositionUnclipped
;
1471 /* GL_NV_point_sprite */
1472 case GL_POINT_SPRITE_NV
:
1473 if (ctx
->API
!= API_OPENGL_COMPAT
&& ctx
->API
!= API_OPENGLES
)
1474 goto invalid_enum_error
;
1475 CHECK_EXTENSION2(NV_point_sprite
, ARB_point_sprite
)
1476 return ctx
->Point
.PointSprite
;
1478 case GL_VERTEX_PROGRAM_ARB
:
1479 if (ctx
->API
!= API_OPENGL_COMPAT
)
1480 goto invalid_enum_error
;
1481 CHECK_EXTENSION(ARB_vertex_program
);
1482 return ctx
->VertexProgram
.Enabled
;
1483 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB
:
1484 /* This was added with ARB_vertex_program, but it is also used with
1485 * GLSL vertex shaders on desktop.
1487 if (!_mesa_is_desktop_gl(ctx
))
1488 goto invalid_enum_error
;
1489 CHECK_EXTENSION(ARB_vertex_program
);
1490 return ctx
->VertexProgram
.PointSizeEnabled
;
1491 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB
:
1492 if (ctx
->API
!= API_OPENGL_COMPAT
)
1493 goto invalid_enum_error
;
1494 CHECK_EXTENSION(ARB_vertex_program
);
1495 return ctx
->VertexProgram
.TwoSideEnabled
;
1497 /* GL_NV_texture_rectangle */
1498 case GL_TEXTURE_RECTANGLE_NV
:
1499 if (ctx
->API
!= API_OPENGL_COMPAT
)
1500 goto invalid_enum_error
;
1501 CHECK_EXTENSION(NV_texture_rectangle
);
1502 return is_texture_enabled(ctx
, TEXTURE_RECT_BIT
);
1504 /* GL_EXT_stencil_two_side */
1505 case GL_STENCIL_TEST_TWO_SIDE_EXT
:
1506 if (ctx
->API
!= API_OPENGL_COMPAT
)
1507 goto invalid_enum_error
;
1508 CHECK_EXTENSION(EXT_stencil_two_side
);
1509 return ctx
->Stencil
.TestTwoSide
;
1511 case GL_FRAGMENT_PROGRAM_ARB
:
1512 if (ctx
->API
!= API_OPENGL_COMPAT
)
1513 goto invalid_enum_error
;
1514 return ctx
->FragmentProgram
.Enabled
;
1516 /* GL_EXT_depth_bounds_test */
1517 case GL_DEPTH_BOUNDS_TEST_EXT
:
1518 if (!_mesa_is_desktop_gl(ctx
))
1519 goto invalid_enum_error
;
1520 CHECK_EXTENSION(EXT_depth_bounds_test
);
1521 return ctx
->Depth
.BoundsTest
;
1523 /* GL_ARB_depth_clamp */
1524 case GL_DEPTH_CLAMP
:
1525 if (!_mesa_is_desktop_gl(ctx
))
1526 goto invalid_enum_error
;
1527 CHECK_EXTENSION(ARB_depth_clamp
);
1528 return ctx
->Transform
.DepthClamp
;
1530 case GL_FRAGMENT_SHADER_ATI
:
1531 if (ctx
->API
!= API_OPENGL_COMPAT
)
1532 goto invalid_enum_error
;
1533 CHECK_EXTENSION(ATI_fragment_shader
);
1534 return ctx
->ATIFragmentShader
.Enabled
;
1536 case GL_TEXTURE_CUBE_MAP_SEAMLESS
:
1537 if (!_mesa_is_desktop_gl(ctx
))
1538 goto invalid_enum_error
;
1539 CHECK_EXTENSION(ARB_seamless_cube_map
);
1540 return ctx
->Texture
.CubeMapSeamless
;
1542 case GL_RASTERIZER_DISCARD
:
1543 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
1544 goto invalid_enum_error
;
1545 CHECK_EXTENSION(EXT_transform_feedback
);
1546 return ctx
->RasterDiscard
;
1548 /* GL_NV_primitive_restart */
1549 case GL_PRIMITIVE_RESTART_NV
:
1550 if (ctx
->API
!= API_OPENGL_COMPAT
|| !ctx
->Extensions
.NV_primitive_restart
) {
1551 goto invalid_enum_error
;
1553 return ctx
->Array
.PrimitiveRestart
;
1555 /* GL 3.1 primitive restart */
1556 case GL_PRIMITIVE_RESTART
:
1557 if (!_mesa_is_desktop_gl(ctx
) || ctx
->Version
< 31) {
1558 goto invalid_enum_error
;
1560 return ctx
->Array
.PrimitiveRestart
;
1562 case GL_PRIMITIVE_RESTART_FIXED_INDEX
:
1563 if (!_mesa_is_gles3(ctx
) && !ctx
->Extensions
.ARB_ES3_compatibility
) {
1564 goto invalid_enum_error
;
1566 return ctx
->Array
.PrimitiveRestartFixedIndex
;
1568 /* GL3.0 - GL_framebuffer_sRGB */
1569 case GL_FRAMEBUFFER_SRGB_EXT
:
1570 if (!_mesa_is_desktop_gl(ctx
))
1571 goto invalid_enum_error
;
1572 CHECK_EXTENSION(EXT_framebuffer_sRGB
);
1573 return ctx
->Color
.sRGBEnabled
;
1575 /* GL_OES_EGL_image_external */
1576 case GL_TEXTURE_EXTERNAL_OES
:
1577 if (!_mesa_is_gles(ctx
))
1578 goto invalid_enum_error
;
1579 CHECK_EXTENSION(OES_EGL_image_external
);
1580 return is_texture_enabled(ctx
, TEXTURE_EXTERNAL_BIT
);
1582 /* ARB_texture_multisample */
1583 case GL_SAMPLE_MASK
:
1584 if (!_mesa_is_desktop_gl(ctx
))
1585 goto invalid_enum_error
;
1586 CHECK_EXTENSION(ARB_texture_multisample
);
1587 return ctx
->Multisample
.SampleMask
;
1589 /* ARB_sample_shading */
1590 case GL_SAMPLE_SHADING
:
1591 if (!_mesa_is_desktop_gl(ctx
))
1592 goto invalid_enum_error
;
1593 CHECK_EXTENSION(ARB_sample_shading
);
1594 return ctx
->Multisample
.SampleShading
;
1597 goto invalid_enum_error
;
1603 _mesa_error(ctx
, GL_INVALID_ENUM
, "glIsEnabled(%s)",
1604 _mesa_lookup_enum_by_nr(cap
));