mesa/main: Maintain compressed fog mode.
[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 "api_arrayelt.h"
41 #include "texstate.h"
42
43
44
45 #define CHECK_EXTENSION(EXTNAME, CAP) \
46 if (!ctx->Extensions.EXTNAME) { \
47 goto invalid_enum_error; \
48 }
49
50
51 static void
52 update_derived_primitive_restart_state(struct gl_context *ctx)
53 {
54 /* Update derived primitive restart state.
55 */
56 ctx->Array._PrimitiveRestart = ctx->Array.PrimitiveRestart
57 || ctx->Array.PrimitiveRestartFixedIndex;
58 }
59
60 /**
61 * Helper to enable/disable client-side state.
62 */
63 static void
64 client_state(struct gl_context *ctx, GLenum cap, GLboolean state)
65 {
66 struct gl_vertex_array_object *vao = ctx->Array.VAO;
67 GLbitfield64 flag;
68 GLboolean *var;
69
70 switch (cap) {
71 case GL_VERTEX_ARRAY:
72 var = &vao->VertexAttrib[VERT_ATTRIB_POS].Enabled;
73 flag = VERT_BIT_POS;
74 break;
75 case GL_NORMAL_ARRAY:
76 var = &vao->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled;
77 flag = VERT_BIT_NORMAL;
78 break;
79 case GL_COLOR_ARRAY:
80 var = &vao->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled;
81 flag = VERT_BIT_COLOR0;
82 break;
83 case GL_INDEX_ARRAY:
84 var = &vao->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled;
85 flag = VERT_BIT_COLOR_INDEX;
86 break;
87 case GL_TEXTURE_COORD_ARRAY:
88 var = &vao->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Enabled;
89 flag = VERT_BIT_TEX(ctx->Array.ActiveTexture);
90 break;
91 case GL_EDGE_FLAG_ARRAY:
92 var = &vao->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled;
93 flag = VERT_BIT_EDGEFLAG;
94 break;
95 case GL_FOG_COORDINATE_ARRAY_EXT:
96 var = &vao->VertexAttrib[VERT_ATTRIB_FOG].Enabled;
97 flag = VERT_BIT_FOG;
98 break;
99 case GL_SECONDARY_COLOR_ARRAY_EXT:
100 var = &vao->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled;
101 flag = VERT_BIT_COLOR1;
102 break;
103
104 case GL_POINT_SIZE_ARRAY_OES:
105 var = &vao->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled;
106 flag = VERT_BIT_POINT_SIZE;
107 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
108 ctx->VertexProgram.PointSizeEnabled = state;
109 break;
110
111 /* GL_NV_primitive_restart */
112 case GL_PRIMITIVE_RESTART_NV:
113 if (!ctx->Extensions.NV_primitive_restart) {
114 goto invalid_enum_error;
115 }
116 var = &ctx->Array.PrimitiveRestart;
117 flag = 0;
118 break;
119
120 default:
121 goto invalid_enum_error;
122 }
123
124 if (*var == state)
125 return;
126
127 FLUSH_VERTICES(ctx, _NEW_ARRAY);
128
129 _ae_invalidate_state(ctx, _NEW_ARRAY);
130
131 *var = state;
132
133 update_derived_primitive_restart_state(ctx);
134
135 if (state)
136 vao->_Enabled |= flag;
137 else
138 vao->_Enabled &= ~flag;
139
140 vao->NewArrays |= flag;
141
142 if (ctx->Driver.Enable) {
143 ctx->Driver.Enable( ctx, cap, state );
144 }
145
146 return;
147
148 invalid_enum_error:
149 _mesa_error(ctx, GL_INVALID_ENUM, "gl%sClientState(%s)",
150 state ? "Enable" : "Disable", _mesa_enum_to_string(cap));
151 }
152
153
154 /**
155 * Enable GL capability.
156 * \param cap state to enable/disable.
157 *
158 * Get's the current context, assures that we're outside glBegin()/glEnd() and
159 * calls client_state().
160 */
161 void GLAPIENTRY
162 _mesa_EnableClientState( GLenum cap )
163 {
164 GET_CURRENT_CONTEXT(ctx);
165 client_state( ctx, cap, GL_TRUE );
166 }
167
168
169 /**
170 * Disable GL capability.
171 * \param cap state to enable/disable.
172 *
173 * Get's the current context, assures that we're outside glBegin()/glEnd() and
174 * calls client_state().
175 */
176 void GLAPIENTRY
177 _mesa_DisableClientState( GLenum cap )
178 {
179 GET_CURRENT_CONTEXT(ctx);
180 client_state( ctx, cap, GL_FALSE );
181 }
182
183
184 #undef CHECK_EXTENSION
185 #define CHECK_EXTENSION(EXTNAME, CAP) \
186 if (!ctx->Extensions.EXTNAME) { \
187 goto invalid_enum_error; \
188 }
189
190 #define CHECK_EXTENSION2(EXT1, EXT2, CAP) \
191 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
192 goto invalid_enum_error; \
193 }
194
195 /**
196 * Return pointer to current texture unit for setting/getting coordinate
197 * state.
198 * Note that we'll set GL_INVALID_OPERATION and return NULL if the active
199 * texture unit is higher than the number of supported coordinate units.
200 */
201 static struct gl_texture_unit *
202 get_texcoord_unit(struct gl_context *ctx)
203 {
204 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
205 _mesa_error(ctx, GL_INVALID_OPERATION, "glEnable/Disable(texcoord unit)");
206 return NULL;
207 }
208 else {
209 return &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
210 }
211 }
212
213
214 /**
215 * Helper function to enable or disable a texture target.
216 * \param bit one of the TEXTURE_x_BIT values
217 * \return GL_TRUE if state is changing or GL_FALSE if no change
218 */
219 static GLboolean
220 enable_texture(struct gl_context *ctx, GLboolean state, GLbitfield texBit)
221 {
222 struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
223 const GLbitfield newenabled = state
224 ? (texUnit->Enabled | texBit) : (texUnit->Enabled & ~texBit);
225
226 if (texUnit->Enabled == newenabled)
227 return GL_FALSE;
228
229 FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);
230 texUnit->Enabled = newenabled;
231 return GL_TRUE;
232 }
233
234
235 /**
236 * Helper function to enable or disable GL_MULTISAMPLE, skipping the check for
237 * whether the API supports it (GLES doesn't).
238 */
239 void
240 _mesa_set_multisample(struct gl_context *ctx, GLboolean state)
241 {
242 if (ctx->Multisample.Enabled == state)
243 return;
244 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
245 ctx->Multisample.Enabled = state;
246
247 if (ctx->Driver.Enable) {
248 ctx->Driver.Enable(ctx, GL_MULTISAMPLE, state);
249 }
250 }
251
252 /**
253 * Helper function to enable or disable GL_FRAMEBUFFER_SRGB, skipping the
254 * check for whether the API supports it (GLES doesn't).
255 */
256 void
257 _mesa_set_framebuffer_srgb(struct gl_context *ctx, GLboolean state)
258 {
259 if (ctx->Color.sRGBEnabled == state)
260 return;
261 FLUSH_VERTICES(ctx, _NEW_BUFFERS);
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, _NEW_SCISSOR);
674 ctx->Scissor.EnableFlags = newEnabled;
675 }
676 }
677 break;
678 case GL_STENCIL_TEST:
679 if (ctx->Stencil.Enabled == state)
680 return;
681 FLUSH_VERTICES(ctx, _NEW_STENCIL);
682 ctx->Stencil.Enabled = state;
683 break;
684 case GL_TEXTURE_1D:
685 if (ctx->API != API_OPENGL_COMPAT)
686 goto invalid_enum_error;
687 if (!enable_texture(ctx, state, TEXTURE_1D_BIT)) {
688 return;
689 }
690 break;
691 case GL_TEXTURE_2D:
692 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
693 goto invalid_enum_error;
694 if (!enable_texture(ctx, state, TEXTURE_2D_BIT)) {
695 return;
696 }
697 break;
698 case GL_TEXTURE_3D:
699 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
700 goto invalid_enum_error;
701 if (!enable_texture(ctx, state, TEXTURE_3D_BIT)) {
702 return;
703 }
704 break;
705 case GL_TEXTURE_GEN_S:
706 case GL_TEXTURE_GEN_T:
707 case GL_TEXTURE_GEN_R:
708 case GL_TEXTURE_GEN_Q:
709 {
710 struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
711
712 if (ctx->API != API_OPENGL_COMPAT)
713 goto invalid_enum_error;
714
715 if (texUnit) {
716 GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
717 GLbitfield newenabled = texUnit->TexGenEnabled & ~coordBit;
718 if (state)
719 newenabled |= coordBit;
720 if (texUnit->TexGenEnabled == newenabled)
721 return;
722 FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);
723 texUnit->TexGenEnabled = newenabled;
724 }
725 }
726 break;
727
728 case GL_TEXTURE_GEN_STR_OES:
729 /* disable S, T, and R at the same time */
730 {
731 struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
732
733 if (ctx->API != API_OPENGLES)
734 goto invalid_enum_error;
735
736 if (texUnit) {
737 GLuint newenabled =
738 texUnit->TexGenEnabled & ~STR_BITS;
739 if (state)
740 newenabled |= STR_BITS;
741 if (texUnit->TexGenEnabled == newenabled)
742 return;
743 FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);
744 texUnit->TexGenEnabled = newenabled;
745 }
746 }
747 break;
748
749 /* client-side state */
750 case GL_VERTEX_ARRAY:
751 case GL_NORMAL_ARRAY:
752 case GL_COLOR_ARRAY:
753 case GL_TEXTURE_COORD_ARRAY:
754 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
755 goto invalid_enum_error;
756 client_state( ctx, cap, state );
757 return;
758 case GL_INDEX_ARRAY:
759 case GL_EDGE_FLAG_ARRAY:
760 case GL_FOG_COORDINATE_ARRAY_EXT:
761 case GL_SECONDARY_COLOR_ARRAY_EXT:
762 if (ctx->API != API_OPENGL_COMPAT)
763 goto invalid_enum_error;
764 client_state( ctx, cap, state );
765 return;
766 case GL_POINT_SIZE_ARRAY_OES:
767 if (ctx->API != API_OPENGLES)
768 goto invalid_enum_error;
769 client_state( ctx, cap, state );
770 return;
771
772 /* GL_ARB_texture_cube_map */
773 case GL_TEXTURE_CUBE_MAP:
774 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
775 goto invalid_enum_error;
776 CHECK_EXTENSION(ARB_texture_cube_map, cap);
777 if (!enable_texture(ctx, state, TEXTURE_CUBE_BIT)) {
778 return;
779 }
780 break;
781
782 /* GL_EXT_secondary_color */
783 case GL_COLOR_SUM_EXT:
784 if (ctx->API != API_OPENGL_COMPAT)
785 goto invalid_enum_error;
786 if (ctx->Fog.ColorSumEnabled == state)
787 return;
788 FLUSH_VERTICES(ctx, _NEW_FOG);
789 ctx->Fog.ColorSumEnabled = state;
790 break;
791
792 /* GL_ARB_multisample */
793 case GL_MULTISAMPLE_ARB:
794 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
795 goto invalid_enum_error;
796 _mesa_set_multisample(ctx, state);
797 return;
798 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
799 if (ctx->Multisample.SampleAlphaToCoverage == state)
800 return;
801 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
802 ctx->Multisample.SampleAlphaToCoverage = state;
803 break;
804 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
805 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
806 goto invalid_enum_error;
807 if (ctx->Multisample.SampleAlphaToOne == state)
808 return;
809 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
810 ctx->Multisample.SampleAlphaToOne = state;
811 break;
812 case GL_SAMPLE_COVERAGE_ARB:
813 if (ctx->Multisample.SampleCoverage == state)
814 return;
815 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
816 ctx->Multisample.SampleCoverage = state;
817 break;
818 case GL_SAMPLE_COVERAGE_INVERT_ARB:
819 if (!_mesa_is_desktop_gl(ctx))
820 goto invalid_enum_error;
821 if (ctx->Multisample.SampleCoverageInvert == state)
822 return;
823 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
824 ctx->Multisample.SampleCoverageInvert = state;
825 break;
826
827 /* GL_ARB_sample_shading */
828 case GL_SAMPLE_SHADING:
829 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
830 goto invalid_enum_error;
831 CHECK_EXTENSION(ARB_sample_shading, cap);
832 if (ctx->Multisample.SampleShading == state)
833 return;
834 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
835 ctx->Multisample.SampleShading = state;
836 break;
837
838 /* GL_IBM_rasterpos_clip */
839 case GL_RASTER_POSITION_UNCLIPPED_IBM:
840 if (ctx->API != API_OPENGL_COMPAT)
841 goto invalid_enum_error;
842 if (ctx->Transform.RasterPositionUnclipped == state)
843 return;
844 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
845 ctx->Transform.RasterPositionUnclipped = state;
846 break;
847
848 /* GL_NV_point_sprite */
849 case GL_POINT_SPRITE_NV:
850 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
851 goto invalid_enum_error;
852 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite, cap);
853 if (ctx->Point.PointSprite == state)
854 return;
855 FLUSH_VERTICES(ctx, _NEW_POINT);
856 ctx->Point.PointSprite = state;
857 break;
858
859 case GL_VERTEX_PROGRAM_ARB:
860 if (ctx->API != API_OPENGL_COMPAT)
861 goto invalid_enum_error;
862 CHECK_EXTENSION(ARB_vertex_program, cap);
863 if (ctx->VertexProgram.Enabled == state)
864 return;
865 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
866 ctx->VertexProgram.Enabled = state;
867 break;
868 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
869 /* This was added with ARB_vertex_program, but it is also used with
870 * GLSL vertex shaders on desktop.
871 */
872 if (!_mesa_is_desktop_gl(ctx))
873 goto invalid_enum_error;
874 CHECK_EXTENSION(ARB_vertex_program, cap);
875 if (ctx->VertexProgram.PointSizeEnabled == state)
876 return;
877 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
878 ctx->VertexProgram.PointSizeEnabled = state;
879 break;
880 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
881 if (ctx->API != API_OPENGL_COMPAT)
882 goto invalid_enum_error;
883 CHECK_EXTENSION(ARB_vertex_program, cap);
884 if (ctx->VertexProgram.TwoSideEnabled == state)
885 return;
886 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
887 ctx->VertexProgram.TwoSideEnabled = state;
888 break;
889
890 /* GL_NV_texture_rectangle */
891 case GL_TEXTURE_RECTANGLE_NV:
892 if (ctx->API != API_OPENGL_COMPAT)
893 goto invalid_enum_error;
894 CHECK_EXTENSION(NV_texture_rectangle, cap);
895 if (!enable_texture(ctx, state, TEXTURE_RECT_BIT)) {
896 return;
897 }
898 break;
899
900 /* GL_EXT_stencil_two_side */
901 case GL_STENCIL_TEST_TWO_SIDE_EXT:
902 if (ctx->API != API_OPENGL_COMPAT)
903 goto invalid_enum_error;
904 CHECK_EXTENSION(EXT_stencil_two_side, cap);
905 if (ctx->Stencil.TestTwoSide == state)
906 return;
907 FLUSH_VERTICES(ctx, _NEW_STENCIL);
908 ctx->Stencil.TestTwoSide = state;
909 if (state) {
910 ctx->Stencil._BackFace = 2;
911 } else {
912 ctx->Stencil._BackFace = 1;
913 }
914 break;
915
916 case GL_FRAGMENT_PROGRAM_ARB:
917 if (ctx->API != API_OPENGL_COMPAT)
918 goto invalid_enum_error;
919 CHECK_EXTENSION(ARB_fragment_program, cap);
920 if (ctx->FragmentProgram.Enabled == state)
921 return;
922 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
923 ctx->FragmentProgram.Enabled = state;
924 break;
925
926 /* GL_EXT_depth_bounds_test */
927 case GL_DEPTH_BOUNDS_TEST_EXT:
928 if (!_mesa_is_desktop_gl(ctx))
929 goto invalid_enum_error;
930 CHECK_EXTENSION(EXT_depth_bounds_test, cap);
931 if (ctx->Depth.BoundsTest == state)
932 return;
933 FLUSH_VERTICES(ctx, _NEW_DEPTH);
934 ctx->Depth.BoundsTest = state;
935 break;
936
937 case GL_DEPTH_CLAMP:
938 if (!_mesa_is_desktop_gl(ctx))
939 goto invalid_enum_error;
940 CHECK_EXTENSION(ARB_depth_clamp, cap);
941 if (ctx->Transform.DepthClamp == state)
942 return;
943 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
944 ctx->Transform.DepthClamp = state;
945 break;
946
947 case GL_FRAGMENT_SHADER_ATI:
948 if (ctx->API != API_OPENGL_COMPAT)
949 goto invalid_enum_error;
950 CHECK_EXTENSION(ATI_fragment_shader, cap);
951 if (ctx->ATIFragmentShader.Enabled == state)
952 return;
953 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
954 ctx->ATIFragmentShader.Enabled = state;
955 break;
956
957 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
958 if (!_mesa_is_desktop_gl(ctx))
959 goto invalid_enum_error;
960 CHECK_EXTENSION(ARB_seamless_cube_map, cap);
961 if (ctx->Texture.CubeMapSeamless != state) {
962 FLUSH_VERTICES(ctx, _NEW_TEXTURE_OBJECT);
963 ctx->Texture.CubeMapSeamless = state;
964 }
965 break;
966
967 case GL_RASTERIZER_DISCARD:
968 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
969 goto invalid_enum_error;
970 CHECK_EXTENSION(EXT_transform_feedback, cap);
971 if (ctx->RasterDiscard != state) {
972 FLUSH_VERTICES(ctx, 0);
973 ctx->NewDriverState |= ctx->DriverFlags.NewRasterizerDiscard;
974 ctx->RasterDiscard = state;
975 }
976 break;
977
978 /* GL 3.1 primitive restart. Note: this enum is different from
979 * GL_PRIMITIVE_RESTART_NV (which is client state).
980 */
981 case GL_PRIMITIVE_RESTART:
982 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
983 goto invalid_enum_error;
984 }
985 if (ctx->Array.PrimitiveRestart != state) {
986 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
987 ctx->Array.PrimitiveRestart = state;
988 update_derived_primitive_restart_state(ctx);
989 }
990 break;
991
992 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
993 if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility)
994 goto invalid_enum_error;
995 if (ctx->Array.PrimitiveRestartFixedIndex != state) {
996 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
997 ctx->Array.PrimitiveRestartFixedIndex = state;
998 update_derived_primitive_restart_state(ctx);
999 }
1000 break;
1001
1002 /* GL3.0 - GL_framebuffer_sRGB */
1003 case GL_FRAMEBUFFER_SRGB_EXT:
1004 if (!_mesa_is_desktop_gl(ctx))
1005 goto invalid_enum_error;
1006 CHECK_EXTENSION(EXT_framebuffer_sRGB, cap);
1007 _mesa_set_framebuffer_srgb(ctx, state);
1008 return;
1009
1010 /* GL_OES_EGL_image_external */
1011 case GL_TEXTURE_EXTERNAL_OES:
1012 if (!_mesa_is_gles(ctx))
1013 goto invalid_enum_error;
1014 CHECK_EXTENSION(OES_EGL_image_external, cap);
1015 if (!enable_texture(ctx, state, TEXTURE_EXTERNAL_BIT)) {
1016 return;
1017 }
1018 break;
1019
1020 /* ARB_texture_multisample */
1021 case GL_SAMPLE_MASK:
1022 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
1023 goto invalid_enum_error;
1024 CHECK_EXTENSION(ARB_texture_multisample, cap);
1025 if (ctx->Multisample.SampleMask == state)
1026 return;
1027 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
1028 ctx->Multisample.SampleMask = state;
1029 break;
1030
1031 case GL_BLEND_ADVANCED_COHERENT_KHR:
1032 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent, cap);
1033 if (ctx->Color.BlendCoherent == state)
1034 return;
1035 FLUSH_VERTICES(ctx, _NEW_COLOR);
1036 ctx->Color.BlendCoherent = state;
1037 break;
1038
1039 default:
1040 goto invalid_enum_error;
1041 }
1042
1043 if (ctx->Driver.Enable) {
1044 ctx->Driver.Enable( ctx, cap, state );
1045 }
1046
1047 return;
1048
1049 invalid_enum_error:
1050 _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(%s)",
1051 state ? "Enable" : "Disable", _mesa_enum_to_string(cap));
1052 }
1053
1054
1055 /**
1056 * Enable GL capability. Called by glEnable()
1057 * \param cap state to enable.
1058 */
1059 void GLAPIENTRY
1060 _mesa_Enable( GLenum cap )
1061 {
1062 GET_CURRENT_CONTEXT(ctx);
1063
1064 _mesa_set_enable( ctx, cap, GL_TRUE );
1065 }
1066
1067
1068 /**
1069 * Disable GL capability. Called by glDisable()
1070 * \param cap state to disable.
1071 */
1072 void GLAPIENTRY
1073 _mesa_Disable( GLenum cap )
1074 {
1075 GET_CURRENT_CONTEXT(ctx);
1076
1077 _mesa_set_enable( ctx, cap, GL_FALSE );
1078 }
1079
1080
1081
1082 /**
1083 * Enable/disable an indexed state var.
1084 */
1085 void
1086 _mesa_set_enablei(struct gl_context *ctx, GLenum cap,
1087 GLuint index, GLboolean state)
1088 {
1089 assert(state == 0 || state == 1);
1090 switch (cap) {
1091 case GL_BLEND:
1092 if (!ctx->Extensions.EXT_draw_buffers2) {
1093 goto invalid_enum_error;
1094 }
1095 if (index >= ctx->Const.MaxDrawBuffers) {
1096 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1097 state ? "glEnableIndexed" : "glDisableIndexed", index);
1098 return;
1099 }
1100 if (((ctx->Color.BlendEnabled >> index) & 1) != state) {
1101 FLUSH_VERTICES(ctx, _NEW_COLOR);
1102 if (state)
1103 ctx->Color.BlendEnabled |= (1 << index);
1104 else
1105 ctx->Color.BlendEnabled &= ~(1 << index);
1106 }
1107 break;
1108 case GL_SCISSOR_TEST:
1109 if (index >= ctx->Const.MaxViewports) {
1110 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1111 state ? "glEnablei" : "glDisablei", index);
1112 return;
1113 }
1114 if (((ctx->Scissor.EnableFlags >> index) & 1) != state) {
1115 FLUSH_VERTICES(ctx, _NEW_SCISSOR);
1116 if (state)
1117 ctx->Scissor.EnableFlags |= (1 << index);
1118 else
1119 ctx->Scissor.EnableFlags &= ~(1 << index);
1120 }
1121 break;
1122 default:
1123 goto invalid_enum_error;
1124 }
1125 return;
1126
1127 invalid_enum_error:
1128 _mesa_error(ctx, GL_INVALID_ENUM, "%s(cap=%s)",
1129 state ? "glEnablei" : "glDisablei",
1130 _mesa_enum_to_string(cap));
1131 }
1132
1133
1134 void GLAPIENTRY
1135 _mesa_Disablei( GLenum cap, GLuint index )
1136 {
1137 GET_CURRENT_CONTEXT(ctx);
1138 _mesa_set_enablei(ctx, cap, index, GL_FALSE);
1139 }
1140
1141
1142 void GLAPIENTRY
1143 _mesa_Enablei( GLenum cap, GLuint index )
1144 {
1145 GET_CURRENT_CONTEXT(ctx);
1146 _mesa_set_enablei(ctx, cap, index, GL_TRUE);
1147 }
1148
1149
1150 GLboolean GLAPIENTRY
1151 _mesa_IsEnabledi( GLenum cap, GLuint index )
1152 {
1153 GET_CURRENT_CONTEXT(ctx);
1154 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1155 switch (cap) {
1156 case GL_BLEND:
1157 if (index >= ctx->Const.MaxDrawBuffers) {
1158 _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
1159 index);
1160 return GL_FALSE;
1161 }
1162 return (ctx->Color.BlendEnabled >> index) & 1;
1163 case GL_SCISSOR_TEST:
1164 if (index >= ctx->Const.MaxViewports) {
1165 _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
1166 index);
1167 return GL_FALSE;
1168 }
1169 return (ctx->Scissor.EnableFlags >> index) & 1;
1170 default:
1171 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabledIndexed(cap=%s)",
1172 _mesa_enum_to_string(cap));
1173 return GL_FALSE;
1174 }
1175 }
1176
1177
1178
1179
1180 #undef CHECK_EXTENSION
1181 #define CHECK_EXTENSION(EXTNAME) \
1182 if (!ctx->Extensions.EXTNAME) { \
1183 goto invalid_enum_error; \
1184 }
1185
1186 #undef CHECK_EXTENSION2
1187 #define CHECK_EXTENSION2(EXT1, EXT2) \
1188 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1189 goto invalid_enum_error; \
1190 }
1191
1192
1193 /**
1194 * Helper function to determine whether a texture target is enabled.
1195 */
1196 static GLboolean
1197 is_texture_enabled(struct gl_context *ctx, GLbitfield bit)
1198 {
1199 const struct gl_texture_unit *const texUnit =
1200 &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1201 return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE;
1202 }
1203
1204
1205 /**
1206 * Return simple enable/disable state.
1207 *
1208 * \param cap state variable to query.
1209 *
1210 * Returns the state of the specified capability from the current GL context.
1211 * For the capabilities associated with extensions verifies that those
1212 * extensions are effectively present before reporting.
1213 */
1214 GLboolean GLAPIENTRY
1215 _mesa_IsEnabled( GLenum cap )
1216 {
1217 GET_CURRENT_CONTEXT(ctx);
1218 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
1219
1220 switch (cap) {
1221 case GL_ALPHA_TEST:
1222 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1223 goto invalid_enum_error;
1224 return ctx->Color.AlphaEnabled;
1225 case GL_AUTO_NORMAL:
1226 if (ctx->API != API_OPENGL_COMPAT)
1227 goto invalid_enum_error;
1228 return ctx->Eval.AutoNormal;
1229 case GL_BLEND:
1230 return ctx->Color.BlendEnabled & 1; /* return state for buffer[0] */
1231 case GL_CLIP_DISTANCE0: /* aka GL_CLIP_PLANE0 */
1232 case GL_CLIP_DISTANCE1:
1233 case GL_CLIP_DISTANCE2:
1234 case GL_CLIP_DISTANCE3:
1235 case GL_CLIP_DISTANCE4:
1236 case GL_CLIP_DISTANCE5:
1237 case GL_CLIP_DISTANCE6:
1238 case GL_CLIP_DISTANCE7: {
1239 const GLuint p = cap - GL_CLIP_DISTANCE0;
1240
1241 if (p >= ctx->Const.MaxClipPlanes)
1242 goto invalid_enum_error;
1243
1244 return (ctx->Transform.ClipPlanesEnabled >> p) & 1;
1245 }
1246 case GL_COLOR_MATERIAL:
1247 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1248 goto invalid_enum_error;
1249 return ctx->Light.ColorMaterialEnabled;
1250 case GL_CULL_FACE:
1251 return ctx->Polygon.CullFlag;
1252 case GL_DEBUG_OUTPUT:
1253 case GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB:
1254 return (GLboolean) _mesa_get_debug_state_int(ctx, cap);
1255 case GL_DEPTH_TEST:
1256 return ctx->Depth.Test;
1257 case GL_DITHER:
1258 return ctx->Color.DitherFlag;
1259 case GL_FOG:
1260 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1261 goto invalid_enum_error;
1262 return ctx->Fog.Enabled;
1263 case GL_LIGHTING:
1264 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1265 goto invalid_enum_error;
1266 return ctx->Light.Enabled;
1267 case GL_LIGHT0:
1268 case GL_LIGHT1:
1269 case GL_LIGHT2:
1270 case GL_LIGHT3:
1271 case GL_LIGHT4:
1272 case GL_LIGHT5:
1273 case GL_LIGHT6:
1274 case GL_LIGHT7:
1275 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1276 goto invalid_enum_error;
1277 return ctx->Light.Light[cap-GL_LIGHT0].Enabled;
1278 case GL_LINE_SMOOTH:
1279 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1280 goto invalid_enum_error;
1281 return ctx->Line.SmoothFlag;
1282 case GL_LINE_STIPPLE:
1283 if (ctx->API != API_OPENGL_COMPAT)
1284 goto invalid_enum_error;
1285 return ctx->Line.StippleFlag;
1286 case GL_INDEX_LOGIC_OP:
1287 if (ctx->API != API_OPENGL_COMPAT)
1288 goto invalid_enum_error;
1289 return ctx->Color.IndexLogicOpEnabled;
1290 case GL_COLOR_LOGIC_OP:
1291 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1292 goto invalid_enum_error;
1293 return ctx->Color.ColorLogicOpEnabled;
1294 case GL_MAP1_COLOR_4:
1295 if (ctx->API != API_OPENGL_COMPAT)
1296 goto invalid_enum_error;
1297 return ctx->Eval.Map1Color4;
1298 case GL_MAP1_INDEX:
1299 if (ctx->API != API_OPENGL_COMPAT)
1300 goto invalid_enum_error;
1301 return ctx->Eval.Map1Index;
1302 case GL_MAP1_NORMAL:
1303 if (ctx->API != API_OPENGL_COMPAT)
1304 goto invalid_enum_error;
1305 return ctx->Eval.Map1Normal;
1306 case GL_MAP1_TEXTURE_COORD_1:
1307 if (ctx->API != API_OPENGL_COMPAT)
1308 goto invalid_enum_error;
1309 return ctx->Eval.Map1TextureCoord1;
1310 case GL_MAP1_TEXTURE_COORD_2:
1311 if (ctx->API != API_OPENGL_COMPAT)
1312 goto invalid_enum_error;
1313 return ctx->Eval.Map1TextureCoord2;
1314 case GL_MAP1_TEXTURE_COORD_3:
1315 if (ctx->API != API_OPENGL_COMPAT)
1316 goto invalid_enum_error;
1317 return ctx->Eval.Map1TextureCoord3;
1318 case GL_MAP1_TEXTURE_COORD_4:
1319 if (ctx->API != API_OPENGL_COMPAT)
1320 goto invalid_enum_error;
1321 return ctx->Eval.Map1TextureCoord4;
1322 case GL_MAP1_VERTEX_3:
1323 if (ctx->API != API_OPENGL_COMPAT)
1324 goto invalid_enum_error;
1325 return ctx->Eval.Map1Vertex3;
1326 case GL_MAP1_VERTEX_4:
1327 if (ctx->API != API_OPENGL_COMPAT)
1328 goto invalid_enum_error;
1329 return ctx->Eval.Map1Vertex4;
1330 case GL_MAP2_COLOR_4:
1331 if (ctx->API != API_OPENGL_COMPAT)
1332 goto invalid_enum_error;
1333 return ctx->Eval.Map2Color4;
1334 case GL_MAP2_INDEX:
1335 if (ctx->API != API_OPENGL_COMPAT)
1336 goto invalid_enum_error;
1337 return ctx->Eval.Map2Index;
1338 case GL_MAP2_NORMAL:
1339 if (ctx->API != API_OPENGL_COMPAT)
1340 goto invalid_enum_error;
1341 return ctx->Eval.Map2Normal;
1342 case GL_MAP2_TEXTURE_COORD_1:
1343 if (ctx->API != API_OPENGL_COMPAT)
1344 goto invalid_enum_error;
1345 return ctx->Eval.Map2TextureCoord1;
1346 case GL_MAP2_TEXTURE_COORD_2:
1347 if (ctx->API != API_OPENGL_COMPAT)
1348 goto invalid_enum_error;
1349 return ctx->Eval.Map2TextureCoord2;
1350 case GL_MAP2_TEXTURE_COORD_3:
1351 if (ctx->API != API_OPENGL_COMPAT)
1352 goto invalid_enum_error;
1353 return ctx->Eval.Map2TextureCoord3;
1354 case GL_MAP2_TEXTURE_COORD_4:
1355 if (ctx->API != API_OPENGL_COMPAT)
1356 goto invalid_enum_error;
1357 return ctx->Eval.Map2TextureCoord4;
1358 case GL_MAP2_VERTEX_3:
1359 if (ctx->API != API_OPENGL_COMPAT)
1360 goto invalid_enum_error;
1361 return ctx->Eval.Map2Vertex3;
1362 case GL_MAP2_VERTEX_4:
1363 if (ctx->API != API_OPENGL_COMPAT)
1364 goto invalid_enum_error;
1365 return ctx->Eval.Map2Vertex4;
1366 case GL_NORMALIZE:
1367 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1368 goto invalid_enum_error;
1369 return ctx->Transform.Normalize;
1370 case GL_POINT_SMOOTH:
1371 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1372 goto invalid_enum_error;
1373 return ctx->Point.SmoothFlag;
1374 case GL_POLYGON_SMOOTH:
1375 if (!_mesa_is_desktop_gl(ctx))
1376 goto invalid_enum_error;
1377 return ctx->Polygon.SmoothFlag;
1378 case GL_POLYGON_STIPPLE:
1379 if (ctx->API != API_OPENGL_COMPAT)
1380 goto invalid_enum_error;
1381 return ctx->Polygon.StippleFlag;
1382 case GL_POLYGON_OFFSET_POINT:
1383 if (!_mesa_is_desktop_gl(ctx))
1384 goto invalid_enum_error;
1385 return ctx->Polygon.OffsetPoint;
1386 case GL_POLYGON_OFFSET_LINE:
1387 if (!_mesa_is_desktop_gl(ctx))
1388 goto invalid_enum_error;
1389 return ctx->Polygon.OffsetLine;
1390 case GL_POLYGON_OFFSET_FILL:
1391 return ctx->Polygon.OffsetFill;
1392 case GL_RESCALE_NORMAL_EXT:
1393 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1394 goto invalid_enum_error;
1395 return ctx->Transform.RescaleNormals;
1396 case GL_SCISSOR_TEST:
1397 return ctx->Scissor.EnableFlags & 1; /* return state for index 0 */
1398 case GL_STENCIL_TEST:
1399 return ctx->Stencil.Enabled;
1400 case GL_TEXTURE_1D:
1401 if (ctx->API != API_OPENGL_COMPAT)
1402 goto invalid_enum_error;
1403 return is_texture_enabled(ctx, TEXTURE_1D_BIT);
1404 case GL_TEXTURE_2D:
1405 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1406 goto invalid_enum_error;
1407 return is_texture_enabled(ctx, TEXTURE_2D_BIT);
1408 case GL_TEXTURE_3D:
1409 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1410 goto invalid_enum_error;
1411 return is_texture_enabled(ctx, TEXTURE_3D_BIT);
1412 case GL_TEXTURE_GEN_S:
1413 case GL_TEXTURE_GEN_T:
1414 case GL_TEXTURE_GEN_R:
1415 case GL_TEXTURE_GEN_Q:
1416 {
1417 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1418
1419 if (ctx->API != API_OPENGL_COMPAT)
1420 goto invalid_enum_error;
1421
1422 if (texUnit) {
1423 GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
1424 return (texUnit->TexGenEnabled & coordBit) ? GL_TRUE : GL_FALSE;
1425 }
1426 }
1427 return GL_FALSE;
1428 case GL_TEXTURE_GEN_STR_OES:
1429 {
1430 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1431
1432 if (ctx->API != API_OPENGLES)
1433 goto invalid_enum_error;
1434
1435 if (texUnit) {
1436 return (texUnit->TexGenEnabled & STR_BITS) == STR_BITS
1437 ? GL_TRUE : GL_FALSE;
1438 }
1439 }
1440
1441 /* client-side state */
1442 case GL_VERTEX_ARRAY:
1443 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1444 goto invalid_enum_error;
1445 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POS].Enabled;
1446 case GL_NORMAL_ARRAY:
1447 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1448 goto invalid_enum_error;
1449 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled;
1450 case GL_COLOR_ARRAY:
1451 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1452 goto invalid_enum_error;
1453 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled;
1454 case GL_INDEX_ARRAY:
1455 if (ctx->API != API_OPENGL_COMPAT)
1456 goto invalid_enum_error;
1457 return ctx->Array.VAO->
1458 VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled;
1459 case GL_TEXTURE_COORD_ARRAY:
1460 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1461 goto invalid_enum_error;
1462 return ctx->Array.VAO->
1463 VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Enabled;
1464 case GL_EDGE_FLAG_ARRAY:
1465 if (ctx->API != API_OPENGL_COMPAT)
1466 goto invalid_enum_error;
1467 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled;
1468 case GL_FOG_COORDINATE_ARRAY_EXT:
1469 if (ctx->API != API_OPENGL_COMPAT)
1470 goto invalid_enum_error;
1471 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_FOG].Enabled;
1472 case GL_SECONDARY_COLOR_ARRAY_EXT:
1473 if (ctx->API != API_OPENGL_COMPAT)
1474 goto invalid_enum_error;
1475 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled;
1476 case GL_POINT_SIZE_ARRAY_OES:
1477 if (ctx->API != API_OPENGLES)
1478 goto invalid_enum_error;
1479 return ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled;
1480
1481 /* GL_ARB_texture_cube_map */
1482 case GL_TEXTURE_CUBE_MAP:
1483 CHECK_EXTENSION(ARB_texture_cube_map);
1484 return is_texture_enabled(ctx, TEXTURE_CUBE_BIT);
1485
1486 /* GL_EXT_secondary_color */
1487 case GL_COLOR_SUM_EXT:
1488 if (ctx->API != API_OPENGL_COMPAT)
1489 goto invalid_enum_error;
1490 return ctx->Fog.ColorSumEnabled;
1491
1492 /* GL_ARB_multisample */
1493 case GL_MULTISAMPLE_ARB:
1494 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1495 goto invalid_enum_error;
1496 return ctx->Multisample.Enabled;
1497 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
1498 return ctx->Multisample.SampleAlphaToCoverage;
1499 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
1500 if (!_mesa_is_desktop_gl(ctx) && ctx->API != API_OPENGLES)
1501 goto invalid_enum_error;
1502 return ctx->Multisample.SampleAlphaToOne;
1503 case GL_SAMPLE_COVERAGE_ARB:
1504 return ctx->Multisample.SampleCoverage;
1505 case GL_SAMPLE_COVERAGE_INVERT_ARB:
1506 if (!_mesa_is_desktop_gl(ctx))
1507 goto invalid_enum_error;
1508 return ctx->Multisample.SampleCoverageInvert;
1509
1510 /* GL_IBM_rasterpos_clip */
1511 case GL_RASTER_POSITION_UNCLIPPED_IBM:
1512 if (ctx->API != API_OPENGL_COMPAT)
1513 goto invalid_enum_error;
1514 return ctx->Transform.RasterPositionUnclipped;
1515
1516 /* GL_NV_point_sprite */
1517 case GL_POINT_SPRITE_NV:
1518 if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
1519 goto invalid_enum_error;
1520 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite)
1521 return ctx->Point.PointSprite;
1522
1523 case GL_VERTEX_PROGRAM_ARB:
1524 if (ctx->API != API_OPENGL_COMPAT)
1525 goto invalid_enum_error;
1526 CHECK_EXTENSION(ARB_vertex_program);
1527 return ctx->VertexProgram.Enabled;
1528 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
1529 /* This was added with ARB_vertex_program, but it is also used with
1530 * GLSL vertex shaders on desktop.
1531 */
1532 if (!_mesa_is_desktop_gl(ctx))
1533 goto invalid_enum_error;
1534 CHECK_EXTENSION(ARB_vertex_program);
1535 return ctx->VertexProgram.PointSizeEnabled;
1536 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
1537 if (ctx->API != API_OPENGL_COMPAT)
1538 goto invalid_enum_error;
1539 CHECK_EXTENSION(ARB_vertex_program);
1540 return ctx->VertexProgram.TwoSideEnabled;
1541
1542 /* GL_NV_texture_rectangle */
1543 case GL_TEXTURE_RECTANGLE_NV:
1544 if (ctx->API != API_OPENGL_COMPAT)
1545 goto invalid_enum_error;
1546 CHECK_EXTENSION(NV_texture_rectangle);
1547 return is_texture_enabled(ctx, TEXTURE_RECT_BIT);
1548
1549 /* GL_EXT_stencil_two_side */
1550 case GL_STENCIL_TEST_TWO_SIDE_EXT:
1551 if (ctx->API != API_OPENGL_COMPAT)
1552 goto invalid_enum_error;
1553 CHECK_EXTENSION(EXT_stencil_two_side);
1554 return ctx->Stencil.TestTwoSide;
1555
1556 case GL_FRAGMENT_PROGRAM_ARB:
1557 if (ctx->API != API_OPENGL_COMPAT)
1558 goto invalid_enum_error;
1559 return ctx->FragmentProgram.Enabled;
1560
1561 /* GL_EXT_depth_bounds_test */
1562 case GL_DEPTH_BOUNDS_TEST_EXT:
1563 if (!_mesa_is_desktop_gl(ctx))
1564 goto invalid_enum_error;
1565 CHECK_EXTENSION(EXT_depth_bounds_test);
1566 return ctx->Depth.BoundsTest;
1567
1568 /* GL_ARB_depth_clamp */
1569 case GL_DEPTH_CLAMP:
1570 if (!_mesa_is_desktop_gl(ctx))
1571 goto invalid_enum_error;
1572 CHECK_EXTENSION(ARB_depth_clamp);
1573 return ctx->Transform.DepthClamp;
1574
1575 case GL_FRAGMENT_SHADER_ATI:
1576 if (ctx->API != API_OPENGL_COMPAT)
1577 goto invalid_enum_error;
1578 CHECK_EXTENSION(ATI_fragment_shader);
1579 return ctx->ATIFragmentShader.Enabled;
1580
1581 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1582 if (!_mesa_is_desktop_gl(ctx))
1583 goto invalid_enum_error;
1584 CHECK_EXTENSION(ARB_seamless_cube_map);
1585 return ctx->Texture.CubeMapSeamless;
1586
1587 case GL_RASTERIZER_DISCARD:
1588 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1589 goto invalid_enum_error;
1590 CHECK_EXTENSION(EXT_transform_feedback);
1591 return ctx->RasterDiscard;
1592
1593 /* GL_NV_primitive_restart */
1594 case GL_PRIMITIVE_RESTART_NV:
1595 if (ctx->API != API_OPENGL_COMPAT || !ctx->Extensions.NV_primitive_restart) {
1596 goto invalid_enum_error;
1597 }
1598 return ctx->Array.PrimitiveRestart;
1599
1600 /* GL 3.1 primitive restart */
1601 case GL_PRIMITIVE_RESTART:
1602 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 31) {
1603 goto invalid_enum_error;
1604 }
1605 return ctx->Array.PrimitiveRestart;
1606
1607 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
1608 if (!_mesa_is_gles3(ctx) && !ctx->Extensions.ARB_ES3_compatibility) {
1609 goto invalid_enum_error;
1610 }
1611 return ctx->Array.PrimitiveRestartFixedIndex;
1612
1613 /* GL3.0 - GL_framebuffer_sRGB */
1614 case GL_FRAMEBUFFER_SRGB_EXT:
1615 if (!_mesa_is_desktop_gl(ctx))
1616 goto invalid_enum_error;
1617 CHECK_EXTENSION(EXT_framebuffer_sRGB);
1618 return ctx->Color.sRGBEnabled;
1619
1620 /* GL_OES_EGL_image_external */
1621 case GL_TEXTURE_EXTERNAL_OES:
1622 if (!_mesa_is_gles(ctx))
1623 goto invalid_enum_error;
1624 CHECK_EXTENSION(OES_EGL_image_external);
1625 return is_texture_enabled(ctx, TEXTURE_EXTERNAL_BIT);
1626
1627 /* ARB_texture_multisample */
1628 case GL_SAMPLE_MASK:
1629 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
1630 goto invalid_enum_error;
1631 CHECK_EXTENSION(ARB_texture_multisample);
1632 return ctx->Multisample.SampleMask;
1633
1634 /* ARB_sample_shading */
1635 case GL_SAMPLE_SHADING:
1636 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
1637 goto invalid_enum_error;
1638 CHECK_EXTENSION(ARB_sample_shading);
1639 return ctx->Multisample.SampleShading;
1640
1641 case GL_BLEND_ADVANCED_COHERENT_KHR:
1642 CHECK_EXTENSION(KHR_blend_equation_advanced_coherent);
1643 return ctx->Color.BlendCoherent;
1644
1645 case GL_CONSERVATIVE_RASTERIZATION_INTEL:
1646 CHECK_EXTENSION(INTEL_conservative_rasterization);
1647 return ctx->IntelConservativeRasterization;
1648
1649 default:
1650 goto invalid_enum_error;
1651 }
1652
1653 return GL_FALSE;
1654
1655 invalid_enum_error:
1656 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(%s)",
1657 _mesa_enum_to_string(cap));
1658 return GL_FALSE;
1659 }