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