Fix Windows build problems.
[mesa.git] / src / glx / x11 / indirect_vertex_program.c
1 /*
2 * (C) Copyright IBM Corporation 2005
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * IBM,
20 * AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26 #include <inttypes.h>
27 #include <GL/gl.h>
28 #include "indirect.h"
29 #include "glxclient.h"
30 #include "indirect_vertex_array.h"
31 #include <GL/glxproto.h>
32
33 void do_vertex_attrib_enable( GLuint index, GLboolean val )
34 {
35 __GLXcontext *gc = __glXGetCurrentContext();
36 __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
37
38 if ( ! __glXSetArrayEnable( state, GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB,
39 index, val ) ) {
40 __glXSetError(gc, GL_INVALID_ENUM);
41 }
42 }
43
44
45 void __indirect_glEnableVertexAttribArrayARB( GLuint index )
46 {
47 do_vertex_attrib_enable( index, GL_TRUE );
48 }
49
50
51 void __indirect_glDisableVertexAttribArrayARB( GLuint index )
52 {
53 do_vertex_attrib_enable( index, GL_FALSE );
54 }
55
56
57 static void
58 get_parameter( unsigned opcode, unsigned size, GLenum target, GLuint index,
59 void * params )
60 {
61 __GLXcontext * const gc = __glXGetCurrentContext();
62 Display * const dpy = gc->currentDpy;
63 const GLuint cmdlen = 12;
64
65 if (__builtin_expect(dpy != NULL, 1)) {
66 GLubyte const * pc = __glXSetupVendorRequest(gc,
67 X_GLXVendorPrivateWithReply,
68 opcode, cmdlen);
69
70 *((GLenum *)(pc + 0)) = target;
71 *((GLuint *)(pc + 4)) = index;
72 *((GLuint *)(pc + 8)) = 0;
73
74 (void) __glXReadReply(dpy, size, params, GL_FALSE);
75 UnlockDisplay(dpy); SyncHandle();
76 }
77 return;
78 }
79
80
81 void __indirect_glGetProgramEnvParameterfvARB( GLenum target, GLuint index,
82 GLfloat * params )
83 {
84 get_parameter( 1296, 4, target, index, params );
85 }
86
87
88 void __indirect_glGetProgramEnvParameterdvARB( GLenum target, GLuint index,
89 GLdouble * params )
90 {
91 get_parameter( 1297, 8, target, index, params );
92 }
93
94
95 void __indirect_glGetProgramLocalParameterfvARB( GLenum target, GLuint index,
96 GLfloat * params )
97 {
98 get_parameter( 1305, 4, target, index, params );
99 }
100
101
102 void __indirect_glGetProgramLocalParameterdvARB( GLenum target, GLuint index,
103 GLdouble * params )
104 {
105 get_parameter( 1306, 8, target, index, params );
106 }
107
108
109 void __indirect_glGetVertexAttribPointervNV( GLuint index, GLenum pname,
110 GLvoid ** pointer )
111 {
112 __GLXcontext * const gc = __glXGetCurrentContext();
113 __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
114
115 if ( pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB ) {
116 __glXSetError( gc, GL_INVALID_ENUM );
117 }
118
119 if ( ! __glXGetArrayPointer( state, GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB,
120 index, pointer ) ) {
121 __glXSetError( gc, GL_INVALID_VALUE );
122 }
123 }
124
125
126 /**
127 * Get the selected attribute from the vertex array state vector.
128 *
129 * \returns
130 * On success \c GL_TRUE is returned. Otherwise, \c GL_FALSE is returned.
131 */
132 static GLboolean
133 get_attrib_array_data( __GLXattribute * state, GLuint index, GLenum cap,
134 GLintptr * data )
135 {
136 GLboolean retval = GL_FALSE;
137 const GLenum attrib = GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB;
138
139 switch( cap ) {
140 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
141 retval = __glXGetArrayEnable( state, attrib, index, data );
142 break;
143
144 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
145 retval = __glXGetArraySize( state, attrib, index, data );
146 break;
147
148 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
149 retval = __glXGetArrayStride( state, attrib, index, data );
150 break;
151
152 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
153 retval = __glXGetArrayType( state, attrib, index, data );
154 break;
155
156 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
157 retval = __glXGetArrayNormalized( state, attrib, index, data );
158 break;
159 }
160
161
162 return retval;
163 }
164
165
166 static void get_vertex_attrib( __GLXcontext * gc, unsigned vop,
167 GLuint index, GLenum pname,
168 xReply * reply )
169 {
170 Display * const dpy = gc->currentDpy;
171 GLubyte * const pc = __glXSetupVendorRequest(gc,
172 X_GLXVendorPrivateWithReply,
173 vop, 8);
174
175 *((uint32_t *)(pc + 0)) = index;
176 *((uint32_t *)(pc + 4)) = pname;
177
178 (void) _XReply( dpy, reply, 0, False );
179 }
180
181
182 void __indirect_glGetVertexAttribivARB( GLuint index, GLenum pname,
183 GLint * params )
184 {
185 __GLXcontext * const gc = __glXGetCurrentContext();
186 Display * const dpy = gc->currentDpy;
187 __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
188 xGLXSingleReply reply;
189
190
191 get_vertex_attrib( gc, 1303, index, pname, (xReply *) & reply );
192
193 if ( reply.size != 0 ) {
194 if ( ! get_attrib_array_data( state, index, pname, params ) ) {
195 if (reply.size == 1) {
196 *params = (GLint) reply.pad3;
197 }
198 else {
199 _XRead(dpy, (void *) params, 4 * reply.size);
200 }
201 }
202 }
203
204 UnlockDisplay(dpy);
205 SyncHandle();
206 }
207
208
209 void __indirect_glGetVertexAttribfvARB( GLuint index, GLenum pname,
210 GLfloat * params )
211 {
212 __GLXcontext * const gc = __glXGetCurrentContext();
213 Display * const dpy = gc->currentDpy;
214 __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
215 xGLXSingleReply reply;
216
217
218 get_vertex_attrib( gc, 1302, index, pname, (xReply *) & reply );
219
220 if ( reply.size != 0 ) {
221 GLintptr data;
222
223
224 if ( get_attrib_array_data( state, index, pname, & data ) ) {
225 *params = (GLfloat) data;
226 }
227 else {
228 if (reply.size == 1) {
229 (void) memcpy( params, & reply.pad3, sizeof( GLfloat ) );
230 }
231 else {
232 _XRead(dpy, (void *) params, 4 * reply.size);
233 }
234 }
235 }
236
237 UnlockDisplay(dpy);
238 SyncHandle();
239 }
240
241
242 void __indirect_glGetVertexAttribdvARB( GLuint index, GLenum pname,
243 GLdouble * params )
244 {
245 __GLXcontext * const gc = __glXGetCurrentContext();
246 Display * const dpy = gc->currentDpy;
247 __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
248 xGLXSingleReply reply;
249
250
251 get_vertex_attrib( gc, 1301, index, pname, (xReply *) & reply );
252
253 if ( reply.size != 0 ) {
254 GLintptr data;
255
256
257 if ( get_attrib_array_data( state, index, pname, & data ) ) {
258 *params = (GLdouble) data;
259 }
260 else {
261 if (reply.size == 1) {
262 (void) memcpy( params, & reply.pad3, sizeof( GLdouble ) );
263 }
264 else {
265 _XRead(dpy, (void *) params, 8 * reply.size);
266 }
267 }
268 }
269
270 UnlockDisplay(dpy);
271 SyncHandle();
272 }