mesa: remove _ARB suffix from cube map enums
[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 "util/simple_list.h"
39 #include "mtypes.h"
40 #include "enums.h"
41 #include "api_arrayelt.h"
42 #include "texstate.h"
43
44
45
46 #define CHECK_EXTENSION(EXTNAME, CAP) \
47 if (!ctx->Extensions.EXTNAME) { \
48 goto invalid_enum_error; \
49 }
50
51
52 static void
53 update_derived_primitive_restart_state(struct gl_context *ctx)
54 {
55 /* Update derived primitive restart state.
56 */
57 ctx->Array._PrimitiveRestart = ctx->Array.PrimitiveRestart
58 || ctx->Array.PrimitiveRestartFixedIndex;
59 }
60
61 /**
62 * Helper to enable/disable client-side state.
63 */
64 static void
65 client_state(struct gl_context *ctx, GLenum cap, GLboolean state)
66 {
67 struct gl_vertex_array_object *vao = ctx->Array.VAO;
68 GLbitfield64 flag;
69 GLboolean *var;
70
71 switch (cap) {
72 case GL_VERTEX_ARRAY:
73 var = &vao->VertexAttrib[VERT_ATTRIB_POS].Enabled;
74 flag = VERT_BIT_POS;
75 break;
76 case GL_NORMAL_ARRAY:
77 var = &vao->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled;
78 flag = VERT_BIT_NORMAL;
79 break;
80 case GL_COLOR_ARRAY:
81 var = &vao->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled;
82 flag = VERT_BIT_COLOR0;
83 break;
84 case GL_INDEX_ARRAY:
85 var = &vao->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled;
86 flag = VERT_BIT_COLOR_INDEX;
87 break;
88 case GL_TEXTURE_COORD_ARRAY:
89 var = &vao->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Enabled;
90 flag = VERT_BIT_TEX(ctx->Array.ActiveTexture);
91 break;
92 case GL_EDGE_FLAG_ARRAY:
93 var = &vao->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled;
94 flag = VERT_BIT_EDGEFLAG;
95 break;
96 case GL_FOG_COORDINATE_ARRAY_EXT:
97 var = &vao->VertexAttrib[VERT_ATTRIB_FOG].Enabled;
98 flag = VERT_BIT_FOG;
99 break;
100 case GL_SECONDARY_COLOR_ARRAY_EXT:
101 var = &vao->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled;
102 flag = VERT_BIT_COLOR1;
103 break;
104
105 case GL_POINT_SIZE_ARRAY_OES:
106 var = &vao->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled;
107 flag = VERT_BIT_POINT_SIZE;
108 break;
109
110 /* GL_NV_primitive_restart */
111 case GL_PRIMITIVE_RESTART_NV:
112 if (!ctx->Extensions.NV_primitive_restart) {
113 goto invalid_enum_error;
114 }
115 var = &ctx->Array.PrimitiveRestart;
116 flag = 0;
117 break;
118
119 default:
120 goto invalid_enum_error;
121 }
122
123 if (*var == state)
124 return;
125
126 FLUSH_VERTICES(ctx, _NEW_ARRAY);
127
128 _ae_invalidate_state(ctx, _NEW_ARRAY);
129
130 *var = state;
131
132 update_derived_primitive_restart_state(ctx);
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);
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 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
244 ctx->Multisample.Enabled = state;
245
246 if (ctx->Driver.Enable) {
247 ctx->Driver.Enable(ctx, GL_MULTISAMPLE, state);
248 }
249 }
250
251 /**
252 * Helper function to enable or disable GL_FRAMEBUFFER_SRGB, skipping the
253 * check for whether the API supports it (GLES doesn't).
254 */
255 void
256 _mesa_set_framebuffer_srgb(struct gl_context *ctx, GLboolean state)
257 {
258 if (ctx->Color.sRGBEnabled == state)
259 return;
260 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
261 ctx->Color.sRGBEnabled = state;
262
263 if (ctx->Driver.Enable) {
264 ctx->Driver.Enable(ctx, GL_FRAMEBUFFER_SRGB, state);
265 }
266 }
267
268 /**
269 * Helper function to enable or disable state.
270 *
271 * \param ctx GL context.
272 * \param cap the state to enable/disable
273 * \param state whether to enable or disable the specified capability.
274 *
275 * Updates the current context and flushes the vertices as needed. For
276 * capabilities associated with extensions it verifies that those extensions
277 * are effectivly present before updating. Notifies the driver via
278 * dd_function_table::Enable.
279 */
280 void
281 _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
282 {
283 if (MESA_VERBOSE & VERBOSE_API)
284 _mesa_debug(ctx, "%s %s (newstate is %x)\n",
285 state ? "glEnable" : "glDisable",
286 _mesa_enum_to_string(cap),
287 ctx->NewState);
288
289 switch (cap) {
290 case GL_ALPHA_TEST:
291 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
292 goto invalid_enum_error;
293 if (ctx->Color.AlphaEnabled == state)
294 return;
295 FLUSH_VERTICES(ctx, _NEW_COLOR);
296 ctx->Color.AlphaEnabled = state;
297 break;
298 case GL_AUTO_NORMAL:
299 if (ctx->API != API_OPENGL_COMPAT)
300 goto invalid_enum_error;
301 if (ctx->Eval.AutoNormal == state)
302 return;
303 FLUSH_VERTICES(ctx, _NEW_EVAL);
304 ctx->Eval.AutoNormal = state;
305 break;
306 case GL_BLEND:
307 {
308 GLbitfield newEnabled =
309 state * ((1 << ctx->Const.MaxDrawBuffers) - 1);
310 if (newEnabled != ctx->Color.BlendEnabled) {
311 FLUSH_VERTICES(ctx, _NEW_COLOR);
312 ctx->Color.BlendEnabled = newEnabled;
313 }
314 }
315 break;
316 case GL_CLIP_DISTANCE0: /* aka GL_CLIP_PLANE0 */
317 case GL_CLIP_DISTANCE1:
318 case GL_CLIP_DISTANCE2:
319 case GL_CLIP_DISTANCE3:
320 case GL_CLIP_DISTANCE4:
321 case GL_CLIP_DISTANCE5:
322 case GL_CLIP_DISTANCE6:
323 case GL_CLIP_DISTANCE7:
324 {
325 const GLuint p = cap - GL_CLIP_DISTANCE0;
326
327 if (p >= ctx->Const.MaxClipPlanes)
328 goto invalid_enum_error;
329
330 if ((ctx->Transform.ClipPlanesEnabled & (1 << p))
331 == ((GLuint) state << p))
332 return;
333
334 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
335
336 if (state) {
337 ctx->Transform.ClipPlanesEnabled |= (1 << p);
338 _mesa_update_clip_plane(ctx, p);
339 }
340 else {
341 ctx->Transform.ClipPlanesEnabled &= ~(1 << p);
342 }
343 }
344 break;
345 case GL_COLOR_MATERIAL:
346 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
347 goto invalid_enum_error;
348 if (ctx->Light.ColorMaterialEnabled == state)
349 return;
350 FLUSH_VERTICES(ctx, _NEW_LIGHT);
351 FLUSH_CURRENT(ctx, 0);
352 ctx->Light.ColorMaterialEnabled = state;
353 if (state) {
354 _mesa_update_color_material( ctx,
355 ctx->Current.Attrib[VERT_ATTRIB_COLOR0] );
356 }
357 break;
358 case GL_CULL_FACE:
359 if (ctx->Polygon.CullFlag == state)
360 return;
361 FLUSH_VERTICES(ctx, _NEW_POLYGON);
362 ctx->Polygon.CullFlag = state;
363 break;
364 case GL_DEPTH_TEST:
365 if (ctx->Depth.Test == state)
366 return;
367 FLUSH_VERTICES(ctx, _NEW_DEPTH);
368 ctx->Depth.Test = state;
369 break;
370 case GL_DEBUG_OUTPUT:
371 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB:
372 _mesa_set_debug_state_int(ctx, cap, state);
373 break;
374 case GL_DITHER:
375 if (ctx->Color.DitherFlag == state)
376 return;
377 FLUSH_VERTICES(ctx, _NEW_COLOR);
378 ctx->Color.DitherFlag = state;
379 break;
380 case GL_FOG:
381 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
382 goto invalid_enum_error;
383 if (ctx->Fog.Enabled == state)
384 return;
385 FLUSH_VERTICES(ctx, _NEW_FOG);
386 ctx->Fog.Enabled = state;
387 break;
388 case GL_LIGHT0:
389 case GL_LIGHT1:
390 case GL_LIGHT2:
391 case GL_LIGHT3:
392 case GL_LIGHT4:
393 case GL_LIGHT5:
394 case GL_LIGHT6:
395 case GL_LIGHT7:
396 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
397 goto invalid_enum_error;
398 if (ctx->Light.Light[cap-GL_LIGHT0].Enabled == state)
399 return;
400 FLUSH_VERTICES(ctx, _NEW_LIGHT);
401 ctx->Light.Light[cap-GL_LIGHT0].Enabled = state;
402 if (state) {
403 insert_at_tail(&ctx->Light.EnabledList,
404 &ctx->Light.Light[cap-GL_LIGHT0]);
405 }
406 else {
407 remove_from_list(&ctx->Light.Light[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_INDEX_ARRAY:
743 case GL_TEXTURE_COORD_ARRAY:
744 case GL_EDGE_FLAG_ARRAY:
745 case GL_FOG_COORDINATE_ARRAY_EXT:
746 case GL_SECONDARY_COLOR_ARRAY_EXT:
747 case GL_POINT_SIZE_ARRAY_OES:
748 client_state( ctx, cap, state );
749 return;
750
751 /* GL_ARB_texture_cube_map */
752 case GL_TEXTURE_CUBE_MAP:
753 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
754 goto invalid_enum_error;
755 CHECK_EXTENSION(ARB_texture_cube_map, cap);
756 if (!enable_texture(ctx, state, TEXTURE_CUBE_BIT)) {
757 return;
758 }
759 break;
760
761 /* GL_EXT_secondary_color */
762 case GL_COLOR_SUM_EXT:
763 if (ctx->API != API_OPENGL_COMPAT)
764 goto invalid_enum_error;
765 if (ctx->Fog.ColorSumEnabled == state)
766 return;
767 FLUSH_VERTICES(ctx, _NEW_FOG);
768 ctx->Fog.ColorSumEnabled = state;
769 break;
770
771 /* GL_ARB_multisample */
772 case GL_MULTISAMPLE_ARB:
773 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
774 goto invalid_enum_error;
775 _mesa_set_multisample(ctx, state);
776 return;
777 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
778 if (ctx->Multisample.SampleAlphaToCoverage == state)
779 return;
780 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
781 ctx->Multisample.SampleAlphaToCoverage = state;
782 break;
783 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
784 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
785 goto invalid_enum_error;
786 if (ctx->Multisample.SampleAlphaToOne == state)
787 return;
788 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
789 ctx->Multisample.SampleAlphaToOne = state;
790 break;
791 case GL_SAMPLE_COVERAGE_ARB:
792 if (ctx->Multisample.SampleCoverage == state)
793 return;
794 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
795 ctx->Multisample.SampleCoverage = state;
796 break;
797 case GL_SAMPLE_COVERAGE_INVERT_ARB:
798 if (!_mesa_is_desktop_gl(ctx))
799 goto invalid_enum_error;
800 if (ctx->Multisample.SampleCoverageInvert == state)
801 return;
802 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
803 ctx->Multisample.SampleCoverageInvert = state;
804 break;
805
806 /* GL_ARB_sample_shading */
807 case GL_SAMPLE_SHADING:
808 if (!_mesa_is_desktop_gl(ctx))
809 goto invalid_enum_error;
810 CHECK_EXTENSION(ARB_sample_shading, cap);
811 if (ctx->Multisample.SampleShading == state)
812 return;
813 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
814 ctx->Multisample.SampleShading = state;
815 break;
816
817 /* GL_IBM_rasterpos_clip */
818 case GL_RASTER_POSITION_UNCLIPPED_IBM:
819 if (ctx->API != API_OPENGL_COMPAT)
820 goto invalid_enum_error;
821 if (ctx->Transform.RasterPositionUnclipped == state)
822 return;
823 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
824 ctx->Transform.RasterPositionUnclipped = state;
825 break;
826
827 /* GL_NV_point_sprite */
828 case GL_POINT_SPRITE_NV:
829 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
830 goto invalid_enum_error;
831 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite, cap);
832 if (ctx->Point.PointSprite == state)
833 return;
834 FLUSH_VERTICES(ctx, _NEW_POINT);
835 ctx->Point.PointSprite = state;
836 break;
837
838 case GL_VERTEX_PROGRAM_ARB:
839 if (ctx->API != API_OPENGL_COMPAT)
840 goto invalid_enum_error;
841 CHECK_EXTENSION(ARB_vertex_program, cap);
842 if (ctx->VertexProgram.Enabled == state)
843 return;
844 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
845 ctx->VertexProgram.Enabled = state;
846 break;
847 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
848 /* This was added with ARB_vertex_program, but it is also used with
849 * GLSL vertex shaders on desktop.
850 */
851 if (!_mesa_is_desktop_gl(ctx))
852 goto invalid_enum_error;
853 CHECK_EXTENSION(ARB_vertex_program, cap);
854 if (ctx->VertexProgram.PointSizeEnabled == state)
855 return;
856 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
857 ctx->VertexProgram.PointSizeEnabled = state;
858 break;
859 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
860 if (ctx->API != API_OPENGL_COMPAT)
861 goto invalid_enum_error;
862 CHECK_EXTENSION(ARB_vertex_program, cap);
863 if (ctx->VertexProgram.TwoSideEnabled == state)
864 return;
865 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
866 ctx->VertexProgram.TwoSideEnabled = state;
867 break;
868
869 /* GL_NV_texture_rectangle */
870 case GL_TEXTURE_RECTANGLE_NV:
871 if (ctx->API != API_OPENGL_COMPAT)
872 goto invalid_enum_error;
873 CHECK_EXTENSION(NV_texture_rectangle, cap);
874 if (!enable_texture(ctx, state, TEXTURE_RECT_BIT)) {
875 return;
876 }
877 break;
878
879 /* GL_EXT_stencil_two_side */
880 case GL_STENCIL_TEST_TWO_SIDE_EXT:
881 if (ctx->API != API_OPENGL_COMPAT)
882 goto invalid_enum_error;
883 CHECK_EXTENSION(EXT_stencil_two_side, cap);
884 if (ctx->Stencil.TestTwoSide == state)
885 return;
886 FLUSH_VERTICES(ctx, _NEW_STENCIL);
887 ctx->Stencil.TestTwoSide = state;
888 if (state) {
889 ctx->Stencil._BackFace = 2;
890 } else {
891 ctx->Stencil._BackFace = 1;
892 }
893 break;
894
895 case GL_FRAGMENT_PROGRAM_ARB:
896 if (ctx->API != API_OPENGL_COMPAT)
897 goto invalid_enum_error;
898 CHECK_EXTENSION(ARB_fragment_program, cap);
899 if (ctx->FragmentProgram.Enabled == state)
900 return;
901 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
902 ctx->FragmentProgram.Enabled = state;
903 break;
904
905 /* GL_EXT_depth_bounds_test */
906 case GL_DEPTH_BOUNDS_TEST_EXT:
907 if (!_mesa_is_desktop_gl(ctx))
908 goto invalid_enum_error;
909 CHECK_EXTENSION(EXT_depth_bounds_test, cap);
910 if (ctx->Depth.BoundsTest == state)
911 return;
912 FLUSH_VERTICES(ctx, _NEW_DEPTH);
913 ctx->Depth.BoundsTest = state;
914 break;
915
916 case GL_DEPTH_CLAMP:
917 if (!_mesa_is_desktop_gl(ctx))
918 goto invalid_enum_error;
919 CHECK_EXTENSION(ARB_depth_clamp, cap);
920 if (ctx->Transform.DepthClamp == state)
921 return;
922 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
923 ctx->Transform.DepthClamp = state;
924 break;
925
926 case GL_FRAGMENT_SHADER_ATI:
927 if (ctx->API != API_OPENGL_COMPAT)
928 goto invalid_enum_error;
929 CHECK_EXTENSION(ATI_fragment_shader, cap);
930 if (ctx->ATIFragmentShader.Enabled == state)
931 return;
932 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
933 ctx->ATIFragmentShader.Enabled = state;
934 break;
935
936 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
937 if (!_mesa_is_desktop_gl(ctx))
938 goto invalid_enum_error;
939 CHECK_EXTENSION(ARB_seamless_cube_map, cap);
940 if (ctx->Texture.CubeMapSeamless != state) {
941 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
942 ctx->Texture.CubeMapSeamless = state;
943 }
944 break;
945
946 case GL_RASTERIZER_DISCARD:
947 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
948 goto invalid_enum_error;
949 CHECK_EXTENSION(EXT_transform_feedback, cap);
950 if (ctx->RasterDiscard != state) {
951 FLUSH_VERTICES(ctx, 0);
952 ctx->NewDriverState |= ctx->DriverFlags.NewRasterizerDiscard;
953 ctx->RasterDiscard = state;
954 }
955 break;
956
957 /* GL 3.1 primitive restart. Note: this enum is different from
958 * GL_PRIMITIVE_RESTART_NV (which is client state).
959 */
960 case GL_PRIMITIVE_RESTART:
961 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
962 goto invalid_enum_error;
963 }
964 if (ctx->Array.PrimitiveRestart != state) {
965 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
966 ctx->Array.PrimitiveRestart = state;
967 update_derived_primitive_restart_state(ctx);
968 }
969 break;
970
971 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
972 if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility)
973 goto invalid_enum_error;
974 if (ctx->Array.PrimitiveRestartFixedIndex != state) {
975 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
976 ctx->Array.PrimitiveRestartFixedIndex = state;
977 update_derived_primitive_restart_state(ctx);
978 }
979 break;
980
981 /* GL3.0 - GL_framebuffer_sRGB */
982 case GL_FRAMEBUFFER_SRGB_EXT:
983 if (!_mesa_is_desktop_gl(ctx))
984 goto invalid_enum_error;
985 CHECK_EXTENSION(EXT_framebuffer_sRGB, cap);
986 _mesa_set_framebuffer_srgb(ctx, state);
987 return;
988
989 /* GL_OES_EGL_image_external */
990 case GL_TEXTURE_EXTERNAL_OES:
991 if (!_mesa_is_gles(ctx))
992 goto invalid_enum_error;
993 CHECK_EXTENSION(OES_EGL_image_external, cap);
994 if (!enable_texture(ctx, state, TEXTURE_EXTERNAL_BIT)) {
995 return;
996 }
997 break;
998
999 /* ARB_texture_multisample */
1000 case GL_SAMPLE_MASK:
1001 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
1002 goto invalid_enum_error;
1003 CHECK_EXTENSION(ARB_texture_multisample, cap);
1004 if (ctx->Multisample.SampleMask == state)
1005 return;
1006 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
1007 ctx->Multisample.SampleMask = state;
1008 break;
1009
1010 default:
1011 goto invalid_enum_error;
1012 }
1013
1014 if (ctx->Driver.Enable) {
1015 ctx->Driver.Enable( ctx, cap, state );
1016 }
1017
1018 return;
1019
1020 invalid_enum_error:
1021 _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(%s)",
1022 state ? "Enable" : "Disable", _mesa_enum_to_string(cap));
1023 }
1024
1025
1026 /**
1027 * Enable GL capability. Called by glEnable()
1028 * \param cap state to enable.
1029 */
1030 void GLAPIENTRY
1031 _mesa_Enable( GLenum cap )
1032 {
1033 GET_CURRENT_CONTEXT(ctx);
1034
1035 _mesa_set_enable( ctx, cap, GL_TRUE );
1036 }
1037
1038
1039 /**
1040 * Disable GL capability. Called by glDisable()
1041 * \param cap state to disable.
1042 */
1043 void GLAPIENTRY
1044 _mesa_Disable( GLenum cap )
1045 {
1046 GET_CURRENT_CONTEXT(ctx);
1047
1048 _mesa_set_enable( ctx, cap, GL_FALSE );
1049 }
1050
1051
1052
1053 /**
1054 * Enable/disable an indexed state var.
1055 */
1056 void
1057 _mesa_set_enablei(struct gl_context *ctx, GLenum cap,
1058 GLuint index, GLboolean state)
1059 {
1060 assert(state == 0 || state == 1);
1061 switch (cap) {
1062 case GL_BLEND:
1063 if (!ctx->Extensions.EXT_draw_buffers2) {
1064 goto invalid_enum_error;
1065 }
1066 if (index >= ctx->Const.MaxDrawBuffers) {
1067 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1068 state ? "glEnableIndexed" : "glDisableIndexed", index);
1069 return;
1070 }
1071 if (((ctx->Color.BlendEnabled >> index) & 1) != state) {
1072 FLUSH_VERTICES(ctx, _NEW_COLOR);
1073 if (state)
1074 ctx->Color.BlendEnabled |= (1 << index);
1075 else
1076 ctx->Color.BlendEnabled &= ~(1 << index);
1077 }
1078 break;
1079 case GL_SCISSOR_TEST:
1080 if (index >= ctx->Const.MaxViewports) {
1081 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1082 state ? "glEnablei" : "glDisablei", index);
1083 return;
1084 }
1085 if (((ctx->Scissor.EnableFlags >> index) & 1) != state) {
1086 FLUSH_VERTICES(ctx, _NEW_SCISSOR);
1087 if (state)
1088 ctx->Scissor.EnableFlags |= (1 << index);
1089 else
1090 ctx->Scissor.EnableFlags &= ~(1 << index);
1091 }
1092 break;
1093 default:
1094 goto invalid_enum_error;
1095 }
1096 return;
1097
1098 invalid_enum_error:
1099 _mesa_error(ctx, GL_INVALID_ENUM, "%s(cap=%s)",
1100 state ? "glEnablei" : "glDisablei",
1101 _mesa_enum_to_string(cap));
1102 }
1103
1104
1105 void GLAPIENTRY
1106 _mesa_Disablei( GLenum cap, GLuint index )
1107 {
1108 GET_CURRENT_CONTEXT(ctx);
1109 _mesa_set_enablei(ctx, cap, index, GL_FALSE);
1110 }
1111
1112
1113 void GLAPIENTRY
1114 _mesa_Enablei( GLenum cap, GLuint index )
1115 {
1116 GET_CURRENT_CONTEXT(ctx);
1117 _mesa_set_enablei(ctx, cap, index, GL_TRUE);
1118 }
1119
1120
1121 GLboolean GLAPIENTRY
1122 _mesa_IsEnabledi( GLenum cap, GLuint index )
1123 {
1124 GET_CURRENT_CONTEXT(ctx);
1125 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1126 switch (cap) {
1127 case GL_BLEND:
1128 if (index >= ctx->Const.MaxDrawBuffers) {
1129 _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
1130 index);
1131 return GL_FALSE;
1132 }
1133 return (ctx->Color.BlendEnabled >> index) & 1;
1134 case GL_SCISSOR_TEST:
1135 if (index >= ctx->Const.MaxViewports) {
1136 _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
1137 index);
1138 return GL_FALSE;
1139 }
1140 return (ctx->Scissor.EnableFlags >> index) & 1;
1141 default:
1142 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabledIndexed(cap=%s)",
1143 _mesa_enum_to_string(cap));
1144 return GL_FALSE;
1145 }
1146 }
1147
1148
1149
1150
1151 #undef CHECK_EXTENSION
1152 #define CHECK_EXTENSION(EXTNAME) \
1153 if (!ctx->Extensions.EXTNAME) { \
1154 goto invalid_enum_error; \
1155 }
1156
1157 #undef CHECK_EXTENSION2
1158 #define CHECK_EXTENSION2(EXT1, EXT2) \
1159 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1160 goto invalid_enum_error; \
1161 }
1162
1163
1164 /**
1165 * Helper function to determine whether a texture target is enabled.
1166 */
1167 static GLboolean
1168 is_texture_enabled(struct gl_context *ctx, GLbitfield bit)
1169 {
1170 const struct gl_texture_unit *const texUnit =
1171 &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1172 return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE;
1173 }
1174
1175
1176 /**
1177 * Return simple enable/disable state.
1178 *
1179 * \param cap state variable to query.
1180 *
1181 * Returns the state of the specified capability from the current GL context.
1182 * For the capabilities associated with extensions verifies that those
1183 * extensions are effectively present before reporting.
1184 */
1185 GLboolean GLAPIENTRY
1186 _mesa_IsEnabled( GLenum cap )
1187 {
1188 GET_CURRENT_CONTEXT(ctx);
1189 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1190
1191 switch (cap) {
1192 case GL_ALPHA_TEST:
1193 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1194 goto invalid_enum_error;
1195 return ctx->Color.AlphaEnabled;
1196 case GL_AUTO_NORMAL:
1197 if (ctx->API != API_OPENGL_COMPAT)
1198 goto invalid_enum_error;
1199 return ctx->Eval.AutoNormal;
1200 case GL_BLEND:
1201 return ctx->Color.BlendEnabled & 1; /* return state for buffer[0] */
1202 case GL_CLIP_DISTANCE0: /* aka GL_CLIP_PLANE0 */
1203 case GL_CLIP_DISTANCE1:
1204 case GL_CLIP_DISTANCE2:
1205 case GL_CLIP_DISTANCE3:
1206 case GL_CLIP_DISTANCE4:
1207 case GL_CLIP_DISTANCE5:
1208 case GL_CLIP_DISTANCE6:
1209 case GL_CLIP_DISTANCE7: {
1210 const GLuint p = cap - GL_CLIP_DISTANCE0;
1211
1212 if (p >= ctx->Const.MaxClipPlanes)
1213 goto invalid_enum_error;
1214
1215 return (ctx->Transform.ClipPlanesEnabled >> p) & 1;
1216 }
1217 case GL_COLOR_MATERIAL:
1218 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1219 goto invalid_enum_error;
1220 return ctx->Light.ColorMaterialEnabled;
1221 case GL_CULL_FACE:
1222 return ctx->Polygon.CullFlag;
1223 case GL_DEBUG_OUTPUT:
1224 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB:
1225 return (GLboolean) _mesa_get_debug_state_int(ctx, cap);
1226 case GL_DEPTH_TEST:
1227 return ctx->Depth.Test;
1228 case GL_DITHER:
1229 return ctx->Color.DitherFlag;
1230 case GL_FOG:
1231 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1232 goto invalid_enum_error;
1233 return ctx->Fog.Enabled;
1234 case GL_LIGHTING:
1235 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1236 goto invalid_enum_error;
1237 return ctx->Light.Enabled;
1238 case GL_LIGHT0:
1239 case GL_LIGHT1:
1240 case GL_LIGHT2:
1241 case GL_LIGHT3:
1242 case GL_LIGHT4:
1243 case GL_LIGHT5:
1244 case GL_LIGHT6:
1245 case GL_LIGHT7:
1246 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1247 goto invalid_enum_error;
1248 return ctx->Light.Light[cap-GL_LIGHT0].Enabled;
1249 case GL_LINE_SMOOTH:
1250 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1251 goto invalid_enum_error;
1252 return ctx->Line.SmoothFlag;
1253 case GL_LINE_STIPPLE:
1254 if (ctx->API != API_OPENGL_COMPAT)
1255 goto invalid_enum_error;
1256 return ctx->Line.StippleFlag;
1257 case GL_INDEX_LOGIC_OP:
1258 if (ctx->API != API_OPENGL_COMPAT)
1259 goto invalid_enum_error;
1260 return ctx->Color.IndexLogicOpEnabled;
1261 case GL_COLOR_LOGIC_OP:
1262 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1263 goto invalid_enum_error;
1264 return ctx->Color.ColorLogicOpEnabled;
1265 case GL_MAP1_COLOR_4:
1266 if (ctx->API != API_OPENGL_COMPAT)
1267 goto invalid_enum_error;
1268 return ctx->Eval.Map1Color4;
1269 case GL_MAP1_INDEX:
1270 if (ctx->API != API_OPENGL_COMPAT)
1271 goto invalid_enum_error;
1272 return ctx->Eval.Map1Index;
1273 case GL_MAP1_NORMAL:
1274 if (ctx->API != API_OPENGL_COMPAT)
1275 goto invalid_enum_error;
1276 return ctx->Eval.Map1Normal;
1277 case GL_MAP1_TEXTURE_COORD_1:
1278 if (ctx->API != API_OPENGL_COMPAT)
1279 goto invalid_enum_error;
1280 return ctx->Eval.Map1TextureCoord1;
1281 case GL_MAP1_TEXTURE_COORD_2:
1282 if (ctx->API != API_OPENGL_COMPAT)
1283 goto invalid_enum_error;
1284 return ctx->Eval.Map1TextureCoord2;
1285 case GL_MAP1_TEXTURE_COORD_3:
1286 if (ctx->API != API_OPENGL_COMPAT)
1287 goto invalid_enum_error;
1288 return ctx->Eval.Map1TextureCoord3;
1289 case GL_MAP1_TEXTURE_COORD_4:
1290 if (ctx->API != API_OPENGL_COMPAT)
1291 goto invalid_enum_error;
1292 return ctx->Eval.Map1TextureCoord4;
1293 case GL_MAP1_VERTEX_3:
1294 if (ctx->API != API_OPENGL_COMPAT)
1295 goto invalid_enum_error;
1296 return ctx->Eval.Map1Vertex3;
1297 case GL_MAP1_VERTEX_4:
1298 if (ctx->API != API_OPENGL_COMPAT)
1299 goto invalid_enum_error;
1300 return ctx->Eval.Map1Vertex4;
1301 case GL_MAP2_COLOR_4:
1302 if (ctx->API != API_OPENGL_COMPAT)
1303 goto invalid_enum_error;
1304 return ctx->Eval.Map2Color4;
1305 case GL_MAP2_INDEX:
1306 if (ctx->API != API_OPENGL_COMPAT)
1307 goto invalid_enum_error;
1308 return ctx->Eval.Map2Index;
1309 case GL_MAP2_NORMAL:
1310 if (ctx->API != API_OPENGL_COMPAT)
1311 goto invalid_enum_error;
1312 return ctx->Eval.Map2Normal;
1313 case GL_MAP2_TEXTURE_COORD_1:
1314 if (ctx->API != API_OPENGL_COMPAT)
1315 goto invalid_enum_error;
1316 return ctx->Eval.Map2TextureCoord1;
1317 case GL_MAP2_TEXTURE_COORD_2:
1318 if (ctx->API != API_OPENGL_COMPAT)
1319 goto invalid_enum_error;
1320 return ctx->Eval.Map2TextureCoord2;
1321 case GL_MAP2_TEXTURE_COORD_3:
1322 if (ctx->API != API_OPENGL_COMPAT)
1323 goto invalid_enum_error;
1324 return ctx->Eval.Map2TextureCoord3;
1325 case GL_MAP2_TEXTURE_COORD_4:
1326 if (ctx->API != API_OPENGL_COMPAT)
1327 goto invalid_enum_error;
1328 return ctx->Eval.Map2TextureCoord4;
1329 case GL_MAP2_VERTEX_3:
1330 if (ctx->API != API_OPENGL_COMPAT)
1331 goto invalid_enum_error;
1332 return ctx->Eval.Map2Vertex3;
1333 case GL_MAP2_VERTEX_4:
1334 if (ctx->API != API_OPENGL_COMPAT)
1335 goto invalid_enum_error;
1336 return ctx->Eval.Map2Vertex4;
1337 case GL_NORMALIZE:
1338 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1339 goto invalid_enum_error;
1340 return ctx->Transform.Normalize;
1341 case GL_POINT_SMOOTH:
1342 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1343 goto invalid_enum_error;
1344 return ctx->Point.SmoothFlag;
1345 case GL_POLYGON_SMOOTH:
1346 if (!_mesa_is_desktop_gl(ctx))
1347 goto invalid_enum_error;
1348 return ctx->Polygon.SmoothFlag;
1349 case GL_POLYGON_STIPPLE:
1350 if (ctx->API != API_OPENGL_COMPAT)
1351 goto invalid_enum_error;
1352 return ctx->Polygon.StippleFlag;
1353 case GL_POLYGON_OFFSET_POINT:
1354 if (!_mesa_is_desktop_gl(ctx))
1355 goto invalid_enum_error;
1356 return ctx->Polygon.OffsetPoint;
1357 case GL_POLYGON_OFFSET_LINE:
1358 if (!_mesa_is_desktop_gl(ctx))
1359 goto invalid_enum_error;
1360 return ctx->Polygon.OffsetLine;
1361 case GL_POLYGON_OFFSET_FILL:
1362 return ctx->Polygon.OffsetFill;
1363 case GL_RESCALE_NORMAL_EXT:
1364 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1365 goto invalid_enum_error;
1366 return ctx->Transform.RescaleNormals;
1367 case GL_SCISSOR_TEST:
1368 return ctx->Scissor.EnableFlags & 1; /* return state for index 0 */
1369 case GL_STENCIL_TEST:
1370 return ctx->Stencil.Enabled;
1371 case GL_TEXTURE_1D:
1372 if (ctx->API != API_OPENGL_COMPAT)
1373 goto invalid_enum_error;
1374 return is_texture_enabled(ctx, TEXTURE_1D_BIT);
1375 case GL_TEXTURE_2D:
1376 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1377 goto invalid_enum_error;
1378 return is_texture_enabled(ctx, TEXTURE_2D_BIT);
1379 case GL_TEXTURE_3D:
1380 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1381 goto invalid_enum_error;
1382 return is_texture_enabled(ctx, TEXTURE_3D_BIT);
1383 case GL_TEXTURE_GEN_S:
1384 case GL_TEXTURE_GEN_T:
1385 case GL_TEXTURE_GEN_R:
1386 case GL_TEXTURE_GEN_Q:
1387 {
1388 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1389
1390 if (ctx->API != API_OPENGL_COMPAT)
1391 goto invalid_enum_error;
1392
1393 if (texUnit) {
1394 GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
1395 return (texUnit->TexGenEnabled & coordBit) ? GL_TRUE : GL_FALSE;
1396 }
1397 }
1398 return GL_FALSE;
1399 case GL_TEXTURE_GEN_STR_OES:
1400 {
1401 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1402
1403 if (ctx->API != API_OPENGLES)
1404 goto invalid_enum_error;
1405
1406 if (texUnit) {
1407 return (texUnit->TexGenEnabled & STR_BITS) == STR_BITS
1408 ? GL_TRUE : GL_FALSE;
1409 }
1410 }
1411
1412 /* client-side state */
1413 case GL_VERTEX_ARRAY:
1414 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1415 goto invalid_enum_error;
1416 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POS].Enabled;
1417 case GL_NORMAL_ARRAY:
1418 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1419 goto invalid_enum_error;
1420 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled;
1421 case GL_COLOR_ARRAY:
1422 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1423 goto invalid_enum_error;
1424 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled;
1425 case GL_INDEX_ARRAY:
1426 if (ctx->API != API_OPENGL_COMPAT)
1427 goto invalid_enum_error;
1428 return ctx->Array.VAO->
1429 VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled;
1430 case GL_TEXTURE_COORD_ARRAY:
1431 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1432 goto invalid_enum_error;
1433 return ctx->Array.VAO->
1434 VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Enabled;
1435 case GL_EDGE_FLAG_ARRAY:
1436 if (ctx->API != API_OPENGL_COMPAT)
1437 goto invalid_enum_error;
1438 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled;
1439 case GL_FOG_COORDINATE_ARRAY_EXT:
1440 if (ctx->API != API_OPENGL_COMPAT)
1441 goto invalid_enum_error;
1442 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_FOG].Enabled;
1443 case GL_SECONDARY_COLOR_ARRAY_EXT:
1444 if (ctx->API != API_OPENGL_COMPAT)
1445 goto invalid_enum_error;
1446 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled;
1447 case GL_POINT_SIZE_ARRAY_OES:
1448 if (ctx->API != API_OPENGLES)
1449 goto invalid_enum_error;
1450 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled;
1451
1452 /* GL_ARB_texture_cube_map */
1453 case GL_TEXTURE_CUBE_MAP:
1454 CHECK_EXTENSION(ARB_texture_cube_map);
1455 return is_texture_enabled(ctx, TEXTURE_CUBE_BIT);
1456
1457 /* GL_EXT_secondary_color */
1458 case GL_COLOR_SUM_EXT:
1459 if (ctx->API != API_OPENGL_COMPAT)
1460 goto invalid_enum_error;
1461 return ctx->Fog.ColorSumEnabled;
1462
1463 /* GL_ARB_multisample */
1464 case GL_MULTISAMPLE_ARB:
1465 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1466 goto invalid_enum_error;
1467 return ctx->Multisample.Enabled;
1468 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
1469 return ctx->Multisample.SampleAlphaToCoverage;
1470 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
1471 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1472 goto invalid_enum_error;
1473 return ctx->Multisample.SampleAlphaToOne;
1474 case GL_SAMPLE_COVERAGE_ARB:
1475 return ctx->Multisample.SampleCoverage;
1476 case GL_SAMPLE_COVERAGE_INVERT_ARB:
1477 if (!_mesa_is_desktop_gl(ctx))
1478 goto invalid_enum_error;
1479 return ctx->Multisample.SampleCoverageInvert;
1480
1481 /* GL_IBM_rasterpos_clip */
1482 case GL_RASTER_POSITION_UNCLIPPED_IBM:
1483 if (ctx->API != API_OPENGL_COMPAT)
1484 goto invalid_enum_error;
1485 return ctx->Transform.RasterPositionUnclipped;
1486
1487 /* GL_NV_point_sprite */
1488 case GL_POINT_SPRITE_NV:
1489 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1490 goto invalid_enum_error;
1491 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite)
1492 return ctx->Point.PointSprite;
1493
1494 case GL_VERTEX_PROGRAM_ARB:
1495 if (ctx->API != API_OPENGL_COMPAT)
1496 goto invalid_enum_error;
1497 CHECK_EXTENSION(ARB_vertex_program);
1498 return ctx->VertexProgram.Enabled;
1499 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
1500 /* This was added with ARB_vertex_program, but it is also used with
1501 * GLSL vertex shaders on desktop.
1502 */
1503 if (!_mesa_is_desktop_gl(ctx))
1504 goto invalid_enum_error;
1505 CHECK_EXTENSION(ARB_vertex_program);
1506 return ctx->VertexProgram.PointSizeEnabled;
1507 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
1508 if (ctx->API != API_OPENGL_COMPAT)
1509 goto invalid_enum_error;
1510 CHECK_EXTENSION(ARB_vertex_program);
1511 return ctx->VertexProgram.TwoSideEnabled;
1512
1513 /* GL_NV_texture_rectangle */
1514 case GL_TEXTURE_RECTANGLE_NV:
1515 if (ctx->API != API_OPENGL_COMPAT)
1516 goto invalid_enum_error;
1517 CHECK_EXTENSION(NV_texture_rectangle);
1518 return is_texture_enabled(ctx, TEXTURE_RECT_BIT);
1519
1520 /* GL_EXT_stencil_two_side */
1521 case GL_STENCIL_TEST_TWO_SIDE_EXT:
1522 if (ctx->API != API_OPENGL_COMPAT)
1523 goto invalid_enum_error;
1524 CHECK_EXTENSION(EXT_stencil_two_side);
1525 return ctx->Stencil.TestTwoSide;
1526
1527 case GL_FRAGMENT_PROGRAM_ARB:
1528 if (ctx->API != API_OPENGL_COMPAT)
1529 goto invalid_enum_error;
1530 return ctx->FragmentProgram.Enabled;
1531
1532 /* GL_EXT_depth_bounds_test */
1533 case GL_DEPTH_BOUNDS_TEST_EXT:
1534 if (!_mesa_is_desktop_gl(ctx))
1535 goto invalid_enum_error;
1536 CHECK_EXTENSION(EXT_depth_bounds_test);
1537 return ctx->Depth.BoundsTest;
1538
1539 /* GL_ARB_depth_clamp */
1540 case GL_DEPTH_CLAMP:
1541 if (!_mesa_is_desktop_gl(ctx))
1542 goto invalid_enum_error;
1543 CHECK_EXTENSION(ARB_depth_clamp);
1544 return ctx->Transform.DepthClamp;
1545
1546 case GL_FRAGMENT_SHADER_ATI:
1547 if (ctx->API != API_OPENGL_COMPAT)
1548 goto invalid_enum_error;
1549 CHECK_EXTENSION(ATI_fragment_shader);
1550 return ctx->ATIFragmentShader.Enabled;
1551
1552 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1553 if (!_mesa_is_desktop_gl(ctx))
1554 goto invalid_enum_error;
1555 CHECK_EXTENSION(ARB_seamless_cube_map);
1556 return ctx->Texture.CubeMapSeamless;
1557
1558 case GL_RASTERIZER_DISCARD:
1559 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1560 goto invalid_enum_error;
1561 CHECK_EXTENSION(EXT_transform_feedback);
1562 return ctx->RasterDiscard;
1563
1564 /* GL_NV_primitive_restart */
1565 case GL_PRIMITIVE_RESTART_NV:
1566 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.NV_primitive_restart) {
1567 goto invalid_enum_error;
1568 }
1569 return ctx->Array.PrimitiveRestart;
1570
1571 /* GL 3.1 primitive restart */
1572 case GL_PRIMITIVE_RESTART:
1573 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
1574 goto invalid_enum_error;
1575 }
1576 return ctx->Array.PrimitiveRestart;
1577
1578 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
1579 if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility) {
1580 goto invalid_enum_error;
1581 }
1582 return ctx->Array.PrimitiveRestartFixedIndex;
1583
1584 /* GL3.0 - GL_framebuffer_sRGB */
1585 case GL_FRAMEBUFFER_SRGB_EXT:
1586 if (!_mesa_is_desktop_gl(ctx))
1587 goto invalid_enum_error;
1588 CHECK_EXTENSION(EXT_framebuffer_sRGB);
1589 return ctx->Color.sRGBEnabled;
1590
1591 /* GL_OES_EGL_image_external */
1592 case GL_TEXTURE_EXTERNAL_OES:
1593 if (!_mesa_is_gles(ctx))
1594 goto invalid_enum_error;
1595 CHECK_EXTENSION(OES_EGL_image_external);
1596 return is_texture_enabled(ctx, TEXTURE_EXTERNAL_BIT);
1597
1598 /* ARB_texture_multisample */
1599 case GL_SAMPLE_MASK:
1600 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
1601 goto invalid_enum_error;
1602 CHECK_EXTENSION(ARB_texture_multisample);
1603 return ctx->Multisample.SampleMask;
1604
1605 /* ARB_sample_shading */
1606 case GL_SAMPLE_SHADING:
1607 if (!_mesa_is_desktop_gl(ctx))
1608 goto invalid_enum_error;
1609 CHECK_EXTENSION(ARB_sample_shading);
1610 return ctx->Multisample.SampleShading;
1611
1612 default:
1613 goto invalid_enum_error;
1614 }
1615
1616 return GL_FALSE;
1617
1618 invalid_enum_error:
1619 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(%s)",
1620 _mesa_enum_to_string(cap));
1621 return GL_FALSE;
1622 }