1 /* $Id: enable.c,v 1.23 1997/10/29 02:23:54 brianp Exp $ */
4 * Mesa 3-D graphics library
6 * Copyright (C) 1995-1997 Brian Paul
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the Free
20 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 * Revision 1.23 1997/10/29 02:23:54 brianp
27 * added UseGlobalTexturePalette() dd function (David Bucciarelli v20 3dfx)
29 * Revision 1.22 1997/10/16 01:59:08 brianp
30 * added GL_EXT_shared_texture_palette extension
32 * Revision 1.21 1997/07/24 01:25:01 brianp
33 * changed precompiled header symbol from PCH to PC_HEADER
35 * Revision 1.20 1997/06/20 02:20:32 brianp
36 * replaced Current.IntColor with Current.ByteColor
38 * Revision 1.19 1997/05/31 16:57:14 brianp
39 * added MESA_NO_RASTER env var support
41 * Revision 1.18 1997/05/28 03:24:22 brianp
42 * added precompiled header (PCH) support
44 * Revision 1.17 1997/04/24 01:49:30 brianp
45 * call gl_set_color_function() instead of directly setting pointers
47 * Revision 1.16 1997/04/12 16:54:05 brianp
48 * new NEW_POLYGON state flag
50 * Revision 1.15 1997/04/12 16:20:27 brianp
51 * removed call to Driver.Dither()
53 * Revision 1.14 1997/04/02 03:10:36 brianp
54 * changed some #include's
56 * Revision 1.13 1997/02/27 19:59:08 brianp
57 * issue a warning if enable depth or stencil test without such a buffer
59 * Revision 1.12 1997/02/09 19:53:43 brianp
60 * now use TEXTURE_xD enable constants
62 * Revision 1.11 1997/02/09 18:49:37 brianp
63 * added GL_EXT_texture3D support
65 * Revision 1.10 1997/01/28 22:13:42 brianp
66 * now there's separate state for CI and RGBA logic op enabled
68 * Revision 1.9 1996/12/18 20:00:57 brianp
69 * gl_set_material() now takes a bitmask instead of face and pname
71 * Revision 1.8 1996/12/11 20:16:49 brianp
72 * more work on the GL_COLOR_MATERIAL bug
74 * Revision 1.7 1996/12/09 22:51:51 brianp
75 * update API Color4f and Color4ub pointers for GL_COLOR_MATERIAL
77 * Revision 1.6 1996/12/07 10:21:07 brianp
78 * call gl_set_material() instead of gl_Materialfv()
80 * Revision 1.5 1996/11/09 03:11:18 brianp
81 * added missing GL_EXT_vertex_array caps to gl_enable()
83 * Revision 1.4 1996/10/11 03:44:09 brianp
84 * added comments for GL_POLYGON_OFFSET_EXT symbol
86 * Revision 1.3 1996/09/27 01:26:40 brianp
87 * removed unused variables
89 * Revision 1.2 1996/09/15 14:17:30 brianp
90 * now use GLframebuffer and GLvisual
92 * Revision 1.1 1996/09/13 01:38:16 brianp
116 * Perform glEnable and glDisable calls.
118 static void gl_enable( GLcontext
* ctx
, GLenum cap
, GLboolean state
)
122 if (INSIDE_BEGIN_END(ctx
)) {
124 gl_error( ctx
, GL_INVALID_OPERATION
, "glEnable" );
127 gl_error( ctx
, GL_INVALID_OPERATION
, "glDisable" );
134 if (ctx
->Color
.AlphaEnabled
!=state
) {
135 ctx
->Color
.AlphaEnabled
= state
;
136 ctx
->NewState
|= NEW_RASTER_OPS
;
140 ctx
->Eval
.AutoNormal
= state
;
143 if (ctx
->Color
.BlendEnabled
!=state
) {
144 ctx
->Color
.BlendEnabled
= state
;
145 /* The following needed to accomodate 1.0 RGB logic op blending */
146 ctx
->Color
.ColorLogicOpEnabled
= GL_FALSE
;
147 ctx
->NewState
|= NEW_RASTER_OPS
;
156 ctx
->Transform
.ClipEnabled
[cap
-GL_CLIP_PLANE0
] = state
;
157 /* Check if any clip planes enabled */
158 ctx
->Transform
.AnyClip
= GL_FALSE
;
159 for (p
=0;p
<MAX_CLIP_PLANES
;p
++) {
160 if (ctx
->Transform
.ClipEnabled
[p
]) {
161 ctx
->Transform
.AnyClip
= GL_TRUE
;
166 case GL_COLOR_MATERIAL
:
167 if (ctx
->Light
.ColorMaterialEnabled
!=state
) {
168 ctx
->Light
.ColorMaterialEnabled
= state
;
171 color
[0] = ctx
->Current
.ByteColor
[0] * ctx
->Visual
->InvRedScale
;
172 color
[1] = ctx
->Current
.ByteColor
[1] * ctx
->Visual
->InvGreenScale
;
173 color
[2] = ctx
->Current
.ByteColor
[2] * ctx
->Visual
->InvBlueScale
;
174 color
[3] = ctx
->Current
.ByteColor
[3] * ctx
->Visual
->InvAlphaScale
;
175 /* update material with current color */
176 gl_set_material( ctx
, ctx
->Light
.ColorMaterialBitmask
, color
);
178 gl_set_color_function(ctx
);
179 ctx
->NewState
|= NEW_LIGHTING
;
183 if (ctx
->Polygon
.CullFlag
!=state
) {
184 ctx
->Polygon
.CullFlag
= state
;
185 ctx
->NewState
|= NEW_POLYGON
;
189 if (state
&& ctx
->Visual
->DepthBits
==0) {
190 gl_warning(ctx
,"glEnable(GL_DEPTH_TEST) but no depth buffer");
193 if (ctx
->Depth
.Test
!=state
) {
194 ctx
->Depth
.Test
= state
;
195 ctx
->NewState
|= NEW_RASTER_OPS
;
200 /* MESA_NO_DITHER env var */
203 if (ctx
->Color
.DitherFlag
!=state
) {
204 ctx
->Color
.DitherFlag
= state
;
205 ctx
->NewState
|= NEW_RASTER_OPS
;
209 if (ctx
->Fog
.Enabled
!=state
) {
210 ctx
->Fog
.Enabled
= state
;
211 ctx
->NewState
|= NEW_RASTER_OPS
;
222 ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
= state
;
223 ctx
->NewState
|= NEW_LIGHTING
;
226 if (ctx
->Light
.Enabled
!=state
) {
227 ctx
->Light
.Enabled
= state
;
228 ctx
->NewState
|= NEW_LIGHTING
;
232 if (ctx
->Line
.SmoothFlag
!=state
) {
233 ctx
->Line
.SmoothFlag
= state
;
234 ctx
->NewState
|= NEW_RASTER_OPS
;
237 case GL_LINE_STIPPLE
:
238 if (ctx
->Line
.StippleFlag
!=state
) {
239 ctx
->Line
.StippleFlag
= state
;
240 ctx
->NewState
|= NEW_RASTER_OPS
;
243 case GL_INDEX_LOGIC_OP
:
244 if (ctx
->Color
.IndexLogicOpEnabled
!=state
) {
245 ctx
->NewState
|= NEW_RASTER_OPS
;
247 ctx
->Color
.IndexLogicOpEnabled
= state
;
249 case GL_COLOR_LOGIC_OP
:
250 if (ctx
->Color
.ColorLogicOpEnabled
!=state
) {
251 ctx
->NewState
|= NEW_RASTER_OPS
;
253 ctx
->Color
.ColorLogicOpEnabled
= state
;
255 case GL_MAP1_COLOR_4
:
256 ctx
->Eval
.Map1Color4
= state
;
259 ctx
->Eval
.Map1Index
= state
;
262 ctx
->Eval
.Map1Normal
= state
;
264 case GL_MAP1_TEXTURE_COORD_1
:
265 ctx
->Eval
.Map1TextureCoord1
= state
;
267 case GL_MAP1_TEXTURE_COORD_2
:
268 ctx
->Eval
.Map1TextureCoord2
= state
;
270 case GL_MAP1_TEXTURE_COORD_3
:
271 ctx
->Eval
.Map1TextureCoord3
= state
;
273 case GL_MAP1_TEXTURE_COORD_4
:
274 ctx
->Eval
.Map1TextureCoord4
= state
;
276 case GL_MAP1_VERTEX_3
:
277 ctx
->Eval
.Map1Vertex3
= state
;
279 case GL_MAP1_VERTEX_4
:
280 ctx
->Eval
.Map1Vertex4
= state
;
282 case GL_MAP2_COLOR_4
:
283 ctx
->Eval
.Map2Color4
= state
;
286 ctx
->Eval
.Map2Index
= state
;
289 ctx
->Eval
.Map2Normal
= state
;
291 case GL_MAP2_TEXTURE_COORD_1
:
292 ctx
->Eval
.Map2TextureCoord1
= state
;
294 case GL_MAP2_TEXTURE_COORD_2
:
295 ctx
->Eval
.Map2TextureCoord2
= state
;
297 case GL_MAP2_TEXTURE_COORD_3
:
298 ctx
->Eval
.Map2TextureCoord3
= state
;
300 case GL_MAP2_TEXTURE_COORD_4
:
301 ctx
->Eval
.Map2TextureCoord4
= state
;
303 case GL_MAP2_VERTEX_3
:
304 ctx
->Eval
.Map2Vertex3
= state
;
306 case GL_MAP2_VERTEX_4
:
307 ctx
->Eval
.Map2Vertex4
= state
;
310 ctx
->Transform
.Normalize
= state
;
312 case GL_POINT_SMOOTH
:
313 if (ctx
->Point
.SmoothFlag
!=state
) {
314 ctx
->Point
.SmoothFlag
= state
;
315 ctx
->NewState
|= NEW_RASTER_OPS
;
318 case GL_POLYGON_SMOOTH
:
319 if (ctx
->Polygon
.SmoothFlag
!=state
) {
320 ctx
->Polygon
.SmoothFlag
= state
;
321 ctx
->NewState
|= NEW_RASTER_OPS
;
324 case GL_POLYGON_STIPPLE
:
325 if (ctx
->Polygon
.StippleFlag
!=state
) {
326 ctx
->Polygon
.StippleFlag
= state
;
327 ctx
->NewState
|= NEW_RASTER_OPS
;
330 case GL_POLYGON_OFFSET_POINT
:
331 if (ctx
->Polygon
.OffsetPoint
!=state
) {
332 ctx
->Polygon
.OffsetPoint
= state
;
333 ctx
->NewState
|= NEW_POLYGON
;
336 case GL_POLYGON_OFFSET_LINE
:
337 if (ctx
->Polygon
.OffsetLine
!=state
) {
338 ctx
->Polygon
.OffsetLine
= state
;
339 ctx
->NewState
|= NEW_POLYGON
;
342 case GL_POLYGON_OFFSET_FILL
:
343 /*case GL_POLYGON_OFFSET_EXT:*/
344 if (ctx
->Polygon
.OffsetFill
!=state
) {
345 ctx
->Polygon
.OffsetFill
= state
;
346 ctx
->NewState
|= NEW_POLYGON
;
349 case GL_SCISSOR_TEST
:
350 if (ctx
->Scissor
.Enabled
!=state
) {
351 ctx
->Scissor
.Enabled
= state
;
352 ctx
->NewState
|= NEW_RASTER_OPS
;
355 case GL_STENCIL_TEST
:
356 if (state
&& ctx
->Visual
->StencilBits
==0) {
357 gl_warning(ctx
, "glEnable(GL_STENCIL_TEST) but no stencil buffer");
360 if (ctx
->Stencil
.Enabled
!=state
) {
361 ctx
->Stencil
.Enabled
= state
;
362 ctx
->NewState
|= NEW_RASTER_OPS
;
366 if (ctx
->Visual
->RGBAflag
) {
367 /* texturing only works in RGB mode */
369 ctx
->Texture
.Enabled
|= TEXTURE_1D
;
372 ctx
->Texture
.Enabled
&= (~TEXTURE_1D
);
374 ctx
->NewState
|= (NEW_RASTER_OPS
| NEW_TEXTURING
);
378 if (ctx
->Visual
->RGBAflag
) {
379 /* texturing only works in RGB mode */
381 ctx
->Texture
.Enabled
|= TEXTURE_2D
;
384 ctx
->Texture
.Enabled
&= (~TEXTURE_2D
);
386 ctx
->NewState
|= (NEW_RASTER_OPS
| NEW_TEXTURING
);
389 case GL_TEXTURE_GEN_Q
:
391 ctx
->Texture
.TexGenEnabled
|= Q_BIT
;
394 ctx
->Texture
.TexGenEnabled
&= ~Q_BIT
;
396 ctx
->NewState
|= NEW_TEXTURING
;
398 case GL_TEXTURE_GEN_R
:
400 ctx
->Texture
.TexGenEnabled
|= R_BIT
;
403 ctx
->Texture
.TexGenEnabled
&= ~R_BIT
;
405 ctx
->NewState
|= NEW_TEXTURING
;
407 case GL_TEXTURE_GEN_S
:
409 ctx
->Texture
.TexGenEnabled
|= S_BIT
;
412 ctx
->Texture
.TexGenEnabled
&= ~S_BIT
;
414 ctx
->NewState
|= NEW_TEXTURING
;
416 case GL_TEXTURE_GEN_T
:
418 ctx
->Texture
.TexGenEnabled
|= T_BIT
;
421 ctx
->Texture
.TexGenEnabled
&= ~T_BIT
;
423 ctx
->NewState
|= NEW_TEXTURING
;
429 case GL_VERTEX_ARRAY
:
430 ctx
->Array
.VertexEnabled
= state
;
432 case GL_NORMAL_ARRAY
:
433 ctx
->Array
.NormalEnabled
= state
;
436 ctx
->Array
.ColorEnabled
= state
;
439 ctx
->Array
.IndexEnabled
= state
;
441 case GL_TEXTURE_COORD_ARRAY
:
442 ctx
->Array
.TexCoordEnabled
= state
;
444 case GL_EDGE_FLAG_ARRAY
:
445 ctx
->Array
.EdgeFlagEnabled
= state
;
450 gl_error( ctx
, GL_INVALID_ENUM
, "glEnable" );
453 gl_error( ctx
, GL_INVALID_ENUM
, "glDisable" );
462 void gl_Enable( GLcontext
* ctx
, GLenum cap
)
464 gl_enable( ctx
, cap
, GL_TRUE
);
469 void gl_Disable( GLcontext
* ctx
, GLenum cap
)
471 gl_enable( ctx
, cap
, GL_FALSE
);
476 GLboolean
gl_IsEnabled( GLcontext
* ctx
, GLenum cap
)
480 return ctx
->Color
.AlphaEnabled
;
482 return ctx
->Eval
.AutoNormal
;
484 return ctx
->Color
.BlendEnabled
;
491 return ctx
->Transform
.ClipEnabled
[cap
-GL_CLIP_PLANE0
];
492 case GL_COLOR_MATERIAL
:
493 return ctx
->Light
.ColorMaterialEnabled
;
495 return ctx
->Polygon
.CullFlag
;
497 return ctx
->Depth
.Test
;
499 return ctx
->Color
.DitherFlag
;
501 return ctx
->Fog
.Enabled
;
503 return ctx
->Light
.Enabled
;
512 return ctx
->Light
.Light
[cap
-GL_LIGHT0
].Enabled
;
514 return ctx
->Line
.SmoothFlag
;
515 case GL_LINE_STIPPLE
:
516 return ctx
->Line
.StippleFlag
;
517 case GL_INDEX_LOGIC_OP
:
518 return ctx
->Color
.IndexLogicOpEnabled
;
519 case GL_COLOR_LOGIC_OP
:
520 return ctx
->Color
.ColorLogicOpEnabled
;
521 case GL_MAP1_COLOR_4
:
522 return ctx
->Eval
.Map1Color4
;
524 return ctx
->Eval
.Map1Index
;
526 return ctx
->Eval
.Map1Normal
;
527 case GL_MAP1_TEXTURE_COORD_1
:
528 return ctx
->Eval
.Map1TextureCoord1
;
529 case GL_MAP1_TEXTURE_COORD_2
:
530 return ctx
->Eval
.Map1TextureCoord2
;
531 case GL_MAP1_TEXTURE_COORD_3
:
532 return ctx
->Eval
.Map1TextureCoord3
;
533 case GL_MAP1_TEXTURE_COORD_4
:
534 return ctx
->Eval
.Map1TextureCoord4
;
535 case GL_MAP1_VERTEX_3
:
536 return ctx
->Eval
.Map1Vertex3
;
537 case GL_MAP1_VERTEX_4
:
538 return ctx
->Eval
.Map1Vertex4
;
539 case GL_MAP2_COLOR_4
:
540 return ctx
->Eval
.Map2Color4
;
542 return ctx
->Eval
.Map2Index
;
544 return ctx
->Eval
.Map2Normal
;
545 case GL_MAP2_TEXTURE_COORD_1
:
546 return ctx
->Eval
.Map2TextureCoord1
;
547 case GL_MAP2_TEXTURE_COORD_2
:
548 return ctx
->Eval
.Map2TextureCoord2
;
549 case GL_MAP2_TEXTURE_COORD_3
:
550 return ctx
->Eval
.Map2TextureCoord3
;
551 case GL_MAP2_TEXTURE_COORD_4
:
552 return ctx
->Eval
.Map2TextureCoord4
;
553 case GL_MAP2_VERTEX_3
:
554 return ctx
->Eval
.Map2Vertex3
;
555 case GL_MAP2_VERTEX_4
:
556 return ctx
->Eval
.Map2Vertex4
;
558 return ctx
->Transform
.Normalize
;
559 case GL_POINT_SMOOTH
:
560 return ctx
->Point
.SmoothFlag
;
561 case GL_POLYGON_SMOOTH
:
562 return ctx
->Polygon
.SmoothFlag
;
563 case GL_POLYGON_STIPPLE
:
564 return ctx
->Polygon
.StippleFlag
;
565 case GL_POLYGON_OFFSET_POINT
:
566 return ctx
->Polygon
.OffsetPoint
;
567 case GL_POLYGON_OFFSET_LINE
:
568 return ctx
->Polygon
.OffsetLine
;
569 case GL_POLYGON_OFFSET_FILL
:
570 /*case GL_POLYGON_OFFSET_EXT:*/
571 return ctx
->Polygon
.OffsetFill
;
572 case GL_SCISSOR_TEST
:
573 return ctx
->Scissor
.Enabled
;
574 case GL_STENCIL_TEST
:
575 return ctx
->Stencil
.Enabled
;
577 return (ctx
->Texture
.Enabled
& TEXTURE_1D
) ? GL_TRUE
: GL_FALSE
;
579 return (ctx
->Texture
.Enabled
& TEXTURE_2D
) ? GL_TRUE
: GL_FALSE
;
580 case GL_TEXTURE_GEN_Q
:
581 return (ctx
->Texture
.TexGenEnabled
& Q_BIT
) ? GL_TRUE
: GL_FALSE
;
582 case GL_TEXTURE_GEN_R
:
583 return (ctx
->Texture
.TexGenEnabled
& R_BIT
) ? GL_TRUE
: GL_FALSE
;
584 case GL_TEXTURE_GEN_S
:
585 return (ctx
->Texture
.TexGenEnabled
& S_BIT
) ? GL_TRUE
: GL_FALSE
;
586 case GL_TEXTURE_GEN_T
:
587 return (ctx
->Texture
.TexGenEnabled
& T_BIT
) ? GL_TRUE
: GL_FALSE
;
592 case GL_VERTEX_ARRAY
:
593 return ctx
->Array
.VertexEnabled
;
594 case GL_NORMAL_ARRAY
:
595 return ctx
->Array
.NormalEnabled
;
597 return ctx
->Array
.ColorEnabled
;
599 return ctx
->Array
.IndexEnabled
;
600 case GL_TEXTURE_COORD_ARRAY
:
601 return ctx
->Array
.TexCoordEnabled
;
602 case GL_EDGE_FLAG_ARRAY
:
603 return ctx
->Array
.EdgeFlagEnabled
;
605 gl_error( ctx
, GL_INVALID_ENUM
, "glIsEnabled" );
613 void gl_client_state( GLcontext
*ctx
, GLenum cap
, GLboolean state
)
616 case GL_VERTEX_ARRAY
:
617 ctx
->Array
.VertexEnabled
= state
;
619 case GL_NORMAL_ARRAY
:
620 ctx
->Array
.NormalEnabled
= state
;
623 ctx
->Array
.ColorEnabled
= state
;
626 ctx
->Array
.IndexEnabled
= state
;
628 case GL_TEXTURE_COORD_ARRAY
:
629 ctx
->Array
.TexCoordEnabled
= state
;
631 case GL_EDGE_FLAG_ARRAY
:
632 ctx
->Array
.EdgeFlagEnabled
= state
;
635 gl_error( ctx
, GL_INVALID_ENUM
, "glEnable/DisableClientState" );
641 void gl_EnableClientState( GLcontext
*ctx
, GLenum cap
)
643 gl_client_state( ctx
, cap
, GL_TRUE
);
648 void gl_DisableClientState( GLcontext
*ctx
, GLenum cap
)
650 gl_client_state( ctx
, cap
, GL_FALSE
);