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