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