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