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