ad743ba7b981251f474476451272000483f3c524
[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 /**
284 * Return pointer to current texture unit for setting/getting coordinate
285 * state.
286 * Note that we'll set GL_INVALID_OPERATION and return NULL if the active
287 * texture unit is higher than the number of supported coordinate units.
288 */
289 static struct gl_fixedfunc_texture_unit *
290 get_texcoord_unit(struct gl_context *ctx)
291 {
292 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
293 _mesa_error(ctx, GL_INVALID_OPERATION, "glEnable/Disable(texcoord unit)");
294 return NULL;
295 }
296 else {
297 return &ctx->Texture.FixedFuncUnit[ctx->Texture.CurrentUnit];
298 }
299 }
300
301
302 /**
303 * Helper function to enable or disable a texture target.
304 * \param bit one of the TEXTURE_x_BIT values
305 * \return GL_TRUE if state is changing or GL_FALSE if no change
306 */
307 static GLboolean
308 enable_texture(struct gl_context *ctx, GLboolean state, GLbitfield texBit)
309 {
310 struct gl_fixedfunc_texture_unit *texUnit =
311 _mesa_get_fixedfunc_tex_unit(ctx, ctx->Texture.CurrentUnit);
312 if (!texUnit)
313 return GL_FALSE;
314
315 const GLbitfield newenabled = state
316 ? (texUnit->Enabled | texBit) : (texUnit->Enabled & ~texBit);
317
318 if (texUnit->Enabled == newenabled)
319 return GL_FALSE;
320
321 FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);
322 texUnit->Enabled = newenabled;
323 return GL_TRUE;
324 }
325
326
327 /**
328 * Helper function to enable or disable GL_MULTISAMPLE, skipping the check for
329 * whether the API supports it (GLES doesn't).
330 */
331 void
332 _mesa_set_multisample(struct gl_context *ctx, GLboolean state)
333 {
334 if (ctx->Multisample.Enabled == state)
335 return;
336
337 /* GL compatibility needs Multisample.Enable to determine program state
338 * constants.
339 */
340 if (ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGLES ||
341 !ctx->DriverFlags.NewMultisampleEnable) {
342 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
343 } else {
344 FLUSH_VERTICES(ctx, 0);
345 }
346
347 ctx->NewDriverState |= ctx->DriverFlags.NewMultisampleEnable;
348 ctx->Multisample.Enabled = state;
349
350 if (ctx->Driver.Enable) {
351 ctx->Driver.Enable(ctx, GL_MULTISAMPLE, state);
352 }
353 }
354
355 /**
356 * Helper function to enable or disable GL_FRAMEBUFFER_SRGB, skipping the
357 * check for whether the API supports it (GLES doesn't).
358 */
359 void
360 _mesa_set_framebuffer_srgb(struct gl_context *ctx, GLboolean state)
361 {
362 if (ctx->Color.sRGBEnabled == state)
363 return;
364
365 /* TODO: Switch i965 to the new flag and remove the conditional */
366 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewFramebufferSRGB ? 0 : _NEW_BUFFERS);
367 ctx->NewDriverState |= ctx->DriverFlags.NewFramebufferSRGB;
368 ctx->Color.sRGBEnabled = state;
369
370 if (ctx->Driver.Enable) {
371 ctx->Driver.Enable(ctx, GL_FRAMEBUFFER_SRGB, state);
372 }
373 }
374
375 /**
376 * Helper function to enable or disable state.
377 *
378 * \param ctx GL context.
379 * \param cap the state to enable/disable
380 * \param state whether to enable or disable the specified capability.
381 *
382 * Updates the current context and flushes the vertices as needed. For
383 * capabilities associated with extensions it verifies that those extensions
384 * are effectivly present before updating. Notifies the driver via
385 * dd_function_table::Enable.
386 */
387 void
388 _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
389 {
390 if (MESA_VERBOSE & VERBOSE_API)
391 _mesa_debug(ctx, "%s %s (newstate is %x)\n",
392 state ? "glEnable" : "glDisable",
393 _mesa_enum_to_string(cap),
394 ctx->NewState);
395
396 switch (cap) {
397 case GL_ALPHA_TEST:
398 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
399 goto invalid_enum_error;
400 if (ctx->Color.AlphaEnabled == state)
401 return;
402 /* AlphaEnabled is used by the fixed-func fragment program */
403 FLUSH_VERTICES(ctx, _NEW_COLOR);
404 ctx->NewDriverState |= ctx->DriverFlags.NewAlphaTest;
405 ctx->Color.AlphaEnabled = state;
406 break;
407 case GL_AUTO_NORMAL:
408 if (ctx->API != API_OPENGL_COMPAT)
409 goto invalid_enum_error;
410 if (ctx->Eval.AutoNormal == state)
411 return;
412 FLUSH_VERTICES(ctx, _NEW_EVAL);
413 ctx->Eval.AutoNormal = state;
414 break;
415 case GL_BLEND:
416 {
417 GLbitfield newEnabled =
418 state * ((1 << ctx->Const.MaxDrawBuffers) - 1);
419 if (newEnabled != ctx->Color.BlendEnabled) {
420 _mesa_flush_vertices_for_blend_adv(ctx, newEnabled,
421 ctx->Color._AdvancedBlendMode);
422 ctx->Color.BlendEnabled = newEnabled;
423 _mesa_update_allow_draw_out_of_order(ctx);
424 }
425 }
426 break;
427 case GL_CLIP_DISTANCE0: /* aka GL_CLIP_PLANE0 */
428 case GL_CLIP_DISTANCE1:
429 case GL_CLIP_DISTANCE2:
430 case GL_CLIP_DISTANCE3:
431 case GL_CLIP_DISTANCE4:
432 case GL_CLIP_DISTANCE5:
433 case GL_CLIP_DISTANCE6:
434 case GL_CLIP_DISTANCE7:
435 {
436 const GLuint p = cap - GL_CLIP_DISTANCE0;
437
438 if (p >= ctx->Const.MaxClipPlanes)
439 goto invalid_enum_error;
440
441 if ((ctx->Transform.ClipPlanesEnabled & (1 << p))
442 == ((GLuint) state << p))
443 return;
444
445 /* The compatibility profile needs _NEW_TRANSFORM to transform
446 * clip planes according to the projection matrix.
447 */
448 if (ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGLES ||
449 !ctx->DriverFlags.NewClipPlaneEnable) {
450 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
451 } else {
452 FLUSH_VERTICES(ctx, 0);
453 }
454 ctx->NewDriverState |= ctx->DriverFlags.NewClipPlaneEnable;
455
456 if (state) {
457 ctx->Transform.ClipPlanesEnabled |= (1 << p);
458
459 /* The projection matrix transforms the clip plane. */
460 /* TODO: glEnable might not be the best place to do it. */
461 if (ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGLES) {
462 _mesa_update_clip_plane(ctx, p);
463 ctx->NewDriverState |= ctx->DriverFlags.NewClipPlane;
464 }
465 }
466 else {
467 ctx->Transform.ClipPlanesEnabled &= ~(1 << p);
468 }
469 }
470 break;
471 case GL_COLOR_MATERIAL:
472 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
473 goto invalid_enum_error;
474 if (ctx->Light.ColorMaterialEnabled == state)
475 return;
476 FLUSH_VERTICES(ctx, _NEW_LIGHT);
477 FLUSH_CURRENT(ctx, 0);
478 ctx->Light.ColorMaterialEnabled = state;
479 if (state) {
480 _mesa_update_color_material( ctx,
481 ctx->Current.Attrib[VERT_ATTRIB_COLOR0] );
482 }
483 break;
484 case GL_CULL_FACE:
485 if (ctx->Polygon.CullFlag == state)
486 return;
487 FLUSH_VERTICES(ctx,
488 ctx->DriverFlags.NewPolygonState ? 0 : _NEW_POLYGON);
489 ctx->NewDriverState |= ctx->DriverFlags.NewPolygonState;
490 ctx->Polygon.CullFlag = state;
491 break;
492 case GL_DEPTH_TEST:
493 if (ctx->Depth.Test == state)
494 return;
495 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepth ? 0 : _NEW_DEPTH);
496 ctx->NewDriverState |= ctx->DriverFlags.NewDepth;
497 ctx->Depth.Test = state;
498 _mesa_update_allow_draw_out_of_order(ctx);
499 break;
500 case GL_DEBUG_OUTPUT:
501 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB:
502 _mesa_set_debug_state_int(ctx, cap, state);
503 break;
504 case GL_DITHER:
505 if (ctx->Color.DitherFlag == state)
506 return;
507 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewBlend ? 0 : _NEW_COLOR);
508 ctx->NewDriverState |= ctx->DriverFlags.NewBlend;
509 ctx->Color.DitherFlag = state;
510 break;
511 case GL_FOG:
512 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
513 goto invalid_enum_error;
514 if (ctx->Fog.Enabled == state)
515 return;
516 FLUSH_VERTICES(ctx, _NEW_FOG);
517 ctx->Fog.Enabled = state;
518 ctx->Fog._PackedEnabledMode = state ? ctx->Fog._PackedMode : FOG_NONE;
519 break;
520 case GL_LIGHT0:
521 case GL_LIGHT1:
522 case GL_LIGHT2:
523 case GL_LIGHT3:
524 case GL_LIGHT4:
525 case GL_LIGHT5:
526 case GL_LIGHT6:
527 case GL_LIGHT7:
528 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
529 goto invalid_enum_error;
530 if (ctx->Light.Light[cap-GL_LIGHT0].Enabled == state)
531 return;
532 FLUSH_VERTICES(ctx, _NEW_LIGHT);
533 ctx->Light.Light[cap-GL_LIGHT0].Enabled = state;
534 if (state) {
535 ctx->Light._EnabledLights |= 1u << (cap - GL_LIGHT0);
536 }
537 else {
538 ctx->Light._EnabledLights &= ~(1u << (cap - GL_LIGHT0));
539 }
540 break;
541 case GL_LIGHTING:
542 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
543 goto invalid_enum_error;
544 if (ctx->Light.Enabled == state)
545 return;
546 FLUSH_VERTICES(ctx, _NEW_LIGHT);
547 ctx->Light.Enabled = state;
548 break;
549 case GL_LINE_SMOOTH:
550 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
551 goto invalid_enum_error;
552 if (ctx->Line.SmoothFlag == state)
553 return;
554 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLineState ? 0 : _NEW_LINE);
555 ctx->NewDriverState |= ctx->DriverFlags.NewLineState;
556 ctx->Line.SmoothFlag = state;
557 break;
558 case GL_LINE_STIPPLE:
559 if (ctx->API != API_OPENGL_COMPAT)
560 goto invalid_enum_error;
561 if (ctx->Line.StippleFlag == state)
562 return;
563 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLineState ? 0 : _NEW_LINE);
564 ctx->NewDriverState |= ctx->DriverFlags.NewLineState;
565 ctx->Line.StippleFlag = state;
566 break;
567 case GL_INDEX_LOGIC_OP:
568 if (ctx->API != API_OPENGL_COMPAT)
569 goto invalid_enum_error;
570 if (ctx->Color.IndexLogicOpEnabled == state)
571 return;
572 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLogicOp ? 0 : _NEW_COLOR);
573 ctx->NewDriverState |= ctx->DriverFlags.NewLogicOp;
574 ctx->Color.IndexLogicOpEnabled = state;
575 break;
576 case GL_CONSERVATIVE_RASTERIZATION_INTEL:
577 if (!_mesa_has_INTEL_conservative_rasterization(ctx))
578 goto invalid_enum_error;
579 if (ctx->IntelConservativeRasterization == state)
580 return;
581 FLUSH_VERTICES(ctx, 0);
582 ctx->NewDriverState |=
583 ctx->DriverFlags.NewIntelConservativeRasterization;
584 ctx->IntelConservativeRasterization = state;
585 break;
586 case GL_CONSERVATIVE_RASTERIZATION_NV:
587 if (!_mesa_has_NV_conservative_raster(ctx))
588 goto invalid_enum_error;
589 if (ctx->ConservativeRasterization == state)
590 return;
591 FLUSH_VERTICES(ctx, 0);
592 ctx->NewDriverState |=
593 ctx->DriverFlags.NewNvConservativeRasterization;
594 ctx->ConservativeRasterization = state;
595 break;
596 case GL_COLOR_LOGIC_OP:
597 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
598 goto invalid_enum_error;
599 if (ctx->Color.ColorLogicOpEnabled == state)
600 return;
601 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLogicOp ? 0 : _NEW_COLOR);
602 ctx->NewDriverState |= ctx->DriverFlags.NewLogicOp;
603 ctx->Color.ColorLogicOpEnabled = state;
604 _mesa_update_allow_draw_out_of_order(ctx);
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 _mesa_update_allow_draw_out_of_order(ctx);
842 break;
843 case GL_TEXTURE_1D:
844 if (ctx->API != API_OPENGL_COMPAT)
845 goto invalid_enum_error;
846 if (!enable_texture(ctx, state, TEXTURE_1D_BIT)) {
847 return;
848 }
849 break;
850 case GL_TEXTURE_2D:
851 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
852 goto invalid_enum_error;
853 if (!enable_texture(ctx, state, TEXTURE_2D_BIT)) {
854 return;
855 }
856 break;
857 case GL_TEXTURE_3D:
858 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
859 goto invalid_enum_error;
860 if (!enable_texture(ctx, state, TEXTURE_3D_BIT)) {
861 return;
862 }
863 break;
864 case GL_TEXTURE_GEN_S:
865 case GL_TEXTURE_GEN_T:
866 case GL_TEXTURE_GEN_R:
867 case GL_TEXTURE_GEN_Q:
868 {
869 struct gl_fixedfunc_texture_unit *texUnit = get_texcoord_unit(ctx);
870
871 if (ctx->API != API_OPENGL_COMPAT)
872 goto invalid_enum_error;
873
874 if (texUnit) {
875 GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
876 GLbitfield newenabled = texUnit->TexGenEnabled & ~coordBit;
877 if (state)
878 newenabled |= coordBit;
879 if (texUnit->TexGenEnabled == newenabled)
880 return;
881 FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);
882 texUnit->TexGenEnabled = newenabled;
883 }
884 }
885 break;
886
887 case GL_TEXTURE_GEN_STR_OES:
888 /* disable S, T, and R at the same time */
889 {
890 struct gl_fixedfunc_texture_unit *texUnit = get_texcoord_unit(ctx);
891
892 if (ctx->API != API_OPENGLES)
893 goto invalid_enum_error;
894
895 if (texUnit) {
896 GLuint newenabled =
897 texUnit->TexGenEnabled & ~STR_BITS;
898 if (state)
899 newenabled |= STR_BITS;
900 if (texUnit->TexGenEnabled == newenabled)
901 return;
902 FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);
903 texUnit->TexGenEnabled = newenabled;
904 }
905 }
906 break;
907
908 /* client-side state */
909 case GL_VERTEX_ARRAY:
910 case GL_NORMAL_ARRAY:
911 case GL_COLOR_ARRAY:
912 case GL_TEXTURE_COORD_ARRAY:
913 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
914 goto invalid_enum_error;
915 client_state( ctx, ctx->Array.VAO, cap, state );
916 return;
917 case GL_INDEX_ARRAY:
918 case GL_EDGE_FLAG_ARRAY:
919 case GL_FOG_COORDINATE_ARRAY_EXT:
920 case GL_SECONDARY_COLOR_ARRAY_EXT:
921 if (ctx->API != API_OPENGL_COMPAT)
922 goto invalid_enum_error;
923 client_state( ctx, ctx->Array.VAO, cap, state );
924 return;
925 case GL_POINT_SIZE_ARRAY_OES:
926 if (ctx->API != API_OPENGLES)
927 goto invalid_enum_error;
928 client_state( ctx, ctx->Array.VAO, cap, state );
929 return;
930
931 /* GL_ARB_texture_cube_map */
932 case GL_TEXTURE_CUBE_MAP:
933 if (!_mesa_has_ARB_texture_cube_map(ctx) &&
934 !_mesa_has_OES_texture_cube_map(ctx))
935 goto invalid_enum_error;
936 if (!enable_texture(ctx, state, TEXTURE_CUBE_BIT)) {
937 return;
938 }
939 break;
940
941 /* GL_EXT_secondary_color */
942 case GL_COLOR_SUM_EXT:
943 if (ctx->API != API_OPENGL_COMPAT)
944 goto invalid_enum_error;
945 if (ctx->Fog.ColorSumEnabled == state)
946 return;
947 FLUSH_VERTICES(ctx, _NEW_FOG);
948 ctx->Fog.ColorSumEnabled = state;
949 break;
950
951 /* GL_ARB_multisample */
952 case GL_MULTISAMPLE_ARB:
953 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
954 goto invalid_enum_error;
955 _mesa_set_multisample(ctx, state);
956 return;
957 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
958 if (ctx->Multisample.SampleAlphaToCoverage == state)
959 return;
960 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleAlphaToXEnable ? 0 :
961 _NEW_MULTISAMPLE);
962 ctx->NewDriverState |= ctx->DriverFlags.NewSampleAlphaToXEnable;
963 ctx->Multisample.SampleAlphaToCoverage = state;
964 break;
965 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
966 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
967 goto invalid_enum_error;
968 if (ctx->Multisample.SampleAlphaToOne == state)
969 return;
970 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleAlphaToXEnable ? 0 :
971 _NEW_MULTISAMPLE);
972 ctx->NewDriverState |= ctx->DriverFlags.NewSampleAlphaToXEnable;
973 ctx->Multisample.SampleAlphaToOne = state;
974 break;
975 case GL_SAMPLE_COVERAGE_ARB:
976 if (ctx->Multisample.SampleCoverage == state)
977 return;
978 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleMask ? 0 :
979 _NEW_MULTISAMPLE);
980 ctx->NewDriverState |= ctx->DriverFlags.NewSampleMask;
981 ctx->Multisample.SampleCoverage = state;
982 break;
983 case GL_SAMPLE_COVERAGE_INVERT_ARB:
984 if (!_mesa_is_desktop_gl(ctx))
985 goto invalid_enum_error;
986 if (ctx->Multisample.SampleCoverageInvert == state)
987 return;
988 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleMask ? 0 :
989 _NEW_MULTISAMPLE);
990 ctx->NewDriverState |= ctx->DriverFlags.NewSampleMask;
991 ctx->Multisample.SampleCoverageInvert = state;
992 break;
993
994 /* GL_ARB_sample_shading */
995 case GL_SAMPLE_SHADING:
996 if (!_mesa_has_ARB_sample_shading(ctx) && !_mesa_is_gles3(ctx))
997 goto invalid_enum_error;
998 if (ctx->Multisample.SampleShading == state)
999 return;
1000 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleShading ? 0 :
1001 _NEW_MULTISAMPLE);
1002 ctx->NewDriverState |= ctx->DriverFlags.NewSampleShading;
1003 ctx->Multisample.SampleShading = state;
1004 break;
1005
1006 /* GL_IBM_rasterpos_clip */
1007 case GL_RASTER_POSITION_UNCLIPPED_IBM:
1008 if (ctx->API != API_OPENGL_COMPAT)
1009 goto invalid_enum_error;
1010 if (ctx->Transform.RasterPositionUnclipped == state)
1011 return;
1012 FLUSH_VERTICES(ctx, 0);
1013 ctx->Transform.RasterPositionUnclipped = state;
1014 break;
1015
1016 /* GL_NV_point_sprite */
1017 case GL_POINT_SPRITE_NV:
1018 if (!(ctx->API == API_OPENGL_COMPAT &&
1019 (_mesa_has_ARB_point_sprite(ctx) ||
1020 _mesa_has_NV_point_sprite(ctx))) &&
1021 !_mesa_has_OES_point_sprite(ctx))
1022 goto invalid_enum_error;
1023 if (ctx->Point.PointSprite == state)
1024 return;
1025 FLUSH_VERTICES(ctx, _NEW_POINT);
1026 ctx->Point.PointSprite = state;
1027 break;
1028
1029 case GL_VERTEX_PROGRAM_ARB:
1030 if (!_mesa_has_ARB_vertex_program(ctx))
1031 goto invalid_enum_error;
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 (!_mesa_has_ARB_vertex_program(ctx))
1052 goto invalid_enum_error;
1053 if (ctx->VertexProgram.TwoSideEnabled == state)
1054 return;
1055 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
1056 ctx->VertexProgram.TwoSideEnabled = state;
1057 break;
1058
1059 /* GL_NV_texture_rectangle */
1060 case GL_TEXTURE_RECTANGLE_NV:
1061 if (ctx->API != API_OPENGL_COMPAT)
1062 goto invalid_enum_error;
1063 CHECK_EXTENSION(NV_texture_rectangle);
1064 if (!enable_texture(ctx, state, TEXTURE_RECT_BIT)) {
1065 return;
1066 }
1067 break;
1068
1069 /* GL_EXT_stencil_two_side */
1070 case GL_STENCIL_TEST_TWO_SIDE_EXT:
1071 if (ctx->API != API_OPENGL_COMPAT)
1072 goto invalid_enum_error;
1073 CHECK_EXTENSION(EXT_stencil_two_side);
1074 if (ctx->Stencil.TestTwoSide == state)
1075 return;
1076 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewStencil ? 0 : _NEW_STENCIL);
1077 ctx->NewDriverState |= ctx->DriverFlags.NewStencil;
1078 ctx->Stencil.TestTwoSide = state;
1079 if (state) {
1080 ctx->Stencil._BackFace = 2;
1081 } else {
1082 ctx->Stencil._BackFace = 1;
1083 }
1084 break;
1085
1086 case GL_FRAGMENT_PROGRAM_ARB:
1087 if (!_mesa_has_ARB_fragment_program(ctx))
1088 goto invalid_enum_error;
1089 if (ctx->FragmentProgram.Enabled == state)
1090 return;
1091 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
1092 ctx->FragmentProgram.Enabled = state;
1093 break;
1094
1095 /* GL_EXT_depth_bounds_test */
1096 case GL_DEPTH_BOUNDS_TEST_EXT:
1097 if (!_mesa_is_desktop_gl(ctx))
1098 goto invalid_enum_error;
1099 CHECK_EXTENSION(EXT_depth_bounds_test);
1100 if (ctx->Depth.BoundsTest == state)
1101 return;
1102 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepth ? 0 : _NEW_DEPTH);
1103 ctx->NewDriverState |= ctx->DriverFlags.NewDepth;
1104 ctx->Depth.BoundsTest = state;
1105 break;
1106
1107 case GL_DEPTH_CLAMP:
1108 if (!_mesa_has_ARB_depth_clamp(ctx) &&
1109 !_mesa_has_EXT_depth_clamp(ctx))
1110 goto invalid_enum_error;
1111 if (ctx->Transform.DepthClampNear == state &&
1112 ctx->Transform.DepthClampFar == state)
1113 return;
1114 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepthClamp ? 0 :
1115 _NEW_TRANSFORM);
1116 ctx->NewDriverState |= ctx->DriverFlags.NewDepthClamp;
1117 ctx->Transform.DepthClampNear = state;
1118 ctx->Transform.DepthClampFar = state;
1119 break;
1120
1121 case GL_DEPTH_CLAMP_NEAR_AMD:
1122 if (!_mesa_is_desktop_gl(ctx))
1123 goto invalid_enum_error;
1124 CHECK_EXTENSION(AMD_depth_clamp_separate);
1125 if (ctx->Transform.DepthClampNear == state)
1126 return;
1127 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepthClamp ? 0 :
1128 _NEW_TRANSFORM);
1129 ctx->NewDriverState |= ctx->DriverFlags.NewDepthClamp;
1130 ctx->Transform.DepthClampNear = state;
1131 break;
1132
1133 case GL_DEPTH_CLAMP_FAR_AMD:
1134 if (!_mesa_is_desktop_gl(ctx))
1135 goto invalid_enum_error;
1136 CHECK_EXTENSION(AMD_depth_clamp_separate);
1137 if (ctx->Transform.DepthClampFar == state)
1138 return;
1139 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepthClamp ? 0 :
1140 _NEW_TRANSFORM);
1141 ctx->NewDriverState |= ctx->DriverFlags.NewDepthClamp;
1142 ctx->Transform.DepthClampFar = state;
1143 break;
1144
1145 case GL_FRAGMENT_SHADER_ATI:
1146 if (ctx->API != API_OPENGL_COMPAT)
1147 goto invalid_enum_error;
1148 CHECK_EXTENSION(ATI_fragment_shader);
1149 if (ctx->ATIFragmentShader.Enabled == state)
1150 return;
1151 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
1152 ctx->ATIFragmentShader.Enabled = state;
1153 break;
1154
1155 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1156 if (!_mesa_is_desktop_gl(ctx))
1157 goto invalid_enum_error;
1158 CHECK_EXTENSION(ARB_seamless_cube_map);
1159 if (ctx->Texture.CubeMapSeamless != state) {
1160 FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT);
1161 ctx->Texture.CubeMapSeamless = state;
1162 }
1163 break;
1164
1165 case GL_RASTERIZER_DISCARD:
1166 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1167 goto invalid_enum_error;
1168 CHECK_EXTENSION(EXT_transform_feedback);
1169 if (ctx->RasterDiscard != state) {
1170 FLUSH_VERTICES(ctx, 0);
1171 ctx->NewDriverState |= ctx->DriverFlags.NewRasterizerDiscard;
1172 ctx->RasterDiscard = state;
1173 }
1174 break;
1175
1176 case GL_TILE_RASTER_ORDER_FIXED_MESA:
1177 if (!_mesa_has_MESA_tile_raster_order(ctx))
1178 goto invalid_enum_error;
1179 if (ctx->TileRasterOrderFixed != state) {
1180 FLUSH_VERTICES(ctx, 0);
1181 ctx->NewDriverState |= ctx->DriverFlags.NewTileRasterOrder;
1182 ctx->TileRasterOrderFixed = state;
1183 }
1184 break;
1185
1186 case GL_TILE_RASTER_ORDER_INCREASING_X_MESA:
1187 if (!_mesa_has_MESA_tile_raster_order(ctx))
1188 goto invalid_enum_error;
1189 if (ctx->TileRasterOrderIncreasingX != state) {
1190 FLUSH_VERTICES(ctx, 0);
1191 ctx->NewDriverState |= ctx->DriverFlags.NewTileRasterOrder;
1192 ctx->TileRasterOrderIncreasingX = state;
1193 }
1194 break;
1195
1196 case GL_TILE_RASTER_ORDER_INCREASING_Y_MESA:
1197 if (!_mesa_has_MESA_tile_raster_order(ctx))
1198 goto invalid_enum_error;
1199 if (ctx->TileRasterOrderIncreasingY != state) {
1200 FLUSH_VERTICES(ctx, 0);
1201 ctx->NewDriverState |= ctx->DriverFlags.NewTileRasterOrder;
1202 ctx->TileRasterOrderIncreasingY = state;
1203 }
1204 break;
1205
1206 /* GL 3.1 primitive restart. Note: this enum is different from
1207 * GL_PRIMITIVE_RESTART_NV (which is client state).
1208 */
1209 case GL_PRIMITIVE_RESTART:
1210 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
1211 goto invalid_enum_error;
1212 }
1213 if (ctx->Array.PrimitiveRestart != state) {
1214 FLUSH_VERTICES(ctx, 0);
1215 ctx->Array.PrimitiveRestart = state;
1216 update_derived_primitive_restart_state(ctx);
1217 }
1218 break;
1219
1220 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
1221 if (!_mesa_is_gles3(ctx) && !_mesa_has_ARB_ES3_compatibility(ctx))
1222 goto invalid_enum_error;
1223 if (ctx->Array.PrimitiveRestartFixedIndex != state) {
1224 FLUSH_VERTICES(ctx, 0);
1225 ctx->Array.PrimitiveRestartFixedIndex = state;
1226 update_derived_primitive_restart_state(ctx);
1227 }
1228 break;
1229
1230 /* GL3.0 - GL_framebuffer_sRGB */
1231 case GL_FRAMEBUFFER_SRGB_EXT:
1232 if (!_mesa_has_EXT_framebuffer_sRGB(ctx) &&
1233 !_mesa_has_EXT_sRGB_write_control(ctx))
1234 goto invalid_enum_error;
1235 _mesa_set_framebuffer_srgb(ctx, state);
1236 return;
1237
1238 /* GL_OES_EGL_image_external */
1239 case GL_TEXTURE_EXTERNAL_OES:
1240 if (!_mesa_is_gles(ctx))
1241 goto invalid_enum_error;
1242 CHECK_EXTENSION(OES_EGL_image_external);
1243 if (!enable_texture(ctx, state, TEXTURE_EXTERNAL_BIT)) {
1244 return;
1245 }
1246 break;
1247
1248 /* ARB_texture_multisample */
1249 case GL_SAMPLE_MASK:
1250 if (!_mesa_has_ARB_texture_multisample(ctx) && !_mesa_is_gles31(ctx))
1251 goto invalid_enum_error;
1252 if (ctx->Multisample.SampleMask == state)
1253 return;
1254 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewSampleMask ? 0 :
1255 _NEW_MULTISAMPLE);
1256 ctx->NewDriverState |= ctx->DriverFlags.NewSampleMask;
1257 ctx->Multisample.SampleMask = state;
1258 break;
1259
1260 case GL_BLEND_ADVANCED_COHERENT_KHR:
1261 if (!_mesa_has_KHR_blend_equation_advanced_coherent(ctx))
1262 goto invalid_enum_error;
1263 if (ctx->Color.BlendCoherent == state)
1264 return;
1265 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewBlend ? 0 : _NEW_COLOR);
1266 ctx->NewDriverState |= ctx->DriverFlags.NewBlend;
1267 ctx->Color.BlendCoherent = state;
1268 break;
1269
1270 case GL_BLACKHOLE_RENDER_INTEL:
1271 if (!_mesa_has_INTEL_blackhole_render(ctx))
1272 goto invalid_enum_error;
1273 if (ctx->IntelBlackholeRender == state)
1274 return;
1275 FLUSH_VERTICES(ctx, 0);
1276 ctx->IntelBlackholeRender = state;
1277 break;
1278
1279 default:
1280 goto invalid_enum_error;
1281 }
1282
1283 if (ctx->Driver.Enable) {
1284 ctx->Driver.Enable( ctx, cap, state );
1285 }
1286
1287 return;
1288
1289 invalid_enum_error:
1290 _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(%s)",
1291 state ? "Enable" : "Disable", _mesa_enum_to_string(cap));
1292 }
1293
1294
1295 /**
1296 * Enable GL capability. Called by glEnable()
1297 * \param cap state to enable.
1298 */
1299 void GLAPIENTRY
1300 _mesa_Enable( GLenum cap )
1301 {
1302 GET_CURRENT_CONTEXT(ctx);
1303
1304 _mesa_set_enable( ctx, cap, GL_TRUE );
1305 }
1306
1307
1308 /**
1309 * Disable GL capability. Called by glDisable()
1310 * \param cap state to disable.
1311 */
1312 void GLAPIENTRY
1313 _mesa_Disable( GLenum cap )
1314 {
1315 GET_CURRENT_CONTEXT(ctx);
1316
1317 _mesa_set_enable( ctx, cap, GL_FALSE );
1318 }
1319
1320
1321
1322 /**
1323 * Enable/disable an indexed state var.
1324 */
1325 void
1326 _mesa_set_enablei(struct gl_context *ctx, GLenum cap,
1327 GLuint index, GLboolean state)
1328 {
1329 assert(state == 0 || state == 1);
1330 switch (cap) {
1331 case GL_BLEND:
1332 if (!ctx->Extensions.EXT_draw_buffers2) {
1333 goto invalid_enum_error;
1334 }
1335 if (index >= ctx->Const.MaxDrawBuffers) {
1336 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1337 state ? "glEnableIndexed" : "glDisableIndexed", index);
1338 return;
1339 }
1340 if (((ctx->Color.BlendEnabled >> index) & 1) != state) {
1341 GLbitfield enabled = ctx->Color.BlendEnabled;
1342
1343 if (state)
1344 enabled |= (1 << index);
1345 else
1346 enabled &= ~(1 << index);
1347
1348 _mesa_flush_vertices_for_blend_adv(ctx, enabled,
1349 ctx->Color._AdvancedBlendMode);
1350 ctx->Color.BlendEnabled = enabled;
1351 _mesa_update_allow_draw_out_of_order(ctx);
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 &&
1805 (_mesa_has_ARB_point_sprite(ctx) ||
1806 _mesa_has_NV_point_sprite(ctx))) &&
1807 !_mesa_has_OES_point_sprite(ctx))
1808 goto invalid_enum_error;
1809 return ctx->Point.PointSprite;
1810
1811 case GL_VERTEX_PROGRAM_ARB:
1812 if (!_mesa_has_ARB_vertex_program(ctx))
1813 goto invalid_enum_error;
1814 return ctx->VertexProgram.Enabled;
1815 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
1816 /* This was added with ARB_vertex_program, but it is also used with
1817 * GLSL vertex shaders on desktop.
1818 */
1819 if (!_mesa_is_desktop_gl(ctx))
1820 goto invalid_enum_error;
1821 CHECK_EXTENSION(ARB_vertex_program);
1822 return ctx->VertexProgram.PointSizeEnabled;
1823 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
1824 if (!_mesa_has_ARB_vertex_program(ctx))
1825 goto invalid_enum_error;
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 if (!_mesa_has_INTEL_blackhole_render(ctx))
1968 goto invalid_enum_error;
1969 return ctx->IntelBlackholeRender;
1970
1971 default:
1972 goto invalid_enum_error;
1973 }
1974
1975 return GL_FALSE;
1976
1977 invalid_enum_error:
1978 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(%s)",
1979 _mesa_enum_to_string(cap));
1980 return GL_FALSE;
1981 }