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