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