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