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