mesa: Add flush_vertices to _mesa_{enable,disable}_vertex_array_attrib.
[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, true);
72 else
73 _mesa_disable_vertex_array_attrib(ctx, ctx->Array.VAO, attr, true);
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_COLOR_LOGIC_OP:
486 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
487 goto invalid_enum_error;
488 if (ctx->Color.ColorLogicOpEnabled == state)
489 return;
490 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLogicOp ? 0 : _NEW_COLOR);
491 ctx->NewDriverState |= ctx->DriverFlags.NewLogicOp;
492 ctx->Color.ColorLogicOpEnabled = state;
493 break;
494 case GL_MAP1_COLOR_4:
495 if (ctx->API != API_OPENGL_COMPAT)
496 goto invalid_enum_error;
497 if (ctx->Eval.Map1Color4 == state)
498 return;
499 FLUSH_VERTICES(ctx, _NEW_EVAL);
500 ctx->Eval.Map1Color4 = state;
501 break;
502 case GL_MAP1_INDEX:
503 if (ctx->API != API_OPENGL_COMPAT)
504 goto invalid_enum_error;
505 if (ctx->Eval.Map1Index == state)
506 return;
507 FLUSH_VERTICES(ctx, _NEW_EVAL);
508 ctx->Eval.Map1Index = state;
509 break;
510 case GL_MAP1_NORMAL:
511 if (ctx->API != API_OPENGL_COMPAT)
512 goto invalid_enum_error;
513 if (ctx->Eval.Map1Normal == state)
514 return;
515 FLUSH_VERTICES(ctx, _NEW_EVAL);
516 ctx->Eval.Map1Normal = state;
517 break;
518 case GL_MAP1_TEXTURE_COORD_1:
519 if (ctx->API != API_OPENGL_COMPAT)
520 goto invalid_enum_error;
521 if (ctx->Eval.Map1TextureCoord1 == state)
522 return;
523 FLUSH_VERTICES(ctx, _NEW_EVAL);
524 ctx->Eval.Map1TextureCoord1 = state;
525 break;
526 case GL_MAP1_TEXTURE_COORD_2:
527 if (ctx->API != API_OPENGL_COMPAT)
528 goto invalid_enum_error;
529 if (ctx->Eval.Map1TextureCoord2 == state)
530 return;
531 FLUSH_VERTICES(ctx, _NEW_EVAL);
532 ctx->Eval.Map1TextureCoord2 = state;
533 break;
534 case GL_MAP1_TEXTURE_COORD_3:
535 if (ctx->API != API_OPENGL_COMPAT)
536 goto invalid_enum_error;
537 if (ctx->Eval.Map1TextureCoord3 == state)
538 return;
539 FLUSH_VERTICES(ctx, _NEW_EVAL);
540 ctx->Eval.Map1TextureCoord3 = state;
541 break;
542 case GL_MAP1_TEXTURE_COORD_4:
543 if (ctx->API != API_OPENGL_COMPAT)
544 goto invalid_enum_error;
545 if (ctx->Eval.Map1TextureCoord4 == state)
546 return;
547 FLUSH_VERTICES(ctx, _NEW_EVAL);
548 ctx->Eval.Map1TextureCoord4 = state;
549 break;
550 case GL_MAP1_VERTEX_3:
551 if (ctx->API != API_OPENGL_COMPAT)
552 goto invalid_enum_error;
553 if (ctx->Eval.Map1Vertex3 == state)
554 return;
555 FLUSH_VERTICES(ctx, _NEW_EVAL);
556 ctx->Eval.Map1Vertex3 = state;
557 break;
558 case GL_MAP1_VERTEX_4:
559 if (ctx->API != API_OPENGL_COMPAT)
560 goto invalid_enum_error;
561 if (ctx->Eval.Map1Vertex4 == state)
562 return;
563 FLUSH_VERTICES(ctx, _NEW_EVAL);
564 ctx->Eval.Map1Vertex4 = state;
565 break;
566 case GL_MAP2_COLOR_4:
567 if (ctx->API != API_OPENGL_COMPAT)
568 goto invalid_enum_error;
569 if (ctx->Eval.Map2Color4 == state)
570 return;
571 FLUSH_VERTICES(ctx, _NEW_EVAL);
572 ctx->Eval.Map2Color4 = state;
573 break;
574 case GL_MAP2_INDEX:
575 if (ctx->API != API_OPENGL_COMPAT)
576 goto invalid_enum_error;
577 if (ctx->Eval.Map2Index == state)
578 return;
579 FLUSH_VERTICES(ctx, _NEW_EVAL);
580 ctx->Eval.Map2Index = state;
581 break;
582 case GL_MAP2_NORMAL:
583 if (ctx->API != API_OPENGL_COMPAT)
584 goto invalid_enum_error;
585 if (ctx->Eval.Map2Normal == state)
586 return;
587 FLUSH_VERTICES(ctx, _NEW_EVAL);
588 ctx->Eval.Map2Normal = state;
589 break;
590 case GL_MAP2_TEXTURE_COORD_1:
591 if (ctx->API != API_OPENGL_COMPAT)
592 goto invalid_enum_error;
593 if (ctx->Eval.Map2TextureCoord1 == state)
594 return;
595 FLUSH_VERTICES(ctx, _NEW_EVAL);
596 ctx->Eval.Map2TextureCoord1 = state;
597 break;
598 case GL_MAP2_TEXTURE_COORD_2:
599 if (ctx->API != API_OPENGL_COMPAT)
600 goto invalid_enum_error;
601 if (ctx->Eval.Map2TextureCoord2 == state)
602 return;
603 FLUSH_VERTICES(ctx, _NEW_EVAL);
604 ctx->Eval.Map2TextureCoord2 = state;
605 break;
606 case GL_MAP2_TEXTURE_COORD_3:
607 if (ctx->API != API_OPENGL_COMPAT)
608 goto invalid_enum_error;
609 if (ctx->Eval.Map2TextureCoord3 == state)
610 return;
611 FLUSH_VERTICES(ctx, _NEW_EVAL);
612 ctx->Eval.Map2TextureCoord3 = state;
613 break;
614 case GL_MAP2_TEXTURE_COORD_4:
615 if (ctx->API != API_OPENGL_COMPAT)
616 goto invalid_enum_error;
617 if (ctx->Eval.Map2TextureCoord4 == state)
618 return;
619 FLUSH_VERTICES(ctx, _NEW_EVAL);
620 ctx->Eval.Map2TextureCoord4 = state;
621 break;
622 case GL_MAP2_VERTEX_3:
623 if (ctx->API != API_OPENGL_COMPAT)
624 goto invalid_enum_error;
625 if (ctx->Eval.Map2Vertex3 == state)
626 return;
627 FLUSH_VERTICES(ctx, _NEW_EVAL);
628 ctx->Eval.Map2Vertex3 = state;
629 break;
630 case GL_MAP2_VERTEX_4:
631 if (ctx->API != API_OPENGL_COMPAT)
632 goto invalid_enum_error;
633 if (ctx->Eval.Map2Vertex4 == state)
634 return;
635 FLUSH_VERTICES(ctx, _NEW_EVAL);
636 ctx->Eval.Map2Vertex4 = state;
637 break;
638 case GL_NORMALIZE:
639 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
640 goto invalid_enum_error;
641 if (ctx->Transform.Normalize == state)
642 return;
643 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
644 ctx->Transform.Normalize = state;
645 break;
646 case GL_POINT_SMOOTH:
647 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
648 goto invalid_enum_error;
649 if (ctx->Point.SmoothFlag == state)
650 return;
651 FLUSH_VERTICES(ctx, _NEW_POINT);
652 ctx->Point.SmoothFlag = state;
653 break;
654 case GL_POLYGON_SMOOTH:
655 if (!_mesa_is_desktop_gl(ctx))
656 goto invalid_enum_error;
657 if (ctx->Polygon.SmoothFlag == state)
658 return;
659 FLUSH_VERTICES(ctx,
660 ctx->DriverFlags.NewPolygonState ? 0 : _NEW_POLYGON);
661 ctx->NewDriverState |= ctx->DriverFlags.NewPolygonState;
662 ctx->Polygon.SmoothFlag = state;
663 break;
664 case GL_POLYGON_STIPPLE:
665 if (ctx->API != API_OPENGL_COMPAT)
666 goto invalid_enum_error;
667 if (ctx->Polygon.StippleFlag == state)
668 return;
669 FLUSH_VERTICES(ctx,
670 ctx->DriverFlags.NewPolygonState ? 0 : _NEW_POLYGON);
671 ctx->NewDriverState |= ctx->DriverFlags.NewPolygonState;
672 ctx->Polygon.StippleFlag = state;
673 break;
674 case GL_POLYGON_OFFSET_POINT:
675 if (!_mesa_is_desktop_gl(ctx))
676 goto invalid_enum_error;
677 if (ctx->Polygon.OffsetPoint == state)
678 return;
679 FLUSH_VERTICES(ctx,
680 ctx->DriverFlags.NewPolygonState ? 0 : _NEW_POLYGON);
681 ctx->NewDriverState |= ctx->DriverFlags.NewPolygonState;
682 ctx->Polygon.OffsetPoint = state;
683 break;
684 case GL_POLYGON_OFFSET_LINE:
685 if (!_mesa_is_desktop_gl(ctx))
686 goto invalid_enum_error;
687 if (ctx->Polygon.OffsetLine == state)
688 return;
689 FLUSH_VERTICES(ctx,
690 ctx->DriverFlags.NewPolygonState ? 0 : _NEW_POLYGON);
691 ctx->NewDriverState |= ctx->DriverFlags.NewPolygonState;
692 ctx->Polygon.OffsetLine = state;
693 break;
694 case GL_POLYGON_OFFSET_FILL:
695 if (ctx->Polygon.OffsetFill == state)
696 return;
697 FLUSH_VERTICES(ctx,
698 ctx->DriverFlags.NewPolygonState ? 0 : _NEW_POLYGON);
699 ctx->NewDriverState |= ctx->DriverFlags.NewPolygonState;
700 ctx->Polygon.OffsetFill = state;
701 break;
702 case GL_RESCALE_NORMAL_EXT:
703 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
704 goto invalid_enum_error;
705 if (ctx->Transform.RescaleNormals == state)
706 return;
707 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
708 ctx->Transform.RescaleNormals = state;
709 break;
710 case GL_SCISSOR_TEST:
711 {
712 /* Must expand glEnable to all scissors */
713 GLbitfield newEnabled =
714 state * ((1 << ctx->Const.MaxViewports) - 1);
715 if (newEnabled != ctx->Scissor.EnableFlags) {
716 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewScissorTest ? 0 :
717 _NEW_SCISSOR);
718 ctx->NewDriverState |= ctx->DriverFlags.NewScissorTest;
719 ctx->Scissor.EnableFlags = newEnabled;
720 }
721 }
722 break;
723 case GL_STENCIL_TEST:
724 if (ctx->Stencil.Enabled == state)
725 return;
726 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewStencil ? 0 : _NEW_STENCIL);
727 ctx->NewDriverState |= ctx->DriverFlags.NewStencil;
728 ctx->Stencil.Enabled = state;
729 break;
730 case GL_TEXTURE_1D:
731 if (ctx->API != API_OPENGL_COMPAT)
732 goto invalid_enum_error;
733 if (!enable_texture(ctx, state, TEXTURE_1D_BIT)) {
734 return;
735 }
736 break;
737 case GL_TEXTURE_2D:
738 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
739 goto invalid_enum_error;
740 if (!enable_texture(ctx, state, TEXTURE_2D_BIT)) {
741 return;
742 }
743 break;
744 case GL_TEXTURE_3D:
745 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
746 goto invalid_enum_error;
747 if (!enable_texture(ctx, state, TEXTURE_3D_BIT)) {
748 return;
749 }
750 break;
751 case GL_TEXTURE_GEN_S:
752 case GL_TEXTURE_GEN_T:
753 case GL_TEXTURE_GEN_R:
754 case GL_TEXTURE_GEN_Q:
755 {
756 struct gl_fixedfunc_texture_unit *texUnit = get_texcoord_unit(ctx);
757
758 if (ctx->API != API_OPENGL_COMPAT)
759 goto invalid_enum_error;
760
761 if (texUnit) {
762 GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
763 GLbitfield newenabled = texUnit->TexGenEnabled & ~coordBit;
764 if (state)
765 newenabled |= coordBit;
766 if (texUnit->TexGenEnabled == newenabled)
767 return;
768 FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);
769 texUnit->TexGenEnabled = newenabled;
770 }
771 }
772 break;
773
774 case GL_TEXTURE_GEN_STR_OES:
775 /* disable S, T, and R at the same time */
776 {
777 struct gl_fixedfunc_texture_unit *texUnit = get_texcoord_unit(ctx);
778
779 if (ctx->API != API_OPENGLES)
780 goto invalid_enum_error;
781
782 if (texUnit) {
783 GLuint newenabled =
784 texUnit->TexGenEnabled & ~STR_BITS;
785 if (state)
786 newenabled |= STR_BITS;
787 if (texUnit->TexGenEnabled == newenabled)
788 return;
789 FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);
790 texUnit->TexGenEnabled = newenabled;
791 }
792 }
793 break;
794
795 /* client-side state */
796 case GL_VERTEX_ARRAY:
797 case GL_NORMAL_ARRAY:
798 case GL_COLOR_ARRAY:
799 case GL_TEXTURE_COORD_ARRAY:
800 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
801 goto invalid_enum_error;
802 client_state( ctx, cap, state );
803 return;
804 case GL_INDEX_ARRAY:
805 case GL_EDGE_FLAG_ARRAY:
806 case GL_FOG_COORDINATE_ARRAY_EXT:
807 case GL_SECONDARY_COLOR_ARRAY_EXT:
808 if (ctx->API != API_OPENGL_COMPAT)
809 goto invalid_enum_error;
810 client_state( ctx, cap, state );
811 return;
812 case GL_POINT_SIZE_ARRAY_OES:
813 if (ctx->API != API_OPENGLES)
814 goto invalid_enum_error;
815 client_state( ctx, cap, state );
816 return;
817
818 /* GL_ARB_texture_cube_map */
819 case GL_TEXTURE_CUBE_MAP:
820 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
821 goto invalid_enum_error;
822 CHECK_EXTENSION(ARB_texture_cube_map, cap);
823 if (!enable_texture(ctx, state, TEXTURE_CUBE_BIT)) {
824 return;
825 }
826 break;
827
828 /* GL_EXT_secondary_color */
829 case GL_COLOR_SUM_EXT:
830 if (ctx->API != API_OPENGL_COMPAT)
831 goto invalid_enum_error;
832 if (ctx->Fog.ColorSumEnabled == state)
833 return;
834 FLUSH_VERTICES(ctx, _NEW_FOG);
835 ctx->Fog.ColorSumEnabled = state;
836 break;
837
838 /* GL_ARB_multisample */
839 case GL_MULTISAMPLE_ARB:
840 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
841 goto invalid_enum_error;
842 _mesa_set_multisample(ctx, state);
843 return;
844 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
845 if (ctx->Multisample.SampleAlphaToCoverage == state)
846 return;
847 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleAlphaToXEnable ? 0 :
848 _NEW_MULTISAMPLE);
849 ctx->NewDriverState |= ctx->DriverFlags.NewSampleAlphaToXEnable;
850 ctx->Multisample.SampleAlphaToCoverage = state;
851 break;
852 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
853 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
854 goto invalid_enum_error;
855 if (ctx->Multisample.SampleAlphaToOne == state)
856 return;
857 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleAlphaToXEnable ? 0 :
858 _NEW_MULTISAMPLE);
859 ctx->NewDriverState |= ctx->DriverFlags.NewSampleAlphaToXEnable;
860 ctx->Multisample.SampleAlphaToOne = state;
861 break;
862 case GL_SAMPLE_COVERAGE_ARB:
863 if (ctx->Multisample.SampleCoverage == state)
864 return;
865 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleMask ? 0 :
866 _NEW_MULTISAMPLE);
867 ctx->NewDriverState |= ctx->DriverFlags.NewSampleMask;
868 ctx->Multisample.SampleCoverage = state;
869 break;
870 case GL_SAMPLE_COVERAGE_INVERT_ARB:
871 if (!_mesa_is_desktop_gl(ctx))
872 goto invalid_enum_error;
873 if (ctx->Multisample.SampleCoverageInvert == state)
874 return;
875 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleMask ? 0 :
876 _NEW_MULTISAMPLE);
877 ctx->NewDriverState |= ctx->DriverFlags.NewSampleMask;
878 ctx->Multisample.SampleCoverageInvert = state;
879 break;
880
881 /* GL_ARB_sample_shading */
882 case GL_SAMPLE_SHADING:
883 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
884 goto invalid_enum_error;
885 CHECK_EXTENSION(ARB_sample_shading, cap);
886 if (ctx->Multisample.SampleShading == state)
887 return;
888 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleShading ? 0 :
889 _NEW_MULTISAMPLE);
890 ctx->NewDriverState |= ctx->DriverFlags.NewSampleShading;
891 ctx->Multisample.SampleShading = state;
892 break;
893
894 /* GL_IBM_rasterpos_clip */
895 case GL_RASTER_POSITION_UNCLIPPED_IBM:
896 if (ctx->API != API_OPENGL_COMPAT)
897 goto invalid_enum_error;
898 if (ctx->Transform.RasterPositionUnclipped == state)
899 return;
900 FLUSH_VERTICES(ctx, 0);
901 ctx->Transform.RasterPositionUnclipped = state;
902 break;
903
904 /* GL_NV_point_sprite */
905 case GL_POINT_SPRITE_NV:
906 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
907 goto invalid_enum_error;
908 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite, cap);
909 if (ctx->Point.PointSprite == state)
910 return;
911 FLUSH_VERTICES(ctx, _NEW_POINT);
912 ctx->Point.PointSprite = state;
913 break;
914
915 case GL_VERTEX_PROGRAM_ARB:
916 if (ctx->API != API_OPENGL_COMPAT)
917 goto invalid_enum_error;
918 CHECK_EXTENSION(ARB_vertex_program, cap);
919 if (ctx->VertexProgram.Enabled == state)
920 return;
921 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
922 ctx->VertexProgram.Enabled = state;
923 _mesa_update_vertex_processing_mode(ctx);
924 break;
925 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
926 /* This was added with ARB_vertex_program, but it is also used with
927 * GLSL vertex shaders on desktop.
928 */
929 if (!_mesa_is_desktop_gl(ctx))
930 goto invalid_enum_error;
931 CHECK_EXTENSION(ARB_vertex_program, cap);
932 if (ctx->VertexProgram.PointSizeEnabled == state)
933 return;
934 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
935 ctx->VertexProgram.PointSizeEnabled = state;
936 break;
937 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
938 if (ctx->API != API_OPENGL_COMPAT)
939 goto invalid_enum_error;
940 CHECK_EXTENSION(ARB_vertex_program, cap);
941 if (ctx->VertexProgram.TwoSideEnabled == state)
942 return;
943 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
944 ctx->VertexProgram.TwoSideEnabled = state;
945 break;
946
947 /* GL_NV_texture_rectangle */
948 case GL_TEXTURE_RECTANGLE_NV:
949 if (ctx->API != API_OPENGL_COMPAT)
950 goto invalid_enum_error;
951 CHECK_EXTENSION(NV_texture_rectangle, cap);
952 if (!enable_texture(ctx, state, TEXTURE_RECT_BIT)) {
953 return;
954 }
955 break;
956
957 /* GL_EXT_stencil_two_side */
958 case GL_STENCIL_TEST_TWO_SIDE_EXT:
959 if (ctx->API != API_OPENGL_COMPAT)
960 goto invalid_enum_error;
961 CHECK_EXTENSION(EXT_stencil_two_side, cap);
962 if (ctx->Stencil.TestTwoSide == state)
963 return;
964 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewStencil ? 0 : _NEW_STENCIL);
965 ctx->NewDriverState |= ctx->DriverFlags.NewStencil;
966 ctx->Stencil.TestTwoSide = state;
967 if (state) {
968 ctx->Stencil._BackFace = 2;
969 } else {
970 ctx->Stencil._BackFace = 1;
971 }
972 break;
973
974 case GL_FRAGMENT_PROGRAM_ARB:
975 if (ctx->API != API_OPENGL_COMPAT)
976 goto invalid_enum_error;
977 CHECK_EXTENSION(ARB_fragment_program, cap);
978 if (ctx->FragmentProgram.Enabled == state)
979 return;
980 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
981 ctx->FragmentProgram.Enabled = state;
982 break;
983
984 /* GL_EXT_depth_bounds_test */
985 case GL_DEPTH_BOUNDS_TEST_EXT:
986 if (!_mesa_is_desktop_gl(ctx))
987 goto invalid_enum_error;
988 CHECK_EXTENSION(EXT_depth_bounds_test, cap);
989 if (ctx->Depth.BoundsTest == state)
990 return;
991 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepth ? 0 : _NEW_DEPTH);
992 ctx->NewDriverState |= ctx->DriverFlags.NewDepth;
993 ctx->Depth.BoundsTest = state;
994 break;
995
996 case GL_DEPTH_CLAMP:
997 if (!_mesa_is_desktop_gl(ctx))
998 goto invalid_enum_error;
999 CHECK_EXTENSION(ARB_depth_clamp, cap);
1000 if (ctx->Transform.DepthClamp == state)
1001 return;
1002 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepthClamp ? 0 :
1003 _NEW_TRANSFORM);
1004 ctx->NewDriverState |= ctx->DriverFlags.NewDepthClamp;
1005 ctx->Transform.DepthClamp = state;
1006 break;
1007
1008 case GL_FRAGMENT_SHADER_ATI:
1009 if (ctx->API != API_OPENGL_COMPAT)
1010 goto invalid_enum_error;
1011 CHECK_EXTENSION(ATI_fragment_shader, cap);
1012 if (ctx->ATIFragmentShader.Enabled == state)
1013 return;
1014 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
1015 ctx->ATIFragmentShader.Enabled = state;
1016 break;
1017
1018 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1019 if (!_mesa_is_desktop_gl(ctx))
1020 goto invalid_enum_error;
1021 CHECK_EXTENSION(ARB_seamless_cube_map, cap);
1022 if (ctx->Texture.CubeMapSeamless != state) {
1023 FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT);
1024 ctx->Texture.CubeMapSeamless = state;
1025 }
1026 break;
1027
1028 case GL_RASTERIZER_DISCARD:
1029 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1030 goto invalid_enum_error;
1031 CHECK_EXTENSION(EXT_transform_feedback, cap);
1032 if (ctx->RasterDiscard != state) {
1033 FLUSH_VERTICES(ctx, 0);
1034 ctx->NewDriverState |= ctx->DriverFlags.NewRasterizerDiscard;
1035 ctx->RasterDiscard = state;
1036 }
1037 break;
1038
1039 case GL_TILE_RASTER_ORDER_FIXED_MESA:
1040 CHECK_EXTENSION(MESA_tile_raster_order, cap);
1041 if (ctx->TileRasterOrderFixed != state) {
1042 FLUSH_VERTICES(ctx, 0);
1043 ctx->NewDriverState |= ctx->DriverFlags.NewTileRasterOrder;
1044 ctx->TileRasterOrderFixed = state;
1045 }
1046 break;
1047
1048 case GL_TILE_RASTER_ORDER_INCREASING_X_MESA:
1049 CHECK_EXTENSION(MESA_tile_raster_order, cap);
1050 if (ctx->TileRasterOrderIncreasingX != state) {
1051 FLUSH_VERTICES(ctx, 0);
1052 ctx->NewDriverState |= ctx->DriverFlags.NewTileRasterOrder;
1053 ctx->TileRasterOrderIncreasingX = state;
1054 }
1055 break;
1056
1057 case GL_TILE_RASTER_ORDER_INCREASING_Y_MESA:
1058 CHECK_EXTENSION(MESA_tile_raster_order, cap);
1059 if (ctx->TileRasterOrderIncreasingY != state) {
1060 FLUSH_VERTICES(ctx, 0);
1061 ctx->NewDriverState |= ctx->DriverFlags.NewTileRasterOrder;
1062 ctx->TileRasterOrderIncreasingY = state;
1063 }
1064 break;
1065
1066 /* GL 3.1 primitive restart. Note: this enum is different from
1067 * GL_PRIMITIVE_RESTART_NV (which is client state).
1068 */
1069 case GL_PRIMITIVE_RESTART:
1070 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
1071 goto invalid_enum_error;
1072 }
1073 if (ctx->Array.PrimitiveRestart != state) {
1074 FLUSH_VERTICES(ctx, 0);
1075 ctx->Array.PrimitiveRestart = state;
1076 update_derived_primitive_restart_state(ctx);
1077 }
1078 break;
1079
1080 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
1081 if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility)
1082 goto invalid_enum_error;
1083 if (ctx->Array.PrimitiveRestartFixedIndex != state) {
1084 FLUSH_VERTICES(ctx, 0);
1085 ctx->Array.PrimitiveRestartFixedIndex = state;
1086 update_derived_primitive_restart_state(ctx);
1087 }
1088 break;
1089
1090 /* GL3.0 - GL_framebuffer_sRGB */
1091 case GL_FRAMEBUFFER_SRGB_EXT:
1092 if (!_mesa_is_desktop_gl(ctx))
1093 goto invalid_enum_error;
1094 CHECK_EXTENSION(EXT_framebuffer_sRGB, cap);
1095 _mesa_set_framebuffer_srgb(ctx, state);
1096 return;
1097
1098 /* GL_OES_EGL_image_external */
1099 case GL_TEXTURE_EXTERNAL_OES:
1100 if (!_mesa_is_gles(ctx))
1101 goto invalid_enum_error;
1102 CHECK_EXTENSION(OES_EGL_image_external, cap);
1103 if (!enable_texture(ctx, state, TEXTURE_EXTERNAL_BIT)) {
1104 return;
1105 }
1106 break;
1107
1108 /* ARB_texture_multisample */
1109 case GL_SAMPLE_MASK:
1110 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
1111 goto invalid_enum_error;
1112 CHECK_EXTENSION(ARB_texture_multisample, cap);
1113 if (ctx->Multisample.SampleMask == state)
1114 return;
1115 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleMask ? 0 :
1116 _NEW_MULTISAMPLE);
1117 ctx->NewDriverState |= ctx->DriverFlags.NewSampleMask;
1118 ctx->Multisample.SampleMask = state;
1119 break;
1120
1121 case GL_BLEND_ADVANCED_COHERENT_KHR:
1122 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent, cap);
1123 if (ctx->Color.BlendCoherent == state)
1124 return;
1125 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewBlend ? 0 : _NEW_COLOR);
1126 ctx->NewDriverState |= ctx->DriverFlags.NewBlend;
1127 ctx->Color.BlendCoherent = state;
1128 break;
1129
1130 default:
1131 goto invalid_enum_error;
1132 }
1133
1134 if (ctx->Driver.Enable) {
1135 ctx->Driver.Enable( ctx, cap, state );
1136 }
1137
1138 return;
1139
1140 invalid_enum_error:
1141 _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(%s)",
1142 state ? "Enable" : "Disable", _mesa_enum_to_string(cap));
1143 }
1144
1145
1146 /**
1147 * Enable GL capability. Called by glEnable()
1148 * \param cap state to enable.
1149 */
1150 void GLAPIENTRY
1151 _mesa_Enable( GLenum cap )
1152 {
1153 GET_CURRENT_CONTEXT(ctx);
1154
1155 _mesa_set_enable( ctx, cap, GL_TRUE );
1156 }
1157
1158
1159 /**
1160 * Disable GL capability. Called by glDisable()
1161 * \param cap state to disable.
1162 */
1163 void GLAPIENTRY
1164 _mesa_Disable( GLenum cap )
1165 {
1166 GET_CURRENT_CONTEXT(ctx);
1167
1168 _mesa_set_enable( ctx, cap, GL_FALSE );
1169 }
1170
1171
1172
1173 /**
1174 * Enable/disable an indexed state var.
1175 */
1176 void
1177 _mesa_set_enablei(struct gl_context *ctx, GLenum cap,
1178 GLuint index, GLboolean state)
1179 {
1180 assert(state == 0 || state == 1);
1181 switch (cap) {
1182 case GL_BLEND:
1183 if (!ctx->Extensions.EXT_draw_buffers2) {
1184 goto invalid_enum_error;
1185 }
1186 if (index >= ctx->Const.MaxDrawBuffers) {
1187 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1188 state ? "glEnableIndexed" : "glDisableIndexed", index);
1189 return;
1190 }
1191 if (((ctx->Color.BlendEnabled >> index) & 1) != state) {
1192 GLbitfield enabled = ctx->Color.BlendEnabled;
1193
1194 if (state)
1195 enabled |= (1 << index);
1196 else
1197 enabled &= ~(1 << index);
1198
1199 _mesa_flush_vertices_for_blend_adv(ctx, enabled,
1200 ctx->Color._AdvancedBlendMode);
1201 ctx->Color.BlendEnabled = enabled;
1202 }
1203 break;
1204 case GL_SCISSOR_TEST:
1205 if (index >= ctx->Const.MaxViewports) {
1206 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1207 state ? "glEnablei" : "glDisablei", index);
1208 return;
1209 }
1210 if (((ctx->Scissor.EnableFlags >> index) & 1) != state) {
1211 FLUSH_VERTICES(ctx,
1212 ctx->DriverFlags.NewScissorTest ? 0 : _NEW_SCISSOR);
1213 ctx->NewDriverState |= ctx->DriverFlags.NewScissorTest;
1214 if (state)
1215 ctx->Scissor.EnableFlags |= (1 << index);
1216 else
1217 ctx->Scissor.EnableFlags &= ~(1 << index);
1218 }
1219 break;
1220 default:
1221 goto invalid_enum_error;
1222 }
1223 return;
1224
1225 invalid_enum_error:
1226 _mesa_error(ctx, GL_INVALID_ENUM, "%s(cap=%s)",
1227 state ? "glEnablei" : "glDisablei",
1228 _mesa_enum_to_string(cap));
1229 }
1230
1231
1232 void GLAPIENTRY
1233 _mesa_Disablei( GLenum cap, GLuint index )
1234 {
1235 GET_CURRENT_CONTEXT(ctx);
1236 _mesa_set_enablei(ctx, cap, index, GL_FALSE);
1237 }
1238
1239
1240 void GLAPIENTRY
1241 _mesa_Enablei( GLenum cap, GLuint index )
1242 {
1243 GET_CURRENT_CONTEXT(ctx);
1244 _mesa_set_enablei(ctx, cap, index, GL_TRUE);
1245 }
1246
1247
1248 GLboolean GLAPIENTRY
1249 _mesa_IsEnabledi( GLenum cap, GLuint index )
1250 {
1251 GET_CURRENT_CONTEXT(ctx);
1252 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1253 switch (cap) {
1254 case GL_BLEND:
1255 if (index >= ctx->Const.MaxDrawBuffers) {
1256 _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
1257 index);
1258 return GL_FALSE;
1259 }
1260 return (ctx->Color.BlendEnabled >> index) & 1;
1261 case GL_SCISSOR_TEST:
1262 if (index >= ctx->Const.MaxViewports) {
1263 _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
1264 index);
1265 return GL_FALSE;
1266 }
1267 return (ctx->Scissor.EnableFlags >> index) & 1;
1268 default:
1269 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabledIndexed(cap=%s)",
1270 _mesa_enum_to_string(cap));
1271 return GL_FALSE;
1272 }
1273 }
1274
1275
1276
1277
1278 #undef CHECK_EXTENSION
1279 #define CHECK_EXTENSION(EXTNAME) \
1280 if (!ctx->Extensions.EXTNAME) { \
1281 goto invalid_enum_error; \
1282 }
1283
1284 #undef CHECK_EXTENSION2
1285 #define CHECK_EXTENSION2(EXT1, EXT2) \
1286 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1287 goto invalid_enum_error; \
1288 }
1289
1290
1291 /**
1292 * Helper function to determine whether a texture target is enabled.
1293 */
1294 static GLboolean
1295 is_texture_enabled(struct gl_context *ctx, GLbitfield bit)
1296 {
1297 const struct gl_fixedfunc_texture_unit *const texUnit =
1298 _mesa_get_current_fixedfunc_tex_unit(ctx);
1299
1300 if (!texUnit)
1301 return GL_FALSE;
1302
1303 return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE;
1304 }
1305
1306
1307 /**
1308 * Return simple enable/disable state.
1309 *
1310 * \param cap state variable to query.
1311 *
1312 * Returns the state of the specified capability from the current GL context.
1313 * For the capabilities associated with extensions verifies that those
1314 * extensions are effectively present before reporting.
1315 */
1316 GLboolean GLAPIENTRY
1317 _mesa_IsEnabled( GLenum cap )
1318 {
1319 GET_CURRENT_CONTEXT(ctx);
1320 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1321
1322 switch (cap) {
1323 case GL_ALPHA_TEST:
1324 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1325 goto invalid_enum_error;
1326 return ctx->Color.AlphaEnabled;
1327 case GL_AUTO_NORMAL:
1328 if (ctx->API != API_OPENGL_COMPAT)
1329 goto invalid_enum_error;
1330 return ctx->Eval.AutoNormal;
1331 case GL_BLEND:
1332 return ctx->Color.BlendEnabled & 1; /* return state for buffer[0] */
1333 case GL_CLIP_DISTANCE0: /* aka GL_CLIP_PLANE0 */
1334 case GL_CLIP_DISTANCE1:
1335 case GL_CLIP_DISTANCE2:
1336 case GL_CLIP_DISTANCE3:
1337 case GL_CLIP_DISTANCE4:
1338 case GL_CLIP_DISTANCE5:
1339 case GL_CLIP_DISTANCE6:
1340 case GL_CLIP_DISTANCE7: {
1341 const GLuint p = cap - GL_CLIP_DISTANCE0;
1342
1343 if (p >= ctx->Const.MaxClipPlanes)
1344 goto invalid_enum_error;
1345
1346 return (ctx->Transform.ClipPlanesEnabled >> p) & 1;
1347 }
1348 case GL_COLOR_MATERIAL:
1349 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1350 goto invalid_enum_error;
1351 return ctx->Light.ColorMaterialEnabled;
1352 case GL_CULL_FACE:
1353 return ctx->Polygon.CullFlag;
1354 case GL_DEBUG_OUTPUT:
1355 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB:
1356 return (GLboolean) _mesa_get_debug_state_int(ctx, cap);
1357 case GL_DEPTH_TEST:
1358 return ctx->Depth.Test;
1359 case GL_DITHER:
1360 return ctx->Color.DitherFlag;
1361 case GL_FOG:
1362 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1363 goto invalid_enum_error;
1364 return ctx->Fog.Enabled;
1365 case GL_LIGHTING:
1366 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1367 goto invalid_enum_error;
1368 return ctx->Light.Enabled;
1369 case GL_LIGHT0:
1370 case GL_LIGHT1:
1371 case GL_LIGHT2:
1372 case GL_LIGHT3:
1373 case GL_LIGHT4:
1374 case GL_LIGHT5:
1375 case GL_LIGHT6:
1376 case GL_LIGHT7:
1377 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1378 goto invalid_enum_error;
1379 return ctx->Light.Light[cap-GL_LIGHT0].Enabled;
1380 case GL_LINE_SMOOTH:
1381 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1382 goto invalid_enum_error;
1383 return ctx->Line.SmoothFlag;
1384 case GL_LINE_STIPPLE:
1385 if (ctx->API != API_OPENGL_COMPAT)
1386 goto invalid_enum_error;
1387 return ctx->Line.StippleFlag;
1388 case GL_INDEX_LOGIC_OP:
1389 if (ctx->API != API_OPENGL_COMPAT)
1390 goto invalid_enum_error;
1391 return ctx->Color.IndexLogicOpEnabled;
1392 case GL_COLOR_LOGIC_OP:
1393 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1394 goto invalid_enum_error;
1395 return ctx->Color.ColorLogicOpEnabled;
1396 case GL_MAP1_COLOR_4:
1397 if (ctx->API != API_OPENGL_COMPAT)
1398 goto invalid_enum_error;
1399 return ctx->Eval.Map1Color4;
1400 case GL_MAP1_INDEX:
1401 if (ctx->API != API_OPENGL_COMPAT)
1402 goto invalid_enum_error;
1403 return ctx->Eval.Map1Index;
1404 case GL_MAP1_NORMAL:
1405 if (ctx->API != API_OPENGL_COMPAT)
1406 goto invalid_enum_error;
1407 return ctx->Eval.Map1Normal;
1408 case GL_MAP1_TEXTURE_COORD_1:
1409 if (ctx->API != API_OPENGL_COMPAT)
1410 goto invalid_enum_error;
1411 return ctx->Eval.Map1TextureCoord1;
1412 case GL_MAP1_TEXTURE_COORD_2:
1413 if (ctx->API != API_OPENGL_COMPAT)
1414 goto invalid_enum_error;
1415 return ctx->Eval.Map1TextureCoord2;
1416 case GL_MAP1_TEXTURE_COORD_3:
1417 if (ctx->API != API_OPENGL_COMPAT)
1418 goto invalid_enum_error;
1419 return ctx->Eval.Map1TextureCoord3;
1420 case GL_MAP1_TEXTURE_COORD_4:
1421 if (ctx->API != API_OPENGL_COMPAT)
1422 goto invalid_enum_error;
1423 return ctx->Eval.Map1TextureCoord4;
1424 case GL_MAP1_VERTEX_3:
1425 if (ctx->API != API_OPENGL_COMPAT)
1426 goto invalid_enum_error;
1427 return ctx->Eval.Map1Vertex3;
1428 case GL_MAP1_VERTEX_4:
1429 if (ctx->API != API_OPENGL_COMPAT)
1430 goto invalid_enum_error;
1431 return ctx->Eval.Map1Vertex4;
1432 case GL_MAP2_COLOR_4:
1433 if (ctx->API != API_OPENGL_COMPAT)
1434 goto invalid_enum_error;
1435 return ctx->Eval.Map2Color4;
1436 case GL_MAP2_INDEX:
1437 if (ctx->API != API_OPENGL_COMPAT)
1438 goto invalid_enum_error;
1439 return ctx->Eval.Map2Index;
1440 case GL_MAP2_NORMAL:
1441 if (ctx->API != API_OPENGL_COMPAT)
1442 goto invalid_enum_error;
1443 return ctx->Eval.Map2Normal;
1444 case GL_MAP2_TEXTURE_COORD_1:
1445 if (ctx->API != API_OPENGL_COMPAT)
1446 goto invalid_enum_error;
1447 return ctx->Eval.Map2TextureCoord1;
1448 case GL_MAP2_TEXTURE_COORD_2:
1449 if (ctx->API != API_OPENGL_COMPAT)
1450 goto invalid_enum_error;
1451 return ctx->Eval.Map2TextureCoord2;
1452 case GL_MAP2_TEXTURE_COORD_3:
1453 if (ctx->API != API_OPENGL_COMPAT)
1454 goto invalid_enum_error;
1455 return ctx->Eval.Map2TextureCoord3;
1456 case GL_MAP2_TEXTURE_COORD_4:
1457 if (ctx->API != API_OPENGL_COMPAT)
1458 goto invalid_enum_error;
1459 return ctx->Eval.Map2TextureCoord4;
1460 case GL_MAP2_VERTEX_3:
1461 if (ctx->API != API_OPENGL_COMPAT)
1462 goto invalid_enum_error;
1463 return ctx->Eval.Map2Vertex3;
1464 case GL_MAP2_VERTEX_4:
1465 if (ctx->API != API_OPENGL_COMPAT)
1466 goto invalid_enum_error;
1467 return ctx->Eval.Map2Vertex4;
1468 case GL_NORMALIZE:
1469 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1470 goto invalid_enum_error;
1471 return ctx->Transform.Normalize;
1472 case GL_POINT_SMOOTH:
1473 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1474 goto invalid_enum_error;
1475 return ctx->Point.SmoothFlag;
1476 case GL_POLYGON_SMOOTH:
1477 if (!_mesa_is_desktop_gl(ctx))
1478 goto invalid_enum_error;
1479 return ctx->Polygon.SmoothFlag;
1480 case GL_POLYGON_STIPPLE:
1481 if (ctx->API != API_OPENGL_COMPAT)
1482 goto invalid_enum_error;
1483 return ctx->Polygon.StippleFlag;
1484 case GL_POLYGON_OFFSET_POINT:
1485 if (!_mesa_is_desktop_gl(ctx))
1486 goto invalid_enum_error;
1487 return ctx->Polygon.OffsetPoint;
1488 case GL_POLYGON_OFFSET_LINE:
1489 if (!_mesa_is_desktop_gl(ctx))
1490 goto invalid_enum_error;
1491 return ctx->Polygon.OffsetLine;
1492 case GL_POLYGON_OFFSET_FILL:
1493 return ctx->Polygon.OffsetFill;
1494 case GL_RESCALE_NORMAL_EXT:
1495 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1496 goto invalid_enum_error;
1497 return ctx->Transform.RescaleNormals;
1498 case GL_SCISSOR_TEST:
1499 return ctx->Scissor.EnableFlags & 1; /* return state for index 0 */
1500 case GL_STENCIL_TEST:
1501 return ctx->Stencil.Enabled;
1502 case GL_TEXTURE_1D:
1503 if (ctx->API != API_OPENGL_COMPAT)
1504 goto invalid_enum_error;
1505 return is_texture_enabled(ctx, TEXTURE_1D_BIT);
1506 case GL_TEXTURE_2D:
1507 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1508 goto invalid_enum_error;
1509 return is_texture_enabled(ctx, TEXTURE_2D_BIT);
1510 case GL_TEXTURE_3D:
1511 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1512 goto invalid_enum_error;
1513 return is_texture_enabled(ctx, TEXTURE_3D_BIT);
1514 case GL_TEXTURE_GEN_S:
1515 case GL_TEXTURE_GEN_T:
1516 case GL_TEXTURE_GEN_R:
1517 case GL_TEXTURE_GEN_Q:
1518 {
1519 const struct gl_fixedfunc_texture_unit *texUnit =
1520 get_texcoord_unit(ctx);
1521
1522 if (ctx->API != API_OPENGL_COMPAT)
1523 goto invalid_enum_error;
1524
1525 if (texUnit) {
1526 GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
1527 return (texUnit->TexGenEnabled & coordBit) ? GL_TRUE : GL_FALSE;
1528 }
1529 }
1530 return GL_FALSE;
1531 case GL_TEXTURE_GEN_STR_OES:
1532 {
1533 const struct gl_fixedfunc_texture_unit *texUnit =
1534 get_texcoord_unit(ctx);
1535
1536 if (ctx->API != API_OPENGLES)
1537 goto invalid_enum_error;
1538
1539 if (texUnit) {
1540 return (texUnit->TexGenEnabled & STR_BITS) == STR_BITS
1541 ? GL_TRUE : GL_FALSE;
1542 }
1543 }
1544
1545 /* client-side state */
1546 case GL_VERTEX_ARRAY:
1547 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1548 goto invalid_enum_error;
1549 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POS].Enabled;
1550 case GL_NORMAL_ARRAY:
1551 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1552 goto invalid_enum_error;
1553 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled;
1554 case GL_COLOR_ARRAY:
1555 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1556 goto invalid_enum_error;
1557 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled;
1558 case GL_INDEX_ARRAY:
1559 if (ctx->API != API_OPENGL_COMPAT)
1560 goto invalid_enum_error;
1561 return ctx->Array.VAO->
1562 VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled;
1563 case GL_TEXTURE_COORD_ARRAY:
1564 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1565 goto invalid_enum_error;
1566 return ctx->Array.VAO->
1567 VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Enabled;
1568 case GL_EDGE_FLAG_ARRAY:
1569 if (ctx->API != API_OPENGL_COMPAT)
1570 goto invalid_enum_error;
1571 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled;
1572 case GL_FOG_COORDINATE_ARRAY_EXT:
1573 if (ctx->API != API_OPENGL_COMPAT)
1574 goto invalid_enum_error;
1575 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_FOG].Enabled;
1576 case GL_SECONDARY_COLOR_ARRAY_EXT:
1577 if (ctx->API != API_OPENGL_COMPAT)
1578 goto invalid_enum_error;
1579 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled;
1580 case GL_POINT_SIZE_ARRAY_OES:
1581 if (ctx->API != API_OPENGLES)
1582 goto invalid_enum_error;
1583 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled;
1584
1585 /* GL_ARB_texture_cube_map */
1586 case GL_TEXTURE_CUBE_MAP:
1587 CHECK_EXTENSION(ARB_texture_cube_map);
1588 return is_texture_enabled(ctx, TEXTURE_CUBE_BIT);
1589
1590 /* GL_EXT_secondary_color */
1591 case GL_COLOR_SUM_EXT:
1592 if (ctx->API != API_OPENGL_COMPAT)
1593 goto invalid_enum_error;
1594 return ctx->Fog.ColorSumEnabled;
1595
1596 /* GL_ARB_multisample */
1597 case GL_MULTISAMPLE_ARB:
1598 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1599 goto invalid_enum_error;
1600 return ctx->Multisample.Enabled;
1601 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
1602 return ctx->Multisample.SampleAlphaToCoverage;
1603 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
1604 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1605 goto invalid_enum_error;
1606 return ctx->Multisample.SampleAlphaToOne;
1607 case GL_SAMPLE_COVERAGE_ARB:
1608 return ctx->Multisample.SampleCoverage;
1609 case GL_SAMPLE_COVERAGE_INVERT_ARB:
1610 if (!_mesa_is_desktop_gl(ctx))
1611 goto invalid_enum_error;
1612 return ctx->Multisample.SampleCoverageInvert;
1613
1614 /* GL_IBM_rasterpos_clip */
1615 case GL_RASTER_POSITION_UNCLIPPED_IBM:
1616 if (ctx->API != API_OPENGL_COMPAT)
1617 goto invalid_enum_error;
1618 return ctx->Transform.RasterPositionUnclipped;
1619
1620 /* GL_NV_point_sprite */
1621 case GL_POINT_SPRITE_NV:
1622 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1623 goto invalid_enum_error;
1624 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite)
1625 return ctx->Point.PointSprite;
1626
1627 case GL_VERTEX_PROGRAM_ARB:
1628 if (ctx->API != API_OPENGL_COMPAT)
1629 goto invalid_enum_error;
1630 CHECK_EXTENSION(ARB_vertex_program);
1631 return ctx->VertexProgram.Enabled;
1632 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
1633 /* This was added with ARB_vertex_program, but it is also used with
1634 * GLSL vertex shaders on desktop.
1635 */
1636 if (!_mesa_is_desktop_gl(ctx))
1637 goto invalid_enum_error;
1638 CHECK_EXTENSION(ARB_vertex_program);
1639 return ctx->VertexProgram.PointSizeEnabled;
1640 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
1641 if (ctx->API != API_OPENGL_COMPAT)
1642 goto invalid_enum_error;
1643 CHECK_EXTENSION(ARB_vertex_program);
1644 return ctx->VertexProgram.TwoSideEnabled;
1645
1646 /* GL_NV_texture_rectangle */
1647 case GL_TEXTURE_RECTANGLE_NV:
1648 if (ctx->API != API_OPENGL_COMPAT)
1649 goto invalid_enum_error;
1650 CHECK_EXTENSION(NV_texture_rectangle);
1651 return is_texture_enabled(ctx, TEXTURE_RECT_BIT);
1652
1653 /* GL_EXT_stencil_two_side */
1654 case GL_STENCIL_TEST_TWO_SIDE_EXT:
1655 if (ctx->API != API_OPENGL_COMPAT)
1656 goto invalid_enum_error;
1657 CHECK_EXTENSION(EXT_stencil_two_side);
1658 return ctx->Stencil.TestTwoSide;
1659
1660 case GL_FRAGMENT_PROGRAM_ARB:
1661 if (ctx->API != API_OPENGL_COMPAT)
1662 goto invalid_enum_error;
1663 return ctx->FragmentProgram.Enabled;
1664
1665 /* GL_EXT_depth_bounds_test */
1666 case GL_DEPTH_BOUNDS_TEST_EXT:
1667 if (!_mesa_is_desktop_gl(ctx))
1668 goto invalid_enum_error;
1669 CHECK_EXTENSION(EXT_depth_bounds_test);
1670 return ctx->Depth.BoundsTest;
1671
1672 /* GL_ARB_depth_clamp */
1673 case GL_DEPTH_CLAMP:
1674 if (!_mesa_is_desktop_gl(ctx))
1675 goto invalid_enum_error;
1676 CHECK_EXTENSION(ARB_depth_clamp);
1677 return ctx->Transform.DepthClamp;
1678
1679 case GL_FRAGMENT_SHADER_ATI:
1680 if (ctx->API != API_OPENGL_COMPAT)
1681 goto invalid_enum_error;
1682 CHECK_EXTENSION(ATI_fragment_shader);
1683 return ctx->ATIFragmentShader.Enabled;
1684
1685 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1686 if (!_mesa_is_desktop_gl(ctx))
1687 goto invalid_enum_error;
1688 CHECK_EXTENSION(ARB_seamless_cube_map);
1689 return ctx->Texture.CubeMapSeamless;
1690
1691 case GL_RASTERIZER_DISCARD:
1692 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1693 goto invalid_enum_error;
1694 CHECK_EXTENSION(EXT_transform_feedback);
1695 return ctx->RasterDiscard;
1696
1697 /* GL_NV_primitive_restart */
1698 case GL_PRIMITIVE_RESTART_NV:
1699 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.NV_primitive_restart) {
1700 goto invalid_enum_error;
1701 }
1702 return ctx->Array.PrimitiveRestart;
1703
1704 /* GL 3.1 primitive restart */
1705 case GL_PRIMITIVE_RESTART:
1706 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
1707 goto invalid_enum_error;
1708 }
1709 return ctx->Array.PrimitiveRestart;
1710
1711 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
1712 if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility) {
1713 goto invalid_enum_error;
1714 }
1715 return ctx->Array.PrimitiveRestartFixedIndex;
1716
1717 /* GL3.0 - GL_framebuffer_sRGB */
1718 case GL_FRAMEBUFFER_SRGB_EXT:
1719 if (!_mesa_is_desktop_gl(ctx))
1720 goto invalid_enum_error;
1721 CHECK_EXTENSION(EXT_framebuffer_sRGB);
1722 return ctx->Color.sRGBEnabled;
1723
1724 /* GL_OES_EGL_image_external */
1725 case GL_TEXTURE_EXTERNAL_OES:
1726 if (!_mesa_is_gles(ctx))
1727 goto invalid_enum_error;
1728 CHECK_EXTENSION(OES_EGL_image_external);
1729 return is_texture_enabled(ctx, TEXTURE_EXTERNAL_BIT);
1730
1731 /* ARB_texture_multisample */
1732 case GL_SAMPLE_MASK:
1733 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
1734 goto invalid_enum_error;
1735 CHECK_EXTENSION(ARB_texture_multisample);
1736 return ctx->Multisample.SampleMask;
1737
1738 /* ARB_sample_shading */
1739 case GL_SAMPLE_SHADING:
1740 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1741 goto invalid_enum_error;
1742 CHECK_EXTENSION(ARB_sample_shading);
1743 return ctx->Multisample.SampleShading;
1744
1745 case GL_BLEND_ADVANCED_COHERENT_KHR:
1746 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent);
1747 return ctx->Color.BlendCoherent;
1748
1749 case GL_CONSERVATIVE_RASTERIZATION_INTEL:
1750 CHECK_EXTENSION(INTEL_conservative_rasterization);
1751 return ctx->IntelConservativeRasterization;
1752
1753 case GL_TILE_RASTER_ORDER_FIXED_MESA:
1754 CHECK_EXTENSION(MESA_tile_raster_order);
1755 return ctx->TileRasterOrderFixed;
1756
1757 case GL_TILE_RASTER_ORDER_INCREASING_X_MESA:
1758 CHECK_EXTENSION(MESA_tile_raster_order);
1759 return ctx->TileRasterOrderIncreasingX;
1760
1761 case GL_TILE_RASTER_ORDER_INCREASING_Y_MESA:
1762 CHECK_EXTENSION(MESA_tile_raster_order);
1763 return ctx->TileRasterOrderIncreasingY;
1764
1765 default:
1766 goto invalid_enum_error;
1767 }
1768
1769 return GL_FALSE;
1770
1771 invalid_enum_error:
1772 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(%s)",
1773 _mesa_enum_to_string(cap));
1774 return GL_FALSE;
1775 }