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