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