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