2c8c000f9f419a99c815b9e443cf4022c7654c43
[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 "mtypes.h"
37 #include "enums.h"
38 #include "api_arrayelt.h"
39 #include "texstate.h"
40
41
42
43 #define CHECK_EXTENSION(EXTNAME, CAP) \
44 if (!ctx->Extensions.EXTNAME) { \
45 goto invalid_enum_error; \
46 }
47
48
49 /**
50 * Helper to enable/disable client-side state.
51 */
52 static void
53 client_state(GLcontext *ctx, GLenum cap, GLboolean state)
54 {
55 struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
56 GLuint flag;
57 GLboolean *var;
58
59 switch (cap) {
60 case GL_VERTEX_ARRAY:
61 var = &arrayObj->Vertex.Enabled;
62 flag = _NEW_ARRAY_VERTEX;
63 break;
64 case GL_NORMAL_ARRAY:
65 var = &arrayObj->Normal.Enabled;
66 flag = _NEW_ARRAY_NORMAL;
67 break;
68 case GL_COLOR_ARRAY:
69 var = &arrayObj->Color.Enabled;
70 flag = _NEW_ARRAY_COLOR0;
71 break;
72 case GL_INDEX_ARRAY:
73 var = &arrayObj->Index.Enabled;
74 flag = _NEW_ARRAY_INDEX;
75 break;
76 case GL_TEXTURE_COORD_ARRAY:
77 var = &arrayObj->TexCoord[ctx->Array.ActiveTexture].Enabled;
78 flag = _NEW_ARRAY_TEXCOORD(ctx->Array.ActiveTexture);
79 break;
80 case GL_EDGE_FLAG_ARRAY:
81 var = &arrayObj->EdgeFlag.Enabled;
82 flag = _NEW_ARRAY_EDGEFLAG;
83 break;
84 case GL_FOG_COORDINATE_ARRAY_EXT:
85 var = &arrayObj->FogCoord.Enabled;
86 flag = _NEW_ARRAY_FOGCOORD;
87 break;
88 case GL_SECONDARY_COLOR_ARRAY_EXT:
89 var = &arrayObj->SecondaryColor.Enabled;
90 flag = _NEW_ARRAY_COLOR1;
91 break;
92
93 #if FEATURE_point_size_array
94 case GL_POINT_SIZE_ARRAY_OES:
95 var = &arrayObj->PointSize.Enabled;
96 flag = _NEW_ARRAY_POINT_SIZE;
97 break;
98 #endif
99
100 #if FEATURE_NV_vertex_program
101 case GL_VERTEX_ATTRIB_ARRAY0_NV:
102 case GL_VERTEX_ATTRIB_ARRAY1_NV:
103 case GL_VERTEX_ATTRIB_ARRAY2_NV:
104 case GL_VERTEX_ATTRIB_ARRAY3_NV:
105 case GL_VERTEX_ATTRIB_ARRAY4_NV:
106 case GL_VERTEX_ATTRIB_ARRAY5_NV:
107 case GL_VERTEX_ATTRIB_ARRAY6_NV:
108 case GL_VERTEX_ATTRIB_ARRAY7_NV:
109 case GL_VERTEX_ATTRIB_ARRAY8_NV:
110 case GL_VERTEX_ATTRIB_ARRAY9_NV:
111 case GL_VERTEX_ATTRIB_ARRAY10_NV:
112 case GL_VERTEX_ATTRIB_ARRAY11_NV:
113 case GL_VERTEX_ATTRIB_ARRAY12_NV:
114 case GL_VERTEX_ATTRIB_ARRAY13_NV:
115 case GL_VERTEX_ATTRIB_ARRAY14_NV:
116 case GL_VERTEX_ATTRIB_ARRAY15_NV:
117 CHECK_EXTENSION(NV_vertex_program, cap);
118 {
119 GLint n = (GLint) cap - GL_VERTEX_ATTRIB_ARRAY0_NV;
120 ASSERT(n < Elements(ctx->Array.ArrayObj->VertexAttrib));
121 var = &arrayObj->VertexAttrib[n].Enabled;
122 flag = _NEW_ARRAY_ATTRIB(n);
123 }
124 break;
125 #endif /* FEATURE_NV_vertex_program */
126
127 default:
128 goto invalid_enum_error;
129 }
130
131 if (*var == state)
132 return;
133
134 FLUSH_VERTICES(ctx, _NEW_ARRAY);
135 ctx->Array.NewState |= flag;
136
137 _ae_invalidate_state(ctx, _NEW_ARRAY);
138
139 *var = state;
140
141 if (state)
142 ctx->Array.ArrayObj->_Enabled |= flag;
143 else
144 ctx->Array.ArrayObj->_Enabled &= ~flag;
145
146 if (ctx->Driver.Enable) {
147 ctx->Driver.Enable( ctx, cap, state );
148 }
149
150 return;
151
152 invalid_enum_error:
153 _mesa_error(ctx, GL_INVALID_ENUM, "gl%sClientState(0x%x)",
154 state ? "Enable" : "Disable", cap);
155 }
156
157
158 /**
159 * Enable GL capability.
160 * \param cap state to enable/disable.
161 *
162 * Get's the current context, assures that we're outside glBegin()/glEnd() and
163 * calls client_state().
164 */
165 void GLAPIENTRY
166 _mesa_EnableClientState( GLenum cap )
167 {
168 GET_CURRENT_CONTEXT(ctx);
169 ASSERT_OUTSIDE_BEGIN_END(ctx);
170 client_state( ctx, cap, GL_TRUE );
171 }
172
173
174 /**
175 * Disable GL capability.
176 * \param cap state to enable/disable.
177 *
178 * Get's the current context, assures that we're outside glBegin()/glEnd() and
179 * calls client_state().
180 */
181 void GLAPIENTRY
182 _mesa_DisableClientState( GLenum cap )
183 {
184 GET_CURRENT_CONTEXT(ctx);
185 ASSERT_OUTSIDE_BEGIN_END(ctx);
186 client_state( ctx, cap, GL_FALSE );
187 }
188
189
190 #undef CHECK_EXTENSION
191 #define CHECK_EXTENSION(EXTNAME, CAP) \
192 if (!ctx->Extensions.EXTNAME) { \
193 goto invalid_enum_error; \
194 }
195
196 #define CHECK_EXTENSION2(EXT1, EXT2, CAP) \
197 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
198 goto invalid_enum_error; \
199 }
200
201
202
203 /**
204 * Return pointer to current texture unit for setting/getting coordinate
205 * state.
206 * Note that we'll set GL_INVALID_OPERATION if the active texture unit is
207 * higher than the number of supported coordinate units. And we'll return NULL.
208 */
209 static struct gl_texture_unit *
210 get_texcoord_unit(GLcontext *ctx)
211 {
212 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
213 _mesa_error(ctx, GL_INVALID_OPERATION, "glEnable/Disable(texcoord unit)");
214 return NULL;
215 }
216 else {
217 return &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
218 }
219 }
220
221
222 /**
223 * Helper function to enable or disable a texture target.
224 * \param bit one of the TEXTURE_x_BIT values
225 * \return GL_TRUE if state is changing or GL_FALSE if no change
226 */
227 static GLboolean
228 enable_texture(GLcontext *ctx, GLboolean state, GLbitfield texBit)
229 {
230 struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
231 const GLbitfield newenabled = state
232 ? (texUnit->Enabled | texBit) : (texUnit->Enabled & ~texBit);
233
234 if (texUnit->Enabled == newenabled)
235 return GL_FALSE;
236
237 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
238 texUnit->Enabled = newenabled;
239 return GL_TRUE;
240 }
241
242
243 /**
244 * Helper function to enable or disable state.
245 *
246 * \param ctx GL context.
247 * \param cap the state to enable/disable
248 * \param state whether to enable or disable the specified capability.
249 *
250 * Updates the current context and flushes the vertices as needed. For
251 * capabilities associated with extensions it verifies that those extensions
252 * are effectivly present before updating. Notifies the driver via
253 * dd_function_table::Enable.
254 */
255 void
256 _mesa_set_enable(GLcontext *ctx, GLenum cap, GLboolean state)
257 {
258 if (MESA_VERBOSE & VERBOSE_API)
259 _mesa_debug(ctx, "%s %s (newstate is %x)\n",
260 state ? "glEnable" : "glDisable",
261 _mesa_lookup_enum_by_nr(cap),
262 ctx->NewState);
263
264 switch (cap) {
265 case GL_ALPHA_TEST:
266 if (ctx->Color.AlphaEnabled == state)
267 return;
268 FLUSH_VERTICES(ctx, _NEW_COLOR);
269 ctx->Color.AlphaEnabled = state;
270 break;
271 case GL_AUTO_NORMAL:
272 if (ctx->Eval.AutoNormal == state)
273 return;
274 FLUSH_VERTICES(ctx, _NEW_EVAL);
275 ctx->Eval.AutoNormal = state;
276 break;
277 case GL_BLEND:
278 {
279 GLbitfield newEnabled = state * ((1 << ctx->Const.MaxDrawBuffers) - 1);
280 if (newEnabled != ctx->Color.BlendEnabled) {
281 FLUSH_VERTICES(ctx, _NEW_COLOR);
282 ctx->Color.BlendEnabled = newEnabled;
283 }
284 }
285 break;
286 #if FEATURE_userclip
287 case GL_CLIP_PLANE0:
288 case GL_CLIP_PLANE1:
289 case GL_CLIP_PLANE2:
290 case GL_CLIP_PLANE3:
291 case GL_CLIP_PLANE4:
292 case GL_CLIP_PLANE5:
293 {
294 const GLuint p = cap - GL_CLIP_PLANE0;
295
296 if ((ctx->Transform.ClipPlanesEnabled & (1 << p)) == ((GLuint) state << p))
297 return;
298
299 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
300
301 if (state) {
302 ctx->Transform.ClipPlanesEnabled |= (1 << p);
303
304 if (_math_matrix_is_dirty(ctx->ProjectionMatrixStack.Top))
305 _math_matrix_analyse( ctx->ProjectionMatrixStack.Top );
306
307 /* This derived state also calculated in clip.c and
308 * from _mesa_update_state() on changes to EyeUserPlane
309 * and ctx->ProjectionMatrix respectively.
310 */
311 _mesa_transform_vector( ctx->Transform._ClipUserPlane[p],
312 ctx->Transform.EyeUserPlane[p],
313 ctx->ProjectionMatrixStack.Top->inv );
314 }
315 else {
316 ctx->Transform.ClipPlanesEnabled &= ~(1 << p);
317 }
318 }
319 break;
320 #endif
321 case GL_COLOR_MATERIAL:
322 if (ctx->Light.ColorMaterialEnabled == state)
323 return;
324 FLUSH_VERTICES(ctx, _NEW_LIGHT);
325 FLUSH_CURRENT(ctx, 0);
326 ctx->Light.ColorMaterialEnabled = state;
327 if (state) {
328 _mesa_update_color_material( ctx,
329 ctx->Current.Attrib[VERT_ATTRIB_COLOR0] );
330 }
331 break;
332 case GL_CULL_FACE:
333 if (ctx->Polygon.CullFlag == state)
334 return;
335 FLUSH_VERTICES(ctx, _NEW_POLYGON);
336 ctx->Polygon.CullFlag = state;
337 break;
338 case GL_CULL_VERTEX_EXT:
339 CHECK_EXTENSION(EXT_cull_vertex, cap);
340 if (ctx->Transform.CullVertexFlag == state)
341 return;
342 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
343 ctx->Transform.CullVertexFlag = state;
344 break;
345 case GL_DEPTH_TEST:
346 if (ctx->Depth.Test == state)
347 return;
348 FLUSH_VERTICES(ctx, _NEW_DEPTH);
349 ctx->Depth.Test = state;
350 break;
351 case GL_DITHER:
352 if (ctx->NoDither) {
353 state = GL_FALSE; /* MESA_NO_DITHER env var */
354 }
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_EXT_convolution */
716 case GL_CONVOLUTION_1D:
717 CHECK_EXTENSION(EXT_convolution, cap);
718 if (ctx->Pixel.Convolution1DEnabled == state)
719 return;
720 FLUSH_VERTICES(ctx, _NEW_PIXEL);
721 ctx->Pixel.Convolution1DEnabled = state;
722 break;
723 case GL_CONVOLUTION_2D:
724 CHECK_EXTENSION(EXT_convolution, cap);
725 if (ctx->Pixel.Convolution2DEnabled == state)
726 return;
727 FLUSH_VERTICES(ctx, _NEW_PIXEL);
728 ctx->Pixel.Convolution2DEnabled = state;
729 break;
730 case GL_SEPARABLE_2D:
731 CHECK_EXTENSION(EXT_convolution, cap);
732 if (ctx->Pixel.Separable2DEnabled == state)
733 return;
734 FLUSH_VERTICES(ctx, _NEW_PIXEL);
735 ctx->Pixel.Separable2DEnabled = state;
736 break;
737
738 /* GL_ARB_texture_cube_map */
739 case GL_TEXTURE_CUBE_MAP_ARB:
740 CHECK_EXTENSION(ARB_texture_cube_map, cap);
741 if (!enable_texture(ctx, state, TEXTURE_CUBE_BIT)) {
742 return;
743 }
744 break;
745
746 /* GL_EXT_secondary_color */
747 case GL_COLOR_SUM_EXT:
748 CHECK_EXTENSION2(EXT_secondary_color, ARB_vertex_program, cap);
749 if (ctx->Fog.ColorSumEnabled == state)
750 return;
751 FLUSH_VERTICES(ctx, _NEW_FOG);
752 ctx->Fog.ColorSumEnabled = state;
753 break;
754
755 /* GL_ARB_multisample */
756 case GL_MULTISAMPLE_ARB:
757 if (ctx->Multisample.Enabled == state)
758 return;
759 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
760 ctx->Multisample.Enabled = state;
761 break;
762 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
763 if (ctx->Multisample.SampleAlphaToCoverage == state)
764 return;
765 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
766 ctx->Multisample.SampleAlphaToCoverage = state;
767 break;
768 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
769 if (ctx->Multisample.SampleAlphaToOne == state)
770 return;
771 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
772 ctx->Multisample.SampleAlphaToOne = state;
773 break;
774 case GL_SAMPLE_COVERAGE_ARB:
775 if (ctx->Multisample.SampleCoverage == state)
776 return;
777 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
778 ctx->Multisample.SampleCoverage = state;
779 break;
780 case GL_SAMPLE_COVERAGE_INVERT_ARB:
781 if (ctx->Multisample.SampleCoverageInvert == state)
782 return;
783 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
784 ctx->Multisample.SampleCoverageInvert = state;
785 break;
786
787 /* GL_IBM_rasterpos_clip */
788 case GL_RASTER_POSITION_UNCLIPPED_IBM:
789 CHECK_EXTENSION(IBM_rasterpos_clip, cap);
790 if (ctx->Transform.RasterPositionUnclipped == state)
791 return;
792 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
793 ctx->Transform.RasterPositionUnclipped = state;
794 break;
795
796 /* GL_NV_point_sprite */
797 case GL_POINT_SPRITE_NV:
798 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite, cap);
799 if (ctx->Point.PointSprite == state)
800 return;
801 FLUSH_VERTICES(ctx, _NEW_POINT);
802 ctx->Point.PointSprite = state;
803 break;
804
805 #if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program
806 case GL_VERTEX_PROGRAM_ARB:
807 CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program, cap);
808 if (ctx->VertexProgram.Enabled == state)
809 return;
810 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
811 ctx->VertexProgram.Enabled = state;
812 break;
813 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
814 CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program, cap);
815 if (ctx->VertexProgram.PointSizeEnabled == state)
816 return;
817 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
818 ctx->VertexProgram.PointSizeEnabled = state;
819 break;
820 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
821 CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program, cap);
822 if (ctx->VertexProgram.TwoSideEnabled == state)
823 return;
824 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
825 ctx->VertexProgram.TwoSideEnabled = state;
826 break;
827 #endif
828 #if FEATURE_NV_vertex_program
829 case GL_MAP1_VERTEX_ATTRIB0_4_NV:
830 case GL_MAP1_VERTEX_ATTRIB1_4_NV:
831 case GL_MAP1_VERTEX_ATTRIB2_4_NV:
832 case GL_MAP1_VERTEX_ATTRIB3_4_NV:
833 case GL_MAP1_VERTEX_ATTRIB4_4_NV:
834 case GL_MAP1_VERTEX_ATTRIB5_4_NV:
835 case GL_MAP1_VERTEX_ATTRIB6_4_NV:
836 case GL_MAP1_VERTEX_ATTRIB7_4_NV:
837 case GL_MAP1_VERTEX_ATTRIB8_4_NV:
838 case GL_MAP1_VERTEX_ATTRIB9_4_NV:
839 case GL_MAP1_VERTEX_ATTRIB10_4_NV:
840 case GL_MAP1_VERTEX_ATTRIB11_4_NV:
841 case GL_MAP1_VERTEX_ATTRIB12_4_NV:
842 case GL_MAP1_VERTEX_ATTRIB13_4_NV:
843 case GL_MAP1_VERTEX_ATTRIB14_4_NV:
844 case GL_MAP1_VERTEX_ATTRIB15_4_NV:
845 CHECK_EXTENSION(NV_vertex_program, cap);
846 {
847 const GLuint map = (GLuint) (cap - GL_MAP1_VERTEX_ATTRIB0_4_NV);
848 FLUSH_VERTICES(ctx, _NEW_EVAL);
849 ctx->Eval.Map1Attrib[map] = state;
850 }
851 break;
852 case GL_MAP2_VERTEX_ATTRIB0_4_NV:
853 case GL_MAP2_VERTEX_ATTRIB1_4_NV:
854 case GL_MAP2_VERTEX_ATTRIB2_4_NV:
855 case GL_MAP2_VERTEX_ATTRIB3_4_NV:
856 case GL_MAP2_VERTEX_ATTRIB4_4_NV:
857 case GL_MAP2_VERTEX_ATTRIB5_4_NV:
858 case GL_MAP2_VERTEX_ATTRIB6_4_NV:
859 case GL_MAP2_VERTEX_ATTRIB7_4_NV:
860 case GL_MAP2_VERTEX_ATTRIB8_4_NV:
861 case GL_MAP2_VERTEX_ATTRIB9_4_NV:
862 case GL_MAP2_VERTEX_ATTRIB10_4_NV:
863 case GL_MAP2_VERTEX_ATTRIB11_4_NV:
864 case GL_MAP2_VERTEX_ATTRIB12_4_NV:
865 case GL_MAP2_VERTEX_ATTRIB13_4_NV:
866 case GL_MAP2_VERTEX_ATTRIB14_4_NV:
867 case GL_MAP2_VERTEX_ATTRIB15_4_NV:
868 CHECK_EXTENSION(NV_vertex_program, cap);
869 {
870 const GLuint map = (GLuint) (cap - GL_MAP2_VERTEX_ATTRIB0_4_NV);
871 FLUSH_VERTICES(ctx, _NEW_EVAL);
872 ctx->Eval.Map2Attrib[map] = state;
873 }
874 break;
875 #endif /* FEATURE_NV_vertex_program */
876
877 #if FEATURE_NV_fragment_program
878 case GL_FRAGMENT_PROGRAM_NV:
879 CHECK_EXTENSION(NV_fragment_program, cap);
880 if (ctx->FragmentProgram.Enabled == state)
881 return;
882 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
883 ctx->FragmentProgram.Enabled = state;
884 break;
885 #endif /* FEATURE_NV_fragment_program */
886
887 /* GL_NV_texture_rectangle */
888 case GL_TEXTURE_RECTANGLE_NV:
889 CHECK_EXTENSION(NV_texture_rectangle, cap);
890 if (!enable_texture(ctx, state, TEXTURE_RECT_BIT)) {
891 return;
892 }
893 break;
894
895 /* GL_EXT_stencil_two_side */
896 case GL_STENCIL_TEST_TWO_SIDE_EXT:
897 CHECK_EXTENSION(EXT_stencil_two_side, cap);
898 if (ctx->Stencil.TestTwoSide == state)
899 return;
900 FLUSH_VERTICES(ctx, _NEW_STENCIL);
901 ctx->Stencil.TestTwoSide = state;
902 if (state) {
903 ctx->Stencil._BackFace = 2;
904 ctx->_TriangleCaps |= DD_TRI_TWOSTENCIL;
905 } else {
906 ctx->Stencil._BackFace = 1;
907 ctx->_TriangleCaps &= ~DD_TRI_TWOSTENCIL;
908 }
909 break;
910
911 #if FEATURE_ARB_fragment_program
912 case GL_FRAGMENT_PROGRAM_ARB:
913 CHECK_EXTENSION(ARB_fragment_program, cap);
914 if (ctx->FragmentProgram.Enabled == state)
915 return;
916 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
917 ctx->FragmentProgram.Enabled = state;
918 break;
919 #endif /* FEATURE_ARB_fragment_program */
920
921 /* GL_EXT_depth_bounds_test */
922 case GL_DEPTH_BOUNDS_TEST_EXT:
923 CHECK_EXTENSION(EXT_depth_bounds_test, cap);
924 if (ctx->Depth.BoundsTest == state)
925 return;
926 FLUSH_VERTICES(ctx, _NEW_DEPTH);
927 ctx->Depth.BoundsTest = state;
928 break;
929
930 case GL_DEPTH_CLAMP:
931 if (ctx->Transform.DepthClamp == state)
932 return;
933 CHECK_EXTENSION(ARB_depth_clamp, cap);
934 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
935 ctx->Transform.DepthClamp = state;
936 break;
937
938 #if FEATURE_ATI_fragment_shader
939 case GL_FRAGMENT_SHADER_ATI:
940 CHECK_EXTENSION(ATI_fragment_shader, cap);
941 if (ctx->ATIFragmentShader.Enabled == state)
942 return;
943 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
944 ctx->ATIFragmentShader.Enabled = state;
945 break;
946 #endif
947
948 /* GL_MESA_texture_array */
949 case GL_TEXTURE_1D_ARRAY_EXT:
950 CHECK_EXTENSION(MESA_texture_array, cap);
951 if (!enable_texture(ctx, state, TEXTURE_1D_ARRAY_BIT)) {
952 return;
953 }
954 break;
955
956 case GL_TEXTURE_2D_ARRAY_EXT:
957 CHECK_EXTENSION(MESA_texture_array, cap);
958 if (!enable_texture(ctx, state, TEXTURE_2D_ARRAY_BIT)) {
959 return;
960 }
961 break;
962
963 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
964 CHECK_EXTENSION(ARB_seamless_cube_map, cap);
965 ctx->Texture.CubeMapSeamless = state;
966 break;
967
968 #if FEATURE_EXT_transform_feedback
969 case GL_RASTERIZER_DISCARD:
970 CHECK_EXTENSION(EXT_transform_feedback, cap);
971 if (ctx->TransformFeedback.RasterDiscard != state) {
972 ctx->TransformFeedback.RasterDiscard = state;
973 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
974 }
975 break;
976 #endif
977
978 /* GL 3.1 primitive restart */
979 case GL_PRIMITIVE_RESTART:
980 if (ctx->VersionMajor * 10 + ctx->VersionMinor < 31) {
981 goto invalid_enum_error;
982 }
983 if (ctx->Array.PrimitiveRestart != state) {
984 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
985 ctx->Array.PrimitiveRestart = state;
986 }
987 break;
988
989 default:
990 goto invalid_enum_error;
991 }
992
993 if (ctx->Driver.Enable) {
994 ctx->Driver.Enable( ctx, cap, state );
995 }
996
997 return;
998
999 invalid_enum_error:
1000 _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(0x%x)",
1001 state ? "Enable" : "Disable", cap);
1002 }
1003
1004
1005 /**
1006 * Enable GL capability. Called by glEnable()
1007 * \param cap state to enable.
1008 */
1009 void GLAPIENTRY
1010 _mesa_Enable( GLenum cap )
1011 {
1012 GET_CURRENT_CONTEXT(ctx);
1013 ASSERT_OUTSIDE_BEGIN_END(ctx);
1014
1015 _mesa_set_enable( ctx, cap, GL_TRUE );
1016 }
1017
1018
1019 /**
1020 * Disable GL capability. Called by glDisable()
1021 * \param cap state to disable.
1022 */
1023 void GLAPIENTRY
1024 _mesa_Disable( GLenum cap )
1025 {
1026 GET_CURRENT_CONTEXT(ctx);
1027 ASSERT_OUTSIDE_BEGIN_END(ctx);
1028
1029 _mesa_set_enable( ctx, cap, GL_FALSE );
1030 }
1031
1032
1033
1034 /**
1035 * Enable/disable an indexed state var.
1036 */
1037 void
1038 _mesa_set_enablei(GLcontext *ctx, GLenum cap, GLuint index, GLboolean state)
1039 {
1040 ASSERT(state == 0 || state == 1);
1041 switch (cap) {
1042 case GL_BLEND:
1043 if (!ctx->Extensions.EXT_draw_buffers2) {
1044 goto invalid_enum_error;
1045 }
1046 if (index >= ctx->Const.MaxDrawBuffers) {
1047 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)",
1048 state ? "glEnableIndexed" : "glDisableIndexed", index);
1049 return;
1050 }
1051 if (((ctx->Color.BlendEnabled >> index) & 1) != state) {
1052 FLUSH_VERTICES(ctx, _NEW_COLOR);
1053 if (state)
1054 ctx->Color.BlendEnabled |= (1 << index);
1055 else
1056 ctx->Color.BlendEnabled &= ~(1 << index);
1057 }
1058 break;
1059 default:
1060 goto invalid_enum_error;
1061 }
1062 return;
1063
1064 invalid_enum_error:
1065 _mesa_error(ctx, GL_INVALID_ENUM, "%s(cap=%s)",
1066 state ? "glEnablei" : "glDisablei",
1067 _mesa_lookup_enum_by_nr(cap));
1068 }
1069
1070
1071 void GLAPIENTRY
1072 _mesa_DisableIndexed( GLenum cap, GLuint index )
1073 {
1074 GET_CURRENT_CONTEXT(ctx);
1075 ASSERT_OUTSIDE_BEGIN_END(ctx);
1076 _mesa_set_enablei(ctx, cap, index, GL_FALSE);
1077 }
1078
1079
1080 void GLAPIENTRY
1081 _mesa_EnableIndexed( GLenum cap, GLuint index )
1082 {
1083 GET_CURRENT_CONTEXT(ctx);
1084 ASSERT_OUTSIDE_BEGIN_END(ctx);
1085 _mesa_set_enablei(ctx, cap, index, GL_TRUE);
1086 }
1087
1088
1089 GLboolean GLAPIENTRY
1090 _mesa_IsEnabledIndexed( GLenum cap, GLuint index )
1091 {
1092 GET_CURRENT_CONTEXT(ctx);
1093 switch (cap) {
1094 case GL_BLEND:
1095 if (index >= ctx->Const.MaxDrawBuffers) {
1096 _mesa_error(ctx, GL_INVALID_VALUE, "glIsEnabledIndexed(index=%u)",
1097 index);
1098 return GL_FALSE;
1099 }
1100 return (ctx->Color.BlendEnabled >> index) & 1;
1101 default:
1102 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabledIndexed(cap=%s)",
1103 _mesa_lookup_enum_by_nr(cap));
1104 return GL_FALSE;
1105 }
1106 }
1107
1108
1109
1110
1111 #undef CHECK_EXTENSION
1112 #define CHECK_EXTENSION(EXTNAME) \
1113 if (!ctx->Extensions.EXTNAME) { \
1114 goto invalid_enum_error; \
1115 }
1116
1117 #undef CHECK_EXTENSION2
1118 #define CHECK_EXTENSION2(EXT1, EXT2) \
1119 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
1120 goto invalid_enum_error; \
1121 }
1122
1123
1124 /**
1125 * Helper function to determine whether a texture target is enabled.
1126 */
1127 static GLboolean
1128 is_texture_enabled(GLcontext *ctx, GLbitfield bit)
1129 {
1130 const struct gl_texture_unit *const texUnit =
1131 &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1132 return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE;
1133 }
1134
1135
1136 /**
1137 * Return simple enable/disable state.
1138 *
1139 * \param cap state variable to query.
1140 *
1141 * Returns the state of the specified capability from the current GL context.
1142 * For the capabilities associated with extensions verifies that those
1143 * extensions are effectively present before reporting.
1144 */
1145 GLboolean GLAPIENTRY
1146 _mesa_IsEnabled( GLenum cap )
1147 {
1148 GET_CURRENT_CONTEXT(ctx);
1149 switch (cap) {
1150 case GL_ALPHA_TEST:
1151 return ctx->Color.AlphaEnabled;
1152 case GL_AUTO_NORMAL:
1153 return ctx->Eval.AutoNormal;
1154 case GL_BLEND:
1155 return ctx->Color.BlendEnabled & 1; /* return state for buffer[0] */
1156 case GL_CLIP_PLANE0:
1157 case GL_CLIP_PLANE1:
1158 case GL_CLIP_PLANE2:
1159 case GL_CLIP_PLANE3:
1160 case GL_CLIP_PLANE4:
1161 case GL_CLIP_PLANE5:
1162 return (ctx->Transform.ClipPlanesEnabled >> (cap - GL_CLIP_PLANE0)) & 1;
1163 case GL_COLOR_MATERIAL:
1164 return ctx->Light.ColorMaterialEnabled;
1165 case GL_CULL_FACE:
1166 return ctx->Polygon.CullFlag;
1167 case GL_DEPTH_TEST:
1168 return ctx->Depth.Test;
1169 case GL_DITHER:
1170 return ctx->Color.DitherFlag;
1171 case GL_FOG:
1172 return ctx->Fog.Enabled;
1173 case GL_LIGHTING:
1174 return ctx->Light.Enabled;
1175 case GL_LIGHT0:
1176 case GL_LIGHT1:
1177 case GL_LIGHT2:
1178 case GL_LIGHT3:
1179 case GL_LIGHT4:
1180 case GL_LIGHT5:
1181 case GL_LIGHT6:
1182 case GL_LIGHT7:
1183 return ctx->Light.Light[cap-GL_LIGHT0].Enabled;
1184 case GL_LINE_SMOOTH:
1185 return ctx->Line.SmoothFlag;
1186 case GL_LINE_STIPPLE:
1187 return ctx->Line.StippleFlag;
1188 case GL_INDEX_LOGIC_OP:
1189 return ctx->Color.IndexLogicOpEnabled;
1190 case GL_COLOR_LOGIC_OP:
1191 return ctx->Color.ColorLogicOpEnabled;
1192 case GL_MAP1_COLOR_4:
1193 return ctx->Eval.Map1Color4;
1194 case GL_MAP1_INDEX:
1195 return ctx->Eval.Map1Index;
1196 case GL_MAP1_NORMAL:
1197 return ctx->Eval.Map1Normal;
1198 case GL_MAP1_TEXTURE_COORD_1:
1199 return ctx->Eval.Map1TextureCoord1;
1200 case GL_MAP1_TEXTURE_COORD_2:
1201 return ctx->Eval.Map1TextureCoord2;
1202 case GL_MAP1_TEXTURE_COORD_3:
1203 return ctx->Eval.Map1TextureCoord3;
1204 case GL_MAP1_TEXTURE_COORD_4:
1205 return ctx->Eval.Map1TextureCoord4;
1206 case GL_MAP1_VERTEX_3:
1207 return ctx->Eval.Map1Vertex3;
1208 case GL_MAP1_VERTEX_4:
1209 return ctx->Eval.Map1Vertex4;
1210 case GL_MAP2_COLOR_4:
1211 return ctx->Eval.Map2Color4;
1212 case GL_MAP2_INDEX:
1213 return ctx->Eval.Map2Index;
1214 case GL_MAP2_NORMAL:
1215 return ctx->Eval.Map2Normal;
1216 case GL_MAP2_TEXTURE_COORD_1:
1217 return ctx->Eval.Map2TextureCoord1;
1218 case GL_MAP2_TEXTURE_COORD_2:
1219 return ctx->Eval.Map2TextureCoord2;
1220 case GL_MAP2_TEXTURE_COORD_3:
1221 return ctx->Eval.Map2TextureCoord3;
1222 case GL_MAP2_TEXTURE_COORD_4:
1223 return ctx->Eval.Map2TextureCoord4;
1224 case GL_MAP2_VERTEX_3:
1225 return ctx->Eval.Map2Vertex3;
1226 case GL_MAP2_VERTEX_4:
1227 return ctx->Eval.Map2Vertex4;
1228 case GL_NORMALIZE:
1229 return ctx->Transform.Normalize;
1230 case GL_POINT_SMOOTH:
1231 return ctx->Point.SmoothFlag;
1232 case GL_POLYGON_SMOOTH:
1233 return ctx->Polygon.SmoothFlag;
1234 case GL_POLYGON_STIPPLE:
1235 return ctx->Polygon.StippleFlag;
1236 case GL_POLYGON_OFFSET_POINT:
1237 return ctx->Polygon.OffsetPoint;
1238 case GL_POLYGON_OFFSET_LINE:
1239 return ctx->Polygon.OffsetLine;
1240 case GL_POLYGON_OFFSET_FILL:
1241 /*case GL_POLYGON_OFFSET_EXT:*/
1242 return ctx->Polygon.OffsetFill;
1243 case GL_RESCALE_NORMAL_EXT:
1244 return ctx->Transform.RescaleNormals;
1245 case GL_SCISSOR_TEST:
1246 return ctx->Scissor.Enabled;
1247 case GL_SHARED_TEXTURE_PALETTE_EXT:
1248 return ctx->Texture.SharedPalette;
1249 case GL_STENCIL_TEST:
1250 return ctx->Stencil.Enabled;
1251 case GL_TEXTURE_1D:
1252 return is_texture_enabled(ctx, TEXTURE_1D_BIT);
1253 case GL_TEXTURE_2D:
1254 return is_texture_enabled(ctx, TEXTURE_2D_BIT);
1255 case GL_TEXTURE_3D:
1256 return is_texture_enabled(ctx, TEXTURE_3D_BIT);
1257 case GL_TEXTURE_GEN_Q:
1258 {
1259 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1260 if (texUnit) {
1261 return (texUnit->TexGenEnabled & Q_BIT) ? GL_TRUE : GL_FALSE;
1262 }
1263 }
1264 return GL_FALSE;
1265 case GL_TEXTURE_GEN_R:
1266 {
1267 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1268 if (texUnit) {
1269 return (texUnit->TexGenEnabled & R_BIT) ? GL_TRUE : GL_FALSE;
1270 }
1271 }
1272 return GL_FALSE;
1273 case GL_TEXTURE_GEN_S:
1274 {
1275 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1276 if (texUnit) {
1277 return (texUnit->TexGenEnabled & S_BIT) ? GL_TRUE : GL_FALSE;
1278 }
1279 }
1280 return GL_FALSE;
1281 case GL_TEXTURE_GEN_T:
1282 {
1283 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1284 if (texUnit) {
1285 return (texUnit->TexGenEnabled & T_BIT) ? GL_TRUE : GL_FALSE;
1286 }
1287 }
1288 return GL_FALSE;
1289 #if FEATURE_ES1
1290 case GL_TEXTURE_GEN_STR_OES:
1291 {
1292 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
1293 if (texUnit) {
1294 return (texUnit->TexGenEnabled & STR_BITS) == STR_BITS ? GL_TRUE : GL_FALSE;
1295 }
1296 }
1297 #endif
1298
1299 /*
1300 * CLIENT STATE!!!
1301 */
1302 case GL_VERTEX_ARRAY:
1303 return (ctx->Array.ArrayObj->Vertex.Enabled != 0);
1304 case GL_NORMAL_ARRAY:
1305 return (ctx->Array.ArrayObj->Normal.Enabled != 0);
1306 case GL_COLOR_ARRAY:
1307 return (ctx->Array.ArrayObj->Color.Enabled != 0);
1308 case GL_INDEX_ARRAY:
1309 return (ctx->Array.ArrayObj->Index.Enabled != 0);
1310 case GL_TEXTURE_COORD_ARRAY:
1311 return (ctx->Array.ArrayObj->TexCoord[ctx->Array.ActiveTexture].Enabled != 0);
1312 case GL_EDGE_FLAG_ARRAY:
1313 return (ctx->Array.ArrayObj->EdgeFlag.Enabled != 0);
1314 case GL_FOG_COORDINATE_ARRAY_EXT:
1315 CHECK_EXTENSION(EXT_fog_coord);
1316 return (ctx->Array.ArrayObj->FogCoord.Enabled != 0);
1317 case GL_SECONDARY_COLOR_ARRAY_EXT:
1318 CHECK_EXTENSION(EXT_secondary_color);
1319 return (ctx->Array.ArrayObj->SecondaryColor.Enabled != 0);
1320 #if FEATURE_point_size_array
1321 case GL_POINT_SIZE_ARRAY_OES:
1322 return (ctx->Array.ArrayObj->PointSize.Enabled != 0);
1323 #endif
1324
1325 /* GL_SGI_texture_color_table */
1326 case GL_TEXTURE_COLOR_TABLE_SGI:
1327 CHECK_EXTENSION(SGI_texture_color_table);
1328 return ctx->Texture.Unit[ctx->Texture.CurrentUnit].ColorTableEnabled;
1329
1330 /* GL_EXT_convolution */
1331 case GL_CONVOLUTION_1D:
1332 CHECK_EXTENSION(EXT_convolution);
1333 return ctx->Pixel.Convolution1DEnabled;
1334 case GL_CONVOLUTION_2D:
1335 CHECK_EXTENSION(EXT_convolution);
1336 return ctx->Pixel.Convolution2DEnabled;
1337 case GL_SEPARABLE_2D:
1338 CHECK_EXTENSION(EXT_convolution);
1339 return ctx->Pixel.Separable2DEnabled;
1340
1341 /* GL_ARB_texture_cube_map */
1342 case GL_TEXTURE_CUBE_MAP_ARB:
1343 CHECK_EXTENSION(ARB_texture_cube_map);
1344 return is_texture_enabled(ctx, TEXTURE_CUBE_BIT);
1345
1346 /* GL_EXT_secondary_color */
1347 case GL_COLOR_SUM_EXT:
1348 CHECK_EXTENSION2(EXT_secondary_color, ARB_vertex_program);
1349 return ctx->Fog.ColorSumEnabled;
1350
1351 /* GL_ARB_multisample */
1352 case GL_MULTISAMPLE_ARB:
1353 return ctx->Multisample.Enabled;
1354 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
1355 return ctx->Multisample.SampleAlphaToCoverage;
1356 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
1357 return ctx->Multisample.SampleAlphaToOne;
1358 case GL_SAMPLE_COVERAGE_ARB:
1359 return ctx->Multisample.SampleCoverage;
1360 case GL_SAMPLE_COVERAGE_INVERT_ARB:
1361 return ctx->Multisample.SampleCoverageInvert;
1362
1363 /* GL_IBM_rasterpos_clip */
1364 case GL_RASTER_POSITION_UNCLIPPED_IBM:
1365 CHECK_EXTENSION(IBM_rasterpos_clip);
1366 return ctx->Transform.RasterPositionUnclipped;
1367
1368 /* GL_NV_point_sprite */
1369 case GL_POINT_SPRITE_NV:
1370 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite)
1371 return ctx->Point.PointSprite;
1372
1373 #if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program
1374 case GL_VERTEX_PROGRAM_ARB:
1375 CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program);
1376 return ctx->VertexProgram.Enabled;
1377 case GL_VERTEX_PROGRAM_POINT_SIZE_ARB:
1378 CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program);
1379 return ctx->VertexProgram.PointSizeEnabled;
1380 case GL_VERTEX_PROGRAM_TWO_SIDE_ARB:
1381 CHECK_EXTENSION2(ARB_vertex_program, NV_vertex_program);
1382 return ctx->VertexProgram.TwoSideEnabled;
1383 #endif
1384 #if FEATURE_NV_vertex_program
1385 case GL_VERTEX_ATTRIB_ARRAY0_NV:
1386 case GL_VERTEX_ATTRIB_ARRAY1_NV:
1387 case GL_VERTEX_ATTRIB_ARRAY2_NV:
1388 case GL_VERTEX_ATTRIB_ARRAY3_NV:
1389 case GL_VERTEX_ATTRIB_ARRAY4_NV:
1390 case GL_VERTEX_ATTRIB_ARRAY5_NV:
1391 case GL_VERTEX_ATTRIB_ARRAY6_NV:
1392 case GL_VERTEX_ATTRIB_ARRAY7_NV:
1393 case GL_VERTEX_ATTRIB_ARRAY8_NV:
1394 case GL_VERTEX_ATTRIB_ARRAY9_NV:
1395 case GL_VERTEX_ATTRIB_ARRAY10_NV:
1396 case GL_VERTEX_ATTRIB_ARRAY11_NV:
1397 case GL_VERTEX_ATTRIB_ARRAY12_NV:
1398 case GL_VERTEX_ATTRIB_ARRAY13_NV:
1399 case GL_VERTEX_ATTRIB_ARRAY14_NV:
1400 case GL_VERTEX_ATTRIB_ARRAY15_NV:
1401 CHECK_EXTENSION(NV_vertex_program);
1402 {
1403 GLint n = (GLint) cap - GL_VERTEX_ATTRIB_ARRAY0_NV;
1404 ASSERT(n < Elements(ctx->Array.ArrayObj->VertexAttrib));
1405 return (ctx->Array.ArrayObj->VertexAttrib[n].Enabled != 0);
1406 }
1407 case GL_MAP1_VERTEX_ATTRIB0_4_NV:
1408 case GL_MAP1_VERTEX_ATTRIB1_4_NV:
1409 case GL_MAP1_VERTEX_ATTRIB2_4_NV:
1410 case GL_MAP1_VERTEX_ATTRIB3_4_NV:
1411 case GL_MAP1_VERTEX_ATTRIB4_4_NV:
1412 case GL_MAP1_VERTEX_ATTRIB5_4_NV:
1413 case GL_MAP1_VERTEX_ATTRIB6_4_NV:
1414 case GL_MAP1_VERTEX_ATTRIB7_4_NV:
1415 case GL_MAP1_VERTEX_ATTRIB8_4_NV:
1416 case GL_MAP1_VERTEX_ATTRIB9_4_NV:
1417 case GL_MAP1_VERTEX_ATTRIB10_4_NV:
1418 case GL_MAP1_VERTEX_ATTRIB11_4_NV:
1419 case GL_MAP1_VERTEX_ATTRIB12_4_NV:
1420 case GL_MAP1_VERTEX_ATTRIB13_4_NV:
1421 case GL_MAP1_VERTEX_ATTRIB14_4_NV:
1422 case GL_MAP1_VERTEX_ATTRIB15_4_NV:
1423 CHECK_EXTENSION(NV_vertex_program);
1424 {
1425 const GLuint map = (GLuint) (cap - GL_MAP1_VERTEX_ATTRIB0_4_NV);
1426 return ctx->Eval.Map1Attrib[map];
1427 }
1428 case GL_MAP2_VERTEX_ATTRIB0_4_NV:
1429 case GL_MAP2_VERTEX_ATTRIB1_4_NV:
1430 case GL_MAP2_VERTEX_ATTRIB2_4_NV:
1431 case GL_MAP2_VERTEX_ATTRIB3_4_NV:
1432 case GL_MAP2_VERTEX_ATTRIB4_4_NV:
1433 case GL_MAP2_VERTEX_ATTRIB5_4_NV:
1434 case GL_MAP2_VERTEX_ATTRIB6_4_NV:
1435 case GL_MAP2_VERTEX_ATTRIB7_4_NV:
1436 case GL_MAP2_VERTEX_ATTRIB8_4_NV:
1437 case GL_MAP2_VERTEX_ATTRIB9_4_NV:
1438 case GL_MAP2_VERTEX_ATTRIB10_4_NV:
1439 case GL_MAP2_VERTEX_ATTRIB11_4_NV:
1440 case GL_MAP2_VERTEX_ATTRIB12_4_NV:
1441 case GL_MAP2_VERTEX_ATTRIB13_4_NV:
1442 case GL_MAP2_VERTEX_ATTRIB14_4_NV:
1443 case GL_MAP2_VERTEX_ATTRIB15_4_NV:
1444 CHECK_EXTENSION(NV_vertex_program);
1445 {
1446 const GLuint map = (GLuint) (cap - GL_MAP2_VERTEX_ATTRIB0_4_NV);
1447 return ctx->Eval.Map2Attrib[map];
1448 }
1449 #endif /* FEATURE_NV_vertex_program */
1450
1451 #if FEATURE_NV_fragment_program
1452 case GL_FRAGMENT_PROGRAM_NV:
1453 CHECK_EXTENSION(NV_fragment_program);
1454 return ctx->FragmentProgram.Enabled;
1455 #endif /* FEATURE_NV_fragment_program */
1456
1457 /* GL_NV_texture_rectangle */
1458 case GL_TEXTURE_RECTANGLE_NV:
1459 CHECK_EXTENSION(NV_texture_rectangle);
1460 return is_texture_enabled(ctx, TEXTURE_RECT_BIT);
1461
1462 /* GL_EXT_stencil_two_side */
1463 case GL_STENCIL_TEST_TWO_SIDE_EXT:
1464 CHECK_EXTENSION(EXT_stencil_two_side);
1465 return ctx->Stencil.TestTwoSide;
1466
1467 #if FEATURE_ARB_fragment_program
1468 case GL_FRAGMENT_PROGRAM_ARB:
1469 return ctx->FragmentProgram.Enabled;
1470 #endif /* FEATURE_ARB_fragment_program */
1471
1472 /* GL_EXT_depth_bounds_test */
1473 case GL_DEPTH_BOUNDS_TEST_EXT:
1474 CHECK_EXTENSION(EXT_depth_bounds_test);
1475 return ctx->Depth.BoundsTest;
1476
1477 /* GL_ARB_depth_clamp */
1478 case GL_DEPTH_CLAMP:
1479 CHECK_EXTENSION(ARB_depth_clamp);
1480 return ctx->Transform.DepthClamp;
1481
1482 #if FEATURE_ATI_fragment_shader
1483 case GL_FRAGMENT_SHADER_ATI:
1484 CHECK_EXTENSION(ATI_fragment_shader);
1485 return ctx->ATIFragmentShader.Enabled;
1486 #endif /* FEATURE_ATI_fragment_shader */
1487
1488 case GL_TEXTURE_CUBE_MAP_SEAMLESS:
1489 CHECK_EXTENSION(ARB_seamless_cube_map);
1490 return ctx->Texture.CubeMapSeamless;
1491
1492 #if FEATURE_EXT_transform_feedback
1493 case GL_RASTERIZER_DISCARD:
1494 CHECK_EXTENSION(EXT_transform_feedback);
1495 return ctx->TransformFeedback.RasterDiscard;
1496 #endif
1497
1498 /* GL 3.1 primitive restart */
1499 case GL_PRIMITIVE_RESTART:
1500 if (ctx->VersionMajor * 10 + ctx->VersionMinor < 31) {
1501 goto invalid_enum_error;
1502 }
1503 return ctx->Array.PrimitiveRestart;
1504
1505 default:
1506 goto invalid_enum_error;
1507 }
1508
1509 return GL_FALSE;
1510
1511 invalid_enum_error:
1512 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(0x%x)", (int) cap);
1513 return GL_FALSE;
1514 }