indirect_texture_compression.c revision 7e31ba66
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 * IBM, 20 * AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 * SOFTWARE. 24 */ 25 26#ifdef HAVE_DIX_CONFIG_H 27#include <dix-config.h> 28#endif 29 30#include "glxserver.h" 31#include "glxbyteorder.h" 32#include "glxext.h" 33#include "singlesize.h" 34#include "unpack.h" 35#include "indirect_size_get.h" 36#include "indirect_dispatch.h" 37 38int 39__glXDisp_GetCompressedTexImage(struct __GLXclientStateRec *cl, GLbyte * pc) 40{ 41 xGLXSingleReq *const req = (xGLXSingleReq *) pc; 42 int error; 43 __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error); 44 ClientPtr client = cl->client; 45 46 REQUEST_FIXED_SIZE(xGLXSingleReq, 8); 47 48 REQUEST_FIXED_SIZE(xGLXSingleReq, 8); 49 50 pc += __GLX_SINGLE_HDR_SIZE; 51 if (cx != NULL) { 52 const GLenum target = *(GLenum *) (pc + 0); 53 const GLint level = *(GLint *) (pc + 4); 54 GLint compsize = 0; 55 char *answer = NULL, answerBuffer[200]; 56 xGLXSingleReply reply = { 0, }; 57 58 glGetTexLevelParameteriv(target, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, 59 &compsize); 60 61 if (compsize != 0) { 62 PFNGLGETCOMPRESSEDTEXIMAGEARBPROC GetCompressedTexImageARB = 63 __glGetProcAddress("glGetCompressedTexImageARB"); 64 __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1); 65 __glXClearErrorOccured(); 66 GetCompressedTexImageARB(target, level, answer); 67 } 68 69 if (__glXErrorOccured()) { 70 __GLX_BEGIN_REPLY(0); 71 __GLX_SEND_HEADER(); 72 } 73 else { 74 __GLX_BEGIN_REPLY(compsize); 75 ((xGLXGetTexImageReply *) &reply)->width = compsize; 76 __GLX_SEND_HEADER(); 77 __GLX_SEND_VOID_ARRAY(compsize); 78 } 79 80 error = Success; 81 } 82 83 return error; 84} 85 86int 87__glXDispSwap_GetCompressedTexImage(struct __GLXclientStateRec *cl, GLbyte * pc) 88{ 89 xGLXSingleReq *const req = (xGLXSingleReq *) pc; 90 int error; 91 __GLXcontext *const cx = 92 __glXForceCurrent(cl, bswap_32(req->contextTag), &error); 93 ClientPtr client = cl->client; 94 95 REQUEST_FIXED_SIZE(xGLXSingleReq, 8); 96 97 REQUEST_FIXED_SIZE(xGLXSingleReq, 8); 98 99 pc += __GLX_SINGLE_HDR_SIZE; 100 if (cx != NULL) { 101 const GLenum target = (GLenum) bswap_32(*(int *) (pc + 0)); 102 const GLint level = (GLint) bswap_32(*(int *) (pc + 4)); 103 GLint compsize = 0; 104 char *answer = NULL, answerBuffer[200]; 105 xGLXSingleReply reply = { 0, }; 106 107 glGetTexLevelParameteriv(target, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, 108 &compsize); 109 110 if (compsize != 0) { 111 PFNGLGETCOMPRESSEDTEXIMAGEARBPROC GetCompressedTexImageARB = 112 __glGetProcAddress("glGetCompressedTexImageARB"); 113 __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1); 114 __glXClearErrorOccured(); 115 GetCompressedTexImageARB(target, level, answer); 116 } 117 118 if (__glXErrorOccured()) { 119 __GLX_BEGIN_REPLY(0); 120 __GLX_SEND_HEADER(); 121 } 122 else { 123 __GLX_BEGIN_REPLY(compsize); 124 ((xGLXGetTexImageReply *) &reply)->width = compsize; 125 __GLX_SEND_HEADER(); 126 __GLX_SEND_VOID_ARRAY(compsize); 127 } 128 129 error = Success; 130 } 131 132 return error; 133} 134