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