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