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