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