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