Merge remote branch 'origin/gallium-0.2' into gallium-0.2
[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 static void
34 do_vertex_attrib_enable( GLuint index, GLboolean val )
35 {
36 __GLXcontext *gc = __glXGetCurrentContext();
37 __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
38
39 if ( ! __glXSetArrayEnable( state, GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB,
40 index, val ) ) {
41 __glXSetError(gc, GL_INVALID_ENUM);
42 }
43 }
44
45
46 void __indirect_glEnableVertexAttribArrayARB( GLuint index )
47 {
48 do_vertex_attrib_enable( index, GL_TRUE );
49 }
50
51
52 void __indirect_glDisableVertexAttribArrayARB( GLuint index )
53 {
54 do_vertex_attrib_enable( index, GL_FALSE );
55 }
56
57
58 static void
59 get_parameter( unsigned opcode, unsigned size, GLenum target, GLuint index,
60 void * params )
61 {
62 __GLXcontext * const gc = __glXGetCurrentContext();
63 Display * const dpy = gc->currentDpy;
64 const GLuint cmdlen = 12;
65
66 if (__builtin_expect(dpy != NULL, 1)) {
67 GLubyte const * pc = __glXSetupVendorRequest(gc,
68 X_GLXVendorPrivateWithReply,
69 opcode, cmdlen);
70
71 *((GLenum *)(pc + 0)) = target;
72 *((GLuint *)(pc + 4)) = index;
73 *((GLuint *)(pc + 8)) = 0;
74
75 (void) __glXReadReply(dpy, size, params, GL_FALSE);
76 UnlockDisplay(dpy); SyncHandle();
77 }
78 return;
79 }
80
81
82 void __indirect_glGetProgramEnvParameterfvARB( GLenum target, GLuint index,
83 GLfloat * params )
84 {
85 get_parameter( 1296, 4, target, index, params );
86 }
87
88
89 void __indirect_glGetProgramEnvParameterdvARB( GLenum target, GLuint index,
90 GLdouble * params )
91 {
92 get_parameter( 1297, 8, target, index, params );
93 }
94
95
96 void __indirect_glGetProgramLocalParameterfvARB( GLenum target, GLuint index,
97 GLfloat * params )
98 {
99 get_parameter( 1305, 4, target, index, params );
100 }
101
102
103 void __indirect_glGetProgramLocalParameterdvARB( GLenum target, GLuint index,
104 GLdouble * params )
105 {
106 get_parameter( 1306, 8, target, index, params );
107 }
108
109
110 void __indirect_glGetVertexAttribPointervNV( GLuint index, GLenum pname,
111 GLvoid ** pointer )
112 {
113 __GLXcontext * const gc = __glXGetCurrentContext();
114 __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
115
116 if ( pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB ) {
117 __glXSetError( gc, GL_INVALID_ENUM );
118 }
119
120 if ( ! __glXGetArrayPointer( state, GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB,
121 index, pointer ) ) {
122 __glXSetError( gc, GL_INVALID_VALUE );
123 }
124 }
125
126
127 /**
128 * Get the selected attribute from the vertex array state vector.
129 *
130 * \returns
131 * On success \c GL_TRUE is returned. Otherwise, \c GL_FALSE is returned.
132 */
133 static GLboolean
134 get_attrib_array_data( __GLXattribute * state, GLuint index, GLenum cap,
135 GLintptr * data )
136 {
137 GLboolean retval = GL_FALSE;
138 const GLenum attrib = GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB;
139
140 switch( cap ) {
141 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
142 retval = __glXGetArrayEnable( state, attrib, index, data );
143 break;
144
145 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
146 retval = __glXGetArraySize( state, attrib, index, data );
147 break;
148
149 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
150 retval = __glXGetArrayStride( state, attrib, index, data );
151 break;
152
153 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
154 retval = __glXGetArrayType( state, attrib, index, data );
155 break;
156
157 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
158 retval = __glXGetArrayNormalized( state, attrib, index, data );
159 break;
160 }
161
162
163 return retval;
164 }
165
166
167 static void get_vertex_attrib( __GLXcontext * gc, unsigned vop,
168 GLuint index, GLenum pname,
169 xReply * reply )
170 {
171 Display * const dpy = gc->currentDpy;
172 GLubyte * const pc = __glXSetupVendorRequest(gc,
173 X_GLXVendorPrivateWithReply,
174 vop, 8);
175
176 *((uint32_t *)(pc + 0)) = index;
177 *((uint32_t *)(pc + 4)) = pname;
178
179 (void) _XReply( dpy, reply, 0, False );
180 }
181
182
183 void __indirect_glGetVertexAttribivARB( GLuint index, GLenum pname,
184 GLint * params )
185 {
186 __GLXcontext * const gc = __glXGetCurrentContext();
187 Display * const dpy = gc->currentDpy;
188 __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
189 xGLXSingleReply reply;
190
191
192 get_vertex_attrib( gc, 1303, index, pname, (xReply *) & reply );
193
194 if ( reply.size != 0 ) {
195 GLintptr data;
196
197
198 if ( get_attrib_array_data( state, index, pname, & data ) ) {
199 *params = (GLint) data;
200 }
201 else {
202 if (reply.size == 1) {
203 *params = (GLint) reply.pad3;
204 }
205 else {
206 _XRead(dpy, (void *) params, 4 * reply.size);
207 }
208 }
209 }
210
211 UnlockDisplay(dpy);
212 SyncHandle();
213 }
214
215
216 void __indirect_glGetVertexAttribfvARB( GLuint index, GLenum pname,
217 GLfloat * params )
218 {
219 __GLXcontext * const gc = __glXGetCurrentContext();
220 Display * const dpy = gc->currentDpy;
221 __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
222 xGLXSingleReply reply;
223
224
225 get_vertex_attrib( gc, 1302, index, pname, (xReply *) & reply );
226
227 if ( reply.size != 0 ) {
228 GLintptr data;
229
230
231 if ( get_attrib_array_data( state, index, pname, & data ) ) {
232 *params = (GLfloat) data;
233 }
234 else {
235 if (reply.size == 1) {
236 (void) memcpy( params, & reply.pad3, sizeof( GLfloat ) );
237 }
238 else {
239 _XRead(dpy, (void *) params, 4 * reply.size);
240 }
241 }
242 }
243
244 UnlockDisplay(dpy);
245 SyncHandle();
246 }
247
248
249 void __indirect_glGetVertexAttribdvARB( GLuint index, GLenum pname,
250 GLdouble * params )
251 {
252 __GLXcontext * const gc = __glXGetCurrentContext();
253 Display * const dpy = gc->currentDpy;
254 __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
255 xGLXSingleReply reply;
256
257
258 get_vertex_attrib( gc, 1301, index, pname, (xReply *) & reply );
259
260 if ( reply.size != 0 ) {
261 GLintptr data;
262
263
264 if ( get_attrib_array_data( state, index, pname, & data ) ) {
265 *params = (GLdouble) data;
266 }
267 else {
268 if (reply.size == 1) {
269 (void) memcpy( params, & reply.pad3, sizeof( GLdouble ) );
270 }
271 else {
272 _XRead(dpy, (void *) params, 8 * reply.size);
273 }
274 }
275 }
276
277 UnlockDisplay(dpy);
278 SyncHandle();
279 }