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