Major rework of tnl module
[mesa.git] / src / mesa / main / enable.c
1 /* $Id: enable.c,v 1.37 2000/12/26 05:09:28 keithw Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
28 #ifdef PC_HEADER
29 #include "all.h"
30 #else
31 #include "glheader.h"
32 #include "context.h"
33 #include "enable.h"
34 #include "light.h"
35 #include "macros.h"
36 #include "mmath.h"
37 #include "simple_list.h"
38 #include "mtypes.h"
39 #include "enums.h"
40
41 #include "math/m_matrix.h"
42 #include "math/m_xform.h"
43
44 #endif
45
46
47 static void
48 client_state( GLcontext *ctx, GLenum cap, GLboolean state )
49 {
50 GLuint flag;
51 GLboolean *var;
52
53 switch (cap) {
54 case GL_VERTEX_ARRAY:
55 var = &ctx->Array.Vertex.Enabled;
56 flag = _NEW_ARRAY_VERTEX;
57 break;
58 case GL_NORMAL_ARRAY:
59 var = &ctx->Array.Normal.Enabled;
60 flag = _NEW_ARRAY_NORMAL;
61 break;
62 case GL_COLOR_ARRAY:
63 var = &ctx->Array.Color.Enabled;
64 flag = _NEW_ARRAY_COLOR;
65 break;
66 case GL_INDEX_ARRAY:
67 var = &ctx->Array.Index.Enabled;
68 flag = _NEW_ARRAY_INDEX;
69 break;
70 case GL_TEXTURE_COORD_ARRAY:
71 var = &ctx->Array.TexCoord[ctx->Array.ActiveTexture].Enabled;
72 flag = _NEW_ARRAY_TEXCOORD(ctx->Array.ActiveTexture);
73 break;
74 case GL_EDGE_FLAG_ARRAY:
75 var = &ctx->Array.EdgeFlag.Enabled;
76 flag = _NEW_ARRAY_EDGEFLAG;
77 break;
78 case GL_FOG_COORDINATE_ARRAY_EXT:
79 var = &ctx->Array.FogCoord.Enabled;
80 flag = _NEW_ARRAY_FOGCOORD;
81 break;
82 case GL_SECONDARY_COLOR_ARRAY_EXT:
83 var = &ctx->Array.SecondaryColor.Enabled;
84 flag = _NEW_ARRAY_SECONDARYCOLOR;
85 break;
86 default:
87 gl_error( ctx, GL_INVALID_ENUM, "glEnable/DisableClientState" );
88 }
89
90 if (*var == flag)
91 return;
92
93 FLUSH_VERTICES(ctx, _NEW_ARRAY);
94 ctx->Array.NewState |= flag;
95 *var = state;
96
97 if (state)
98 ctx->Array._Enabled |= flag;
99 else
100 ctx->Array._Enabled &= ~flag;
101
102 if (ctx->Driver.Enable) {
103 (*ctx->Driver.Enable)( ctx, cap, state );
104 }
105 }
106
107
108
109 void
110 _mesa_EnableClientState( GLenum cap )
111 {
112 GET_CURRENT_CONTEXT(ctx);
113 ASSERT_OUTSIDE_BEGIN_END(ctx);
114 client_state( ctx, cap, GL_TRUE );
115 }
116
117
118
119 void
120 _mesa_DisableClientState( GLenum cap )
121 {
122 GET_CURRENT_CONTEXT(ctx);
123 ASSERT_OUTSIDE_BEGIN_END(ctx);
124 client_state( ctx, cap, GL_FALSE );
125 }
126
127
128 /*
129 * Perform glEnable and glDisable calls.
130 */
131 void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
132 {
133 if (MESA_VERBOSE & VERBOSE_API)
134 fprintf(stderr, "%s %s (newstate is %x)\n",
135 state ? "glEnable" : "glDisable",
136 gl_lookup_enum_by_nr(cap),
137 ctx->NewState);
138
139 switch (cap) {
140 case GL_ALPHA_TEST:
141 if (ctx->Color.AlphaEnabled == state)
142 return;
143 FLUSH_VERTICES(ctx, _NEW_COLOR);
144 ctx->Color.AlphaEnabled = state;
145 break;
146 case GL_AUTO_NORMAL:
147 if (ctx->Eval.AutoNormal == state)
148 return;
149 FLUSH_VERTICES(ctx, _NEW_EVAL);
150 ctx->Eval.AutoNormal = state;
151 break;
152 case GL_BLEND:
153 if (ctx->Color.BlendEnabled == state)
154 return;
155
156 FLUSH_VERTICES(ctx, _NEW_COLOR);
157 ctx->Color.BlendEnabled = state;
158 /* The following needed to accomodate 1.0 RGB logic op blending */
159 ctx->Color.ColorLogicOpEnabled =
160 (ctx->Color.BlendEquation == GL_LOGIC_OP && state);
161 break;
162 case GL_CLIP_PLANE0:
163 case GL_CLIP_PLANE1:
164 case GL_CLIP_PLANE2:
165 case GL_CLIP_PLANE3:
166 case GL_CLIP_PLANE4:
167 case GL_CLIP_PLANE5: {
168 GLuint p = cap-GL_CLIP_PLANE0;
169
170 if (ctx->Transform.ClipEnabled[p] == state)
171 return;
172
173 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
174 ctx->Transform.ClipEnabled[p] = state;
175
176 if (state) {
177 ctx->_Enabled |= ENABLE_USERCLIP;
178 ctx->Transform._AnyClip++;
179
180 if (ctx->ProjectionMatrix.flags & MAT_DIRTY) {
181 _math_matrix_analyse( &ctx->ProjectionMatrix );
182 }
183
184 /* This derived state also calculated in clip.c and
185 * from gl_update_state() on changes to EyeUserPlane
186 * and ctx->ProjectionMatrix respectively.
187 */
188 gl_transform_vector( ctx->Transform._ClipUserPlane[p],
189 ctx->Transform.EyeUserPlane[p],
190 ctx->ProjectionMatrix.inv );
191 } else {
192 if (--ctx->Transform._AnyClip == 0)
193 ctx->_Enabled &= ~ENABLE_USERCLIP;
194 }
195 }
196 break;
197 case GL_COLOR_MATERIAL:
198 if (ctx->Light.ColorMaterialEnabled == state)
199 return;
200 FLUSH_VERTICES(ctx, _NEW_LIGHT);
201 ctx->Light.ColorMaterialEnabled = state;
202 if (state) {
203 FLUSH_CURRENT(ctx, 0);
204 gl_update_color_material( ctx, ctx->Current.Color );
205 }
206 break;
207 case GL_CULL_FACE:
208 if (ctx->Polygon.CullFlag == state)
209 return;
210 FLUSH_VERTICES(ctx, _NEW_POLYGON);
211 ctx->Polygon.CullFlag = state;
212 break;
213 case GL_DEPTH_TEST:
214 if (state && ctx->Visual.DepthBits==0) {
215 _mesa_warning(ctx,"glEnable(GL_DEPTH_TEST) but no depth buffer");
216 return;
217 }
218 if (ctx->Depth.Test==state)
219 return;
220 FLUSH_VERTICES(ctx, _NEW_DEPTH);
221 ctx->Depth.Test = state;
222 break;
223 case GL_DITHER:
224 if (ctx->NoDither) {
225 state = GL_FALSE; /* MESA_NO_DITHER env var */
226 }
227 if (ctx->Color.DitherFlag==state)
228 return;
229 FLUSH_VERTICES(ctx, _NEW_COLOR);
230 ctx->Color.DitherFlag = state;
231 break;
232 case GL_FOG:
233 if (ctx->Fog.Enabled==state)
234 return;
235 FLUSH_VERTICES(ctx, _NEW_FOG);
236 ctx->Fog.Enabled = state;
237 ctx->_Enabled ^= ENABLE_FOG;
238 break;
239 case GL_HISTOGRAM:
240 if (!ctx->Extensions.EXT_histogram) {
241 gl_error(ctx, GL_INVALID_ENUM, "enable GL_HISTOGRAM");
242 return;
243 }
244 if (ctx->Pixel.HistogramEnabled == state)
245 return;
246 FLUSH_VERTICES(ctx, _NEW_PIXEL);
247 ctx->Pixel.HistogramEnabled = state;
248 break;
249 case GL_LIGHT0:
250 case GL_LIGHT1:
251 case GL_LIGHT2:
252 case GL_LIGHT3:
253 case GL_LIGHT4:
254 case GL_LIGHT5:
255 case GL_LIGHT6:
256 case GL_LIGHT7:
257 if (ctx->Light.Light[cap-GL_LIGHT0].Enabled == state)
258 return;
259 FLUSH_VERTICES(ctx, _NEW_LIGHT);
260 ctx->Light.Light[cap-GL_LIGHT0].Enabled = state;
261 if (state) {
262 insert_at_tail(&ctx->Light.EnabledList,
263 &ctx->Light.Light[cap-GL_LIGHT0]);
264 }
265 else {
266 remove_from_list(&ctx->Light.Light[cap-GL_LIGHT0]);
267 }
268 break;
269 case GL_LIGHTING:
270 if (ctx->Light.Enabled == state)
271 return;
272 FLUSH_VERTICES(ctx, _NEW_LIGHT);
273 ctx->Light.Enabled = state;
274 ctx->_Enabled ^= ENABLE_LIGHT;
275 break;
276 case GL_LINE_SMOOTH:
277 if (ctx->Line.SmoothFlag == state)
278 return;
279 FLUSH_VERTICES(ctx, _NEW_LINE);
280 ctx->Line.SmoothFlag = state;
281 ctx->_TriangleCaps ^= DD_LINE_SMOOTH;
282 break;
283 case GL_LINE_STIPPLE:
284 if (ctx->Line.StippleFlag == state)
285 return;
286 FLUSH_VERTICES(ctx, _NEW_LINE);
287 ctx->Line.StippleFlag = state;
288 ctx->_TriangleCaps ^= DD_LINE_STIPPLE;
289 break;
290 case GL_INDEX_LOGIC_OP:
291 if (ctx->Color.IndexLogicOpEnabled == state)
292 return;
293 FLUSH_VERTICES(ctx, _NEW_COLOR);
294 ctx->Color.IndexLogicOpEnabled = state;
295 break;
296 case GL_COLOR_LOGIC_OP:
297 if (ctx->Color.ColorLogicOpEnabled == state)
298 return;
299 FLUSH_VERTICES(ctx, _NEW_COLOR);
300 ctx->Color.ColorLogicOpEnabled = state;
301 break;
302 case GL_MAP1_COLOR_4:
303 if (ctx->Eval.Map1Color4 == state)
304 return;
305 FLUSH_VERTICES(ctx, _NEW_EVAL);
306 ctx->Eval.Map1Color4 = state;
307 break;
308 case GL_MAP1_INDEX:
309 if (ctx->Eval.Map1Index == state)
310 return;
311 FLUSH_VERTICES(ctx, _NEW_EVAL);
312 ctx->Eval.Map1Index = state;
313 break;
314 case GL_MAP1_NORMAL:
315 if (ctx->Eval.Map1Normal == state)
316 return;
317 FLUSH_VERTICES(ctx, _NEW_EVAL);
318 ctx->Eval.Map1Normal = state;
319 break;
320 case GL_MAP1_TEXTURE_COORD_1:
321 if (ctx->Eval.Map1TextureCoord1 == state)
322 return;
323 FLUSH_VERTICES(ctx, _NEW_EVAL);
324 ctx->Eval.Map1TextureCoord1 = state;
325 break;
326 case GL_MAP1_TEXTURE_COORD_2:
327 if (ctx->Eval.Map1TextureCoord2 == state)
328 return;
329 FLUSH_VERTICES(ctx, _NEW_EVAL);
330 ctx->Eval.Map1TextureCoord2 = state;
331 break;
332 case GL_MAP1_TEXTURE_COORD_3:
333 if (ctx->Eval.Map1TextureCoord3 == state)
334 return;
335 FLUSH_VERTICES(ctx, _NEW_EVAL);
336 ctx->Eval.Map1TextureCoord3 = state;
337 break;
338 case GL_MAP1_TEXTURE_COORD_4:
339 if (ctx->Eval.Map1TextureCoord4 == state)
340 return;
341 FLUSH_VERTICES(ctx, _NEW_EVAL);
342 ctx->Eval.Map1TextureCoord4 = state;
343 break;
344 case GL_MAP1_VERTEX_3:
345 if (ctx->Eval.Map1Vertex3 == state)
346 return;
347 FLUSH_VERTICES(ctx, _NEW_EVAL);
348 ctx->Eval.Map1Vertex3 = state;
349 break;
350 case GL_MAP1_VERTEX_4:
351 if (ctx->Eval.Map1Vertex4 == state)
352 return;
353 FLUSH_VERTICES(ctx, _NEW_EVAL);
354 ctx->Eval.Map1Vertex4 = state;
355 break;
356 case GL_MAP2_COLOR_4:
357 if (ctx->Eval.Map2Color4 == state)
358 return;
359 FLUSH_VERTICES(ctx, _NEW_EVAL);
360 ctx->Eval.Map2Color4 = state;
361 break;
362 case GL_MAP2_INDEX:
363 if (ctx->Eval.Map2Index == state)
364 return;
365 FLUSH_VERTICES(ctx, _NEW_EVAL);
366 ctx->Eval.Map2Index = state;
367 break;
368 case GL_MAP2_NORMAL:
369 if (ctx->Eval.Map2Normal == state)
370 return;
371 FLUSH_VERTICES(ctx, _NEW_EVAL);
372 ctx->Eval.Map2Normal = state;
373 break;
374 case GL_MAP2_TEXTURE_COORD_1:
375 if (ctx->Eval.Map2TextureCoord1 == state)
376 return;
377 FLUSH_VERTICES(ctx, _NEW_EVAL);
378 ctx->Eval.Map2TextureCoord1 = state;
379 break;
380 case GL_MAP2_TEXTURE_COORD_2:
381 if (ctx->Eval.Map2TextureCoord2 == state)
382 return;
383 FLUSH_VERTICES(ctx, _NEW_EVAL);
384 ctx->Eval.Map2TextureCoord2 = state;
385 break;
386 case GL_MAP2_TEXTURE_COORD_3:
387 if (ctx->Eval.Map2TextureCoord3 == state)
388 return;
389 FLUSH_VERTICES(ctx, _NEW_EVAL);
390 ctx->Eval.Map2TextureCoord3 = state;
391 break;
392 case GL_MAP2_TEXTURE_COORD_4:
393 if (ctx->Eval.Map2TextureCoord4 == state)
394 return;
395 FLUSH_VERTICES(ctx, _NEW_EVAL);
396 ctx->Eval.Map2TextureCoord4 = state;
397 break;
398 case GL_MAP2_VERTEX_3:
399 if (ctx->Eval.Map2Vertex3 == state)
400 return;
401 FLUSH_VERTICES(ctx, _NEW_EVAL);
402 ctx->Eval.Map2Vertex3 = state;
403 break;
404 case GL_MAP2_VERTEX_4:
405 if (ctx->Eval.Map2Vertex4 == state)
406 return;
407 FLUSH_VERTICES(ctx, _NEW_EVAL);
408 ctx->Eval.Map2Vertex4 = state;
409 break;
410 case GL_MINMAX:
411 if (ctx->Pixel.MinMaxEnabled == state)
412 return;
413 FLUSH_VERTICES(ctx, _NEW_PIXEL);
414 ctx->Pixel.MinMaxEnabled = state;
415 break;
416 case GL_NORMALIZE:
417 if (ctx->Transform.Normalize == state)
418 return;
419 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
420 ctx->Transform.Normalize = state;
421 ctx->_Enabled ^= ENABLE_NORMALIZE;
422 break;
423 case GL_POINT_SMOOTH:
424 if (ctx->Point.SmoothFlag==state)
425 return;
426 FLUSH_VERTICES(ctx, _NEW_POINT);
427 ctx->Point.SmoothFlag = state;
428 ctx->_TriangleCaps ^= DD_POINT_SMOOTH;
429 break;
430 case GL_POLYGON_SMOOTH:
431 if (ctx->Polygon.SmoothFlag==state)
432 return;
433 FLUSH_VERTICES(ctx, _NEW_POLYGON);
434 ctx->Polygon.SmoothFlag = state;
435 ctx->_TriangleCaps ^= DD_TRI_SMOOTH;
436 break;
437 case GL_POLYGON_STIPPLE:
438 if (ctx->Polygon.StippleFlag==state)
439 return;
440 FLUSH_VERTICES(ctx, _NEW_POLYGON);
441 ctx->Polygon.StippleFlag = state;
442 ctx->_TriangleCaps ^= DD_TRI_STIPPLE;
443 break;
444 case GL_POLYGON_OFFSET_POINT:
445 if (ctx->Polygon.OffsetPoint==state)
446 return;
447 FLUSH_VERTICES(ctx, _NEW_POLYGON);
448 ctx->Polygon.OffsetPoint = state;
449 break;
450 case GL_POLYGON_OFFSET_LINE:
451 if (ctx->Polygon.OffsetLine==state)
452 return;
453 FLUSH_VERTICES(ctx, _NEW_POLYGON);
454 ctx->Polygon.OffsetLine = state;
455 break;
456 case GL_POLYGON_OFFSET_FILL:
457 /*case GL_POLYGON_OFFSET_EXT:*/
458 if (ctx->Polygon.OffsetFill==state)
459 return;
460 FLUSH_VERTICES(ctx, _NEW_POLYGON);
461 ctx->Polygon.OffsetFill = state;
462 break;
463 case GL_RESCALE_NORMAL_EXT:
464 if (ctx->Transform.RescaleNormals == state)
465 return;
466 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
467 ctx->Transform.RescaleNormals = state;
468 ctx->_Enabled ^= ENABLE_RESCALE;
469 break;
470 case GL_SCISSOR_TEST:
471 if (ctx->Scissor.Enabled==state)
472 return;
473 FLUSH_VERTICES(ctx, _NEW_SCISSOR);
474 ctx->Scissor.Enabled = state;
475 break;
476 case GL_SHARED_TEXTURE_PALETTE_EXT:
477 if (ctx->Texture.SharedPalette == state)
478 return;
479 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
480 ctx->Texture.SharedPalette = state;
481 break;
482 case GL_STENCIL_TEST:
483 if (state && ctx->Visual.StencilBits==0) {
484 _mesa_warning(ctx, "glEnable(GL_STENCIL_TEST) but no stencil buffer");
485 return;
486 }
487 if (ctx->Stencil.Enabled==state)
488 return;
489 FLUSH_VERTICES(ctx, _NEW_STENCIL);
490 ctx->Stencil.Enabled = state;
491 ctx->_TriangleCaps ^= DD_STENCIL;
492 break;
493 case GL_TEXTURE_1D: {
494 const GLuint curr = ctx->Texture.CurrentUnit;
495 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[curr];
496 GLuint newenabled = texUnit->Enabled & ~TEXTURE0_1D;
497 if (state)
498 newenabled |= TEXTURE0_1D;
499 if (!ctx->Visual.RGBAflag || texUnit->Enabled == newenabled)
500 return;
501 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
502 texUnit->Enabled = newenabled;
503 break;
504 }
505 case GL_TEXTURE_2D: {
506 const GLuint curr = ctx->Texture.CurrentUnit;
507 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[curr];
508 GLuint newenabled = texUnit->Enabled & ~TEXTURE0_2D;
509 if (state)
510 newenabled |= TEXTURE0_2D;
511 if (!ctx->Visual.RGBAflag || texUnit->Enabled == newenabled)
512 return;
513 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
514 texUnit->Enabled = newenabled;
515 break;
516 }
517 case GL_TEXTURE_3D: {
518 const GLuint curr = ctx->Texture.CurrentUnit;
519 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[curr];
520 GLuint newenabled = texUnit->Enabled & ~TEXTURE0_3D;
521 if (state)
522 newenabled |= TEXTURE0_3D;
523 if (!ctx->Visual.RGBAflag || texUnit->Enabled == newenabled)
524 return;
525 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
526 texUnit->Enabled = newenabled;
527 break;
528 }
529 case GL_TEXTURE_GEN_Q: {
530 GLuint unit = ctx->Texture.CurrentUnit;
531 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
532 GLuint newenabled = texUnit->TexGenEnabled & ~Q_BIT;
533 if (state)
534 newenabled |= Q_BIT;
535 if (texUnit->TexGenEnabled == newenabled)
536 return;
537 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
538 texUnit->TexGenEnabled = newenabled;
539 break;
540 }
541 case GL_TEXTURE_GEN_R: {
542 GLuint unit = ctx->Texture.CurrentUnit;
543 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
544 GLuint newenabled = texUnit->TexGenEnabled & ~R_BIT;
545 if (state)
546 newenabled |= R_BIT;
547 if (texUnit->TexGenEnabled == newenabled)
548 return;
549 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
550 texUnit->TexGenEnabled = newenabled;
551 break;
552 }
553 break;
554 case GL_TEXTURE_GEN_S: {
555 GLuint unit = ctx->Texture.CurrentUnit;
556 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
557 GLuint newenabled = texUnit->TexGenEnabled & ~S_BIT;
558 if (state)
559 newenabled |= S_BIT;
560 if (texUnit->TexGenEnabled == newenabled)
561 return;
562 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
563 texUnit->TexGenEnabled = newenabled;
564 break;
565 }
566 break;
567 case GL_TEXTURE_GEN_T: {
568 GLuint unit = ctx->Texture.CurrentUnit;
569 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
570 GLuint newenabled = texUnit->TexGenEnabled & ~T_BIT;
571 if (state)
572 newenabled |= T_BIT;
573 if (texUnit->TexGenEnabled == newenabled)
574 return;
575 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
576 texUnit->TexGenEnabled = newenabled;
577 break;
578 }
579 break;
580
581 /*
582 * CLIENT STATE!!!
583 */
584 case GL_VERTEX_ARRAY:
585 case GL_NORMAL_ARRAY:
586 case GL_COLOR_ARRAY:
587 case GL_INDEX_ARRAY:
588 case GL_TEXTURE_COORD_ARRAY:
589 case GL_EDGE_FLAG_ARRAY:
590 case GL_FOG_COORDINATE_ARRAY_EXT:
591 case GL_SECONDARY_COLOR_ARRAY_EXT:
592 client_state( ctx, cap, state );
593 return;
594
595 /* GL_HP_occlusion_test */
596 case GL_OCCLUSION_TEST_HP:
597 if (!ctx->Extensions.HP_occlusion_test) {
598 gl_error( ctx, GL_INVALID_ENUM, state ? "glEnable": "glDisable" );
599 return;
600 }
601 if (ctx->Depth.OcclusionTest == state)
602 return;
603 FLUSH_VERTICES(ctx, _NEW_DEPTH);
604 ctx->Depth.OcclusionTest = state;
605 if (state)
606 ctx->OcclusionResult = ctx->OcclusionResultSaved;
607 else
608 ctx->OcclusionResultSaved = ctx->OcclusionResult;
609 break;
610
611 /* GL_SGIS_pixel_texture */
612 case GL_PIXEL_TEXTURE_SGIS:
613 if (!ctx->Extensions.SGIS_pixel_texture) {
614 gl_error( ctx, GL_INVALID_ENUM, state ? "glEnable": "glDisable" );
615 return;
616 }
617 if (ctx->Pixel.PixelTextureEnabled == state)
618 return;
619 FLUSH_VERTICES(ctx, _NEW_PIXEL);
620 ctx->Pixel.PixelTextureEnabled = state;
621 break;
622
623 /* GL_SGIX_pixel_texture */
624 case GL_PIXEL_TEX_GEN_SGIX:
625 if (!ctx->Extensions.SGIX_pixel_texture) {
626 gl_error( ctx, GL_INVALID_ENUM, state ? "glEnable": "glDisable" );
627 return;
628 }
629 if (ctx->Pixel.PixelTextureEnabled == state)
630 return;
631 FLUSH_VERTICES(ctx, _NEW_PIXEL);
632 ctx->Pixel.PixelTextureEnabled = state;
633 break;
634
635 /* GL_SGI_color_table */
636 case GL_COLOR_TABLE_SGI:
637 if (!ctx->Extensions.SGI_color_table) {
638 gl_error( ctx, GL_INVALID_ENUM, state ? "glEnable": "glDisable" );
639 return;
640 }
641 if (ctx->Pixel.ColorTableEnabled == state)
642 return;
643 FLUSH_VERTICES(ctx, _NEW_PIXEL);
644 ctx->Pixel.ColorTableEnabled = state;
645 break;
646 case GL_POST_CONVOLUTION_COLOR_TABLE_SGI:
647 if (!ctx->Extensions.SGI_color_table) {
648 gl_error( ctx, GL_INVALID_ENUM, state ? "glEnable": "glDisable" );
649 return;
650 }
651 if (ctx->Pixel.PostConvolutionColorTableEnabled == state)
652 return;
653 FLUSH_VERTICES(ctx, _NEW_PIXEL);
654 ctx->Pixel.PostConvolutionColorTableEnabled = state;
655 break;
656 case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI:
657 if (!ctx->Extensions.SGI_color_table) {
658 gl_error( ctx, GL_INVALID_ENUM, state ? "glEnable": "glDisable" );
659 return;
660 }
661 if (ctx->Pixel.PostColorMatrixColorTableEnabled == state)
662 return;
663 FLUSH_VERTICES(ctx, _NEW_PIXEL);
664 ctx->Pixel.PostColorMatrixColorTableEnabled = state;
665 break;
666
667 /* GL_EXT_convolution */
668 case GL_CONVOLUTION_1D:
669 if (!ctx->Extensions.EXT_convolution) {
670 gl_error(ctx, GL_INVALID_ENUM, state ? "glEnable" : "glDisable");
671 return;
672 }
673 if (ctx->Pixel.Convolution1DEnabled == state)
674 return;
675 FLUSH_VERTICES(ctx, _NEW_PIXEL);
676 ctx->Pixel.Convolution1DEnabled = state;
677 break;
678 case GL_CONVOLUTION_2D:
679 if (!ctx->Extensions.EXT_convolution) {
680 gl_error(ctx, GL_INVALID_ENUM, state ? "glEnable" : "glDisable");
681 return;
682 }
683 if (ctx->Pixel.Convolution2DEnabled == state)
684 return;
685 FLUSH_VERTICES(ctx, _NEW_PIXEL);
686 ctx->Pixel.Convolution2DEnabled = state;
687 break;
688 case GL_SEPARABLE_2D:
689 if (!ctx->Extensions.EXT_convolution) {
690 gl_error(ctx, GL_INVALID_ENUM, state ? "glEnable" : "glDisable");
691 return;
692 }
693 if (ctx->Pixel.Separable2DEnabled == state)
694 return;
695 FLUSH_VERTICES(ctx, _NEW_PIXEL);
696 ctx->Pixel.Separable2DEnabled = state;
697 break;
698
699 /* GL_ARB_texture_cube_map */
700 case GL_TEXTURE_CUBE_MAP_ARB: {
701 const GLuint curr = ctx->Texture.CurrentUnit;
702 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[curr];
703 GLuint newenabled = texUnit->Enabled & ~TEXTURE0_CUBE;
704 if (state)
705 newenabled |= TEXTURE0_CUBE;
706 if (!ctx->Extensions.ARB_texture_cube_map) {
707 gl_error(ctx, GL_INVALID_ENUM, state ? "glEnable" : "glDisable");
708 return;
709 }
710 if (!ctx->Visual.RGBAflag || texUnit->Enabled == newenabled)
711 return;
712 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
713 texUnit->Enabled = newenabled;
714 break;
715 }
716 /* GL_EXT_secondary_color */
717 case GL_COLOR_SUM_EXT:
718 if (!ctx->Extensions.EXT_secondary_color) {
719 gl_error(ctx, GL_INVALID_ENUM, state ? "glEnable" : "glDisable");
720 return;
721 }
722 if (ctx->Fog.ColorSumEnabled == state)
723 return;
724 FLUSH_VERTICES(ctx, _NEW_FOG);
725 ctx->Fog.ColorSumEnabled = state;
726 ctx->_TriangleCaps ^= DD_SEPERATE_SPECULAR;
727 break;
728
729 /* GL_MESA_sprite_point */
730 case GL_SPRITE_POINT_MESA:
731 if (!ctx->Extensions.MESA_sprite_point) {
732 gl_error(ctx, GL_INVALID_ENUM, state ? "glEnable" : "glDisable");
733 return;
734 }
735 if (ctx->Point.SpriteMode == state)
736 return;
737 FLUSH_VERTICES(ctx, _NEW_POINT);
738 ctx->Point.SpriteMode = state;
739 break;
740
741 default:
742 gl_error(ctx, GL_INVALID_ENUM, state ? "glEnable" : "glDisable");
743 return;
744 }
745
746 if (ctx->Driver.Enable) {
747 (*ctx->Driver.Enable)( ctx, cap, state );
748 }
749 }
750
751
752
753
754 void
755 _mesa_Enable( GLenum cap )
756 {
757 GET_CURRENT_CONTEXT(ctx);
758 _mesa_set_enable( ctx, cap, GL_TRUE );
759 }
760
761
762
763 void
764 _mesa_Disable( GLenum cap )
765 {
766 GET_CURRENT_CONTEXT(ctx);
767 _mesa_set_enable( ctx, cap, GL_FALSE );
768 }
769
770
771
772 GLboolean
773 _mesa_IsEnabled( GLenum cap )
774 {
775 GET_CURRENT_CONTEXT(ctx);
776 switch (cap) {
777 case GL_ALPHA_TEST:
778 return ctx->Color.AlphaEnabled;
779 case GL_AUTO_NORMAL:
780 return ctx->Eval.AutoNormal;
781 case GL_BLEND:
782 return ctx->Color.BlendEnabled;
783 case GL_CLIP_PLANE0:
784 case GL_CLIP_PLANE1:
785 case GL_CLIP_PLANE2:
786 case GL_CLIP_PLANE3:
787 case GL_CLIP_PLANE4:
788 case GL_CLIP_PLANE5:
789 return ctx->Transform.ClipEnabled[cap-GL_CLIP_PLANE0];
790 case GL_COLOR_MATERIAL:
791 return ctx->Light.ColorMaterialEnabled;
792 case GL_CULL_FACE:
793 return ctx->Polygon.CullFlag;
794 case GL_DEPTH_TEST:
795 return ctx->Depth.Test;
796 case GL_DITHER:
797 return ctx->Color.DitherFlag;
798 case GL_FOG:
799 return ctx->Fog.Enabled;
800 case GL_HISTOGRAM:
801 if (ctx->Extensions.EXT_histogram) {
802 return ctx->Pixel.HistogramEnabled;
803 }
804 else {
805 gl_error(ctx, GL_INVALID_ENUM, "glIsEnabled");
806 return GL_FALSE;
807 }
808 case GL_LIGHTING:
809 return ctx->Light.Enabled;
810 case GL_LIGHT0:
811 case GL_LIGHT1:
812 case GL_LIGHT2:
813 case GL_LIGHT3:
814 case GL_LIGHT4:
815 case GL_LIGHT5:
816 case GL_LIGHT6:
817 case GL_LIGHT7:
818 return ctx->Light.Light[cap-GL_LIGHT0].Enabled;
819 case GL_LINE_SMOOTH:
820 return ctx->Line.SmoothFlag;
821 case GL_LINE_STIPPLE:
822 return ctx->Line.StippleFlag;
823 case GL_INDEX_LOGIC_OP:
824 return ctx->Color.IndexLogicOpEnabled;
825 case GL_COLOR_LOGIC_OP:
826 return ctx->Color.ColorLogicOpEnabled;
827 case GL_MAP1_COLOR_4:
828 return ctx->Eval.Map1Color4;
829 case GL_MAP1_INDEX:
830 return ctx->Eval.Map1Index;
831 case GL_MAP1_NORMAL:
832 return ctx->Eval.Map1Normal;
833 case GL_MAP1_TEXTURE_COORD_1:
834 return ctx->Eval.Map1TextureCoord1;
835 case GL_MAP1_TEXTURE_COORD_2:
836 return ctx->Eval.Map1TextureCoord2;
837 case GL_MAP1_TEXTURE_COORD_3:
838 return ctx->Eval.Map1TextureCoord3;
839 case GL_MAP1_TEXTURE_COORD_4:
840 return ctx->Eval.Map1TextureCoord4;
841 case GL_MAP1_VERTEX_3:
842 return ctx->Eval.Map1Vertex3;
843 case GL_MAP1_VERTEX_4:
844 return ctx->Eval.Map1Vertex4;
845 case GL_MAP2_COLOR_4:
846 return ctx->Eval.Map2Color4;
847 case GL_MAP2_INDEX:
848 return ctx->Eval.Map2Index;
849 case GL_MAP2_NORMAL:
850 return ctx->Eval.Map2Normal;
851 case GL_MAP2_TEXTURE_COORD_1:
852 return ctx->Eval.Map2TextureCoord1;
853 case GL_MAP2_TEXTURE_COORD_2:
854 return ctx->Eval.Map2TextureCoord2;
855 case GL_MAP2_TEXTURE_COORD_3:
856 return ctx->Eval.Map2TextureCoord3;
857 case GL_MAP2_TEXTURE_COORD_4:
858 return ctx->Eval.Map2TextureCoord4;
859 case GL_MAP2_VERTEX_3:
860 return ctx->Eval.Map2Vertex3;
861 case GL_MAP2_VERTEX_4:
862 return ctx->Eval.Map2Vertex4;
863 case GL_MINMAX:
864 return ctx->Pixel.MinMaxEnabled;
865 case GL_NORMALIZE:
866 return ctx->Transform.Normalize;
867 case GL_POINT_SMOOTH:
868 return ctx->Point.SmoothFlag;
869 case GL_POLYGON_SMOOTH:
870 return ctx->Polygon.SmoothFlag;
871 case GL_POLYGON_STIPPLE:
872 return ctx->Polygon.StippleFlag;
873 case GL_POLYGON_OFFSET_POINT:
874 return ctx->Polygon.OffsetPoint;
875 case GL_POLYGON_OFFSET_LINE:
876 return ctx->Polygon.OffsetLine;
877 case GL_POLYGON_OFFSET_FILL:
878 /*case GL_POLYGON_OFFSET_EXT:*/
879 return ctx->Polygon.OffsetFill;
880 case GL_RESCALE_NORMAL_EXT:
881 return ctx->Transform.RescaleNormals;
882 case GL_SCISSOR_TEST:
883 return ctx->Scissor.Enabled;
884 case GL_SHARED_TEXTURE_PALETTE_EXT:
885 return ctx->Texture.SharedPalette;
886 case GL_STENCIL_TEST:
887 return ctx->Stencil.Enabled;
888 case GL_TEXTURE_1D:
889 {
890 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
891 return (texUnit->Enabled & TEXTURE0_1D) ? GL_TRUE : GL_FALSE;
892 }
893 case GL_TEXTURE_2D:
894 {
895 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
896 return (texUnit->Enabled & TEXTURE0_2D) ? GL_TRUE : GL_FALSE;
897 }
898 case GL_TEXTURE_3D:
899 {
900 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
901 return (texUnit->Enabled & TEXTURE0_3D) ? GL_TRUE : GL_FALSE;
902 }
903 case GL_TEXTURE_GEN_Q:
904 {
905 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
906 return (texUnit->TexGenEnabled & Q_BIT) ? GL_TRUE : GL_FALSE;
907 }
908 case GL_TEXTURE_GEN_R:
909 {
910 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
911 return (texUnit->TexGenEnabled & R_BIT) ? GL_TRUE : GL_FALSE;
912 }
913 case GL_TEXTURE_GEN_S:
914 {
915 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
916 return (texUnit->TexGenEnabled & S_BIT) ? GL_TRUE : GL_FALSE;
917 }
918 case GL_TEXTURE_GEN_T:
919 {
920 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
921 return (texUnit->TexGenEnabled & T_BIT) ? GL_TRUE : GL_FALSE;
922 }
923
924 /*
925 * CLIENT STATE!!!
926 */
927 case GL_VERTEX_ARRAY:
928 return ctx->Array.Vertex.Enabled;
929 case GL_NORMAL_ARRAY:
930 return ctx->Array.Normal.Enabled;
931 case GL_COLOR_ARRAY:
932 return ctx->Array.Color.Enabled;
933 case GL_INDEX_ARRAY:
934 return ctx->Array.Index.Enabled;
935 case GL_TEXTURE_COORD_ARRAY:
936 return ctx->Array.TexCoord[ctx->Array.ActiveTexture].Enabled;
937 case GL_EDGE_FLAG_ARRAY:
938 return ctx->Array.EdgeFlag.Enabled;
939
940 /* GL_HP_occlusion_test */
941 case GL_OCCLUSION_TEST_HP:
942 if (ctx->Extensions.HP_occlusion_test) {
943 return ctx->Depth.OcclusionTest;
944 }
945 else {
946 gl_error( ctx, GL_INVALID_ENUM, "glIsEnabled" );
947 return GL_FALSE;
948 }
949
950 /* GL_SGIS_pixel_texture */
951 case GL_PIXEL_TEXTURE_SGIS:
952 return ctx->Pixel.PixelTextureEnabled;
953
954 /* GL_SGIX_pixel_texture */
955 case GL_PIXEL_TEX_GEN_SGIX:
956 return ctx->Pixel.PixelTextureEnabled;
957
958 /* GL_SGI_color_table */
959 case GL_COLOR_TABLE_SGI:
960 return ctx->Pixel.ColorTableEnabled;
961 case GL_POST_CONVOLUTION_COLOR_TABLE_SGI:
962 return ctx->Pixel.PostConvolutionColorTableEnabled;
963 case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI:
964 return ctx->Pixel.PostColorMatrixColorTableEnabled;
965
966 /* GL_EXT_convolution */
967 case GL_CONVOLUTION_1D:
968 return ctx->Pixel.Convolution1DEnabled;
969 case GL_CONVOLUTION_2D:
970 return ctx->Pixel.Convolution2DEnabled;
971 case GL_SEPARABLE_2D:
972 return ctx->Pixel.Separable2DEnabled;
973
974 /* GL_ARB_texture_cube_map */
975 case GL_TEXTURE_CUBE_MAP_ARB:
976 if (ctx->Extensions.ARB_texture_cube_map) {
977 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
978 return (texUnit->Enabled & TEXTURE0_CUBE) ? GL_TRUE : GL_FALSE;
979 }
980 else {
981 gl_error(ctx, GL_INVALID_ENUM, "glIsEnabled");
982 return GL_FALSE;
983 }
984
985 /* GL_MESA_sprite_point */
986 case GL_SPRITE_POINT_MESA:
987 return ctx->Point.SpriteMode;
988
989 default:
990 gl_error( ctx, GL_INVALID_ENUM, "glIsEnabled" );
991 return GL_FALSE;
992 }
993 }
994
995
996
997
998
999
1000