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