mesa: Factor out _mesa_disable_vertex_array_attrib.
[mesa.git] / src / mesa / main / enable.c
1 /**
2 * \file enable.c
3 * Enable/disable/query GL capabilities.
4 */
5
6 /*
7 * Mesa 3-D graphics library
8 *
9 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
10 *
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:
17 *
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
20 *
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.
28 */
29
30
31 #include "glheader.h"
32 #include "arrayobj.h"
33 #include "blend.h"
34 #include "clip.h"
35 #include "context.h"
36 #include "debug_output.h"
37 #include "enable.h"
38 #include "errors.h"
39 #include "light.h"
40 #include "mtypes.h"
41 #include "enums.h"
42 #include "texstate.h"
43 #include "varray.h"
44
45
46
47 #define CHECK_EXTENSION(EXTNAME, CAP) \
48 if (!ctx->Extensions.EXTNAME) { \
49 goto invalid_enum_error; \
50 }
51
52
53 static void
54 update_derived_primitive_restart_state(struct gl_context *ctx)
55 {
56 /* Update derived primitive restart state.
57 */
58 ctx->Array._PrimitiveRestart = ctx->Array.PrimitiveRestart
59 || ctx->Array.PrimitiveRestartFixedIndex;
60 }
61
62
63 /**
64 * Helper to enable/disable VAO client-side state.
65 */
66 static void
67 vao_state(struct gl_context *ctx, gl_vert_attrib attr, GLboolean state)
68 {
69 if (state)
70 _mesa_enable_vertex_array_attrib(ctx, ctx->Array.VAO, attr);
71 else
72 _mesa_disable_vertex_array_attrib(ctx, ctx->Array.VAO, attr);
73 }
74
75
76 /**
77 * Helper to enable/disable client-side state.
78 */
79 static void
80 client_state(struct gl_context *ctx, GLenum cap, GLboolean state)
81 {
82 switch (cap) {
83 case GL_VERTEX_ARRAY:
84 vao_state(ctx, VERT_ATTRIB_POS, state);
85 break;
86 case GL_NORMAL_ARRAY:
87 vao_state(ctx, VERT_ATTRIB_NORMAL, state);
88 break;
89 case GL_COLOR_ARRAY:
90 vao_state(ctx, VERT_ATTRIB_COLOR0, state);
91 break;
92 case GL_INDEX_ARRAY:
93 vao_state(ctx, VERT_ATTRIB_COLOR_INDEX, state);
94 break;
95 case GL_TEXTURE_COORD_ARRAY:
96 vao_state(ctx, VERT_ATTRIB_TEX(ctx->Array.ActiveTexture), state);
97 break;
98 case GL_EDGE_FLAG_ARRAY:
99 vao_state(ctx, VERT_ATTRIB_EDGEFLAG, state);
100 break;
101 case GL_FOG_COORDINATE_ARRAY_EXT:
102 vao_state(ctx, VERT_ATTRIB_FOG, state);
103 break;
104 case GL_SECONDARY_COLOR_ARRAY_EXT:
105 vao_state(ctx, VERT_ATTRIB_COLOR1, state);
106 break;
107
108 case GL_POINT_SIZE_ARRAY_OES:
109 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
110 ctx->VertexProgram.PointSizeEnabled = state;
111 vao_state(ctx, VERT_ATTRIB_POINT_SIZE, state);
112 break;
113
114 /* GL_NV_primitive_restart */
115 case GL_PRIMITIVE_RESTART_NV:
116 if (!ctx->Extensions.NV_primitive_restart)
117 goto invalid_enum_error;
118 if (ctx->Array.PrimitiveRestart == state)
119 return;
120
121 FLUSH_VERTICES(ctx, 0);
122 ctx->Array.PrimitiveRestart = state;
123 update_derived_primitive_restart_state(ctx);
124 return;
125
126 default:
127 goto invalid_enum_error;
128 }
129
130 if (ctx->Driver.Enable) {
131 ctx->Driver.Enable( ctx, cap, state );
132 }
133
134 return;
135
136 invalid_enum_error:
137 _mesa_error(ctx, GL_INVALID_ENUM, "gl%sClientState(%s)",
138 state ? "Enable" : "Disable", _mesa_enum_to_string(cap));
139 }
140
141
142 /**
143 * Enable GL capability.
144 * \param cap state to enable/disable.
145 *
146 * Get's the current context, assures that we're outside glBegin()/glEnd() and
147 * calls client_state().
148 */
149 void GLAPIENTRY
150 _mesa_EnableClientState( GLenum cap )
151 {
152 GET_CURRENT_CONTEXT(ctx);
153 client_state( ctx, cap, GL_TRUE );
154 }
155
156
157 /**
158 * Disable GL capability.
159 * \param cap state to enable/disable.
160 *
161 * Get's the current context, assures that we're outside glBegin()/glEnd() and
162 * calls client_state().
163 */
164 void GLAPIENTRY
165 _mesa_DisableClientState( GLenum cap )
166 {
167 GET_CURRENT_CONTEXT(ctx);
168 client_state( ctx, cap, GL_FALSE );
169 }
170
171
172 #undef CHECK_EXTENSION
173 #define CHECK_EXTENSION(EXTNAME, CAP) \
174 if (!ctx->Extensions.EXTNAME) { \
175 goto invalid_enum_error; \
176 }
177
178 #define CHECK_EXTENSION2(EXT1, EXT2, CAP) \
179 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
180 goto invalid_enum_error; \
181 }
182
183 /**
184 * Return pointer to current texture unit for setting/getting coordinate
185 * state.
186 * Note that we'll set GL_INVALID_OPERATION and return NULL if the active
187 * texture unit is higher than the number of supported coordinate units.
188 */
189 static struct gl_texture_unit *
190 get_texcoord_unit(struct gl_context *ctx)
191 {
192 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
193 _mesa_error(ctx, GL_INVALID_OPERATION, "glEnable/Disable(texcoord unit)");
194 return NULL;
195 }
196 else {
197 return &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
198 }
199 }
200
201
202 /**
203 * Helper function to enable or disable a texture target.
204 * \param bit one of the TEXTURE_x_BIT values
205 * \return GL_TRUE if state is changing or GL_FALSE if no change
206 */
207 static GLboolean
208 enable_texture(struct gl_context *ctx, GLboolean state, GLbitfield texBit)
209 {
210 struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
211 const GLbitfield newenabled = state
212 ? (texUnit->Enabled | texBit) : (texUnit->Enabled & ~texBit);
213
214 if (texUnit->Enabled == newenabled)
215 return GL_FALSE;
216
217 FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);
218 texUnit->Enabled = newenabled;
219 return GL_TRUE;
220 }
221
222
223 /**
224 * Helper function to enable or disable GL_MULTISAMPLE, skipping the check for
225 * whether the API supports it (GLES doesn't).
226 */
227 void
228 _mesa_set_multisample(struct gl_context *ctx, GLboolean state)
229 {
230 if (ctx->Multisample.Enabled == state)
231 return;
232
233 /* GL compatibility needs Multisample.Enable to determine program state
234 * constants.
235 */
236 if (ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGLES ||
237 !ctx->DriverFlags.NewMultisampleEnable) {
238 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
239 } else {
240 FLUSH_VERTICES(ctx, 0);
241 }
242
243 ctx->NewDriverState |= ctx->DriverFlags.NewMultisampleEnable;
244 ctx->Multisample.Enabled = state;
245
246 if (ctx->Driver.Enable) {
247 ctx->Driver.Enable(ctx, GL_MULTISAMPLE, state);
248 }
249 }
250
251 /**
252 * Helper function to enable or disable GL_FRAMEBUFFER_SRGB, skipping the
253 * check for whether the API supports it (GLES doesn't).
254 */
255 void
256 _mesa_set_framebuffer_srgb(struct gl_context *ctx, GLboolean state)
257 {
258 if (ctx->Color.sRGBEnabled == state)
259 return;
260
261 /* TODO: Switch i965 to the new flag and remove the conditional */
262 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewFramebufferSRGB ? 0 : _NEW_BUFFERS);
263 ctx->NewDriverState |= ctx->DriverFlags.NewFramebufferSRGB;
264 ctx->Color.sRGBEnabled = state;
265
266 if (ctx->Driver.Enable) {
267 ctx->Driver.Enable(ctx, GL_FRAMEBUFFER_SRGB, state);
268 }
269 }
270
271 /**
272 * Helper function to enable or disable state.
273 *
274 * \param ctx GL context.
275 * \param cap the state to enable/disable
276 * \param state whether to enable or disable the specified capability.
277 *
278 * Updates the current context and flushes the vertices as needed. For
279 * capabilities associated with extensions it verifies that those extensions
280 * are effectivly present before updating. Notifies the driver via
281 * dd_function_table::Enable.
282 */
283 void
284 _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
285 {
286 if (MESA_VERBOSE & VERBOSE_API)
287 _mesa_debug(ctx, "%s %s (newstate is %x)\n",
288 state ? "glEnable" : "glDisable",
289 _mesa_enum_to_string(cap),
290 ctx->NewState);
291
292 switch (cap) {
293 case GL_ALPHA_TEST:
294 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
295 goto invalid_enum_error;
296 if (ctx->Color.AlphaEnabled == state)
297 return;
298 /* AlphaEnabled is used by the fixed-func fragment program */
299 FLUSH_VERTICES(ctx, _NEW_COLOR);
300 ctx->NewDriverState |= ctx->DriverFlags.NewAlphaTest;
301 ctx->Color.AlphaEnabled = state;
302 break;
303 case GL_AUTO_NORMAL:
304 if (ctx->API != API_OPENGL_COMPAT)
305 goto invalid_enum_error;
306 if (ctx->Eval.AutoNormal == state)
307 return;
308 FLUSH_VERTICES(ctx, _NEW_EVAL);
309 ctx->Eval.AutoNormal = state;
310 break;
311 case GL_BLEND:
312 {
313 GLbitfield newEnabled =
314 state * ((1 << ctx->Const.MaxDrawBuffers) - 1);
315 if (newEnabled != ctx->Color.BlendEnabled) {
316 _mesa_flush_vertices_for_blend_adv(ctx, newEnabled,
317 ctx->Color._AdvancedBlendMode);
318 ctx->Color.BlendEnabled = newEnabled;
319 }
320 }
321 break;
322 case GL_CLIP_DISTANCE0: /* aka GL_CLIP_PLANE0 */
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:
330 {
331 const GLuint p = cap - GL_CLIP_DISTANCE0;
332
333 if (p >= ctx->Const.MaxClipPlanes)
334 goto invalid_enum_error;
335
336 if ((ctx->Transform.ClipPlanesEnabled & (1 << p))
337 == ((GLuint) state << p))
338 return;
339
340 /* The compatibility profile needs _NEW_TRANSFORM to transform
341 * clip planes according to the projection matrix.
342 */
343 if (ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGLES ||
344 !ctx->DriverFlags.NewClipPlaneEnable) {
345 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
346 } else {
347 FLUSH_VERTICES(ctx, 0);
348 }
349 ctx->NewDriverState |= ctx->DriverFlags.NewClipPlaneEnable;
350
351 if (state) {
352 ctx->Transform.ClipPlanesEnabled |= (1 << p);
353
354 /* The projection matrix transforms the clip plane. */
355 /* TODO: glEnable might not be the best place to do it. */
356 if (ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGLES) {
357 _mesa_update_clip_plane(ctx, p);
358 ctx->NewDriverState |= ctx->DriverFlags.NewClipPlane;
359 }
360 }
361 else {
362 ctx->Transform.ClipPlanesEnabled &= ~(1 << p);
363 }
364 }
365 break;
366 case GL_COLOR_MATERIAL:
367 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
368 goto invalid_enum_error;
369 if (ctx->Light.ColorMaterialEnabled == state)
370 return;
371 FLUSH_VERTICES(ctx, _NEW_LIGHT);
372 FLUSH_CURRENT(ctx, 0);
373 ctx->Light.ColorMaterialEnabled = state;
374 if (state) {
375 _mesa_update_color_material( ctx,
376 ctx->Current.Attrib[VERT_ATTRIB_COLOR0] );
377 }
378 break;
379 case GL_CULL_FACE:
380 if (ctx->Polygon.CullFlag == state)
381 return;
382 FLUSH_VERTICES(ctx,
383 ctx->DriverFlags.NewPolygonState ? 0 : _NEW_POLYGON);
384 ctx->NewDriverState |= ctx->DriverFlags.NewPolygonState;
385 ctx->Polygon.CullFlag = state;
386 break;
387 case GL_DEPTH_TEST:
388 if (ctx->Depth.Test == state)
389 return;
390 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepth ? 0 : _NEW_DEPTH);
391 ctx->NewDriverState |= ctx->DriverFlags.NewDepth;
392 ctx->Depth.Test = state;
393 break;
394 case GL_DEBUG_OUTPUT:
395 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB:
396 _mesa_set_debug_state_int(ctx, cap, state);
397 break;
398 case GL_DITHER:
399 if (ctx->Color.DitherFlag == state)
400 return;
401 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewBlend ? 0 : _NEW_COLOR);
402 ctx->NewDriverState |= ctx->DriverFlags.NewBlend;
403 ctx->Color.DitherFlag = state;
404 break;
405 case GL_FOG:
406 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
407 goto invalid_enum_error;
408 if (ctx->Fog.Enabled == state)
409 return;
410 FLUSH_VERTICES(ctx, _NEW_FOG);
411 ctx->Fog.Enabled = state;
412 ctx->Fog._PackedEnabledMode = state ? ctx->Fog._PackedMode : FOG_NONE;
413 break;
414 case GL_LIGHT0:
415 case GL_LIGHT1:
416 case GL_LIGHT2:
417 case GL_LIGHT3:
418 case GL_LIGHT4:
419 case GL_LIGHT5:
420 case GL_LIGHT6:
421 case GL_LIGHT7:
422 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
423 goto invalid_enum_error;
424 if (ctx->Light.Light[cap-GL_LIGHT0].Enabled == state)
425 return;
426 FLUSH_VERTICES(ctx, _NEW_LIGHT);
427 ctx->Light.Light[cap-GL_LIGHT0].Enabled = state;
428 if (state) {
429 ctx->Light._EnabledLights |= 1u << (cap - GL_LIGHT0);
430 }
431 else {
432 ctx->Light._EnabledLights &= ~(1u << (cap - GL_LIGHT0));
433 }
434 break;
435 case GL_LIGHTING:
436 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
437 goto invalid_enum_error;
438 if (ctx->Light.Enabled == state)
439 return;
440 FLUSH_VERTICES(ctx, _NEW_LIGHT);
441 ctx->Light.Enabled = state;
442 break;
443 case GL_LINE_SMOOTH:
444 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
445 goto invalid_enum_error;
446 if (ctx->Line.SmoothFlag == state)
447 return;
448 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLineState ? 0 : _NEW_LINE);
449 ctx->NewDriverState |= ctx->DriverFlags.NewLineState;
450 ctx->Line.SmoothFlag = state;
451 break;
452 case GL_LINE_STIPPLE:
453 if (ctx->API != API_OPENGL_COMPAT)
454 goto invalid_enum_error;
455 if (ctx->Line.StippleFlag == state)
456 return;
457 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLineState ? 0 : _NEW_LINE);
458 ctx->NewDriverState |= ctx->DriverFlags.NewLineState;
459 ctx->Line.StippleFlag = state;
460 break;
461 case GL_INDEX_LOGIC_OP:
462 if (ctx->API != API_OPENGL_COMPAT)
463 goto invalid_enum_error;
464 if (ctx->Color.IndexLogicOpEnabled == state)
465 return;
466 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLogicOp ? 0 : _NEW_COLOR);
467 ctx->NewDriverState |= ctx->DriverFlags.NewLogicOp;
468 ctx->Color.IndexLogicOpEnabled = state;
469 break;
470 case GL_CONSERVATIVE_RASTERIZATION_INTEL:
471 if (!_mesa_has_INTEL_conservative_rasterization(ctx))
472 goto invalid_enum_error;
473 if (ctx->IntelConservativeRasterization == state)
474 return;
475 FLUSH_VERTICES(ctx, 0);
476 ctx->NewDriverState |=
477 ctx->DriverFlags.NewIntelConservativeRasterization;
478 ctx->IntelConservativeRasterization = state;
479 break;
480 case GL_COLOR_LOGIC_OP:
481 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
482 goto invalid_enum_error;
483 if (ctx->Color.ColorLogicOpEnabled == state)
484 return;
485 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLogicOp ? 0 : _NEW_COLOR);
486 ctx->NewDriverState |= ctx->DriverFlags.NewLogicOp;
487 ctx->Color.ColorLogicOpEnabled = state;
488 break;
489 case GL_MAP1_COLOR_4:
490 if (ctx->API != API_OPENGL_COMPAT)
491 goto invalid_enum_error;
492 if (ctx->Eval.Map1Color4 == state)
493 return;
494 FLUSH_VERTICES(ctx, _NEW_EVAL);
495 ctx->Eval.Map1Color4 = state;
496 break;
497 case GL_MAP1_INDEX:
498 if (ctx->API != API_OPENGL_COMPAT)
499 goto invalid_enum_error;
500 if (ctx->Eval.Map1Index == state)
501 return;
502 FLUSH_VERTICES(ctx, _NEW_EVAL);
503 ctx->Eval.Map1Index = state;
504 break;
505 case GL_MAP1_NORMAL:
506 if (ctx->API != API_OPENGL_COMPAT)
507 goto invalid_enum_error;
508 if (ctx->Eval.Map1Normal == state)
509 return;
510 FLUSH_VERTICES(ctx, _NEW_EVAL);
511 ctx->Eval.Map1Normal = state;
512 break;
513 case GL_MAP1_TEXTURE_COORD_1:
514 if (ctx->API != API_OPENGL_COMPAT)
515 goto invalid_enum_error;
516 if (ctx->Eval.Map1TextureCoord1 == state)
517 return;
518 FLUSH_VERTICES(ctx, _NEW_EVAL);
519 ctx->Eval.Map1TextureCoord1 = state;
520 break;
521 case GL_MAP1_TEXTURE_COORD_2:
522 if (ctx->API != API_OPENGL_COMPAT)
523 goto invalid_enum_error;
524 if (ctx->Eval.Map1TextureCoord2 == state)
525 return;
526 FLUSH_VERTICES(ctx, _NEW_EVAL);
527 ctx->Eval.Map1TextureCoord2 = state;
528 break;
529 case GL_MAP1_TEXTURE_COORD_3:
530 if (ctx->API != API_OPENGL_COMPAT)
531 goto invalid_enum_error;
532 if (ctx->Eval.Map1TextureCoord3 == state)
533 return;
534 FLUSH_VERTICES(ctx, _NEW_EVAL);
535 ctx->Eval.Map1TextureCoord3 = state;
536 break;
537 case GL_MAP1_TEXTURE_COORD_4:
538 if (ctx->API != API_OPENGL_COMPAT)
539 goto invalid_enum_error;
540 if (ctx->Eval.Map1TextureCoord4 == state)
541 return;
542 FLUSH_VERTICES(ctx, _NEW_EVAL);
543 ctx->Eval.Map1TextureCoord4 = state;
544 break;
545 case GL_MAP1_VERTEX_3:
546 if (ctx->API != API_OPENGL_COMPAT)
547 goto invalid_enum_error;
548 if (ctx->Eval.Map1Vertex3 == state)
549 return;
550 FLUSH_VERTICES(ctx, _NEW_EVAL);
551 ctx->Eval.Map1Vertex3 = state;
552 break;
553 case GL_MAP1_VERTEX_4:
554 if (ctx->API != API_OPENGL_COMPAT)
555 goto invalid_enum_error;
556 if (ctx->Eval.Map1Vertex4 == state)
557 return;
558 FLUSH_VERTICES(ctx, _NEW_EVAL);
559 ctx->Eval.Map1Vertex4 = state;
560 break;
561 case GL_MAP2_COLOR_4:
562 if (ctx->API != API_OPENGL_COMPAT)
563 goto invalid_enum_error;
564 if (ctx->Eval.Map2Color4 == state)
565 return;
566 FLUSH_VERTICES(ctx, _NEW_EVAL);
567 ctx->Eval.Map2Color4 = state;
568 break;
569 case GL_MAP2_INDEX:
570 if (ctx->API != API_OPENGL_COMPAT)
571 goto invalid_enum_error;
572 if (ctx->Eval.Map2Index == state)
573 return;
574 FLUSH_VERTICES(ctx, _NEW_EVAL);
575 ctx->Eval.Map2Index = state;
576 break;
577 case GL_MAP2_NORMAL:
578 if (ctx->API != API_OPENGL_COMPAT)
579 goto invalid_enum_error;
580 if (ctx->Eval.Map2Normal == state)
581 return;
582 FLUSH_VERTICES(ctx, _NEW_EVAL);
583 ctx->Eval.Map2Normal = state;
584 break;
585 case GL_MAP2_TEXTURE_COORD_1:
586 if (ctx->API != API_OPENGL_COMPAT)
587 goto invalid_enum_error;
588 if (ctx->Eval.Map2TextureCoord1 == state)
589 return;
590 FLUSH_VERTICES(ctx, _NEW_EVAL);
591 ctx->Eval.Map2TextureCoord1 = state;
592 break;
593 case GL_MAP2_TEXTURE_COORD_2:
594 if (ctx->API != API_OPENGL_COMPAT)
595 goto invalid_enum_error;
596 if (ctx->Eval.Map2TextureCoord2 == state)
597 return;
598 FLUSH_VERTICES(ctx, _NEW_EVAL);
599 ctx->Eval.Map2TextureCoord2 = state;
600 break;
601 case GL_MAP2_TEXTURE_COORD_3:
602 if (ctx->API != API_OPENGL_COMPAT)
603 goto invalid_enum_error;
604 if (ctx->Eval.Map2TextureCoord3 == state)
605 return;
606 FLUSH_VERTICES(ctx, _NEW_EVAL);
607 ctx->Eval.Map2TextureCoord3 = state;
608 break;
609 case GL_MAP2_TEXTURE_COORD_4:
610 if (ctx->API != API_OPENGL_COMPAT)
611 goto invalid_enum_error;
612 if (ctx->Eval.Map2TextureCoord4 == state)
613 return;
614 FLUSH_VERTICES(ctx, _NEW_EVAL);
615 ctx->Eval.Map2TextureCoord4 = state;
616 break;
617 case GL_MAP2_VERTEX_3:
618 if (ctx->API != API_OPENGL_COMPAT)
619 goto invalid_enum_error;
620 if (ctx->Eval.Map2Vertex3 == state)
621 return;
622 FLUSH_VERTICES(ctx, _NEW_EVAL);
623 ctx->Eval.Map2Vertex3 = state;
624 break;
625 case GL_MAP2_VERTEX_4:
626 if (ctx->API != API_OPENGL_COMPAT)
627 goto invalid_enum_error;
628 if (ctx->Eval.Map2Vertex4 == state)
629 return;
630 FLUSH_VERTICES(ctx, _NEW_EVAL);
631 ctx->Eval.Map2Vertex4 = state;
632 break;
633 case GL_NORMALIZE:
634 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
635 goto invalid_enum_error;
636 if (ctx->Transform.Normalize == state)
637 return;
638 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
639 ctx->Transform.Normalize = state;
640 break;
641 case GL_POINT_SMOOTH:
642 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
643 goto invalid_enum_error;
644 if (ctx->Point.SmoothFlag == state)
645 return;
646 FLUSH_VERTICES(ctx, _NEW_POINT);
647 ctx->Point.SmoothFlag = state;
648 break;
649 case GL_POLYGON_SMOOTH:
650 if (!_mesa_is_desktop_gl(ctx))
651 goto invalid_enum_error;
652 if (ctx->Polygon.SmoothFlag == state)
653 return;
654 FLUSH_VERTICES(ctx,
655 ctx->DriverFlags.NewPolygonState ? 0 : _NEW_POLYGON);
656 ctx->NewDriverState |= ctx->DriverFlags.NewPolygonState;
657 ctx->Polygon.SmoothFlag = state;
658 break;
659 case GL_POLYGON_STIPPLE:
660 if (ctx->API != API_OPENGL_COMPAT)
661 goto invalid_enum_error;
662 if (ctx->Polygon.StippleFlag == state)
663 return;
664 FLUSH_VERTICES(ctx,
665 ctx->DriverFlags.NewPolygonState ? 0 : _NEW_POLYGON);
666 ctx->NewDriverState |= ctx->DriverFlags.NewPolygonState;
667 ctx->Polygon.StippleFlag = state;
668 break;
669 case GL_POLYGON_OFFSET_POINT:
670 if (!_mesa_is_desktop_gl(ctx))
671 goto invalid_enum_error;
672 if (ctx->Polygon.OffsetPoint == state)
673 return;
674 FLUSH_VERTICES(ctx,
675 ctx->DriverFlags.NewPolygonState ? 0 : _NEW_POLYGON);
676 ctx->NewDriverState |= ctx->DriverFlags.NewPolygonState;
677 ctx->Polygon.OffsetPoint = state;
678 break;
679 case GL_POLYGON_OFFSET_LINE:
680 if (!_mesa_is_desktop_gl(ctx))
681 goto invalid_enum_error;
682 if (ctx->Polygon.OffsetLine == state)
683 return;
684 FLUSH_VERTICES(ctx,
685 ctx->DriverFlags.NewPolygonState ? 0 : _NEW_POLYGON);
686 ctx->NewDriverState |= ctx->DriverFlags.NewPolygonState;
687 ctx->Polygon.OffsetLine = state;
688 break;
689 case GL_POLYGON_OFFSET_FILL:
690 if (ctx->Polygon.OffsetFill == state)
691 return;
692 FLUSH_VERTICES(ctx,
693 ctx->DriverFlags.NewPolygonState ? 0 : _NEW_POLYGON);
694 ctx->NewDriverState |= ctx->DriverFlags.NewPolygonState;
695 ctx->Polygon.OffsetFill = state;
696 break;
697 case GL_RESCALE_NORMAL_EXT:
698 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
699 goto invalid_enum_error;
700 if (ctx->Transform.RescaleNormals == state)
701 return;
702 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
703 ctx->Transform.RescaleNormals = state;
704 break;
705 case GL_SCISSOR_TEST:
706 {
707 /* Must expand glEnable to all scissors */
708 GLbitfield newEnabled =
709 state * ((1 << ctx->Const.MaxViewports) - 1);
710 if (newEnabled != ctx->Scissor.EnableFlags) {
711 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewScissorTest ? 0 :
712 _NEW_SCISSOR);
713 ctx->NewDriverState |= ctx->DriverFlags.NewScissorTest;
714 ctx->Scissor.EnableFlags = newEnabled;
715 }
716 }
717 break;
718 case GL_STENCIL_TEST:
719 if (ctx->Stencil.Enabled == state)
720 return;
721 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewStencil ? 0 : _NEW_STENCIL);
722 ctx->NewDriverState |= ctx->DriverFlags.NewStencil;
723 ctx->Stencil.Enabled = state;
724 break;
725 case GL_TEXTURE_1D:
726 if (ctx->API != API_OPENGL_COMPAT)
727 goto invalid_enum_error;
728 if (!enable_texture(ctx, state, TEXTURE_1D_BIT)) {
729 return;
730 }
731 break;
732 case GL_TEXTURE_2D:
733 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
734 goto invalid_enum_error;
735 if (!enable_texture(ctx, state, TEXTURE_2D_BIT)) {
736 return;
737 }
738 break;
739 case GL_TEXTURE_3D:
740 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
741 goto invalid_enum_error;
742 if (!enable_texture(ctx, state, TEXTURE_3D_BIT)) {
743 return;
744 }
745 break;
746 case GL_TEXTURE_GEN_S:
747 case GL_TEXTURE_GEN_T:
748 case GL_TEXTURE_GEN_R:
749 case GL_TEXTURE_GEN_Q:
750 {
751 struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
752
753 if (ctx->API != API_OPENGL_COMPAT)
754 goto invalid_enum_error;
755
756 if (texUnit) {
757 GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
758 GLbitfield newenabled = texUnit->TexGenEnabled & ~coordBit;
759 if (state)
760 newenabled |= coordBit;
761 if (texUnit->TexGenEnabled == newenabled)
762 return;
763 FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);
764 texUnit->TexGenEnabled = newenabled;
765 }
766 }
767 break;
768
769 case GL_TEXTURE_GEN_STR_OES:
770 /* disable S, T, and R at the same time */
771 {
772 struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
773
774 if (ctx->API != API_OPENGLES)
775 goto invalid_enum_error;
776
777 if (texUnit) {
778 GLuint newenabled =
779 texUnit->TexGenEnabled & ~STR_BITS;
780 if (state)
781 newenabled |= STR_BITS;
782 if (texUnit->TexGenEnabled == newenabled)
783 return;
784 FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);
785 texUnit->TexGenEnabled = newenabled;
786 }
787 }
788 break;
789
790 /* client-side state */
791 case GL_VERTEX_ARRAY:
792 case GL_NORMAL_ARRAY:
793 case GL_COLOR_ARRAY:
794 case GL_TEXTURE_COORD_ARRAY:
795 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
796 goto invalid_enum_error;
797 client_state( ctx, cap, state );
798 return;
799 case GL_INDEX_ARRAY:
800 case GL_EDGE_FLAG_ARRAY:
801 case GL_FOG_COORDINATE_ARRAY_EXT:
802 case GL_SECONDARY_COLOR_ARRAY_EXT:
803 if (ctx->API != API_OPENGL_COMPAT)
804 goto invalid_enum_error;
805 client_state( ctx, cap, state );
806 return;
807 case GL_POINT_SIZE_ARRAY_OES:
808 if (ctx->API != API_OPENGLES)
809 goto invalid_enum_error;
810 client_state( ctx, cap, state );
811 return;
812
813 /* GL_ARB_texture_cube_map */
814 case GL_TEXTURE_CUBE_MAP:
815 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
816 goto invalid_enum_error;
817 CHECK_EXTENSION(ARB_texture_cube_map, cap);
818 if (!enable_texture(ctx, state, TEXTURE_CUBE_BIT)) {
819 return;
820 }
821 break;
822
823 /* GL_EXT_secondary_color */
824 case GL_COLOR_SUM_EXT:
825 if (ctx->API != API_OPENGL_COMPAT)
826 goto invalid_enum_error;
827 if (ctx->Fog.ColorSumEnabled == state)
828 return;
829 FLUSH_VERTICES(ctx, _NEW_FOG);
830 ctx->Fog.ColorSumEnabled = state;
831 break;
832
833 /* GL_ARB_multisample */
834 case GL_MULTISAMPLE_ARB:
835 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
836 goto invalid_enum_error;
837 _mesa_set_multisample(ctx, state);
838 return;
839 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
840 if (ctx->Multisample.SampleAlphaToCoverage == state)
841 return;
842 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleAlphaToXEnable ? 0 :
843 _NEW_MULTISAMPLE);
844 ctx->NewDriverState |= ctx->DriverFlags.NewSampleAlphaToXEnable;
845 ctx->Multisample.SampleAlphaToCoverage = state;
846 break;
847 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
848 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
849 goto invalid_enum_error;
850 if (ctx->Multisample.SampleAlphaToOne == state)
851 return;
852 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleAlphaToXEnable ? 0 :
853 _NEW_MULTISAMPLE);
854 ctx->NewDriverState |= ctx->DriverFlags.NewSampleAlphaToXEnable;
855 ctx->Multisample.SampleAlphaToOne = state;
856 break;
857 case GL_SAMPLE_COVERAGE_ARB:
858 if (ctx->Multisample.SampleCoverage == state)
859 return;
860 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleMask ? 0 :
861 _NEW_MULTISAMPLE);
862 ctx->NewDriverState |= ctx->DriverFlags.NewSampleMask;
863 ctx->Multisample.SampleCoverage = state;
864 break;
865 case GL_SAMPLE_COVERAGE_INVERT_ARB:
866 if (!_mesa_is_desktop_gl(ctx))
867 goto invalid_enum_error;
868 if (ctx->Multisample.SampleCoverageInvert == state)
869 return;
870 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleMask ? 0 :
871 _NEW_MULTISAMPLE);
872 ctx->NewDriverState |= ctx->DriverFlags.NewSampleMask;
873 ctx->Multisample.SampleCoverageInvert = state;
874 break;
875
876 /* GL_ARB_sample_shading */
877 case GL_SAMPLE_SHADING:
878 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
879 goto invalid_enum_error;
880 CHECK_EXTENSION(ARB_sample_shading, cap);
881 if (ctx->Multisample.SampleShading == state)
882 return;
883 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleShading ? 0 :
884 _NEW_MULTISAMPLE);
885 ctx->NewDriverState |= ctx->DriverFlags.NewSampleShading;
886 ctx->Multisample.SampleShading = state;
887 break;
888
889 /* GL_IBM_rasterpos_clip */
890 case GL_RASTER_POSITION_UNCLIPPED_IBM:
891 if (ctx->API != API_OPENGL_COMPAT)
892 goto invalid_enum_error;
893 if (ctx->Transform.RasterPositionUnclipped == state)
894 return;
895 FLUSH_VERTICES(ctx, 0);
896 ctx->Transform.RasterPositionUnclipped = state;
897 break;
898
899 /* GL_NV_point_sprite */
900 case GL_POINT_SPRITE_NV:
901 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
902 goto invalid_enum_error;
903 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite, cap);
904 if (ctx->Point.PointSprite == state)
905 return;
906 FLUSH_VERTICES(ctx, _NEW_POINT);
907 ctx->Point.PointSprite = state;
908 break;
909
910 case GL_VERTEX_PROGRAM_ARB:
911 if (ctx->API != API_OPENGL_COMPAT)
912 goto invalid_enum_error;
913 CHECK_EXTENSION(ARB_vertex_program, cap);
914 if (ctx->VertexProgram.Enabled == state)
915 return;
916 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
917 ctx->VertexProgram.Enabled = state;
918 break;
919 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
920 /* This was added with ARB_vertex_program, but it is also used with
921 * GLSL vertex shaders on desktop.
922 */
923 if (!_mesa_is_desktop_gl(ctx))
924 goto invalid_enum_error;
925 CHECK_EXTENSION(ARB_vertex_program, cap);
926 if (ctx->VertexProgram.PointSizeEnabled == state)
927 return;
928 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
929 ctx->VertexProgram.PointSizeEnabled = state;
930 break;
931 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
932 if (ctx->API != API_OPENGL_COMPAT)
933 goto invalid_enum_error;
934 CHECK_EXTENSION(ARB_vertex_program, cap);
935 if (ctx->VertexProgram.TwoSideEnabled == state)
936 return;
937 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
938 ctx->VertexProgram.TwoSideEnabled = state;
939 break;
940
941 /* GL_NV_texture_rectangle */
942 case GL_TEXTURE_RECTANGLE_NV:
943 if (ctx->API != API_OPENGL_COMPAT)
944 goto invalid_enum_error;
945 CHECK_EXTENSION(NV_texture_rectangle, cap);
946 if (!enable_texture(ctx, state, TEXTURE_RECT_BIT)) {
947 return;
948 }
949 break;
950
951 /* GL_EXT_stencil_two_side */
952 case GL_STENCIL_TEST_TWO_SIDE_EXT:
953 if (ctx->API != API_OPENGL_COMPAT)
954 goto invalid_enum_error;
955 CHECK_EXTENSION(EXT_stencil_two_side, cap);
956 if (ctx->Stencil.TestTwoSide == state)
957 return;
958 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewStencil ? 0 : _NEW_STENCIL);
959 ctx->NewDriverState |= ctx->DriverFlags.NewStencil;
960 ctx->Stencil.TestTwoSide = state;
961 if (state) {
962 ctx->Stencil._BackFace = 2;
963 } else {
964 ctx->Stencil._BackFace = 1;
965 }
966 break;
967
968 case GL_FRAGMENT_PROGRAM_ARB:
969 if (ctx->API != API_OPENGL_COMPAT)
970 goto invalid_enum_error;
971 CHECK_EXTENSION(ARB_fragment_program, cap);
972 if (ctx->FragmentProgram.Enabled == state)
973 return;
974 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
975 ctx->FragmentProgram.Enabled = state;
976 break;
977
978 /* GL_EXT_depth_bounds_test */
979 case GL_DEPTH_BOUNDS_TEST_EXT:
980 if (!_mesa_is_desktop_gl(ctx))
981 goto invalid_enum_error;
982 CHECK_EXTENSION(EXT_depth_bounds_test, cap);
983 if (ctx->Depth.BoundsTest == state)
984 return;
985 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepth ? 0 : _NEW_DEPTH);
986 ctx->NewDriverState |= ctx->DriverFlags.NewDepth;
987 ctx->Depth.BoundsTest = state;
988 break;
989
990 case GL_DEPTH_CLAMP:
991 if (!_mesa_is_desktop_gl(ctx))
992 goto invalid_enum_error;
993 CHECK_EXTENSION(ARB_depth_clamp, cap);
994 if (ctx->Transform.DepthClamp == state)
995 return;
996 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepthClamp ? 0 :
997 _NEW_TRANSFORM);
998 ctx->NewDriverState |= ctx->DriverFlags.NewDepthClamp;
999 ctx->Transform.DepthClamp = state;
1000 break;
1001
1002 case GL_FRAGMENT_SHADER_ATI:
1003 if (ctx->API != API_OPENGL_COMPAT)
1004 goto invalid_enum_error;
1005 CHECK_EXTENSION(ATI_fragment_shader, cap);
1006 if (ctx->ATIFragmentShader.Enabled == state)
1007 return;
1008 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
1009 ctx->ATIFragmentShader.Enabled = state;
1010 break;
1011
1012 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1013 if (!_mesa_is_desktop_gl(ctx))
1014 goto invalid_enum_error;
1015 CHECK_EXTENSION(ARB_seamless_cube_map, cap);
1016 if (ctx->Texture.CubeMapSeamless != state) {
1017 FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT);
1018 ctx->Texture.CubeMapSeamless = state;
1019 }
1020 break;
1021
1022 case GL_RASTERIZER_DISCARD:
1023 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1024 goto invalid_enum_error;
1025 CHECK_EXTENSION(EXT_transform_feedback, cap);
1026 if (ctx->RasterDiscard != state) {
1027 FLUSH_VERTICES(ctx, 0);
1028 ctx->NewDriverState |= ctx->DriverFlags.NewRasterizerDiscard;
1029 ctx->RasterDiscard = state;
1030 }
1031 break;
1032
1033 case GL_TILE_RASTER_ORDER_FIXED_MESA:
1034 CHECK_EXTENSION(MESA_tile_raster_order, cap);
1035 if (ctx->TileRasterOrderFixed != state) {
1036 FLUSH_VERTICES(ctx, 0);
1037 ctx->NewDriverState |= ctx->DriverFlags.NewTileRasterOrder;
1038 ctx->TileRasterOrderFixed = state;
1039 }
1040 break;
1041
1042 case GL_TILE_RASTER_ORDER_INCREASING_X_MESA:
1043 CHECK_EXTENSION(MESA_tile_raster_order, cap);
1044 if (ctx->TileRasterOrderIncreasingX != state) {
1045 FLUSH_VERTICES(ctx, 0);
1046 ctx->NewDriverState |= ctx->DriverFlags.NewTileRasterOrder;
1047 ctx->TileRasterOrderIncreasingX = state;
1048 }
1049 break;
1050
1051 case GL_TILE_RASTER_ORDER_INCREASING_Y_MESA:
1052 CHECK_EXTENSION(MESA_tile_raster_order, cap);
1053 if (ctx->TileRasterOrderIncreasingY != state) {
1054 FLUSH_VERTICES(ctx, 0);
1055 ctx->NewDriverState |= ctx->DriverFlags.NewTileRasterOrder;
1056 ctx->TileRasterOrderIncreasingY = state;
1057 }
1058 break;
1059
1060 /* GL 3.1 primitive restart. Note: this enum is different from
1061 * GL_PRIMITIVE_RESTART_NV (which is client state).
1062 */
1063 case GL_PRIMITIVE_RESTART:
1064 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
1065 goto invalid_enum_error;
1066 }
1067 if (ctx->Array.PrimitiveRestart != state) {
1068 FLUSH_VERTICES(ctx, 0);
1069 ctx->Array.PrimitiveRestart = state;
1070 update_derived_primitive_restart_state(ctx);
1071 }
1072 break;
1073
1074 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
1075 if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility)
1076 goto invalid_enum_error;
1077 if (ctx->Array.PrimitiveRestartFixedIndex != state) {
1078 FLUSH_VERTICES(ctx, 0);
1079 ctx->Array.PrimitiveRestartFixedIndex = state;
1080 update_derived_primitive_restart_state(ctx);
1081 }
1082 break;
1083
1084 /* GL3.0 - GL_framebuffer_sRGB */
1085 case GL_FRAMEBUFFER_SRGB_EXT:
1086 if (!_mesa_is_desktop_gl(ctx))
1087 goto invalid_enum_error;
1088 CHECK_EXTENSION(EXT_framebuffer_sRGB, cap);
1089 _mesa_set_framebuffer_srgb(ctx, state);
1090 return;
1091
1092 /* GL_OES_EGL_image_external */
1093 case GL_TEXTURE_EXTERNAL_OES:
1094 if (!_mesa_is_gles(ctx))
1095 goto invalid_enum_error;
1096 CHECK_EXTENSION(OES_EGL_image_external, cap);
1097 if (!enable_texture(ctx, state, TEXTURE_EXTERNAL_BIT)) {
1098 return;
1099 }
1100 break;
1101
1102 /* ARB_texture_multisample */
1103 case GL_SAMPLE_MASK:
1104 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
1105 goto invalid_enum_error;
1106 CHECK_EXTENSION(ARB_texture_multisample, cap);
1107 if (ctx->Multisample.SampleMask == state)
1108 return;
1109 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleMask ? 0 :
1110 _NEW_MULTISAMPLE);
1111 ctx->NewDriverState |= ctx->DriverFlags.NewSampleMask;
1112 ctx->Multisample.SampleMask = state;
1113 break;
1114
1115 case GL_BLEND_ADVANCED_COHERENT_KHR:
1116 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent, cap);
1117 if (ctx->Color.BlendCoherent == state)
1118 return;
1119 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewBlend ? 0 : _NEW_COLOR);
1120 ctx->NewDriverState |= ctx->DriverFlags.NewBlend;
1121 ctx->Color.BlendCoherent = state;
1122 break;
1123
1124 default:
1125 goto invalid_enum_error;
1126 }
1127
1128 if (ctx->Driver.Enable) {
1129 ctx->Driver.Enable( ctx, cap, state );
1130 }
1131
1132 return;
1133
1134 invalid_enum_error:
1135 _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(%s)",
1136 state ? "Enable" : "Disable", _mesa_enum_to_string(cap));
1137 }
1138
1139
1140 /**
1141 * Enable GL capability. Called by glEnable()
1142 * \param cap state to enable.
1143 */
1144 void GLAPIENTRY
1145 _mesa_Enable( GLenum cap )
1146 {
1147 GET_CURRENT_CONTEXT(ctx);
1148
1149 _mesa_set_enable( ctx, cap, GL_TRUE );
1150 }
1151
1152
1153 /**
1154 * Disable GL capability. Called by glDisable()
1155 * \param cap state to disable.
1156 */
1157 void GLAPIENTRY
1158 _mesa_Disable( GLenum cap )
1159 {
1160 GET_CURRENT_CONTEXT(ctx);
1161
1162 _mesa_set_enable( ctx, cap, GL_FALSE );
1163 }
1164
1165
1166
1167 /**
1168 * Enable/disable an indexed state var.
1169 */
1170 void
1171 _mesa_set_enablei(struct gl_context *ctx, GLenum cap,
1172 GLuint index, GLboolean state)
1173 {
1174 assert(state == 0 || state == 1);
1175 switch (cap) {
1176 case GL_BLEND:
1177 if (!ctx->Extensions.EXT_draw_buffers2) {
1178 goto invalid_enum_error;
1179 }
1180 if (index >= ctx->Const.MaxDrawBuffers) {
1181 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1182 state ? "glEnableIndexed" : "glDisableIndexed", index);
1183 return;
1184 }
1185 if (((ctx->Color.BlendEnabled >> index) & 1) != state) {
1186 GLbitfield enabled = ctx->Color.BlendEnabled;
1187
1188 if (state)
1189 enabled |= (1 << index);
1190 else
1191 enabled &= ~(1 << index);
1192
1193 _mesa_flush_vertices_for_blend_adv(ctx, enabled,
1194 ctx->Color._AdvancedBlendMode);
1195 ctx->Color.BlendEnabled = enabled;
1196 }
1197 break;
1198 case GL_SCISSOR_TEST:
1199 if (index >= ctx->Const.MaxViewports) {
1200 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1201 state ? "glEnablei" : "glDisablei", index);
1202 return;
1203 }
1204 if (((ctx->Scissor.EnableFlags >> index) & 1) != state) {
1205 FLUSH_VERTICES(ctx,
1206 ctx->DriverFlags.NewScissorTest ? 0 : _NEW_SCISSOR);
1207 ctx->NewDriverState |= ctx->DriverFlags.NewScissorTest;
1208 if (state)
1209 ctx->Scissor.EnableFlags |= (1 << index);
1210 else
1211 ctx->Scissor.EnableFlags &= ~(1 << index);
1212 }
1213 break;
1214 default:
1215 goto invalid_enum_error;
1216 }
1217 return;
1218
1219 invalid_enum_error:
1220 _mesa_error(ctx, GL_INVALID_ENUM, "%s(cap=%s)",
1221 state ? "glEnablei" : "glDisablei",
1222 _mesa_enum_to_string(cap));
1223 }
1224
1225
1226 void GLAPIENTRY
1227 _mesa_Disablei( GLenum cap, GLuint index )
1228 {
1229 GET_CURRENT_CONTEXT(ctx);
1230 _mesa_set_enablei(ctx, cap, index, GL_FALSE);
1231 }
1232
1233
1234 void GLAPIENTRY
1235 _mesa_Enablei( GLenum cap, GLuint index )
1236 {
1237 GET_CURRENT_CONTEXT(ctx);
1238 _mesa_set_enablei(ctx, cap, index, GL_TRUE);
1239 }
1240
1241
1242 GLboolean GLAPIENTRY
1243 _mesa_IsEnabledi( GLenum cap, GLuint index )
1244 {
1245 GET_CURRENT_CONTEXT(ctx);
1246 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1247 switch (cap) {
1248 case GL_BLEND:
1249 if (index >= ctx->Const.MaxDrawBuffers) {
1250 _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
1251 index);
1252 return GL_FALSE;
1253 }
1254 return (ctx->Color.BlendEnabled >> index) & 1;
1255 case GL_SCISSOR_TEST:
1256 if (index >= ctx->Const.MaxViewports) {
1257 _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
1258 index);
1259 return GL_FALSE;
1260 }
1261 return (ctx->Scissor.EnableFlags >> index) & 1;
1262 default:
1263 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabledIndexed(cap=%s)",
1264 _mesa_enum_to_string(cap));
1265 return GL_FALSE;
1266 }
1267 }
1268
1269
1270
1271
1272 #undef CHECK_EXTENSION
1273 #define CHECK_EXTENSION(EXTNAME) \
1274 if (!ctx->Extensions.EXTNAME) { \
1275 goto invalid_enum_error; \
1276 }
1277
1278 #undef CHECK_EXTENSION2
1279 #define CHECK_EXTENSION2(EXT1, EXT2) \
1280 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1281 goto invalid_enum_error; \
1282 }
1283
1284
1285 /**
1286 * Helper function to determine whether a texture target is enabled.
1287 */
1288 static GLboolean
1289 is_texture_enabled(struct gl_context *ctx, GLbitfield bit)
1290 {
1291 const struct gl_texture_unit *const texUnit =
1292 &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1293 return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE;
1294 }
1295
1296
1297 /**
1298 * Return simple enable/disable state.
1299 *
1300 * \param cap state variable to query.
1301 *
1302 * Returns the state of the specified capability from the current GL context.
1303 * For the capabilities associated with extensions verifies that those
1304 * extensions are effectively present before reporting.
1305 */
1306 GLboolean GLAPIENTRY
1307 _mesa_IsEnabled( GLenum cap )
1308 {
1309 GET_CURRENT_CONTEXT(ctx);
1310 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1311
1312 switch (cap) {
1313 case GL_ALPHA_TEST:
1314 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1315 goto invalid_enum_error;
1316 return ctx->Color.AlphaEnabled;
1317 case GL_AUTO_NORMAL:
1318 if (ctx->API != API_OPENGL_COMPAT)
1319 goto invalid_enum_error;
1320 return ctx->Eval.AutoNormal;
1321 case GL_BLEND:
1322 return ctx->Color.BlendEnabled & 1; /* return state for buffer[0] */
1323 case GL_CLIP_DISTANCE0: /* aka GL_CLIP_PLANE0 */
1324 case GL_CLIP_DISTANCE1:
1325 case GL_CLIP_DISTANCE2:
1326 case GL_CLIP_DISTANCE3:
1327 case GL_CLIP_DISTANCE4:
1328 case GL_CLIP_DISTANCE5:
1329 case GL_CLIP_DISTANCE6:
1330 case GL_CLIP_DISTANCE7: {
1331 const GLuint p = cap - GL_CLIP_DISTANCE0;
1332
1333 if (p >= ctx->Const.MaxClipPlanes)
1334 goto invalid_enum_error;
1335
1336 return (ctx->Transform.ClipPlanesEnabled >> p) & 1;
1337 }
1338 case GL_COLOR_MATERIAL:
1339 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1340 goto invalid_enum_error;
1341 return ctx->Light.ColorMaterialEnabled;
1342 case GL_CULL_FACE:
1343 return ctx->Polygon.CullFlag;
1344 case GL_DEBUG_OUTPUT:
1345 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB:
1346 return (GLboolean) _mesa_get_debug_state_int(ctx, cap);
1347 case GL_DEPTH_TEST:
1348 return ctx->Depth.Test;
1349 case GL_DITHER:
1350 return ctx->Color.DitherFlag;
1351 case GL_FOG:
1352 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1353 goto invalid_enum_error;
1354 return ctx->Fog.Enabled;
1355 case GL_LIGHTING:
1356 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1357 goto invalid_enum_error;
1358 return ctx->Light.Enabled;
1359 case GL_LIGHT0:
1360 case GL_LIGHT1:
1361 case GL_LIGHT2:
1362 case GL_LIGHT3:
1363 case GL_LIGHT4:
1364 case GL_LIGHT5:
1365 case GL_LIGHT6:
1366 case GL_LIGHT7:
1367 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1368 goto invalid_enum_error;
1369 return ctx->Light.Light[cap-GL_LIGHT0].Enabled;
1370 case GL_LINE_SMOOTH:
1371 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1372 goto invalid_enum_error;
1373 return ctx->Line.SmoothFlag;
1374 case GL_LINE_STIPPLE:
1375 if (ctx->API != API_OPENGL_COMPAT)
1376 goto invalid_enum_error;
1377 return ctx->Line.StippleFlag;
1378 case GL_INDEX_LOGIC_OP:
1379 if (ctx->API != API_OPENGL_COMPAT)
1380 goto invalid_enum_error;
1381 return ctx->Color.IndexLogicOpEnabled;
1382 case GL_COLOR_LOGIC_OP:
1383 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1384 goto invalid_enum_error;
1385 return ctx->Color.ColorLogicOpEnabled;
1386 case GL_MAP1_COLOR_4:
1387 if (ctx->API != API_OPENGL_COMPAT)
1388 goto invalid_enum_error;
1389 return ctx->Eval.Map1Color4;
1390 case GL_MAP1_INDEX:
1391 if (ctx->API != API_OPENGL_COMPAT)
1392 goto invalid_enum_error;
1393 return ctx->Eval.Map1Index;
1394 case GL_MAP1_NORMAL:
1395 if (ctx->API != API_OPENGL_COMPAT)
1396 goto invalid_enum_error;
1397 return ctx->Eval.Map1Normal;
1398 case GL_MAP1_TEXTURE_COORD_1:
1399 if (ctx->API != API_OPENGL_COMPAT)
1400 goto invalid_enum_error;
1401 return ctx->Eval.Map1TextureCoord1;
1402 case GL_MAP1_TEXTURE_COORD_2:
1403 if (ctx->API != API_OPENGL_COMPAT)
1404 goto invalid_enum_error;
1405 return ctx->Eval.Map1TextureCoord2;
1406 case GL_MAP1_TEXTURE_COORD_3:
1407 if (ctx->API != API_OPENGL_COMPAT)
1408 goto invalid_enum_error;
1409 return ctx->Eval.Map1TextureCoord3;
1410 case GL_MAP1_TEXTURE_COORD_4:
1411 if (ctx->API != API_OPENGL_COMPAT)
1412 goto invalid_enum_error;
1413 return ctx->Eval.Map1TextureCoord4;
1414 case GL_MAP1_VERTEX_3:
1415 if (ctx->API != API_OPENGL_COMPAT)
1416 goto invalid_enum_error;
1417 return ctx->Eval.Map1Vertex3;
1418 case GL_MAP1_VERTEX_4:
1419 if (ctx->API != API_OPENGL_COMPAT)
1420 goto invalid_enum_error;
1421 return ctx->Eval.Map1Vertex4;
1422 case GL_MAP2_COLOR_4:
1423 if (ctx->API != API_OPENGL_COMPAT)
1424 goto invalid_enum_error;
1425 return ctx->Eval.Map2Color4;
1426 case GL_MAP2_INDEX:
1427 if (ctx->API != API_OPENGL_COMPAT)
1428 goto invalid_enum_error;
1429 return ctx->Eval.Map2Index;
1430 case GL_MAP2_NORMAL:
1431 if (ctx->API != API_OPENGL_COMPAT)
1432 goto invalid_enum_error;
1433 return ctx->Eval.Map2Normal;
1434 case GL_MAP2_TEXTURE_COORD_1:
1435 if (ctx->API != API_OPENGL_COMPAT)
1436 goto invalid_enum_error;
1437 return ctx->Eval.Map2TextureCoord1;
1438 case GL_MAP2_TEXTURE_COORD_2:
1439 if (ctx->API != API_OPENGL_COMPAT)
1440 goto invalid_enum_error;
1441 return ctx->Eval.Map2TextureCoord2;
1442 case GL_MAP2_TEXTURE_COORD_3:
1443 if (ctx->API != API_OPENGL_COMPAT)
1444 goto invalid_enum_error;
1445 return ctx->Eval.Map2TextureCoord3;
1446 case GL_MAP2_TEXTURE_COORD_4:
1447 if (ctx->API != API_OPENGL_COMPAT)
1448 goto invalid_enum_error;
1449 return ctx->Eval.Map2TextureCoord4;
1450 case GL_MAP2_VERTEX_3:
1451 if (ctx->API != API_OPENGL_COMPAT)
1452 goto invalid_enum_error;
1453 return ctx->Eval.Map2Vertex3;
1454 case GL_MAP2_VERTEX_4:
1455 if (ctx->API != API_OPENGL_COMPAT)
1456 goto invalid_enum_error;
1457 return ctx->Eval.Map2Vertex4;
1458 case GL_NORMALIZE:
1459 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1460 goto invalid_enum_error;
1461 return ctx->Transform.Normalize;
1462 case GL_POINT_SMOOTH:
1463 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1464 goto invalid_enum_error;
1465 return ctx->Point.SmoothFlag;
1466 case GL_POLYGON_SMOOTH:
1467 if (!_mesa_is_desktop_gl(ctx))
1468 goto invalid_enum_error;
1469 return ctx->Polygon.SmoothFlag;
1470 case GL_POLYGON_STIPPLE:
1471 if (ctx->API != API_OPENGL_COMPAT)
1472 goto invalid_enum_error;
1473 return ctx->Polygon.StippleFlag;
1474 case GL_POLYGON_OFFSET_POINT:
1475 if (!_mesa_is_desktop_gl(ctx))
1476 goto invalid_enum_error;
1477 return ctx->Polygon.OffsetPoint;
1478 case GL_POLYGON_OFFSET_LINE:
1479 if (!_mesa_is_desktop_gl(ctx))
1480 goto invalid_enum_error;
1481 return ctx->Polygon.OffsetLine;
1482 case GL_POLYGON_OFFSET_FILL:
1483 return ctx->Polygon.OffsetFill;
1484 case GL_RESCALE_NORMAL_EXT:
1485 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1486 goto invalid_enum_error;
1487 return ctx->Transform.RescaleNormals;
1488 case GL_SCISSOR_TEST:
1489 return ctx->Scissor.EnableFlags & 1; /* return state for index 0 */
1490 case GL_STENCIL_TEST:
1491 return ctx->Stencil.Enabled;
1492 case GL_TEXTURE_1D:
1493 if (ctx->API != API_OPENGL_COMPAT)
1494 goto invalid_enum_error;
1495 return is_texture_enabled(ctx, TEXTURE_1D_BIT);
1496 case GL_TEXTURE_2D:
1497 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1498 goto invalid_enum_error;
1499 return is_texture_enabled(ctx, TEXTURE_2D_BIT);
1500 case GL_TEXTURE_3D:
1501 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1502 goto invalid_enum_error;
1503 return is_texture_enabled(ctx, TEXTURE_3D_BIT);
1504 case GL_TEXTURE_GEN_S:
1505 case GL_TEXTURE_GEN_T:
1506 case GL_TEXTURE_GEN_R:
1507 case GL_TEXTURE_GEN_Q:
1508 {
1509 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1510
1511 if (ctx->API != API_OPENGL_COMPAT)
1512 goto invalid_enum_error;
1513
1514 if (texUnit) {
1515 GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
1516 return (texUnit->TexGenEnabled & coordBit) ? GL_TRUE : GL_FALSE;
1517 }
1518 }
1519 return GL_FALSE;
1520 case GL_TEXTURE_GEN_STR_OES:
1521 {
1522 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1523
1524 if (ctx->API != API_OPENGLES)
1525 goto invalid_enum_error;
1526
1527 if (texUnit) {
1528 return (texUnit->TexGenEnabled & STR_BITS) == STR_BITS
1529 ? GL_TRUE : GL_FALSE;
1530 }
1531 }
1532
1533 /* client-side state */
1534 case GL_VERTEX_ARRAY:
1535 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1536 goto invalid_enum_error;
1537 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POS].Enabled;
1538 case GL_NORMAL_ARRAY:
1539 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1540 goto invalid_enum_error;
1541 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled;
1542 case GL_COLOR_ARRAY:
1543 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1544 goto invalid_enum_error;
1545 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled;
1546 case GL_INDEX_ARRAY:
1547 if (ctx->API != API_OPENGL_COMPAT)
1548 goto invalid_enum_error;
1549 return ctx->Array.VAO->
1550 VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled;
1551 case GL_TEXTURE_COORD_ARRAY:
1552 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1553 goto invalid_enum_error;
1554 return ctx->Array.VAO->
1555 VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Enabled;
1556 case GL_EDGE_FLAG_ARRAY:
1557 if (ctx->API != API_OPENGL_COMPAT)
1558 goto invalid_enum_error;
1559 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled;
1560 case GL_FOG_COORDINATE_ARRAY_EXT:
1561 if (ctx->API != API_OPENGL_COMPAT)
1562 goto invalid_enum_error;
1563 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_FOG].Enabled;
1564 case GL_SECONDARY_COLOR_ARRAY_EXT:
1565 if (ctx->API != API_OPENGL_COMPAT)
1566 goto invalid_enum_error;
1567 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled;
1568 case GL_POINT_SIZE_ARRAY_OES:
1569 if (ctx->API != API_OPENGLES)
1570 goto invalid_enum_error;
1571 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled;
1572
1573 /* GL_ARB_texture_cube_map */
1574 case GL_TEXTURE_CUBE_MAP:
1575 CHECK_EXTENSION(ARB_texture_cube_map);
1576 return is_texture_enabled(ctx, TEXTURE_CUBE_BIT);
1577
1578 /* GL_EXT_secondary_color */
1579 case GL_COLOR_SUM_EXT:
1580 if (ctx->API != API_OPENGL_COMPAT)
1581 goto invalid_enum_error;
1582 return ctx->Fog.ColorSumEnabled;
1583
1584 /* GL_ARB_multisample */
1585 case GL_MULTISAMPLE_ARB:
1586 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1587 goto invalid_enum_error;
1588 return ctx->Multisample.Enabled;
1589 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
1590 return ctx->Multisample.SampleAlphaToCoverage;
1591 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
1592 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1593 goto invalid_enum_error;
1594 return ctx->Multisample.SampleAlphaToOne;
1595 case GL_SAMPLE_COVERAGE_ARB:
1596 return ctx->Multisample.SampleCoverage;
1597 case GL_SAMPLE_COVERAGE_INVERT_ARB:
1598 if (!_mesa_is_desktop_gl(ctx))
1599 goto invalid_enum_error;
1600 return ctx->Multisample.SampleCoverageInvert;
1601
1602 /* GL_IBM_rasterpos_clip */
1603 case GL_RASTER_POSITION_UNCLIPPED_IBM:
1604 if (ctx->API != API_OPENGL_COMPAT)
1605 goto invalid_enum_error;
1606 return ctx->Transform.RasterPositionUnclipped;
1607
1608 /* GL_NV_point_sprite */
1609 case GL_POINT_SPRITE_NV:
1610 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1611 goto invalid_enum_error;
1612 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite)
1613 return ctx->Point.PointSprite;
1614
1615 case GL_VERTEX_PROGRAM_ARB:
1616 if (ctx->API != API_OPENGL_COMPAT)
1617 goto invalid_enum_error;
1618 CHECK_EXTENSION(ARB_vertex_program);
1619 return ctx->VertexProgram.Enabled;
1620 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
1621 /* This was added with ARB_vertex_program, but it is also used with
1622 * GLSL vertex shaders on desktop.
1623 */
1624 if (!_mesa_is_desktop_gl(ctx))
1625 goto invalid_enum_error;
1626 CHECK_EXTENSION(ARB_vertex_program);
1627 return ctx->VertexProgram.PointSizeEnabled;
1628 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
1629 if (ctx->API != API_OPENGL_COMPAT)
1630 goto invalid_enum_error;
1631 CHECK_EXTENSION(ARB_vertex_program);
1632 return ctx->VertexProgram.TwoSideEnabled;
1633
1634 /* GL_NV_texture_rectangle */
1635 case GL_TEXTURE_RECTANGLE_NV:
1636 if (ctx->API != API_OPENGL_COMPAT)
1637 goto invalid_enum_error;
1638 CHECK_EXTENSION(NV_texture_rectangle);
1639 return is_texture_enabled(ctx, TEXTURE_RECT_BIT);
1640
1641 /* GL_EXT_stencil_two_side */
1642 case GL_STENCIL_TEST_TWO_SIDE_EXT:
1643 if (ctx->API != API_OPENGL_COMPAT)
1644 goto invalid_enum_error;
1645 CHECK_EXTENSION(EXT_stencil_two_side);
1646 return ctx->Stencil.TestTwoSide;
1647
1648 case GL_FRAGMENT_PROGRAM_ARB:
1649 if (ctx->API != API_OPENGL_COMPAT)
1650 goto invalid_enum_error;
1651 return ctx->FragmentProgram.Enabled;
1652
1653 /* GL_EXT_depth_bounds_test */
1654 case GL_DEPTH_BOUNDS_TEST_EXT:
1655 if (!_mesa_is_desktop_gl(ctx))
1656 goto invalid_enum_error;
1657 CHECK_EXTENSION(EXT_depth_bounds_test);
1658 return ctx->Depth.BoundsTest;
1659
1660 /* GL_ARB_depth_clamp */
1661 case GL_DEPTH_CLAMP:
1662 if (!_mesa_is_desktop_gl(ctx))
1663 goto invalid_enum_error;
1664 CHECK_EXTENSION(ARB_depth_clamp);
1665 return ctx->Transform.DepthClamp;
1666
1667 case GL_FRAGMENT_SHADER_ATI:
1668 if (ctx->API != API_OPENGL_COMPAT)
1669 goto invalid_enum_error;
1670 CHECK_EXTENSION(ATI_fragment_shader);
1671 return ctx->ATIFragmentShader.Enabled;
1672
1673 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1674 if (!_mesa_is_desktop_gl(ctx))
1675 goto invalid_enum_error;
1676 CHECK_EXTENSION(ARB_seamless_cube_map);
1677 return ctx->Texture.CubeMapSeamless;
1678
1679 case GL_RASTERIZER_DISCARD:
1680 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1681 goto invalid_enum_error;
1682 CHECK_EXTENSION(EXT_transform_feedback);
1683 return ctx->RasterDiscard;
1684
1685 /* GL_NV_primitive_restart */
1686 case GL_PRIMITIVE_RESTART_NV:
1687 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.NV_primitive_restart) {
1688 goto invalid_enum_error;
1689 }
1690 return ctx->Array.PrimitiveRestart;
1691
1692 /* GL 3.1 primitive restart */
1693 case GL_PRIMITIVE_RESTART:
1694 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
1695 goto invalid_enum_error;
1696 }
1697 return ctx->Array.PrimitiveRestart;
1698
1699 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
1700 if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility) {
1701 goto invalid_enum_error;
1702 }
1703 return ctx->Array.PrimitiveRestartFixedIndex;
1704
1705 /* GL3.0 - GL_framebuffer_sRGB */
1706 case GL_FRAMEBUFFER_SRGB_EXT:
1707 if (!_mesa_is_desktop_gl(ctx))
1708 goto invalid_enum_error;
1709 CHECK_EXTENSION(EXT_framebuffer_sRGB);
1710 return ctx->Color.sRGBEnabled;
1711
1712 /* GL_OES_EGL_image_external */
1713 case GL_TEXTURE_EXTERNAL_OES:
1714 if (!_mesa_is_gles(ctx))
1715 goto invalid_enum_error;
1716 CHECK_EXTENSION(OES_EGL_image_external);
1717 return is_texture_enabled(ctx, TEXTURE_EXTERNAL_BIT);
1718
1719 /* ARB_texture_multisample */
1720 case GL_SAMPLE_MASK:
1721 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
1722 goto invalid_enum_error;
1723 CHECK_EXTENSION(ARB_texture_multisample);
1724 return ctx->Multisample.SampleMask;
1725
1726 /* ARB_sample_shading */
1727 case GL_SAMPLE_SHADING:
1728 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1729 goto invalid_enum_error;
1730 CHECK_EXTENSION(ARB_sample_shading);
1731 return ctx->Multisample.SampleShading;
1732
1733 case GL_BLEND_ADVANCED_COHERENT_KHR:
1734 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent);
1735 return ctx->Color.BlendCoherent;
1736
1737 case GL_CONSERVATIVE_RASTERIZATION_INTEL:
1738 CHECK_EXTENSION(INTEL_conservative_rasterization);
1739 return ctx->IntelConservativeRasterization;
1740
1741 case GL_TILE_RASTER_ORDER_FIXED_MESA:
1742 CHECK_EXTENSION(MESA_tile_raster_order);
1743 return ctx->TileRasterOrderFixed;
1744
1745 case GL_TILE_RASTER_ORDER_INCREASING_X_MESA:
1746 CHECK_EXTENSION(MESA_tile_raster_order);
1747 return ctx->TileRasterOrderIncreasingX;
1748
1749 case GL_TILE_RASTER_ORDER_INCREASING_Y_MESA:
1750 CHECK_EXTENSION(MESA_tile_raster_order);
1751 return ctx->TileRasterOrderIncreasingY;
1752
1753 default:
1754 goto invalid_enum_error;
1755 }
1756
1757 return GL_FALSE;
1758
1759 invalid_enum_error:
1760 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(%s)",
1761 _mesa_enum_to_string(cap));
1762 return GL_FALSE;
1763 }