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