mesa: raise error for glEnable(GL_VERTEX_ARRAY), etc. in core profile
[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_TEXTURE_COORD_ARRAY:
745 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
746 goto invalid_enum_error;
747 client_state( ctx, cap, state );
748 return;
749 case GL_INDEX_ARRAY:
750 case GL_EDGE_FLAG_ARRAY:
751 case GL_FOG_COORDINATE_ARRAY_EXT:
752 case GL_SECONDARY_COLOR_ARRAY_EXT:
753 if (ctx->API != API_OPENGL_COMPAT)
754 goto invalid_enum_error;
755 client_state( ctx, cap, state );
756 return;
757 case GL_POINT_SIZE_ARRAY_OES:
758 if (ctx->API != API_OPENGLES)
759 goto invalid_enum_error;
760 client_state( ctx, cap, state );
761 return;
762
763 /* GL_ARB_texture_cube_map */
764 case GL_TEXTURE_CUBE_MAP:
765 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
766 goto invalid_enum_error;
767 CHECK_EXTENSION(ARB_texture_cube_map, cap);
768 if (!enable_texture(ctx, state, TEXTURE_CUBE_BIT)) {
769 return;
770 }
771 break;
772
773 /* GL_EXT_secondary_color */
774 case GL_COLOR_SUM_EXT:
775 if (ctx->API != API_OPENGL_COMPAT)
776 goto invalid_enum_error;
777 if (ctx->Fog.ColorSumEnabled == state)
778 return;
779 FLUSH_VERTICES(ctx, _NEW_FOG);
780 ctx->Fog.ColorSumEnabled = state;
781 break;
782
783 /* GL_ARB_multisample */
784 case GL_MULTISAMPLE_ARB:
785 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
786 goto invalid_enum_error;
787 _mesa_set_multisample(ctx, state);
788 return;
789 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
790 if (ctx->Multisample.SampleAlphaToCoverage == state)
791 return;
792 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
793 ctx->Multisample.SampleAlphaToCoverage = state;
794 break;
795 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
796 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
797 goto invalid_enum_error;
798 if (ctx->Multisample.SampleAlphaToOne == state)
799 return;
800 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
801 ctx->Multisample.SampleAlphaToOne = state;
802 break;
803 case GL_SAMPLE_COVERAGE_ARB:
804 if (ctx->Multisample.SampleCoverage == state)
805 return;
806 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
807 ctx->Multisample.SampleCoverage = state;
808 break;
809 case GL_SAMPLE_COVERAGE_INVERT_ARB:
810 if (!_mesa_is_desktop_gl(ctx))
811 goto invalid_enum_error;
812 if (ctx->Multisample.SampleCoverageInvert == state)
813 return;
814 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
815 ctx->Multisample.SampleCoverageInvert = state;
816 break;
817
818 /* GL_ARB_sample_shading */
819 case GL_SAMPLE_SHADING:
820 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
821 goto invalid_enum_error;
822 CHECK_EXTENSION(ARB_sample_shading, cap);
823 if (ctx->Multisample.SampleShading == state)
824 return;
825 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
826 ctx->Multisample.SampleShading = state;
827 break;
828
829 /* GL_IBM_rasterpos_clip */
830 case GL_RASTER_POSITION_UNCLIPPED_IBM:
831 if (ctx->API != API_OPENGL_COMPAT)
832 goto invalid_enum_error;
833 if (ctx->Transform.RasterPositionUnclipped == state)
834 return;
835 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
836 ctx->Transform.RasterPositionUnclipped = state;
837 break;
838
839 /* GL_NV_point_sprite */
840 case GL_POINT_SPRITE_NV:
841 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
842 goto invalid_enum_error;
843 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite, cap);
844 if (ctx->Point.PointSprite == state)
845 return;
846 FLUSH_VERTICES(ctx, _NEW_POINT);
847 ctx->Point.PointSprite = state;
848 break;
849
850 case GL_VERTEX_PROGRAM_ARB:
851 if (ctx->API != API_OPENGL_COMPAT)
852 goto invalid_enum_error;
853 CHECK_EXTENSION(ARB_vertex_program, cap);
854 if (ctx->VertexProgram.Enabled == state)
855 return;
856 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
857 ctx->VertexProgram.Enabled = state;
858 break;
859 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
860 /* This was added with ARB_vertex_program, but it is also used with
861 * GLSL vertex shaders on desktop.
862 */
863 if (!_mesa_is_desktop_gl(ctx))
864 goto invalid_enum_error;
865 CHECK_EXTENSION(ARB_vertex_program, cap);
866 if (ctx->VertexProgram.PointSizeEnabled == state)
867 return;
868 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
869 ctx->VertexProgram.PointSizeEnabled = state;
870 break;
871 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
872 if (ctx->API != API_OPENGL_COMPAT)
873 goto invalid_enum_error;
874 CHECK_EXTENSION(ARB_vertex_program, cap);
875 if (ctx->VertexProgram.TwoSideEnabled == state)
876 return;
877 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
878 ctx->VertexProgram.TwoSideEnabled = state;
879 break;
880
881 /* GL_NV_texture_rectangle */
882 case GL_TEXTURE_RECTANGLE_NV:
883 if (ctx->API != API_OPENGL_COMPAT)
884 goto invalid_enum_error;
885 CHECK_EXTENSION(NV_texture_rectangle, cap);
886 if (!enable_texture(ctx, state, TEXTURE_RECT_BIT)) {
887 return;
888 }
889 break;
890
891 /* GL_EXT_stencil_two_side */
892 case GL_STENCIL_TEST_TWO_SIDE_EXT:
893 if (ctx->API != API_OPENGL_COMPAT)
894 goto invalid_enum_error;
895 CHECK_EXTENSION(EXT_stencil_two_side, cap);
896 if (ctx->Stencil.TestTwoSide == state)
897 return;
898 FLUSH_VERTICES(ctx, _NEW_STENCIL);
899 ctx->Stencil.TestTwoSide = state;
900 if (state) {
901 ctx->Stencil._BackFace = 2;
902 } else {
903 ctx->Stencil._BackFace = 1;
904 }
905 break;
906
907 case GL_FRAGMENT_PROGRAM_ARB:
908 if (ctx->API != API_OPENGL_COMPAT)
909 goto invalid_enum_error;
910 CHECK_EXTENSION(ARB_fragment_program, cap);
911 if (ctx->FragmentProgram.Enabled == state)
912 return;
913 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
914 ctx->FragmentProgram.Enabled = state;
915 break;
916
917 /* GL_EXT_depth_bounds_test */
918 case GL_DEPTH_BOUNDS_TEST_EXT:
919 if (!_mesa_is_desktop_gl(ctx))
920 goto invalid_enum_error;
921 CHECK_EXTENSION(EXT_depth_bounds_test, cap);
922 if (ctx->Depth.BoundsTest == state)
923 return;
924 FLUSH_VERTICES(ctx, _NEW_DEPTH);
925 ctx->Depth.BoundsTest = state;
926 break;
927
928 case GL_DEPTH_CLAMP:
929 if (!_mesa_is_desktop_gl(ctx))
930 goto invalid_enum_error;
931 CHECK_EXTENSION(ARB_depth_clamp, cap);
932 if (ctx->Transform.DepthClamp == state)
933 return;
934 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
935 ctx->Transform.DepthClamp = state;
936 break;
937
938 case GL_FRAGMENT_SHADER_ATI:
939 if (ctx->API != API_OPENGL_COMPAT)
940 goto invalid_enum_error;
941 CHECK_EXTENSION(ATI_fragment_shader, cap);
942 if (ctx->ATIFragmentShader.Enabled == state)
943 return;
944 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
945 ctx->ATIFragmentShader.Enabled = state;
946 break;
947
948 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
949 if (!_mesa_is_desktop_gl(ctx))
950 goto invalid_enum_error;
951 CHECK_EXTENSION(ARB_seamless_cube_map, cap);
952 if (ctx->Texture.CubeMapSeamless != state) {
953 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
954 ctx->Texture.CubeMapSeamless = state;
955 }
956 break;
957
958 case GL_RASTERIZER_DISCARD:
959 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
960 goto invalid_enum_error;
961 CHECK_EXTENSION(EXT_transform_feedback, cap);
962 if (ctx->RasterDiscard != state) {
963 FLUSH_VERTICES(ctx, 0);
964 ctx->NewDriverState |= ctx->DriverFlags.NewRasterizerDiscard;
965 ctx->RasterDiscard = state;
966 }
967 break;
968
969 /* GL 3.1 primitive restart. Note: this enum is different from
970 * GL_PRIMITIVE_RESTART_NV (which is client state).
971 */
972 case GL_PRIMITIVE_RESTART:
973 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
974 goto invalid_enum_error;
975 }
976 if (ctx->Array.PrimitiveRestart != state) {
977 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
978 ctx->Array.PrimitiveRestart = state;
979 update_derived_primitive_restart_state(ctx);
980 }
981 break;
982
983 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
984 if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility)
985 goto invalid_enum_error;
986 if (ctx->Array.PrimitiveRestartFixedIndex != state) {
987 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
988 ctx->Array.PrimitiveRestartFixedIndex = state;
989 update_derived_primitive_restart_state(ctx);
990 }
991 break;
992
993 /* GL3.0 - GL_framebuffer_sRGB */
994 case GL_FRAMEBUFFER_SRGB_EXT:
995 if (!_mesa_is_desktop_gl(ctx))
996 goto invalid_enum_error;
997 CHECK_EXTENSION(EXT_framebuffer_sRGB, cap);
998 _mesa_set_framebuffer_srgb(ctx, state);
999 return;
1000
1001 /* GL_OES_EGL_image_external */
1002 case GL_TEXTURE_EXTERNAL_OES:
1003 if (!_mesa_is_gles(ctx))
1004 goto invalid_enum_error;
1005 CHECK_EXTENSION(OES_EGL_image_external, cap);
1006 if (!enable_texture(ctx, state, TEXTURE_EXTERNAL_BIT)) {
1007 return;
1008 }
1009 break;
1010
1011 /* ARB_texture_multisample */
1012 case GL_SAMPLE_MASK:
1013 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
1014 goto invalid_enum_error;
1015 CHECK_EXTENSION(ARB_texture_multisample, cap);
1016 if (ctx->Multisample.SampleMask == state)
1017 return;
1018 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
1019 ctx->Multisample.SampleMask = state;
1020 break;
1021
1022 default:
1023 goto invalid_enum_error;
1024 }
1025
1026 if (ctx->Driver.Enable) {
1027 ctx->Driver.Enable( ctx, cap, state );
1028 }
1029
1030 return;
1031
1032 invalid_enum_error:
1033 _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(%s)",
1034 state ? "Enable" : "Disable", _mesa_enum_to_string(cap));
1035 }
1036
1037
1038 /**
1039 * Enable GL capability. Called by glEnable()
1040 * \param cap state to enable.
1041 */
1042 void GLAPIENTRY
1043 _mesa_Enable( GLenum cap )
1044 {
1045 GET_CURRENT_CONTEXT(ctx);
1046
1047 _mesa_set_enable( ctx, cap, GL_TRUE );
1048 }
1049
1050
1051 /**
1052 * Disable GL capability. Called by glDisable()
1053 * \param cap state to disable.
1054 */
1055 void GLAPIENTRY
1056 _mesa_Disable( GLenum cap )
1057 {
1058 GET_CURRENT_CONTEXT(ctx);
1059
1060 _mesa_set_enable( ctx, cap, GL_FALSE );
1061 }
1062
1063
1064
1065 /**
1066 * Enable/disable an indexed state var.
1067 */
1068 void
1069 _mesa_set_enablei(struct gl_context *ctx, GLenum cap,
1070 GLuint index, GLboolean state)
1071 {
1072 assert(state == 0 || state == 1);
1073 switch (cap) {
1074 case GL_BLEND:
1075 if (!ctx->Extensions.EXT_draw_buffers2) {
1076 goto invalid_enum_error;
1077 }
1078 if (index >= ctx->Const.MaxDrawBuffers) {
1079 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1080 state ? "glEnableIndexed" : "glDisableIndexed", index);
1081 return;
1082 }
1083 if (((ctx->Color.BlendEnabled >> index) & 1) != state) {
1084 FLUSH_VERTICES(ctx, _NEW_COLOR);
1085 if (state)
1086 ctx->Color.BlendEnabled |= (1 << index);
1087 else
1088 ctx->Color.BlendEnabled &= ~(1 << index);
1089 }
1090 break;
1091 case GL_SCISSOR_TEST:
1092 if (index >= ctx->Const.MaxViewports) {
1093 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1094 state ? "glEnablei" : "glDisablei", index);
1095 return;
1096 }
1097 if (((ctx->Scissor.EnableFlags >> index) & 1) != state) {
1098 FLUSH_VERTICES(ctx, _NEW_SCISSOR);
1099 if (state)
1100 ctx->Scissor.EnableFlags |= (1 << index);
1101 else
1102 ctx->Scissor.EnableFlags &= ~(1 << index);
1103 }
1104 break;
1105 default:
1106 goto invalid_enum_error;
1107 }
1108 return;
1109
1110 invalid_enum_error:
1111 _mesa_error(ctx, GL_INVALID_ENUM, "%s(cap=%s)",
1112 state ? "glEnablei" : "glDisablei",
1113 _mesa_enum_to_string(cap));
1114 }
1115
1116
1117 void GLAPIENTRY
1118 _mesa_Disablei( GLenum cap, GLuint index )
1119 {
1120 GET_CURRENT_CONTEXT(ctx);
1121 _mesa_set_enablei(ctx, cap, index, GL_FALSE);
1122 }
1123
1124
1125 void GLAPIENTRY
1126 _mesa_Enablei( GLenum cap, GLuint index )
1127 {
1128 GET_CURRENT_CONTEXT(ctx);
1129 _mesa_set_enablei(ctx, cap, index, GL_TRUE);
1130 }
1131
1132
1133 GLboolean GLAPIENTRY
1134 _mesa_IsEnabledi( GLenum cap, GLuint index )
1135 {
1136 GET_CURRENT_CONTEXT(ctx);
1137 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1138 switch (cap) {
1139 case GL_BLEND:
1140 if (index >= ctx->Const.MaxDrawBuffers) {
1141 _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
1142 index);
1143 return GL_FALSE;
1144 }
1145 return (ctx->Color.BlendEnabled >> index) & 1;
1146 case GL_SCISSOR_TEST:
1147 if (index >= ctx->Const.MaxViewports) {
1148 _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
1149 index);
1150 return GL_FALSE;
1151 }
1152 return (ctx->Scissor.EnableFlags >> index) & 1;
1153 default:
1154 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabledIndexed(cap=%s)",
1155 _mesa_enum_to_string(cap));
1156 return GL_FALSE;
1157 }
1158 }
1159
1160
1161
1162
1163 #undef CHECK_EXTENSION
1164 #define CHECK_EXTENSION(EXTNAME) \
1165 if (!ctx->Extensions.EXTNAME) { \
1166 goto invalid_enum_error; \
1167 }
1168
1169 #undef CHECK_EXTENSION2
1170 #define CHECK_EXTENSION2(EXT1, EXT2) \
1171 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1172 goto invalid_enum_error; \
1173 }
1174
1175
1176 /**
1177 * Helper function to determine whether a texture target is enabled.
1178 */
1179 static GLboolean
1180 is_texture_enabled(struct gl_context *ctx, GLbitfield bit)
1181 {
1182 const struct gl_texture_unit *const texUnit =
1183 &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1184 return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE;
1185 }
1186
1187
1188 /**
1189 * Return simple enable/disable state.
1190 *
1191 * \param cap state variable to query.
1192 *
1193 * Returns the state of the specified capability from the current GL context.
1194 * For the capabilities associated with extensions verifies that those
1195 * extensions are effectively present before reporting.
1196 */
1197 GLboolean GLAPIENTRY
1198 _mesa_IsEnabled( GLenum cap )
1199 {
1200 GET_CURRENT_CONTEXT(ctx);
1201 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1202
1203 switch (cap) {
1204 case GL_ALPHA_TEST:
1205 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1206 goto invalid_enum_error;
1207 return ctx->Color.AlphaEnabled;
1208 case GL_AUTO_NORMAL:
1209 if (ctx->API != API_OPENGL_COMPAT)
1210 goto invalid_enum_error;
1211 return ctx->Eval.AutoNormal;
1212 case GL_BLEND:
1213 return ctx->Color.BlendEnabled & 1; /* return state for buffer[0] */
1214 case GL_CLIP_DISTANCE0: /* aka GL_CLIP_PLANE0 */
1215 case GL_CLIP_DISTANCE1:
1216 case GL_CLIP_DISTANCE2:
1217 case GL_CLIP_DISTANCE3:
1218 case GL_CLIP_DISTANCE4:
1219 case GL_CLIP_DISTANCE5:
1220 case GL_CLIP_DISTANCE6:
1221 case GL_CLIP_DISTANCE7: {
1222 const GLuint p = cap - GL_CLIP_DISTANCE0;
1223
1224 if (p >= ctx->Const.MaxClipPlanes)
1225 goto invalid_enum_error;
1226
1227 return (ctx->Transform.ClipPlanesEnabled >> p) & 1;
1228 }
1229 case GL_COLOR_MATERIAL:
1230 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1231 goto invalid_enum_error;
1232 return ctx->Light.ColorMaterialEnabled;
1233 case GL_CULL_FACE:
1234 return ctx->Polygon.CullFlag;
1235 case GL_DEBUG_OUTPUT:
1236 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB:
1237 return (GLboolean) _mesa_get_debug_state_int(ctx, cap);
1238 case GL_DEPTH_TEST:
1239 return ctx->Depth.Test;
1240 case GL_DITHER:
1241 return ctx->Color.DitherFlag;
1242 case GL_FOG:
1243 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1244 goto invalid_enum_error;
1245 return ctx->Fog.Enabled;
1246 case GL_LIGHTING:
1247 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1248 goto invalid_enum_error;
1249 return ctx->Light.Enabled;
1250 case GL_LIGHT0:
1251 case GL_LIGHT1:
1252 case GL_LIGHT2:
1253 case GL_LIGHT3:
1254 case GL_LIGHT4:
1255 case GL_LIGHT5:
1256 case GL_LIGHT6:
1257 case GL_LIGHT7:
1258 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1259 goto invalid_enum_error;
1260 return ctx->Light.Light[cap-GL_LIGHT0].Enabled;
1261 case GL_LINE_SMOOTH:
1262 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1263 goto invalid_enum_error;
1264 return ctx->Line.SmoothFlag;
1265 case GL_LINE_STIPPLE:
1266 if (ctx->API != API_OPENGL_COMPAT)
1267 goto invalid_enum_error;
1268 return ctx->Line.StippleFlag;
1269 case GL_INDEX_LOGIC_OP:
1270 if (ctx->API != API_OPENGL_COMPAT)
1271 goto invalid_enum_error;
1272 return ctx->Color.IndexLogicOpEnabled;
1273 case GL_COLOR_LOGIC_OP:
1274 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1275 goto invalid_enum_error;
1276 return ctx->Color.ColorLogicOpEnabled;
1277 case GL_MAP1_COLOR_4:
1278 if (ctx->API != API_OPENGL_COMPAT)
1279 goto invalid_enum_error;
1280 return ctx->Eval.Map1Color4;
1281 case GL_MAP1_INDEX:
1282 if (ctx->API != API_OPENGL_COMPAT)
1283 goto invalid_enum_error;
1284 return ctx->Eval.Map1Index;
1285 case GL_MAP1_NORMAL:
1286 if (ctx->API != API_OPENGL_COMPAT)
1287 goto invalid_enum_error;
1288 return ctx->Eval.Map1Normal;
1289 case GL_MAP1_TEXTURE_COORD_1:
1290 if (ctx->API != API_OPENGL_COMPAT)
1291 goto invalid_enum_error;
1292 return ctx->Eval.Map1TextureCoord1;
1293 case GL_MAP1_TEXTURE_COORD_2:
1294 if (ctx->API != API_OPENGL_COMPAT)
1295 goto invalid_enum_error;
1296 return ctx->Eval.Map1TextureCoord2;
1297 case GL_MAP1_TEXTURE_COORD_3:
1298 if (ctx->API != API_OPENGL_COMPAT)
1299 goto invalid_enum_error;
1300 return ctx->Eval.Map1TextureCoord3;
1301 case GL_MAP1_TEXTURE_COORD_4:
1302 if (ctx->API != API_OPENGL_COMPAT)
1303 goto invalid_enum_error;
1304 return ctx->Eval.Map1TextureCoord4;
1305 case GL_MAP1_VERTEX_3:
1306 if (ctx->API != API_OPENGL_COMPAT)
1307 goto invalid_enum_error;
1308 return ctx->Eval.Map1Vertex3;
1309 case GL_MAP1_VERTEX_4:
1310 if (ctx->API != API_OPENGL_COMPAT)
1311 goto invalid_enum_error;
1312 return ctx->Eval.Map1Vertex4;
1313 case GL_MAP2_COLOR_4:
1314 if (ctx->API != API_OPENGL_COMPAT)
1315 goto invalid_enum_error;
1316 return ctx->Eval.Map2Color4;
1317 case GL_MAP2_INDEX:
1318 if (ctx->API != API_OPENGL_COMPAT)
1319 goto invalid_enum_error;
1320 return ctx->Eval.Map2Index;
1321 case GL_MAP2_NORMAL:
1322 if (ctx->API != API_OPENGL_COMPAT)
1323 goto invalid_enum_error;
1324 return ctx->Eval.Map2Normal;
1325 case GL_MAP2_TEXTURE_COORD_1:
1326 if (ctx->API != API_OPENGL_COMPAT)
1327 goto invalid_enum_error;
1328 return ctx->Eval.Map2TextureCoord1;
1329 case GL_MAP2_TEXTURE_COORD_2:
1330 if (ctx->API != API_OPENGL_COMPAT)
1331 goto invalid_enum_error;
1332 return ctx->Eval.Map2TextureCoord2;
1333 case GL_MAP2_TEXTURE_COORD_3:
1334 if (ctx->API != API_OPENGL_COMPAT)
1335 goto invalid_enum_error;
1336 return ctx->Eval.Map2TextureCoord3;
1337 case GL_MAP2_TEXTURE_COORD_4:
1338 if (ctx->API != API_OPENGL_COMPAT)
1339 goto invalid_enum_error;
1340 return ctx->Eval.Map2TextureCoord4;
1341 case GL_MAP2_VERTEX_3:
1342 if (ctx->API != API_OPENGL_COMPAT)
1343 goto invalid_enum_error;
1344 return ctx->Eval.Map2Vertex3;
1345 case GL_MAP2_VERTEX_4:
1346 if (ctx->API != API_OPENGL_COMPAT)
1347 goto invalid_enum_error;
1348 return ctx->Eval.Map2Vertex4;
1349 case GL_NORMALIZE:
1350 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1351 goto invalid_enum_error;
1352 return ctx->Transform.Normalize;
1353 case GL_POINT_SMOOTH:
1354 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1355 goto invalid_enum_error;
1356 return ctx->Point.SmoothFlag;
1357 case GL_POLYGON_SMOOTH:
1358 if (!_mesa_is_desktop_gl(ctx))
1359 goto invalid_enum_error;
1360 return ctx->Polygon.SmoothFlag;
1361 case GL_POLYGON_STIPPLE:
1362 if (ctx->API != API_OPENGL_COMPAT)
1363 goto invalid_enum_error;
1364 return ctx->Polygon.StippleFlag;
1365 case GL_POLYGON_OFFSET_POINT:
1366 if (!_mesa_is_desktop_gl(ctx))
1367 goto invalid_enum_error;
1368 return ctx->Polygon.OffsetPoint;
1369 case GL_POLYGON_OFFSET_LINE:
1370 if (!_mesa_is_desktop_gl(ctx))
1371 goto invalid_enum_error;
1372 return ctx->Polygon.OffsetLine;
1373 case GL_POLYGON_OFFSET_FILL:
1374 return ctx->Polygon.OffsetFill;
1375 case GL_RESCALE_NORMAL_EXT:
1376 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1377 goto invalid_enum_error;
1378 return ctx->Transform.RescaleNormals;
1379 case GL_SCISSOR_TEST:
1380 return ctx->Scissor.EnableFlags & 1; /* return state for index 0 */
1381 case GL_STENCIL_TEST:
1382 return ctx->Stencil.Enabled;
1383 case GL_TEXTURE_1D:
1384 if (ctx->API != API_OPENGL_COMPAT)
1385 goto invalid_enum_error;
1386 return is_texture_enabled(ctx, TEXTURE_1D_BIT);
1387 case GL_TEXTURE_2D:
1388 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1389 goto invalid_enum_error;
1390 return is_texture_enabled(ctx, TEXTURE_2D_BIT);
1391 case GL_TEXTURE_3D:
1392 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1393 goto invalid_enum_error;
1394 return is_texture_enabled(ctx, TEXTURE_3D_BIT);
1395 case GL_TEXTURE_GEN_S:
1396 case GL_TEXTURE_GEN_T:
1397 case GL_TEXTURE_GEN_R:
1398 case GL_TEXTURE_GEN_Q:
1399 {
1400 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1401
1402 if (ctx->API != API_OPENGL_COMPAT)
1403 goto invalid_enum_error;
1404
1405 if (texUnit) {
1406 GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
1407 return (texUnit->TexGenEnabled & coordBit) ? GL_TRUE : GL_FALSE;
1408 }
1409 }
1410 return GL_FALSE;
1411 case GL_TEXTURE_GEN_STR_OES:
1412 {
1413 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1414
1415 if (ctx->API != API_OPENGLES)
1416 goto invalid_enum_error;
1417
1418 if (texUnit) {
1419 return (texUnit->TexGenEnabled & STR_BITS) == STR_BITS
1420 ? GL_TRUE : GL_FALSE;
1421 }
1422 }
1423
1424 /* client-side state */
1425 case GL_VERTEX_ARRAY:
1426 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1427 goto invalid_enum_error;
1428 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POS].Enabled;
1429 case GL_NORMAL_ARRAY:
1430 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1431 goto invalid_enum_error;
1432 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled;
1433 case GL_COLOR_ARRAY:
1434 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1435 goto invalid_enum_error;
1436 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled;
1437 case GL_INDEX_ARRAY:
1438 if (ctx->API != API_OPENGL_COMPAT)
1439 goto invalid_enum_error;
1440 return ctx->Array.VAO->
1441 VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled;
1442 case GL_TEXTURE_COORD_ARRAY:
1443 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1444 goto invalid_enum_error;
1445 return ctx->Array.VAO->
1446 VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Enabled;
1447 case GL_EDGE_FLAG_ARRAY:
1448 if (ctx->API != API_OPENGL_COMPAT)
1449 goto invalid_enum_error;
1450 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled;
1451 case GL_FOG_COORDINATE_ARRAY_EXT:
1452 if (ctx->API != API_OPENGL_COMPAT)
1453 goto invalid_enum_error;
1454 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_FOG].Enabled;
1455 case GL_SECONDARY_COLOR_ARRAY_EXT:
1456 if (ctx->API != API_OPENGL_COMPAT)
1457 goto invalid_enum_error;
1458 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled;
1459 case GL_POINT_SIZE_ARRAY_OES:
1460 if (ctx->API != API_OPENGLES)
1461 goto invalid_enum_error;
1462 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled;
1463
1464 /* GL_ARB_texture_cube_map */
1465 case GL_TEXTURE_CUBE_MAP:
1466 CHECK_EXTENSION(ARB_texture_cube_map);
1467 return is_texture_enabled(ctx, TEXTURE_CUBE_BIT);
1468
1469 /* GL_EXT_secondary_color */
1470 case GL_COLOR_SUM_EXT:
1471 if (ctx->API != API_OPENGL_COMPAT)
1472 goto invalid_enum_error;
1473 return ctx->Fog.ColorSumEnabled;
1474
1475 /* GL_ARB_multisample */
1476 case GL_MULTISAMPLE_ARB:
1477 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1478 goto invalid_enum_error;
1479 return ctx->Multisample.Enabled;
1480 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
1481 return ctx->Multisample.SampleAlphaToCoverage;
1482 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
1483 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1484 goto invalid_enum_error;
1485 return ctx->Multisample.SampleAlphaToOne;
1486 case GL_SAMPLE_COVERAGE_ARB:
1487 return ctx->Multisample.SampleCoverage;
1488 case GL_SAMPLE_COVERAGE_INVERT_ARB:
1489 if (!_mesa_is_desktop_gl(ctx))
1490 goto invalid_enum_error;
1491 return ctx->Multisample.SampleCoverageInvert;
1492
1493 /* GL_IBM_rasterpos_clip */
1494 case GL_RASTER_POSITION_UNCLIPPED_IBM:
1495 if (ctx->API != API_OPENGL_COMPAT)
1496 goto invalid_enum_error;
1497 return ctx->Transform.RasterPositionUnclipped;
1498
1499 /* GL_NV_point_sprite */
1500 case GL_POINT_SPRITE_NV:
1501 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1502 goto invalid_enum_error;
1503 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite)
1504 return ctx->Point.PointSprite;
1505
1506 case GL_VERTEX_PROGRAM_ARB:
1507 if (ctx->API != API_OPENGL_COMPAT)
1508 goto invalid_enum_error;
1509 CHECK_EXTENSION(ARB_vertex_program);
1510 return ctx->VertexProgram.Enabled;
1511 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
1512 /* This was added with ARB_vertex_program, but it is also used with
1513 * GLSL vertex shaders on desktop.
1514 */
1515 if (!_mesa_is_desktop_gl(ctx))
1516 goto invalid_enum_error;
1517 CHECK_EXTENSION(ARB_vertex_program);
1518 return ctx->VertexProgram.PointSizeEnabled;
1519 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
1520 if (ctx->API != API_OPENGL_COMPAT)
1521 goto invalid_enum_error;
1522 CHECK_EXTENSION(ARB_vertex_program);
1523 return ctx->VertexProgram.TwoSideEnabled;
1524
1525 /* GL_NV_texture_rectangle */
1526 case GL_TEXTURE_RECTANGLE_NV:
1527 if (ctx->API != API_OPENGL_COMPAT)
1528 goto invalid_enum_error;
1529 CHECK_EXTENSION(NV_texture_rectangle);
1530 return is_texture_enabled(ctx, TEXTURE_RECT_BIT);
1531
1532 /* GL_EXT_stencil_two_side */
1533 case GL_STENCIL_TEST_TWO_SIDE_EXT:
1534 if (ctx->API != API_OPENGL_COMPAT)
1535 goto invalid_enum_error;
1536 CHECK_EXTENSION(EXT_stencil_two_side);
1537 return ctx->Stencil.TestTwoSide;
1538
1539 case GL_FRAGMENT_PROGRAM_ARB:
1540 if (ctx->API != API_OPENGL_COMPAT)
1541 goto invalid_enum_error;
1542 return ctx->FragmentProgram.Enabled;
1543
1544 /* GL_EXT_depth_bounds_test */
1545 case GL_DEPTH_BOUNDS_TEST_EXT:
1546 if (!_mesa_is_desktop_gl(ctx))
1547 goto invalid_enum_error;
1548 CHECK_EXTENSION(EXT_depth_bounds_test);
1549 return ctx->Depth.BoundsTest;
1550
1551 /* GL_ARB_depth_clamp */
1552 case GL_DEPTH_CLAMP:
1553 if (!_mesa_is_desktop_gl(ctx))
1554 goto invalid_enum_error;
1555 CHECK_EXTENSION(ARB_depth_clamp);
1556 return ctx->Transform.DepthClamp;
1557
1558 case GL_FRAGMENT_SHADER_ATI:
1559 if (ctx->API != API_OPENGL_COMPAT)
1560 goto invalid_enum_error;
1561 CHECK_EXTENSION(ATI_fragment_shader);
1562 return ctx->ATIFragmentShader.Enabled;
1563
1564 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1565 if (!_mesa_is_desktop_gl(ctx))
1566 goto invalid_enum_error;
1567 CHECK_EXTENSION(ARB_seamless_cube_map);
1568 return ctx->Texture.CubeMapSeamless;
1569
1570 case GL_RASTERIZER_DISCARD:
1571 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1572 goto invalid_enum_error;
1573 CHECK_EXTENSION(EXT_transform_feedback);
1574 return ctx->RasterDiscard;
1575
1576 /* GL_NV_primitive_restart */
1577 case GL_PRIMITIVE_RESTART_NV:
1578 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.NV_primitive_restart) {
1579 goto invalid_enum_error;
1580 }
1581 return ctx->Array.PrimitiveRestart;
1582
1583 /* GL 3.1 primitive restart */
1584 case GL_PRIMITIVE_RESTART:
1585 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
1586 goto invalid_enum_error;
1587 }
1588 return ctx->Array.PrimitiveRestart;
1589
1590 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
1591 if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility) {
1592 goto invalid_enum_error;
1593 }
1594 return ctx->Array.PrimitiveRestartFixedIndex;
1595
1596 /* GL3.0 - GL_framebuffer_sRGB */
1597 case GL_FRAMEBUFFER_SRGB_EXT:
1598 if (!_mesa_is_desktop_gl(ctx))
1599 goto invalid_enum_error;
1600 CHECK_EXTENSION(EXT_framebuffer_sRGB);
1601 return ctx->Color.sRGBEnabled;
1602
1603 /* GL_OES_EGL_image_external */
1604 case GL_TEXTURE_EXTERNAL_OES:
1605 if (!_mesa_is_gles(ctx))
1606 goto invalid_enum_error;
1607 CHECK_EXTENSION(OES_EGL_image_external);
1608 return is_texture_enabled(ctx, TEXTURE_EXTERNAL_BIT);
1609
1610 /* ARB_texture_multisample */
1611 case GL_SAMPLE_MASK:
1612 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
1613 goto invalid_enum_error;
1614 CHECK_EXTENSION(ARB_texture_multisample);
1615 return ctx->Multisample.SampleMask;
1616
1617 /* ARB_sample_shading */
1618 case GL_SAMPLE_SHADING:
1619 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1620 goto invalid_enum_error;
1621 CHECK_EXTENSION(ARB_sample_shading);
1622 return ctx->Multisample.SampleShading;
1623
1624 default:
1625 goto invalid_enum_error;
1626 }
1627
1628 return GL_FALSE;
1629
1630 invalid_enum_error:
1631 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(%s)",
1632 _mesa_enum_to_string(cap));
1633 return GL_FALSE;
1634 }