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