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