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