mesa: Track position/generic0 aliasing in the VAO.
[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 "texstate.h"
43
44
45
46 #define CHECK_EXTENSION(EXTNAME, CAP) \
47 if (!ctx->Extensions.EXTNAME) { \
48 goto invalid_enum_error; \
49 }
50
51
52 static void
53 update_derived_primitive_restart_state(struct gl_context *ctx)
54 {
55 /* Update derived primitive restart state.
56 */
57 ctx->Array._PrimitiveRestart = ctx->Array.PrimitiveRestart
58 || ctx->Array.PrimitiveRestartFixedIndex;
59 }
60
61 /**
62 * Helper to enable/disable client-side state.
63 */
64 static void
65 client_state(struct gl_context *ctx, GLenum cap, GLboolean state)
66 {
67 struct gl_vertex_array_object *vao = ctx->Array.VAO;
68 GLbitfield vert_attrib_bit;
69 GLboolean *enable_var;
70
71 switch (cap) {
72 case GL_VERTEX_ARRAY:
73 enable_var = &vao->VertexAttrib[VERT_ATTRIB_POS].Enabled;
74 vert_attrib_bit = VERT_BIT_POS;
75 break;
76 case GL_NORMAL_ARRAY:
77 enable_var = &vao->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled;
78 vert_attrib_bit = VERT_BIT_NORMAL;
79 break;
80 case GL_COLOR_ARRAY:
81 enable_var = &vao->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled;
82 vert_attrib_bit = VERT_BIT_COLOR0;
83 break;
84 case GL_INDEX_ARRAY:
85 enable_var = &vao->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled;
86 vert_attrib_bit = VERT_BIT_COLOR_INDEX;
87 break;
88 case GL_TEXTURE_COORD_ARRAY:
89 enable_var = &vao->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Enabled;
90 vert_attrib_bit = VERT_BIT_TEX(ctx->Array.ActiveTexture);
91 break;
92 case GL_EDGE_FLAG_ARRAY:
93 enable_var = &vao->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled;
94 vert_attrib_bit = VERT_BIT_EDGEFLAG;
95 break;
96 case GL_FOG_COORDINATE_ARRAY_EXT:
97 enable_var = &vao->VertexAttrib[VERT_ATTRIB_FOG].Enabled;
98 vert_attrib_bit = VERT_BIT_FOG;
99 break;
100 case GL_SECONDARY_COLOR_ARRAY_EXT:
101 enable_var = &vao->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled;
102 vert_attrib_bit = VERT_BIT_COLOR1;
103 break;
104
105 case GL_POINT_SIZE_ARRAY_OES:
106 enable_var = &vao->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled;
107 vert_attrib_bit = VERT_BIT_POINT_SIZE;
108 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
109 ctx->VertexProgram.PointSizeEnabled = state;
110 break;
111
112 /* GL_NV_primitive_restart */
113 case GL_PRIMITIVE_RESTART_NV:
114 if (!ctx->Extensions.NV_primitive_restart)
115 goto invalid_enum_error;
116 if (ctx->Array.PrimitiveRestart == state)
117 return;
118
119 FLUSH_VERTICES(ctx, 0);
120 ctx->Array.PrimitiveRestart = state;
121 update_derived_primitive_restart_state(ctx);
122 return;
123
124 default:
125 goto invalid_enum_error;
126 }
127
128 if (*enable_var == state)
129 return;
130
131 FLUSH_VERTICES(ctx, _NEW_ARRAY);
132
133 *enable_var = state;
134
135 if (state)
136 vao->_Enabled |= vert_attrib_bit;
137 else
138 vao->_Enabled &= ~vert_attrib_bit;
139
140 vao->NewArrays |= vert_attrib_bit;
141
142 /* Something got en/disabled, so update the map mode */
143 if (vert_attrib_bit & (VERT_BIT_POS|VERT_BIT_GENERIC0))
144 _mesa_update_attribute_map_mode(ctx, vao);
145
146 if (ctx->Driver.Enable) {
147 ctx->Driver.Enable( ctx, cap, state );
148 }
149
150 return;
151
152 invalid_enum_error:
153 _mesa_error(ctx, GL_INVALID_ENUM, "gl%sClientState(%s)",
154 state ? "Enable" : "Disable", _mesa_enum_to_string(cap));
155 }
156
157
158 /**
159 * Enable 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_EnableClientState( GLenum cap )
167 {
168 GET_CURRENT_CONTEXT(ctx);
169 client_state( ctx, cap, GL_TRUE );
170 }
171
172
173 /**
174 * Disable GL capability.
175 * \param cap state to enable/disable.
176 *
177 * Get's the current context, assures that we're outside glBegin()/glEnd() and
178 * calls client_state().
179 */
180 void GLAPIENTRY
181 _mesa_DisableClientState( GLenum cap )
182 {
183 GET_CURRENT_CONTEXT(ctx);
184 client_state( ctx, cap, GL_FALSE );
185 }
186
187
188 #undef CHECK_EXTENSION
189 #define CHECK_EXTENSION(EXTNAME, CAP) \
190 if (!ctx->Extensions.EXTNAME) { \
191 goto invalid_enum_error; \
192 }
193
194 #define CHECK_EXTENSION2(EXT1, EXT2, CAP) \
195 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
196 goto invalid_enum_error; \
197 }
198
199 /**
200 * Return pointer to current texture unit for setting/getting coordinate
201 * state.
202 * Note that we'll set GL_INVALID_OPERATION and return NULL if the active
203 * texture unit is higher than the number of supported coordinate units.
204 */
205 static struct gl_texture_unit *
206 get_texcoord_unit(struct gl_context *ctx)
207 {
208 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
209 _mesa_error(ctx, GL_INVALID_OPERATION, "glEnable/Disable(texcoord unit)");
210 return NULL;
211 }
212 else {
213 return &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
214 }
215 }
216
217
218 /**
219 * Helper function to enable or disable a texture target.
220 * \param bit one of the TEXTURE_x_BIT values
221 * \return GL_TRUE if state is changing or GL_FALSE if no change
222 */
223 static GLboolean
224 enable_texture(struct gl_context *ctx, GLboolean state, GLbitfield texBit)
225 {
226 struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
227 const GLbitfield newenabled = state
228 ? (texUnit->Enabled | texBit) : (texUnit->Enabled & ~texBit);
229
230 if (texUnit->Enabled == newenabled)
231 return GL_FALSE;
232
233 FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);
234 texUnit->Enabled = newenabled;
235 return GL_TRUE;
236 }
237
238
239 /**
240 * Helper function to enable or disable GL_MULTISAMPLE, skipping the check for
241 * whether the API supports it (GLES doesn't).
242 */
243 void
244 _mesa_set_multisample(struct gl_context *ctx, GLboolean state)
245 {
246 if (ctx->Multisample.Enabled == state)
247 return;
248
249 /* GL compatibility needs Multisample.Enable to determine program state
250 * constants.
251 */
252 if (ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGLES ||
253 !ctx->DriverFlags.NewMultisampleEnable) {
254 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
255 } else {
256 FLUSH_VERTICES(ctx, 0);
257 }
258
259 ctx->NewDriverState |= ctx->DriverFlags.NewMultisampleEnable;
260 ctx->Multisample.Enabled = state;
261
262 if (ctx->Driver.Enable) {
263 ctx->Driver.Enable(ctx, GL_MULTISAMPLE, state);
264 }
265 }
266
267 /**
268 * Helper function to enable or disable GL_FRAMEBUFFER_SRGB, skipping the
269 * check for whether the API supports it (GLES doesn't).
270 */
271 void
272 _mesa_set_framebuffer_srgb(struct gl_context *ctx, GLboolean state)
273 {
274 if (ctx->Color.sRGBEnabled == state)
275 return;
276
277 /* TODO: Switch i965 to the new flag and remove the conditional */
278 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewFramebufferSRGB ? 0 : _NEW_BUFFERS);
279 ctx->NewDriverState |= ctx->DriverFlags.NewFramebufferSRGB;
280 ctx->Color.sRGBEnabled = state;
281
282 if (ctx->Driver.Enable) {
283 ctx->Driver.Enable(ctx, GL_FRAMEBUFFER_SRGB, state);
284 }
285 }
286
287 /**
288 * Helper function to enable or disable state.
289 *
290 * \param ctx GL context.
291 * \param cap the state to enable/disable
292 * \param state whether to enable or disable the specified capability.
293 *
294 * Updates the current context and flushes the vertices as needed. For
295 * capabilities associated with extensions it verifies that those extensions
296 * are effectivly present before updating. Notifies the driver via
297 * dd_function_table::Enable.
298 */
299 void
300 _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
301 {
302 if (MESA_VERBOSE & VERBOSE_API)
303 _mesa_debug(ctx, "%s %s (newstate is %x)\n",
304 state ? "glEnable" : "glDisable",
305 _mesa_enum_to_string(cap),
306 ctx->NewState);
307
308 switch (cap) {
309 case GL_ALPHA_TEST:
310 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
311 goto invalid_enum_error;
312 if (ctx->Color.AlphaEnabled == state)
313 return;
314 /* AlphaEnabled is used by the fixed-func fragment program */
315 FLUSH_VERTICES(ctx, _NEW_COLOR);
316 ctx->NewDriverState |= ctx->DriverFlags.NewAlphaTest;
317 ctx->Color.AlphaEnabled = state;
318 break;
319 case GL_AUTO_NORMAL:
320 if (ctx->API != API_OPENGL_COMPAT)
321 goto invalid_enum_error;
322 if (ctx->Eval.AutoNormal == state)
323 return;
324 FLUSH_VERTICES(ctx, _NEW_EVAL);
325 ctx->Eval.AutoNormal = state;
326 break;
327 case GL_BLEND:
328 {
329 GLbitfield newEnabled =
330 state * ((1 << ctx->Const.MaxDrawBuffers) - 1);
331 if (newEnabled != ctx->Color.BlendEnabled) {
332 _mesa_flush_vertices_for_blend_state(ctx);
333 ctx->Color.BlendEnabled = newEnabled;
334 }
335 }
336 break;
337 case GL_CLIP_DISTANCE0: /* aka GL_CLIP_PLANE0 */
338 case GL_CLIP_DISTANCE1:
339 case GL_CLIP_DISTANCE2:
340 case GL_CLIP_DISTANCE3:
341 case GL_CLIP_DISTANCE4:
342 case GL_CLIP_DISTANCE5:
343 case GL_CLIP_DISTANCE6:
344 case GL_CLIP_DISTANCE7:
345 {
346 const GLuint p = cap - GL_CLIP_DISTANCE0;
347
348 if (p >= ctx->Const.MaxClipPlanes)
349 goto invalid_enum_error;
350
351 if ((ctx->Transform.ClipPlanesEnabled & (1 << p))
352 == ((GLuint) state << p))
353 return;
354
355 /* The compatibility profile needs _NEW_TRANSFORM to transform
356 * clip planes according to the projection matrix.
357 */
358 if (ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGLES ||
359 !ctx->DriverFlags.NewClipPlaneEnable) {
360 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
361 } else {
362 FLUSH_VERTICES(ctx, 0);
363 }
364 ctx->NewDriverState |= ctx->DriverFlags.NewClipPlaneEnable;
365
366 if (state) {
367 ctx->Transform.ClipPlanesEnabled |= (1 << p);
368
369 /* The projection matrix transforms the clip plane. */
370 /* TODO: glEnable might not be the best place to do it. */
371 if (ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGLES) {
372 _mesa_update_clip_plane(ctx, p);
373 ctx->NewDriverState |= ctx->DriverFlags.NewClipPlane;
374 }
375 }
376 else {
377 ctx->Transform.ClipPlanesEnabled &= ~(1 << p);
378 }
379 }
380 break;
381 case GL_COLOR_MATERIAL:
382 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
383 goto invalid_enum_error;
384 if (ctx->Light.ColorMaterialEnabled == state)
385 return;
386 FLUSH_VERTICES(ctx, _NEW_LIGHT);
387 FLUSH_CURRENT(ctx, 0);
388 ctx->Light.ColorMaterialEnabled = state;
389 if (state) {
390 _mesa_update_color_material( ctx,
391 ctx->Current.Attrib[VERT_ATTRIB_COLOR0] );
392 }
393 break;
394 case GL_CULL_FACE:
395 if (ctx->Polygon.CullFlag == state)
396 return;
397 FLUSH_VERTICES(ctx,
398 ctx->DriverFlags.NewPolygonState ? 0 : _NEW_POLYGON);
399 ctx->NewDriverState |= ctx->DriverFlags.NewPolygonState;
400 ctx->Polygon.CullFlag = state;
401 break;
402 case GL_DEPTH_TEST:
403 if (ctx->Depth.Test == state)
404 return;
405 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepth ? 0 : _NEW_DEPTH);
406 ctx->NewDriverState |= ctx->DriverFlags.NewDepth;
407 ctx->Depth.Test = state;
408 break;
409 case GL_DEBUG_OUTPUT:
410 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB:
411 _mesa_set_debug_state_int(ctx, cap, state);
412 break;
413 case GL_DITHER:
414 if (ctx->Color.DitherFlag == state)
415 return;
416 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewBlend ? 0 : _NEW_COLOR);
417 ctx->NewDriverState |= ctx->DriverFlags.NewBlend;
418 ctx->Color.DitherFlag = state;
419 break;
420 case GL_FOG:
421 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
422 goto invalid_enum_error;
423 if (ctx->Fog.Enabled == state)
424 return;
425 FLUSH_VERTICES(ctx, _NEW_FOG);
426 ctx->Fog.Enabled = state;
427 ctx->Fog._PackedEnabledMode = state ? ctx->Fog._PackedMode : FOG_NONE;
428 break;
429 case GL_LIGHT0:
430 case GL_LIGHT1:
431 case GL_LIGHT2:
432 case GL_LIGHT3:
433 case GL_LIGHT4:
434 case GL_LIGHT5:
435 case GL_LIGHT6:
436 case GL_LIGHT7:
437 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
438 goto invalid_enum_error;
439 if (ctx->Light.Light[cap-GL_LIGHT0].Enabled == state)
440 return;
441 FLUSH_VERTICES(ctx, _NEW_LIGHT);
442 ctx->Light.Light[cap-GL_LIGHT0].Enabled = state;
443 if (state) {
444 ctx->Light._EnabledLights |= 1u << (cap - GL_LIGHT0);
445 }
446 else {
447 ctx->Light._EnabledLights &= ~(1u << (cap - GL_LIGHT0));
448 }
449 break;
450 case GL_LIGHTING:
451 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
452 goto invalid_enum_error;
453 if (ctx->Light.Enabled == state)
454 return;
455 FLUSH_VERTICES(ctx, _NEW_LIGHT);
456 ctx->Light.Enabled = state;
457 break;
458 case GL_LINE_SMOOTH:
459 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
460 goto invalid_enum_error;
461 if (ctx->Line.SmoothFlag == state)
462 return;
463 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLineState ? 0 : _NEW_LINE);
464 ctx->NewDriverState |= ctx->DriverFlags.NewLineState;
465 ctx->Line.SmoothFlag = state;
466 break;
467 case GL_LINE_STIPPLE:
468 if (ctx->API != API_OPENGL_COMPAT)
469 goto invalid_enum_error;
470 if (ctx->Line.StippleFlag == state)
471 return;
472 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLineState ? 0 : _NEW_LINE);
473 ctx->NewDriverState |= ctx->DriverFlags.NewLineState;
474 ctx->Line.StippleFlag = state;
475 break;
476 case GL_INDEX_LOGIC_OP:
477 if (ctx->API != API_OPENGL_COMPAT)
478 goto invalid_enum_error;
479 if (ctx->Color.IndexLogicOpEnabled == state)
480 return;
481 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLogicOp ? 0 : _NEW_COLOR);
482 ctx->NewDriverState |= ctx->DriverFlags.NewLogicOp;
483 ctx->Color.IndexLogicOpEnabled = state;
484 break;
485 case GL_CONSERVATIVE_RASTERIZATION_INTEL:
486 if (!_mesa_has_INTEL_conservative_rasterization(ctx))
487 goto invalid_enum_error;
488 if (ctx->IntelConservativeRasterization == state)
489 return;
490 FLUSH_VERTICES(ctx, 0);
491 ctx->NewDriverState |=
492 ctx->DriverFlags.NewIntelConservativeRasterization;
493 ctx->IntelConservativeRasterization = 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_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_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 break;
934 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
935 /* This was added with ARB_vertex_program, but it is also used with
936 * GLSL vertex shaders on desktop.
937 */
938 if (!_mesa_is_desktop_gl(ctx))
939 goto invalid_enum_error;
940 CHECK_EXTENSION(ARB_vertex_program, cap);
941 if (ctx->VertexProgram.PointSizeEnabled == state)
942 return;
943 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
944 ctx->VertexProgram.PointSizeEnabled = state;
945 break;
946 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
947 if (ctx->API != API_OPENGL_COMPAT)
948 goto invalid_enum_error;
949 CHECK_EXTENSION(ARB_vertex_program, cap);
950 if (ctx->VertexProgram.TwoSideEnabled == state)
951 return;
952 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
953 ctx->VertexProgram.TwoSideEnabled = state;
954 break;
955
956 /* GL_NV_texture_rectangle */
957 case GL_TEXTURE_RECTANGLE_NV:
958 if (ctx->API != API_OPENGL_COMPAT)
959 goto invalid_enum_error;
960 CHECK_EXTENSION(NV_texture_rectangle, cap);
961 if (!enable_texture(ctx, state, TEXTURE_RECT_BIT)) {
962 return;
963 }
964 break;
965
966 /* GL_EXT_stencil_two_side */
967 case GL_STENCIL_TEST_TWO_SIDE_EXT:
968 if (ctx->API != API_OPENGL_COMPAT)
969 goto invalid_enum_error;
970 CHECK_EXTENSION(EXT_stencil_two_side, cap);
971 if (ctx->Stencil.TestTwoSide == state)
972 return;
973 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewStencil ? 0 : _NEW_STENCIL);
974 ctx->NewDriverState |= ctx->DriverFlags.NewStencil;
975 ctx->Stencil.TestTwoSide = state;
976 if (state) {
977 ctx->Stencil._BackFace = 2;
978 } else {
979 ctx->Stencil._BackFace = 1;
980 }
981 break;
982
983 case GL_FRAGMENT_PROGRAM_ARB:
984 if (ctx->API != API_OPENGL_COMPAT)
985 goto invalid_enum_error;
986 CHECK_EXTENSION(ARB_fragment_program, cap);
987 if (ctx->FragmentProgram.Enabled == state)
988 return;
989 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
990 ctx->FragmentProgram.Enabled = state;
991 break;
992
993 /* GL_EXT_depth_bounds_test */
994 case GL_DEPTH_BOUNDS_TEST_EXT:
995 if (!_mesa_is_desktop_gl(ctx))
996 goto invalid_enum_error;
997 CHECK_EXTENSION(EXT_depth_bounds_test, cap);
998 if (ctx->Depth.BoundsTest == state)
999 return;
1000 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepth ? 0 : _NEW_DEPTH);
1001 ctx->NewDriverState |= ctx->DriverFlags.NewDepth;
1002 ctx->Depth.BoundsTest = state;
1003 break;
1004
1005 case GL_DEPTH_CLAMP:
1006 if (!_mesa_is_desktop_gl(ctx))
1007 goto invalid_enum_error;
1008 CHECK_EXTENSION(ARB_depth_clamp, cap);
1009 if (ctx->Transform.DepthClamp == state)
1010 return;
1011 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepthClamp ? 0 :
1012 _NEW_TRANSFORM);
1013 ctx->NewDriverState |= ctx->DriverFlags.NewDepthClamp;
1014 ctx->Transform.DepthClamp = state;
1015 break;
1016
1017 case GL_FRAGMENT_SHADER_ATI:
1018 if (ctx->API != API_OPENGL_COMPAT)
1019 goto invalid_enum_error;
1020 CHECK_EXTENSION(ATI_fragment_shader, cap);
1021 if (ctx->ATIFragmentShader.Enabled == state)
1022 return;
1023 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
1024 ctx->ATIFragmentShader.Enabled = state;
1025 break;
1026
1027 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1028 if (!_mesa_is_desktop_gl(ctx))
1029 goto invalid_enum_error;
1030 CHECK_EXTENSION(ARB_seamless_cube_map, cap);
1031 if (ctx->Texture.CubeMapSeamless != state) {
1032 FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT);
1033 ctx->Texture.CubeMapSeamless = state;
1034 }
1035 break;
1036
1037 case GL_RASTERIZER_DISCARD:
1038 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1039 goto invalid_enum_error;
1040 CHECK_EXTENSION(EXT_transform_feedback, cap);
1041 if (ctx->RasterDiscard != state) {
1042 FLUSH_VERTICES(ctx, 0);
1043 ctx->NewDriverState |= ctx->DriverFlags.NewRasterizerDiscard;
1044 ctx->RasterDiscard = state;
1045 }
1046 break;
1047
1048 case GL_TILE_RASTER_ORDER_FIXED_MESA:
1049 CHECK_EXTENSION(MESA_tile_raster_order, cap);
1050 if (ctx->TileRasterOrderFixed != state) {
1051 FLUSH_VERTICES(ctx, 0);
1052 ctx->NewDriverState |= ctx->DriverFlags.NewTileRasterOrder;
1053 ctx->TileRasterOrderFixed = state;
1054 }
1055 break;
1056
1057 case GL_TILE_RASTER_ORDER_INCREASING_X_MESA:
1058 CHECK_EXTENSION(MESA_tile_raster_order, cap);
1059 if (ctx->TileRasterOrderIncreasingX != state) {
1060 FLUSH_VERTICES(ctx, 0);
1061 ctx->NewDriverState |= ctx->DriverFlags.NewTileRasterOrder;
1062 ctx->TileRasterOrderIncreasingX = state;
1063 }
1064 break;
1065
1066 case GL_TILE_RASTER_ORDER_INCREASING_Y_MESA:
1067 CHECK_EXTENSION(MESA_tile_raster_order, cap);
1068 if (ctx->TileRasterOrderIncreasingY != state) {
1069 FLUSH_VERTICES(ctx, 0);
1070 ctx->NewDriverState |= ctx->DriverFlags.NewTileRasterOrder;
1071 ctx->TileRasterOrderIncreasingY = state;
1072 }
1073 break;
1074
1075 /* GL 3.1 primitive restart. Note: this enum is different from
1076 * GL_PRIMITIVE_RESTART_NV (which is client state).
1077 */
1078 case GL_PRIMITIVE_RESTART:
1079 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
1080 goto invalid_enum_error;
1081 }
1082 if (ctx->Array.PrimitiveRestart != state) {
1083 FLUSH_VERTICES(ctx, 0);
1084 ctx->Array.PrimitiveRestart = state;
1085 update_derived_primitive_restart_state(ctx);
1086 }
1087 break;
1088
1089 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
1090 if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility)
1091 goto invalid_enum_error;
1092 if (ctx->Array.PrimitiveRestartFixedIndex != state) {
1093 FLUSH_VERTICES(ctx, 0);
1094 ctx->Array.PrimitiveRestartFixedIndex = state;
1095 update_derived_primitive_restart_state(ctx);
1096 }
1097 break;
1098
1099 /* GL3.0 - GL_framebuffer_sRGB */
1100 case GL_FRAMEBUFFER_SRGB_EXT:
1101 if (!_mesa_is_desktop_gl(ctx))
1102 goto invalid_enum_error;
1103 CHECK_EXTENSION(EXT_framebuffer_sRGB, cap);
1104 _mesa_set_framebuffer_srgb(ctx, state);
1105 return;
1106
1107 /* GL_OES_EGL_image_external */
1108 case GL_TEXTURE_EXTERNAL_OES:
1109 if (!_mesa_is_gles(ctx))
1110 goto invalid_enum_error;
1111 CHECK_EXTENSION(OES_EGL_image_external, cap);
1112 if (!enable_texture(ctx, state, TEXTURE_EXTERNAL_BIT)) {
1113 return;
1114 }
1115 break;
1116
1117 /* ARB_texture_multisample */
1118 case GL_SAMPLE_MASK:
1119 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
1120 goto invalid_enum_error;
1121 CHECK_EXTENSION(ARB_texture_multisample, cap);
1122 if (ctx->Multisample.SampleMask == state)
1123 return;
1124 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleMask ? 0 :
1125 _NEW_MULTISAMPLE);
1126 ctx->NewDriverState |= ctx->DriverFlags.NewSampleMask;
1127 ctx->Multisample.SampleMask = state;
1128 break;
1129
1130 case GL_BLEND_ADVANCED_COHERENT_KHR:
1131 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent, cap);
1132 if (ctx->Color.BlendCoherent == state)
1133 return;
1134 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewBlend ? 0 : _NEW_COLOR);
1135 ctx->NewDriverState |= ctx->DriverFlags.NewBlend;
1136 ctx->Color.BlendCoherent = state;
1137 break;
1138
1139 default:
1140 goto invalid_enum_error;
1141 }
1142
1143 if (ctx->Driver.Enable) {
1144 ctx->Driver.Enable( ctx, cap, state );
1145 }
1146
1147 return;
1148
1149 invalid_enum_error:
1150 _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(%s)",
1151 state ? "Enable" : "Disable", _mesa_enum_to_string(cap));
1152 }
1153
1154
1155 /**
1156 * Enable GL capability. Called by glEnable()
1157 * \param cap state to enable.
1158 */
1159 void GLAPIENTRY
1160 _mesa_Enable( GLenum cap )
1161 {
1162 GET_CURRENT_CONTEXT(ctx);
1163
1164 _mesa_set_enable( ctx, cap, GL_TRUE );
1165 }
1166
1167
1168 /**
1169 * Disable GL capability. Called by glDisable()
1170 * \param cap state to disable.
1171 */
1172 void GLAPIENTRY
1173 _mesa_Disable( GLenum cap )
1174 {
1175 GET_CURRENT_CONTEXT(ctx);
1176
1177 _mesa_set_enable( ctx, cap, GL_FALSE );
1178 }
1179
1180
1181
1182 /**
1183 * Enable/disable an indexed state var.
1184 */
1185 void
1186 _mesa_set_enablei(struct gl_context *ctx, GLenum cap,
1187 GLuint index, GLboolean state)
1188 {
1189 assert(state == 0 || state == 1);
1190 switch (cap) {
1191 case GL_BLEND:
1192 if (!ctx->Extensions.EXT_draw_buffers2) {
1193 goto invalid_enum_error;
1194 }
1195 if (index >= ctx->Const.MaxDrawBuffers) {
1196 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1197 state ? "glEnableIndexed" : "glDisableIndexed", index);
1198 return;
1199 }
1200 if (((ctx->Color.BlendEnabled >> index) & 1) != state) {
1201 _mesa_flush_vertices_for_blend_state(ctx);
1202 if (state)
1203 ctx->Color.BlendEnabled |= (1 << index);
1204 else
1205 ctx->Color.BlendEnabled &= ~(1 << index);
1206 }
1207 break;
1208 case GL_SCISSOR_TEST:
1209 if (index >= ctx->Const.MaxViewports) {
1210 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1211 state ? "glEnablei" : "glDisablei", index);
1212 return;
1213 }
1214 if (((ctx->Scissor.EnableFlags >> index) & 1) != state) {
1215 FLUSH_VERTICES(ctx,
1216 ctx->DriverFlags.NewScissorTest ? 0 : _NEW_SCISSOR);
1217 ctx->NewDriverState |= ctx->DriverFlags.NewScissorTest;
1218 if (state)
1219 ctx->Scissor.EnableFlags |= (1 << index);
1220 else
1221 ctx->Scissor.EnableFlags &= ~(1 << index);
1222 }
1223 break;
1224 default:
1225 goto invalid_enum_error;
1226 }
1227 return;
1228
1229 invalid_enum_error:
1230 _mesa_error(ctx, GL_INVALID_ENUM, "%s(cap=%s)",
1231 state ? "glEnablei" : "glDisablei",
1232 _mesa_enum_to_string(cap));
1233 }
1234
1235
1236 void GLAPIENTRY
1237 _mesa_Disablei( GLenum cap, GLuint index )
1238 {
1239 GET_CURRENT_CONTEXT(ctx);
1240 _mesa_set_enablei(ctx, cap, index, GL_FALSE);
1241 }
1242
1243
1244 void GLAPIENTRY
1245 _mesa_Enablei( GLenum cap, GLuint index )
1246 {
1247 GET_CURRENT_CONTEXT(ctx);
1248 _mesa_set_enablei(ctx, cap, index, GL_TRUE);
1249 }
1250
1251
1252 GLboolean GLAPIENTRY
1253 _mesa_IsEnabledi( GLenum cap, GLuint index )
1254 {
1255 GET_CURRENT_CONTEXT(ctx);
1256 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1257 switch (cap) {
1258 case GL_BLEND:
1259 if (index >= ctx->Const.MaxDrawBuffers) {
1260 _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
1261 index);
1262 return GL_FALSE;
1263 }
1264 return (ctx->Color.BlendEnabled >> index) & 1;
1265 case GL_SCISSOR_TEST:
1266 if (index >= ctx->Const.MaxViewports) {
1267 _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
1268 index);
1269 return GL_FALSE;
1270 }
1271 return (ctx->Scissor.EnableFlags >> index) & 1;
1272 default:
1273 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabledIndexed(cap=%s)",
1274 _mesa_enum_to_string(cap));
1275 return GL_FALSE;
1276 }
1277 }
1278
1279
1280
1281
1282 #undef CHECK_EXTENSION
1283 #define CHECK_EXTENSION(EXTNAME) \
1284 if (!ctx->Extensions.EXTNAME) { \
1285 goto invalid_enum_error; \
1286 }
1287
1288 #undef CHECK_EXTENSION2
1289 #define CHECK_EXTENSION2(EXT1, EXT2) \
1290 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1291 goto invalid_enum_error; \
1292 }
1293
1294
1295 /**
1296 * Helper function to determine whether a texture target is enabled.
1297 */
1298 static GLboolean
1299 is_texture_enabled(struct gl_context *ctx, GLbitfield bit)
1300 {
1301 const struct gl_texture_unit *const texUnit =
1302 &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
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_texture_unit *texUnit = get_texcoord_unit(ctx);
1520
1521 if (ctx->API != API_OPENGL_COMPAT)
1522 goto invalid_enum_error;
1523
1524 if (texUnit) {
1525 GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
1526 return (texUnit->TexGenEnabled & coordBit) ? GL_TRUE : GL_FALSE;
1527 }
1528 }
1529 return GL_FALSE;
1530 case GL_TEXTURE_GEN_STR_OES:
1531 {
1532 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1533
1534 if (ctx->API != API_OPENGLES)
1535 goto invalid_enum_error;
1536
1537 if (texUnit) {
1538 return (texUnit->TexGenEnabled & STR_BITS) == STR_BITS
1539 ? GL_TRUE : GL_FALSE;
1540 }
1541 }
1542
1543 /* client-side state */
1544 case GL_VERTEX_ARRAY:
1545 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1546 goto invalid_enum_error;
1547 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POS].Enabled;
1548 case GL_NORMAL_ARRAY:
1549 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1550 goto invalid_enum_error;
1551 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled;
1552 case GL_COLOR_ARRAY:
1553 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1554 goto invalid_enum_error;
1555 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled;
1556 case GL_INDEX_ARRAY:
1557 if (ctx->API != API_OPENGL_COMPAT)
1558 goto invalid_enum_error;
1559 return ctx->Array.VAO->
1560 VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled;
1561 case GL_TEXTURE_COORD_ARRAY:
1562 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1563 goto invalid_enum_error;
1564 return ctx->Array.VAO->
1565 VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Enabled;
1566 case GL_EDGE_FLAG_ARRAY:
1567 if (ctx->API != API_OPENGL_COMPAT)
1568 goto invalid_enum_error;
1569 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled;
1570 case GL_FOG_COORDINATE_ARRAY_EXT:
1571 if (ctx->API != API_OPENGL_COMPAT)
1572 goto invalid_enum_error;
1573 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_FOG].Enabled;
1574 case GL_SECONDARY_COLOR_ARRAY_EXT:
1575 if (ctx->API != API_OPENGL_COMPAT)
1576 goto invalid_enum_error;
1577 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled;
1578 case GL_POINT_SIZE_ARRAY_OES:
1579 if (ctx->API != API_OPENGLES)
1580 goto invalid_enum_error;
1581 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled;
1582
1583 /* GL_ARB_texture_cube_map */
1584 case GL_TEXTURE_CUBE_MAP:
1585 CHECK_EXTENSION(ARB_texture_cube_map);
1586 return is_texture_enabled(ctx, TEXTURE_CUBE_BIT);
1587
1588 /* GL_EXT_secondary_color */
1589 case GL_COLOR_SUM_EXT:
1590 if (ctx->API != API_OPENGL_COMPAT)
1591 goto invalid_enum_error;
1592 return ctx->Fog.ColorSumEnabled;
1593
1594 /* GL_ARB_multisample */
1595 case GL_MULTISAMPLE_ARB:
1596 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1597 goto invalid_enum_error;
1598 return ctx->Multisample.Enabled;
1599 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
1600 return ctx->Multisample.SampleAlphaToCoverage;
1601 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
1602 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1603 goto invalid_enum_error;
1604 return ctx->Multisample.SampleAlphaToOne;
1605 case GL_SAMPLE_COVERAGE_ARB:
1606 return ctx->Multisample.SampleCoverage;
1607 case GL_SAMPLE_COVERAGE_INVERT_ARB:
1608 if (!_mesa_is_desktop_gl(ctx))
1609 goto invalid_enum_error;
1610 return ctx->Multisample.SampleCoverageInvert;
1611
1612 /* GL_IBM_rasterpos_clip */
1613 case GL_RASTER_POSITION_UNCLIPPED_IBM:
1614 if (ctx->API != API_OPENGL_COMPAT)
1615 goto invalid_enum_error;
1616 return ctx->Transform.RasterPositionUnclipped;
1617
1618 /* GL_NV_point_sprite */
1619 case GL_POINT_SPRITE_NV:
1620 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1621 goto invalid_enum_error;
1622 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite)
1623 return ctx->Point.PointSprite;
1624
1625 case GL_VERTEX_PROGRAM_ARB:
1626 if (ctx->API != API_OPENGL_COMPAT)
1627 goto invalid_enum_error;
1628 CHECK_EXTENSION(ARB_vertex_program);
1629 return ctx->VertexProgram.Enabled;
1630 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
1631 /* This was added with ARB_vertex_program, but it is also used with
1632 * GLSL vertex shaders on desktop.
1633 */
1634 if (!_mesa_is_desktop_gl(ctx))
1635 goto invalid_enum_error;
1636 CHECK_EXTENSION(ARB_vertex_program);
1637 return ctx->VertexProgram.PointSizeEnabled;
1638 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
1639 if (ctx->API != API_OPENGL_COMPAT)
1640 goto invalid_enum_error;
1641 CHECK_EXTENSION(ARB_vertex_program);
1642 return ctx->VertexProgram.TwoSideEnabled;
1643
1644 /* GL_NV_texture_rectangle */
1645 case GL_TEXTURE_RECTANGLE_NV:
1646 if (ctx->API != API_OPENGL_COMPAT)
1647 goto invalid_enum_error;
1648 CHECK_EXTENSION(NV_texture_rectangle);
1649 return is_texture_enabled(ctx, TEXTURE_RECT_BIT);
1650
1651 /* GL_EXT_stencil_two_side */
1652 case GL_STENCIL_TEST_TWO_SIDE_EXT:
1653 if (ctx->API != API_OPENGL_COMPAT)
1654 goto invalid_enum_error;
1655 CHECK_EXTENSION(EXT_stencil_two_side);
1656 return ctx->Stencil.TestTwoSide;
1657
1658 case GL_FRAGMENT_PROGRAM_ARB:
1659 if (ctx->API != API_OPENGL_COMPAT)
1660 goto invalid_enum_error;
1661 return ctx->FragmentProgram.Enabled;
1662
1663 /* GL_EXT_depth_bounds_test */
1664 case GL_DEPTH_BOUNDS_TEST_EXT:
1665 if (!_mesa_is_desktop_gl(ctx))
1666 goto invalid_enum_error;
1667 CHECK_EXTENSION(EXT_depth_bounds_test);
1668 return ctx->Depth.BoundsTest;
1669
1670 /* GL_ARB_depth_clamp */
1671 case GL_DEPTH_CLAMP:
1672 if (!_mesa_is_desktop_gl(ctx))
1673 goto invalid_enum_error;
1674 CHECK_EXTENSION(ARB_depth_clamp);
1675 return ctx->Transform.DepthClamp;
1676
1677 case GL_FRAGMENT_SHADER_ATI:
1678 if (ctx->API != API_OPENGL_COMPAT)
1679 goto invalid_enum_error;
1680 CHECK_EXTENSION(ATI_fragment_shader);
1681 return ctx->ATIFragmentShader.Enabled;
1682
1683 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1684 if (!_mesa_is_desktop_gl(ctx))
1685 goto invalid_enum_error;
1686 CHECK_EXTENSION(ARB_seamless_cube_map);
1687 return ctx->Texture.CubeMapSeamless;
1688
1689 case GL_RASTERIZER_DISCARD:
1690 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1691 goto invalid_enum_error;
1692 CHECK_EXTENSION(EXT_transform_feedback);
1693 return ctx->RasterDiscard;
1694
1695 /* GL_NV_primitive_restart */
1696 case GL_PRIMITIVE_RESTART_NV:
1697 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.NV_primitive_restart) {
1698 goto invalid_enum_error;
1699 }
1700 return ctx->Array.PrimitiveRestart;
1701
1702 /* GL 3.1 primitive restart */
1703 case GL_PRIMITIVE_RESTART:
1704 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
1705 goto invalid_enum_error;
1706 }
1707 return ctx->Array.PrimitiveRestart;
1708
1709 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
1710 if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility) {
1711 goto invalid_enum_error;
1712 }
1713 return ctx->Array.PrimitiveRestartFixedIndex;
1714
1715 /* GL3.0 - GL_framebuffer_sRGB */
1716 case GL_FRAMEBUFFER_SRGB_EXT:
1717 if (!_mesa_is_desktop_gl(ctx))
1718 goto invalid_enum_error;
1719 CHECK_EXTENSION(EXT_framebuffer_sRGB);
1720 return ctx->Color.sRGBEnabled;
1721
1722 /* GL_OES_EGL_image_external */
1723 case GL_TEXTURE_EXTERNAL_OES:
1724 if (!_mesa_is_gles(ctx))
1725 goto invalid_enum_error;
1726 CHECK_EXTENSION(OES_EGL_image_external);
1727 return is_texture_enabled(ctx, TEXTURE_EXTERNAL_BIT);
1728
1729 /* ARB_texture_multisample */
1730 case GL_SAMPLE_MASK:
1731 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
1732 goto invalid_enum_error;
1733 CHECK_EXTENSION(ARB_texture_multisample);
1734 return ctx->Multisample.SampleMask;
1735
1736 /* ARB_sample_shading */
1737 case GL_SAMPLE_SHADING:
1738 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1739 goto invalid_enum_error;
1740 CHECK_EXTENSION(ARB_sample_shading);
1741 return ctx->Multisample.SampleShading;
1742
1743 case GL_BLEND_ADVANCED_COHERENT_KHR:
1744 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent);
1745 return ctx->Color.BlendCoherent;
1746
1747 case GL_CONSERVATIVE_RASTERIZATION_INTEL:
1748 CHECK_EXTENSION(INTEL_conservative_rasterization);
1749 return ctx->IntelConservativeRasterization;
1750
1751 case GL_TILE_RASTER_ORDER_FIXED_MESA:
1752 CHECK_EXTENSION(MESA_tile_raster_order);
1753 return ctx->TileRasterOrderFixed;
1754
1755 case GL_TILE_RASTER_ORDER_INCREASING_X_MESA:
1756 CHECK_EXTENSION(MESA_tile_raster_order);
1757 return ctx->TileRasterOrderIncreasingX;
1758
1759 case GL_TILE_RASTER_ORDER_INCREASING_Y_MESA:
1760 CHECK_EXTENSION(MESA_tile_raster_order);
1761 return ctx->TileRasterOrderIncreasingY;
1762
1763 default:
1764 goto invalid_enum_error;
1765 }
1766
1767 return GL_FALSE;
1768
1769 invalid_enum_error:
1770 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(%s)",
1771 _mesa_enum_to_string(cap));
1772 return GL_FALSE;
1773 }