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