g3dvl: Use sobel filter for chroma interpolation
[mesa/nouveau-pmpeg.git] / src / glx / indirect_vertex_program.c
blobd955fdfa93eea6ed8f93daa556ec1627d42d770c
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:
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.
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.
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>
33 #if !defined(__GNUC__)
34 # define __builtin_expect(x, y) x
35 #endif
37 static void
38 do_vertex_attrib_enable(GLuint index, GLboolean val)
40 struct glx_context *gc = __glXGetCurrentContext();
41 __GLXattribute *state = (__GLXattribute *) (gc->client_state_private);
43 if (!__glXSetArrayEnable(state, GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB,
44 index, val)) {
45 __glXSetError(gc, GL_INVALID_ENUM);
50 void
51 __indirect_glEnableVertexAttribArrayARB(GLuint index)
53 do_vertex_attrib_enable(index, GL_TRUE);
57 void
58 __indirect_glDisableVertexAttribArrayARB(GLuint index)
60 do_vertex_attrib_enable(index, GL_FALSE);
64 static void
65 get_parameter(unsigned opcode, unsigned size, GLenum target, GLuint index,
66 void *params)
68 struct glx_context *const gc = __glXGetCurrentContext();
69 Display *const dpy = gc->currentDpy;
70 const GLuint cmdlen = 12;
72 if (__builtin_expect(dpy != NULL, 1)) {
73 GLubyte const *pc = __glXSetupVendorRequest(gc,
74 X_GLXVendorPrivateWithReply,
75 opcode, cmdlen);
77 *((GLenum *) (pc + 0)) = target;
78 *((GLuint *) (pc + 4)) = index;
79 *((GLuint *) (pc + 8)) = 0;
81 (void) __glXReadReply(dpy, size, params, GL_FALSE);
82 UnlockDisplay(dpy);
83 SyncHandle();
85 return;
89 void
90 __indirect_glGetProgramEnvParameterfvARB(GLenum target, GLuint index,
91 GLfloat * params)
93 get_parameter(1296, 4, target, index, params);
97 void
98 __indirect_glGetProgramEnvParameterdvARB(GLenum target, GLuint index,
99 GLdouble * params)
101 get_parameter(1297, 8, target, index, params);
105 void
106 __indirect_glGetProgramLocalParameterfvARB(GLenum target, GLuint index,
107 GLfloat * params)
109 get_parameter(1305, 4, target, index, params);
113 void
114 __indirect_glGetProgramLocalParameterdvARB(GLenum target, GLuint index,
115 GLdouble * params)
117 get_parameter(1306, 8, target, index, params);
121 void
122 __indirect_glGetVertexAttribPointervNV(GLuint index, GLenum pname,
123 GLvoid ** pointer)
125 struct glx_context *const gc = __glXGetCurrentContext();
126 __GLXattribute *state = (__GLXattribute *) (gc->client_state_private);
128 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
129 __glXSetError(gc, GL_INVALID_ENUM);
132 if (!__glXGetArrayPointer(state, GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB,
133 index, pointer)) {
134 __glXSetError(gc, GL_INVALID_VALUE);
140 * Get the selected attribute from the vertex array state vector.
142 * \returns
143 * On success \c GL_TRUE is returned. Otherwise, \c GL_FALSE is returned.
145 static GLboolean
146 get_attrib_array_data(__GLXattribute * state, GLuint index, GLenum cap,
147 GLintptr * data)
149 GLboolean retval = GL_FALSE;
150 const GLenum attrib = GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB;
152 switch (cap) {
153 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
154 retval = __glXGetArrayEnable(state, attrib, index, data);
155 break;
157 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
158 retval = __glXGetArraySize(state, attrib, index, data);
159 break;
161 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
162 retval = __glXGetArrayStride(state, attrib, index, data);
163 break;
165 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
166 retval = __glXGetArrayType(state, attrib, index, data);
167 break;
169 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
170 retval = __glXGetArrayNormalized(state, attrib, index, data);
171 break;
175 return retval;
179 static void
180 get_vertex_attrib(struct glx_context * gc, unsigned vop,
181 GLuint index, GLenum pname, xReply * reply)
183 Display *const dpy = gc->currentDpy;
184 GLubyte *const pc = __glXSetupVendorRequest(gc,
185 X_GLXVendorPrivateWithReply,
186 vop, 8);
188 *((uint32_t *) (pc + 0)) = index;
189 *((uint32_t *) (pc + 4)) = pname;
191 (void) _XReply(dpy, reply, 0, False);
195 void
196 __indirect_glGetVertexAttribivARB(GLuint index, GLenum pname, GLint * params)
198 struct glx_context *const gc = __glXGetCurrentContext();
199 Display *const dpy = gc->currentDpy;
200 __GLXattribute *state = (__GLXattribute *) (gc->client_state_private);
201 xGLXSingleReply reply;
204 get_vertex_attrib(gc, 1303, index, pname, (xReply *) & reply);
206 if (reply.size != 0) {
207 GLintptr data;
210 if (get_attrib_array_data(state, index, pname, &data)) {
211 *params = (GLint) data;
213 else {
214 if (reply.size == 1) {
215 *params = (GLint) reply.pad3;
217 else {
218 _XRead(dpy, (void *) params, 4 * reply.size);
223 UnlockDisplay(dpy);
224 SyncHandle();
228 void
229 __indirect_glGetVertexAttribfvARB(GLuint index, GLenum pname,
230 GLfloat * params)
232 struct glx_context *const gc = __glXGetCurrentContext();
233 Display *const dpy = gc->currentDpy;
234 __GLXattribute *state = (__GLXattribute *) (gc->client_state_private);
235 xGLXSingleReply reply;
238 get_vertex_attrib(gc, 1302, index, pname, (xReply *) & reply);
240 if (reply.size != 0) {
241 GLintptr data;
244 if (get_attrib_array_data(state, index, pname, &data)) {
245 *params = (GLfloat) data;
247 else {
248 if (reply.size == 1) {
249 (void) memcpy(params, &reply.pad3, sizeof(GLfloat));
251 else {
252 _XRead(dpy, (void *) params, 4 * reply.size);
257 UnlockDisplay(dpy);
258 SyncHandle();
262 void
263 __indirect_glGetVertexAttribdvARB(GLuint index, GLenum pname,
264 GLdouble * params)
266 struct glx_context *const gc = __glXGetCurrentContext();
267 Display *const dpy = gc->currentDpy;
268 __GLXattribute *state = (__GLXattribute *) (gc->client_state_private);
269 xGLXSingleReply reply;
272 get_vertex_attrib(gc, 1301, index, pname, (xReply *) & reply);
274 if (reply.size != 0) {
275 GLintptr data;
278 if (get_attrib_array_data(state, index, pname, &data)) {
279 *params = (GLdouble) data;
281 else {
282 if (reply.size == 1) {
283 (void) memcpy(params, &reply.pad3, sizeof(GLdouble));
285 else {
286 _XRead(dpy, (void *) params, 8 * reply.size);
291 UnlockDisplay(dpy);
292 SyncHandle();