mesa: remove FEATURE_NV_(fragment|vertex)_program defines.
[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 #if FEATURE_ARB_fragment_program
953 case GL_FRAGMENT_PROGRAM_ARB:
954 if (ctx->API != API_OPENGL)
955 goto invalid_enum_error;
956 CHECK_EXTENSION(ARB_fragment_program, cap);
957 if (ctx->FragmentProgram.Enabled == state)
958 return;
959 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
960 ctx->FragmentProgram.Enabled = state;
961 break;
962 #endif /* FEATURE_ARB_fragment_program */
963
964 /* GL_EXT_depth_bounds_test */
965 case GL_DEPTH_BOUNDS_TEST_EXT:
966 if (!_mesa_is_desktop_gl(ctx))
967 goto invalid_enum_error;
968 CHECK_EXTENSION(EXT_depth_bounds_test, cap);
969 if (ctx->Depth.BoundsTest == state)
970 return;
971 FLUSH_VERTICES(ctx, _NEW_DEPTH);
972 ctx->Depth.BoundsTest = state;
973 break;
974
975 case GL_DEPTH_CLAMP:
976 if (!_mesa_is_desktop_gl(ctx))
977 goto invalid_enum_error;
978 CHECK_EXTENSION(ARB_depth_clamp, cap);
979 if (ctx->Transform.DepthClamp == state)
980 return;
981 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
982 ctx->Transform.DepthClamp = state;
983 break;
984
985 #if FEATURE_ATI_fragment_shader
986 case GL_FRAGMENT_SHADER_ATI:
987 if (ctx->API != API_OPENGL)
988 goto invalid_enum_error;
989 CHECK_EXTENSION(ATI_fragment_shader, cap);
990 if (ctx->ATIFragmentShader.Enabled == state)
991 return;
992 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
993 ctx->ATIFragmentShader.Enabled = state;
994 break;
995 #endif
996
997 /* GL_MESA_texture_array */
998 case GL_TEXTURE_1D_ARRAY_EXT:
999 if (ctx->API != API_OPENGL)
1000 goto invalid_enum_error;
1001 CHECK_EXTENSION(MESA_texture_array, cap);
1002 if (!enable_texture(ctx, state, TEXTURE_1D_ARRAY_BIT)) {
1003 return;
1004 }
1005 break;
1006
1007 case GL_TEXTURE_2D_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_2D_ARRAY_BIT)) {
1012 return;
1013 }
1014 break;
1015
1016 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1017 if (!_mesa_is_desktop_gl(ctx))
1018 goto invalid_enum_error;
1019 CHECK_EXTENSION(ARB_seamless_cube_map, cap);
1020 if (ctx->Texture.CubeMapSeamless != state) {
1021 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1022 ctx->Texture.CubeMapSeamless = state;
1023 }
1024 break;
1025
1026 #if FEATURE_EXT_transform_feedback
1027 case GL_RASTERIZER_DISCARD:
1028 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1029 goto invalid_enum_error;
1030 CHECK_EXTENSION(EXT_transform_feedback, cap);
1031 if (ctx->RasterDiscard != state) {
1032 FLUSH_VERTICES(ctx, _NEW_RASTERIZER_DISCARD);
1033 ctx->RasterDiscard = state;
1034 }
1035 break;
1036 #endif
1037
1038 /* GL 3.1 primitive restart. Note: this enum is different from
1039 * GL_PRIMITIVE_RESTART_NV (which is client state).
1040 */
1041 case GL_PRIMITIVE_RESTART:
1042 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
1043 goto invalid_enum_error;
1044 }
1045 if (ctx->Array.PrimitiveRestart != state) {
1046 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
1047 ctx->Array.PrimitiveRestart = state;
1048 }
1049 break;
1050
1051 /* GL3.0 - GL_framebuffer_sRGB */
1052 case GL_FRAMEBUFFER_SRGB_EXT:
1053 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1054 goto invalid_enum_error;
1055 CHECK_EXTENSION(EXT_framebuffer_sRGB, cap);
1056 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
1057 ctx->Color.sRGBEnabled = state;
1058 break;
1059
1060 /* GL_OES_EGL_image_external */
1061 case GL_TEXTURE_EXTERNAL_OES:
1062 if (!_mesa_is_gles(ctx))
1063 goto invalid_enum_error;
1064 CHECK_EXTENSION(OES_EGL_image_external, cap);
1065 if (!enable_texture(ctx, state, TEXTURE_EXTERNAL_BIT)) {
1066 return;
1067 }
1068 break;
1069
1070 default:
1071 goto invalid_enum_error;
1072 }
1073
1074 if (ctx->Driver.Enable) {
1075 ctx->Driver.Enable( ctx, cap, state );
1076 }
1077
1078 return;
1079
1080 invalid_enum_error:
1081 _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(%s)",
1082 state ? "Enable" : "Disable", _mesa_lookup_enum_by_nr(cap));
1083 }
1084
1085
1086 /**
1087 * Enable GL capability. Called by glEnable()
1088 * \param cap state to enable.
1089 */
1090 void GLAPIENTRY
1091 _mesa_Enable( GLenum cap )
1092 {
1093 GET_CURRENT_CONTEXT(ctx);
1094 ASSERT_OUTSIDE_BEGIN_END(ctx);
1095
1096 _mesa_set_enable( ctx, cap, GL_TRUE );
1097 }
1098
1099
1100 /**
1101 * Disable GL capability. Called by glDisable()
1102 * \param cap state to disable.
1103 */
1104 void GLAPIENTRY
1105 _mesa_Disable( GLenum cap )
1106 {
1107 GET_CURRENT_CONTEXT(ctx);
1108 ASSERT_OUTSIDE_BEGIN_END(ctx);
1109
1110 _mesa_set_enable( ctx, cap, GL_FALSE );
1111 }
1112
1113
1114
1115 /**
1116 * Enable/disable an indexed state var.
1117 */
1118 void
1119 _mesa_set_enablei(struct gl_context *ctx, GLenum cap,
1120 GLuint index, GLboolean state)
1121 {
1122 ASSERT(state == 0 || state == 1);
1123 switch (cap) {
1124 case GL_BLEND:
1125 if (!ctx->Extensions.EXT_draw_buffers2) {
1126 goto invalid_enum_error;
1127 }
1128 if (index >= ctx->Const.MaxDrawBuffers) {
1129 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1130 state ? "glEnableIndexed" : "glDisableIndexed", index);
1131 return;
1132 }
1133 if (((ctx->Color.BlendEnabled >> index) & 1) != state) {
1134 FLUSH_VERTICES(ctx, _NEW_COLOR);
1135 if (state)
1136 ctx->Color.BlendEnabled |= (1 << index);
1137 else
1138 ctx->Color.BlendEnabled &= ~(1 << index);
1139 }
1140 break;
1141 default:
1142 goto invalid_enum_error;
1143 }
1144 return;
1145
1146 invalid_enum_error:
1147 _mesa_error(ctx, GL_INVALID_ENUM, "%s(cap=%s)",
1148 state ? "glEnablei" : "glDisablei",
1149 _mesa_lookup_enum_by_nr(cap));
1150 }
1151
1152
1153 void GLAPIENTRY
1154 _mesa_DisableIndexed( GLenum cap, GLuint index )
1155 {
1156 GET_CURRENT_CONTEXT(ctx);
1157 ASSERT_OUTSIDE_BEGIN_END(ctx);
1158 _mesa_set_enablei(ctx, cap, index, GL_FALSE);
1159 }
1160
1161
1162 void GLAPIENTRY
1163 _mesa_EnableIndexed( GLenum cap, GLuint index )
1164 {
1165 GET_CURRENT_CONTEXT(ctx);
1166 ASSERT_OUTSIDE_BEGIN_END(ctx);
1167 _mesa_set_enablei(ctx, cap, index, GL_TRUE);
1168 }
1169
1170
1171 GLboolean GLAPIENTRY
1172 _mesa_IsEnabledIndexed( GLenum cap, GLuint index )
1173 {
1174 GET_CURRENT_CONTEXT(ctx);
1175 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1176 switch (cap) {
1177 case GL_BLEND:
1178 if (index >= ctx->Const.MaxDrawBuffers) {
1179 _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
1180 index);
1181 return GL_FALSE;
1182 }
1183 return (ctx->Color.BlendEnabled >> index) & 1;
1184 default:
1185 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabledIndexed(cap=%s)",
1186 _mesa_lookup_enum_by_nr(cap));
1187 return GL_FALSE;
1188 }
1189 }
1190
1191
1192
1193
1194 #undef CHECK_EXTENSION
1195 #define CHECK_EXTENSION(EXTNAME) \
1196 if (!ctx->Extensions.EXTNAME) { \
1197 goto invalid_enum_error; \
1198 }
1199
1200 #undef CHECK_EXTENSION2
1201 #define CHECK_EXTENSION2(EXT1, EXT2) \
1202 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1203 goto invalid_enum_error; \
1204 }
1205
1206
1207 /**
1208 * Helper function to determine whether a texture target is enabled.
1209 */
1210 static GLboolean
1211 is_texture_enabled(struct gl_context *ctx, GLbitfield bit)
1212 {
1213 const struct gl_texture_unit *const texUnit =
1214 &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1215 return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE;
1216 }
1217
1218
1219 /**
1220 * Return simple enable/disable state.
1221 *
1222 * \param cap state variable to query.
1223 *
1224 * Returns the state of the specified capability from the current GL context.
1225 * For the capabilities associated with extensions verifies that those
1226 * extensions are effectively present before reporting.
1227 */
1228 GLboolean GLAPIENTRY
1229 _mesa_IsEnabled( GLenum cap )
1230 {
1231 GET_CURRENT_CONTEXT(ctx);
1232 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1233
1234 switch (cap) {
1235 case GL_ALPHA_TEST:
1236 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1237 goto invalid_enum_error;
1238 return ctx->Color.AlphaEnabled;
1239 case GL_AUTO_NORMAL:
1240 if (ctx->API != API_OPENGL)
1241 goto invalid_enum_error;
1242 return ctx->Eval.AutoNormal;
1243 case GL_BLEND:
1244 return ctx->Color.BlendEnabled & 1; /* return state for buffer[0] */
1245 case GL_CLIP_DISTANCE0:
1246 case GL_CLIP_DISTANCE1:
1247 case GL_CLIP_DISTANCE2:
1248 case GL_CLIP_DISTANCE3:
1249 case GL_CLIP_DISTANCE4:
1250 case GL_CLIP_DISTANCE5:
1251 case GL_CLIP_DISTANCE6:
1252 case GL_CLIP_DISTANCE7: {
1253 const GLuint p = cap - GL_CLIP_DISTANCE0;
1254
1255 if (p >= ctx->Const.MaxClipPlanes)
1256 goto invalid_enum_error;
1257
1258 return (ctx->Transform.ClipPlanesEnabled >> p) & 1;
1259 }
1260 case GL_COLOR_MATERIAL:
1261 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1262 goto invalid_enum_error;
1263 return ctx->Light.ColorMaterialEnabled;
1264 case GL_CULL_FACE:
1265 return ctx->Polygon.CullFlag;
1266 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB:
1267 if (!_mesa_is_desktop_gl(ctx))
1268 goto invalid_enum_error;
1269 return ctx->Debug.SyncOutput;
1270 case GL_DEPTH_TEST:
1271 return ctx->Depth.Test;
1272 case GL_DITHER:
1273 return ctx->Color.DitherFlag;
1274 case GL_FOG:
1275 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1276 goto invalid_enum_error;
1277 return ctx->Fog.Enabled;
1278 case GL_LIGHTING:
1279 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1280 goto invalid_enum_error;
1281 return ctx->Light.Enabled;
1282 case GL_LIGHT0:
1283 case GL_LIGHT1:
1284 case GL_LIGHT2:
1285 case GL_LIGHT3:
1286 case GL_LIGHT4:
1287 case GL_LIGHT5:
1288 case GL_LIGHT6:
1289 case GL_LIGHT7:
1290 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1291 goto invalid_enum_error;
1292 return ctx->Light.Light[cap-GL_LIGHT0].Enabled;
1293 case GL_LINE_SMOOTH:
1294 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1295 goto invalid_enum_error;
1296 return ctx->Line.SmoothFlag;
1297 case GL_LINE_STIPPLE:
1298 if (ctx->API != API_OPENGL)
1299 goto invalid_enum_error;
1300 return ctx->Line.StippleFlag;
1301 case GL_INDEX_LOGIC_OP:
1302 if (ctx->API != API_OPENGL)
1303 goto invalid_enum_error;
1304 return ctx->Color.IndexLogicOpEnabled;
1305 case GL_COLOR_LOGIC_OP:
1306 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1307 goto invalid_enum_error;
1308 return ctx->Color.ColorLogicOpEnabled;
1309 case GL_MAP1_COLOR_4:
1310 if (ctx->API != API_OPENGL)
1311 goto invalid_enum_error;
1312 return ctx->Eval.Map1Color4;
1313 case GL_MAP1_INDEX:
1314 if (ctx->API != API_OPENGL)
1315 goto invalid_enum_error;
1316 return ctx->Eval.Map1Index;
1317 case GL_MAP1_NORMAL:
1318 if (ctx->API != API_OPENGL)
1319 goto invalid_enum_error;
1320 return ctx->Eval.Map1Normal;
1321 case GL_MAP1_TEXTURE_COORD_1:
1322 if (ctx->API != API_OPENGL)
1323 goto invalid_enum_error;
1324 return ctx->Eval.Map1TextureCoord1;
1325 case GL_MAP1_TEXTURE_COORD_2:
1326 if (ctx->API != API_OPENGL)
1327 goto invalid_enum_error;
1328 return ctx->Eval.Map1TextureCoord2;
1329 case GL_MAP1_TEXTURE_COORD_3:
1330 if (ctx->API != API_OPENGL)
1331 goto invalid_enum_error;
1332 return ctx->Eval.Map1TextureCoord3;
1333 case GL_MAP1_TEXTURE_COORD_4:
1334 if (ctx->API != API_OPENGL)
1335 goto invalid_enum_error;
1336 return ctx->Eval.Map1TextureCoord4;
1337 case GL_MAP1_VERTEX_3:
1338 if (ctx->API != API_OPENGL)
1339 goto invalid_enum_error;
1340 return ctx->Eval.Map1Vertex3;
1341 case GL_MAP1_VERTEX_4:
1342 if (ctx->API != API_OPENGL)
1343 goto invalid_enum_error;
1344 return ctx->Eval.Map1Vertex4;
1345 case GL_MAP2_COLOR_4:
1346 if (ctx->API != API_OPENGL)
1347 goto invalid_enum_error;
1348 return ctx->Eval.Map2Color4;
1349 case GL_MAP2_INDEX:
1350 if (ctx->API != API_OPENGL)
1351 goto invalid_enum_error;
1352 return ctx->Eval.Map2Index;
1353 case GL_MAP2_NORMAL:
1354 if (ctx->API != API_OPENGL)
1355 goto invalid_enum_error;
1356 return ctx->Eval.Map2Normal;
1357 case GL_MAP2_TEXTURE_COORD_1:
1358 if (ctx->API != API_OPENGL)
1359 goto invalid_enum_error;
1360 return ctx->Eval.Map2TextureCoord1;
1361 case GL_MAP2_TEXTURE_COORD_2:
1362 if (ctx->API != API_OPENGL)
1363 goto invalid_enum_error;
1364 return ctx->Eval.Map2TextureCoord2;
1365 case GL_MAP2_TEXTURE_COORD_3:
1366 if (ctx->API != API_OPENGL)
1367 goto invalid_enum_error;
1368 return ctx->Eval.Map2TextureCoord3;
1369 case GL_MAP2_TEXTURE_COORD_4:
1370 if (ctx->API != API_OPENGL)
1371 goto invalid_enum_error;
1372 return ctx->Eval.Map2TextureCoord4;
1373 case GL_MAP2_VERTEX_3:
1374 if (ctx->API != API_OPENGL)
1375 goto invalid_enum_error;
1376 return ctx->Eval.Map2Vertex3;
1377 case GL_MAP2_VERTEX_4:
1378 if (ctx->API != API_OPENGL)
1379 goto invalid_enum_error;
1380 return ctx->Eval.Map2Vertex4;
1381 case GL_NORMALIZE:
1382 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1383 goto invalid_enum_error;
1384 return ctx->Transform.Normalize;
1385 case GL_POINT_SMOOTH:
1386 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1387 goto invalid_enum_error;
1388 return ctx->Point.SmoothFlag;
1389 case GL_POLYGON_SMOOTH:
1390 if (!_mesa_is_desktop_gl(ctx))
1391 goto invalid_enum_error;
1392 return ctx->Polygon.SmoothFlag;
1393 case GL_POLYGON_STIPPLE:
1394 if (ctx->API != API_OPENGL)
1395 goto invalid_enum_error;
1396 return ctx->Polygon.StippleFlag;
1397 case GL_POLYGON_OFFSET_POINT:
1398 if (!_mesa_is_desktop_gl(ctx))
1399 goto invalid_enum_error;
1400 return ctx->Polygon.OffsetPoint;
1401 case GL_POLYGON_OFFSET_LINE:
1402 if (!_mesa_is_desktop_gl(ctx))
1403 goto invalid_enum_error;
1404 return ctx->Polygon.OffsetLine;
1405 case GL_POLYGON_OFFSET_FILL:
1406 return ctx->Polygon.OffsetFill;
1407 case GL_RESCALE_NORMAL_EXT:
1408 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1409 goto invalid_enum_error;
1410 return ctx->Transform.RescaleNormals;
1411 case GL_SCISSOR_TEST:
1412 return ctx->Scissor.Enabled;
1413 case GL_STENCIL_TEST:
1414 return ctx->Stencil.Enabled;
1415 case GL_TEXTURE_1D:
1416 if (ctx->API != API_OPENGL)
1417 goto invalid_enum_error;
1418 return is_texture_enabled(ctx, TEXTURE_1D_BIT);
1419 case GL_TEXTURE_2D:
1420 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1421 goto invalid_enum_error;
1422 return is_texture_enabled(ctx, TEXTURE_2D_BIT);
1423 case GL_TEXTURE_3D:
1424 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1425 goto invalid_enum_error;
1426 return is_texture_enabled(ctx, TEXTURE_3D_BIT);
1427 case GL_TEXTURE_GEN_S:
1428 case GL_TEXTURE_GEN_T:
1429 case GL_TEXTURE_GEN_R:
1430 case GL_TEXTURE_GEN_Q:
1431 {
1432 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1433
1434 if (ctx->API != API_OPENGL)
1435 goto invalid_enum_error;
1436
1437 if (texUnit) {
1438 GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
1439 return (texUnit->TexGenEnabled & coordBit) ? GL_TRUE : GL_FALSE;
1440 }
1441 }
1442 return GL_FALSE;
1443 #if FEATURE_ES1
1444 case GL_TEXTURE_GEN_STR_OES:
1445 {
1446 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1447
1448 if (ctx->API != API_OPENGLES)
1449 goto invalid_enum_error;
1450
1451 if (texUnit) {
1452 return (texUnit->TexGenEnabled & STR_BITS) == STR_BITS
1453 ? GL_TRUE : GL_FALSE;
1454 }
1455 }
1456 #endif
1457
1458 /* client-side state */
1459 case GL_VERTEX_ARRAY:
1460 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1461 goto invalid_enum_error;
1462 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POS].Enabled != 0);
1463 case GL_NORMAL_ARRAY:
1464 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1465 goto invalid_enum_error;
1466 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled != 0);
1467 case GL_COLOR_ARRAY:
1468 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1469 goto invalid_enum_error;
1470 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled != 0);
1471 case GL_INDEX_ARRAY:
1472 if (ctx->API != API_OPENGL)
1473 goto invalid_enum_error;
1474 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled != 0);
1475 case GL_TEXTURE_COORD_ARRAY:
1476 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1477 goto invalid_enum_error;
1478 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)]
1479 .Enabled != 0);
1480 case GL_EDGE_FLAG_ARRAY:
1481 if (ctx->API != API_OPENGL)
1482 goto invalid_enum_error;
1483 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled != 0);
1484 case GL_FOG_COORDINATE_ARRAY_EXT:
1485 if (ctx->API != API_OPENGL)
1486 goto invalid_enum_error;
1487 CHECK_EXTENSION(EXT_fog_coord);
1488 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_FOG].Enabled != 0);
1489 case GL_SECONDARY_COLOR_ARRAY_EXT:
1490 if (ctx->API != API_OPENGL)
1491 goto invalid_enum_error;
1492 CHECK_EXTENSION(EXT_secondary_color);
1493 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled != 0);
1494 #if FEATURE_ES
1495 case GL_POINT_SIZE_ARRAY_OES:
1496 if (ctx->API != API_OPENGLES)
1497 goto invalid_enum_error;
1498 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled != 0);
1499 #endif
1500
1501 /* GL_ARB_texture_cube_map */
1502 case GL_TEXTURE_CUBE_MAP_ARB:
1503 CHECK_EXTENSION(ARB_texture_cube_map);
1504 return is_texture_enabled(ctx, TEXTURE_CUBE_BIT);
1505
1506 /* GL_EXT_secondary_color */
1507 case GL_COLOR_SUM_EXT:
1508 if (ctx->API != API_OPENGL)
1509 goto invalid_enum_error;
1510 CHECK_EXTENSION2(EXT_secondary_color, ARB_vertex_program);
1511 return ctx->Fog.ColorSumEnabled;
1512
1513 /* GL_ARB_multisample */
1514 case GL_MULTISAMPLE_ARB:
1515 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1516 goto invalid_enum_error;
1517 return ctx->Multisample.Enabled;
1518 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
1519 return ctx->Multisample.SampleAlphaToCoverage;
1520 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
1521 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1522 goto invalid_enum_error;
1523 return ctx->Multisample.SampleAlphaToOne;
1524 case GL_SAMPLE_COVERAGE_ARB:
1525 return ctx->Multisample.SampleCoverage;
1526 case GL_SAMPLE_COVERAGE_INVERT_ARB:
1527 if (!_mesa_is_desktop_gl(ctx))
1528 goto invalid_enum_error;
1529 return ctx->Multisample.SampleCoverageInvert;
1530
1531 /* GL_IBM_rasterpos_clip */
1532 case GL_RASTER_POSITION_UNCLIPPED_IBM:
1533 if (ctx->API != API_OPENGL)
1534 goto invalid_enum_error;
1535 CHECK_EXTENSION(IBM_rasterpos_clip);
1536 return ctx->Transform.RasterPositionUnclipped;
1537
1538 /* GL_NV_point_sprite */
1539 case GL_POINT_SPRITE_NV:
1540 if (ctx->API != API_OPENGL && ctx->API != API_OPENGLES)
1541 goto invalid_enum_error;
1542 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite)
1543 return ctx->Point.PointSprite;
1544
1545 case GL_VERTEX_PROGRAM_ARB:
1546 if (ctx->API != API_OPENGL)
1547 goto invalid_enum_error;
1548 CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program);
1549 return ctx->VertexProgram.Enabled;
1550 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
1551 /* This was added with ARB_vertex_program, but it is also used with
1552 * GLSL vertex shaders on desktop.
1553 */
1554 if (!_mesa_is_desktop_gl(ctx))
1555 goto invalid_enum_error;
1556 CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program);
1557 return ctx->VertexProgram.PointSizeEnabled;
1558 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
1559 if (ctx->API != API_OPENGL)
1560 goto invalid_enum_error;
1561 CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program);
1562 return ctx->VertexProgram.TwoSideEnabled;
1563
1564 case GL_VERTEX_ATTRIB_ARRAY0_NV:
1565 case GL_VERTEX_ATTRIB_ARRAY1_NV:
1566 case GL_VERTEX_ATTRIB_ARRAY2_NV:
1567 case GL_VERTEX_ATTRIB_ARRAY3_NV:
1568 case GL_VERTEX_ATTRIB_ARRAY4_NV:
1569 case GL_VERTEX_ATTRIB_ARRAY5_NV:
1570 case GL_VERTEX_ATTRIB_ARRAY6_NV:
1571 case GL_VERTEX_ATTRIB_ARRAY7_NV:
1572 case GL_VERTEX_ATTRIB_ARRAY8_NV:
1573 case GL_VERTEX_ATTRIB_ARRAY9_NV:
1574 case GL_VERTEX_ATTRIB_ARRAY10_NV:
1575 case GL_VERTEX_ATTRIB_ARRAY11_NV:
1576 case GL_VERTEX_ATTRIB_ARRAY12_NV:
1577 case GL_VERTEX_ATTRIB_ARRAY13_NV:
1578 case GL_VERTEX_ATTRIB_ARRAY14_NV:
1579 case GL_VERTEX_ATTRIB_ARRAY15_NV:
1580 if (ctx->API != API_OPENGL)
1581 goto invalid_enum_error;
1582 CHECK_EXTENSION(NV_vertex_program);
1583 {
1584 GLint n = (GLint) cap - GL_VERTEX_ATTRIB_ARRAY0_NV;
1585 ASSERT(VERT_ATTRIB_GENERIC(n) < Elements(ctx->Array.ArrayObj->VertexAttrib));
1586 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(n)].Enabled != 0);
1587 }
1588 case GL_MAP1_VERTEX_ATTRIB0_4_NV:
1589 case GL_MAP1_VERTEX_ATTRIB1_4_NV:
1590 case GL_MAP1_VERTEX_ATTRIB2_4_NV:
1591 case GL_MAP1_VERTEX_ATTRIB3_4_NV:
1592 case GL_MAP1_VERTEX_ATTRIB4_4_NV:
1593 case GL_MAP1_VERTEX_ATTRIB5_4_NV:
1594 case GL_MAP1_VERTEX_ATTRIB6_4_NV:
1595 case GL_MAP1_VERTEX_ATTRIB7_4_NV:
1596 case GL_MAP1_VERTEX_ATTRIB8_4_NV:
1597 case GL_MAP1_VERTEX_ATTRIB9_4_NV:
1598 case GL_MAP1_VERTEX_ATTRIB10_4_NV:
1599 case GL_MAP1_VERTEX_ATTRIB11_4_NV:
1600 case GL_MAP1_VERTEX_ATTRIB12_4_NV:
1601 case GL_MAP1_VERTEX_ATTRIB13_4_NV:
1602 case GL_MAP1_VERTEX_ATTRIB14_4_NV:
1603 case GL_MAP1_VERTEX_ATTRIB15_4_NV:
1604 if (ctx->API != API_OPENGL)
1605 goto invalid_enum_error;
1606 CHECK_EXTENSION(NV_vertex_program);
1607 {
1608 const GLuint map = (GLuint) (cap - GL_MAP1_VERTEX_ATTRIB0_4_NV);
1609 return ctx->Eval.Map1Attrib[map];
1610 }
1611 case GL_MAP2_VERTEX_ATTRIB0_4_NV:
1612 case GL_MAP2_VERTEX_ATTRIB1_4_NV:
1613 case GL_MAP2_VERTEX_ATTRIB2_4_NV:
1614 case GL_MAP2_VERTEX_ATTRIB3_4_NV:
1615 case GL_MAP2_VERTEX_ATTRIB4_4_NV:
1616 case GL_MAP2_VERTEX_ATTRIB5_4_NV:
1617 case GL_MAP2_VERTEX_ATTRIB6_4_NV:
1618 case GL_MAP2_VERTEX_ATTRIB7_4_NV:
1619 case GL_MAP2_VERTEX_ATTRIB8_4_NV:
1620 case GL_MAP2_VERTEX_ATTRIB9_4_NV:
1621 case GL_MAP2_VERTEX_ATTRIB10_4_NV:
1622 case GL_MAP2_VERTEX_ATTRIB11_4_NV:
1623 case GL_MAP2_VERTEX_ATTRIB12_4_NV:
1624 case GL_MAP2_VERTEX_ATTRIB13_4_NV:
1625 case GL_MAP2_VERTEX_ATTRIB14_4_NV:
1626 case GL_MAP2_VERTEX_ATTRIB15_4_NV:
1627 if (ctx->API != API_OPENGL)
1628 goto invalid_enum_error;
1629 CHECK_EXTENSION(NV_vertex_program);
1630 {
1631 const GLuint map = (GLuint) (cap - GL_MAP2_VERTEX_ATTRIB0_4_NV);
1632 return ctx->Eval.Map2Attrib[map];
1633 }
1634
1635 case GL_FRAGMENT_PROGRAM_NV:
1636 if (ctx->API != API_OPENGL)
1637 goto invalid_enum_error;
1638 CHECK_EXTENSION(NV_fragment_program);
1639 return ctx->FragmentProgram.Enabled;
1640
1641 /* GL_NV_texture_rectangle */
1642 case GL_TEXTURE_RECTANGLE_NV:
1643 if (ctx->API != API_OPENGL)
1644 goto invalid_enum_error;
1645 CHECK_EXTENSION(NV_texture_rectangle);
1646 return is_texture_enabled(ctx, TEXTURE_RECT_BIT);
1647
1648 /* GL_EXT_stencil_two_side */
1649 case GL_STENCIL_TEST_TWO_SIDE_EXT:
1650 if (ctx->API != API_OPENGL)
1651 goto invalid_enum_error;
1652 CHECK_EXTENSION(EXT_stencil_two_side);
1653 return ctx->Stencil.TestTwoSide;
1654
1655 #if FEATURE_ARB_fragment_program
1656 case GL_FRAGMENT_PROGRAM_ARB:
1657 if (ctx->API != API_OPENGL)
1658 goto invalid_enum_error;
1659 return ctx->FragmentProgram.Enabled;
1660 #endif /* FEATURE_ARB_fragment_program */
1661
1662 /* GL_EXT_depth_bounds_test */
1663 case GL_DEPTH_BOUNDS_TEST_EXT:
1664 if (!_mesa_is_desktop_gl(ctx))
1665 goto invalid_enum_error;
1666 CHECK_EXTENSION(EXT_depth_bounds_test);
1667 return ctx->Depth.BoundsTest;
1668
1669 /* GL_ARB_depth_clamp */
1670 case GL_DEPTH_CLAMP:
1671 if (!_mesa_is_desktop_gl(ctx))
1672 goto invalid_enum_error;
1673 CHECK_EXTENSION(ARB_depth_clamp);
1674 return ctx->Transform.DepthClamp;
1675
1676 #if FEATURE_ATI_fragment_shader
1677 case GL_FRAGMENT_SHADER_ATI:
1678 if (ctx->API != API_OPENGL)
1679 goto invalid_enum_error;
1680 CHECK_EXTENSION(ATI_fragment_shader);
1681 return ctx->ATIFragmentShader.Enabled;
1682 #endif /* FEATURE_ATI_fragment_shader */
1683
1684 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1685 if (!_mesa_is_desktop_gl(ctx))
1686 goto invalid_enum_error;
1687 CHECK_EXTENSION(ARB_seamless_cube_map);
1688 return ctx->Texture.CubeMapSeamless;
1689
1690 #if FEATURE_EXT_transform_feedback
1691 case GL_RASTERIZER_DISCARD:
1692 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1693 goto invalid_enum_error;
1694 CHECK_EXTENSION(EXT_transform_feedback);
1695 return ctx->RasterDiscard;
1696 #endif
1697
1698 /* GL_NV_primitive_restart */
1699 case GL_PRIMITIVE_RESTART_NV:
1700 if (ctx->API != API_OPENGL || !ctx->Extensions.NV_primitive_restart) {
1701 goto invalid_enum_error;
1702 }
1703 return ctx->Array.PrimitiveRestart;
1704
1705 /* GL 3.1 primitive restart */
1706 case GL_PRIMITIVE_RESTART:
1707 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
1708 goto invalid_enum_error;
1709 }
1710 return ctx->Array.PrimitiveRestart;
1711
1712 /* GL3.0 - GL_framebuffer_sRGB */
1713 case GL_FRAMEBUFFER_SRGB_EXT:
1714 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1715 goto invalid_enum_error;
1716 CHECK_EXTENSION(EXT_framebuffer_sRGB);
1717 return ctx->Color.sRGBEnabled;
1718
1719 /* GL_OES_EGL_image_external */
1720 case GL_TEXTURE_EXTERNAL_OES:
1721 if (!_mesa_is_gles(ctx))
1722 goto invalid_enum_error;
1723 CHECK_EXTENSION(OES_EGL_image_external);
1724 return is_texture_enabled(ctx, TEXTURE_EXTERNAL_BIT);
1725
1726 default:
1727 goto invalid_enum_error;
1728 }
1729
1730 return GL_FALSE;
1731
1732 invalid_enum_error:
1733 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(%s)",
1734 _mesa_lookup_enum_by_nr(cap));
1735 return GL_FALSE;
1736 }