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