i965: Move FS instruction scheduling to a non-FS-specific file.
[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 arrayObj->NewArrays |= flag;
144
145 if (ctx->Driver.Enable) {
146 ctx->Driver.Enable( ctx, cap, state );
147 }
148
149 return;
150
151 invalid_enum_error:
152 _mesa_error(ctx, GL_INVALID_ENUM, "gl%sClientState(%s)",
153 state ? "Enable" : "Disable", _mesa_lookup_enum_by_nr(cap));
154 }
155
156
157 /**
158 * Enable GL capability.
159 * \param cap state to enable/disable.
160 *
161 * Get's the current context, assures that we're outside glBegin()/glEnd() and
162 * calls client_state().
163 */
164 void GLAPIENTRY
165 _mesa_EnableClientState( GLenum cap )
166 {
167 GET_CURRENT_CONTEXT(ctx);
168 client_state( ctx, cap, GL_TRUE );
169 }
170
171
172 /**
173 * Disable GL capability.
174 * \param cap state to enable/disable.
175 *
176 * Get's the current context, assures that we're outside glBegin()/glEnd() and
177 * calls client_state().
178 */
179 void GLAPIENTRY
180 _mesa_DisableClientState( GLenum cap )
181 {
182 GET_CURRENT_CONTEXT(ctx);
183 client_state( ctx, cap, GL_FALSE );
184 }
185
186
187 #undef CHECK_EXTENSION
188 #define CHECK_EXTENSION(EXTNAME, CAP) \
189 if (!ctx->Extensions.EXTNAME) { \
190 goto invalid_enum_error; \
191 }
192
193 #define CHECK_EXTENSION2(EXT1, EXT2, CAP) \
194 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
195 goto invalid_enum_error; \
196 }
197
198 /**
199 * Return pointer to current texture unit for setting/getting coordinate
200 * state.
201 * Note that we'll set GL_INVALID_OPERATION and return NULL if the active
202 * texture unit is higher than the number of supported coordinate units.
203 */
204 static struct gl_texture_unit *
205 get_texcoord_unit(struct gl_context *ctx)
206 {
207 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
208 _mesa_error(ctx, GL_INVALID_OPERATION, "glEnable/Disable(texcoord unit)");
209 return NULL;
210 }
211 else {
212 return &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
213 }
214 }
215
216
217 /**
218 * Helper function to enable or disable a texture target.
219 * \param bit one of the TEXTURE_x_BIT values
220 * \return GL_TRUE if state is changing or GL_FALSE if no change
221 */
222 static GLboolean
223 enable_texture(struct gl_context *ctx, GLboolean state, GLbitfield texBit)
224 {
225 struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
226 const GLbitfield newenabled = state
227 ? (texUnit->Enabled | texBit) : (texUnit->Enabled & ~texBit);
228
229 if (texUnit->Enabled == newenabled)
230 return GL_FALSE;
231
232 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
233 texUnit->Enabled = newenabled;
234 return GL_TRUE;
235 }
236
237
238 /**
239 * Helper function to enable or disable GL_MULTISAMPLE, skipping the check for
240 * whether the API supports it (GLES doesn't).
241 */
242 void
243 _mesa_set_multisample(struct gl_context *ctx, GLboolean state)
244 {
245 if (ctx->Multisample.Enabled == state)
246 return;
247 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
248 ctx->Multisample.Enabled = state;
249
250 if (ctx->Driver.Enable) {
251 ctx->Driver.Enable(ctx, GL_MULTISAMPLE, state);
252 }
253 }
254
255 /**
256 * Helper function to enable or disable GL_FRAMEBUFFER_SRGB, skipping the
257 * check for whether the API supports it (GLES doesn't).
258 */
259 void
260 _mesa_set_framebuffer_srgb(struct gl_context *ctx, GLboolean state)
261 {
262 if (ctx->Color.sRGBEnabled == state)
263 return;
264 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
265 ctx->Color.sRGBEnabled = state;
266
267 if (ctx->Driver.Enable) {
268 ctx->Driver.Enable(ctx, GL_FRAMEBUFFER_SRGB, state);
269 }
270 }
271
272 /**
273 * Helper function to enable or disable state.
274 *
275 * \param ctx GL context.
276 * \param cap the state to enable/disable
277 * \param state whether to enable or disable the specified capability.
278 *
279 * Updates the current context and flushes the vertices as needed. For
280 * capabilities associated with extensions it verifies that those extensions
281 * are effectivly present before updating. Notifies the driver via
282 * dd_function_table::Enable.
283 */
284 void
285 _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
286 {
287 if (MESA_VERBOSE & VERBOSE_API)
288 _mesa_debug(ctx, "%s %s (newstate is %x)\n",
289 state ? "glEnable" : "glDisable",
290 _mesa_lookup_enum_by_nr(cap),
291 ctx->NewState);
292
293 switch (cap) {
294 case GL_ALPHA_TEST:
295 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
296 goto invalid_enum_error;
297 if (ctx->Color.AlphaEnabled == state)
298 return;
299 FLUSH_VERTICES(ctx, _NEW_COLOR);
300 ctx->Color.AlphaEnabled = state;
301 break;
302 case GL_AUTO_NORMAL:
303 if (ctx->API != API_OPENGL_COMPAT)
304 goto invalid_enum_error;
305 if (ctx->Eval.AutoNormal == state)
306 return;
307 FLUSH_VERTICES(ctx, _NEW_EVAL);
308 ctx->Eval.AutoNormal = state;
309 break;
310 case GL_BLEND:
311 {
312 GLbitfield newEnabled =
313 state * ((1 << ctx->Const.MaxDrawBuffers) - 1);
314 if (newEnabled != ctx->Color.BlendEnabled) {
315 FLUSH_VERTICES(ctx, _NEW_COLOR);
316 ctx->Color.BlendEnabled = newEnabled;
317 }
318 }
319 break;
320 case GL_CLIP_DISTANCE0:
321 case GL_CLIP_DISTANCE1:
322 case GL_CLIP_DISTANCE2:
323 case GL_CLIP_DISTANCE3:
324 case GL_CLIP_DISTANCE4:
325 case GL_CLIP_DISTANCE5:
326 case GL_CLIP_DISTANCE6:
327 case GL_CLIP_DISTANCE7:
328 {
329 const GLuint p = cap - GL_CLIP_DISTANCE0;
330
331 if (p >= ctx->Const.MaxClipPlanes)
332 goto invalid_enum_error;
333
334 if ((ctx->Transform.ClipPlanesEnabled & (1 << p))
335 == ((GLuint) state << p))
336 return;
337
338 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
339
340 if (state) {
341 ctx->Transform.ClipPlanesEnabled |= (1 << p);
342 _mesa_update_clip_plane(ctx, p);
343 }
344 else {
345 ctx->Transform.ClipPlanesEnabled &= ~(1 << p);
346 }
347 }
348 break;
349 case GL_COLOR_MATERIAL:
350 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
351 goto invalid_enum_error;
352 if (ctx->Light.ColorMaterialEnabled == state)
353 return;
354 FLUSH_VERTICES(ctx, _NEW_LIGHT);
355 FLUSH_CURRENT(ctx, 0);
356 ctx->Light.ColorMaterialEnabled = state;
357 if (state) {
358 _mesa_update_color_material( ctx,
359 ctx->Current.Attrib[VERT_ATTRIB_COLOR0] );
360 }
361 break;
362 case GL_CULL_FACE:
363 if (ctx->Polygon.CullFlag == state)
364 return;
365 FLUSH_VERTICES(ctx, _NEW_POLYGON);
366 ctx->Polygon.CullFlag = state;
367 break;
368 case GL_DEPTH_TEST:
369 if (ctx->Depth.Test == state)
370 return;
371 FLUSH_VERTICES(ctx, _NEW_DEPTH);
372 ctx->Depth.Test = 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 if (ctx->Scissor.Enabled == state)
663 return;
664 FLUSH_VERTICES(ctx, _NEW_SCISSOR);
665 ctx->Scissor.Enabled = state;
666 break;
667 case GL_STENCIL_TEST:
668 if (ctx->Stencil.Enabled == state)
669 return;
670 FLUSH_VERTICES(ctx, _NEW_STENCIL);
671 ctx->Stencil.Enabled = state;
672 break;
673 case GL_TEXTURE_1D:
674 if (ctx->API != API_OPENGL_COMPAT)
675 goto invalid_enum_error;
676 if (!enable_texture(ctx, state, TEXTURE_1D_BIT)) {
677 return;
678 }
679 break;
680 case GL_TEXTURE_2D:
681 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
682 goto invalid_enum_error;
683 if (!enable_texture(ctx, state, TEXTURE_2D_BIT)) {
684 return;
685 }
686 break;
687 case GL_TEXTURE_3D:
688 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
689 goto invalid_enum_error;
690 if (!enable_texture(ctx, state, TEXTURE_3D_BIT)) {
691 return;
692 }
693 break;
694 case GL_TEXTURE_GEN_S:
695 case GL_TEXTURE_GEN_T:
696 case GL_TEXTURE_GEN_R:
697 case GL_TEXTURE_GEN_Q:
698 {
699 struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
700
701 if (ctx->API != API_OPENGL_COMPAT)
702 goto invalid_enum_error;
703
704 if (texUnit) {
705 GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
706 GLbitfield newenabled = texUnit->TexGenEnabled & ~coordBit;
707 if (state)
708 newenabled |= coordBit;
709 if (texUnit->TexGenEnabled == newenabled)
710 return;
711 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
712 texUnit->TexGenEnabled = newenabled;
713 }
714 }
715 break;
716
717 case GL_TEXTURE_GEN_STR_OES:
718 /* disable S, T, and R at the same time */
719 {
720 struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
721
722 if (ctx->API != API_OPENGLES)
723 goto invalid_enum_error;
724
725 if (texUnit) {
726 GLuint newenabled =
727 texUnit->TexGenEnabled & ~STR_BITS;
728 if (state)
729 newenabled |= STR_BITS;
730 if (texUnit->TexGenEnabled == newenabled)
731 return;
732 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
733 texUnit->TexGenEnabled = newenabled;
734 }
735 }
736 break;
737
738 /* client-side state */
739 case GL_VERTEX_ARRAY:
740 case GL_NORMAL_ARRAY:
741 case GL_COLOR_ARRAY:
742 case GL_INDEX_ARRAY:
743 case GL_TEXTURE_COORD_ARRAY:
744 case GL_EDGE_FLAG_ARRAY:
745 case GL_FOG_COORDINATE_ARRAY_EXT:
746 case GL_SECONDARY_COLOR_ARRAY_EXT:
747 case GL_POINT_SIZE_ARRAY_OES:
748 client_state( ctx, cap, state );
749 return;
750
751 /* GL_ARB_texture_cube_map */
752 case GL_TEXTURE_CUBE_MAP_ARB:
753 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
754 goto invalid_enum_error;
755 CHECK_EXTENSION(ARB_texture_cube_map, cap);
756 if (!enable_texture(ctx, state, TEXTURE_CUBE_BIT)) {
757 return;
758 }
759 break;
760
761 /* GL_EXT_secondary_color */
762 case GL_COLOR_SUM_EXT:
763 if (ctx->API != API_OPENGL_COMPAT)
764 goto invalid_enum_error;
765 CHECK_EXTENSION2(EXT_secondary_color, ARB_vertex_program, cap);
766 if (ctx->Fog.ColorSumEnabled == state)
767 return;
768 FLUSH_VERTICES(ctx, _NEW_FOG);
769 ctx->Fog.ColorSumEnabled = state;
770 break;
771
772 /* GL_ARB_multisample */
773 case GL_MULTISAMPLE_ARB:
774 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
775 goto invalid_enum_error;
776 _mesa_set_multisample(ctx, state);
777 return;
778 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
779 if (ctx->Multisample.SampleAlphaToCoverage == state)
780 return;
781 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
782 ctx->Multisample.SampleAlphaToCoverage = state;
783 break;
784 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
785 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
786 goto invalid_enum_error;
787 if (ctx->Multisample.SampleAlphaToOne == state)
788 return;
789 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
790 ctx->Multisample.SampleAlphaToOne = state;
791 break;
792 case GL_SAMPLE_COVERAGE_ARB:
793 if (ctx->Multisample.SampleCoverage == state)
794 return;
795 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
796 ctx->Multisample.SampleCoverage = state;
797 break;
798 case GL_SAMPLE_COVERAGE_INVERT_ARB:
799 if (!_mesa_is_desktop_gl(ctx))
800 goto invalid_enum_error;
801 if (ctx->Multisample.SampleCoverageInvert == state)
802 return;
803 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
804 ctx->Multisample.SampleCoverageInvert = state;
805 break;
806
807 /* GL_IBM_rasterpos_clip */
808 case GL_RASTER_POSITION_UNCLIPPED_IBM:
809 if (ctx->API != API_OPENGL_COMPAT)
810 goto invalid_enum_error;
811 if (ctx->Transform.RasterPositionUnclipped == state)
812 return;
813 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
814 ctx->Transform.RasterPositionUnclipped = state;
815 break;
816
817 /* GL_NV_point_sprite */
818 case GL_POINT_SPRITE_NV:
819 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
820 goto invalid_enum_error;
821 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite, cap);
822 if (ctx->Point.PointSprite == state)
823 return;
824 FLUSH_VERTICES(ctx, _NEW_POINT);
825 ctx->Point.PointSprite = state;
826 break;
827
828 case GL_VERTEX_PROGRAM_ARB:
829 if (ctx->API != API_OPENGL_COMPAT)
830 goto invalid_enum_error;
831 CHECK_EXTENSION(ARB_vertex_program, cap);
832 if (ctx->VertexProgram.Enabled == state)
833 return;
834 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
835 ctx->VertexProgram.Enabled = state;
836 break;
837 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
838 /* This was added with ARB_vertex_program, but it is also used with
839 * GLSL vertex shaders on desktop.
840 */
841 if (!_mesa_is_desktop_gl(ctx))
842 goto invalid_enum_error;
843 CHECK_EXTENSION(ARB_vertex_program, cap);
844 if (ctx->VertexProgram.PointSizeEnabled == state)
845 return;
846 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
847 ctx->VertexProgram.PointSizeEnabled = state;
848 break;
849 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
850 if (ctx->API != API_OPENGL_COMPAT)
851 goto invalid_enum_error;
852 CHECK_EXTENSION(ARB_vertex_program, cap);
853 if (ctx->VertexProgram.TwoSideEnabled == state)
854 return;
855 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
856 ctx->VertexProgram.TwoSideEnabled = state;
857 break;
858
859 /* GL_NV_texture_rectangle */
860 case GL_TEXTURE_RECTANGLE_NV:
861 if (ctx->API != API_OPENGL_COMPAT)
862 goto invalid_enum_error;
863 CHECK_EXTENSION(NV_texture_rectangle, cap);
864 if (!enable_texture(ctx, state, TEXTURE_RECT_BIT)) {
865 return;
866 }
867 break;
868
869 /* GL_EXT_stencil_two_side */
870 case GL_STENCIL_TEST_TWO_SIDE_EXT:
871 if (ctx->API != API_OPENGL_COMPAT)
872 goto invalid_enum_error;
873 CHECK_EXTENSION(EXT_stencil_two_side, cap);
874 if (ctx->Stencil.TestTwoSide == state)
875 return;
876 FLUSH_VERTICES(ctx, _NEW_STENCIL);
877 ctx->Stencil.TestTwoSide = state;
878 if (state) {
879 ctx->Stencil._BackFace = 2;
880 } else {
881 ctx->Stencil._BackFace = 1;
882 }
883 break;
884
885 case GL_FRAGMENT_PROGRAM_ARB:
886 if (ctx->API != API_OPENGL_COMPAT)
887 goto invalid_enum_error;
888 CHECK_EXTENSION(ARB_fragment_program, cap);
889 if (ctx->FragmentProgram.Enabled == state)
890 return;
891 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
892 ctx->FragmentProgram.Enabled = state;
893 break;
894
895 /* GL_EXT_depth_bounds_test */
896 case GL_DEPTH_BOUNDS_TEST_EXT:
897 if (!_mesa_is_desktop_gl(ctx))
898 goto invalid_enum_error;
899 CHECK_EXTENSION(EXT_depth_bounds_test, cap);
900 if (ctx->Depth.BoundsTest == state)
901 return;
902 FLUSH_VERTICES(ctx, _NEW_DEPTH);
903 ctx->Depth.BoundsTest = state;
904 break;
905
906 case GL_DEPTH_CLAMP:
907 if (!_mesa_is_desktop_gl(ctx))
908 goto invalid_enum_error;
909 CHECK_EXTENSION(ARB_depth_clamp, cap);
910 if (ctx->Transform.DepthClamp == state)
911 return;
912 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
913 ctx->Transform.DepthClamp = state;
914 break;
915
916 case GL_FRAGMENT_SHADER_ATI:
917 if (ctx->API != API_OPENGL_COMPAT)
918 goto invalid_enum_error;
919 CHECK_EXTENSION(ATI_fragment_shader, cap);
920 if (ctx->ATIFragmentShader.Enabled == state)
921 return;
922 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
923 ctx->ATIFragmentShader.Enabled = state;
924 break;
925
926 /* GL_MESA_texture_array */
927 case GL_TEXTURE_1D_ARRAY_EXT:
928 if (ctx->API != API_OPENGL_COMPAT)
929 goto invalid_enum_error;
930 CHECK_EXTENSION(MESA_texture_array, cap);
931 if (!enable_texture(ctx, state, TEXTURE_1D_ARRAY_BIT)) {
932 return;
933 }
934 break;
935
936 case GL_TEXTURE_2D_ARRAY_EXT:
937 if (ctx->API != API_OPENGL_COMPAT)
938 goto invalid_enum_error;
939 CHECK_EXTENSION(MESA_texture_array, cap);
940 if (!enable_texture(ctx, state, TEXTURE_2D_ARRAY_BIT)) {
941 return;
942 }
943 break;
944
945 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
946 if (!_mesa_is_desktop_gl(ctx))
947 goto invalid_enum_error;
948 CHECK_EXTENSION(ARB_seamless_cube_map, cap);
949 if (ctx->Texture.CubeMapSeamless != state) {
950 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
951 ctx->Texture.CubeMapSeamless = state;
952 }
953 break;
954
955 case GL_RASTERIZER_DISCARD:
956 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
957 goto invalid_enum_error;
958 CHECK_EXTENSION(EXT_transform_feedback, cap);
959 if (ctx->RasterDiscard != state) {
960 FLUSH_VERTICES(ctx, 0);
961 ctx->NewDriverState |= ctx->DriverFlags.NewRasterizerDiscard;
962 ctx->RasterDiscard = state;
963 }
964 break;
965
966 /* GL 3.1 primitive restart. Note: this enum is different from
967 * GL_PRIMITIVE_RESTART_NV (which is client state).
968 */
969 case GL_PRIMITIVE_RESTART:
970 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
971 goto invalid_enum_error;
972 }
973 if (ctx->Array.PrimitiveRestart != state) {
974 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
975 ctx->Array.PrimitiveRestart = state;
976 update_derived_primitive_restart_state(ctx);
977 }
978 break;
979
980 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
981 if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility)
982 goto invalid_enum_error;
983 if (ctx->Array.PrimitiveRestartFixedIndex != state) {
984 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
985 ctx->Array.PrimitiveRestartFixedIndex = state;
986 update_derived_primitive_restart_state(ctx);
987 }
988 break;
989
990 /* GL3.0 - GL_framebuffer_sRGB */
991 case GL_FRAMEBUFFER_SRGB_EXT:
992 if (!_mesa_is_desktop_gl(ctx))
993 goto invalid_enum_error;
994 CHECK_EXTENSION(EXT_framebuffer_sRGB, cap);
995 _mesa_set_framebuffer_srgb(ctx, state);
996 return;
997
998 /* GL_OES_EGL_image_external */
999 case GL_TEXTURE_EXTERNAL_OES:
1000 if (!_mesa_is_gles(ctx))
1001 goto invalid_enum_error;
1002 CHECK_EXTENSION(OES_EGL_image_external, cap);
1003 if (!enable_texture(ctx, state, TEXTURE_EXTERNAL_BIT)) {
1004 return;
1005 }
1006 break;
1007
1008 /* ARB_texture_multisample */
1009 case GL_SAMPLE_MASK:
1010 if (!_mesa_is_desktop_gl(ctx))
1011 goto invalid_enum_error;
1012 CHECK_EXTENSION(ARB_texture_multisample, cap);
1013 if (ctx->Multisample.SampleMask == state)
1014 return;
1015 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
1016 ctx->Multisample.SampleMask = state;
1017 break;
1018
1019 default:
1020 goto invalid_enum_error;
1021 }
1022
1023 if (ctx->Driver.Enable) {
1024 ctx->Driver.Enable( ctx, cap, state );
1025 }
1026
1027 return;
1028
1029 invalid_enum_error:
1030 _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(%s)",
1031 state ? "Enable" : "Disable", _mesa_lookup_enum_by_nr(cap));
1032 }
1033
1034
1035 /**
1036 * Enable GL capability. Called by glEnable()
1037 * \param cap state to enable.
1038 */
1039 void GLAPIENTRY
1040 _mesa_Enable( GLenum cap )
1041 {
1042 GET_CURRENT_CONTEXT(ctx);
1043
1044 _mesa_set_enable( ctx, cap, GL_TRUE );
1045 }
1046
1047
1048 /**
1049 * Disable GL capability. Called by glDisable()
1050 * \param cap state to disable.
1051 */
1052 void GLAPIENTRY
1053 _mesa_Disable( GLenum cap )
1054 {
1055 GET_CURRENT_CONTEXT(ctx);
1056
1057 _mesa_set_enable( ctx, cap, GL_FALSE );
1058 }
1059
1060
1061
1062 /**
1063 * Enable/disable an indexed state var.
1064 */
1065 void
1066 _mesa_set_enablei(struct gl_context *ctx, GLenum cap,
1067 GLuint index, GLboolean state)
1068 {
1069 ASSERT(state == 0 || state == 1);
1070 switch (cap) {
1071 case GL_BLEND:
1072 if (!ctx->Extensions.EXT_draw_buffers2) {
1073 goto invalid_enum_error;
1074 }
1075 if (index >= ctx->Const.MaxDrawBuffers) {
1076 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1077 state ? "glEnableIndexed" : "glDisableIndexed", index);
1078 return;
1079 }
1080 if (((ctx->Color.BlendEnabled >> index) & 1) != state) {
1081 FLUSH_VERTICES(ctx, _NEW_COLOR);
1082 if (state)
1083 ctx->Color.BlendEnabled |= (1 << index);
1084 else
1085 ctx->Color.BlendEnabled &= ~(1 << index);
1086 }
1087 break;
1088 default:
1089 goto invalid_enum_error;
1090 }
1091 return;
1092
1093 invalid_enum_error:
1094 _mesa_error(ctx, GL_INVALID_ENUM, "%s(cap=%s)",
1095 state ? "glEnablei" : "glDisablei",
1096 _mesa_lookup_enum_by_nr(cap));
1097 }
1098
1099
1100 void GLAPIENTRY
1101 _mesa_Disablei( GLenum cap, GLuint index )
1102 {
1103 GET_CURRENT_CONTEXT(ctx);
1104 _mesa_set_enablei(ctx, cap, index, GL_FALSE);
1105 }
1106
1107
1108 void GLAPIENTRY
1109 _mesa_Enablei( GLenum cap, GLuint index )
1110 {
1111 GET_CURRENT_CONTEXT(ctx);
1112 _mesa_set_enablei(ctx, cap, index, GL_TRUE);
1113 }
1114
1115
1116 GLboolean GLAPIENTRY
1117 _mesa_IsEnabledi( GLenum cap, GLuint index )
1118 {
1119 GET_CURRENT_CONTEXT(ctx);
1120 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1121 switch (cap) {
1122 case GL_BLEND:
1123 if (index >= ctx->Const.MaxDrawBuffers) {
1124 _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
1125 index);
1126 return GL_FALSE;
1127 }
1128 return (ctx->Color.BlendEnabled >> index) & 1;
1129 default:
1130 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabledIndexed(cap=%s)",
1131 _mesa_lookup_enum_by_nr(cap));
1132 return GL_FALSE;
1133 }
1134 }
1135
1136
1137
1138
1139 #undef CHECK_EXTENSION
1140 #define CHECK_EXTENSION(EXTNAME) \
1141 if (!ctx->Extensions.EXTNAME) { \
1142 goto invalid_enum_error; \
1143 }
1144
1145 #undef CHECK_EXTENSION2
1146 #define CHECK_EXTENSION2(EXT1, EXT2) \
1147 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1148 goto invalid_enum_error; \
1149 }
1150
1151
1152 /**
1153 * Helper function to determine whether a texture target is enabled.
1154 */
1155 static GLboolean
1156 is_texture_enabled(struct gl_context *ctx, GLbitfield bit)
1157 {
1158 const struct gl_texture_unit *const texUnit =
1159 &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1160 return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE;
1161 }
1162
1163
1164 /**
1165 * Return simple enable/disable state.
1166 *
1167 * \param cap state variable to query.
1168 *
1169 * Returns the state of the specified capability from the current GL context.
1170 * For the capabilities associated with extensions verifies that those
1171 * extensions are effectively present before reporting.
1172 */
1173 GLboolean GLAPIENTRY
1174 _mesa_IsEnabled( GLenum cap )
1175 {
1176 GET_CURRENT_CONTEXT(ctx);
1177 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1178
1179 switch (cap) {
1180 case GL_ALPHA_TEST:
1181 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1182 goto invalid_enum_error;
1183 return ctx->Color.AlphaEnabled;
1184 case GL_AUTO_NORMAL:
1185 if (ctx->API != API_OPENGL_COMPAT)
1186 goto invalid_enum_error;
1187 return ctx->Eval.AutoNormal;
1188 case GL_BLEND:
1189 return ctx->Color.BlendEnabled & 1; /* return state for buffer[0] */
1190 case GL_CLIP_DISTANCE0:
1191 case GL_CLIP_DISTANCE1:
1192 case GL_CLIP_DISTANCE2:
1193 case GL_CLIP_DISTANCE3:
1194 case GL_CLIP_DISTANCE4:
1195 case GL_CLIP_DISTANCE5:
1196 case GL_CLIP_DISTANCE6:
1197 case GL_CLIP_DISTANCE7: {
1198 const GLuint p = cap - GL_CLIP_DISTANCE0;
1199
1200 if (p >= ctx->Const.MaxClipPlanes)
1201 goto invalid_enum_error;
1202
1203 return (ctx->Transform.ClipPlanesEnabled >> p) & 1;
1204 }
1205 case GL_COLOR_MATERIAL:
1206 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1207 goto invalid_enum_error;
1208 return ctx->Light.ColorMaterialEnabled;
1209 case GL_CULL_FACE:
1210 return ctx->Polygon.CullFlag;
1211 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB:
1212 if (!_mesa_is_desktop_gl(ctx))
1213 goto invalid_enum_error;
1214 return ctx->Debug.SyncOutput;
1215 case GL_DEPTH_TEST:
1216 return ctx->Depth.Test;
1217 case GL_DITHER:
1218 return ctx->Color.DitherFlag;
1219 case GL_FOG:
1220 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1221 goto invalid_enum_error;
1222 return ctx->Fog.Enabled;
1223 case GL_LIGHTING:
1224 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1225 goto invalid_enum_error;
1226 return ctx->Light.Enabled;
1227 case GL_LIGHT0:
1228 case GL_LIGHT1:
1229 case GL_LIGHT2:
1230 case GL_LIGHT3:
1231 case GL_LIGHT4:
1232 case GL_LIGHT5:
1233 case GL_LIGHT6:
1234 case GL_LIGHT7:
1235 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1236 goto invalid_enum_error;
1237 return ctx->Light.Light[cap-GL_LIGHT0].Enabled;
1238 case GL_LINE_SMOOTH:
1239 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1240 goto invalid_enum_error;
1241 return ctx->Line.SmoothFlag;
1242 case GL_LINE_STIPPLE:
1243 if (ctx->API != API_OPENGL_COMPAT)
1244 goto invalid_enum_error;
1245 return ctx->Line.StippleFlag;
1246 case GL_INDEX_LOGIC_OP:
1247 if (ctx->API != API_OPENGL_COMPAT)
1248 goto invalid_enum_error;
1249 return ctx->Color.IndexLogicOpEnabled;
1250 case GL_COLOR_LOGIC_OP:
1251 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1252 goto invalid_enum_error;
1253 return ctx->Color.ColorLogicOpEnabled;
1254 case GL_MAP1_COLOR_4:
1255 if (ctx->API != API_OPENGL_COMPAT)
1256 goto invalid_enum_error;
1257 return ctx->Eval.Map1Color4;
1258 case GL_MAP1_INDEX:
1259 if (ctx->API != API_OPENGL_COMPAT)
1260 goto invalid_enum_error;
1261 return ctx->Eval.Map1Index;
1262 case GL_MAP1_NORMAL:
1263 if (ctx->API != API_OPENGL_COMPAT)
1264 goto invalid_enum_error;
1265 return ctx->Eval.Map1Normal;
1266 case GL_MAP1_TEXTURE_COORD_1:
1267 if (ctx->API != API_OPENGL_COMPAT)
1268 goto invalid_enum_error;
1269 return ctx->Eval.Map1TextureCoord1;
1270 case GL_MAP1_TEXTURE_COORD_2:
1271 if (ctx->API != API_OPENGL_COMPAT)
1272 goto invalid_enum_error;
1273 return ctx->Eval.Map1TextureCoord2;
1274 case GL_MAP1_TEXTURE_COORD_3:
1275 if (ctx->API != API_OPENGL_COMPAT)
1276 goto invalid_enum_error;
1277 return ctx->Eval.Map1TextureCoord3;
1278 case GL_MAP1_TEXTURE_COORD_4:
1279 if (ctx->API != API_OPENGL_COMPAT)
1280 goto invalid_enum_error;
1281 return ctx->Eval.Map1TextureCoord4;
1282 case GL_MAP1_VERTEX_3:
1283 if (ctx->API != API_OPENGL_COMPAT)
1284 goto invalid_enum_error;
1285 return ctx->Eval.Map1Vertex3;
1286 case GL_MAP1_VERTEX_4:
1287 if (ctx->API != API_OPENGL_COMPAT)
1288 goto invalid_enum_error;
1289 return ctx->Eval.Map1Vertex4;
1290 case GL_MAP2_COLOR_4:
1291 if (ctx->API != API_OPENGL_COMPAT)
1292 goto invalid_enum_error;
1293 return ctx->Eval.Map2Color4;
1294 case GL_MAP2_INDEX:
1295 if (ctx->API != API_OPENGL_COMPAT)
1296 goto invalid_enum_error;
1297 return ctx->Eval.Map2Index;
1298 case GL_MAP2_NORMAL:
1299 if (ctx->API != API_OPENGL_COMPAT)
1300 goto invalid_enum_error;
1301 return ctx->Eval.Map2Normal;
1302 case GL_MAP2_TEXTURE_COORD_1:
1303 if (ctx->API != API_OPENGL_COMPAT)
1304 goto invalid_enum_error;
1305 return ctx->Eval.Map2TextureCoord1;
1306 case GL_MAP2_TEXTURE_COORD_2:
1307 if (ctx->API != API_OPENGL_COMPAT)
1308 goto invalid_enum_error;
1309 return ctx->Eval.Map2TextureCoord2;
1310 case GL_MAP2_TEXTURE_COORD_3:
1311 if (ctx->API != API_OPENGL_COMPAT)
1312 goto invalid_enum_error;
1313 return ctx->Eval.Map2TextureCoord3;
1314 case GL_MAP2_TEXTURE_COORD_4:
1315 if (ctx->API != API_OPENGL_COMPAT)
1316 goto invalid_enum_error;
1317 return ctx->Eval.Map2TextureCoord4;
1318 case GL_MAP2_VERTEX_3:
1319 if (ctx->API != API_OPENGL_COMPAT)
1320 goto invalid_enum_error;
1321 return ctx->Eval.Map2Vertex3;
1322 case GL_MAP2_VERTEX_4:
1323 if (ctx->API != API_OPENGL_COMPAT)
1324 goto invalid_enum_error;
1325 return ctx->Eval.Map2Vertex4;
1326 case GL_NORMALIZE:
1327 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1328 goto invalid_enum_error;
1329 return ctx->Transform.Normalize;
1330 case GL_POINT_SMOOTH:
1331 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1332 goto invalid_enum_error;
1333 return ctx->Point.SmoothFlag;
1334 case GL_POLYGON_SMOOTH:
1335 if (!_mesa_is_desktop_gl(ctx))
1336 goto invalid_enum_error;
1337 return ctx->Polygon.SmoothFlag;
1338 case GL_POLYGON_STIPPLE:
1339 if (ctx->API != API_OPENGL_COMPAT)
1340 goto invalid_enum_error;
1341 return ctx->Polygon.StippleFlag;
1342 case GL_POLYGON_OFFSET_POINT:
1343 if (!_mesa_is_desktop_gl(ctx))
1344 goto invalid_enum_error;
1345 return ctx->Polygon.OffsetPoint;
1346 case GL_POLYGON_OFFSET_LINE:
1347 if (!_mesa_is_desktop_gl(ctx))
1348 goto invalid_enum_error;
1349 return ctx->Polygon.OffsetLine;
1350 case GL_POLYGON_OFFSET_FILL:
1351 return ctx->Polygon.OffsetFill;
1352 case GL_RESCALE_NORMAL_EXT:
1353 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1354 goto invalid_enum_error;
1355 return ctx->Transform.RescaleNormals;
1356 case GL_SCISSOR_TEST:
1357 return ctx->Scissor.Enabled;
1358 case GL_STENCIL_TEST:
1359 return ctx->Stencil.Enabled;
1360 case GL_TEXTURE_1D:
1361 if (ctx->API != API_OPENGL_COMPAT)
1362 goto invalid_enum_error;
1363 return is_texture_enabled(ctx, TEXTURE_1D_BIT);
1364 case GL_TEXTURE_2D:
1365 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1366 goto invalid_enum_error;
1367 return is_texture_enabled(ctx, TEXTURE_2D_BIT);
1368 case GL_TEXTURE_3D:
1369 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1370 goto invalid_enum_error;
1371 return is_texture_enabled(ctx, TEXTURE_3D_BIT);
1372 case GL_TEXTURE_GEN_S:
1373 case GL_TEXTURE_GEN_T:
1374 case GL_TEXTURE_GEN_R:
1375 case GL_TEXTURE_GEN_Q:
1376 {
1377 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1378
1379 if (ctx->API != API_OPENGL_COMPAT)
1380 goto invalid_enum_error;
1381
1382 if (texUnit) {
1383 GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
1384 return (texUnit->TexGenEnabled & coordBit) ? GL_TRUE : GL_FALSE;
1385 }
1386 }
1387 return GL_FALSE;
1388 case GL_TEXTURE_GEN_STR_OES:
1389 {
1390 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1391
1392 if (ctx->API != API_OPENGLES)
1393 goto invalid_enum_error;
1394
1395 if (texUnit) {
1396 return (texUnit->TexGenEnabled & STR_BITS) == STR_BITS
1397 ? GL_TRUE : GL_FALSE;
1398 }
1399 }
1400
1401 /* client-side state */
1402 case GL_VERTEX_ARRAY:
1403 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1404 goto invalid_enum_error;
1405 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POS].Enabled != 0);
1406 case GL_NORMAL_ARRAY:
1407 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1408 goto invalid_enum_error;
1409 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled != 0);
1410 case GL_COLOR_ARRAY:
1411 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1412 goto invalid_enum_error;
1413 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled != 0);
1414 case GL_INDEX_ARRAY:
1415 if (ctx->API != API_OPENGL_COMPAT)
1416 goto invalid_enum_error;
1417 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled != 0);
1418 case GL_TEXTURE_COORD_ARRAY:
1419 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1420 goto invalid_enum_error;
1421 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)]
1422 .Enabled != 0);
1423 case GL_EDGE_FLAG_ARRAY:
1424 if (ctx->API != API_OPENGL_COMPAT)
1425 goto invalid_enum_error;
1426 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled != 0);
1427 case GL_FOG_COORDINATE_ARRAY_EXT:
1428 if (ctx->API != API_OPENGL_COMPAT)
1429 goto invalid_enum_error;
1430 CHECK_EXTENSION(EXT_fog_coord);
1431 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_FOG].Enabled != 0);
1432 case GL_SECONDARY_COLOR_ARRAY_EXT:
1433 if (ctx->API != API_OPENGL_COMPAT)
1434 goto invalid_enum_error;
1435 CHECK_EXTENSION(EXT_secondary_color);
1436 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled != 0);
1437 case GL_POINT_SIZE_ARRAY_OES:
1438 if (ctx->API != API_OPENGLES)
1439 goto invalid_enum_error;
1440 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled != 0);
1441
1442 /* GL_ARB_texture_cube_map */
1443 case GL_TEXTURE_CUBE_MAP_ARB:
1444 CHECK_EXTENSION(ARB_texture_cube_map);
1445 return is_texture_enabled(ctx, TEXTURE_CUBE_BIT);
1446
1447 /* GL_EXT_secondary_color */
1448 case GL_COLOR_SUM_EXT:
1449 if (ctx->API != API_OPENGL_COMPAT)
1450 goto invalid_enum_error;
1451 CHECK_EXTENSION2(EXT_secondary_color, ARB_vertex_program);
1452 return ctx->Fog.ColorSumEnabled;
1453
1454 /* GL_ARB_multisample */
1455 case GL_MULTISAMPLE_ARB:
1456 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1457 goto invalid_enum_error;
1458 return ctx->Multisample.Enabled;
1459 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
1460 return ctx->Multisample.SampleAlphaToCoverage;
1461 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
1462 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1463 goto invalid_enum_error;
1464 return ctx->Multisample.SampleAlphaToOne;
1465 case GL_SAMPLE_COVERAGE_ARB:
1466 return ctx->Multisample.SampleCoverage;
1467 case GL_SAMPLE_COVERAGE_INVERT_ARB:
1468 if (!_mesa_is_desktop_gl(ctx))
1469 goto invalid_enum_error;
1470 return ctx->Multisample.SampleCoverageInvert;
1471
1472 /* GL_IBM_rasterpos_clip */
1473 case GL_RASTER_POSITION_UNCLIPPED_IBM:
1474 if (ctx->API != API_OPENGL_COMPAT)
1475 goto invalid_enum_error;
1476 return ctx->Transform.RasterPositionUnclipped;
1477
1478 /* GL_NV_point_sprite */
1479 case GL_POINT_SPRITE_NV:
1480 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1481 goto invalid_enum_error;
1482 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite)
1483 return ctx->Point.PointSprite;
1484
1485 case GL_VERTEX_PROGRAM_ARB:
1486 if (ctx->API != API_OPENGL_COMPAT)
1487 goto invalid_enum_error;
1488 CHECK_EXTENSION(ARB_vertex_program);
1489 return ctx->VertexProgram.Enabled;
1490 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
1491 /* This was added with ARB_vertex_program, but it is also used with
1492 * GLSL vertex shaders on desktop.
1493 */
1494 if (!_mesa_is_desktop_gl(ctx))
1495 goto invalid_enum_error;
1496 CHECK_EXTENSION(ARB_vertex_program);
1497 return ctx->VertexProgram.PointSizeEnabled;
1498 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
1499 if (ctx->API != API_OPENGL_COMPAT)
1500 goto invalid_enum_error;
1501 CHECK_EXTENSION(ARB_vertex_program);
1502 return ctx->VertexProgram.TwoSideEnabled;
1503
1504 /* GL_NV_texture_rectangle */
1505 case GL_TEXTURE_RECTANGLE_NV:
1506 if (ctx->API != API_OPENGL_COMPAT)
1507 goto invalid_enum_error;
1508 CHECK_EXTENSION(NV_texture_rectangle);
1509 return is_texture_enabled(ctx, TEXTURE_RECT_BIT);
1510
1511 /* GL_EXT_stencil_two_side */
1512 case GL_STENCIL_TEST_TWO_SIDE_EXT:
1513 if (ctx->API != API_OPENGL_COMPAT)
1514 goto invalid_enum_error;
1515 CHECK_EXTENSION(EXT_stencil_two_side);
1516 return ctx->Stencil.TestTwoSide;
1517
1518 case GL_FRAGMENT_PROGRAM_ARB:
1519 if (ctx->API != API_OPENGL_COMPAT)
1520 goto invalid_enum_error;
1521 return ctx->FragmentProgram.Enabled;
1522
1523 /* GL_EXT_depth_bounds_test */
1524 case GL_DEPTH_BOUNDS_TEST_EXT:
1525 if (!_mesa_is_desktop_gl(ctx))
1526 goto invalid_enum_error;
1527 CHECK_EXTENSION(EXT_depth_bounds_test);
1528 return ctx->Depth.BoundsTest;
1529
1530 /* GL_ARB_depth_clamp */
1531 case GL_DEPTH_CLAMP:
1532 if (!_mesa_is_desktop_gl(ctx))
1533 goto invalid_enum_error;
1534 CHECK_EXTENSION(ARB_depth_clamp);
1535 return ctx->Transform.DepthClamp;
1536
1537 case GL_FRAGMENT_SHADER_ATI:
1538 if (ctx->API != API_OPENGL_COMPAT)
1539 goto invalid_enum_error;
1540 CHECK_EXTENSION(ATI_fragment_shader);
1541 return ctx->ATIFragmentShader.Enabled;
1542
1543 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1544 if (!_mesa_is_desktop_gl(ctx))
1545 goto invalid_enum_error;
1546 CHECK_EXTENSION(ARB_seamless_cube_map);
1547 return ctx->Texture.CubeMapSeamless;
1548
1549 case GL_RASTERIZER_DISCARD:
1550 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1551 goto invalid_enum_error;
1552 CHECK_EXTENSION(EXT_transform_feedback);
1553 return ctx->RasterDiscard;
1554
1555 /* GL_NV_primitive_restart */
1556 case GL_PRIMITIVE_RESTART_NV:
1557 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.NV_primitive_restart) {
1558 goto invalid_enum_error;
1559 }
1560 return ctx->Array.PrimitiveRestart;
1561
1562 /* GL 3.1 primitive restart */
1563 case GL_PRIMITIVE_RESTART:
1564 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
1565 goto invalid_enum_error;
1566 }
1567 return ctx->Array.PrimitiveRestart;
1568
1569 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
1570 if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility) {
1571 goto invalid_enum_error;
1572 }
1573 return ctx->Array.PrimitiveRestartFixedIndex;
1574
1575 /* GL3.0 - GL_framebuffer_sRGB */
1576 case GL_FRAMEBUFFER_SRGB_EXT:
1577 if (!_mesa_is_desktop_gl(ctx))
1578 goto invalid_enum_error;
1579 CHECK_EXTENSION(EXT_framebuffer_sRGB);
1580 return ctx->Color.sRGBEnabled;
1581
1582 /* GL_OES_EGL_image_external */
1583 case GL_TEXTURE_EXTERNAL_OES:
1584 if (!_mesa_is_gles(ctx))
1585 goto invalid_enum_error;
1586 CHECK_EXTENSION(OES_EGL_image_external);
1587 return is_texture_enabled(ctx, TEXTURE_EXTERNAL_BIT);
1588
1589 /* ARB_texture_multisample */
1590 case GL_SAMPLE_MASK:
1591 if (!_mesa_is_desktop_gl(ctx))
1592 goto invalid_enum_error;
1593 CHECK_EXTENSION(ARB_texture_multisample);
1594 return ctx->Multisample.SampleMask;
1595
1596 default:
1597 goto invalid_enum_error;
1598 }
1599
1600 return GL_FALSE;
1601
1602 invalid_enum_error:
1603 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(%s)",
1604 _mesa_lookup_enum_by_nr(cap));
1605 return GL_FALSE;
1606 }