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