Import the GLX client side library, formerly from xc/lib/GL/glx. Build it
[mesa.git] / src / glx / x11 / clientattrib.c
1 /* $XFree86: xc/lib/GL/glx/clientattrib.c,v 1.5 2001/03/21 16:04:39 dawes Exp $ */
2 /*
3 ** License Applicability. Except to the extent portions of this file are
4 ** made subject to an alternative license as permitted in the SGI Free
5 ** Software License B, Version 1.1 (the "License"), the contents of this
6 ** file are subject only to the provisions of the License. You may not use
7 ** this file except in compliance with the License. You may obtain a copy
8 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
9 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10 **
11 ** http://oss.sgi.com/projects/FreeB
12 **
13 ** Note that, as provided in the License, the Software is distributed on an
14 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
15 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
16 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
17 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18 **
19 ** Original Code. The Original Code is: OpenGL Sample Implementation,
20 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
21 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
22 ** Copyright in any portions created by third parties is as indicated
23 ** elsewhere herein. All Rights Reserved.
24 **
25 ** Additional Notice Provisions: The application programming interfaces
26 ** established by SGI in conjunction with the Original Code are The
27 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
28 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
29 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
30 ** Window System(R) (Version 1.3), released October 19, 1998. This software
31 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
32 ** published by SGI, but has not been independently verified as being
33 ** compliant with the OpenGL(R) version 1.2.1 Specification.
34 **
35 */
36
37 #include <assert.h>
38 #define NEED_GL_FUNCS_WRAPPED
39 #include "glxclient.h"
40
41 /*****************************************************************************/
42
43 void glEnableClientState(GLenum array)
44 {
45 __GLXcontext *gc = __glXGetCurrentContext();
46 __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
47
48 switch (array) {
49 case GL_COLOR_ARRAY:
50 ENABLE_ARRAY(state, color);
51 break;
52 case GL_EDGE_FLAG_ARRAY:
53 ENABLE_ARRAY(state, edgeFlag);
54 break;
55 case GL_INDEX_ARRAY:
56 ENABLE_ARRAY(state, index);
57 break;
58 case GL_NORMAL_ARRAY:
59 ENABLE_ARRAY(state, normal);
60 break;
61 case GL_TEXTURE_COORD_ARRAY:
62 ENABLE_TEXARRAY(state, state->vertArray.activeTexture);
63 break;
64 case GL_VERTEX_ARRAY:
65 ENABLE_ARRAY(state, vertex);
66 break;
67 case GL_SECONDARY_COLOR_ARRAY:
68 ENABLE_ARRAY(state, secondaryColor);
69 break;
70 case GL_FOG_COORD_ARRAY:
71 ENABLE_ARRAY(state, fogCoord);
72 break;
73 default:
74 __glXSetError(gc, GL_INVALID_ENUM);
75 }
76 }
77
78 void glDisableClientState(GLenum array)
79 {
80 __GLXcontext *gc = __glXGetCurrentContext();
81 __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
82
83 switch (array) {
84 case GL_COLOR_ARRAY:
85 DISABLE_ARRAY(state, color);
86 break;
87 case GL_EDGE_FLAG_ARRAY:
88 DISABLE_ARRAY(state, edgeFlag);
89 break;
90 case GL_INDEX_ARRAY:
91 DISABLE_ARRAY(state, index);
92 break;
93 case GL_NORMAL_ARRAY:
94 DISABLE_ARRAY(state, normal);
95 break;
96 case GL_TEXTURE_COORD_ARRAY:
97 DISABLE_TEXARRAY(state, state->vertArray.activeTexture);
98 break;
99 case GL_VERTEX_ARRAY:
100 DISABLE_ARRAY(state, vertex);
101 break;
102 case GL_SECONDARY_COLOR_ARRAY:
103 DISABLE_ARRAY(state, secondaryColor);
104 break;
105 case GL_FOG_COORD_ARRAY:
106 DISABLE_ARRAY(state, fogCoord);
107 break;
108 default:
109 __glXSetError(gc, GL_INVALID_ENUM);
110 }
111 }
112
113 /************************************************************************/
114
115 void glPushClientAttrib(GLuint mask)
116 {
117 __GLXcontext *gc = __glXGetCurrentContext();
118 __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
119 __GLXattribute **spp = gc->attributes.stackPointer, *sp;
120
121 if (spp < &gc->attributes.stack[__GL_CLIENT_ATTRIB_STACK_DEPTH]) {
122 if (!(sp = *spp)) {
123 sp = (__GLXattribute *)Xmalloc(sizeof(__GLXattribute));
124 *spp = sp;
125 }
126 sp->mask = mask;
127 gc->attributes.stackPointer = spp + 1;
128 if (mask & GL_CLIENT_PIXEL_STORE_BIT) {
129 sp->storePack = state->storePack;
130 sp->storeUnpack = state->storeUnpack;
131 }
132 if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
133 sp->vertArray = state->vertArray;
134 }
135 } else {
136 __glXSetError(gc, GL_STACK_OVERFLOW);
137 return;
138 }
139 }
140
141 void glPopClientAttrib(void)
142 {
143 __GLXcontext *gc = __glXGetCurrentContext();
144 __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
145 __GLXattribute **spp = gc->attributes.stackPointer, *sp;
146 GLuint mask;
147
148 if (spp > &gc->attributes.stack[0]) {
149 --spp;
150 sp = *spp;
151 assert(sp != 0);
152 mask = sp->mask;
153 gc->attributes.stackPointer = spp;
154
155 if (mask & GL_CLIENT_PIXEL_STORE_BIT) {
156 state->storePack = sp->storePack;
157 state->storeUnpack = sp->storeUnpack;
158 }
159 if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
160 state->vertArray = sp->vertArray;
161 }
162
163 sp->mask = 0;
164 } else {
165 __glXSetError(gc, GL_STACK_UNDERFLOW);
166 return;
167 }
168 }
169
170 void __glFreeAttributeState(__GLXcontext *gc)
171 {
172 __GLXattribute *sp, **spp;
173
174 for (spp = &gc->attributes.stack[0];
175 spp < &gc->attributes.stack[__GL_CLIENT_ATTRIB_STACK_DEPTH];
176 spp++) {
177 sp = *spp;
178 if (sp) {
179 XFree((char *)sp);
180 } else {
181 break;
182 }
183 }
184 }
185
186