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