mesa: don't flag _NEW_TRANSFORM for st/mesa if possible
[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 _mesa_update_clip_plane(ctx, p);
363 }
364 else {
365 ctx->Transform.ClipPlanesEnabled &= ~(1 << p);
366 }
367 }
368 break;
369 case GL_COLOR_MATERIAL:
370 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
371 goto invalid_enum_error;
372 if (ctx->Light.ColorMaterialEnabled == state)
373 return;
374 FLUSH_VERTICES(ctx, _NEW_LIGHT);
375 FLUSH_CURRENT(ctx, 0);
376 ctx->Light.ColorMaterialEnabled = state;
377 if (state) {
378 _mesa_update_color_material( ctx,
379 ctx->Current.Attrib[VERT_ATTRIB_COLOR0] );
380 }
381 break;
382 case GL_CULL_FACE:
383 if (ctx->Polygon.CullFlag == state)
384 return;
385 FLUSH_VERTICES(ctx, _NEW_POLYGON);
386 ctx->Polygon.CullFlag = state;
387 break;
388 case GL_DEPTH_TEST:
389 if (ctx->Depth.Test == state)
390 return;
391 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepth ? 0 : _NEW_DEPTH);
392 ctx->NewDriverState |= ctx->DriverFlags.NewDepth;
393 ctx->Depth.Test = state;
394 break;
395 case GL_DEBUG_OUTPUT:
396 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB:
397 _mesa_set_debug_state_int(ctx, cap, state);
398 break;
399 case GL_DITHER:
400 if (ctx->Color.DitherFlag == state)
401 return;
402 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewBlend ? 0 : _NEW_COLOR);
403 ctx->NewDriverState |= ctx->DriverFlags.NewBlend;
404 ctx->Color.DitherFlag = state;
405 break;
406 case GL_FOG:
407 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
408 goto invalid_enum_error;
409 if (ctx->Fog.Enabled == state)
410 return;
411 FLUSH_VERTICES(ctx, _NEW_FOG);
412 ctx->Fog.Enabled = state;
413 ctx->Fog._PackedEnabledMode = state ? ctx->Fog._PackedMode : FOG_NONE;
414 break;
415 case GL_LIGHT0:
416 case GL_LIGHT1:
417 case GL_LIGHT2:
418 case GL_LIGHT3:
419 case GL_LIGHT4:
420 case GL_LIGHT5:
421 case GL_LIGHT6:
422 case GL_LIGHT7:
423 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
424 goto invalid_enum_error;
425 if (ctx->Light.Light[cap-GL_LIGHT0].Enabled == state)
426 return;
427 FLUSH_VERTICES(ctx, _NEW_LIGHT);
428 ctx->Light.Light[cap-GL_LIGHT0].Enabled = state;
429 if (state) {
430 ctx->Light._EnabledLights |= 1u << (cap - GL_LIGHT0);
431 }
432 else {
433 ctx->Light._EnabledLights &= ~(1u << (cap - GL_LIGHT0));
434 }
435 break;
436 case GL_LIGHTING:
437 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
438 goto invalid_enum_error;
439 if (ctx->Light.Enabled == state)
440 return;
441 FLUSH_VERTICES(ctx, _NEW_LIGHT);
442 ctx->Light.Enabled = state;
443 break;
444 case GL_LINE_SMOOTH:
445 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
446 goto invalid_enum_error;
447 if (ctx->Line.SmoothFlag == state)
448 return;
449 FLUSH_VERTICES(ctx, _NEW_LINE);
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, _NEW_LINE);
458 ctx->Line.StippleFlag = state;
459 break;
460 case GL_INDEX_LOGIC_OP:
461 if (ctx->API != API_OPENGL_COMPAT)
462 goto invalid_enum_error;
463 if (ctx->Color.IndexLogicOpEnabled == state)
464 return;
465 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLogicOp ? 0 : _NEW_COLOR);
466 ctx->NewDriverState |= ctx->DriverFlags.NewLogicOp;
467 ctx->Color.IndexLogicOpEnabled = state;
468 break;
469 case GL_CONSERVATIVE_RASTERIZATION_INTEL:
470 if (!_mesa_has_INTEL_conservative_rasterization(ctx))
471 goto invalid_enum_error;
472 if (ctx->IntelConservativeRasterization == state)
473 return;
474 FLUSH_VERTICES(ctx, 0);
475 ctx->NewDriverState |=
476 ctx->DriverFlags.NewIntelConservativeRasterization;
477 ctx->IntelConservativeRasterization = state;
478 break;
479 case GL_COLOR_LOGIC_OP:
480 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
481 goto invalid_enum_error;
482 if (ctx->Color.ColorLogicOpEnabled == state)
483 return;
484 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLogicOp ? 0 : _NEW_COLOR);
485 ctx->NewDriverState |= ctx->DriverFlags.NewLogicOp;
486 ctx->Color.ColorLogicOpEnabled = state;
487 break;
488 case GL_MAP1_COLOR_4:
489 if (ctx->API != API_OPENGL_COMPAT)
490 goto invalid_enum_error;
491 if (ctx->Eval.Map1Color4 == state)
492 return;
493 FLUSH_VERTICES(ctx, _NEW_EVAL);
494 ctx->Eval.Map1Color4 = state;
495 break;
496 case GL_MAP1_INDEX:
497 if (ctx->API != API_OPENGL_COMPAT)
498 goto invalid_enum_error;
499 if (ctx->Eval.Map1Index == state)
500 return;
501 FLUSH_VERTICES(ctx, _NEW_EVAL);
502 ctx->Eval.Map1Index = state;
503 break;
504 case GL_MAP1_NORMAL:
505 if (ctx->API != API_OPENGL_COMPAT)
506 goto invalid_enum_error;
507 if (ctx->Eval.Map1Normal == state)
508 return;
509 FLUSH_VERTICES(ctx, _NEW_EVAL);
510 ctx->Eval.Map1Normal = state;
511 break;
512 case GL_MAP1_TEXTURE_COORD_1:
513 if (ctx->API != API_OPENGL_COMPAT)
514 goto invalid_enum_error;
515 if (ctx->Eval.Map1TextureCoord1 == state)
516 return;
517 FLUSH_VERTICES(ctx, _NEW_EVAL);
518 ctx->Eval.Map1TextureCoord1 = state;
519 break;
520 case GL_MAP1_TEXTURE_COORD_2:
521 if (ctx->API != API_OPENGL_COMPAT)
522 goto invalid_enum_error;
523 if (ctx->Eval.Map1TextureCoord2 == state)
524 return;
525 FLUSH_VERTICES(ctx, _NEW_EVAL);
526 ctx->Eval.Map1TextureCoord2 = state;
527 break;
528 case GL_MAP1_TEXTURE_COORD_3:
529 if (ctx->API != API_OPENGL_COMPAT)
530 goto invalid_enum_error;
531 if (ctx->Eval.Map1TextureCoord3 == state)
532 return;
533 FLUSH_VERTICES(ctx, _NEW_EVAL);
534 ctx->Eval.Map1TextureCoord3 = state;
535 break;
536 case GL_MAP1_TEXTURE_COORD_4:
537 if (ctx->API != API_OPENGL_COMPAT)
538 goto invalid_enum_error;
539 if (ctx->Eval.Map1TextureCoord4 == state)
540 return;
541 FLUSH_VERTICES(ctx, _NEW_EVAL);
542 ctx->Eval.Map1TextureCoord4 = state;
543 break;
544 case GL_MAP1_VERTEX_3:
545 if (ctx->API != API_OPENGL_COMPAT)
546 goto invalid_enum_error;
547 if (ctx->Eval.Map1Vertex3 == state)
548 return;
549 FLUSH_VERTICES(ctx, _NEW_EVAL);
550 ctx->Eval.Map1Vertex3 = state;
551 break;
552 case GL_MAP1_VERTEX_4:
553 if (ctx->API != API_OPENGL_COMPAT)
554 goto invalid_enum_error;
555 if (ctx->Eval.Map1Vertex4 == state)
556 return;
557 FLUSH_VERTICES(ctx, _NEW_EVAL);
558 ctx->Eval.Map1Vertex4 = state;
559 break;
560 case GL_MAP2_COLOR_4:
561 if (ctx->API != API_OPENGL_COMPAT)
562 goto invalid_enum_error;
563 if (ctx->Eval.Map2Color4 == state)
564 return;
565 FLUSH_VERTICES(ctx, _NEW_EVAL);
566 ctx->Eval.Map2Color4 = state;
567 break;
568 case GL_MAP2_INDEX:
569 if (ctx->API != API_OPENGL_COMPAT)
570 goto invalid_enum_error;
571 if (ctx->Eval.Map2Index == state)
572 return;
573 FLUSH_VERTICES(ctx, _NEW_EVAL);
574 ctx->Eval.Map2Index = state;
575 break;
576 case GL_MAP2_NORMAL:
577 if (ctx->API != API_OPENGL_COMPAT)
578 goto invalid_enum_error;
579 if (ctx->Eval.Map2Normal == state)
580 return;
581 FLUSH_VERTICES(ctx, _NEW_EVAL);
582 ctx->Eval.Map2Normal = state;
583 break;
584 case GL_MAP2_TEXTURE_COORD_1:
585 if (ctx->API != API_OPENGL_COMPAT)
586 goto invalid_enum_error;
587 if (ctx->Eval.Map2TextureCoord1 == state)
588 return;
589 FLUSH_VERTICES(ctx, _NEW_EVAL);
590 ctx->Eval.Map2TextureCoord1 = state;
591 break;
592 case GL_MAP2_TEXTURE_COORD_2:
593 if (ctx->API != API_OPENGL_COMPAT)
594 goto invalid_enum_error;
595 if (ctx->Eval.Map2TextureCoord2 == state)
596 return;
597 FLUSH_VERTICES(ctx, _NEW_EVAL);
598 ctx->Eval.Map2TextureCoord2 = state;
599 break;
600 case GL_MAP2_TEXTURE_COORD_3:
601 if (ctx->API != API_OPENGL_COMPAT)
602 goto invalid_enum_error;
603 if (ctx->Eval.Map2TextureCoord3 == state)
604 return;
605 FLUSH_VERTICES(ctx, _NEW_EVAL);
606 ctx->Eval.Map2TextureCoord3 = state;
607 break;
608 case GL_MAP2_TEXTURE_COORD_4:
609 if (ctx->API != API_OPENGL_COMPAT)
610 goto invalid_enum_error;
611 if (ctx->Eval.Map2TextureCoord4 == state)
612 return;
613 FLUSH_VERTICES(ctx, _NEW_EVAL);
614 ctx->Eval.Map2TextureCoord4 = state;
615 break;
616 case GL_MAP2_VERTEX_3:
617 if (ctx->API != API_OPENGL_COMPAT)
618 goto invalid_enum_error;
619 if (ctx->Eval.Map2Vertex3 == state)
620 return;
621 FLUSH_VERTICES(ctx, _NEW_EVAL);
622 ctx->Eval.Map2Vertex3 = state;
623 break;
624 case GL_MAP2_VERTEX_4:
625 if (ctx->API != API_OPENGL_COMPAT)
626 goto invalid_enum_error;
627 if (ctx->Eval.Map2Vertex4 == state)
628 return;
629 FLUSH_VERTICES(ctx, _NEW_EVAL);
630 ctx->Eval.Map2Vertex4 = state;
631 break;
632 case GL_NORMALIZE:
633 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
634 goto invalid_enum_error;
635 if (ctx->Transform.Normalize == state)
636 return;
637 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
638 ctx->Transform.Normalize = state;
639 break;
640 case GL_POINT_SMOOTH:
641 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
642 goto invalid_enum_error;
643 if (ctx->Point.SmoothFlag == state)
644 return;
645 FLUSH_VERTICES(ctx, _NEW_POINT);
646 ctx->Point.SmoothFlag = state;
647 break;
648 case GL_POLYGON_SMOOTH:
649 if (!_mesa_is_desktop_gl(ctx))
650 goto invalid_enum_error;
651 if (ctx->Polygon.SmoothFlag == state)
652 return;
653 FLUSH_VERTICES(ctx, _NEW_POLYGON);
654 ctx->Polygon.SmoothFlag = state;
655 break;
656 case GL_POLYGON_STIPPLE:
657 if (ctx->API != API_OPENGL_COMPAT)
658 goto invalid_enum_error;
659 if (ctx->Polygon.StippleFlag == state)
660 return;
661 FLUSH_VERTICES(ctx, _NEW_POLYGON);
662 ctx->Polygon.StippleFlag = state;
663 break;
664 case GL_POLYGON_OFFSET_POINT:
665 if (!_mesa_is_desktop_gl(ctx))
666 goto invalid_enum_error;
667 if (ctx->Polygon.OffsetPoint == state)
668 return;
669 FLUSH_VERTICES(ctx, _NEW_POLYGON);
670 ctx->Polygon.OffsetPoint = state;
671 break;
672 case GL_POLYGON_OFFSET_LINE:
673 if (!_mesa_is_desktop_gl(ctx))
674 goto invalid_enum_error;
675 if (ctx->Polygon.OffsetLine == state)
676 return;
677 FLUSH_VERTICES(ctx, _NEW_POLYGON);
678 ctx->Polygon.OffsetLine = state;
679 break;
680 case GL_POLYGON_OFFSET_FILL:
681 if (ctx->Polygon.OffsetFill == state)
682 return;
683 FLUSH_VERTICES(ctx, _NEW_POLYGON);
684 ctx->Polygon.OffsetFill = state;
685 break;
686 case GL_RESCALE_NORMAL_EXT:
687 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
688 goto invalid_enum_error;
689 if (ctx->Transform.RescaleNormals == state)
690 return;
691 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
692 ctx->Transform.RescaleNormals = state;
693 break;
694 case GL_SCISSOR_TEST:
695 {
696 /* Must expand glEnable to all scissors */
697 GLbitfield newEnabled =
698 state * ((1 << ctx->Const.MaxViewports) - 1);
699 if (newEnabled != ctx->Scissor.EnableFlags) {
700 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewScissorTest ? 0 :
701 _NEW_SCISSOR);
702 ctx->NewDriverState |= ctx->DriverFlags.NewScissorTest;
703 ctx->Scissor.EnableFlags = newEnabled;
704 }
705 }
706 break;
707 case GL_STENCIL_TEST:
708 if (ctx->Stencil.Enabled == state)
709 return;
710 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewStencil ? 0 : _NEW_STENCIL);
711 ctx->NewDriverState |= ctx->DriverFlags.NewStencil;
712 ctx->Stencil.Enabled = state;
713 break;
714 case GL_TEXTURE_1D:
715 if (ctx->API != API_OPENGL_COMPAT)
716 goto invalid_enum_error;
717 if (!enable_texture(ctx, state, TEXTURE_1D_BIT)) {
718 return;
719 }
720 break;
721 case GL_TEXTURE_2D:
722 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
723 goto invalid_enum_error;
724 if (!enable_texture(ctx, state, TEXTURE_2D_BIT)) {
725 return;
726 }
727 break;
728 case GL_TEXTURE_3D:
729 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
730 goto invalid_enum_error;
731 if (!enable_texture(ctx, state, TEXTURE_3D_BIT)) {
732 return;
733 }
734 break;
735 case GL_TEXTURE_GEN_S:
736 case GL_TEXTURE_GEN_T:
737 case GL_TEXTURE_GEN_R:
738 case GL_TEXTURE_GEN_Q:
739 {
740 struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
741
742 if (ctx->API != API_OPENGL_COMPAT)
743 goto invalid_enum_error;
744
745 if (texUnit) {
746 GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
747 GLbitfield newenabled = texUnit->TexGenEnabled & ~coordBit;
748 if (state)
749 newenabled |= coordBit;
750 if (texUnit->TexGenEnabled == newenabled)
751 return;
752 FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);
753 texUnit->TexGenEnabled = newenabled;
754 }
755 }
756 break;
757
758 case GL_TEXTURE_GEN_STR_OES:
759 /* disable S, T, and R at the same time */
760 {
761 struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
762
763 if (ctx->API != API_OPENGLES)
764 goto invalid_enum_error;
765
766 if (texUnit) {
767 GLuint newenabled =
768 texUnit->TexGenEnabled & ~STR_BITS;
769 if (state)
770 newenabled |= STR_BITS;
771 if (texUnit->TexGenEnabled == newenabled)
772 return;
773 FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);
774 texUnit->TexGenEnabled = newenabled;
775 }
776 }
777 break;
778
779 /* client-side state */
780 case GL_VERTEX_ARRAY:
781 case GL_NORMAL_ARRAY:
782 case GL_COLOR_ARRAY:
783 case GL_TEXTURE_COORD_ARRAY:
784 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
785 goto invalid_enum_error;
786 client_state( ctx, cap, state );
787 return;
788 case GL_INDEX_ARRAY:
789 case GL_EDGE_FLAG_ARRAY:
790 case GL_FOG_COORDINATE_ARRAY_EXT:
791 case GL_SECONDARY_COLOR_ARRAY_EXT:
792 if (ctx->API != API_OPENGL_COMPAT)
793 goto invalid_enum_error;
794 client_state( ctx, cap, state );
795 return;
796 case GL_POINT_SIZE_ARRAY_OES:
797 if (ctx->API != API_OPENGLES)
798 goto invalid_enum_error;
799 client_state( ctx, cap, state );
800 return;
801
802 /* GL_ARB_texture_cube_map */
803 case GL_TEXTURE_CUBE_MAP:
804 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
805 goto invalid_enum_error;
806 CHECK_EXTENSION(ARB_texture_cube_map, cap);
807 if (!enable_texture(ctx, state, TEXTURE_CUBE_BIT)) {
808 return;
809 }
810 break;
811
812 /* GL_EXT_secondary_color */
813 case GL_COLOR_SUM_EXT:
814 if (ctx->API != API_OPENGL_COMPAT)
815 goto invalid_enum_error;
816 if (ctx->Fog.ColorSumEnabled == state)
817 return;
818 FLUSH_VERTICES(ctx, _NEW_FOG);
819 ctx->Fog.ColorSumEnabled = state;
820 break;
821
822 /* GL_ARB_multisample */
823 case GL_MULTISAMPLE_ARB:
824 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
825 goto invalid_enum_error;
826 _mesa_set_multisample(ctx, state);
827 return;
828 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
829 if (ctx->Multisample.SampleAlphaToCoverage == state)
830 return;
831 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleAlphaToXEnable ? 0 :
832 _NEW_MULTISAMPLE);
833 ctx->NewDriverState |= ctx->DriverFlags.NewSampleAlphaToXEnable;
834 ctx->Multisample.SampleAlphaToCoverage = state;
835 break;
836 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
837 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
838 goto invalid_enum_error;
839 if (ctx->Multisample.SampleAlphaToOne == state)
840 return;
841 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleAlphaToXEnable ? 0 :
842 _NEW_MULTISAMPLE);
843 ctx->NewDriverState |= ctx->DriverFlags.NewSampleAlphaToXEnable;
844 ctx->Multisample.SampleAlphaToOne = state;
845 break;
846 case GL_SAMPLE_COVERAGE_ARB:
847 if (ctx->Multisample.SampleCoverage == state)
848 return;
849 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleMask ? 0 :
850 _NEW_MULTISAMPLE);
851 ctx->NewDriverState |= ctx->DriverFlags.NewSampleMask;
852 ctx->Multisample.SampleCoverage = state;
853 break;
854 case GL_SAMPLE_COVERAGE_INVERT_ARB:
855 if (!_mesa_is_desktop_gl(ctx))
856 goto invalid_enum_error;
857 if (ctx->Multisample.SampleCoverageInvert == state)
858 return;
859 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleMask ? 0 :
860 _NEW_MULTISAMPLE);
861 ctx->NewDriverState |= ctx->DriverFlags.NewSampleMask;
862 ctx->Multisample.SampleCoverageInvert = state;
863 break;
864
865 /* GL_ARB_sample_shading */
866 case GL_SAMPLE_SHADING:
867 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
868 goto invalid_enum_error;
869 CHECK_EXTENSION(ARB_sample_shading, cap);
870 if (ctx->Multisample.SampleShading == state)
871 return;
872 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleShading ? 0 :
873 _NEW_MULTISAMPLE);
874 ctx->NewDriverState |= ctx->DriverFlags.NewSampleShading;
875 ctx->Multisample.SampleShading = state;
876 break;
877
878 /* GL_IBM_rasterpos_clip */
879 case GL_RASTER_POSITION_UNCLIPPED_IBM:
880 if (ctx->API != API_OPENGL_COMPAT)
881 goto invalid_enum_error;
882 if (ctx->Transform.RasterPositionUnclipped == state)
883 return;
884 FLUSH_VERTICES(ctx, 0);
885 ctx->Transform.RasterPositionUnclipped = state;
886 break;
887
888 /* GL_NV_point_sprite */
889 case GL_POINT_SPRITE_NV:
890 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
891 goto invalid_enum_error;
892 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite, cap);
893 if (ctx->Point.PointSprite == state)
894 return;
895 FLUSH_VERTICES(ctx, _NEW_POINT);
896 ctx->Point.PointSprite = state;
897 break;
898
899 case GL_VERTEX_PROGRAM_ARB:
900 if (ctx->API != API_OPENGL_COMPAT)
901 goto invalid_enum_error;
902 CHECK_EXTENSION(ARB_vertex_program, cap);
903 if (ctx->VertexProgram.Enabled == state)
904 return;
905 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
906 ctx->VertexProgram.Enabled = state;
907 break;
908 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
909 /* This was added with ARB_vertex_program, but it is also used with
910 * GLSL vertex shaders on desktop.
911 */
912 if (!_mesa_is_desktop_gl(ctx))
913 goto invalid_enum_error;
914 CHECK_EXTENSION(ARB_vertex_program, cap);
915 if (ctx->VertexProgram.PointSizeEnabled == state)
916 return;
917 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
918 ctx->VertexProgram.PointSizeEnabled = state;
919 break;
920 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
921 if (ctx->API != API_OPENGL_COMPAT)
922 goto invalid_enum_error;
923 CHECK_EXTENSION(ARB_vertex_program, cap);
924 if (ctx->VertexProgram.TwoSideEnabled == state)
925 return;
926 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
927 ctx->VertexProgram.TwoSideEnabled = state;
928 break;
929
930 /* GL_NV_texture_rectangle */
931 case GL_TEXTURE_RECTANGLE_NV:
932 if (ctx->API != API_OPENGL_COMPAT)
933 goto invalid_enum_error;
934 CHECK_EXTENSION(NV_texture_rectangle, cap);
935 if (!enable_texture(ctx, state, TEXTURE_RECT_BIT)) {
936 return;
937 }
938 break;
939
940 /* GL_EXT_stencil_two_side */
941 case GL_STENCIL_TEST_TWO_SIDE_EXT:
942 if (ctx->API != API_OPENGL_COMPAT)
943 goto invalid_enum_error;
944 CHECK_EXTENSION(EXT_stencil_two_side, cap);
945 if (ctx->Stencil.TestTwoSide == state)
946 return;
947 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewStencil ? 0 : _NEW_STENCIL);
948 ctx->NewDriverState |= ctx->DriverFlags.NewStencil;
949 ctx->Stencil.TestTwoSide = state;
950 if (state) {
951 ctx->Stencil._BackFace = 2;
952 } else {
953 ctx->Stencil._BackFace = 1;
954 }
955 break;
956
957 case GL_FRAGMENT_PROGRAM_ARB:
958 if (ctx->API != API_OPENGL_COMPAT)
959 goto invalid_enum_error;
960 CHECK_EXTENSION(ARB_fragment_program, cap);
961 if (ctx->FragmentProgram.Enabled == state)
962 return;
963 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
964 ctx->FragmentProgram.Enabled = state;
965 break;
966
967 /* GL_EXT_depth_bounds_test */
968 case GL_DEPTH_BOUNDS_TEST_EXT:
969 if (!_mesa_is_desktop_gl(ctx))
970 goto invalid_enum_error;
971 CHECK_EXTENSION(EXT_depth_bounds_test, cap);
972 if (ctx->Depth.BoundsTest == state)
973 return;
974 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepth ? 0 : _NEW_DEPTH);
975 ctx->NewDriverState |= ctx->DriverFlags.NewDepth;
976 ctx->Depth.BoundsTest = state;
977 break;
978
979 case GL_DEPTH_CLAMP:
980 if (!_mesa_is_desktop_gl(ctx))
981 goto invalid_enum_error;
982 CHECK_EXTENSION(ARB_depth_clamp, cap);
983 if (ctx->Transform.DepthClamp == state)
984 return;
985 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepthClamp ? 0 :
986 _NEW_TRANSFORM);
987 ctx->NewDriverState |= ctx->DriverFlags.NewDepthClamp;
988 ctx->Transform.DepthClamp = state;
989 break;
990
991 case GL_FRAGMENT_SHADER_ATI:
992 if (ctx->API != API_OPENGL_COMPAT)
993 goto invalid_enum_error;
994 CHECK_EXTENSION(ATI_fragment_shader, cap);
995 if (ctx->ATIFragmentShader.Enabled == state)
996 return;
997 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
998 ctx->ATIFragmentShader.Enabled = state;
999 break;
1000
1001 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1002 if (!_mesa_is_desktop_gl(ctx))
1003 goto invalid_enum_error;
1004 CHECK_EXTENSION(ARB_seamless_cube_map, cap);
1005 if (ctx->Texture.CubeMapSeamless != state) {
1006 FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT);
1007 ctx->Texture.CubeMapSeamless = state;
1008 }
1009 break;
1010
1011 case GL_RASTERIZER_DISCARD:
1012 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1013 goto invalid_enum_error;
1014 CHECK_EXTENSION(EXT_transform_feedback, cap);
1015 if (ctx->RasterDiscard != state) {
1016 FLUSH_VERTICES(ctx, 0);
1017 ctx->NewDriverState |= ctx->DriverFlags.NewRasterizerDiscard;
1018 ctx->RasterDiscard = state;
1019 }
1020 break;
1021
1022 /* GL 3.1 primitive restart. Note: this enum is different from
1023 * GL_PRIMITIVE_RESTART_NV (which is client state).
1024 */
1025 case GL_PRIMITIVE_RESTART:
1026 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
1027 goto invalid_enum_error;
1028 }
1029 if (ctx->Array.PrimitiveRestart != state) {
1030 FLUSH_VERTICES(ctx, 0);
1031 ctx->Array.PrimitiveRestart = state;
1032 update_derived_primitive_restart_state(ctx);
1033 }
1034 break;
1035
1036 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
1037 if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility)
1038 goto invalid_enum_error;
1039 if (ctx->Array.PrimitiveRestartFixedIndex != state) {
1040 FLUSH_VERTICES(ctx, 0);
1041 ctx->Array.PrimitiveRestartFixedIndex = state;
1042 update_derived_primitive_restart_state(ctx);
1043 }
1044 break;
1045
1046 /* GL3.0 - GL_framebuffer_sRGB */
1047 case GL_FRAMEBUFFER_SRGB_EXT:
1048 if (!_mesa_is_desktop_gl(ctx))
1049 goto invalid_enum_error;
1050 CHECK_EXTENSION(EXT_framebuffer_sRGB, cap);
1051 _mesa_set_framebuffer_srgb(ctx, state);
1052 return;
1053
1054 /* GL_OES_EGL_image_external */
1055 case GL_TEXTURE_EXTERNAL_OES:
1056 if (!_mesa_is_gles(ctx))
1057 goto invalid_enum_error;
1058 CHECK_EXTENSION(OES_EGL_image_external, cap);
1059 if (!enable_texture(ctx, state, TEXTURE_EXTERNAL_BIT)) {
1060 return;
1061 }
1062 break;
1063
1064 /* ARB_texture_multisample */
1065 case GL_SAMPLE_MASK:
1066 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
1067 goto invalid_enum_error;
1068 CHECK_EXTENSION(ARB_texture_multisample, cap);
1069 if (ctx->Multisample.SampleMask == state)
1070 return;
1071 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleMask ? 0 :
1072 _NEW_MULTISAMPLE);
1073 ctx->NewDriverState |= ctx->DriverFlags.NewSampleMask;
1074 ctx->Multisample.SampleMask = state;
1075 break;
1076
1077 case GL_BLEND_ADVANCED_COHERENT_KHR:
1078 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent, cap);
1079 if (ctx->Color.BlendCoherent == state)
1080 return;
1081 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewBlend ? 0 : _NEW_COLOR);
1082 ctx->NewDriverState |= ctx->DriverFlags.NewBlend;
1083 ctx->Color.BlendCoherent = state;
1084 break;
1085
1086 default:
1087 goto invalid_enum_error;
1088 }
1089
1090 if (ctx->Driver.Enable) {
1091 ctx->Driver.Enable( ctx, cap, state );
1092 }
1093
1094 return;
1095
1096 invalid_enum_error:
1097 _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(%s)",
1098 state ? "Enable" : "Disable", _mesa_enum_to_string(cap));
1099 }
1100
1101
1102 /**
1103 * Enable GL capability. Called by glEnable()
1104 * \param cap state to enable.
1105 */
1106 void GLAPIENTRY
1107 _mesa_Enable( GLenum cap )
1108 {
1109 GET_CURRENT_CONTEXT(ctx);
1110
1111 _mesa_set_enable( ctx, cap, GL_TRUE );
1112 }
1113
1114
1115 /**
1116 * Disable GL capability. Called by glDisable()
1117 * \param cap state to disable.
1118 */
1119 void GLAPIENTRY
1120 _mesa_Disable( GLenum cap )
1121 {
1122 GET_CURRENT_CONTEXT(ctx);
1123
1124 _mesa_set_enable( ctx, cap, GL_FALSE );
1125 }
1126
1127
1128
1129 /**
1130 * Enable/disable an indexed state var.
1131 */
1132 void
1133 _mesa_set_enablei(struct gl_context *ctx, GLenum cap,
1134 GLuint index, GLboolean state)
1135 {
1136 assert(state == 0 || state == 1);
1137 switch (cap) {
1138 case GL_BLEND:
1139 if (!ctx->Extensions.EXT_draw_buffers2) {
1140 goto invalid_enum_error;
1141 }
1142 if (index >= ctx->Const.MaxDrawBuffers) {
1143 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1144 state ? "glEnableIndexed" : "glDisableIndexed", index);
1145 return;
1146 }
1147 if (((ctx->Color.BlendEnabled >> index) & 1) != state) {
1148 _mesa_flush_vertices_for_blend_state(ctx);
1149 if (state)
1150 ctx->Color.BlendEnabled |= (1 << index);
1151 else
1152 ctx->Color.BlendEnabled &= ~(1 << index);
1153 }
1154 break;
1155 case GL_SCISSOR_TEST:
1156 if (index >= ctx->Const.MaxViewports) {
1157 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1158 state ? "glEnablei" : "glDisablei", index);
1159 return;
1160 }
1161 if (((ctx->Scissor.EnableFlags >> index) & 1) != state) {
1162 FLUSH_VERTICES(ctx,
1163 ctx->DriverFlags.NewScissorTest ? 0 : _NEW_SCISSOR);
1164 ctx->NewDriverState |= ctx->DriverFlags.NewScissorTest;
1165 if (state)
1166 ctx->Scissor.EnableFlags |= (1 << index);
1167 else
1168 ctx->Scissor.EnableFlags &= ~(1 << index);
1169 }
1170 break;
1171 default:
1172 goto invalid_enum_error;
1173 }
1174 return;
1175
1176 invalid_enum_error:
1177 _mesa_error(ctx, GL_INVALID_ENUM, "%s(cap=%s)",
1178 state ? "glEnablei" : "glDisablei",
1179 _mesa_enum_to_string(cap));
1180 }
1181
1182
1183 void GLAPIENTRY
1184 _mesa_Disablei( GLenum cap, GLuint index )
1185 {
1186 GET_CURRENT_CONTEXT(ctx);
1187 _mesa_set_enablei(ctx, cap, index, GL_FALSE);
1188 }
1189
1190
1191 void GLAPIENTRY
1192 _mesa_Enablei( GLenum cap, GLuint index )
1193 {
1194 GET_CURRENT_CONTEXT(ctx);
1195 _mesa_set_enablei(ctx, cap, index, GL_TRUE);
1196 }
1197
1198
1199 GLboolean GLAPIENTRY
1200 _mesa_IsEnabledi( GLenum cap, GLuint index )
1201 {
1202 GET_CURRENT_CONTEXT(ctx);
1203 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1204 switch (cap) {
1205 case GL_BLEND:
1206 if (index >= ctx->Const.MaxDrawBuffers) {
1207 _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
1208 index);
1209 return GL_FALSE;
1210 }
1211 return (ctx->Color.BlendEnabled >> index) & 1;
1212 case GL_SCISSOR_TEST:
1213 if (index >= ctx->Const.MaxViewports) {
1214 _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
1215 index);
1216 return GL_FALSE;
1217 }
1218 return (ctx->Scissor.EnableFlags >> index) & 1;
1219 default:
1220 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabledIndexed(cap=%s)",
1221 _mesa_enum_to_string(cap));
1222 return GL_FALSE;
1223 }
1224 }
1225
1226
1227
1228
1229 #undef CHECK_EXTENSION
1230 #define CHECK_EXTENSION(EXTNAME) \
1231 if (!ctx->Extensions.EXTNAME) { \
1232 goto invalid_enum_error; \
1233 }
1234
1235 #undef CHECK_EXTENSION2
1236 #define CHECK_EXTENSION2(EXT1, EXT2) \
1237 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1238 goto invalid_enum_error; \
1239 }
1240
1241
1242 /**
1243 * Helper function to determine whether a texture target is enabled.
1244 */
1245 static GLboolean
1246 is_texture_enabled(struct gl_context *ctx, GLbitfield bit)
1247 {
1248 const struct gl_texture_unit *const texUnit =
1249 &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1250 return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE;
1251 }
1252
1253
1254 /**
1255 * Return simple enable/disable state.
1256 *
1257 * \param cap state variable to query.
1258 *
1259 * Returns the state of the specified capability from the current GL context.
1260 * For the capabilities associated with extensions verifies that those
1261 * extensions are effectively present before reporting.
1262 */
1263 GLboolean GLAPIENTRY
1264 _mesa_IsEnabled( GLenum cap )
1265 {
1266 GET_CURRENT_CONTEXT(ctx);
1267 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1268
1269 switch (cap) {
1270 case GL_ALPHA_TEST:
1271 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1272 goto invalid_enum_error;
1273 return ctx->Color.AlphaEnabled;
1274 case GL_AUTO_NORMAL:
1275 if (ctx->API != API_OPENGL_COMPAT)
1276 goto invalid_enum_error;
1277 return ctx->Eval.AutoNormal;
1278 case GL_BLEND:
1279 return ctx->Color.BlendEnabled & 1; /* return state for buffer[0] */
1280 case GL_CLIP_DISTANCE0: /* aka GL_CLIP_PLANE0 */
1281 case GL_CLIP_DISTANCE1:
1282 case GL_CLIP_DISTANCE2:
1283 case GL_CLIP_DISTANCE3:
1284 case GL_CLIP_DISTANCE4:
1285 case GL_CLIP_DISTANCE5:
1286 case GL_CLIP_DISTANCE6:
1287 case GL_CLIP_DISTANCE7: {
1288 const GLuint p = cap - GL_CLIP_DISTANCE0;
1289
1290 if (p >= ctx->Const.MaxClipPlanes)
1291 goto invalid_enum_error;
1292
1293 return (ctx->Transform.ClipPlanesEnabled >> p) & 1;
1294 }
1295 case GL_COLOR_MATERIAL:
1296 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1297 goto invalid_enum_error;
1298 return ctx->Light.ColorMaterialEnabled;
1299 case GL_CULL_FACE:
1300 return ctx->Polygon.CullFlag;
1301 case GL_DEBUG_OUTPUT:
1302 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB:
1303 return (GLboolean) _mesa_get_debug_state_int(ctx, cap);
1304 case GL_DEPTH_TEST:
1305 return ctx->Depth.Test;
1306 case GL_DITHER:
1307 return ctx->Color.DitherFlag;
1308 case GL_FOG:
1309 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1310 goto invalid_enum_error;
1311 return ctx->Fog.Enabled;
1312 case GL_LIGHTING:
1313 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1314 goto invalid_enum_error;
1315 return ctx->Light.Enabled;
1316 case GL_LIGHT0:
1317 case GL_LIGHT1:
1318 case GL_LIGHT2:
1319 case GL_LIGHT3:
1320 case GL_LIGHT4:
1321 case GL_LIGHT5:
1322 case GL_LIGHT6:
1323 case GL_LIGHT7:
1324 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1325 goto invalid_enum_error;
1326 return ctx->Light.Light[cap-GL_LIGHT0].Enabled;
1327 case GL_LINE_SMOOTH:
1328 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1329 goto invalid_enum_error;
1330 return ctx->Line.SmoothFlag;
1331 case GL_LINE_STIPPLE:
1332 if (ctx->API != API_OPENGL_COMPAT)
1333 goto invalid_enum_error;
1334 return ctx->Line.StippleFlag;
1335 case GL_INDEX_LOGIC_OP:
1336 if (ctx->API != API_OPENGL_COMPAT)
1337 goto invalid_enum_error;
1338 return ctx->Color.IndexLogicOpEnabled;
1339 case GL_COLOR_LOGIC_OP:
1340 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1341 goto invalid_enum_error;
1342 return ctx->Color.ColorLogicOpEnabled;
1343 case GL_MAP1_COLOR_4:
1344 if (ctx->API != API_OPENGL_COMPAT)
1345 goto invalid_enum_error;
1346 return ctx->Eval.Map1Color4;
1347 case GL_MAP1_INDEX:
1348 if (ctx->API != API_OPENGL_COMPAT)
1349 goto invalid_enum_error;
1350 return ctx->Eval.Map1Index;
1351 case GL_MAP1_NORMAL:
1352 if (ctx->API != API_OPENGL_COMPAT)
1353 goto invalid_enum_error;
1354 return ctx->Eval.Map1Normal;
1355 case GL_MAP1_TEXTURE_COORD_1:
1356 if (ctx->API != API_OPENGL_COMPAT)
1357 goto invalid_enum_error;
1358 return ctx->Eval.Map1TextureCoord1;
1359 case GL_MAP1_TEXTURE_COORD_2:
1360 if (ctx->API != API_OPENGL_COMPAT)
1361 goto invalid_enum_error;
1362 return ctx->Eval.Map1TextureCoord2;
1363 case GL_MAP1_TEXTURE_COORD_3:
1364 if (ctx->API != API_OPENGL_COMPAT)
1365 goto invalid_enum_error;
1366 return ctx->Eval.Map1TextureCoord3;
1367 case GL_MAP1_TEXTURE_COORD_4:
1368 if (ctx->API != API_OPENGL_COMPAT)
1369 goto invalid_enum_error;
1370 return ctx->Eval.Map1TextureCoord4;
1371 case GL_MAP1_VERTEX_3:
1372 if (ctx->API != API_OPENGL_COMPAT)
1373 goto invalid_enum_error;
1374 return ctx->Eval.Map1Vertex3;
1375 case GL_MAP1_VERTEX_4:
1376 if (ctx->API != API_OPENGL_COMPAT)
1377 goto invalid_enum_error;
1378 return ctx->Eval.Map1Vertex4;
1379 case GL_MAP2_COLOR_4:
1380 if (ctx->API != API_OPENGL_COMPAT)
1381 goto invalid_enum_error;
1382 return ctx->Eval.Map2Color4;
1383 case GL_MAP2_INDEX:
1384 if (ctx->API != API_OPENGL_COMPAT)
1385 goto invalid_enum_error;
1386 return ctx->Eval.Map2Index;
1387 case GL_MAP2_NORMAL:
1388 if (ctx->API != API_OPENGL_COMPAT)
1389 goto invalid_enum_error;
1390 return ctx->Eval.Map2Normal;
1391 case GL_MAP2_TEXTURE_COORD_1:
1392 if (ctx->API != API_OPENGL_COMPAT)
1393 goto invalid_enum_error;
1394 return ctx->Eval.Map2TextureCoord1;
1395 case GL_MAP2_TEXTURE_COORD_2:
1396 if (ctx->API != API_OPENGL_COMPAT)
1397 goto invalid_enum_error;
1398 return ctx->Eval.Map2TextureCoord2;
1399 case GL_MAP2_TEXTURE_COORD_3:
1400 if (ctx->API != API_OPENGL_COMPAT)
1401 goto invalid_enum_error;
1402 return ctx->Eval.Map2TextureCoord3;
1403 case GL_MAP2_TEXTURE_COORD_4:
1404 if (ctx->API != API_OPENGL_COMPAT)
1405 goto invalid_enum_error;
1406 return ctx->Eval.Map2TextureCoord4;
1407 case GL_MAP2_VERTEX_3:
1408 if (ctx->API != API_OPENGL_COMPAT)
1409 goto invalid_enum_error;
1410 return ctx->Eval.Map2Vertex3;
1411 case GL_MAP2_VERTEX_4:
1412 if (ctx->API != API_OPENGL_COMPAT)
1413 goto invalid_enum_error;
1414 return ctx->Eval.Map2Vertex4;
1415 case GL_NORMALIZE:
1416 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1417 goto invalid_enum_error;
1418 return ctx->Transform.Normalize;
1419 case GL_POINT_SMOOTH:
1420 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1421 goto invalid_enum_error;
1422 return ctx->Point.SmoothFlag;
1423 case GL_POLYGON_SMOOTH:
1424 if (!_mesa_is_desktop_gl(ctx))
1425 goto invalid_enum_error;
1426 return ctx->Polygon.SmoothFlag;
1427 case GL_POLYGON_STIPPLE:
1428 if (ctx->API != API_OPENGL_COMPAT)
1429 goto invalid_enum_error;
1430 return ctx->Polygon.StippleFlag;
1431 case GL_POLYGON_OFFSET_POINT:
1432 if (!_mesa_is_desktop_gl(ctx))
1433 goto invalid_enum_error;
1434 return ctx->Polygon.OffsetPoint;
1435 case GL_POLYGON_OFFSET_LINE:
1436 if (!_mesa_is_desktop_gl(ctx))
1437 goto invalid_enum_error;
1438 return ctx->Polygon.OffsetLine;
1439 case GL_POLYGON_OFFSET_FILL:
1440 return ctx->Polygon.OffsetFill;
1441 case GL_RESCALE_NORMAL_EXT:
1442 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1443 goto invalid_enum_error;
1444 return ctx->Transform.RescaleNormals;
1445 case GL_SCISSOR_TEST:
1446 return ctx->Scissor.EnableFlags & 1; /* return state for index 0 */
1447 case GL_STENCIL_TEST:
1448 return ctx->Stencil.Enabled;
1449 case GL_TEXTURE_1D:
1450 if (ctx->API != API_OPENGL_COMPAT)
1451 goto invalid_enum_error;
1452 return is_texture_enabled(ctx, TEXTURE_1D_BIT);
1453 case GL_TEXTURE_2D:
1454 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1455 goto invalid_enum_error;
1456 return is_texture_enabled(ctx, TEXTURE_2D_BIT);
1457 case GL_TEXTURE_3D:
1458 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1459 goto invalid_enum_error;
1460 return is_texture_enabled(ctx, TEXTURE_3D_BIT);
1461 case GL_TEXTURE_GEN_S:
1462 case GL_TEXTURE_GEN_T:
1463 case GL_TEXTURE_GEN_R:
1464 case GL_TEXTURE_GEN_Q:
1465 {
1466 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1467
1468 if (ctx->API != API_OPENGL_COMPAT)
1469 goto invalid_enum_error;
1470
1471 if (texUnit) {
1472 GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
1473 return (texUnit->TexGenEnabled & coordBit) ? GL_TRUE : GL_FALSE;
1474 }
1475 }
1476 return GL_FALSE;
1477 case GL_TEXTURE_GEN_STR_OES:
1478 {
1479 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1480
1481 if (ctx->API != API_OPENGLES)
1482 goto invalid_enum_error;
1483
1484 if (texUnit) {
1485 return (texUnit->TexGenEnabled & STR_BITS) == STR_BITS
1486 ? GL_TRUE : GL_FALSE;
1487 }
1488 }
1489
1490 /* client-side state */
1491 case GL_VERTEX_ARRAY:
1492 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1493 goto invalid_enum_error;
1494 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POS].Enabled;
1495 case GL_NORMAL_ARRAY:
1496 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1497 goto invalid_enum_error;
1498 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled;
1499 case GL_COLOR_ARRAY:
1500 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1501 goto invalid_enum_error;
1502 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled;
1503 case GL_INDEX_ARRAY:
1504 if (ctx->API != API_OPENGL_COMPAT)
1505 goto invalid_enum_error;
1506 return ctx->Array.VAO->
1507 VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled;
1508 case GL_TEXTURE_COORD_ARRAY:
1509 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1510 goto invalid_enum_error;
1511 return ctx->Array.VAO->
1512 VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Enabled;
1513 case GL_EDGE_FLAG_ARRAY:
1514 if (ctx->API != API_OPENGL_COMPAT)
1515 goto invalid_enum_error;
1516 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled;
1517 case GL_FOG_COORDINATE_ARRAY_EXT:
1518 if (ctx->API != API_OPENGL_COMPAT)
1519 goto invalid_enum_error;
1520 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_FOG].Enabled;
1521 case GL_SECONDARY_COLOR_ARRAY_EXT:
1522 if (ctx->API != API_OPENGL_COMPAT)
1523 goto invalid_enum_error;
1524 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled;
1525 case GL_POINT_SIZE_ARRAY_OES:
1526 if (ctx->API != API_OPENGLES)
1527 goto invalid_enum_error;
1528 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled;
1529
1530 /* GL_ARB_texture_cube_map */
1531 case GL_TEXTURE_CUBE_MAP:
1532 CHECK_EXTENSION(ARB_texture_cube_map);
1533 return is_texture_enabled(ctx, TEXTURE_CUBE_BIT);
1534
1535 /* GL_EXT_secondary_color */
1536 case GL_COLOR_SUM_EXT:
1537 if (ctx->API != API_OPENGL_COMPAT)
1538 goto invalid_enum_error;
1539 return ctx->Fog.ColorSumEnabled;
1540
1541 /* GL_ARB_multisample */
1542 case GL_MULTISAMPLE_ARB:
1543 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1544 goto invalid_enum_error;
1545 return ctx->Multisample.Enabled;
1546 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
1547 return ctx->Multisample.SampleAlphaToCoverage;
1548 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
1549 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1550 goto invalid_enum_error;
1551 return ctx->Multisample.SampleAlphaToOne;
1552 case GL_SAMPLE_COVERAGE_ARB:
1553 return ctx->Multisample.SampleCoverage;
1554 case GL_SAMPLE_COVERAGE_INVERT_ARB:
1555 if (!_mesa_is_desktop_gl(ctx))
1556 goto invalid_enum_error;
1557 return ctx->Multisample.SampleCoverageInvert;
1558
1559 /* GL_IBM_rasterpos_clip */
1560 case GL_RASTER_POSITION_UNCLIPPED_IBM:
1561 if (ctx->API != API_OPENGL_COMPAT)
1562 goto invalid_enum_error;
1563 return ctx->Transform.RasterPositionUnclipped;
1564
1565 /* GL_NV_point_sprite */
1566 case GL_POINT_SPRITE_NV:
1567 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1568 goto invalid_enum_error;
1569 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite)
1570 return ctx->Point.PointSprite;
1571
1572 case GL_VERTEX_PROGRAM_ARB:
1573 if (ctx->API != API_OPENGL_COMPAT)
1574 goto invalid_enum_error;
1575 CHECK_EXTENSION(ARB_vertex_program);
1576 return ctx->VertexProgram.Enabled;
1577 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
1578 /* This was added with ARB_vertex_program, but it is also used with
1579 * GLSL vertex shaders on desktop.
1580 */
1581 if (!_mesa_is_desktop_gl(ctx))
1582 goto invalid_enum_error;
1583 CHECK_EXTENSION(ARB_vertex_program);
1584 return ctx->VertexProgram.PointSizeEnabled;
1585 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
1586 if (ctx->API != API_OPENGL_COMPAT)
1587 goto invalid_enum_error;
1588 CHECK_EXTENSION(ARB_vertex_program);
1589 return ctx->VertexProgram.TwoSideEnabled;
1590
1591 /* GL_NV_texture_rectangle */
1592 case GL_TEXTURE_RECTANGLE_NV:
1593 if (ctx->API != API_OPENGL_COMPAT)
1594 goto invalid_enum_error;
1595 CHECK_EXTENSION(NV_texture_rectangle);
1596 return is_texture_enabled(ctx, TEXTURE_RECT_BIT);
1597
1598 /* GL_EXT_stencil_two_side */
1599 case GL_STENCIL_TEST_TWO_SIDE_EXT:
1600 if (ctx->API != API_OPENGL_COMPAT)
1601 goto invalid_enum_error;
1602 CHECK_EXTENSION(EXT_stencil_two_side);
1603 return ctx->Stencil.TestTwoSide;
1604
1605 case GL_FRAGMENT_PROGRAM_ARB:
1606 if (ctx->API != API_OPENGL_COMPAT)
1607 goto invalid_enum_error;
1608 return ctx->FragmentProgram.Enabled;
1609
1610 /* GL_EXT_depth_bounds_test */
1611 case GL_DEPTH_BOUNDS_TEST_EXT:
1612 if (!_mesa_is_desktop_gl(ctx))
1613 goto invalid_enum_error;
1614 CHECK_EXTENSION(EXT_depth_bounds_test);
1615 return ctx->Depth.BoundsTest;
1616
1617 /* GL_ARB_depth_clamp */
1618 case GL_DEPTH_CLAMP:
1619 if (!_mesa_is_desktop_gl(ctx))
1620 goto invalid_enum_error;
1621 CHECK_EXTENSION(ARB_depth_clamp);
1622 return ctx->Transform.DepthClamp;
1623
1624 case GL_FRAGMENT_SHADER_ATI:
1625 if (ctx->API != API_OPENGL_COMPAT)
1626 goto invalid_enum_error;
1627 CHECK_EXTENSION(ATI_fragment_shader);
1628 return ctx->ATIFragmentShader.Enabled;
1629
1630 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1631 if (!_mesa_is_desktop_gl(ctx))
1632 goto invalid_enum_error;
1633 CHECK_EXTENSION(ARB_seamless_cube_map);
1634 return ctx->Texture.CubeMapSeamless;
1635
1636 case GL_RASTERIZER_DISCARD:
1637 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1638 goto invalid_enum_error;
1639 CHECK_EXTENSION(EXT_transform_feedback);
1640 return ctx->RasterDiscard;
1641
1642 /* GL_NV_primitive_restart */
1643 case GL_PRIMITIVE_RESTART_NV:
1644 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.NV_primitive_restart) {
1645 goto invalid_enum_error;
1646 }
1647 return ctx->Array.PrimitiveRestart;
1648
1649 /* GL 3.1 primitive restart */
1650 case GL_PRIMITIVE_RESTART:
1651 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
1652 goto invalid_enum_error;
1653 }
1654 return ctx->Array.PrimitiveRestart;
1655
1656 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
1657 if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility) {
1658 goto invalid_enum_error;
1659 }
1660 return ctx->Array.PrimitiveRestartFixedIndex;
1661
1662 /* GL3.0 - GL_framebuffer_sRGB */
1663 case GL_FRAMEBUFFER_SRGB_EXT:
1664 if (!_mesa_is_desktop_gl(ctx))
1665 goto invalid_enum_error;
1666 CHECK_EXTENSION(EXT_framebuffer_sRGB);
1667 return ctx->Color.sRGBEnabled;
1668
1669 /* GL_OES_EGL_image_external */
1670 case GL_TEXTURE_EXTERNAL_OES:
1671 if (!_mesa_is_gles(ctx))
1672 goto invalid_enum_error;
1673 CHECK_EXTENSION(OES_EGL_image_external);
1674 return is_texture_enabled(ctx, TEXTURE_EXTERNAL_BIT);
1675
1676 /* ARB_texture_multisample */
1677 case GL_SAMPLE_MASK:
1678 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
1679 goto invalid_enum_error;
1680 CHECK_EXTENSION(ARB_texture_multisample);
1681 return ctx->Multisample.SampleMask;
1682
1683 /* ARB_sample_shading */
1684 case GL_SAMPLE_SHADING:
1685 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1686 goto invalid_enum_error;
1687 CHECK_EXTENSION(ARB_sample_shading);
1688 return ctx->Multisample.SampleShading;
1689
1690 case GL_BLEND_ADVANCED_COHERENT_KHR:
1691 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent);
1692 return ctx->Color.BlendCoherent;
1693
1694 case GL_CONSERVATIVE_RASTERIZATION_INTEL:
1695 CHECK_EXTENSION(INTEL_conservative_rasterization);
1696 return ctx->IntelConservativeRasterization;
1697
1698 default:
1699 goto invalid_enum_error;
1700 }
1701
1702 return GL_FALSE;
1703
1704 invalid_enum_error:
1705 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(%s)",
1706 _mesa_enum_to_string(cap));
1707 return GL_FALSE;
1708 }