mesa: Remove support for GL_MESA_texture_array
[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 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
938 if (!_mesa_is_desktop_gl(ctx))
939 goto invalid_enum_error;
940 CHECK_EXTENSION(ARB_seamless_cube_map, cap);
941 if (ctx->Texture.CubeMapSeamless != state) {
942 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
943 ctx->Texture.CubeMapSeamless = state;
944 }
945 break;
946
947 case GL_RASTERIZER_DISCARD:
948 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
949 goto invalid_enum_error;
950 CHECK_EXTENSION(EXT_transform_feedback, cap);
951 if (ctx->RasterDiscard != state) {
952 FLUSH_VERTICES(ctx, 0);
953 ctx->NewDriverState |= ctx->DriverFlags.NewRasterizerDiscard;
954 ctx->RasterDiscard = state;
955 }
956 break;
957
958 /* GL 3.1 primitive restart. Note: this enum is different from
959 * GL_PRIMITIVE_RESTART_NV (which is client state).
960 */
961 case GL_PRIMITIVE_RESTART:
962 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
963 goto invalid_enum_error;
964 }
965 if (ctx->Array.PrimitiveRestart != state) {
966 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
967 ctx->Array.PrimitiveRestart = state;
968 update_derived_primitive_restart_state(ctx);
969 }
970 break;
971
972 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
973 if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility)
974 goto invalid_enum_error;
975 if (ctx->Array.PrimitiveRestartFixedIndex != state) {
976 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
977 ctx->Array.PrimitiveRestartFixedIndex = state;
978 update_derived_primitive_restart_state(ctx);
979 }
980 break;
981
982 /* GL3.0 - GL_framebuffer_sRGB */
983 case GL_FRAMEBUFFER_SRGB_EXT:
984 if (!_mesa_is_desktop_gl(ctx))
985 goto invalid_enum_error;
986 CHECK_EXTENSION(EXT_framebuffer_sRGB, cap);
987 _mesa_set_framebuffer_srgb(ctx, state);
988 return;
989
990 /* GL_OES_EGL_image_external */
991 case GL_TEXTURE_EXTERNAL_OES:
992 if (!_mesa_is_gles(ctx))
993 goto invalid_enum_error;
994 CHECK_EXTENSION(OES_EGL_image_external, cap);
995 if (!enable_texture(ctx, state, TEXTURE_EXTERNAL_BIT)) {
996 return;
997 }
998 break;
999
1000 /* ARB_texture_multisample */
1001 case GL_SAMPLE_MASK:
1002 if (!_mesa_is_desktop_gl(ctx))
1003 goto invalid_enum_error;
1004 CHECK_EXTENSION(ARB_texture_multisample, cap);
1005 if (ctx->Multisample.SampleMask == state)
1006 return;
1007 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
1008 ctx->Multisample.SampleMask = state;
1009 break;
1010
1011 default:
1012 goto invalid_enum_error;
1013 }
1014
1015 if (ctx->Driver.Enable) {
1016 ctx->Driver.Enable( ctx, cap, state );
1017 }
1018
1019 return;
1020
1021 invalid_enum_error:
1022 _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(%s)",
1023 state ? "Enable" : "Disable", _mesa_lookup_enum_by_nr(cap));
1024 }
1025
1026
1027 /**
1028 * Enable GL capability. Called by glEnable()
1029 * \param cap state to enable.
1030 */
1031 void GLAPIENTRY
1032 _mesa_Enable( GLenum cap )
1033 {
1034 GET_CURRENT_CONTEXT(ctx);
1035
1036 _mesa_set_enable( ctx, cap, GL_TRUE );
1037 }
1038
1039
1040 /**
1041 * Disable GL capability. Called by glDisable()
1042 * \param cap state to disable.
1043 */
1044 void GLAPIENTRY
1045 _mesa_Disable( GLenum cap )
1046 {
1047 GET_CURRENT_CONTEXT(ctx);
1048
1049 _mesa_set_enable( ctx, cap, GL_FALSE );
1050 }
1051
1052
1053
1054 /**
1055 * Enable/disable an indexed state var.
1056 */
1057 void
1058 _mesa_set_enablei(struct gl_context *ctx, GLenum cap,
1059 GLuint index, GLboolean state)
1060 {
1061 ASSERT(state == 0 || state == 1);
1062 switch (cap) {
1063 case GL_BLEND:
1064 if (!ctx->Extensions.EXT_draw_buffers2) {
1065 goto invalid_enum_error;
1066 }
1067 if (index >= ctx->Const.MaxDrawBuffers) {
1068 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1069 state ? "glEnableIndexed" : "glDisableIndexed", index);
1070 return;
1071 }
1072 if (((ctx->Color.BlendEnabled >> index) & 1) != state) {
1073 FLUSH_VERTICES(ctx, _NEW_COLOR);
1074 if (state)
1075 ctx->Color.BlendEnabled |= (1 << index);
1076 else
1077 ctx->Color.BlendEnabled &= ~(1 << index);
1078 }
1079 break;
1080 default:
1081 goto invalid_enum_error;
1082 }
1083 return;
1084
1085 invalid_enum_error:
1086 _mesa_error(ctx, GL_INVALID_ENUM, "%s(cap=%s)",
1087 state ? "glEnablei" : "glDisablei",
1088 _mesa_lookup_enum_by_nr(cap));
1089 }
1090
1091
1092 void GLAPIENTRY
1093 _mesa_Disablei( GLenum cap, GLuint index )
1094 {
1095 GET_CURRENT_CONTEXT(ctx);
1096 _mesa_set_enablei(ctx, cap, index, GL_FALSE);
1097 }
1098
1099
1100 void GLAPIENTRY
1101 _mesa_Enablei( GLenum cap, GLuint index )
1102 {
1103 GET_CURRENT_CONTEXT(ctx);
1104 _mesa_set_enablei(ctx, cap, index, GL_TRUE);
1105 }
1106
1107
1108 GLboolean GLAPIENTRY
1109 _mesa_IsEnabledi( GLenum cap, GLuint index )
1110 {
1111 GET_CURRENT_CONTEXT(ctx);
1112 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1113 switch (cap) {
1114 case GL_BLEND:
1115 if (index >= ctx->Const.MaxDrawBuffers) {
1116 _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
1117 index);
1118 return GL_FALSE;
1119 }
1120 return (ctx->Color.BlendEnabled >> index) & 1;
1121 default:
1122 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabledIndexed(cap=%s)",
1123 _mesa_lookup_enum_by_nr(cap));
1124 return GL_FALSE;
1125 }
1126 }
1127
1128
1129
1130
1131 #undef CHECK_EXTENSION
1132 #define CHECK_EXTENSION(EXTNAME) \
1133 if (!ctx->Extensions.EXTNAME) { \
1134 goto invalid_enum_error; \
1135 }
1136
1137 #undef CHECK_EXTENSION2
1138 #define CHECK_EXTENSION2(EXT1, EXT2) \
1139 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1140 goto invalid_enum_error; \
1141 }
1142
1143
1144 /**
1145 * Helper function to determine whether a texture target is enabled.
1146 */
1147 static GLboolean
1148 is_texture_enabled(struct gl_context *ctx, GLbitfield bit)
1149 {
1150 const struct gl_texture_unit *const texUnit =
1151 &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1152 return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE;
1153 }
1154
1155
1156 /**
1157 * Return simple enable/disable state.
1158 *
1159 * \param cap state variable to query.
1160 *
1161 * Returns the state of the specified capability from the current GL context.
1162 * For the capabilities associated with extensions verifies that those
1163 * extensions are effectively present before reporting.
1164 */
1165 GLboolean GLAPIENTRY
1166 _mesa_IsEnabled( GLenum cap )
1167 {
1168 GET_CURRENT_CONTEXT(ctx);
1169 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1170
1171 switch (cap) {
1172 case GL_ALPHA_TEST:
1173 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1174 goto invalid_enum_error;
1175 return ctx->Color.AlphaEnabled;
1176 case GL_AUTO_NORMAL:
1177 if (ctx->API != API_OPENGL_COMPAT)
1178 goto invalid_enum_error;
1179 return ctx->Eval.AutoNormal;
1180 case GL_BLEND:
1181 return ctx->Color.BlendEnabled & 1; /* return state for buffer[0] */
1182 case GL_CLIP_DISTANCE0:
1183 case GL_CLIP_DISTANCE1:
1184 case GL_CLIP_DISTANCE2:
1185 case GL_CLIP_DISTANCE3:
1186 case GL_CLIP_DISTANCE4:
1187 case GL_CLIP_DISTANCE5:
1188 case GL_CLIP_DISTANCE6:
1189 case GL_CLIP_DISTANCE7: {
1190 const GLuint p = cap - GL_CLIP_DISTANCE0;
1191
1192 if (p >= ctx->Const.MaxClipPlanes)
1193 goto invalid_enum_error;
1194
1195 return (ctx->Transform.ClipPlanesEnabled >> p) & 1;
1196 }
1197 case GL_COLOR_MATERIAL:
1198 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1199 goto invalid_enum_error;
1200 return ctx->Light.ColorMaterialEnabled;
1201 case GL_CULL_FACE:
1202 return ctx->Polygon.CullFlag;
1203 case GL_DEBUG_OUTPUT:
1204 if (!_mesa_is_desktop_gl(ctx))
1205 goto invalid_enum_error;
1206 return ctx->Debug.DebugOutput;
1207 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB:
1208 if (!_mesa_is_desktop_gl(ctx))
1209 goto invalid_enum_error;
1210 return ctx->Debug.SyncOutput;
1211 case GL_DEPTH_TEST:
1212 return ctx->Depth.Test;
1213 case GL_DITHER:
1214 return ctx->Color.DitherFlag;
1215 case GL_FOG:
1216 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1217 goto invalid_enum_error;
1218 return ctx->Fog.Enabled;
1219 case GL_LIGHTING:
1220 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1221 goto invalid_enum_error;
1222 return ctx->Light.Enabled;
1223 case GL_LIGHT0:
1224 case GL_LIGHT1:
1225 case GL_LIGHT2:
1226 case GL_LIGHT3:
1227 case GL_LIGHT4:
1228 case GL_LIGHT5:
1229 case GL_LIGHT6:
1230 case GL_LIGHT7:
1231 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1232 goto invalid_enum_error;
1233 return ctx->Light.Light[cap-GL_LIGHT0].Enabled;
1234 case GL_LINE_SMOOTH:
1235 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1236 goto invalid_enum_error;
1237 return ctx->Line.SmoothFlag;
1238 case GL_LINE_STIPPLE:
1239 if (ctx->API != API_OPENGL_COMPAT)
1240 goto invalid_enum_error;
1241 return ctx->Line.StippleFlag;
1242 case GL_INDEX_LOGIC_OP:
1243 if (ctx->API != API_OPENGL_COMPAT)
1244 goto invalid_enum_error;
1245 return ctx->Color.IndexLogicOpEnabled;
1246 case GL_COLOR_LOGIC_OP:
1247 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1248 goto invalid_enum_error;
1249 return ctx->Color.ColorLogicOpEnabled;
1250 case GL_MAP1_COLOR_4:
1251 if (ctx->API != API_OPENGL_COMPAT)
1252 goto invalid_enum_error;
1253 return ctx->Eval.Map1Color4;
1254 case GL_MAP1_INDEX:
1255 if (ctx->API != API_OPENGL_COMPAT)
1256 goto invalid_enum_error;
1257 return ctx->Eval.Map1Index;
1258 case GL_MAP1_NORMAL:
1259 if (ctx->API != API_OPENGL_COMPAT)
1260 goto invalid_enum_error;
1261 return ctx->Eval.Map1Normal;
1262 case GL_MAP1_TEXTURE_COORD_1:
1263 if (ctx->API != API_OPENGL_COMPAT)
1264 goto invalid_enum_error;
1265 return ctx->Eval.Map1TextureCoord1;
1266 case GL_MAP1_TEXTURE_COORD_2:
1267 if (ctx->API != API_OPENGL_COMPAT)
1268 goto invalid_enum_error;
1269 return ctx->Eval.Map1TextureCoord2;
1270 case GL_MAP1_TEXTURE_COORD_3:
1271 if (ctx->API != API_OPENGL_COMPAT)
1272 goto invalid_enum_error;
1273 return ctx->Eval.Map1TextureCoord3;
1274 case GL_MAP1_TEXTURE_COORD_4:
1275 if (ctx->API != API_OPENGL_COMPAT)
1276 goto invalid_enum_error;
1277 return ctx->Eval.Map1TextureCoord4;
1278 case GL_MAP1_VERTEX_3:
1279 if (ctx->API != API_OPENGL_COMPAT)
1280 goto invalid_enum_error;
1281 return ctx->Eval.Map1Vertex3;
1282 case GL_MAP1_VERTEX_4:
1283 if (ctx->API != API_OPENGL_COMPAT)
1284 goto invalid_enum_error;
1285 return ctx->Eval.Map1Vertex4;
1286 case GL_MAP2_COLOR_4:
1287 if (ctx->API != API_OPENGL_COMPAT)
1288 goto invalid_enum_error;
1289 return ctx->Eval.Map2Color4;
1290 case GL_MAP2_INDEX:
1291 if (ctx->API != API_OPENGL_COMPAT)
1292 goto invalid_enum_error;
1293 return ctx->Eval.Map2Index;
1294 case GL_MAP2_NORMAL:
1295 if (ctx->API != API_OPENGL_COMPAT)
1296 goto invalid_enum_error;
1297 return ctx->Eval.Map2Normal;
1298 case GL_MAP2_TEXTURE_COORD_1:
1299 if (ctx->API != API_OPENGL_COMPAT)
1300 goto invalid_enum_error;
1301 return ctx->Eval.Map2TextureCoord1;
1302 case GL_MAP2_TEXTURE_COORD_2:
1303 if (ctx->API != API_OPENGL_COMPAT)
1304 goto invalid_enum_error;
1305 return ctx->Eval.Map2TextureCoord2;
1306 case GL_MAP2_TEXTURE_COORD_3:
1307 if (ctx->API != API_OPENGL_COMPAT)
1308 goto invalid_enum_error;
1309 return ctx->Eval.Map2TextureCoord3;
1310 case GL_MAP2_TEXTURE_COORD_4:
1311 if (ctx->API != API_OPENGL_COMPAT)
1312 goto invalid_enum_error;
1313 return ctx->Eval.Map2TextureCoord4;
1314 case GL_MAP2_VERTEX_3:
1315 if (ctx->API != API_OPENGL_COMPAT)
1316 goto invalid_enum_error;
1317 return ctx->Eval.Map2Vertex3;
1318 case GL_MAP2_VERTEX_4:
1319 if (ctx->API != API_OPENGL_COMPAT)
1320 goto invalid_enum_error;
1321 return ctx->Eval.Map2Vertex4;
1322 case GL_NORMALIZE:
1323 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1324 goto invalid_enum_error;
1325 return ctx->Transform.Normalize;
1326 case GL_POINT_SMOOTH:
1327 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1328 goto invalid_enum_error;
1329 return ctx->Point.SmoothFlag;
1330 case GL_POLYGON_SMOOTH:
1331 if (!_mesa_is_desktop_gl(ctx))
1332 goto invalid_enum_error;
1333 return ctx->Polygon.SmoothFlag;
1334 case GL_POLYGON_STIPPLE:
1335 if (ctx->API != API_OPENGL_COMPAT)
1336 goto invalid_enum_error;
1337 return ctx->Polygon.StippleFlag;
1338 case GL_POLYGON_OFFSET_POINT:
1339 if (!_mesa_is_desktop_gl(ctx))
1340 goto invalid_enum_error;
1341 return ctx->Polygon.OffsetPoint;
1342 case GL_POLYGON_OFFSET_LINE:
1343 if (!_mesa_is_desktop_gl(ctx))
1344 goto invalid_enum_error;
1345 return ctx->Polygon.OffsetLine;
1346 case GL_POLYGON_OFFSET_FILL:
1347 return ctx->Polygon.OffsetFill;
1348 case GL_RESCALE_NORMAL_EXT:
1349 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1350 goto invalid_enum_error;
1351 return ctx->Transform.RescaleNormals;
1352 case GL_SCISSOR_TEST:
1353 return ctx->Scissor.Enabled;
1354 case GL_STENCIL_TEST:
1355 return ctx->Stencil.Enabled;
1356 case GL_TEXTURE_1D:
1357 if (ctx->API != API_OPENGL_COMPAT)
1358 goto invalid_enum_error;
1359 return is_texture_enabled(ctx, TEXTURE_1D_BIT);
1360 case GL_TEXTURE_2D:
1361 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1362 goto invalid_enum_error;
1363 return is_texture_enabled(ctx, TEXTURE_2D_BIT);
1364 case GL_TEXTURE_3D:
1365 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1366 goto invalid_enum_error;
1367 return is_texture_enabled(ctx, TEXTURE_3D_BIT);
1368 case GL_TEXTURE_GEN_S:
1369 case GL_TEXTURE_GEN_T:
1370 case GL_TEXTURE_GEN_R:
1371 case GL_TEXTURE_GEN_Q:
1372 {
1373 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1374
1375 if (ctx->API != API_OPENGL_COMPAT)
1376 goto invalid_enum_error;
1377
1378 if (texUnit) {
1379 GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
1380 return (texUnit->TexGenEnabled & coordBit) ? GL_TRUE : GL_FALSE;
1381 }
1382 }
1383 return GL_FALSE;
1384 case GL_TEXTURE_GEN_STR_OES:
1385 {
1386 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1387
1388 if (ctx->API != API_OPENGLES)
1389 goto invalid_enum_error;
1390
1391 if (texUnit) {
1392 return (texUnit->TexGenEnabled & STR_BITS) == STR_BITS
1393 ? GL_TRUE : GL_FALSE;
1394 }
1395 }
1396
1397 /* client-side state */
1398 case GL_VERTEX_ARRAY:
1399 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1400 goto invalid_enum_error;
1401 return ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POS].Enabled;
1402 case GL_NORMAL_ARRAY:
1403 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1404 goto invalid_enum_error;
1405 return ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled;
1406 case GL_COLOR_ARRAY:
1407 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1408 goto invalid_enum_error;
1409 return ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled;
1410 case GL_INDEX_ARRAY:
1411 if (ctx->API != API_OPENGL_COMPAT)
1412 goto invalid_enum_error;
1413 return ctx->Array.ArrayObj->
1414 VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled;
1415 case GL_TEXTURE_COORD_ARRAY:
1416 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1417 goto invalid_enum_error;
1418 return ctx->Array.ArrayObj->
1419 VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Enabled;
1420 case GL_EDGE_FLAG_ARRAY:
1421 if (ctx->API != API_OPENGL_COMPAT)
1422 goto invalid_enum_error;
1423 return ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled;
1424 case GL_FOG_COORDINATE_ARRAY_EXT:
1425 if (ctx->API != API_OPENGL_COMPAT)
1426 goto invalid_enum_error;
1427 return ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_FOG].Enabled;
1428 case GL_SECONDARY_COLOR_ARRAY_EXT:
1429 if (ctx->API != API_OPENGL_COMPAT)
1430 goto invalid_enum_error;
1431 return ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled;
1432 case GL_POINT_SIZE_ARRAY_OES:
1433 if (ctx->API != API_OPENGLES)
1434 goto invalid_enum_error;
1435 return ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled;
1436
1437 /* GL_ARB_texture_cube_map */
1438 case GL_TEXTURE_CUBE_MAP_ARB:
1439 CHECK_EXTENSION(ARB_texture_cube_map);
1440 return is_texture_enabled(ctx, TEXTURE_CUBE_BIT);
1441
1442 /* GL_EXT_secondary_color */
1443 case GL_COLOR_SUM_EXT:
1444 if (ctx->API != API_OPENGL_COMPAT)
1445 goto invalid_enum_error;
1446 CHECK_EXTENSION(ARB_vertex_program);
1447 return ctx->Fog.ColorSumEnabled;
1448
1449 /* GL_ARB_multisample */
1450 case GL_MULTISAMPLE_ARB:
1451 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1452 goto invalid_enum_error;
1453 return ctx->Multisample.Enabled;
1454 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
1455 return ctx->Multisample.SampleAlphaToCoverage;
1456 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
1457 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1458 goto invalid_enum_error;
1459 return ctx->Multisample.SampleAlphaToOne;
1460 case GL_SAMPLE_COVERAGE_ARB:
1461 return ctx->Multisample.SampleCoverage;
1462 case GL_SAMPLE_COVERAGE_INVERT_ARB:
1463 if (!_mesa_is_desktop_gl(ctx))
1464 goto invalid_enum_error;
1465 return ctx->Multisample.SampleCoverageInvert;
1466
1467 /* GL_IBM_rasterpos_clip */
1468 case GL_RASTER_POSITION_UNCLIPPED_IBM:
1469 if (ctx->API != API_OPENGL_COMPAT)
1470 goto invalid_enum_error;
1471 return ctx->Transform.RasterPositionUnclipped;
1472
1473 /* GL_NV_point_sprite */
1474 case GL_POINT_SPRITE_NV:
1475 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1476 goto invalid_enum_error;
1477 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite)
1478 return ctx->Point.PointSprite;
1479
1480 case GL_VERTEX_PROGRAM_ARB:
1481 if (ctx->API != API_OPENGL_COMPAT)
1482 goto invalid_enum_error;
1483 CHECK_EXTENSION(ARB_vertex_program);
1484 return ctx->VertexProgram.Enabled;
1485 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
1486 /* This was added with ARB_vertex_program, but it is also used with
1487 * GLSL vertex shaders on desktop.
1488 */
1489 if (!_mesa_is_desktop_gl(ctx))
1490 goto invalid_enum_error;
1491 CHECK_EXTENSION(ARB_vertex_program);
1492 return ctx->VertexProgram.PointSizeEnabled;
1493 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
1494 if (ctx->API != API_OPENGL_COMPAT)
1495 goto invalid_enum_error;
1496 CHECK_EXTENSION(ARB_vertex_program);
1497 return ctx->VertexProgram.TwoSideEnabled;
1498
1499 /* GL_NV_texture_rectangle */
1500 case GL_TEXTURE_RECTANGLE_NV:
1501 if (ctx->API != API_OPENGL_COMPAT)
1502 goto invalid_enum_error;
1503 CHECK_EXTENSION(NV_texture_rectangle);
1504 return is_texture_enabled(ctx, TEXTURE_RECT_BIT);
1505
1506 /* GL_EXT_stencil_two_side */
1507 case GL_STENCIL_TEST_TWO_SIDE_EXT:
1508 if (ctx->API != API_OPENGL_COMPAT)
1509 goto invalid_enum_error;
1510 CHECK_EXTENSION(EXT_stencil_two_side);
1511 return ctx->Stencil.TestTwoSide;
1512
1513 case GL_FRAGMENT_PROGRAM_ARB:
1514 if (ctx->API != API_OPENGL_COMPAT)
1515 goto invalid_enum_error;
1516 return ctx->FragmentProgram.Enabled;
1517
1518 /* GL_EXT_depth_bounds_test */
1519 case GL_DEPTH_BOUNDS_TEST_EXT:
1520 if (!_mesa_is_desktop_gl(ctx))
1521 goto invalid_enum_error;
1522 CHECK_EXTENSION(EXT_depth_bounds_test);
1523 return ctx->Depth.BoundsTest;
1524
1525 /* GL_ARB_depth_clamp */
1526 case GL_DEPTH_CLAMP:
1527 if (!_mesa_is_desktop_gl(ctx))
1528 goto invalid_enum_error;
1529 CHECK_EXTENSION(ARB_depth_clamp);
1530 return ctx->Transform.DepthClamp;
1531
1532 case GL_FRAGMENT_SHADER_ATI:
1533 if (ctx->API != API_OPENGL_COMPAT)
1534 goto invalid_enum_error;
1535 CHECK_EXTENSION(ATI_fragment_shader);
1536 return ctx->ATIFragmentShader.Enabled;
1537
1538 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1539 if (!_mesa_is_desktop_gl(ctx))
1540 goto invalid_enum_error;
1541 CHECK_EXTENSION(ARB_seamless_cube_map);
1542 return ctx->Texture.CubeMapSeamless;
1543
1544 case GL_RASTERIZER_DISCARD:
1545 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1546 goto invalid_enum_error;
1547 CHECK_EXTENSION(EXT_transform_feedback);
1548 return ctx->RasterDiscard;
1549
1550 /* GL_NV_primitive_restart */
1551 case GL_PRIMITIVE_RESTART_NV:
1552 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.NV_primitive_restart) {
1553 goto invalid_enum_error;
1554 }
1555 return ctx->Array.PrimitiveRestart;
1556
1557 /* GL 3.1 primitive restart */
1558 case GL_PRIMITIVE_RESTART:
1559 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
1560 goto invalid_enum_error;
1561 }
1562 return ctx->Array.PrimitiveRestart;
1563
1564 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
1565 if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility) {
1566 goto invalid_enum_error;
1567 }
1568 return ctx->Array.PrimitiveRestartFixedIndex;
1569
1570 /* GL3.0 - GL_framebuffer_sRGB */
1571 case GL_FRAMEBUFFER_SRGB_EXT:
1572 if (!_mesa_is_desktop_gl(ctx))
1573 goto invalid_enum_error;
1574 CHECK_EXTENSION(EXT_framebuffer_sRGB);
1575 return ctx->Color.sRGBEnabled;
1576
1577 /* GL_OES_EGL_image_external */
1578 case GL_TEXTURE_EXTERNAL_OES:
1579 if (!_mesa_is_gles(ctx))
1580 goto invalid_enum_error;
1581 CHECK_EXTENSION(OES_EGL_image_external);
1582 return is_texture_enabled(ctx, TEXTURE_EXTERNAL_BIT);
1583
1584 /* ARB_texture_multisample */
1585 case GL_SAMPLE_MASK:
1586 if (!_mesa_is_desktop_gl(ctx))
1587 goto invalid_enum_error;
1588 CHECK_EXTENSION(ARB_texture_multisample);
1589 return ctx->Multisample.SampleMask;
1590
1591 /* ARB_sample_shading */
1592 case GL_SAMPLE_SHADING:
1593 if (!_mesa_is_desktop_gl(ctx))
1594 goto invalid_enum_error;
1595 CHECK_EXTENSION(ARB_sample_shading);
1596 return ctx->Multisample.SampleShading;
1597
1598 default:
1599 goto invalid_enum_error;
1600 }
1601
1602 return GL_FALSE;
1603
1604 invalid_enum_error:
1605 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(%s)",
1606 _mesa_lookup_enum_by_nr(cap));
1607 return GL_FALSE;
1608 }