indirect_program.c revision 4642e01f
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#define NEED_REPLIES 33#ifdef HAVE_DIX_CONFIG_H 34#include <dix-config.h> 35#endif 36 37#include "glxserver.h" 38#include "glxbyteorder.h" 39#include "glxext.h" 40#include "singlesize.h" 41#include "unpack.h" 42#include "indirect_size_get.h" 43#include "indirect_dispatch.h" 44#include "glapitable.h" 45#include "glapi.h" 46#include "glthread.h" 47#include "dispatch.h" 48#include "glapioffsets.h" 49 50static int DoGetProgramString(struct __GLXclientStateRec *cl, GLbyte *pc, 51 unsigned get_programiv_offset, unsigned get_program_string_offset, 52 Bool do_swap); 53 54/** 55 * Handle both types of glGetProgramString calls. 56 * 57 * This single function handles both \c glGetProgramStringARB and 58 * \c glGetProgramStringNV. The dispatch offsets for the functions to use 59 * for \c glGetProgramivARB and \c glGetProgramStringARB are passed in by the 60 * caller. These can be the offsets of either the ARB versions or the NV 61 * versions. 62 */ 63int DoGetProgramString(struct __GLXclientStateRec *cl, GLbyte *pc, 64 unsigned get_programiv_offset, 65 unsigned get_program_string_offset, 66 Bool do_swap) 67{ 68 xGLXVendorPrivateWithReplyReq * const req = 69 (xGLXVendorPrivateWithReplyReq *) pc; 70 int error; 71 __GLXcontext * const cx = __glXForceCurrent(cl, req->contextTag, & error); 72 ClientPtr client = cl->client; 73 74 75 pc += __GLX_VENDPRIV_HDR_SIZE; 76 if (cx != NULL) { 77 GLenum target; 78 GLenum pname; 79 GLint compsize = 0; 80 char *answer = NULL, answerBuffer[200]; 81 82 if (do_swap) { 83 target = (GLenum) bswap_32(*(int *)(pc + 0)); 84 pname = (GLenum) bswap_32(*(int *)(pc + 4)); 85 } 86 else { 87 target = *(GLenum *)(pc + 0); 88 pname = *(GLuint *)(pc + 4); 89 } 90 91 /* The value of the GL_PROGRAM_LENGTH_ARB and GL_PROGRAM_LENGTH_NV 92 * enumerants is the same. 93 */ 94 CALL_by_offset(GET_DISPATCH(), 95 (void (GLAPIENTRYP)(GLuint, GLenum, GLint *)), 96 get_programiv_offset, 97 (target, GL_PROGRAM_LENGTH_ARB, &compsize)); 98 99 if (compsize != 0) { 100 __GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1); 101 __glXClearErrorOccured(); 102 103 CALL_by_offset(GET_DISPATCH(), 104 (void (GLAPIENTRYP)(GLuint, GLenum, GLubyte *)), 105 get_program_string_offset, 106 (target, pname, answer)); 107 } 108 109 if (__glXErrorOccured()) { 110 __GLX_BEGIN_REPLY(0); 111 __GLX_SEND_HEADER(); 112 } else { 113 __GLX_BEGIN_REPLY(compsize); 114 ((xGLXGetTexImageReply *)&__glXReply)->width = compsize; 115 __GLX_SEND_HEADER(); 116 __GLX_SEND_VOID_ARRAY(compsize); 117 } 118 119 error = Success; 120 } 121 122 return error; 123} 124 125int __glXDisp_GetProgramStringARB(struct __GLXclientStateRec *cl, GLbyte *pc) 126{ 127 return DoGetProgramString(cl, pc, _gloffset_GetProgramivARB, 128 _gloffset_GetProgramStringARB, False); 129} 130 131 132int __glXDispSwap_GetProgramStringARB(struct __GLXclientStateRec *cl, GLbyte *pc) 133{ 134 return DoGetProgramString(cl, pc, _gloffset_GetProgramivARB, 135 _gloffset_GetProgramStringARB, True); 136} 137 138 139int __glXDisp_GetProgramStringNV(struct __GLXclientStateRec *cl, GLbyte *pc) 140{ 141 return DoGetProgramString(cl, pc, _gloffset_GetProgramivNV, 142 _gloffset_GetProgramStringNV, False); 143} 144 145 146int __glXDispSwap_GetProgramStringNV(struct __GLXclientStateRec *cl, GLbyte *pc) 147{ 148 return DoGetProgramString(cl, pc, _gloffset_GetProgramivNV, 149 _gloffset_GetProgramStringNV, True); 150} 151