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