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