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