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