r300c: Unbreak after R4xx support was added to r300/compiler.
[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->NoDither) {
356 state = GL_FALSE; /* MESA_NO_DITHER env var */
357 }
358 if (ctx->Color.DitherFlag == state)
359 return;
360 FLUSH_VERTICES(ctx, _NEW_COLOR);
361 ctx->Color.DitherFlag = state;
362 break;
363 case GL_FOG:
364 if (ctx->Fog.Enabled == state)
365 return;
366 FLUSH_VERTICES(ctx, _NEW_FOG);
367 ctx->Fog.Enabled = state;
368 break;
369 case GL_LIGHT0:
370 case GL_LIGHT1:
371 case GL_LIGHT2:
372 case GL_LIGHT3:
373 case GL_LIGHT4:
374 case GL_LIGHT5:
375 case GL_LIGHT6:
376 case GL_LIGHT7:
377 if (ctx->Light.Light[cap-GL_LIGHT0].Enabled == state)
378 return;
379 FLUSH_VERTICES(ctx, _NEW_LIGHT);
380 ctx->Light.Light[cap-GL_LIGHT0].Enabled = state;
381 if (state) {
382 insert_at_tail(&ctx->Light.EnabledList,
383 &ctx->Light.Light[cap-GL_LIGHT0]);
384 }
385 else {
386 remove_from_list(&ctx->Light.Light[cap-GL_LIGHT0]);
387 }
388 break;
389 case GL_LIGHTING:
390 if (ctx->Light.Enabled == state)
391 return;
392 FLUSH_VERTICES(ctx, _NEW_LIGHT);
393 ctx->Light.Enabled = state;
394 if (ctx->Light.Enabled && ctx->Light.Model.TwoSide)
395 ctx->_TriangleCaps |= DD_TRI_LIGHT_TWOSIDE;
396 else
397 ctx->_TriangleCaps &= ~DD_TRI_LIGHT_TWOSIDE;
398 break;
399 case GL_LINE_SMOOTH:
400 if (ctx->Line.SmoothFlag == state)
401 return;
402 FLUSH_VERTICES(ctx, _NEW_LINE);
403 ctx->Line.SmoothFlag = state;
404 ctx->_TriangleCaps ^= DD_LINE_SMOOTH;
405 break;
406 case GL_LINE_STIPPLE:
407 if (ctx->Line.StippleFlag == state)
408 return;
409 FLUSH_VERTICES(ctx, _NEW_LINE);
410 ctx->Line.StippleFlag = state;
411 ctx->_TriangleCaps ^= DD_LINE_STIPPLE;
412 break;
413 case GL_INDEX_LOGIC_OP:
414 if (ctx->Color.IndexLogicOpEnabled == state)
415 return;
416 FLUSH_VERTICES(ctx, _NEW_COLOR);
417 ctx->Color.IndexLogicOpEnabled = state;
418 break;
419 case GL_COLOR_LOGIC_OP:
420 if (ctx->Color.ColorLogicOpEnabled == state)
421 return;
422 FLUSH_VERTICES(ctx, _NEW_COLOR);
423 ctx->Color.ColorLogicOpEnabled = state;
424 break;
425 case GL_MAP1_COLOR_4:
426 if (ctx->Eval.Map1Color4 == state)
427 return;
428 FLUSH_VERTICES(ctx, _NEW_EVAL);
429 ctx->Eval.Map1Color4 = state;
430 break;
431 case GL_MAP1_INDEX:
432 if (ctx->Eval.Map1Index == state)
433 return;
434 FLUSH_VERTICES(ctx, _NEW_EVAL);
435 ctx->Eval.Map1Index = state;
436 break;
437 case GL_MAP1_NORMAL:
438 if (ctx->Eval.Map1Normal == state)
439 return;
440 FLUSH_VERTICES(ctx, _NEW_EVAL);
441 ctx->Eval.Map1Normal = state;
442 break;
443 case GL_MAP1_TEXTURE_COORD_1:
444 if (ctx->Eval.Map1TextureCoord1 == state)
445 return;
446 FLUSH_VERTICES(ctx, _NEW_EVAL);
447 ctx->Eval.Map1TextureCoord1 = state;
448 break;
449 case GL_MAP1_TEXTURE_COORD_2:
450 if (ctx->Eval.Map1TextureCoord2 == state)
451 return;
452 FLUSH_VERTICES(ctx, _NEW_EVAL);
453 ctx->Eval.Map1TextureCoord2 = state;
454 break;
455 case GL_MAP1_TEXTURE_COORD_3:
456 if (ctx->Eval.Map1TextureCoord3 == state)
457 return;
458 FLUSH_VERTICES(ctx, _NEW_EVAL);
459 ctx->Eval.Map1TextureCoord3 = state;
460 break;
461 case GL_MAP1_TEXTURE_COORD_4:
462 if (ctx->Eval.Map1TextureCoord4 == state)
463 return;
464 FLUSH_VERTICES(ctx, _NEW_EVAL);
465 ctx->Eval.Map1TextureCoord4 = state;
466 break;
467 case GL_MAP1_VERTEX_3:
468 if (ctx->Eval.Map1Vertex3 == state)
469 return;
470 FLUSH_VERTICES(ctx, _NEW_EVAL);
471 ctx->Eval.Map1Vertex3 = state;
472 break;
473 case GL_MAP1_VERTEX_4:
474 if (ctx->Eval.Map1Vertex4 == state)
475 return;
476 FLUSH_VERTICES(ctx, _NEW_EVAL);
477 ctx->Eval.Map1Vertex4 = state;
478 break;
479 case GL_MAP2_COLOR_4:
480 if (ctx->Eval.Map2Color4 == state)
481 return;
482 FLUSH_VERTICES(ctx, _NEW_EVAL);
483 ctx->Eval.Map2Color4 = state;
484 break;
485 case GL_MAP2_INDEX:
486 if (ctx->Eval.Map2Index == state)
487 return;
488 FLUSH_VERTICES(ctx, _NEW_EVAL);
489 ctx->Eval.Map2Index = state;
490 break;
491 case GL_MAP2_NORMAL:
492 if (ctx->Eval.Map2Normal == state)
493 return;
494 FLUSH_VERTICES(ctx, _NEW_EVAL);
495 ctx->Eval.Map2Normal = state;
496 break;
497 case GL_MAP2_TEXTURE_COORD_1:
498 if (ctx->Eval.Map2TextureCoord1 == state)
499 return;
500 FLUSH_VERTICES(ctx, _NEW_EVAL);
501 ctx->Eval.Map2TextureCoord1 = state;
502 break;
503 case GL_MAP2_TEXTURE_COORD_2:
504 if (ctx->Eval.Map2TextureCoord2 == state)
505 return;
506 FLUSH_VERTICES(ctx, _NEW_EVAL);
507 ctx->Eval.Map2TextureCoord2 = state;
508 break;
509 case GL_MAP2_TEXTURE_COORD_3:
510 if (ctx->Eval.Map2TextureCoord3 == state)
511 return;
512 FLUSH_VERTICES(ctx, _NEW_EVAL);
513 ctx->Eval.Map2TextureCoord3 = state;
514 break;
515 case GL_MAP2_TEXTURE_COORD_4:
516 if (ctx->Eval.Map2TextureCoord4 == state)
517 return;
518 FLUSH_VERTICES(ctx, _NEW_EVAL);
519 ctx->Eval.Map2TextureCoord4 = state;
520 break;
521 case GL_MAP2_VERTEX_3:
522 if (ctx->Eval.Map2Vertex3 == state)
523 return;
524 FLUSH_VERTICES(ctx, _NEW_EVAL);
525 ctx->Eval.Map2Vertex3 = state;
526 break;
527 case GL_MAP2_VERTEX_4:
528 if (ctx->Eval.Map2Vertex4 == state)
529 return;
530 FLUSH_VERTICES(ctx, _NEW_EVAL);
531 ctx->Eval.Map2Vertex4 = state;
532 break;
533 case GL_NORMALIZE:
534 if (ctx->Transform.Normalize == state)
535 return;
536 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
537 ctx->Transform.Normalize = state;
538 break;
539 case GL_POINT_SMOOTH:
540 if (ctx->Point.SmoothFlag == state)
541 return;
542 FLUSH_VERTICES(ctx, _NEW_POINT);
543 ctx->Point.SmoothFlag = state;
544 ctx->_TriangleCaps ^= DD_POINT_SMOOTH;
545 break;
546 case GL_POLYGON_SMOOTH:
547 if (ctx->Polygon.SmoothFlag == state)
548 return;
549 FLUSH_VERTICES(ctx, _NEW_POLYGON);
550 ctx->Polygon.SmoothFlag = state;
551 ctx->_TriangleCaps ^= DD_TRI_SMOOTH;
552 break;
553 case GL_POLYGON_STIPPLE:
554 if (ctx->Polygon.StippleFlag == state)
555 return;
556 FLUSH_VERTICES(ctx, _NEW_POLYGON);
557 ctx->Polygon.StippleFlag = state;
558 ctx->_TriangleCaps ^= DD_TRI_STIPPLE;
559 break;
560 case GL_POLYGON_OFFSET_POINT:
561 if (ctx->Polygon.OffsetPoint == state)
562 return;
563 FLUSH_VERTICES(ctx, _NEW_POLYGON);
564 ctx->Polygon.OffsetPoint = state;
565 break;
566 case GL_POLYGON_OFFSET_LINE:
567 if (ctx->Polygon.OffsetLine == state)
568 return;
569 FLUSH_VERTICES(ctx, _NEW_POLYGON);
570 ctx->Polygon.OffsetLine = state;
571 break;
572 case GL_POLYGON_OFFSET_FILL:
573 /*case GL_POLYGON_OFFSET_EXT:*/
574 if (ctx->Polygon.OffsetFill == state)
575 return;
576 FLUSH_VERTICES(ctx, _NEW_POLYGON);
577 ctx->Polygon.OffsetFill = state;
578 break;
579 case GL_RESCALE_NORMAL_EXT:
580 if (ctx->Transform.RescaleNormals == state)
581 return;
582 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
583 ctx->Transform.RescaleNormals = state;
584 break;
585 case GL_SCISSOR_TEST:
586 if (ctx->Scissor.Enabled == state)
587 return;
588 FLUSH_VERTICES(ctx, _NEW_SCISSOR);
589 ctx->Scissor.Enabled = state;
590 break;
591 case GL_SHARED_TEXTURE_PALETTE_EXT:
592 if (ctx->Texture.SharedPalette == state)
593 return;
594 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
595 ctx->Texture.SharedPalette = state;
596 break;
597 case GL_STENCIL_TEST:
598 if (ctx->Stencil.Enabled == state)
599 return;
600 FLUSH_VERTICES(ctx, _NEW_STENCIL);
601 ctx->Stencil.Enabled = state;
602 break;
603 case GL_TEXTURE_1D:
604 if (!enable_texture(ctx, state, TEXTURE_1D_BIT)) {
605 return;
606 }
607 break;
608 case GL_TEXTURE_2D:
609 if (!enable_texture(ctx, state, TEXTURE_2D_BIT)) {
610 return;
611 }
612 break;
613 case GL_TEXTURE_3D:
614 if (!enable_texture(ctx, state, TEXTURE_3D_BIT)) {
615 return;
616 }
617 break;
618 case GL_TEXTURE_GEN_Q:
619 {
620 struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
621 if (texUnit) {
622 GLuint newenabled = texUnit->TexGenEnabled & ~Q_BIT;
623 if (state)
624 newenabled |= Q_BIT;
625 if (texUnit->TexGenEnabled == newenabled)
626 return;
627 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
628 texUnit->TexGenEnabled = newenabled;
629 }
630 }
631 break;
632 case GL_TEXTURE_GEN_R:
633 {
634 struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
635 if (texUnit) {
636 GLuint newenabled = texUnit->TexGenEnabled & ~R_BIT;
637 if (state)
638 newenabled |= R_BIT;
639 if (texUnit->TexGenEnabled == newenabled)
640 return;
641 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
642 texUnit->TexGenEnabled = newenabled;
643 }
644 }
645 break;
646 case GL_TEXTURE_GEN_S:
647 {
648 struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
649 if (texUnit) {
650 GLuint newenabled = texUnit->TexGenEnabled & ~S_BIT;
651 if (state)
652 newenabled |= S_BIT;
653 if (texUnit->TexGenEnabled == newenabled)
654 return;
655 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
656 texUnit->TexGenEnabled = newenabled;
657 }
658 }
659 break;
660 case GL_TEXTURE_GEN_T:
661 {
662 struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
663 if (texUnit) {
664 GLuint newenabled = texUnit->TexGenEnabled & ~T_BIT;
665 if (state)
666 newenabled |= T_BIT;
667 if (texUnit->TexGenEnabled == newenabled)
668 return;
669 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
670 texUnit->TexGenEnabled = newenabled;
671 }
672 }
673 break;
674
675 #if FEATURE_ES1
676 case GL_TEXTURE_GEN_STR_OES:
677 /* disable S, T, and R at the same time */
678 {
679 struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
680 if (texUnit) {
681 GLuint newenabled =
682 texUnit->TexGenEnabled & ~STR_BITS;
683 if (state)
684 newenabled |= STR_BITS;
685 if (texUnit->TexGenEnabled == newenabled)
686 return;
687 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
688 texUnit->TexGenEnabled = newenabled;
689 }
690 }
691 break;
692 #endif
693
694 /*
695 * CLIENT STATE!!!
696 */
697 case GL_VERTEX_ARRAY:
698 case GL_NORMAL_ARRAY:
699 case GL_COLOR_ARRAY:
700 case GL_INDEX_ARRAY:
701 case GL_TEXTURE_COORD_ARRAY:
702 case GL_EDGE_FLAG_ARRAY:
703 case GL_FOG_COORDINATE_ARRAY_EXT:
704 case GL_SECONDARY_COLOR_ARRAY_EXT:
705 case GL_POINT_SIZE_ARRAY_OES:
706 client_state( ctx, cap, state );
707 return;
708
709 /* GL_SGI_texture_color_table */
710 case GL_TEXTURE_COLOR_TABLE_SGI:
711 CHECK_EXTENSION(SGI_texture_color_table, cap);
712 if (ctx->Texture.Unit[ctx->Texture.CurrentUnit].ColorTableEnabled == state)
713 return;
714 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
715 ctx->Texture.Unit[ctx->Texture.CurrentUnit].ColorTableEnabled = state;
716 break;
717
718 /* GL_ARB_texture_cube_map */
719 case GL_TEXTURE_CUBE_MAP_ARB:
720 CHECK_EXTENSION(ARB_texture_cube_map, cap);
721 if (!enable_texture(ctx, state, TEXTURE_CUBE_BIT)) {
722 return;
723 }
724 break;
725
726 /* GL_EXT_secondary_color */
727 case GL_COLOR_SUM_EXT:
728 CHECK_EXTENSION2(EXT_secondary_color, ARB_vertex_program, cap);
729 if (ctx->Fog.ColorSumEnabled == state)
730 return;
731 FLUSH_VERTICES(ctx, _NEW_FOG);
732 ctx->Fog.ColorSumEnabled = state;
733 break;
734
735 /* GL_ARB_multisample */
736 case GL_MULTISAMPLE_ARB:
737 if (ctx->Multisample.Enabled == state)
738 return;
739 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
740 ctx->Multisample.Enabled = state;
741 break;
742 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
743 if (ctx->Multisample.SampleAlphaToCoverage == state)
744 return;
745 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
746 ctx->Multisample.SampleAlphaToCoverage = state;
747 break;
748 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
749 if (ctx->Multisample.SampleAlphaToOne == state)
750 return;
751 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
752 ctx->Multisample.SampleAlphaToOne = state;
753 break;
754 case GL_SAMPLE_COVERAGE_ARB:
755 if (ctx->Multisample.SampleCoverage == state)
756 return;
757 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
758 ctx->Multisample.SampleCoverage = state;
759 break;
760 case GL_SAMPLE_COVERAGE_INVERT_ARB:
761 if (ctx->Multisample.SampleCoverageInvert == state)
762 return;
763 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
764 ctx->Multisample.SampleCoverageInvert = state;
765 break;
766
767 /* GL_IBM_rasterpos_clip */
768 case GL_RASTER_POSITION_UNCLIPPED_IBM:
769 CHECK_EXTENSION(IBM_rasterpos_clip, cap);
770 if (ctx->Transform.RasterPositionUnclipped == state)
771 return;
772 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
773 ctx->Transform.RasterPositionUnclipped = state;
774 break;
775
776 /* GL_NV_point_sprite */
777 case GL_POINT_SPRITE_NV:
778 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite, cap);
779 if (ctx->Point.PointSprite == state)
780 return;
781 FLUSH_VERTICES(ctx, _NEW_POINT);
782 ctx->Point.PointSprite = state;
783 break;
784
785 #if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program
786 case GL_VERTEX_PROGRAM_ARB:
787 CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program, cap);
788 if (ctx->VertexProgram.Enabled == state)
789 return;
790 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
791 ctx->VertexProgram.Enabled = state;
792 break;
793 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
794 CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program, cap);
795 if (ctx->VertexProgram.PointSizeEnabled == state)
796 return;
797 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
798 ctx->VertexProgram.PointSizeEnabled = state;
799 break;
800 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
801 CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program, cap);
802 if (ctx->VertexProgram.TwoSideEnabled == state)
803 return;
804 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
805 ctx->VertexProgram.TwoSideEnabled = state;
806 break;
807 #endif
808 #if FEATURE_NV_vertex_program
809 case GL_MAP1_VERTEX_ATTRIB0_4_NV:
810 case GL_MAP1_VERTEX_ATTRIB1_4_NV:
811 case GL_MAP1_VERTEX_ATTRIB2_4_NV:
812 case GL_MAP1_VERTEX_ATTRIB3_4_NV:
813 case GL_MAP1_VERTEX_ATTRIB4_4_NV:
814 case GL_MAP1_VERTEX_ATTRIB5_4_NV:
815 case GL_MAP1_VERTEX_ATTRIB6_4_NV:
816 case GL_MAP1_VERTEX_ATTRIB7_4_NV:
817 case GL_MAP1_VERTEX_ATTRIB8_4_NV:
818 case GL_MAP1_VERTEX_ATTRIB9_4_NV:
819 case GL_MAP1_VERTEX_ATTRIB10_4_NV:
820 case GL_MAP1_VERTEX_ATTRIB11_4_NV:
821 case GL_MAP1_VERTEX_ATTRIB12_4_NV:
822 case GL_MAP1_VERTEX_ATTRIB13_4_NV:
823 case GL_MAP1_VERTEX_ATTRIB14_4_NV:
824 case GL_MAP1_VERTEX_ATTRIB15_4_NV:
825 CHECK_EXTENSION(NV_vertex_program, cap);
826 {
827 const GLuint map = (GLuint) (cap - GL_MAP1_VERTEX_ATTRIB0_4_NV);
828 FLUSH_VERTICES(ctx, _NEW_EVAL);
829 ctx->Eval.Map1Attrib[map] = state;
830 }
831 break;
832 case GL_MAP2_VERTEX_ATTRIB0_4_NV:
833 case GL_MAP2_VERTEX_ATTRIB1_4_NV:
834 case GL_MAP2_VERTEX_ATTRIB2_4_NV:
835 case GL_MAP2_VERTEX_ATTRIB3_4_NV:
836 case GL_MAP2_VERTEX_ATTRIB4_4_NV:
837 case GL_MAP2_VERTEX_ATTRIB5_4_NV:
838 case GL_MAP2_VERTEX_ATTRIB6_4_NV:
839 case GL_MAP2_VERTEX_ATTRIB7_4_NV:
840 case GL_MAP2_VERTEX_ATTRIB8_4_NV:
841 case GL_MAP2_VERTEX_ATTRIB9_4_NV:
842 case GL_MAP2_VERTEX_ATTRIB10_4_NV:
843 case GL_MAP2_VERTEX_ATTRIB11_4_NV:
844 case GL_MAP2_VERTEX_ATTRIB12_4_NV:
845 case GL_MAP2_VERTEX_ATTRIB13_4_NV:
846 case GL_MAP2_VERTEX_ATTRIB14_4_NV:
847 case GL_MAP2_VERTEX_ATTRIB15_4_NV:
848 CHECK_EXTENSION(NV_vertex_program, cap);
849 {
850 const GLuint map = (GLuint) (cap - GL_MAP2_VERTEX_ATTRIB0_4_NV);
851 FLUSH_VERTICES(ctx, _NEW_EVAL);
852 ctx->Eval.Map2Attrib[map] = state;
853 }
854 break;
855 #endif /* FEATURE_NV_vertex_program */
856
857 #if FEATURE_NV_fragment_program
858 case GL_FRAGMENT_PROGRAM_NV:
859 CHECK_EXTENSION(NV_fragment_program, cap);
860 if (ctx->FragmentProgram.Enabled == state)
861 return;
862 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
863 ctx->FragmentProgram.Enabled = state;
864 break;
865 #endif /* FEATURE_NV_fragment_program */
866
867 /* GL_NV_texture_rectangle */
868 case GL_TEXTURE_RECTANGLE_NV:
869 CHECK_EXTENSION(NV_texture_rectangle, cap);
870 if (!enable_texture(ctx, state, TEXTURE_RECT_BIT)) {
871 return;
872 }
873 break;
874
875 /* GL_EXT_stencil_two_side */
876 case GL_STENCIL_TEST_TWO_SIDE_EXT:
877 CHECK_EXTENSION(EXT_stencil_two_side, cap);
878 if (ctx->Stencil.TestTwoSide == state)
879 return;
880 FLUSH_VERTICES(ctx, _NEW_STENCIL);
881 ctx->Stencil.TestTwoSide = state;
882 if (state) {
883 ctx->Stencil._BackFace = 2;
884 ctx->_TriangleCaps |= DD_TRI_TWOSTENCIL;
885 } else {
886 ctx->Stencil._BackFace = 1;
887 ctx->_TriangleCaps &= ~DD_TRI_TWOSTENCIL;
888 }
889 break;
890
891 #if FEATURE_ARB_fragment_program
892 case GL_FRAGMENT_PROGRAM_ARB:
893 CHECK_EXTENSION(ARB_fragment_program, cap);
894 if (ctx->FragmentProgram.Enabled == state)
895 return;
896 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
897 ctx->FragmentProgram.Enabled = state;
898 break;
899 #endif /* FEATURE_ARB_fragment_program */
900
901 /* GL_EXT_depth_bounds_test */
902 case GL_DEPTH_BOUNDS_TEST_EXT:
903 CHECK_EXTENSION(EXT_depth_bounds_test, cap);
904 if (ctx->Depth.BoundsTest == state)
905 return;
906 FLUSH_VERTICES(ctx, _NEW_DEPTH);
907 ctx->Depth.BoundsTest = state;
908 break;
909
910 case GL_DEPTH_CLAMP:
911 if (ctx->Transform.DepthClamp == state)
912 return;
913 CHECK_EXTENSION(ARB_depth_clamp, cap);
914 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
915 ctx->Transform.DepthClamp = state;
916 break;
917
918 #if FEATURE_ATI_fragment_shader
919 case GL_FRAGMENT_SHADER_ATI:
920 CHECK_EXTENSION(ATI_fragment_shader, cap);
921 if (ctx->ATIFragmentShader.Enabled == state)
922 return;
923 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
924 ctx->ATIFragmentShader.Enabled = state;
925 break;
926 #endif
927
928 /* GL_MESA_texture_array */
929 case GL_TEXTURE_1D_ARRAY_EXT:
930 CHECK_EXTENSION(MESA_texture_array, cap);
931 if (!enable_texture(ctx, state, TEXTURE_1D_ARRAY_BIT)) {
932 return;
933 }
934 break;
935
936 case GL_TEXTURE_2D_ARRAY_EXT:
937 CHECK_EXTENSION(MESA_texture_array, cap);
938 if (!enable_texture(ctx, state, TEXTURE_2D_ARRAY_BIT)) {
939 return;
940 }
941 break;
942
943 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
944 CHECK_EXTENSION(ARB_seamless_cube_map, cap);
945 ctx->Texture.CubeMapSeamless = state;
946 break;
947
948 #if FEATURE_EXT_transform_feedback
949 case GL_RASTERIZER_DISCARD:
950 CHECK_EXTENSION(EXT_transform_feedback, cap);
951 if (ctx->TransformFeedback.RasterDiscard != state) {
952 ctx->TransformFeedback.RasterDiscard = state;
953 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
954 }
955 break;
956 #endif
957
958 /* GL 3.1 primitive restart. Note: this enum is different from
959 * GL_PRIMITIVE_RESTART_NV (which is client state).
960 */
961 case GL_PRIMITIVE_RESTART:
962 if (ctx->VersionMajor * 10 + ctx->VersionMinor < 31) {
963 goto invalid_enum_error;
964 }
965 if (ctx->Array.PrimitiveRestart != state) {
966 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
967 ctx->Array.PrimitiveRestart = state;
968 }
969 break;
970
971 /* GL3.0 - GL_framebuffer_sRGB */
972 case GL_FRAMEBUFFER_SRGB_EXT:
973 CHECK_EXTENSION(EXT_framebuffer_sRGB, cap);
974 ctx->Color.sRGBEnabled = state;
975 break;
976
977 default:
978 goto invalid_enum_error;
979 }
980
981 if (ctx->Driver.Enable) {
982 ctx->Driver.Enable( ctx, cap, state );
983 }
984
985 return;
986
987 invalid_enum_error:
988 _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(0x%x)",
989 state ? "Enable" : "Disable", cap);
990 }
991
992
993 /**
994 * Enable GL capability. Called by glEnable()
995 * \param cap state to enable.
996 */
997 void GLAPIENTRY
998 _mesa_Enable( GLenum cap )
999 {
1000 GET_CURRENT_CONTEXT(ctx);
1001 ASSERT_OUTSIDE_BEGIN_END(ctx);
1002
1003 _mesa_set_enable( ctx, cap, GL_TRUE );
1004 }
1005
1006
1007 /**
1008 * Disable GL capability. Called by glDisable()
1009 * \param cap state to disable.
1010 */
1011 void GLAPIENTRY
1012 _mesa_Disable( GLenum cap )
1013 {
1014 GET_CURRENT_CONTEXT(ctx);
1015 ASSERT_OUTSIDE_BEGIN_END(ctx);
1016
1017 _mesa_set_enable( ctx, cap, GL_FALSE );
1018 }
1019
1020
1021
1022 /**
1023 * Enable/disable an indexed state var.
1024 */
1025 void
1026 _mesa_set_enablei(struct gl_context *ctx, GLenum cap, GLuint index, GLboolean state)
1027 {
1028 ASSERT(state == 0 || state == 1);
1029 switch (cap) {
1030 case GL_BLEND:
1031 if (!ctx->Extensions.EXT_draw_buffers2) {
1032 goto invalid_enum_error;
1033 }
1034 if (index >= ctx->Const.MaxDrawBuffers) {
1035 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1036 state ? "glEnableIndexed" : "glDisableIndexed", index);
1037 return;
1038 }
1039 if (((ctx->Color.BlendEnabled >> index) & 1) != state) {
1040 FLUSH_VERTICES(ctx, _NEW_COLOR);
1041 if (state)
1042 ctx->Color.BlendEnabled |= (1 << index);
1043 else
1044 ctx->Color.BlendEnabled &= ~(1 << index);
1045 }
1046 break;
1047 default:
1048 goto invalid_enum_error;
1049 }
1050 return;
1051
1052 invalid_enum_error:
1053 _mesa_error(ctx, GL_INVALID_ENUM, "%s(cap=%s)",
1054 state ? "glEnablei" : "glDisablei",
1055 _mesa_lookup_enum_by_nr(cap));
1056 }
1057
1058
1059 void GLAPIENTRY
1060 _mesa_DisableIndexed( GLenum cap, GLuint index )
1061 {
1062 GET_CURRENT_CONTEXT(ctx);
1063 ASSERT_OUTSIDE_BEGIN_END(ctx);
1064 _mesa_set_enablei(ctx, cap, index, GL_FALSE);
1065 }
1066
1067
1068 void GLAPIENTRY
1069 _mesa_EnableIndexed( GLenum cap, GLuint index )
1070 {
1071 GET_CURRENT_CONTEXT(ctx);
1072 ASSERT_OUTSIDE_BEGIN_END(ctx);
1073 _mesa_set_enablei(ctx, cap, index, GL_TRUE);
1074 }
1075
1076
1077 GLboolean GLAPIENTRY
1078 _mesa_IsEnabledIndexed( GLenum cap, GLuint index )
1079 {
1080 GET_CURRENT_CONTEXT(ctx);
1081 switch (cap) {
1082 case GL_BLEND:
1083 if (index >= ctx->Const.MaxDrawBuffers) {
1084 _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
1085 index);
1086 return GL_FALSE;
1087 }
1088 return (ctx->Color.BlendEnabled >> index) & 1;
1089 default:
1090 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabledIndexed(cap=%s)",
1091 _mesa_lookup_enum_by_nr(cap));
1092 return GL_FALSE;
1093 }
1094 }
1095
1096
1097
1098
1099 #undef CHECK_EXTENSION
1100 #define CHECK_EXTENSION(EXTNAME) \
1101 if (!ctx->Extensions.EXTNAME) { \
1102 goto invalid_enum_error; \
1103 }
1104
1105 #undef CHECK_EXTENSION2
1106 #define CHECK_EXTENSION2(EXT1, EXT2) \
1107 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1108 goto invalid_enum_error; \
1109 }
1110
1111
1112 /**
1113 * Helper function to determine whether a texture target is enabled.
1114 */
1115 static GLboolean
1116 is_texture_enabled(struct gl_context *ctx, GLbitfield bit)
1117 {
1118 const struct gl_texture_unit *const texUnit =
1119 &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1120 return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE;
1121 }
1122
1123
1124 /**
1125 * Return simple enable/disable state.
1126 *
1127 * \param cap state variable to query.
1128 *
1129 * Returns the state of the specified capability from the current GL context.
1130 * For the capabilities associated with extensions verifies that those
1131 * extensions are effectively present before reporting.
1132 */
1133 GLboolean GLAPIENTRY
1134 _mesa_IsEnabled( GLenum cap )
1135 {
1136 GET_CURRENT_CONTEXT(ctx);
1137 switch (cap) {
1138 case GL_ALPHA_TEST:
1139 return ctx->Color.AlphaEnabled;
1140 case GL_AUTO_NORMAL:
1141 return ctx->Eval.AutoNormal;
1142 case GL_BLEND:
1143 return ctx->Color.BlendEnabled & 1; /* return state for buffer[0] */
1144 case GL_CLIP_PLANE0:
1145 case GL_CLIP_PLANE1:
1146 case GL_CLIP_PLANE2:
1147 case GL_CLIP_PLANE3:
1148 case GL_CLIP_PLANE4:
1149 case GL_CLIP_PLANE5:
1150 return (ctx->Transform.ClipPlanesEnabled >> (cap - GL_CLIP_PLANE0)) & 1;
1151 case GL_COLOR_MATERIAL:
1152 return ctx->Light.ColorMaterialEnabled;
1153 case GL_CULL_FACE:
1154 return ctx->Polygon.CullFlag;
1155 case GL_DEPTH_TEST:
1156 return ctx->Depth.Test;
1157 case GL_DITHER:
1158 return ctx->Color.DitherFlag;
1159 case GL_FOG:
1160 return ctx->Fog.Enabled;
1161 case GL_LIGHTING:
1162 return ctx->Light.Enabled;
1163 case GL_LIGHT0:
1164 case GL_LIGHT1:
1165 case GL_LIGHT2:
1166 case GL_LIGHT3:
1167 case GL_LIGHT4:
1168 case GL_LIGHT5:
1169 case GL_LIGHT6:
1170 case GL_LIGHT7:
1171 return ctx->Light.Light[cap-GL_LIGHT0].Enabled;
1172 case GL_LINE_SMOOTH:
1173 return ctx->Line.SmoothFlag;
1174 case GL_LINE_STIPPLE:
1175 return ctx->Line.StippleFlag;
1176 case GL_INDEX_LOGIC_OP:
1177 return ctx->Color.IndexLogicOpEnabled;
1178 case GL_COLOR_LOGIC_OP:
1179 return ctx->Color.ColorLogicOpEnabled;
1180 case GL_MAP1_COLOR_4:
1181 return ctx->Eval.Map1Color4;
1182 case GL_MAP1_INDEX:
1183 return ctx->Eval.Map1Index;
1184 case GL_MAP1_NORMAL:
1185 return ctx->Eval.Map1Normal;
1186 case GL_MAP1_TEXTURE_COORD_1:
1187 return ctx->Eval.Map1TextureCoord1;
1188 case GL_MAP1_TEXTURE_COORD_2:
1189 return ctx->Eval.Map1TextureCoord2;
1190 case GL_MAP1_TEXTURE_COORD_3:
1191 return ctx->Eval.Map1TextureCoord3;
1192 case GL_MAP1_TEXTURE_COORD_4:
1193 return ctx->Eval.Map1TextureCoord4;
1194 case GL_MAP1_VERTEX_3:
1195 return ctx->Eval.Map1Vertex3;
1196 case GL_MAP1_VERTEX_4:
1197 return ctx->Eval.Map1Vertex4;
1198 case GL_MAP2_COLOR_4:
1199 return ctx->Eval.Map2Color4;
1200 case GL_MAP2_INDEX:
1201 return ctx->Eval.Map2Index;
1202 case GL_MAP2_NORMAL:
1203 return ctx->Eval.Map2Normal;
1204 case GL_MAP2_TEXTURE_COORD_1:
1205 return ctx->Eval.Map2TextureCoord1;
1206 case GL_MAP2_TEXTURE_COORD_2:
1207 return ctx->Eval.Map2TextureCoord2;
1208 case GL_MAP2_TEXTURE_COORD_3:
1209 return ctx->Eval.Map2TextureCoord3;
1210 case GL_MAP2_TEXTURE_COORD_4:
1211 return ctx->Eval.Map2TextureCoord4;
1212 case GL_MAP2_VERTEX_3:
1213 return ctx->Eval.Map2Vertex3;
1214 case GL_MAP2_VERTEX_4:
1215 return ctx->Eval.Map2Vertex4;
1216 case GL_NORMALIZE:
1217 return ctx->Transform.Normalize;
1218 case GL_POINT_SMOOTH:
1219 return ctx->Point.SmoothFlag;
1220 case GL_POLYGON_SMOOTH:
1221 return ctx->Polygon.SmoothFlag;
1222 case GL_POLYGON_STIPPLE:
1223 return ctx->Polygon.StippleFlag;
1224 case GL_POLYGON_OFFSET_POINT:
1225 return ctx->Polygon.OffsetPoint;
1226 case GL_POLYGON_OFFSET_LINE:
1227 return ctx->Polygon.OffsetLine;
1228 case GL_POLYGON_OFFSET_FILL:
1229 /*case GL_POLYGON_OFFSET_EXT:*/
1230 return ctx->Polygon.OffsetFill;
1231 case GL_RESCALE_NORMAL_EXT:
1232 return ctx->Transform.RescaleNormals;
1233 case GL_SCISSOR_TEST:
1234 return ctx->Scissor.Enabled;
1235 case GL_SHARED_TEXTURE_PALETTE_EXT:
1236 return ctx->Texture.SharedPalette;
1237 case GL_STENCIL_TEST:
1238 return ctx->Stencil.Enabled;
1239 case GL_TEXTURE_1D:
1240 return is_texture_enabled(ctx, TEXTURE_1D_BIT);
1241 case GL_TEXTURE_2D:
1242 return is_texture_enabled(ctx, TEXTURE_2D_BIT);
1243 case GL_TEXTURE_3D:
1244 return is_texture_enabled(ctx, TEXTURE_3D_BIT);
1245 case GL_TEXTURE_GEN_Q:
1246 {
1247 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1248 if (texUnit) {
1249 return (texUnit->TexGenEnabled & Q_BIT) ? GL_TRUE : GL_FALSE;
1250 }
1251 }
1252 return GL_FALSE;
1253 case GL_TEXTURE_GEN_R:
1254 {
1255 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1256 if (texUnit) {
1257 return (texUnit->TexGenEnabled & R_BIT) ? GL_TRUE : GL_FALSE;
1258 }
1259 }
1260 return GL_FALSE;
1261 case GL_TEXTURE_GEN_S:
1262 {
1263 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1264 if (texUnit) {
1265 return (texUnit->TexGenEnabled & S_BIT) ? GL_TRUE : GL_FALSE;
1266 }
1267 }
1268 return GL_FALSE;
1269 case GL_TEXTURE_GEN_T:
1270 {
1271 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1272 if (texUnit) {
1273 return (texUnit->TexGenEnabled & T_BIT) ? GL_TRUE : GL_FALSE;
1274 }
1275 }
1276 return GL_FALSE;
1277 #if FEATURE_ES1
1278 case GL_TEXTURE_GEN_STR_OES:
1279 {
1280 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1281 if (texUnit) {
1282 return (texUnit->TexGenEnabled & STR_BITS) == STR_BITS ? GL_TRUE : GL_FALSE;
1283 }
1284 }
1285 #endif
1286
1287 /*
1288 * CLIENT STATE!!!
1289 */
1290 case GL_VERTEX_ARRAY:
1291 return (ctx->Array.ArrayObj->Vertex.Enabled != 0);
1292 case GL_NORMAL_ARRAY:
1293 return (ctx->Array.ArrayObj->Normal.Enabled != 0);
1294 case GL_COLOR_ARRAY:
1295 return (ctx->Array.ArrayObj->Color.Enabled != 0);
1296 case GL_INDEX_ARRAY:
1297 return (ctx->Array.ArrayObj->Index.Enabled != 0);
1298 case GL_TEXTURE_COORD_ARRAY:
1299 return (ctx->Array.ArrayObj->TexCoord[ctx->Array.ActiveTexture].Enabled != 0);
1300 case GL_EDGE_FLAG_ARRAY:
1301 return (ctx->Array.ArrayObj->EdgeFlag.Enabled != 0);
1302 case GL_FOG_COORDINATE_ARRAY_EXT:
1303 CHECK_EXTENSION(EXT_fog_coord);
1304 return (ctx->Array.ArrayObj->FogCoord.Enabled != 0);
1305 case GL_SECONDARY_COLOR_ARRAY_EXT:
1306 CHECK_EXTENSION(EXT_secondary_color);
1307 return (ctx->Array.ArrayObj->SecondaryColor.Enabled != 0);
1308 #if FEATURE_point_size_array
1309 case GL_POINT_SIZE_ARRAY_OES:
1310 return (ctx->Array.ArrayObj->PointSize.Enabled != 0);
1311 #endif
1312
1313 /* GL_SGI_texture_color_table */
1314 case GL_TEXTURE_COLOR_TABLE_SGI:
1315 CHECK_EXTENSION(SGI_texture_color_table);
1316 return ctx->Texture.Unit[ctx->Texture.CurrentUnit].ColorTableEnabled;
1317
1318 /* GL_ARB_texture_cube_map */
1319 case GL_TEXTURE_CUBE_MAP_ARB:
1320 CHECK_EXTENSION(ARB_texture_cube_map);
1321 return is_texture_enabled(ctx, TEXTURE_CUBE_BIT);
1322
1323 /* GL_EXT_secondary_color */
1324 case GL_COLOR_SUM_EXT:
1325 CHECK_EXTENSION2(EXT_secondary_color, ARB_vertex_program);
1326 return ctx->Fog.ColorSumEnabled;
1327
1328 /* GL_ARB_multisample */
1329 case GL_MULTISAMPLE_ARB:
1330 return ctx->Multisample.Enabled;
1331 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
1332 return ctx->Multisample.SampleAlphaToCoverage;
1333 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
1334 return ctx->Multisample.SampleAlphaToOne;
1335 case GL_SAMPLE_COVERAGE_ARB:
1336 return ctx->Multisample.SampleCoverage;
1337 case GL_SAMPLE_COVERAGE_INVERT_ARB:
1338 return ctx->Multisample.SampleCoverageInvert;
1339
1340 /* GL_IBM_rasterpos_clip */
1341 case GL_RASTER_POSITION_UNCLIPPED_IBM:
1342 CHECK_EXTENSION(IBM_rasterpos_clip);
1343 return ctx->Transform.RasterPositionUnclipped;
1344
1345 /* GL_NV_point_sprite */
1346 case GL_POINT_SPRITE_NV:
1347 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite)
1348 return ctx->Point.PointSprite;
1349
1350 #if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program
1351 case GL_VERTEX_PROGRAM_ARB:
1352 CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program);
1353 return ctx->VertexProgram.Enabled;
1354 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
1355 CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program);
1356 return ctx->VertexProgram.PointSizeEnabled;
1357 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
1358 CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program);
1359 return ctx->VertexProgram.TwoSideEnabled;
1360 #endif
1361 #if FEATURE_NV_vertex_program
1362 case GL_VERTEX_ATTRIB_ARRAY0_NV:
1363 case GL_VERTEX_ATTRIB_ARRAY1_NV:
1364 case GL_VERTEX_ATTRIB_ARRAY2_NV:
1365 case GL_VERTEX_ATTRIB_ARRAY3_NV:
1366 case GL_VERTEX_ATTRIB_ARRAY4_NV:
1367 case GL_VERTEX_ATTRIB_ARRAY5_NV:
1368 case GL_VERTEX_ATTRIB_ARRAY6_NV:
1369 case GL_VERTEX_ATTRIB_ARRAY7_NV:
1370 case GL_VERTEX_ATTRIB_ARRAY8_NV:
1371 case GL_VERTEX_ATTRIB_ARRAY9_NV:
1372 case GL_VERTEX_ATTRIB_ARRAY10_NV:
1373 case GL_VERTEX_ATTRIB_ARRAY11_NV:
1374 case GL_VERTEX_ATTRIB_ARRAY12_NV:
1375 case GL_VERTEX_ATTRIB_ARRAY13_NV:
1376 case GL_VERTEX_ATTRIB_ARRAY14_NV:
1377 case GL_VERTEX_ATTRIB_ARRAY15_NV:
1378 CHECK_EXTENSION(NV_vertex_program);
1379 {
1380 GLint n = (GLint) cap - GL_VERTEX_ATTRIB_ARRAY0_NV;
1381 ASSERT(n < Elements(ctx->Array.ArrayObj->VertexAttrib));
1382 return (ctx->Array.ArrayObj->VertexAttrib[n].Enabled != 0);
1383 }
1384 case GL_MAP1_VERTEX_ATTRIB0_4_NV:
1385 case GL_MAP1_VERTEX_ATTRIB1_4_NV:
1386 case GL_MAP1_VERTEX_ATTRIB2_4_NV:
1387 case GL_MAP1_VERTEX_ATTRIB3_4_NV:
1388 case GL_MAP1_VERTEX_ATTRIB4_4_NV:
1389 case GL_MAP1_VERTEX_ATTRIB5_4_NV:
1390 case GL_MAP1_VERTEX_ATTRIB6_4_NV:
1391 case GL_MAP1_VERTEX_ATTRIB7_4_NV:
1392 case GL_MAP1_VERTEX_ATTRIB8_4_NV:
1393 case GL_MAP1_VERTEX_ATTRIB9_4_NV:
1394 case GL_MAP1_VERTEX_ATTRIB10_4_NV:
1395 case GL_MAP1_VERTEX_ATTRIB11_4_NV:
1396 case GL_MAP1_VERTEX_ATTRIB12_4_NV:
1397 case GL_MAP1_VERTEX_ATTRIB13_4_NV:
1398 case GL_MAP1_VERTEX_ATTRIB14_4_NV:
1399 case GL_MAP1_VERTEX_ATTRIB15_4_NV:
1400 CHECK_EXTENSION(NV_vertex_program);
1401 {
1402 const GLuint map = (GLuint) (cap - GL_MAP1_VERTEX_ATTRIB0_4_NV);
1403 return ctx->Eval.Map1Attrib[map];
1404 }
1405 case GL_MAP2_VERTEX_ATTRIB0_4_NV:
1406 case GL_MAP2_VERTEX_ATTRIB1_4_NV:
1407 case GL_MAP2_VERTEX_ATTRIB2_4_NV:
1408 case GL_MAP2_VERTEX_ATTRIB3_4_NV:
1409 case GL_MAP2_VERTEX_ATTRIB4_4_NV:
1410 case GL_MAP2_VERTEX_ATTRIB5_4_NV:
1411 case GL_MAP2_VERTEX_ATTRIB6_4_NV:
1412 case GL_MAP2_VERTEX_ATTRIB7_4_NV:
1413 case GL_MAP2_VERTEX_ATTRIB8_4_NV:
1414 case GL_MAP2_VERTEX_ATTRIB9_4_NV:
1415 case GL_MAP2_VERTEX_ATTRIB10_4_NV:
1416 case GL_MAP2_VERTEX_ATTRIB11_4_NV:
1417 case GL_MAP2_VERTEX_ATTRIB12_4_NV:
1418 case GL_MAP2_VERTEX_ATTRIB13_4_NV:
1419 case GL_MAP2_VERTEX_ATTRIB14_4_NV:
1420 case GL_MAP2_VERTEX_ATTRIB15_4_NV:
1421 CHECK_EXTENSION(NV_vertex_program);
1422 {
1423 const GLuint map = (GLuint) (cap - GL_MAP2_VERTEX_ATTRIB0_4_NV);
1424 return ctx->Eval.Map2Attrib[map];
1425 }
1426 #endif /* FEATURE_NV_vertex_program */
1427
1428 #if FEATURE_NV_fragment_program
1429 case GL_FRAGMENT_PROGRAM_NV:
1430 CHECK_EXTENSION(NV_fragment_program);
1431 return ctx->FragmentProgram.Enabled;
1432 #endif /* FEATURE_NV_fragment_program */
1433
1434 /* GL_NV_texture_rectangle */
1435 case GL_TEXTURE_RECTANGLE_NV:
1436 CHECK_EXTENSION(NV_texture_rectangle);
1437 return is_texture_enabled(ctx, TEXTURE_RECT_BIT);
1438
1439 /* GL_EXT_stencil_two_side */
1440 case GL_STENCIL_TEST_TWO_SIDE_EXT:
1441 CHECK_EXTENSION(EXT_stencil_two_side);
1442 return ctx->Stencil.TestTwoSide;
1443
1444 #if FEATURE_ARB_fragment_program
1445 case GL_FRAGMENT_PROGRAM_ARB:
1446 return ctx->FragmentProgram.Enabled;
1447 #endif /* FEATURE_ARB_fragment_program */
1448
1449 /* GL_EXT_depth_bounds_test */
1450 case GL_DEPTH_BOUNDS_TEST_EXT:
1451 CHECK_EXTENSION(EXT_depth_bounds_test);
1452 return ctx->Depth.BoundsTest;
1453
1454 /* GL_ARB_depth_clamp */
1455 case GL_DEPTH_CLAMP:
1456 CHECK_EXTENSION(ARB_depth_clamp);
1457 return ctx->Transform.DepthClamp;
1458
1459 #if FEATURE_ATI_fragment_shader
1460 case GL_FRAGMENT_SHADER_ATI:
1461 CHECK_EXTENSION(ATI_fragment_shader);
1462 return ctx->ATIFragmentShader.Enabled;
1463 #endif /* FEATURE_ATI_fragment_shader */
1464
1465 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1466 CHECK_EXTENSION(ARB_seamless_cube_map);
1467 return ctx->Texture.CubeMapSeamless;
1468
1469 #if FEATURE_EXT_transform_feedback
1470 case GL_RASTERIZER_DISCARD:
1471 CHECK_EXTENSION(EXT_transform_feedback);
1472 return ctx->TransformFeedback.RasterDiscard;
1473 #endif
1474
1475 /* GL_NV_primitive_restart */
1476 case GL_PRIMITIVE_RESTART_NV:
1477 if (!ctx->Extensions.NV_primitive_restart) {
1478 goto invalid_enum_error;
1479 }
1480 return ctx->Array.PrimitiveRestart;
1481
1482 /* GL 3.1 primitive restart */
1483 case GL_PRIMITIVE_RESTART:
1484 if (ctx->VersionMajor * 10 + ctx->VersionMinor < 31) {
1485 goto invalid_enum_error;
1486 }
1487 return ctx->Array.PrimitiveRestart;
1488
1489 /* GL3.0 - GL_framebuffer_sRGB */
1490 case GL_FRAMEBUFFER_SRGB_EXT:
1491 CHECK_EXTENSION(EXT_framebuffer_sRGB);
1492 return ctx->Color.sRGBEnabled;
1493
1494 default:
1495 goto invalid_enum_error;
1496 }
1497
1498 return GL_FALSE;
1499
1500 invalid_enum_error:
1501 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(0x%x)", (int) cap);
1502 return GL_FALSE;
1503 }