blob: f60fcc44f2369e29f746a51fbfa998f261fb0499 [file] [log] [blame]
Brian Paul19300532000-10-29 19:02:23 +00001/* $Id: enable.c,v 1.28 2000/10/29 19:02:23 brianp Exp $ */
jtgafb833d1999-08-19 00:55:39 +00002
3/*
4 * Mesa 3-D graphics library
Brian Pauleb326f52000-10-21 01:29:12 +00005 * Version: 3.5
jtgafb833d1999-08-19 00:55:39 +00006 *
Brian Pauleb326f52000-10-21 01:29:12 +00007 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
jtgafb833d1999-08-19 00:55:39 +00008 *
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
Brian Paulfbd8f211999-11-11 01:22:25 +000031#include "glheader.h"
jtgafb833d1999-08-19 00:55:39 +000032#include "context.h"
33#include "enable.h"
34#include "light.h"
35#include "macros.h"
36#include "matrix.h"
37#include "mmath.h"
38#include "simple_list.h"
39#include "types.h"
40#include "vbfill.h"
41#include "xform.h"
42#include "enums.h"
jtgafb833d1999-08-19 00:55:39 +000043#endif
44
45
46
47/*
48 * Perform glEnable and glDisable calls.
49 */
Brian Paulfbd8f211999-11-11 01:22:25 +000050void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
jtgafb833d1999-08-19 00:55:39 +000051{
52 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx, "gl_enable/disable" );
53
54 if (MESA_VERBOSE & VERBOSE_API)
Keith Whitwell2be79c11999-08-26 14:50:49 +000055 fprintf(stderr, "%s %s (newstate is %x)\n",
jtgafb833d1999-08-19 00:55:39 +000056 state ? "glEnable" : "glDisable",
57 gl_lookup_enum_by_nr(cap),
58 ctx->NewState);
59
60 switch (cap) {
61 case GL_ALPHA_TEST:
62 if (ctx->Color.AlphaEnabled!=state) {
63 ctx->Color.AlphaEnabled = state;
64 ctx->NewState |= NEW_RASTER_OPS;
65 }
66 break;
67 case GL_AUTO_NORMAL:
68 ctx->Eval.AutoNormal = state;
69 break;
70 case GL_BLEND:
71 if (ctx->Color.BlendEnabled!=state) {
72 ctx->Color.BlendEnabled = state;
73 /* The following needed to accomodate 1.0 RGB logic op blending */
74 if (ctx->Color.BlendEquation==GL_LOGIC_OP && state) {
75 ctx->Color.ColorLogicOpEnabled = GL_TRUE;
76 }
77 else {
78 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
79 }
80 ctx->NewState |= NEW_RASTER_OPS;
81 }
82 break;
83 case GL_CLIP_PLANE0:
84 case GL_CLIP_PLANE1:
85 case GL_CLIP_PLANE2:
86 case GL_CLIP_PLANE3:
87 case GL_CLIP_PLANE4:
88 case GL_CLIP_PLANE5:
89 if (cap >= GL_CLIP_PLANE0 &&
90 cap <= GL_CLIP_PLANE5 &&
91 ctx->Transform.ClipEnabled[cap-GL_CLIP_PLANE0] != state)
92 {
93 GLuint p = cap-GL_CLIP_PLANE0;
94
95 ctx->Transform.ClipEnabled[p] = state;
96 ctx->NewState |= NEW_USER_CLIP;
97
98 if (state) {
99 ctx->Enabled |= ENABLE_USERCLIP;
100 ctx->Transform.AnyClip++;
101
102 if (ctx->ProjectionMatrix.flags & MAT_DIRTY_ALL_OVER) {
103 gl_matrix_analyze( &ctx->ProjectionMatrix );
104 }
105
106 gl_transform_vector( ctx->Transform.ClipUserPlane[p],
107 ctx->Transform.EyeUserPlane[p],
108 ctx->ProjectionMatrix.inv );
109 } else {
110 if (--ctx->Transform.AnyClip == 0)
111 ctx->Enabled &= ~ENABLE_USERCLIP;
112 }
113 }
114 break;
115 case GL_COLOR_MATERIAL:
116 if (ctx->Light.ColorMaterialEnabled!=state) {
117 ctx->Light.ColorMaterialEnabled = state;
118 ctx->NewState |= NEW_LIGHTING;
Brian Paulfbd8f211999-11-11 01:22:25 +0000119 if (state)
Brian Paul19300532000-10-29 19:02:23 +0000120 gl_update_color_material( ctx, ctx->Current.Color );
jtgafb833d1999-08-19 00:55:39 +0000121 }
122 break;
123 case GL_CULL_FACE:
124 if (ctx->Polygon.CullFlag!=state) {
125 ctx->Polygon.CullFlag = state;
126 ctx->TriangleCaps ^= DD_TRI_CULL;
127 ctx->NewState |= NEW_POLYGON;
128 }
129 break;
130 case GL_DEPTH_TEST:
Brian Paulb1394fa2000-09-26 20:53:53 +0000131 if (state && ctx->Visual.DepthBits==0) {
132 _mesa_warning(ctx,"glEnable(GL_DEPTH_TEST) but no depth buffer");
jtgafb833d1999-08-19 00:55:39 +0000133 return;
134 }
135 if (ctx->Depth.Test!=state) {
136 ctx->Depth.Test = state;
137 ctx->NewState |= NEW_RASTER_OPS;
138 }
139 break;
140 case GL_DITHER:
141 if (ctx->NoDither) {
142 /* MESA_NO_DITHER env var */
143 state = GL_FALSE;
144 }
145 if (ctx->Color.DitherFlag!=state) {
146 ctx->Color.DitherFlag = state;
147 ctx->NewState |= NEW_RASTER_OPS;
148 }
149 break;
150 case GL_FOG:
151 if (ctx->Fog.Enabled!=state) {
152 ctx->Fog.Enabled = state;
153 ctx->Enabled ^= ENABLE_FOG;
Keith Whitwell2be79c11999-08-26 14:50:49 +0000154 ctx->NewState |= NEW_FOG|NEW_RASTER_OPS;
jtgafb833d1999-08-19 00:55:39 +0000155 }
156 break;
Brian Paul1a1cf7e2000-05-04 13:48:49 +0000157 case GL_HISTOGRAM:
Brian Paul8e053912000-08-30 18:21:06 +0000158 if (ctx->Extensions.HaveHistogram) {
159 ctx->Pixel.HistogramEnabled = state;
160 }
161 else {
162 gl_error( ctx, GL_INVALID_ENUM, state ? "glEnable": "glDisable" );
163 return;
164 }
Brian Paul1a1cf7e2000-05-04 13:48:49 +0000165 break;
jtgafb833d1999-08-19 00:55:39 +0000166 case GL_LIGHT0:
167 case GL_LIGHT1:
168 case GL_LIGHT2:
169 case GL_LIGHT3:
170 case GL_LIGHT4:
171 case GL_LIGHT5:
172 case GL_LIGHT6:
173 case GL_LIGHT7:
Brian Paul8e053912000-08-30 18:21:06 +0000174 if (ctx->Light.Light[cap-GL_LIGHT0].Enabled != state) {
jtgafb833d1999-08-19 00:55:39 +0000175 ctx->Light.Light[cap-GL_LIGHT0].Enabled = state;
176
177 if (state) {
178 insert_at_tail(&ctx->Light.EnabledList,
179 &ctx->Light.Light[cap-GL_LIGHT0]);
180 if (ctx->Light.Enabled)
181 ctx->Enabled |= ENABLE_LIGHT;
182 } else {
183 remove_from_list(&ctx->Light.Light[cap-GL_LIGHT0]);
184 if (is_empty_list(&ctx->Light.EnabledList))
185 ctx->Enabled &= ~ENABLE_LIGHT;
186 }
187
188 ctx->NewState |= NEW_LIGHTING;
189 }
190 break;
191 case GL_LIGHTING:
192 if (ctx->Light.Enabled!=state) {
193 ctx->Light.Enabled = state;
194 ctx->Enabled &= ~ENABLE_LIGHT;
Brian Paul2c318aa1999-10-20 22:16:45 +0000195 if (state)
jtgafb833d1999-08-19 00:55:39 +0000196 ctx->Enabled |= ENABLE_LIGHT;
197 ctx->NewState |= NEW_LIGHTING;
198 }
199 break;
200 case GL_LINE_SMOOTH:
201 if (ctx->Line.SmoothFlag!=state) {
202 ctx->Line.SmoothFlag = state;
Brian Paul1afd9462000-05-05 23:41:52 +0000203 ctx->TriangleCaps ^= DD_LINE_SMOOTH;
jtgafb833d1999-08-19 00:55:39 +0000204 ctx->NewState |= NEW_RASTER_OPS;
205 }
206 break;
207 case GL_LINE_STIPPLE:
208 if (ctx->Line.StippleFlag!=state) {
209 ctx->Line.StippleFlag = state;
210 ctx->TriangleCaps ^= DD_LINE_STIPPLE;
211 ctx->NewState |= NEW_RASTER_OPS;
212 }
213 break;
214 case GL_INDEX_LOGIC_OP:
215 if (ctx->Color.IndexLogicOpEnabled!=state) {
216 ctx->Color.IndexLogicOpEnabled = state;
217 ctx->NewState |= NEW_RASTER_OPS;
218 }
219 break;
220 case GL_COLOR_LOGIC_OP:
221 if (ctx->Color.ColorLogicOpEnabled!=state) {
222 ctx->Color.ColorLogicOpEnabled = state;
223 ctx->NewState |= NEW_RASTER_OPS;
224 }
225 break;
226 case GL_MAP1_COLOR_4:
227 ctx->Eval.Map1Color4 = state;
228 break;
229 case GL_MAP1_INDEX:
230 ctx->Eval.Map1Index = state;
231 break;
232 case GL_MAP1_NORMAL:
233 ctx->Eval.Map1Normal = state;
234 break;
235 case GL_MAP1_TEXTURE_COORD_1:
236 ctx->Eval.Map1TextureCoord1 = state;
237 break;
238 case GL_MAP1_TEXTURE_COORD_2:
239 ctx->Eval.Map1TextureCoord2 = state;
240 break;
241 case GL_MAP1_TEXTURE_COORD_3:
242 ctx->Eval.Map1TextureCoord3 = state;
243 break;
244 case GL_MAP1_TEXTURE_COORD_4:
245 ctx->Eval.Map1TextureCoord4 = state;
246 break;
247 case GL_MAP1_VERTEX_3:
248 ctx->Eval.Map1Vertex3 = state;
249 break;
250 case GL_MAP1_VERTEX_4:
251 ctx->Eval.Map1Vertex4 = state;
252 break;
253 case GL_MAP2_COLOR_4:
254 ctx->Eval.Map2Color4 = state;
255 break;
256 case GL_MAP2_INDEX:
257 ctx->Eval.Map2Index = state;
258 break;
259 case GL_MAP2_NORMAL:
260 ctx->Eval.Map2Normal = state;
261 break;
262 case GL_MAP2_TEXTURE_COORD_1:
263 ctx->Eval.Map2TextureCoord1 = state;
264 break;
265 case GL_MAP2_TEXTURE_COORD_2:
266 ctx->Eval.Map2TextureCoord2 = state;
267 break;
268 case GL_MAP2_TEXTURE_COORD_3:
269 ctx->Eval.Map2TextureCoord3 = state;
270 break;
271 case GL_MAP2_TEXTURE_COORD_4:
272 ctx->Eval.Map2TextureCoord4 = state;
273 break;
274 case GL_MAP2_VERTEX_3:
275 ctx->Eval.Map2Vertex3 = state;
276 break;
277 case GL_MAP2_VERTEX_4:
278 ctx->Eval.Map2Vertex4 = state;
279 break;
Brian Paul1a1cf7e2000-05-04 13:48:49 +0000280 case GL_MINMAX:
281 ctx->Pixel.MinMaxEnabled = state;
282 break;
jtgafb833d1999-08-19 00:55:39 +0000283 case GL_NORMALIZE:
284 if (ctx->Transform.Normalize != state) {
285 ctx->Transform.Normalize = state;
286 ctx->NewState |= NEW_NORMAL_TRANSFORM|NEW_LIGHTING;
287 ctx->Enabled ^= ENABLE_NORMALIZE;
288 }
289 break;
290 case GL_POINT_SMOOTH:
291 if (ctx->Point.SmoothFlag!=state) {
292 ctx->Point.SmoothFlag = state;
Brian Paul17919012000-10-05 23:10:42 +0000293 ctx->TriangleCaps ^= DD_POINT_SMOOTH;
jtgafb833d1999-08-19 00:55:39 +0000294 ctx->NewState |= NEW_RASTER_OPS;
295 }
296 break;
297 case GL_POLYGON_SMOOTH:
298 if (ctx->Polygon.SmoothFlag!=state) {
299 ctx->Polygon.SmoothFlag = state;
Brian Paul17919012000-10-05 23:10:42 +0000300 ctx->TriangleCaps ^= DD_TRI_SMOOTH;
jtgafb833d1999-08-19 00:55:39 +0000301 ctx->NewState |= NEW_RASTER_OPS;
302 }
303 break;
304 case GL_POLYGON_STIPPLE:
305 if (ctx->Polygon.StippleFlag!=state) {
306 ctx->Polygon.StippleFlag = state;
307 ctx->TriangleCaps ^= DD_TRI_STIPPLE;
308 ctx->NewState |= NEW_RASTER_OPS;
309 }
310 break;
311 case GL_POLYGON_OFFSET_POINT:
312 if (ctx->Polygon.OffsetPoint!=state) {
313 ctx->Polygon.OffsetPoint = state;
314 ctx->NewState |= NEW_POLYGON;
315 }
316 break;
317 case GL_POLYGON_OFFSET_LINE:
318 if (ctx->Polygon.OffsetLine!=state) {
319 ctx->Polygon.OffsetLine = state;
320 ctx->NewState |= NEW_POLYGON;
321 }
322 break;
323 case GL_POLYGON_OFFSET_FILL:
324 /*case GL_POLYGON_OFFSET_EXT:*/
325 if (ctx->Polygon.OffsetFill!=state) {
326 ctx->Polygon.OffsetFill = state;
327 ctx->NewState |= NEW_POLYGON;
328 }
329 break;
330 case GL_RESCALE_NORMAL_EXT:
331 if (ctx->Transform.RescaleNormals != state) {
332 ctx->Transform.RescaleNormals = state;
333 ctx->NewState |= NEW_NORMAL_TRANSFORM|NEW_LIGHTING;
334 ctx->Enabled ^= ENABLE_RESCALE;
335 }
336 break;
337 case GL_SCISSOR_TEST:
338 if (ctx->Scissor.Enabled!=state) {
339 ctx->Scissor.Enabled = state;
340 ctx->NewState |= NEW_RASTER_OPS;
341 }
342 break;
343 case GL_SHARED_TEXTURE_PALETTE_EXT:
344 ctx->Texture.SharedPalette = state;
jtgafb833d1999-08-19 00:55:39 +0000345 break;
346 case GL_STENCIL_TEST:
Brian Paulb1394fa2000-09-26 20:53:53 +0000347 if (state && ctx->Visual.StencilBits==0) {
348 _mesa_warning(ctx, "glEnable(GL_STENCIL_TEST) but no stencil buffer");
jtgafb833d1999-08-19 00:55:39 +0000349 return;
350 }
351 if (ctx->Stencil.Enabled!=state) {
352 ctx->Stencil.Enabled = state;
353 ctx->NewState |= NEW_RASTER_OPS;
Keith Whitwell1bf9dfa1999-09-18 20:41:22 +0000354 ctx->TriangleCaps ^= DD_STENCIL;
jtgafb833d1999-08-19 00:55:39 +0000355 }
356 break;
357 case GL_TEXTURE_1D:
Brian Paulb1394fa2000-09-26 20:53:53 +0000358 if (ctx->Visual.RGBAflag) {
jtgafb833d1999-08-19 00:55:39 +0000359 const GLuint curr = ctx->Texture.CurrentUnit;
jtgafb833d1999-08-19 00:55:39 +0000360 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[curr];
361 ctx->NewState |= NEW_TEXTURE_ENABLE;
362 if (state) {
363 texUnit->Enabled |= TEXTURE0_1D;
jtgafb833d1999-08-19 00:55:39 +0000364 }
365 else {
366 texUnit->Enabled &= ~TEXTURE0_1D;
jtgafb833d1999-08-19 00:55:39 +0000367 }
368 }
369 break;
370 case GL_TEXTURE_2D:
Brian Paulb1394fa2000-09-26 20:53:53 +0000371 if (ctx->Visual.RGBAflag) {
jtgafb833d1999-08-19 00:55:39 +0000372 const GLuint curr = ctx->Texture.CurrentUnit;
jtgafb833d1999-08-19 00:55:39 +0000373 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[curr];
374 ctx->NewState |= NEW_TEXTURE_ENABLE;
375 if (state) {
376 texUnit->Enabled |= TEXTURE0_2D;
jtgafb833d1999-08-19 00:55:39 +0000377 }
378 else {
379 texUnit->Enabled &= ~TEXTURE0_2D;
jtgafb833d1999-08-19 00:55:39 +0000380 }
381 }
382 break;
383 case GL_TEXTURE_3D:
Brian Paulb1394fa2000-09-26 20:53:53 +0000384 if (ctx->Visual.RGBAflag) {
jtgafb833d1999-08-19 00:55:39 +0000385 const GLuint curr = ctx->Texture.CurrentUnit;
jtgafb833d1999-08-19 00:55:39 +0000386 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[curr];
387 ctx->NewState |= NEW_TEXTURE_ENABLE;
388 if (state) {
389 texUnit->Enabled |= TEXTURE0_3D;
jtgafb833d1999-08-19 00:55:39 +0000390 }
391 else {
392 texUnit->Enabled &= ~TEXTURE0_3D;
jtgafb833d1999-08-19 00:55:39 +0000393 }
394 }
395 break;
396 case GL_TEXTURE_GEN_Q:
397 {
398 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
399 if (state)
400 texUnit->TexGenEnabled |= Q_BIT;
401 else
402 texUnit->TexGenEnabled &= ~Q_BIT;
403 ctx->NewState |= NEW_TEXTURING;
404 }
405 break;
406 case GL_TEXTURE_GEN_R:
407 {
408 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
409 if (state)
410 texUnit->TexGenEnabled |= R_BIT;
411 else
412 texUnit->TexGenEnabled &= ~R_BIT;
413 ctx->NewState |= NEW_TEXTURING;
414 }
415 break;
416 case GL_TEXTURE_GEN_S:
417 {
418 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
419 if (state)
420 texUnit->TexGenEnabled |= S_BIT;
421 else
422 texUnit->TexGenEnabled &= ~S_BIT;
423 ctx->NewState |= NEW_TEXTURING;
424 }
425 break;
426 case GL_TEXTURE_GEN_T:
427 {
428 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
429 if (state)
430 texUnit->TexGenEnabled |= T_BIT;
431 else
432 texUnit->TexGenEnabled &= ~T_BIT;
433 ctx->NewState |= NEW_TEXTURING;
434 }
435 break;
436
437 /*
438 * CLIENT STATE!!!
439 */
440 case GL_VERTEX_ARRAY:
441 ctx->Array.Vertex.Enabled = state;
442 break;
443 case GL_NORMAL_ARRAY:
444 ctx->Array.Normal.Enabled = state;
445 break;
446 case GL_COLOR_ARRAY:
447 ctx->Array.Color.Enabled = state;
448 break;
449 case GL_INDEX_ARRAY:
450 ctx->Array.Index.Enabled = state;
451 break;
452 case GL_TEXTURE_COORD_ARRAY:
Brian Paul45224fa1999-09-07 22:31:30 +0000453 ctx->Array.TexCoord[ctx->Array.ActiveTexture].Enabled = state;
jtgafb833d1999-08-19 00:55:39 +0000454 break;
455 case GL_EDGE_FLAG_ARRAY:
456 ctx->Array.EdgeFlag.Enabled = state;
457 break;
458
Brian Paul1b2ff692000-03-11 23:23:26 +0000459 /* GL_HP_occlusion_test */
460 case GL_OCCLUSION_TEST_HP:
461 if (ctx->Extensions.HaveHpOcclusionTest) {
462 ctx->Depth.OcclusionTest = state;
Brian Paul7e67fb42000-04-04 15:14:10 +0000463 if (state)
464 ctx->OcclusionResult = ctx->OcclusionResultSaved;
465 else
466 ctx->OcclusionResultSaved = ctx->OcclusionResult;
Brian Paul1b2ff692000-03-11 23:23:26 +0000467 ctx->NewState |= NEW_RASTER_OPS;
468 }
469 else {
470 gl_error( ctx, GL_INVALID_ENUM, state ? "glEnable": "glDisable" );
471 return;
472 }
473 break;
474
Brian Paul2b2e9252000-04-07 16:27:26 +0000475 /* GL_SGIS_pixel_texture */
476 case GL_PIXEL_TEXTURE_SGIS:
Brian Paulfa4525e2000-08-21 14:22:24 +0000477 /* XXX check for extension */
Brian Paul2b2e9252000-04-07 16:27:26 +0000478 ctx->Pixel.PixelTextureEnabled = state;
479 break;
480
481 /* GL_SGIX_pixel_texture */
482 case GL_PIXEL_TEX_GEN_SGIX:
Brian Paulfa4525e2000-08-21 14:22:24 +0000483 /* XXX check for extension */
Brian Paul2b2e9252000-04-07 16:27:26 +0000484 ctx->Pixel.PixelTextureEnabled = state;
485 break;
486
Brian Paul13811372000-04-12 00:27:37 +0000487 /* GL_SGI_color_table */
488 case GL_COLOR_TABLE_SGI:
Brian Paulfa4525e2000-08-21 14:22:24 +0000489 /* XXX check for extension */
Brian Paul13811372000-04-12 00:27:37 +0000490 ctx->Pixel.ColorTableEnabled = state;
Brian Paulfa4525e2000-08-21 14:22:24 +0000491 ctx->ImageTransferState = UPDATE_IMAGE_TRANSFER_STATE;
Brian Paul13811372000-04-12 00:27:37 +0000492 break;
493 case GL_POST_CONVOLUTION_COLOR_TABLE_SGI:
494 ctx->Pixel.PostConvolutionColorTableEnabled = state;
Brian Paulfa4525e2000-08-21 14:22:24 +0000495 ctx->ImageTransferState = UPDATE_IMAGE_TRANSFER_STATE;
Brian Paul13811372000-04-12 00:27:37 +0000496 break;
497 case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI:
498 ctx->Pixel.PostColorMatrixColorTableEnabled = state;
Brian Paulfa4525e2000-08-21 14:22:24 +0000499 ctx->ImageTransferState = UPDATE_IMAGE_TRANSFER_STATE;
Brian Paul13811372000-04-12 00:27:37 +0000500 break;
501
Brian Paul82b02f02000-05-07 20:37:40 +0000502 /* GL_EXT_convolution */
503 case GL_CONVOLUTION_1D:
Brian Paulfa4525e2000-08-21 14:22:24 +0000504 /* XXX check for extension */
Brian Paul82b02f02000-05-07 20:37:40 +0000505 ctx->Pixel.Convolution1DEnabled = state;
Brian Paulfa4525e2000-08-21 14:22:24 +0000506 ctx->ImageTransferState = UPDATE_IMAGE_TRANSFER_STATE;
Brian Paul82b02f02000-05-07 20:37:40 +0000507 break;
508 case GL_CONVOLUTION_2D:
509 ctx->Pixel.Convolution2DEnabled = state;
Brian Paulfa4525e2000-08-21 14:22:24 +0000510 ctx->ImageTransferState = UPDATE_IMAGE_TRANSFER_STATE;
Brian Paul82b02f02000-05-07 20:37:40 +0000511 break;
512 case GL_SEPARABLE_2D:
513 ctx->Pixel.Separable2DEnabled = state;
Brian Paulfa4525e2000-08-21 14:22:24 +0000514 ctx->ImageTransferState = UPDATE_IMAGE_TRANSFER_STATE;
Brian Paul82b02f02000-05-07 20:37:40 +0000515 break;
516
Brian Paul86fc3702000-05-22 16:33:20 +0000517 /* GL_ARB_texture_cube_map */
518 case GL_TEXTURE_CUBE_MAP_ARB:
Brian Paulfc4b4432000-05-23 15:17:12 +0000519 if (ctx->Extensions.HaveTextureCubeMap) {
Brian Paulb1394fa2000-09-26 20:53:53 +0000520 if (ctx->Visual.RGBAflag) {
Brian Paulfc4b4432000-05-23 15:17:12 +0000521 const GLuint curr = ctx->Texture.CurrentUnit;
Brian Paulfc4b4432000-05-23 15:17:12 +0000522 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[curr];
523 ctx->NewState |= NEW_TEXTURE_ENABLE;
524 if (state) {
525 texUnit->Enabled |= TEXTURE0_CUBE;
Brian Paulfc4b4432000-05-23 15:17:12 +0000526 }
527 else {
528 texUnit->Enabled &= ~TEXTURE0_CUBE;
Brian Paulfc4b4432000-05-23 15:17:12 +0000529 }
Brian Paul86fc3702000-05-22 16:33:20 +0000530 }
531 }
Brian Paulfc4b4432000-05-23 15:17:12 +0000532 else {
Brian Pauleb326f52000-10-21 01:29:12 +0000533 gl_error(ctx, GL_INVALID_ENUM, state ? "glEnable" : "glDisable");
Brian Paulfc4b4432000-05-23 15:17:12 +0000534 return;
535 }
Brian Paul86fc3702000-05-22 16:33:20 +0000536 break;
Brian Paul86fc3702000-05-22 16:33:20 +0000537
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000538 /* GL_EXT_secondary_color */
539 case GL_COLOR_SUM_EXT:
540 ctx->Fog.ColorSumEnabled = state;
541 if (state)
542 SET_BITS(ctx->TriangleCaps, DD_SEPERATE_SPECULAR);
543 else if (ctx->Light.Model.ColorControl == GL_SINGLE_COLOR)
544 CLEAR_BITS(ctx->TriangleCaps, DD_SEPERATE_SPECULAR);
545 ctx->NewState |= NEW_RASTER_OPS;
546 break;
547
jtgafb833d1999-08-19 00:55:39 +0000548 default:
Brian Pauleb326f52000-10-21 01:29:12 +0000549 gl_error(ctx, GL_INVALID_ENUM, state ? "glEnable" : "glDisable");
jtgafb833d1999-08-19 00:55:39 +0000550 return;
551 }
552
553 if (ctx->Driver.Enable) {
554 (*ctx->Driver.Enable)( ctx, cap, state );
555 }
556}
557
558
559
560
Brian Paulfbd8f211999-11-11 01:22:25 +0000561void
562_mesa_Enable( GLenum cap )
jtgafb833d1999-08-19 00:55:39 +0000563{
Brian Paulfbd8f211999-11-11 01:22:25 +0000564 GET_CURRENT_CONTEXT(ctx);
565 _mesa_set_enable( ctx, cap, GL_TRUE );
jtgafb833d1999-08-19 00:55:39 +0000566}
567
568
569
Brian Paulfbd8f211999-11-11 01:22:25 +0000570void
571_mesa_Disable( GLenum cap )
jtgafb833d1999-08-19 00:55:39 +0000572{
Brian Paulfbd8f211999-11-11 01:22:25 +0000573 GET_CURRENT_CONTEXT(ctx);
574 _mesa_set_enable( ctx, cap, GL_FALSE );
jtgafb833d1999-08-19 00:55:39 +0000575}
576
577
578
Brian Paulfbd8f211999-11-11 01:22:25 +0000579GLboolean
580_mesa_IsEnabled( GLenum cap )
jtgafb833d1999-08-19 00:55:39 +0000581{
Brian Paulfbd8f211999-11-11 01:22:25 +0000582 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000583 switch (cap) {
584 case GL_ALPHA_TEST:
585 return ctx->Color.AlphaEnabled;
586 case GL_AUTO_NORMAL:
587 return ctx->Eval.AutoNormal;
588 case GL_BLEND:
589 return ctx->Color.BlendEnabled;
590 case GL_CLIP_PLANE0:
591 case GL_CLIP_PLANE1:
592 case GL_CLIP_PLANE2:
593 case GL_CLIP_PLANE3:
594 case GL_CLIP_PLANE4:
595 case GL_CLIP_PLANE5:
596 return ctx->Transform.ClipEnabled[cap-GL_CLIP_PLANE0];
597 case GL_COLOR_MATERIAL:
598 return ctx->Light.ColorMaterialEnabled;
599 case GL_CULL_FACE:
600 return ctx->Polygon.CullFlag;
601 case GL_DEPTH_TEST:
602 return ctx->Depth.Test;
603 case GL_DITHER:
604 return ctx->Color.DitherFlag;
605 case GL_FOG:
606 return ctx->Fog.Enabled;
Brian Paul1a1cf7e2000-05-04 13:48:49 +0000607 case GL_HISTOGRAM:
Brian Paul8e053912000-08-30 18:21:06 +0000608 if (ctx->Extensions.HaveHistogram) {
609 return ctx->Pixel.HistogramEnabled;
610 }
611 else {
612 gl_error(ctx, GL_INVALID_ENUM, "glIsEnabled");
613 return GL_FALSE;
614 }
jtgafb833d1999-08-19 00:55:39 +0000615 case GL_LIGHTING:
616 return ctx->Light.Enabled;
617 case GL_LIGHT0:
618 case GL_LIGHT1:
619 case GL_LIGHT2:
620 case GL_LIGHT3:
621 case GL_LIGHT4:
622 case GL_LIGHT5:
623 case GL_LIGHT6:
624 case GL_LIGHT7:
625 return ctx->Light.Light[cap-GL_LIGHT0].Enabled;
626 case GL_LINE_SMOOTH:
627 return ctx->Line.SmoothFlag;
628 case GL_LINE_STIPPLE:
629 return ctx->Line.StippleFlag;
630 case GL_INDEX_LOGIC_OP:
631 return ctx->Color.IndexLogicOpEnabled;
632 case GL_COLOR_LOGIC_OP:
633 return ctx->Color.ColorLogicOpEnabled;
634 case GL_MAP1_COLOR_4:
635 return ctx->Eval.Map1Color4;
636 case GL_MAP1_INDEX:
637 return ctx->Eval.Map1Index;
638 case GL_MAP1_NORMAL:
639 return ctx->Eval.Map1Normal;
640 case GL_MAP1_TEXTURE_COORD_1:
641 return ctx->Eval.Map1TextureCoord1;
642 case GL_MAP1_TEXTURE_COORD_2:
643 return ctx->Eval.Map1TextureCoord2;
644 case GL_MAP1_TEXTURE_COORD_3:
645 return ctx->Eval.Map1TextureCoord3;
646 case GL_MAP1_TEXTURE_COORD_4:
647 return ctx->Eval.Map1TextureCoord4;
648 case GL_MAP1_VERTEX_3:
649 return ctx->Eval.Map1Vertex3;
650 case GL_MAP1_VERTEX_4:
651 return ctx->Eval.Map1Vertex4;
652 case GL_MAP2_COLOR_4:
653 return ctx->Eval.Map2Color4;
654 case GL_MAP2_INDEX:
655 return ctx->Eval.Map2Index;
656 case GL_MAP2_NORMAL:
657 return ctx->Eval.Map2Normal;
658 case GL_MAP2_TEXTURE_COORD_1:
659 return ctx->Eval.Map2TextureCoord1;
660 case GL_MAP2_TEXTURE_COORD_2:
661 return ctx->Eval.Map2TextureCoord2;
662 case GL_MAP2_TEXTURE_COORD_3:
663 return ctx->Eval.Map2TextureCoord3;
664 case GL_MAP2_TEXTURE_COORD_4:
665 return ctx->Eval.Map2TextureCoord4;
666 case GL_MAP2_VERTEX_3:
667 return ctx->Eval.Map2Vertex3;
668 case GL_MAP2_VERTEX_4:
669 return ctx->Eval.Map2Vertex4;
Brian Paul1a1cf7e2000-05-04 13:48:49 +0000670 case GL_MINMAX:
671 return ctx->Pixel.MinMaxEnabled;
jtgafb833d1999-08-19 00:55:39 +0000672 case GL_NORMALIZE:
673 return ctx->Transform.Normalize;
674 case GL_POINT_SMOOTH:
675 return ctx->Point.SmoothFlag;
676 case GL_POLYGON_SMOOTH:
677 return ctx->Polygon.SmoothFlag;
678 case GL_POLYGON_STIPPLE:
679 return ctx->Polygon.StippleFlag;
680 case GL_POLYGON_OFFSET_POINT:
681 return ctx->Polygon.OffsetPoint;
682 case GL_POLYGON_OFFSET_LINE:
683 return ctx->Polygon.OffsetLine;
684 case GL_POLYGON_OFFSET_FILL:
685 /*case GL_POLYGON_OFFSET_EXT:*/
686 return ctx->Polygon.OffsetFill;
687 case GL_RESCALE_NORMAL_EXT:
688 return ctx->Transform.RescaleNormals;
689 case GL_SCISSOR_TEST:
690 return ctx->Scissor.Enabled;
691 case GL_SHARED_TEXTURE_PALETTE_EXT:
692 return ctx->Texture.SharedPalette;
693 case GL_STENCIL_TEST:
694 return ctx->Stencil.Enabled;
695 case GL_TEXTURE_1D:
696 {
697 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
698 return (texUnit->Enabled & TEXTURE0_1D) ? GL_TRUE : GL_FALSE;
699 }
700 case GL_TEXTURE_2D:
701 {
702 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
703 return (texUnit->Enabled & TEXTURE0_2D) ? GL_TRUE : GL_FALSE;
704 }
705 case GL_TEXTURE_3D:
706 {
707 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
Brian Paul65b5e1e1999-08-19 13:24:27 +0000708 return (texUnit->Enabled & TEXTURE0_3D) ? GL_TRUE : GL_FALSE;
jtgafb833d1999-08-19 00:55:39 +0000709 }
710 case GL_TEXTURE_GEN_Q:
711 {
712 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
713 return (texUnit->TexGenEnabled & Q_BIT) ? GL_TRUE : GL_FALSE;
714 }
715 case GL_TEXTURE_GEN_R:
716 {
717 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
718 return (texUnit->TexGenEnabled & R_BIT) ? GL_TRUE : GL_FALSE;
719 }
720 case GL_TEXTURE_GEN_S:
721 {
722 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
723 return (texUnit->TexGenEnabled & S_BIT) ? GL_TRUE : GL_FALSE;
724 }
725 case GL_TEXTURE_GEN_T:
726 {
727 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
728 return (texUnit->TexGenEnabled & T_BIT) ? GL_TRUE : GL_FALSE;
729 }
730
731 /*
732 * CLIENT STATE!!!
733 */
734 case GL_VERTEX_ARRAY:
735 return ctx->Array.Vertex.Enabled;
736 case GL_NORMAL_ARRAY:
737 return ctx->Array.Normal.Enabled;
738 case GL_COLOR_ARRAY:
739 return ctx->Array.Color.Enabled;
740 case GL_INDEX_ARRAY:
741 return ctx->Array.Index.Enabled;
742 case GL_TEXTURE_COORD_ARRAY:
Brian Paul45224fa1999-09-07 22:31:30 +0000743 return ctx->Array.TexCoord[ctx->Array.ActiveTexture].Enabled;
jtgafb833d1999-08-19 00:55:39 +0000744 case GL_EDGE_FLAG_ARRAY:
745 return ctx->Array.EdgeFlag.Enabled;
Brian Paul1b2ff692000-03-11 23:23:26 +0000746
747 /* GL_HP_occlusion_test */
748 case GL_OCCLUSION_TEST_HP:
749 if (ctx->Extensions.HaveHpOcclusionTest) {
750 return ctx->Depth.OcclusionTest;
751 }
752 else {
753 gl_error( ctx, GL_INVALID_ENUM, "glIsEnabled" );
754 return GL_FALSE;
755 }
756
Brian Paul2b2e9252000-04-07 16:27:26 +0000757 /* GL_SGIS_pixel_texture */
758 case GL_PIXEL_TEXTURE_SGIS:
759 return ctx->Pixel.PixelTextureEnabled;
Brian Paul2b2e9252000-04-07 16:27:26 +0000760
761 /* GL_SGIX_pixel_texture */
762 case GL_PIXEL_TEX_GEN_SGIX:
763 return ctx->Pixel.PixelTextureEnabled;
Brian Paul13811372000-04-12 00:27:37 +0000764
765 /* GL_SGI_color_table */
766 case GL_COLOR_TABLE_SGI:
767 return ctx->Pixel.ColorTableEnabled;
768 case GL_POST_CONVOLUTION_COLOR_TABLE_SGI:
769 return ctx->Pixel.PostConvolutionColorTableEnabled;
770 case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI:
771 return ctx->Pixel.PostColorMatrixColorTableEnabled;
Brian Paul2b2e9252000-04-07 16:27:26 +0000772
Brian Paul82b02f02000-05-07 20:37:40 +0000773 /* GL_EXT_convolution */
774 case GL_CONVOLUTION_1D:
775 return ctx->Pixel.Convolution1DEnabled;
776 case GL_CONVOLUTION_2D:
777 return ctx->Pixel.Convolution2DEnabled;
778 case GL_SEPARABLE_2D:
779 return ctx->Pixel.Separable2DEnabled;
780
Brian Paul86fc3702000-05-22 16:33:20 +0000781 /* GL_ARB_texture_cube_map */
782 case GL_TEXTURE_CUBE_MAP_ARB:
Brian Paulfc4b4432000-05-23 15:17:12 +0000783 if (ctx->Extensions.HaveTextureCubeMap) {
784 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
785 return (texUnit->Enabled & TEXTURE0_CUBE) ? GL_TRUE : GL_FALSE;
Brian Paul86fc3702000-05-22 16:33:20 +0000786 }
Brian Paulfc4b4432000-05-23 15:17:12 +0000787 else {
788 gl_error(ctx, GL_INVALID_ENUM, "glIsEnabled");
789 return GL_FALSE;
790 }
Brian Paul86fc3702000-05-22 16:33:20 +0000791
jtgafb833d1999-08-19 00:55:39 +0000792 default:
793 gl_error( ctx, GL_INVALID_ENUM, "glIsEnabled" );
794 return GL_FALSE;
795 }
796}
797
798
799
800
Brian Paulfbd8f211999-11-11 01:22:25 +0000801static void
802client_state( GLcontext *ctx, GLenum cap, GLboolean state )
jtgafb833d1999-08-19 00:55:39 +0000803{
804 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx,
805 (state
806 ? "glEnableClientState"
807 : "glDisableClientState") );
808
809 switch (cap) {
810 case GL_VERTEX_ARRAY:
811 ctx->Array.Vertex.Enabled = state;
812 break;
813 case GL_NORMAL_ARRAY:
814 ctx->Array.Normal.Enabled = state;
815 break;
816 case GL_COLOR_ARRAY:
817 ctx->Array.Color.Enabled = state;
818 break;
819 case GL_INDEX_ARRAY:
820 ctx->Array.Index.Enabled = state;
821 break;
822 case GL_TEXTURE_COORD_ARRAY:
Brian Paul45224fa1999-09-07 22:31:30 +0000823 ctx->Array.TexCoord[ctx->Array.ActiveTexture].Enabled = state;
jtgafb833d1999-08-19 00:55:39 +0000824 break;
825 case GL_EDGE_FLAG_ARRAY:
826 ctx->Array.EdgeFlag.Enabled = state;
827 break;
Keith Whitwellfe5d67d2000-10-27 16:44:40 +0000828 case GL_FOG_COORDINATE_ARRAY_EXT:
829 ctx->Array.FogCoord.Enabled = state;
830 break;
831 case GL_SECONDARY_COLOR_ARRAY_EXT:
832 ctx->Array.SecondaryColor.Enabled = state;
833 break;
jtgafb833d1999-08-19 00:55:39 +0000834 default:
835 gl_error( ctx, GL_INVALID_ENUM, "glEnable/DisableClientState" );
836 }
837
838 ctx->NewState |= NEW_CLIENT_STATE;
839}
840
841
842
Brian Paulfbd8f211999-11-11 01:22:25 +0000843void
844_mesa_EnableClientState( GLenum cap )
jtgafb833d1999-08-19 00:55:39 +0000845{
Brian Paulfbd8f211999-11-11 01:22:25 +0000846 GET_CURRENT_CONTEXT(ctx);
847 client_state( ctx, cap, GL_TRUE );
jtgafb833d1999-08-19 00:55:39 +0000848}
849
850
851
Brian Paulfbd8f211999-11-11 01:22:25 +0000852void
853_mesa_DisableClientState( GLenum cap )
jtgafb833d1999-08-19 00:55:39 +0000854{
Brian Paulfbd8f211999-11-11 01:22:25 +0000855 GET_CURRENT_CONTEXT(ctx);
856 client_state( ctx, cap, GL_FALSE );
jtgafb833d1999-08-19 00:55:39 +0000857}
858