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