indirect_program.c revision f7df2e56
1/*
2 * (C) Copyright IBM Corporation 2005, 2006
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 * THE COPYRIGHT HOLDERS, THE AUTHORS, AND/OR THEIR SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25/**
26 * \file indirect_program.c
27 * Hand-coded routines needed to support programmable pipeline extensions.
28 *
29 * \author Ian Romanick <idr@us.ibm.com>
30 */
31
32#ifdef HAVE_DIX_CONFIG_H
33#include <dix-config.h>
34#endif
35
36#include "glxserver.h"
37#include "glxbyteorder.h"
38#include "glxext.h"
39#include "singlesize.h"
40#include "unpack.h"
41#include "indirect_size_get.h"
42#include "indirect_dispatch.h"
43
44/**
45 * Handle both types of glGetProgramString calls.
46 */
47static int
48DoGetProgramString(struct __GLXclientStateRec *cl, GLbyte * pc,
49                   PFNGLGETPROGRAMIVARBPROC get_programiv,
50                   PFNGLGETPROGRAMSTRINGARBPROC get_program_string,
51                   Bool do_swap)
52{
53    xGLXVendorPrivateWithReplyReq *const req =
54        (xGLXVendorPrivateWithReplyReq *) pc;
55    int error;
56    __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
57    ClientPtr client = cl->client;
58
59    REQUEST_FIXED_SIZE(xGLXVendorPrivateWithReplyReq, 8);
60
61    REQUEST_FIXED_SIZE(xGLXVendorPrivateWithReplyReq, 8);
62
63    pc += __GLX_VENDPRIV_HDR_SIZE;
64    if (cx != NULL) {
65        GLenum target;
66        GLenum pname;
67        GLint compsize = 0;
68        char *answer = NULL, answerBuffer[200];
69
70        if (do_swap) {
71            target = (GLenum) bswap_32(*(int *) (pc + 0));
72            pname = (GLenum) bswap_32(*(int *) (pc + 4));
73        }
74        else {
75            target = *(GLenum *) (pc + 0);
76            pname = *(GLuint *) (pc + 4);
77        }
78
79        /* The value of the GL_PROGRAM_LENGTH_ARB and GL_PROGRAM_LENGTH_NV
80         * enumerants is the same.
81         */
82        get_programiv(target, GL_PROGRAM_LENGTH_ARB, &compsize);
83
84        if (compsize != 0) {
85            __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1);
86            __glXClearErrorOccured();
87
88            get_program_string(target, pname, (GLubyte *) answer);
89        }
90
91        if (__glXErrorOccured()) {
92            __GLX_BEGIN_REPLY(0);
93            __GLX_SEND_HEADER();
94        }
95        else {
96            __GLX_BEGIN_REPLY(compsize);
97            ((xGLXGetTexImageReply *) &__glXReply)->width = compsize;
98            __GLX_SEND_HEADER();
99            __GLX_SEND_VOID_ARRAY(compsize);
100        }
101
102        error = Success;
103    }
104
105    return error;
106}
107
108int
109__glXDisp_GetProgramStringARB(struct __GLXclientStateRec *cl, GLbyte * pc)
110{
111    PFNGLGETPROGRAMIVARBPROC get_program =
112        __glGetProcAddress("glGetProgramivARB");
113    PFNGLGETPROGRAMSTRINGARBPROC get_program_string =
114        __glGetProcAddress("glGetProgramStringARB");
115
116    return DoGetProgramString(cl, pc, get_program, get_program_string, False);
117}
118
119int
120__glXDispSwap_GetProgramStringARB(struct __GLXclientStateRec *cl, GLbyte * pc)
121{
122    PFNGLGETPROGRAMIVARBPROC get_program =
123        __glGetProcAddress("glGetProgramivARB");
124    PFNGLGETPROGRAMSTRINGARBPROC get_program_string =
125        __glGetProcAddress("glGetProgramStringARB");
126
127    return DoGetProgramString(cl, pc, get_program, get_program_string, True);
128}
129