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