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