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