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