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