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