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