1706f2543Smrg/* 2706f2543Smrg * (C) Copyright IBM Corporation 2005, 2006 3706f2543Smrg * All Rights Reserved. 4706f2543Smrg * 5706f2543Smrg * Permission is hereby granted, free of charge, to any person obtaining a 6706f2543Smrg * copy of this software and associated documentation files (the "Software"), 7706f2543Smrg * to deal in the Software without restriction, including without limitation 8706f2543Smrg * the rights to use, copy, modify, merge, publish, distribute, sub license, 9706f2543Smrg * and/or sell copies of the Software, and to permit persons to whom the 10706f2543Smrg * Software is furnished to do so, subject to the following conditions: 11706f2543Smrg * 12706f2543Smrg * The above copyright notice and this permission notice (including the next 13706f2543Smrg * paragraph) shall be included in all copies or substantial portions of the 14706f2543Smrg * Software. 15706f2543Smrg * 16706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17706f2543Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18706f2543Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 19706f2543Smrg * THE COPYRIGHT HOLDERS, THE AUTHORS, AND/OR THEIR SUPPLIERS BE LIABLE FOR 20706f2543Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21706f2543Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 22706f2543Smrg * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23706f2543Smrg */ 24706f2543Smrg 25706f2543Smrg/** 26706f2543Smrg * \file indirect_program.c 27706f2543Smrg * Hand-coded routines needed to support programmable pipeline extensions. 28706f2543Smrg * 29706f2543Smrg * \author Ian Romanick <idr@us.ibm.com> 30706f2543Smrg */ 31706f2543Smrg 32706f2543Smrg#ifdef HAVE_DIX_CONFIG_H 33706f2543Smrg#include <dix-config.h> 34706f2543Smrg#endif 35706f2543Smrg 36706f2543Smrg#include "glxserver.h" 37706f2543Smrg#include "glxbyteorder.h" 38706f2543Smrg#include "glxext.h" 39706f2543Smrg#include "singlesize.h" 40706f2543Smrg#include "unpack.h" 41706f2543Smrg#include "indirect_size_get.h" 42706f2543Smrg#include "indirect_dispatch.h" 43706f2543Smrg#include "glapitable.h" 44706f2543Smrg#include "glapi.h" 45706f2543Smrg#include "glthread.h" 46706f2543Smrg#include "dispatch.h" 47706f2543Smrg#include "glapioffsets.h" 48706f2543Smrg 49706f2543Smrgstatic int DoGetProgramString(struct __GLXclientStateRec *cl, GLbyte *pc, 50706f2543Smrg unsigned get_programiv_offset, unsigned get_program_string_offset, 51706f2543Smrg Bool do_swap); 52706f2543Smrg 53706f2543Smrg/** 54706f2543Smrg * Handle both types of glGetProgramString calls. 55706f2543Smrg * 56706f2543Smrg * This single function handles both \c glGetProgramStringARB and 57706f2543Smrg * \c glGetProgramStringNV. The dispatch offsets for the functions to use 58706f2543Smrg * for \c glGetProgramivARB and \c glGetProgramStringARB are passed in by the 59706f2543Smrg * caller. These can be the offsets of either the ARB versions or the NV 60706f2543Smrg * versions. 61706f2543Smrg */ 62706f2543Smrgint DoGetProgramString(struct __GLXclientStateRec *cl, GLbyte *pc, 63706f2543Smrg unsigned get_programiv_offset, 64706f2543Smrg unsigned get_program_string_offset, 65706f2543Smrg Bool do_swap) 66706f2543Smrg{ 67706f2543Smrg xGLXVendorPrivateWithReplyReq * const req = 68706f2543Smrg (xGLXVendorPrivateWithReplyReq *) pc; 69706f2543Smrg int error; 70706f2543Smrg __GLXcontext * const cx = __glXForceCurrent(cl, req->contextTag, & error); 71706f2543Smrg ClientPtr client = cl->client; 72706f2543Smrg 73706f2543Smrg 74706f2543Smrg REQUEST_FIXED_SIZE(xGLXVendorPrivateWithReplyReq, 8); 75706f2543Smrg 76706f2543Smrg pc += __GLX_VENDPRIV_HDR_SIZE; 77706f2543Smrg if (cx != NULL) { 78706f2543Smrg GLenum target; 79706f2543Smrg GLenum pname; 80706f2543Smrg GLint compsize = 0; 81706f2543Smrg char *answer = NULL, answerBuffer[200]; 82706f2543Smrg 83706f2543Smrg if (do_swap) { 84706f2543Smrg target = (GLenum) bswap_32(*(int *)(pc + 0)); 85706f2543Smrg pname = (GLenum) bswap_32(*(int *)(pc + 4)); 86706f2543Smrg } 87706f2543Smrg else { 88706f2543Smrg target = *(GLenum *)(pc + 0); 89706f2543Smrg pname = *(GLuint *)(pc + 4); 90706f2543Smrg } 91706f2543Smrg 92706f2543Smrg /* The value of the GL_PROGRAM_LENGTH_ARB and GL_PROGRAM_LENGTH_NV 93706f2543Smrg * enumerants is the same. 94706f2543Smrg */ 95706f2543Smrg CALL_by_offset(GET_DISPATCH(), 96706f2543Smrg (void (GLAPIENTRYP)(GLuint, GLenum, GLint *)), 97706f2543Smrg get_programiv_offset, 98706f2543Smrg (target, GL_PROGRAM_LENGTH_ARB, &compsize)); 99706f2543Smrg 100706f2543Smrg if (compsize != 0) { 101706f2543Smrg __GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1); 102706f2543Smrg __glXClearErrorOccured(); 103706f2543Smrg 104706f2543Smrg CALL_by_offset(GET_DISPATCH(), 105706f2543Smrg (void (GLAPIENTRYP)(GLuint, GLenum, GLubyte *)), 106706f2543Smrg get_program_string_offset, 107706f2543Smrg (target, pname, (GLubyte *)answer)); 108706f2543Smrg } 109706f2543Smrg 110706f2543Smrg if (__glXErrorOccured()) { 111706f2543Smrg __GLX_BEGIN_REPLY(0); 112706f2543Smrg __GLX_SEND_HEADER(); 113706f2543Smrg } else { 114706f2543Smrg __GLX_BEGIN_REPLY(compsize); 115706f2543Smrg ((xGLXGetTexImageReply *)&__glXReply)->width = compsize; 116706f2543Smrg __GLX_SEND_HEADER(); 117706f2543Smrg __GLX_SEND_VOID_ARRAY(compsize); 118706f2543Smrg } 119706f2543Smrg 120706f2543Smrg error = Success; 121706f2543Smrg } 122706f2543Smrg 123706f2543Smrg return error; 124706f2543Smrg} 125706f2543Smrg 126706f2543Smrgint __glXDisp_GetProgramStringARB(struct __GLXclientStateRec *cl, GLbyte *pc) 127706f2543Smrg{ 128706f2543Smrg return DoGetProgramString(cl, pc, _gloffset_GetProgramivARB, 129706f2543Smrg _gloffset_GetProgramStringARB, False); 130706f2543Smrg} 131706f2543Smrg 132706f2543Smrg 133706f2543Smrgint __glXDispSwap_GetProgramStringARB(struct __GLXclientStateRec *cl, GLbyte *pc) 134706f2543Smrg{ 135706f2543Smrg return DoGetProgramString(cl, pc, _gloffset_GetProgramivARB, 136706f2543Smrg _gloffset_GetProgramStringARB, True); 137706f2543Smrg} 138706f2543Smrg 139706f2543Smrg 140706f2543Smrgint __glXDisp_GetProgramStringNV(struct __GLXclientStateRec *cl, GLbyte *pc) 141706f2543Smrg{ 142706f2543Smrg return DoGetProgramString(cl, pc, _gloffset_GetProgramivNV, 143706f2543Smrg _gloffset_GetProgramStringNV, False); 144706f2543Smrg} 145706f2543Smrg 146706f2543Smrg 147706f2543Smrgint __glXDispSwap_GetProgramStringNV(struct __GLXclientStateRec *cl, GLbyte *pc) 148706f2543Smrg{ 149706f2543Smrg return DoGetProgramString(cl, pc, _gloffset_GetProgramivNV, 150706f2543Smrg _gloffset_GetProgramStringNV, True); 151706f2543Smrg} 152