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