meta: Refactor handling of GL_MULTISAMPLE.
[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 /**
52 * Helper to enable/disable client-side state.
53 */
54 static void
55 client_state(struct gl_context *ctx, GLenum cap, GLboolean state)
56 {
57 struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
58 GLbitfield64 flag;
59 GLboolean *var;
60
61 switch (cap) {
62 case GL_VERTEX_ARRAY:
63 var = &arrayObj->VertexAttrib[VERT_ATTRIB_POS].Enabled;
64 flag = VERT_BIT_POS;
65 break;
66 case GL_NORMAL_ARRAY:
67 var = &arrayObj->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled;
68 flag = VERT_BIT_NORMAL;
69 break;
70 case GL_COLOR_ARRAY:
71 var = &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled;
72 flag = VERT_BIT_COLOR0;
73 break;
74 case GL_INDEX_ARRAY:
75 var = &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled;
76 flag = VERT_BIT_COLOR_INDEX;
77 break;
78 case GL_TEXTURE_COORD_ARRAY:
79 var = &arrayObj->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Enabled;
80 flag = VERT_BIT_TEX(ctx->Array.ActiveTexture);
81 break;
82 case GL_EDGE_FLAG_ARRAY:
83 var = &arrayObj->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled;
84 flag = VERT_BIT_EDGEFLAG;
85 break;
86 case GL_FOG_COORDINATE_ARRAY_EXT:
87 var = &arrayObj->VertexAttrib[VERT_ATTRIB_FOG].Enabled;
88 flag = VERT_BIT_FOG;
89 break;
90 case GL_SECONDARY_COLOR_ARRAY_EXT:
91 var = &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled;
92 flag = VERT_BIT_COLOR1;
93 break;
94
95 #if FEATURE_point_size_array
96 case GL_POINT_SIZE_ARRAY_OES:
97 var = &arrayObj->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled;
98 flag = VERT_BIT_POINT_SIZE;
99 break;
100 #endif
101
102 #if FEATURE_NV_vertex_program
103 case GL_VERTEX_ATTRIB_ARRAY0_NV:
104 case GL_VERTEX_ATTRIB_ARRAY1_NV:
105 case GL_VERTEX_ATTRIB_ARRAY2_NV:
106 case GL_VERTEX_ATTRIB_ARRAY3_NV:
107 case GL_VERTEX_ATTRIB_ARRAY4_NV:
108 case GL_VERTEX_ATTRIB_ARRAY5_NV:
109 case GL_VERTEX_ATTRIB_ARRAY6_NV:
110 case GL_VERTEX_ATTRIB_ARRAY7_NV:
111 case GL_VERTEX_ATTRIB_ARRAY8_NV:
112 case GL_VERTEX_ATTRIB_ARRAY9_NV:
113 case GL_VERTEX_ATTRIB_ARRAY10_NV:
114 case GL_VERTEX_ATTRIB_ARRAY11_NV:
115 case GL_VERTEX_ATTRIB_ARRAY12_NV:
116 case GL_VERTEX_ATTRIB_ARRAY13_NV:
117 case GL_VERTEX_ATTRIB_ARRAY14_NV:
118 case GL_VERTEX_ATTRIB_ARRAY15_NV:
119 CHECK_EXTENSION(NV_vertex_program, cap);
120 {
121 GLint n = (GLint) cap - GL_VERTEX_ATTRIB_ARRAY0_NV;
122 ASSERT(VERT_ATTRIB_GENERIC(n) < Elements(arrayObj->VertexAttrib));
123 var = &arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(n)].Enabled;
124 flag = VERT_BIT_GENERIC(n);
125 }
126 break;
127 #endif /* FEATURE_NV_vertex_program */
128
129 /* GL_NV_primitive_restart */
130 case GL_PRIMITIVE_RESTART_NV:
131 if (!ctx->Extensions.NV_primitive_restart) {
132 goto invalid_enum_error;
133 }
134 var = &ctx->Array.PrimitiveRestart;
135 flag = 0;
136 break;
137
138 default:
139 goto invalid_enum_error;
140 }
141
142 if (*var == state)
143 return;
144
145 FLUSH_VERTICES(ctx, _NEW_ARRAY);
146
147 _ae_invalidate_state(ctx, _NEW_ARRAY);
148
149 *var = state;
150
151 if (state)
152 arrayObj->_Enabled |= flag;
153 else
154 arrayObj->_Enabled &= ~flag;
155
156 arrayObj->NewArrays |= flag;
157
158 if (ctx->Driver.Enable) {
159 ctx->Driver.Enable( ctx, cap, state );
160 }
161
162 return;
163
164 invalid_enum_error:
165 _mesa_error(ctx, GL_INVALID_ENUM, "gl%sClientState(%s)",
166 state ? "Enable" : "Disable", _mesa_lookup_enum_by_nr(cap));
167 }
168
169
170 /**
171 * Enable GL capability.
172 * \param cap state to enable/disable.
173 *
174 * Get's the current context, assures that we're outside glBegin()/glEnd() and
175 * calls client_state().
176 */
177 void GLAPIENTRY
178 _mesa_EnableClientState( GLenum cap )
179 {
180 GET_CURRENT_CONTEXT(ctx);
181 ASSERT_OUTSIDE_BEGIN_END(ctx);
182 client_state( ctx, cap, GL_TRUE );
183 }
184
185
186 /**
187 * Disable GL capability.
188 * \param cap state to enable/disable.
189 *
190 * Get's the current context, assures that we're outside glBegin()/glEnd() and
191 * calls client_state().
192 */
193 void GLAPIENTRY
194 _mesa_DisableClientState( GLenum cap )
195 {
196 GET_CURRENT_CONTEXT(ctx);
197 ASSERT_OUTSIDE_BEGIN_END(ctx);
198 client_state( ctx, cap, GL_FALSE );
199 }
200
201
202 #undef CHECK_EXTENSION
203 #define CHECK_EXTENSION(EXTNAME, CAP) \
204 if (!ctx->Extensions.EXTNAME) { \
205 goto invalid_enum_error; \
206 }
207
208 #define CHECK_EXTENSION2(EXT1, EXT2, CAP) \
209 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
210 goto invalid_enum_error; \
211 }
212
213 /**
214 * Return pointer to current texture unit for setting/getting coordinate
215 * state.
216 * Note that we'll set GL_INVALID_OPERATION and return NULL if the active
217 * texture unit is higher than the number of supported coordinate units.
218 */
219 static struct gl_texture_unit *
220 get_texcoord_unit(struct gl_context *ctx)
221 {
222 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
223 _mesa_error(ctx, GL_INVALID_OPERATION, "glEnable/Disable(texcoord unit)");
224 return NULL;
225 }
226 else {
227 return &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
228 }
229 }
230
231
232 /**
233 * Helper function to enable or disable a texture target.
234 * \param bit one of the TEXTURE_x_BIT values
235 * \return GL_TRUE if state is changing or GL_FALSE if no change
236 */
237 static GLboolean
238 enable_texture(struct gl_context *ctx, GLboolean state, GLbitfield texBit)
239 {
240 struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
241 const GLbitfield newenabled = state
242 ? (texUnit->Enabled | texBit) : (texUnit->Enabled & ~texBit);
243
244 if (texUnit->Enabled == newenabled)
245 return GL_FALSE;
246
247 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
248 texUnit->Enabled = newenabled;
249 return GL_TRUE;
250 }
251
252
253 /**
254 * Helper function to enable or disable GL_MULTISAMPLE, skipping the check for
255 * whether the API supports it (GLES doesn't).
256 */
257 void
258 _mesa_set_multisample(struct gl_context *ctx, GLboolean state)
259 {
260 if (ctx->Multisample.Enabled == state)
261 return;
262 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
263 ctx->Multisample.Enabled = state;
264
265 if (ctx->Driver.Enable) {
266 ctx->Driver.Enable(ctx, GL_MULTISAMPLE, state);
267 }
268 }
269
270 /**
271 * Helper function to enable or disable state.
272 *
273 * \param ctx GL context.
274 * \param cap the state to enable/disable
275 * \param state whether to enable or disable the specified capability.
276 *
277 * Updates the current context and flushes the vertices as needed. For
278 * capabilities associated with extensions it verifies that those extensions
279 * are effectivly present before updating. Notifies the driver via
280 * dd_function_table::Enable.
281 */
282 void
283 _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
284 {
285 if (MESA_VERBOSE & VERBOSE_API)
286 _mesa_debug(ctx, "%s %s (newstate is %x)\n",
287 state ? "glEnable" : "glDisable",
288 _mesa_lookup_enum_by_nr(cap),
289 ctx->NewState);
290
291 switch (cap) {
292 case GL_ALPHA_TEST:
293 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
294 goto invalid_enum_error;
295 if (ctx->Color.AlphaEnabled == state)
296 return;
297 FLUSH_VERTICES(ctx, _NEW_COLOR);
298 ctx->Color.AlphaEnabled = state;
299 break;
300 case GL_AUTO_NORMAL:
301 if (ctx->API != API_OPENGL)
302 goto invalid_enum_error;
303 if (ctx->Eval.AutoNormal == state)
304 return;
305 FLUSH_VERTICES(ctx, _NEW_EVAL);
306 ctx->Eval.AutoNormal = state;
307 break;
308 case GL_BLEND:
309 {
310 GLbitfield newEnabled =
311 state * ((1 << ctx->Const.MaxDrawBuffers) - 1);
312 if (newEnabled != ctx->Color.BlendEnabled) {
313 FLUSH_VERTICES(ctx, _NEW_COLOR);
314 ctx->Color.BlendEnabled = newEnabled;
315 }
316 }
317 break;
318 #if FEATURE_userclip
319 case GL_CLIP_DISTANCE0:
320 case GL_CLIP_DISTANCE1:
321 case GL_CLIP_DISTANCE2:
322 case GL_CLIP_DISTANCE3:
323 case GL_CLIP_DISTANCE4:
324 case GL_CLIP_DISTANCE5:
325 case GL_CLIP_DISTANCE6:
326 case GL_CLIP_DISTANCE7:
327 {
328 const GLuint p = cap - GL_CLIP_DISTANCE0;
329
330 if (p >= ctx->Const.MaxClipPlanes)
331 goto invalid_enum_error;
332
333 if ((ctx->Transform.ClipPlanesEnabled & (1 << p))
334 == ((GLuint) state << p))
335 return;
336
337 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
338
339 if (state) {
340 ctx->Transform.ClipPlanesEnabled |= (1 << p);
341 _mesa_update_clip_plane(ctx, p);
342 }
343 else {
344 ctx->Transform.ClipPlanesEnabled &= ~(1 << p);
345 }
346 }
347 break;
348 #endif
349 case GL_COLOR_MATERIAL:
350 if (ctx->API != API_OPENGL && 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 && 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 && 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 && 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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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 && 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 && 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)
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 && 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)
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 && 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 && 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)
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 #if FEATURE_ES1
727 case GL_TEXTURE_GEN_STR_OES:
728 /* disable S, T, and R at the same time */
729 {
730 struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
731
732 if (ctx->API != API_OPENGLES)
733 goto invalid_enum_error;
734
735 if (texUnit) {
736 GLuint newenabled =
737 texUnit->TexGenEnabled & ~STR_BITS;
738 if (state)
739 newenabled |= STR_BITS;
740 if (texUnit->TexGenEnabled == newenabled)
741 return;
742 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
743 texUnit->TexGenEnabled = newenabled;
744 }
745 }
746 break;
747 #endif
748
749 /* client-side state */
750 case GL_VERTEX_ARRAY:
751 case GL_NORMAL_ARRAY:
752 case GL_COLOR_ARRAY:
753 case GL_INDEX_ARRAY:
754 case GL_TEXTURE_COORD_ARRAY:
755 case GL_EDGE_FLAG_ARRAY:
756 case GL_FOG_COORDINATE_ARRAY_EXT:
757 case GL_SECONDARY_COLOR_ARRAY_EXT:
758 case GL_POINT_SIZE_ARRAY_OES:
759 client_state( ctx, cap, state );
760 return;
761
762 /* GL_ARB_texture_cube_map */
763 case GL_TEXTURE_CUBE_MAP_ARB:
764 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
765 goto invalid_enum_error;
766 CHECK_EXTENSION(ARB_texture_cube_map, cap);
767 if (!enable_texture(ctx, state, TEXTURE_CUBE_BIT)) {
768 return;
769 }
770 break;
771
772 /* GL_EXT_secondary_color */
773 case GL_COLOR_SUM_EXT:
774 if (ctx->API != API_OPENGL)
775 goto invalid_enum_error;
776 CHECK_EXTENSION2(EXT_secondary_color, ARB_vertex_program, cap);
777 if (ctx->Fog.ColorSumEnabled == state)
778 return;
779 FLUSH_VERTICES(ctx, _NEW_FOG);
780 ctx->Fog.ColorSumEnabled = state;
781 break;
782
783 /* GL_ARB_multisample */
784 case GL_MULTISAMPLE_ARB:
785 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
786 goto invalid_enum_error;
787 _mesa_set_multisample(ctx, state);
788 return;
789 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
790 if (ctx->Multisample.SampleAlphaToCoverage == state)
791 return;
792 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
793 ctx->Multisample.SampleAlphaToCoverage = state;
794 break;
795 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
796 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
797 goto invalid_enum_error;
798 if (ctx->Multisample.SampleAlphaToOne == state)
799 return;
800 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
801 ctx->Multisample.SampleAlphaToOne = state;
802 break;
803 case GL_SAMPLE_COVERAGE_ARB:
804 if (ctx->Multisample.SampleCoverage == state)
805 return;
806 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
807 ctx->Multisample.SampleCoverage = state;
808 break;
809 case GL_SAMPLE_COVERAGE_INVERT_ARB:
810 if (!_mesa_is_desktop_gl(ctx))
811 goto invalid_enum_error;
812 if (ctx->Multisample.SampleCoverageInvert == state)
813 return;
814 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
815 ctx->Multisample.SampleCoverageInvert = state;
816 break;
817
818 /* GL_IBM_rasterpos_clip */
819 case GL_RASTER_POSITION_UNCLIPPED_IBM:
820 if (ctx->API != API_OPENGL)
821 goto invalid_enum_error;
822 CHECK_EXTENSION(IBM_rasterpos_clip, cap);
823 if (ctx->Transform.RasterPositionUnclipped == state)
824 return;
825 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
826 ctx->Transform.RasterPositionUnclipped = state;
827 break;
828
829 /* GL_NV_point_sprite */
830 case GL_POINT_SPRITE_NV:
831 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
832 goto invalid_enum_error;
833 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite, cap);
834 if (ctx->Point.PointSprite == state)
835 return;
836 FLUSH_VERTICES(ctx, _NEW_POINT);
837 ctx->Point.PointSprite = state;
838 break;
839
840 #if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program
841 case GL_VERTEX_PROGRAM_ARB:
842 if (ctx->API != API_OPENGL)
843 goto invalid_enum_error;
844 CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program, cap);
845 if (ctx->VertexProgram.Enabled == state)
846 return;
847 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
848 ctx->VertexProgram.Enabled = state;
849 break;
850 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
851 /* This was added with ARB_vertex_program, but it is also used with
852 * GLSL vertex shaders on desktop.
853 */
854 if (!_mesa_is_desktop_gl(ctx))
855 goto invalid_enum_error;
856 CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program, cap);
857 if (ctx->VertexProgram.PointSizeEnabled == state)
858 return;
859 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
860 ctx->VertexProgram.PointSizeEnabled = state;
861 break;
862 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
863 if (ctx->API != API_OPENGL)
864 goto invalid_enum_error;
865 CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program, cap);
866 if (ctx->VertexProgram.TwoSideEnabled == state)
867 return;
868 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
869 ctx->VertexProgram.TwoSideEnabled = state;
870 break;
871 #endif
872 #if FEATURE_NV_vertex_program
873 case GL_MAP1_VERTEX_ATTRIB0_4_NV:
874 case GL_MAP1_VERTEX_ATTRIB1_4_NV:
875 case GL_MAP1_VERTEX_ATTRIB2_4_NV:
876 case GL_MAP1_VERTEX_ATTRIB3_4_NV:
877 case GL_MAP1_VERTEX_ATTRIB4_4_NV:
878 case GL_MAP1_VERTEX_ATTRIB5_4_NV:
879 case GL_MAP1_VERTEX_ATTRIB6_4_NV:
880 case GL_MAP1_VERTEX_ATTRIB7_4_NV:
881 case GL_MAP1_VERTEX_ATTRIB8_4_NV:
882 case GL_MAP1_VERTEX_ATTRIB9_4_NV:
883 case GL_MAP1_VERTEX_ATTRIB10_4_NV:
884 case GL_MAP1_VERTEX_ATTRIB11_4_NV:
885 case GL_MAP1_VERTEX_ATTRIB12_4_NV:
886 case GL_MAP1_VERTEX_ATTRIB13_4_NV:
887 case GL_MAP1_VERTEX_ATTRIB14_4_NV:
888 case GL_MAP1_VERTEX_ATTRIB15_4_NV:
889 if (ctx->API != API_OPENGL)
890 goto invalid_enum_error;
891 CHECK_EXTENSION(NV_vertex_program, cap);
892 {
893 const GLuint map = (GLuint) (cap - GL_MAP1_VERTEX_ATTRIB0_4_NV);
894 FLUSH_VERTICES(ctx, _NEW_EVAL);
895 ctx->Eval.Map1Attrib[map] = state;
896 }
897 break;
898 case GL_MAP2_VERTEX_ATTRIB0_4_NV:
899 case GL_MAP2_VERTEX_ATTRIB1_4_NV:
900 case GL_MAP2_VERTEX_ATTRIB2_4_NV:
901 case GL_MAP2_VERTEX_ATTRIB3_4_NV:
902 case GL_MAP2_VERTEX_ATTRIB4_4_NV:
903 case GL_MAP2_VERTEX_ATTRIB5_4_NV:
904 case GL_MAP2_VERTEX_ATTRIB6_4_NV:
905 case GL_MAP2_VERTEX_ATTRIB7_4_NV:
906 case GL_MAP2_VERTEX_ATTRIB8_4_NV:
907 case GL_MAP2_VERTEX_ATTRIB9_4_NV:
908 case GL_MAP2_VERTEX_ATTRIB10_4_NV:
909 case GL_MAP2_VERTEX_ATTRIB11_4_NV:
910 case GL_MAP2_VERTEX_ATTRIB12_4_NV:
911 case GL_MAP2_VERTEX_ATTRIB13_4_NV:
912 case GL_MAP2_VERTEX_ATTRIB14_4_NV:
913 case GL_MAP2_VERTEX_ATTRIB15_4_NV:
914 if (ctx->API != API_OPENGL)
915 goto invalid_enum_error;
916 CHECK_EXTENSION(NV_vertex_program, cap);
917 {
918 const GLuint map = (GLuint) (cap - GL_MAP2_VERTEX_ATTRIB0_4_NV);
919 FLUSH_VERTICES(ctx, _NEW_EVAL);
920 ctx->Eval.Map2Attrib[map] = state;
921 }
922 break;
923 #endif /* FEATURE_NV_vertex_program */
924
925 #if FEATURE_NV_fragment_program
926 case GL_FRAGMENT_PROGRAM_NV:
927 if (ctx->API != API_OPENGL)
928 goto invalid_enum_error;
929 CHECK_EXTENSION(NV_fragment_program, cap);
930 if (ctx->FragmentProgram.Enabled == state)
931 return;
932 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
933 ctx->FragmentProgram.Enabled = state;
934 break;
935 #endif /* FEATURE_NV_fragment_program */
936
937 /* GL_NV_texture_rectangle */
938 case GL_TEXTURE_RECTANGLE_NV:
939 if (ctx->API != API_OPENGL)
940 goto invalid_enum_error;
941 CHECK_EXTENSION(NV_texture_rectangle, cap);
942 if (!enable_texture(ctx, state, TEXTURE_RECT_BIT)) {
943 return;
944 }
945 break;
946
947 /* GL_EXT_stencil_two_side */
948 case GL_STENCIL_TEST_TWO_SIDE_EXT:
949 if (ctx->API != API_OPENGL)
950 goto invalid_enum_error;
951 CHECK_EXTENSION(EXT_stencil_two_side, cap);
952 if (ctx->Stencil.TestTwoSide == state)
953 return;
954 FLUSH_VERTICES(ctx, _NEW_STENCIL);
955 ctx->Stencil.TestTwoSide = state;
956 if (state) {
957 ctx->Stencil._BackFace = 2;
958 } else {
959 ctx->Stencil._BackFace = 1;
960 }
961 break;
962
963 #if FEATURE_ARB_fragment_program
964 case GL_FRAGMENT_PROGRAM_ARB:
965 if (ctx->API != API_OPENGL)
966 goto invalid_enum_error;
967 CHECK_EXTENSION(ARB_fragment_program, cap);
968 if (ctx->FragmentProgram.Enabled == state)
969 return;
970 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
971 ctx->FragmentProgram.Enabled = state;
972 break;
973 #endif /* FEATURE_ARB_fragment_program */
974
975 /* GL_EXT_depth_bounds_test */
976 case GL_DEPTH_BOUNDS_TEST_EXT:
977 if (!_mesa_is_desktop_gl(ctx))
978 goto invalid_enum_error;
979 CHECK_EXTENSION(EXT_depth_bounds_test, cap);
980 if (ctx->Depth.BoundsTest == state)
981 return;
982 FLUSH_VERTICES(ctx, _NEW_DEPTH);
983 ctx->Depth.BoundsTest = state;
984 break;
985
986 case GL_DEPTH_CLAMP:
987 if (!_mesa_is_desktop_gl(ctx))
988 goto invalid_enum_error;
989 CHECK_EXTENSION(ARB_depth_clamp, cap);
990 if (ctx->Transform.DepthClamp == state)
991 return;
992 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
993 ctx->Transform.DepthClamp = state;
994 break;
995
996 #if FEATURE_ATI_fragment_shader
997 case GL_FRAGMENT_SHADER_ATI:
998 if (ctx->API != API_OPENGL)
999 goto invalid_enum_error;
1000 CHECK_EXTENSION(ATI_fragment_shader, cap);
1001 if (ctx->ATIFragmentShader.Enabled == state)
1002 return;
1003 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
1004 ctx->ATIFragmentShader.Enabled = state;
1005 break;
1006 #endif
1007
1008 /* GL_MESA_texture_array */
1009 case GL_TEXTURE_1D_ARRAY_EXT:
1010 if (ctx->API != API_OPENGL)
1011 goto invalid_enum_error;
1012 CHECK_EXTENSION(MESA_texture_array, cap);
1013 if (!enable_texture(ctx, state, TEXTURE_1D_ARRAY_BIT)) {
1014 return;
1015 }
1016 break;
1017
1018 case GL_TEXTURE_2D_ARRAY_EXT:
1019 if (ctx->API != API_OPENGL)
1020 goto invalid_enum_error;
1021 CHECK_EXTENSION(MESA_texture_array, cap);
1022 if (!enable_texture(ctx, state, TEXTURE_2D_ARRAY_BIT)) {
1023 return;
1024 }
1025 break;
1026
1027 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1028 if (!_mesa_is_desktop_gl(ctx))
1029 goto invalid_enum_error;
1030 CHECK_EXTENSION(ARB_seamless_cube_map, cap);
1031 if (ctx->Texture.CubeMapSeamless != state) {
1032 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1033 ctx->Texture.CubeMapSeamless = state;
1034 }
1035 break;
1036
1037 #if FEATURE_EXT_transform_feedback
1038 case GL_RASTERIZER_DISCARD:
1039 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1040 goto invalid_enum_error;
1041 CHECK_EXTENSION(EXT_transform_feedback, cap);
1042 if (ctx->RasterDiscard != state) {
1043 FLUSH_VERTICES(ctx, _NEW_RASTERIZER_DISCARD);
1044 ctx->RasterDiscard = state;
1045 }
1046 break;
1047 #endif
1048
1049 /* GL 3.1 primitive restart. Note: this enum is different from
1050 * GL_PRIMITIVE_RESTART_NV (which is client state).
1051 */
1052 case GL_PRIMITIVE_RESTART:
1053 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
1054 goto invalid_enum_error;
1055 }
1056 if (ctx->Array.PrimitiveRestart != state) {
1057 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
1058 ctx->Array.PrimitiveRestart = state;
1059 }
1060 break;
1061
1062 /* GL3.0 - GL_framebuffer_sRGB */
1063 case GL_FRAMEBUFFER_SRGB_EXT:
1064 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1065 goto invalid_enum_error;
1066 CHECK_EXTENSION(EXT_framebuffer_sRGB, cap);
1067 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
1068 ctx->Color.sRGBEnabled = state;
1069 break;
1070
1071 /* GL_OES_EGL_image_external */
1072 case GL_TEXTURE_EXTERNAL_OES:
1073 if (!_mesa_is_gles(ctx))
1074 goto invalid_enum_error;
1075 CHECK_EXTENSION(OES_EGL_image_external, cap);
1076 if (!enable_texture(ctx, state, TEXTURE_EXTERNAL_BIT)) {
1077 return;
1078 }
1079 break;
1080
1081 default:
1082 goto invalid_enum_error;
1083 }
1084
1085 if (ctx->Driver.Enable) {
1086 ctx->Driver.Enable( ctx, cap, state );
1087 }
1088
1089 return;
1090
1091 invalid_enum_error:
1092 _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(%s)",
1093 state ? "Enable" : "Disable", _mesa_lookup_enum_by_nr(cap));
1094 }
1095
1096
1097 /**
1098 * Enable GL capability. Called by glEnable()
1099 * \param cap state to enable.
1100 */
1101 void GLAPIENTRY
1102 _mesa_Enable( GLenum cap )
1103 {
1104 GET_CURRENT_CONTEXT(ctx);
1105 ASSERT_OUTSIDE_BEGIN_END(ctx);
1106
1107 _mesa_set_enable( ctx, cap, GL_TRUE );
1108 }
1109
1110
1111 /**
1112 * Disable GL capability. Called by glDisable()
1113 * \param cap state to disable.
1114 */
1115 void GLAPIENTRY
1116 _mesa_Disable( GLenum cap )
1117 {
1118 GET_CURRENT_CONTEXT(ctx);
1119 ASSERT_OUTSIDE_BEGIN_END(ctx);
1120
1121 _mesa_set_enable( ctx, cap, GL_FALSE );
1122 }
1123
1124
1125
1126 /**
1127 * Enable/disable an indexed state var.
1128 */
1129 void
1130 _mesa_set_enablei(struct gl_context *ctx, GLenum cap,
1131 GLuint index, GLboolean state)
1132 {
1133 ASSERT(state == 0 || state == 1);
1134 switch (cap) {
1135 case GL_BLEND:
1136 if (!ctx->Extensions.EXT_draw_buffers2) {
1137 goto invalid_enum_error;
1138 }
1139 if (index >= ctx->Const.MaxDrawBuffers) {
1140 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1141 state ? "glEnableIndexed" : "glDisableIndexed", index);
1142 return;
1143 }
1144 if (((ctx->Color.BlendEnabled >> index) & 1) != state) {
1145 FLUSH_VERTICES(ctx, _NEW_COLOR);
1146 if (state)
1147 ctx->Color.BlendEnabled |= (1 << index);
1148 else
1149 ctx->Color.BlendEnabled &= ~(1 << index);
1150 }
1151 break;
1152 default:
1153 goto invalid_enum_error;
1154 }
1155 return;
1156
1157 invalid_enum_error:
1158 _mesa_error(ctx, GL_INVALID_ENUM, "%s(cap=%s)",
1159 state ? "glEnablei" : "glDisablei",
1160 _mesa_lookup_enum_by_nr(cap));
1161 }
1162
1163
1164 void GLAPIENTRY
1165 _mesa_DisableIndexed( GLenum cap, GLuint index )
1166 {
1167 GET_CURRENT_CONTEXT(ctx);
1168 ASSERT_OUTSIDE_BEGIN_END(ctx);
1169 _mesa_set_enablei(ctx, cap, index, GL_FALSE);
1170 }
1171
1172
1173 void GLAPIENTRY
1174 _mesa_EnableIndexed( GLenum cap, GLuint index )
1175 {
1176 GET_CURRENT_CONTEXT(ctx);
1177 ASSERT_OUTSIDE_BEGIN_END(ctx);
1178 _mesa_set_enablei(ctx, cap, index, GL_TRUE);
1179 }
1180
1181
1182 GLboolean GLAPIENTRY
1183 _mesa_IsEnabledIndexed( GLenum cap, GLuint index )
1184 {
1185 GET_CURRENT_CONTEXT(ctx);
1186 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1187 switch (cap) {
1188 case GL_BLEND:
1189 if (index >= ctx->Const.MaxDrawBuffers) {
1190 _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
1191 index);
1192 return GL_FALSE;
1193 }
1194 return (ctx->Color.BlendEnabled >> index) & 1;
1195 default:
1196 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabledIndexed(cap=%s)",
1197 _mesa_lookup_enum_by_nr(cap));
1198 return GL_FALSE;
1199 }
1200 }
1201
1202
1203
1204
1205 #undef CHECK_EXTENSION
1206 #define CHECK_EXTENSION(EXTNAME) \
1207 if (!ctx->Extensions.EXTNAME) { \
1208 goto invalid_enum_error; \
1209 }
1210
1211 #undef CHECK_EXTENSION2
1212 #define CHECK_EXTENSION2(EXT1, EXT2) \
1213 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1214 goto invalid_enum_error; \
1215 }
1216
1217
1218 /**
1219 * Helper function to determine whether a texture target is enabled.
1220 */
1221 static GLboolean
1222 is_texture_enabled(struct gl_context *ctx, GLbitfield bit)
1223 {
1224 const struct gl_texture_unit *const texUnit =
1225 &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1226 return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE;
1227 }
1228
1229
1230 /**
1231 * Return simple enable/disable state.
1232 *
1233 * \param cap state variable to query.
1234 *
1235 * Returns the state of the specified capability from the current GL context.
1236 * For the capabilities associated with extensions verifies that those
1237 * extensions are effectively present before reporting.
1238 */
1239 GLboolean GLAPIENTRY
1240 _mesa_IsEnabled( GLenum cap )
1241 {
1242 GET_CURRENT_CONTEXT(ctx);
1243 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1244
1245 switch (cap) {
1246 case GL_ALPHA_TEST:
1247 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1248 goto invalid_enum_error;
1249 return ctx->Color.AlphaEnabled;
1250 case GL_AUTO_NORMAL:
1251 if (ctx->API != API_OPENGL)
1252 goto invalid_enum_error;
1253 return ctx->Eval.AutoNormal;
1254 case GL_BLEND:
1255 return ctx->Color.BlendEnabled & 1; /* return state for buffer[0] */
1256 case GL_CLIP_DISTANCE0:
1257 case GL_CLIP_DISTANCE1:
1258 case GL_CLIP_DISTANCE2:
1259 case GL_CLIP_DISTANCE3:
1260 case GL_CLIP_DISTANCE4:
1261 case GL_CLIP_DISTANCE5:
1262 case GL_CLIP_DISTANCE6:
1263 case GL_CLIP_DISTANCE7: {
1264 const GLuint p = cap - GL_CLIP_DISTANCE0;
1265
1266 if (p >= ctx->Const.MaxClipPlanes)
1267 goto invalid_enum_error;
1268
1269 return (ctx->Transform.ClipPlanesEnabled >> p) & 1;
1270 }
1271 case GL_COLOR_MATERIAL:
1272 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1273 goto invalid_enum_error;
1274 return ctx->Light.ColorMaterialEnabled;
1275 case GL_CULL_FACE:
1276 return ctx->Polygon.CullFlag;
1277 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB:
1278 if (!_mesa_is_desktop_gl(ctx))
1279 goto invalid_enum_error;
1280 return ctx->Debug.SyncOutput;
1281 case GL_DEPTH_TEST:
1282 return ctx->Depth.Test;
1283 case GL_DITHER:
1284 return ctx->Color.DitherFlag;
1285 case GL_FOG:
1286 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1287 goto invalid_enum_error;
1288 return ctx->Fog.Enabled;
1289 case GL_LIGHTING:
1290 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1291 goto invalid_enum_error;
1292 return ctx->Light.Enabled;
1293 case GL_LIGHT0:
1294 case GL_LIGHT1:
1295 case GL_LIGHT2:
1296 case GL_LIGHT3:
1297 case GL_LIGHT4:
1298 case GL_LIGHT5:
1299 case GL_LIGHT6:
1300 case GL_LIGHT7:
1301 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1302 goto invalid_enum_error;
1303 return ctx->Light.Light[cap-GL_LIGHT0].Enabled;
1304 case GL_LINE_SMOOTH:
1305 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1306 goto invalid_enum_error;
1307 return ctx->Line.SmoothFlag;
1308 case GL_LINE_STIPPLE:
1309 if (ctx->API != API_OPENGL)
1310 goto invalid_enum_error;
1311 return ctx->Line.StippleFlag;
1312 case GL_INDEX_LOGIC_OP:
1313 if (ctx->API != API_OPENGL)
1314 goto invalid_enum_error;
1315 return ctx->Color.IndexLogicOpEnabled;
1316 case GL_COLOR_LOGIC_OP:
1317 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1318 goto invalid_enum_error;
1319 return ctx->Color.ColorLogicOpEnabled;
1320 case GL_MAP1_COLOR_4:
1321 if (ctx->API != API_OPENGL)
1322 goto invalid_enum_error;
1323 return ctx->Eval.Map1Color4;
1324 case GL_MAP1_INDEX:
1325 if (ctx->API != API_OPENGL)
1326 goto invalid_enum_error;
1327 return ctx->Eval.Map1Index;
1328 case GL_MAP1_NORMAL:
1329 if (ctx->API != API_OPENGL)
1330 goto invalid_enum_error;
1331 return ctx->Eval.Map1Normal;
1332 case GL_MAP1_TEXTURE_COORD_1:
1333 if (ctx->API != API_OPENGL)
1334 goto invalid_enum_error;
1335 return ctx->Eval.Map1TextureCoord1;
1336 case GL_MAP1_TEXTURE_COORD_2:
1337 if (ctx->API != API_OPENGL)
1338 goto invalid_enum_error;
1339 return ctx->Eval.Map1TextureCoord2;
1340 case GL_MAP1_TEXTURE_COORD_3:
1341 if (ctx->API != API_OPENGL)
1342 goto invalid_enum_error;
1343 return ctx->Eval.Map1TextureCoord3;
1344 case GL_MAP1_TEXTURE_COORD_4:
1345 if (ctx->API != API_OPENGL)
1346 goto invalid_enum_error;
1347 return ctx->Eval.Map1TextureCoord4;
1348 case GL_MAP1_VERTEX_3:
1349 if (ctx->API != API_OPENGL)
1350 goto invalid_enum_error;
1351 return ctx->Eval.Map1Vertex3;
1352 case GL_MAP1_VERTEX_4:
1353 if (ctx->API != API_OPENGL)
1354 goto invalid_enum_error;
1355 return ctx->Eval.Map1Vertex4;
1356 case GL_MAP2_COLOR_4:
1357 if (ctx->API != API_OPENGL)
1358 goto invalid_enum_error;
1359 return ctx->Eval.Map2Color4;
1360 case GL_MAP2_INDEX:
1361 if (ctx->API != API_OPENGL)
1362 goto invalid_enum_error;
1363 return ctx->Eval.Map2Index;
1364 case GL_MAP2_NORMAL:
1365 if (ctx->API != API_OPENGL)
1366 goto invalid_enum_error;
1367 return ctx->Eval.Map2Normal;
1368 case GL_MAP2_TEXTURE_COORD_1:
1369 if (ctx->API != API_OPENGL)
1370 goto invalid_enum_error;
1371 return ctx->Eval.Map2TextureCoord1;
1372 case GL_MAP2_TEXTURE_COORD_2:
1373 if (ctx->API != API_OPENGL)
1374 goto invalid_enum_error;
1375 return ctx->Eval.Map2TextureCoord2;
1376 case GL_MAP2_TEXTURE_COORD_3:
1377 if (ctx->API != API_OPENGL)
1378 goto invalid_enum_error;
1379 return ctx->Eval.Map2TextureCoord3;
1380 case GL_MAP2_TEXTURE_COORD_4:
1381 if (ctx->API != API_OPENGL)
1382 goto invalid_enum_error;
1383 return ctx->Eval.Map2TextureCoord4;
1384 case GL_MAP2_VERTEX_3:
1385 if (ctx->API != API_OPENGL)
1386 goto invalid_enum_error;
1387 return ctx->Eval.Map2Vertex3;
1388 case GL_MAP2_VERTEX_4:
1389 if (ctx->API != API_OPENGL)
1390 goto invalid_enum_error;
1391 return ctx->Eval.Map2Vertex4;
1392 case GL_NORMALIZE:
1393 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1394 goto invalid_enum_error;
1395 return ctx->Transform.Normalize;
1396 case GL_POINT_SMOOTH:
1397 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1398 goto invalid_enum_error;
1399 return ctx->Point.SmoothFlag;
1400 case GL_POLYGON_SMOOTH:
1401 if (!_mesa_is_desktop_gl(ctx))
1402 goto invalid_enum_error;
1403 return ctx->Polygon.SmoothFlag;
1404 case GL_POLYGON_STIPPLE:
1405 if (ctx->API != API_OPENGL)
1406 goto invalid_enum_error;
1407 return ctx->Polygon.StippleFlag;
1408 case GL_POLYGON_OFFSET_POINT:
1409 if (!_mesa_is_desktop_gl(ctx))
1410 goto invalid_enum_error;
1411 return ctx->Polygon.OffsetPoint;
1412 case GL_POLYGON_OFFSET_LINE:
1413 if (!_mesa_is_desktop_gl(ctx))
1414 goto invalid_enum_error;
1415 return ctx->Polygon.OffsetLine;
1416 case GL_POLYGON_OFFSET_FILL:
1417 return ctx->Polygon.OffsetFill;
1418 case GL_RESCALE_NORMAL_EXT:
1419 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1420 goto invalid_enum_error;
1421 return ctx->Transform.RescaleNormals;
1422 case GL_SCISSOR_TEST:
1423 return ctx->Scissor.Enabled;
1424 case GL_STENCIL_TEST:
1425 return ctx->Stencil.Enabled;
1426 case GL_TEXTURE_1D:
1427 if (ctx->API != API_OPENGL)
1428 goto invalid_enum_error;
1429 return is_texture_enabled(ctx, TEXTURE_1D_BIT);
1430 case GL_TEXTURE_2D:
1431 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1432 goto invalid_enum_error;
1433 return is_texture_enabled(ctx, TEXTURE_2D_BIT);
1434 case GL_TEXTURE_3D:
1435 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1436 goto invalid_enum_error;
1437 return is_texture_enabled(ctx, TEXTURE_3D_BIT);
1438 case GL_TEXTURE_GEN_S:
1439 case GL_TEXTURE_GEN_T:
1440 case GL_TEXTURE_GEN_R:
1441 case GL_TEXTURE_GEN_Q:
1442 {
1443 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1444
1445 if (ctx->API != API_OPENGL)
1446 goto invalid_enum_error;
1447
1448 if (texUnit) {
1449 GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
1450 return (texUnit->TexGenEnabled & coordBit) ? GL_TRUE : GL_FALSE;
1451 }
1452 }
1453 return GL_FALSE;
1454 #if FEATURE_ES1
1455 case GL_TEXTURE_GEN_STR_OES:
1456 {
1457 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1458
1459 if (ctx->API != API_OPENGLES)
1460 goto invalid_enum_error;
1461
1462 if (texUnit) {
1463 return (texUnit->TexGenEnabled & STR_BITS) == STR_BITS
1464 ? GL_TRUE : GL_FALSE;
1465 }
1466 }
1467 #endif
1468
1469 /* client-side state */
1470 case GL_VERTEX_ARRAY:
1471 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1472 goto invalid_enum_error;
1473 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POS].Enabled != 0);
1474 case GL_NORMAL_ARRAY:
1475 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1476 goto invalid_enum_error;
1477 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled != 0);
1478 case GL_COLOR_ARRAY:
1479 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1480 goto invalid_enum_error;
1481 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled != 0);
1482 case GL_INDEX_ARRAY:
1483 if (ctx->API != API_OPENGL)
1484 goto invalid_enum_error;
1485 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled != 0);
1486 case GL_TEXTURE_COORD_ARRAY:
1487 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1488 goto invalid_enum_error;
1489 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)]
1490 .Enabled != 0);
1491 case GL_EDGE_FLAG_ARRAY:
1492 if (ctx->API != API_OPENGL)
1493 goto invalid_enum_error;
1494 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled != 0);
1495 case GL_FOG_COORDINATE_ARRAY_EXT:
1496 if (ctx->API != API_OPENGL)
1497 goto invalid_enum_error;
1498 CHECK_EXTENSION(EXT_fog_coord);
1499 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_FOG].Enabled != 0);
1500 case GL_SECONDARY_COLOR_ARRAY_EXT:
1501 if (ctx->API != API_OPENGL)
1502 goto invalid_enum_error;
1503 CHECK_EXTENSION(EXT_secondary_color);
1504 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled != 0);
1505 #if FEATURE_point_size_array
1506 case GL_POINT_SIZE_ARRAY_OES:
1507 if (ctx->API != API_OPENGLES)
1508 goto invalid_enum_error;
1509 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled != 0);
1510 #endif
1511
1512 /* GL_ARB_texture_cube_map */
1513 case GL_TEXTURE_CUBE_MAP_ARB:
1514 CHECK_EXTENSION(ARB_texture_cube_map);
1515 return is_texture_enabled(ctx, TEXTURE_CUBE_BIT);
1516
1517 /* GL_EXT_secondary_color */
1518 case GL_COLOR_SUM_EXT:
1519 if (ctx->API != API_OPENGL)
1520 goto invalid_enum_error;
1521 CHECK_EXTENSION2(EXT_secondary_color, ARB_vertex_program);
1522 return ctx->Fog.ColorSumEnabled;
1523
1524 /* GL_ARB_multisample */
1525 case GL_MULTISAMPLE_ARB:
1526 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1527 goto invalid_enum_error;
1528 return ctx->Multisample.Enabled;
1529 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
1530 return ctx->Multisample.SampleAlphaToCoverage;
1531 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
1532 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1533 goto invalid_enum_error;
1534 return ctx->Multisample.SampleAlphaToOne;
1535 case GL_SAMPLE_COVERAGE_ARB:
1536 return ctx->Multisample.SampleCoverage;
1537 case GL_SAMPLE_COVERAGE_INVERT_ARB:
1538 if (!_mesa_is_desktop_gl(ctx))
1539 goto invalid_enum_error;
1540 return ctx->Multisample.SampleCoverageInvert;
1541
1542 /* GL_IBM_rasterpos_clip */
1543 case GL_RASTER_POSITION_UNCLIPPED_IBM:
1544 if (ctx->API != API_OPENGL)
1545 goto invalid_enum_error;
1546 CHECK_EXTENSION(IBM_rasterpos_clip);
1547 return ctx->Transform.RasterPositionUnclipped;
1548
1549 /* GL_NV_point_sprite */
1550 case GL_POINT_SPRITE_NV:
1551 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1552 goto invalid_enum_error;
1553 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite)
1554 return ctx->Point.PointSprite;
1555
1556 #if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program
1557 case GL_VERTEX_PROGRAM_ARB:
1558 if (ctx->API != API_OPENGL)
1559 goto invalid_enum_error;
1560 CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program);
1561 return ctx->VertexProgram.Enabled;
1562 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
1563 /* This was added with ARB_vertex_program, but it is also used with
1564 * GLSL vertex shaders on desktop.
1565 */
1566 if (!_mesa_is_desktop_gl(ctx))
1567 goto invalid_enum_error;
1568 CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program);
1569 return ctx->VertexProgram.PointSizeEnabled;
1570 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
1571 if (ctx->API != API_OPENGL)
1572 goto invalid_enum_error;
1573 CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program);
1574 return ctx->VertexProgram.TwoSideEnabled;
1575 #endif
1576 #if FEATURE_NV_vertex_program
1577 case GL_VERTEX_ATTRIB_ARRAY0_NV:
1578 case GL_VERTEX_ATTRIB_ARRAY1_NV:
1579 case GL_VERTEX_ATTRIB_ARRAY2_NV:
1580 case GL_VERTEX_ATTRIB_ARRAY3_NV:
1581 case GL_VERTEX_ATTRIB_ARRAY4_NV:
1582 case GL_VERTEX_ATTRIB_ARRAY5_NV:
1583 case GL_VERTEX_ATTRIB_ARRAY6_NV:
1584 case GL_VERTEX_ATTRIB_ARRAY7_NV:
1585 case GL_VERTEX_ATTRIB_ARRAY8_NV:
1586 case GL_VERTEX_ATTRIB_ARRAY9_NV:
1587 case GL_VERTEX_ATTRIB_ARRAY10_NV:
1588 case GL_VERTEX_ATTRIB_ARRAY11_NV:
1589 case GL_VERTEX_ATTRIB_ARRAY12_NV:
1590 case GL_VERTEX_ATTRIB_ARRAY13_NV:
1591 case GL_VERTEX_ATTRIB_ARRAY14_NV:
1592 case GL_VERTEX_ATTRIB_ARRAY15_NV:
1593 if (ctx->API != API_OPENGL)
1594 goto invalid_enum_error;
1595 CHECK_EXTENSION(NV_vertex_program);
1596 {
1597 GLint n = (GLint) cap - GL_VERTEX_ATTRIB_ARRAY0_NV;
1598 ASSERT(VERT_ATTRIB_GENERIC(n) < Elements(ctx->Array.ArrayObj->VertexAttrib));
1599 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(n)].Enabled != 0);
1600 }
1601 case GL_MAP1_VERTEX_ATTRIB0_4_NV:
1602 case GL_MAP1_VERTEX_ATTRIB1_4_NV:
1603 case GL_MAP1_VERTEX_ATTRIB2_4_NV:
1604 case GL_MAP1_VERTEX_ATTRIB3_4_NV:
1605 case GL_MAP1_VERTEX_ATTRIB4_4_NV:
1606 case GL_MAP1_VERTEX_ATTRIB5_4_NV:
1607 case GL_MAP1_VERTEX_ATTRIB6_4_NV:
1608 case GL_MAP1_VERTEX_ATTRIB7_4_NV:
1609 case GL_MAP1_VERTEX_ATTRIB8_4_NV:
1610 case GL_MAP1_VERTEX_ATTRIB9_4_NV:
1611 case GL_MAP1_VERTEX_ATTRIB10_4_NV:
1612 case GL_MAP1_VERTEX_ATTRIB11_4_NV:
1613 case GL_MAP1_VERTEX_ATTRIB12_4_NV:
1614 case GL_MAP1_VERTEX_ATTRIB13_4_NV:
1615 case GL_MAP1_VERTEX_ATTRIB14_4_NV:
1616 case GL_MAP1_VERTEX_ATTRIB15_4_NV:
1617 if (ctx->API != API_OPENGL)
1618 goto invalid_enum_error;
1619 CHECK_EXTENSION(NV_vertex_program);
1620 {
1621 const GLuint map = (GLuint) (cap - GL_MAP1_VERTEX_ATTRIB0_4_NV);
1622 return ctx->Eval.Map1Attrib[map];
1623 }
1624 case GL_MAP2_VERTEX_ATTRIB0_4_NV:
1625 case GL_MAP2_VERTEX_ATTRIB1_4_NV:
1626 case GL_MAP2_VERTEX_ATTRIB2_4_NV:
1627 case GL_MAP2_VERTEX_ATTRIB3_4_NV:
1628 case GL_MAP2_VERTEX_ATTRIB4_4_NV:
1629 case GL_MAP2_VERTEX_ATTRIB5_4_NV:
1630 case GL_MAP2_VERTEX_ATTRIB6_4_NV:
1631 case GL_MAP2_VERTEX_ATTRIB7_4_NV:
1632 case GL_MAP2_VERTEX_ATTRIB8_4_NV:
1633 case GL_MAP2_VERTEX_ATTRIB9_4_NV:
1634 case GL_MAP2_VERTEX_ATTRIB10_4_NV:
1635 case GL_MAP2_VERTEX_ATTRIB11_4_NV:
1636 case GL_MAP2_VERTEX_ATTRIB12_4_NV:
1637 case GL_MAP2_VERTEX_ATTRIB13_4_NV:
1638 case GL_MAP2_VERTEX_ATTRIB14_4_NV:
1639 case GL_MAP2_VERTEX_ATTRIB15_4_NV:
1640 if (ctx->API != API_OPENGL)
1641 goto invalid_enum_error;
1642 CHECK_EXTENSION(NV_vertex_program);
1643 {
1644 const GLuint map = (GLuint) (cap - GL_MAP2_VERTEX_ATTRIB0_4_NV);
1645 return ctx->Eval.Map2Attrib[map];
1646 }
1647 #endif /* FEATURE_NV_vertex_program */
1648
1649 #if FEATURE_NV_fragment_program
1650 case GL_FRAGMENT_PROGRAM_NV:
1651 if (ctx->API != API_OPENGL)
1652 goto invalid_enum_error;
1653 CHECK_EXTENSION(NV_fragment_program);
1654 return ctx->FragmentProgram.Enabled;
1655 #endif /* FEATURE_NV_fragment_program */
1656
1657 /* GL_NV_texture_rectangle */
1658 case GL_TEXTURE_RECTANGLE_NV:
1659 if (ctx->API != API_OPENGL)
1660 goto invalid_enum_error;
1661 CHECK_EXTENSION(NV_texture_rectangle);
1662 return is_texture_enabled(ctx, TEXTURE_RECT_BIT);
1663
1664 /* GL_EXT_stencil_two_side */
1665 case GL_STENCIL_TEST_TWO_SIDE_EXT:
1666 if (ctx->API != API_OPENGL)
1667 goto invalid_enum_error;
1668 CHECK_EXTENSION(EXT_stencil_two_side);
1669 return ctx->Stencil.TestTwoSide;
1670
1671 #if FEATURE_ARB_fragment_program
1672 case GL_FRAGMENT_PROGRAM_ARB:
1673 if (ctx->API != API_OPENGL)
1674 goto invalid_enum_error;
1675 return ctx->FragmentProgram.Enabled;
1676 #endif /* FEATURE_ARB_fragment_program */
1677
1678 /* GL_EXT_depth_bounds_test */
1679 case GL_DEPTH_BOUNDS_TEST_EXT:
1680 if (!_mesa_is_desktop_gl(ctx))
1681 goto invalid_enum_error;
1682 CHECK_EXTENSION(EXT_depth_bounds_test);
1683 return ctx->Depth.BoundsTest;
1684
1685 /* GL_ARB_depth_clamp */
1686 case GL_DEPTH_CLAMP:
1687 if (!_mesa_is_desktop_gl(ctx))
1688 goto invalid_enum_error;
1689 CHECK_EXTENSION(ARB_depth_clamp);
1690 return ctx->Transform.DepthClamp;
1691
1692 #if FEATURE_ATI_fragment_shader
1693 case GL_FRAGMENT_SHADER_ATI:
1694 if (ctx->API != API_OPENGL)
1695 goto invalid_enum_error;
1696 CHECK_EXTENSION(ATI_fragment_shader);
1697 return ctx->ATIFragmentShader.Enabled;
1698 #endif /* FEATURE_ATI_fragment_shader */
1699
1700 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1701 if (!_mesa_is_desktop_gl(ctx))
1702 goto invalid_enum_error;
1703 CHECK_EXTENSION(ARB_seamless_cube_map);
1704 return ctx->Texture.CubeMapSeamless;
1705
1706 #if FEATURE_EXT_transform_feedback
1707 case GL_RASTERIZER_DISCARD:
1708 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1709 goto invalid_enum_error;
1710 CHECK_EXTENSION(EXT_transform_feedback);
1711 return ctx->RasterDiscard;
1712 #endif
1713
1714 /* GL_NV_primitive_restart */
1715 case GL_PRIMITIVE_RESTART_NV:
1716 if (ctx->API != API_OPENGL || !ctx->Extensions.NV_primitive_restart) {
1717 goto invalid_enum_error;
1718 }
1719 return ctx->Array.PrimitiveRestart;
1720
1721 /* GL 3.1 primitive restart */
1722 case GL_PRIMITIVE_RESTART:
1723 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
1724 goto invalid_enum_error;
1725 }
1726 return ctx->Array.PrimitiveRestart;
1727
1728 /* GL3.0 - GL_framebuffer_sRGB */
1729 case GL_FRAMEBUFFER_SRGB_EXT:
1730 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1731 goto invalid_enum_error;
1732 CHECK_EXTENSION(EXT_framebuffer_sRGB);
1733 return ctx->Color.sRGBEnabled;
1734
1735 /* GL_OES_EGL_image_external */
1736 case GL_TEXTURE_EXTERNAL_OES:
1737 if (!_mesa_is_gles(ctx))
1738 goto invalid_enum_error;
1739 CHECK_EXTENSION(OES_EGL_image_external);
1740 return is_texture_enabled(ctx, TEXTURE_EXTERNAL_BIT);
1741
1742 default:
1743 goto invalid_enum_error;
1744 }
1745
1746 return GL_FALSE;
1747
1748 invalid_enum_error:
1749 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(%s)",
1750 _mesa_lookup_enum_by_nr(cap));
1751 return GL_FALSE;
1752 }