[OPENGL32/MESA]
[reactos.git] / reactos / dll / opengl / 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 *
9 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
25 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 */
28
29
30 #include <precomp.h>
31
32 #define CHECK_EXTENSION(EXTNAME, CAP) \
33 if (!ctx->Extensions.EXTNAME) { \
34 goto invalid_enum_error; \
35 }
36
37
38 /**
39 * Helper to enable/disable client-side state.
40 */
41 static void
42 client_state(struct gl_context *ctx, GLenum cap, GLboolean state)
43 {
44 GLbitfield64 flag;
45 GLboolean *var;
46
47 switch (cap) {
48 case GL_VERTEX_ARRAY:
49 var = &ctx->Array.VertexAttrib[VERT_ATTRIB_POS].Enabled;
50 flag = VERT_BIT_POS;
51 break;
52 case GL_NORMAL_ARRAY:
53 var = &ctx->Array.VertexAttrib[VERT_ATTRIB_NORMAL].Enabled;
54 flag = VERT_BIT_NORMAL;
55 break;
56 case GL_COLOR_ARRAY:
57 var = &ctx->Array.VertexAttrib[VERT_ATTRIB_COLOR0].Enabled;
58 flag = VERT_BIT_COLOR0;
59 break;
60 case GL_INDEX_ARRAY:
61 var = &ctx->Array.VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled;
62 flag = VERT_BIT_COLOR_INDEX;
63 break;
64 case GL_TEXTURE_COORD_ARRAY:
65 var = &ctx->Array.VertexAttrib[VERT_ATTRIB_TEX].Enabled;
66 flag = VERT_BIT_TEX;
67 break;
68 case GL_EDGE_FLAG_ARRAY:
69 var = &ctx->Array.VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled;
70 flag = VERT_BIT_EDGEFLAG;
71 break;
72 case GL_FOG_COORDINATE_ARRAY_EXT:
73 var = &ctx->Array.VertexAttrib[VERT_ATTRIB_FOG].Enabled;
74 flag = VERT_BIT_FOG;
75 break;
76 case GL_SECONDARY_COLOR_ARRAY_EXT:
77 var = &ctx->Array.VertexAttrib[VERT_ATTRIB_COLOR1].Enabled;
78 flag = VERT_BIT_COLOR1;
79 break;
80
81 #if FEATURE_point_size_array
82 case GL_POINT_SIZE_ARRAY_OES:
83 var = &ctx->Array.VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled;
84 flag = VERT_BIT_POINT_SIZE;
85 break;
86 #endif
87
88 default:
89 goto invalid_enum_error;
90 }
91
92 if (*var == state)
93 return;
94
95 FLUSH_VERTICES(ctx, _NEW_ARRAY);
96 ctx->Array.NewState |= flag;
97
98 _ae_invalidate_state(ctx, _NEW_ARRAY);
99
100 *var = state;
101
102 if (state)
103 ctx->Array._Enabled |= flag;
104 else
105 ctx->Array._Enabled &= ~flag;
106
107 if (ctx->Driver.Enable) {
108 ctx->Driver.Enable( ctx, cap, state );
109 }
110
111 return;
112
113 invalid_enum_error:
114 _mesa_error(ctx, GL_INVALID_ENUM, "gl%sClientState(0x%x)",
115 state ? "Enable" : "Disable", cap);
116 }
117
118
119 /**
120 * Enable GL capability.
121 * \param cap state to enable/disable.
122 *
123 * Get's the current context, assures that we're outside glBegin()/glEnd() and
124 * calls client_state().
125 */
126 void GLAPIENTRY
127 _mesa_EnableClientState( GLenum cap )
128 {
129 GET_CURRENT_CONTEXT(ctx);
130 ASSERT_OUTSIDE_BEGIN_END(ctx);
131 client_state( ctx, cap, GL_TRUE );
132 }
133
134
135 /**
136 * Disable GL capability.
137 * \param cap state to enable/disable.
138 *
139 * Get's the current context, assures that we're outside glBegin()/glEnd() and
140 * calls client_state().
141 */
142 void GLAPIENTRY
143 _mesa_DisableClientState( GLenum cap )
144 {
145 GET_CURRENT_CONTEXT(ctx);
146 ASSERT_OUTSIDE_BEGIN_END(ctx);
147 client_state( ctx, cap, GL_FALSE );
148 }
149
150
151 #undef CHECK_EXTENSION
152 #define CHECK_EXTENSION(EXTNAME, CAP) \
153 if (!ctx->Extensions.EXTNAME) { \
154 goto invalid_enum_error; \
155 }
156
157 #define CHECK_EXTENSION2(EXT1, EXT2, CAP) \
158 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
159 goto invalid_enum_error; \
160 }
161
162
163
164 /**
165 * Return pointer to current texture unit for setting/getting coordinate
166 * state.
167 * Note that we'll set GL_INVALID_OPERATION and return NULL if the active
168 * texture unit is higher than the number of supported coordinate units.
169 */
170 static inline struct gl_texture_unit *
171 get_texcoord_unit(struct gl_context *ctx)
172 {
173 return &ctx->Texture.Unit;
174 }
175
176
177 /**
178 * Helper function to enable or disable a texture target.
179 * \param bit one of the TEXTURE_x_BIT values
180 * \return GL_TRUE if state is changing or GL_FALSE if no change
181 */
182 static GLboolean
183 enable_texture(struct gl_context *ctx, GLboolean state, GLbitfield texBit)
184 {
185 struct gl_texture_unit *texUnit = &ctx->Texture.Unit;
186 const GLbitfield newenabled = state
187 ? (texUnit->Enabled | texBit) : (texUnit->Enabled & ~texBit);
188
189 if (texUnit->Enabled == newenabled)
190 return GL_FALSE;
191
192 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
193 texUnit->Enabled = newenabled;
194 return GL_TRUE;
195 }
196
197
198 /**
199 * Helper function to enable or disable state.
200 *
201 * \param ctx GL context.
202 * \param cap the state to enable/disable
203 * \param state whether to enable or disable the specified capability.
204 *
205 * Updates the current context and flushes the vertices as needed. For
206 * capabilities associated with extensions it verifies that those extensions
207 * are effectivly present before updating. Notifies the driver via
208 * dd_function_table::Enable.
209 */
210 void
211 _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
212 {
213 if (MESA_VERBOSE & VERBOSE_API)
214 _mesa_debug(ctx, "%s %s (newstate is %x)\n",
215 state ? "glEnable" : "glDisable",
216 _mesa_lookup_enum_by_nr(cap),
217 ctx->NewState);
218
219 switch (cap) {
220 case GL_ALPHA_TEST:
221 if (ctx->Color.AlphaEnabled == state)
222 return;
223 FLUSH_VERTICES(ctx, _NEW_COLOR);
224 ctx->Color.AlphaEnabled = state;
225 break;
226 case GL_AUTO_NORMAL:
227 if (ctx->Eval.AutoNormal == state)
228 return;
229 FLUSH_VERTICES(ctx, _NEW_EVAL);
230 ctx->Eval.AutoNormal = state;
231 break;
232 case GL_BLEND:
233 {
234 if (state != ctx->Color.BlendEnabled) {
235 FLUSH_VERTICES(ctx, _NEW_COLOR);
236 ctx->Color.BlendEnabled = state;
237 }
238 }
239 break;
240 #if FEATURE_userclip
241 case GL_CLIP_DISTANCE0:
242 case GL_CLIP_DISTANCE1:
243 case GL_CLIP_DISTANCE2:
244 case GL_CLIP_DISTANCE3:
245 case GL_CLIP_DISTANCE4:
246 case GL_CLIP_DISTANCE5:
247 case GL_CLIP_DISTANCE6:
248 case GL_CLIP_DISTANCE7:
249 {
250 const GLuint p = cap - GL_CLIP_DISTANCE0;
251
252 if (p >= ctx->Const.MaxClipPlanes)
253 goto invalid_enum_error;
254
255 if ((ctx->Transform.ClipPlanesEnabled & (1 << p))
256 == ((GLuint) state << p))
257 return;
258
259 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
260
261 if (state) {
262 ctx->Transform.ClipPlanesEnabled |= (1 << p);
263 _mesa_update_clip_plane(ctx, p);
264 }
265 else {
266 ctx->Transform.ClipPlanesEnabled &= ~(1 << p);
267 }
268 }
269 break;
270 #endif
271 case GL_COLOR_MATERIAL:
272 if (ctx->Light.ColorMaterialEnabled == state)
273 return;
274 FLUSH_VERTICES(ctx, _NEW_LIGHT);
275 FLUSH_CURRENT(ctx, 0);
276 ctx->Light.ColorMaterialEnabled = state;
277 if (state) {
278 _mesa_update_color_material( ctx,
279 ctx->Current.Attrib[VERT_ATTRIB_COLOR0] );
280 }
281 break;
282 case GL_CULL_FACE:
283 if (ctx->Polygon.CullFlag == state)
284 return;
285 FLUSH_VERTICES(ctx, _NEW_POLYGON);
286 ctx->Polygon.CullFlag = state;
287 break;
288 case GL_DEPTH_TEST:
289 if (ctx->Depth.Test == state)
290 return;
291 FLUSH_VERTICES(ctx, _NEW_DEPTH);
292 ctx->Depth.Test = state;
293 break;
294 case GL_DITHER:
295 if (ctx->Color.DitherFlag == state)
296 return;
297 FLUSH_VERTICES(ctx, _NEW_COLOR);
298 ctx->Color.DitherFlag = state;
299 break;
300 case GL_FOG:
301 if (ctx->Fog.Enabled == state)
302 return;
303 FLUSH_VERTICES(ctx, _NEW_FOG);
304 ctx->Fog.Enabled = state;
305 break;
306 case GL_LIGHT0:
307 case GL_LIGHT1:
308 case GL_LIGHT2:
309 case GL_LIGHT3:
310 case GL_LIGHT4:
311 case GL_LIGHT5:
312 case GL_LIGHT6:
313 case GL_LIGHT7:
314 if (ctx->Light.Light[cap-GL_LIGHT0].Enabled == state)
315 return;
316 FLUSH_VERTICES(ctx, _NEW_LIGHT);
317 ctx->Light.Light[cap-GL_LIGHT0].Enabled = state;
318 if (state) {
319 insert_at_tail(&ctx->Light.EnabledList,
320 &ctx->Light.Light[cap-GL_LIGHT0]);
321 }
322 else {
323 remove_from_list(&ctx->Light.Light[cap-GL_LIGHT0]);
324 }
325 break;
326 case GL_LIGHTING:
327 if (ctx->Light.Enabled == state)
328 return;
329 FLUSH_VERTICES(ctx, _NEW_LIGHT);
330 ctx->Light.Enabled = state;
331 if (ctx->Light.Enabled && ctx->Light.Model.TwoSide)
332 ctx->_TriangleCaps |= DD_TRI_LIGHT_TWOSIDE;
333 else
334 ctx->_TriangleCaps &= ~DD_TRI_LIGHT_TWOSIDE;
335 break;
336 case GL_LINE_SMOOTH:
337 if (ctx->Line.SmoothFlag == state)
338 return;
339 FLUSH_VERTICES(ctx, _NEW_LINE);
340 ctx->Line.SmoothFlag = state;
341 ctx->_TriangleCaps ^= DD_LINE_SMOOTH;
342 break;
343 case GL_LINE_STIPPLE:
344 if (ctx->Line.StippleFlag == state)
345 return;
346 FLUSH_VERTICES(ctx, _NEW_LINE);
347 ctx->Line.StippleFlag = state;
348 ctx->_TriangleCaps ^= DD_LINE_STIPPLE;
349 break;
350 case GL_INDEX_LOGIC_OP:
351 if (ctx->Color.IndexLogicOpEnabled == state)
352 return;
353 FLUSH_VERTICES(ctx, _NEW_COLOR);
354 ctx->Color.IndexLogicOpEnabled = state;
355 break;
356 case GL_COLOR_LOGIC_OP:
357 if (ctx->Color.ColorLogicOpEnabled == state)
358 return;
359 FLUSH_VERTICES(ctx, _NEW_COLOR);
360 ctx->Color.ColorLogicOpEnabled = state;
361 break;
362 case GL_MAP1_COLOR_4:
363 if (ctx->Eval.Map1Color4 == state)
364 return;
365 FLUSH_VERTICES(ctx, _NEW_EVAL);
366 ctx->Eval.Map1Color4 = state;
367 break;
368 case GL_MAP1_INDEX:
369 if (ctx->Eval.Map1Index == state)
370 return;
371 FLUSH_VERTICES(ctx, _NEW_EVAL);
372 ctx->Eval.Map1Index = state;
373 break;
374 case GL_MAP1_NORMAL:
375 if (ctx->Eval.Map1Normal == state)
376 return;
377 FLUSH_VERTICES(ctx, _NEW_EVAL);
378 ctx->Eval.Map1Normal = state;
379 break;
380 case GL_MAP1_TEXTURE_COORD_1:
381 if (ctx->Eval.Map1TextureCoord1 == state)
382 return;
383 FLUSH_VERTICES(ctx, _NEW_EVAL);
384 ctx->Eval.Map1TextureCoord1 = state;
385 break;
386 case GL_MAP1_TEXTURE_COORD_2:
387 if (ctx->Eval.Map1TextureCoord2 == state)
388 return;
389 FLUSH_VERTICES(ctx, _NEW_EVAL);
390 ctx->Eval.Map1TextureCoord2 = state;
391 break;
392 case GL_MAP1_TEXTURE_COORD_3:
393 if (ctx->Eval.Map1TextureCoord3 == state)
394 return;
395 FLUSH_VERTICES(ctx, _NEW_EVAL);
396 ctx->Eval.Map1TextureCoord3 = state;
397 break;
398 case GL_MAP1_TEXTURE_COORD_4:
399 if (ctx->Eval.Map1TextureCoord4 == state)
400 return;
401 FLUSH_VERTICES(ctx, _NEW_EVAL);
402 ctx->Eval.Map1TextureCoord4 = state;
403 break;
404 case GL_MAP1_VERTEX_3:
405 if (ctx->Eval.Map1Vertex3 == state)
406 return;
407 FLUSH_VERTICES(ctx, _NEW_EVAL);
408 ctx->Eval.Map1Vertex3 = state;
409 break;
410 case GL_MAP1_VERTEX_4:
411 if (ctx->Eval.Map1Vertex4 == state)
412 return;
413 FLUSH_VERTICES(ctx, _NEW_EVAL);
414 ctx->Eval.Map1Vertex4 = state;
415 break;
416 case GL_MAP2_COLOR_4:
417 if (ctx->Eval.Map2Color4 == state)
418 return;
419 FLUSH_VERTICES(ctx, _NEW_EVAL);
420 ctx->Eval.Map2Color4 = state;
421 break;
422 case GL_MAP2_INDEX:
423 if (ctx->Eval.Map2Index == state)
424 return;
425 FLUSH_VERTICES(ctx, _NEW_EVAL);
426 ctx->Eval.Map2Index = state;
427 break;
428 case GL_MAP2_NORMAL:
429 if (ctx->Eval.Map2Normal == state)
430 return;
431 FLUSH_VERTICES(ctx, _NEW_EVAL);
432 ctx->Eval.Map2Normal = state;
433 break;
434 case GL_MAP2_TEXTURE_COORD_1:
435 if (ctx->Eval.Map2TextureCoord1 == state)
436 return;
437 FLUSH_VERTICES(ctx, _NEW_EVAL);
438 ctx->Eval.Map2TextureCoord1 = state;
439 break;
440 case GL_MAP2_TEXTURE_COORD_2:
441 if (ctx->Eval.Map2TextureCoord2 == state)
442 return;
443 FLUSH_VERTICES(ctx, _NEW_EVAL);
444 ctx->Eval.Map2TextureCoord2 = state;
445 break;
446 case GL_MAP2_TEXTURE_COORD_3:
447 if (ctx->Eval.Map2TextureCoord3 == state)
448 return;
449 FLUSH_VERTICES(ctx, _NEW_EVAL);
450 ctx->Eval.Map2TextureCoord3 = state;
451 break;
452 case GL_MAP2_TEXTURE_COORD_4:
453 if (ctx->Eval.Map2TextureCoord4 == state)
454 return;
455 FLUSH_VERTICES(ctx, _NEW_EVAL);
456 ctx->Eval.Map2TextureCoord4 = state;
457 break;
458 case GL_MAP2_VERTEX_3:
459 if (ctx->Eval.Map2Vertex3 == state)
460 return;
461 FLUSH_VERTICES(ctx, _NEW_EVAL);
462 ctx->Eval.Map2Vertex3 = state;
463 break;
464 case GL_MAP2_VERTEX_4:
465 if (ctx->Eval.Map2Vertex4 == state)
466 return;
467 FLUSH_VERTICES(ctx, _NEW_EVAL);
468 ctx->Eval.Map2Vertex4 = state;
469 break;
470 case GL_NORMALIZE:
471 if (ctx->Transform.Normalize == state)
472 return;
473 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
474 ctx->Transform.Normalize = state;
475 break;
476 case GL_POINT_SMOOTH:
477 if (ctx->Point.SmoothFlag == state)
478 return;
479 FLUSH_VERTICES(ctx, _NEW_POINT);
480 ctx->Point.SmoothFlag = state;
481 ctx->_TriangleCaps ^= DD_POINT_SMOOTH;
482 break;
483 case GL_POLYGON_SMOOTH:
484 if (ctx->Polygon.SmoothFlag == state)
485 return;
486 FLUSH_VERTICES(ctx, _NEW_POLYGON);
487 ctx->Polygon.SmoothFlag = state;
488 ctx->_TriangleCaps ^= DD_TRI_SMOOTH;
489 break;
490 case GL_POLYGON_STIPPLE:
491 if (ctx->Polygon.StippleFlag == state)
492 return;
493 FLUSH_VERTICES(ctx, _NEW_POLYGON);
494 ctx->Polygon.StippleFlag = state;
495 ctx->_TriangleCaps ^= DD_TRI_STIPPLE;
496 break;
497 case GL_POLYGON_OFFSET_POINT:
498 if (ctx->Polygon.OffsetPoint == state)
499 return;
500 FLUSH_VERTICES(ctx, _NEW_POLYGON);
501 ctx->Polygon.OffsetPoint = state;
502 break;
503 case GL_POLYGON_OFFSET_LINE:
504 if (ctx->Polygon.OffsetLine == state)
505 return;
506 FLUSH_VERTICES(ctx, _NEW_POLYGON);
507 ctx->Polygon.OffsetLine = state;
508 break;
509 case GL_POLYGON_OFFSET_FILL:
510 if (ctx->Polygon.OffsetFill == state)
511 return;
512 FLUSH_VERTICES(ctx, _NEW_POLYGON);
513 ctx->Polygon.OffsetFill = state;
514 break;
515 case GL_RESCALE_NORMAL_EXT:
516 if (ctx->Transform.RescaleNormals == state)
517 return;
518 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
519 ctx->Transform.RescaleNormals = state;
520 break;
521 case GL_SCISSOR_TEST:
522 if (ctx->Scissor.Enabled == state)
523 return;
524 FLUSH_VERTICES(ctx, _NEW_SCISSOR);
525 ctx->Scissor.Enabled = state;
526 break;
527 case GL_STENCIL_TEST:
528 if (ctx->Stencil.Enabled == state)
529 return;
530 FLUSH_VERTICES(ctx, _NEW_STENCIL);
531 ctx->Stencil.Enabled = state;
532 break;
533 case GL_TEXTURE_1D:
534 if (!enable_texture(ctx, state, TEXTURE_1D_BIT)) {
535 return;
536 }
537 break;
538 case GL_TEXTURE_2D:
539 if (!enable_texture(ctx, state, TEXTURE_2D_BIT)) {
540 return;
541 }
542 break;
543 case GL_TEXTURE_GEN_S:
544 case GL_TEXTURE_GEN_T:
545 case GL_TEXTURE_GEN_R:
546 case GL_TEXTURE_GEN_Q:
547 {
548 struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
549 if (texUnit) {
550 GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
551 GLbitfield newenabled = texUnit->TexGenEnabled & ~coordBit;
552 if (state)
553 newenabled |= coordBit;
554 if (texUnit->TexGenEnabled == newenabled)
555 return;
556 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
557 texUnit->TexGenEnabled = newenabled;
558 }
559 }
560 break;
561
562 #if FEATURE_ES1
563 case GL_TEXTURE_GEN_STR_OES:
564 /* disable S, T, and R at the same time */
565 {
566 struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
567 if (texUnit) {
568 GLuint newenabled =
569 texUnit->TexGenEnabled & ~STR_BITS;
570 if (state)
571 newenabled |= STR_BITS;
572 if (texUnit->TexGenEnabled == newenabled)
573 return;
574 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
575 texUnit->TexGenEnabled = newenabled;
576 }
577 }
578 break;
579 #endif
580
581 /* client-side state */
582 case GL_VERTEX_ARRAY:
583 case GL_NORMAL_ARRAY:
584 case GL_COLOR_ARRAY:
585 case GL_INDEX_ARRAY:
586 case GL_TEXTURE_COORD_ARRAY:
587 case GL_EDGE_FLAG_ARRAY:
588 case GL_FOG_COORDINATE_ARRAY_EXT:
589 case GL_SECONDARY_COLOR_ARRAY_EXT:
590 case GL_POINT_SIZE_ARRAY_OES:
591 client_state( ctx, cap, state );
592 return;
593
594 /* GL_ARB_texture_cube_map */
595 case GL_TEXTURE_CUBE_MAP_ARB:
596 CHECK_EXTENSION(ARB_texture_cube_map, cap);
597 if (!enable_texture(ctx, state, TEXTURE_CUBE_BIT)) {
598 return;
599 }
600 break;
601
602 /* GL_ARB_multisample */
603 case GL_MULTISAMPLE_ARB:
604 if (ctx->Multisample.Enabled == state)
605 return;
606 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
607 ctx->Multisample.Enabled = state;
608 break;
609 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
610 if (ctx->Multisample.SampleAlphaToCoverage == state)
611 return;
612 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
613 ctx->Multisample.SampleAlphaToCoverage = state;
614 break;
615 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
616 if (ctx->Multisample.SampleAlphaToOne == state)
617 return;
618 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
619 ctx->Multisample.SampleAlphaToOne = state;
620 break;
621 case GL_SAMPLE_COVERAGE_ARB:
622 if (ctx->Multisample.SampleCoverage == state)
623 return;
624 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
625 ctx->Multisample.SampleCoverage = state;
626 break;
627 case GL_SAMPLE_COVERAGE_INVERT_ARB:
628 if (ctx->Multisample.SampleCoverageInvert == state)
629 return;
630 FLUSH_VERTICES(ctx, _NEW_MULTISAMPLE);
631 ctx->Multisample.SampleCoverageInvert = state;
632 break;
633
634 /* GL_IBM_rasterpos_clip */
635 case GL_RASTER_POSITION_UNCLIPPED_IBM:
636 CHECK_EXTENSION(IBM_rasterpos_clip, cap);
637 if (ctx->Transform.RasterPositionUnclipped == state)
638 return;
639 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
640 ctx->Transform.RasterPositionUnclipped = state;
641 break;
642
643 /* GL_NV_point_sprite */
644 case GL_POINT_SPRITE_NV:
645 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite, cap);
646 if (ctx->Point.PointSprite == state)
647 return;
648 FLUSH_VERTICES(ctx, _NEW_POINT);
649 ctx->Point.PointSprite = state;
650 break;
651
652 /* GL_EXT_depth_bounds_test */
653 case GL_DEPTH_BOUNDS_TEST_EXT:
654 CHECK_EXTENSION(EXT_depth_bounds_test, cap);
655 if (ctx->Depth.BoundsTest == state)
656 return;
657 FLUSH_VERTICES(ctx, _NEW_DEPTH);
658 ctx->Depth.BoundsTest = state;
659 break;
660
661 default:
662 goto invalid_enum_error;
663 }
664
665 if (ctx->Driver.Enable) {
666 ctx->Driver.Enable( ctx, cap, state );
667 }
668
669 return;
670
671 invalid_enum_error:
672 _mesa_error(ctx, GL_INVALID_ENUM, "gl%s(0x%x)",
673 state ? "Enable" : "Disable", cap);
674 }
675
676
677 /**
678 * Enable GL capability. Called by glEnable()
679 * \param cap state to enable.
680 */
681 void GLAPIENTRY
682 _mesa_Enable( GLenum cap )
683 {
684 GET_CURRENT_CONTEXT(ctx);
685 ASSERT_OUTSIDE_BEGIN_END(ctx);
686
687 _mesa_set_enable( ctx, cap, GL_TRUE );
688 }
689
690
691 /**
692 * Disable GL capability. Called by glDisable()
693 * \param cap state to disable.
694 */
695 void GLAPIENTRY
696 _mesa_Disable( GLenum cap )
697 {
698 GET_CURRENT_CONTEXT(ctx);
699 ASSERT_OUTSIDE_BEGIN_END(ctx);
700
701 _mesa_set_enable( ctx, cap, GL_FALSE );
702 }
703
704
705 #undef CHECK_EXTENSION
706 #define CHECK_EXTENSION(EXTNAME) \
707 if (!ctx->Extensions.EXTNAME) { \
708 goto invalid_enum_error; \
709 }
710
711 #undef CHECK_EXTENSION2
712 #define CHECK_EXTENSION2(EXT1, EXT2) \
713 if (!ctx->Extensions.EXT1 && !ctx->Extensions.EXT2) { \
714 goto invalid_enum_error; \
715 }
716
717
718 /**
719 * Helper function to determine whether a texture target is enabled.
720 */
721 static GLboolean
722 is_texture_enabled(struct gl_context *ctx, GLbitfield bit)
723 {
724 const struct gl_texture_unit *const texUnit =
725 &ctx->Texture.Unit;
726 return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE;
727 }
728
729
730 /**
731 * Return simple enable/disable state.
732 *
733 * \param cap state variable to query.
734 *
735 * Returns the state of the specified capability from the current GL context.
736 * For the capabilities associated with extensions verifies that those
737 * extensions are effectively present before reporting.
738 */
739 GLboolean GLAPIENTRY
740 _mesa_IsEnabled( GLenum cap )
741 {
742 GET_CURRENT_CONTEXT(ctx);
743 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
744
745 switch (cap) {
746 case GL_ALPHA_TEST:
747 return ctx->Color.AlphaEnabled;
748 case GL_AUTO_NORMAL:
749 return ctx->Eval.AutoNormal;
750 case GL_BLEND:
751 return ctx->Color.BlendEnabled & 1; /* return state for buffer[0] */
752 case GL_CLIP_DISTANCE0:
753 case GL_CLIP_DISTANCE1:
754 case GL_CLIP_DISTANCE2:
755 case GL_CLIP_DISTANCE3:
756 case GL_CLIP_DISTANCE4:
757 case GL_CLIP_DISTANCE5:
758 case GL_CLIP_DISTANCE6:
759 case GL_CLIP_DISTANCE7: {
760 const GLuint p = cap - GL_CLIP_DISTANCE0;
761
762 if (p >= ctx->Const.MaxClipPlanes)
763 goto invalid_enum_error;
764
765 return (ctx->Transform.ClipPlanesEnabled >> p) & 1;
766 }
767 case GL_COLOR_MATERIAL:
768 return ctx->Light.ColorMaterialEnabled;
769 case GL_CULL_FACE:
770 return ctx->Polygon.CullFlag;
771 case GL_DEPTH_TEST:
772 return ctx->Depth.Test;
773 case GL_DITHER:
774 return ctx->Color.DitherFlag;
775 case GL_FOG:
776 return ctx->Fog.Enabled;
777 case GL_LIGHTING:
778 return ctx->Light.Enabled;
779 case GL_LIGHT0:
780 case GL_LIGHT1:
781 case GL_LIGHT2:
782 case GL_LIGHT3:
783 case GL_LIGHT4:
784 case GL_LIGHT5:
785 case GL_LIGHT6:
786 case GL_LIGHT7:
787 return ctx->Light.Light[cap-GL_LIGHT0].Enabled;
788 case GL_LINE_SMOOTH:
789 return ctx->Line.SmoothFlag;
790 case GL_LINE_STIPPLE:
791 return ctx->Line.StippleFlag;
792 case GL_INDEX_LOGIC_OP:
793 return ctx->Color.IndexLogicOpEnabled;
794 case GL_COLOR_LOGIC_OP:
795 return ctx->Color.ColorLogicOpEnabled;
796 case GL_MAP1_COLOR_4:
797 return ctx->Eval.Map1Color4;
798 case GL_MAP1_INDEX:
799 return ctx->Eval.Map1Index;
800 case GL_MAP1_NORMAL:
801 return ctx->Eval.Map1Normal;
802 case GL_MAP1_TEXTURE_COORD_1:
803 return ctx->Eval.Map1TextureCoord1;
804 case GL_MAP1_TEXTURE_COORD_2:
805 return ctx->Eval.Map1TextureCoord2;
806 case GL_MAP1_TEXTURE_COORD_3:
807 return ctx->Eval.Map1TextureCoord3;
808 case GL_MAP1_TEXTURE_COORD_4:
809 return ctx->Eval.Map1TextureCoord4;
810 case GL_MAP1_VERTEX_3:
811 return ctx->Eval.Map1Vertex3;
812 case GL_MAP1_VERTEX_4:
813 return ctx->Eval.Map1Vertex4;
814 case GL_MAP2_COLOR_4:
815 return ctx->Eval.Map2Color4;
816 case GL_MAP2_INDEX:
817 return ctx->Eval.Map2Index;
818 case GL_MAP2_NORMAL:
819 return ctx->Eval.Map2Normal;
820 case GL_MAP2_TEXTURE_COORD_1:
821 return ctx->Eval.Map2TextureCoord1;
822 case GL_MAP2_TEXTURE_COORD_2:
823 return ctx->Eval.Map2TextureCoord2;
824 case GL_MAP2_TEXTURE_COORD_3:
825 return ctx->Eval.Map2TextureCoord3;
826 case GL_MAP2_TEXTURE_COORD_4:
827 return ctx->Eval.Map2TextureCoord4;
828 case GL_MAP2_VERTEX_3:
829 return ctx->Eval.Map2Vertex3;
830 case GL_MAP2_VERTEX_4:
831 return ctx->Eval.Map2Vertex4;
832 case GL_NORMALIZE:
833 return ctx->Transform.Normalize;
834 case GL_POINT_SMOOTH:
835 return ctx->Point.SmoothFlag;
836 case GL_POLYGON_SMOOTH:
837 return ctx->Polygon.SmoothFlag;
838 case GL_POLYGON_STIPPLE:
839 return ctx->Polygon.StippleFlag;
840 case GL_POLYGON_OFFSET_POINT:
841 return ctx->Polygon.OffsetPoint;
842 case GL_POLYGON_OFFSET_LINE:
843 return ctx->Polygon.OffsetLine;
844 case GL_POLYGON_OFFSET_FILL:
845 return ctx->Polygon.OffsetFill;
846 case GL_RESCALE_NORMAL_EXT:
847 return ctx->Transform.RescaleNormals;
848 case GL_SCISSOR_TEST:
849 return ctx->Scissor.Enabled;
850 case GL_STENCIL_TEST:
851 return ctx->Stencil.Enabled;
852 case GL_TEXTURE_1D:
853 return is_texture_enabled(ctx, TEXTURE_1D_BIT);
854 case GL_TEXTURE_2D:
855 return is_texture_enabled(ctx, TEXTURE_2D_BIT);
856 case GL_TEXTURE_GEN_S:
857 case GL_TEXTURE_GEN_T:
858 case GL_TEXTURE_GEN_R:
859 case GL_TEXTURE_GEN_Q:
860 {
861 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
862 if (texUnit) {
863 GLbitfield coordBit = S_BIT << (cap - GL_TEXTURE_GEN_S);
864 return (texUnit->TexGenEnabled & coordBit) ? GL_TRUE : GL_FALSE;
865 }
866 }
867 return GL_FALSE;
868 #if FEATURE_ES1
869 case GL_TEXTURE_GEN_STR_OES:
870 {
871 const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx);
872 if (texUnit) {
873 return (texUnit->TexGenEnabled & STR_BITS) == STR_BITS
874 ? GL_TRUE : GL_FALSE;
875 }
876 }
877 #endif
878
879 /* client-side state */
880 case GL_VERTEX_ARRAY:
881 return (ctx->Array.VertexAttrib[VERT_ATTRIB_POS].Enabled != 0);
882 case GL_NORMAL_ARRAY:
883 return (ctx->Array.VertexAttrib[VERT_ATTRIB_NORMAL].Enabled != 0);
884 case GL_COLOR_ARRAY:
885 return (ctx->Array.VertexAttrib[VERT_ATTRIB_COLOR0].Enabled != 0);
886 case GL_INDEX_ARRAY:
887 return (ctx->Array.VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled != 0);
888 case GL_TEXTURE_COORD_ARRAY:
889 return (ctx->Array.VertexAttrib[VERT_ATTRIB_TEX]
890 .Enabled != 0);
891 case GL_EDGE_FLAG_ARRAY:
892 return (ctx->Array.VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled != 0);
893 case GL_FOG_COORDINATE_ARRAY_EXT:
894 CHECK_EXTENSION(EXT_fog_coord);
895 return (ctx->Array.VertexAttrib[VERT_ATTRIB_FOG].Enabled != 0);
896 case GL_SECONDARY_COLOR_ARRAY_EXT:
897 CHECK_EXTENSION(EXT_secondary_color);
898 return (ctx->Array.VertexAttrib[VERT_ATTRIB_COLOR1].Enabled != 0);
899 #if FEATURE_point_size_array
900 case GL_POINT_SIZE_ARRAY_OES:
901 return (ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled != 0);
902 #endif
903
904 /* GL_ARB_texture_cube_map */
905 case GL_TEXTURE_CUBE_MAP_ARB:
906 CHECK_EXTENSION(ARB_texture_cube_map);
907 return is_texture_enabled(ctx, TEXTURE_CUBE_BIT);
908
909 /* GL_ARB_multisample */
910 case GL_MULTISAMPLE_ARB:
911 return ctx->Multisample.Enabled;
912 case GL_SAMPLE_ALPHA_TO_COVERAGE_ARB:
913 return ctx->Multisample.SampleAlphaToCoverage;
914 case GL_SAMPLE_ALPHA_TO_ONE_ARB:
915 return ctx->Multisample.SampleAlphaToOne;
916 case GL_SAMPLE_COVERAGE_ARB:
917 return ctx->Multisample.SampleCoverage;
918 case GL_SAMPLE_COVERAGE_INVERT_ARB:
919 return ctx->Multisample.SampleCoverageInvert;
920
921 /* GL_IBM_rasterpos_clip */
922 case GL_RASTER_POSITION_UNCLIPPED_IBM:
923 CHECK_EXTENSION(IBM_rasterpos_clip);
924 return ctx->Transform.RasterPositionUnclipped;
925
926 /* GL_NV_point_sprite */
927 case GL_POINT_SPRITE_NV:
928 CHECK_EXTENSION2(NV_point_sprite, ARB_point_sprite)
929 return ctx->Point.PointSprite;
930
931 /* GL_EXT_depth_bounds_test */
932 case GL_DEPTH_BOUNDS_TEST_EXT:
933 CHECK_EXTENSION(EXT_depth_bounds_test);
934 return ctx->Depth.BoundsTest;
935
936 default:
937 goto invalid_enum_error;
938 }
939
940 return GL_FALSE;
941
942 invalid_enum_error:
943 _mesa_error(ctx, GL_INVALID_ENUM, "glIsEnabled(0x%x)", (int) cap);
944 return GL_FALSE;
945 }