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