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