indirect_program.c (4157B)
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 */ 47 static int 48 DoGetProgramString(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 pc += __GLX_VENDPRIV_HDR_SIZE; 62 if (cx != NULL) { 63 GLenum target; 64 GLenum pname; 65 GLint compsize = 0; 66 char *answer = NULL, answerBuffer[200]; 67 xGLXSingleReply reply = { 0, }; 68 69 if (do_swap) { 70 target = (GLenum) bswap_32(*(int *) (pc + 0)); 71 pname = (GLenum) bswap_32(*(int *) (pc + 4)); 72 } 73 else { 74 target = *(GLenum *) (pc + 0); 75 pname = *(GLuint *) (pc + 4); 76 } 77 78 /* The value of the GL_PROGRAM_LENGTH_ARB and GL_PROGRAM_LENGTH_NV 79 * enumerants is the same. 80 */ 81 get_programiv(target, GL_PROGRAM_LENGTH_ARB, &compsize); 82 83 if (compsize != 0) { 84 __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1); 85 __glXClearErrorOccured(); 86 87 get_program_string(target, pname, (GLubyte *) answer); 88 } 89 90 if (__glXErrorOccured()) { 91 __GLX_BEGIN_REPLY(0); 92 __GLX_SEND_HEADER(); 93 } 94 else { 95 __GLX_BEGIN_REPLY(compsize); 96 ((xGLXGetTexImageReply *) &reply)->width = compsize; 97 __GLX_SEND_HEADER(); 98 __GLX_SEND_VOID_ARRAY(compsize); 99 } 100 101 error = Success; 102 } 103 104 return error; 105 } 106 107 int 108 __glXDisp_GetProgramStringARB(struct __GLXclientStateRec *cl, GLbyte * pc) 109 { 110 PFNGLGETPROGRAMIVARBPROC get_program = 111 __glGetProcAddress("glGetProgramivARB"); 112 PFNGLGETPROGRAMSTRINGARBPROC get_program_string = 113 __glGetProcAddress("glGetProgramStringARB"); 114 115 return DoGetProgramString(cl, pc, get_program, get_program_string, FALSE); 116 } 117 118 int 119 __glXDispSwap_GetProgramStringARB(struct __GLXclientStateRec *cl, GLbyte * pc) 120 { 121 PFNGLGETPROGRAMIVARBPROC get_program = 122 __glGetProcAddress("glGetProgramivARB"); 123 PFNGLGETPROGRAMSTRINGARBPROC get_program_string = 124 __glGetProcAddress("glGetProgramStringARB"); 125 126 return DoGetProgramString(cl, pc, get_program, get_program_string, TRUE); 127 }