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