indirect_texture_compression.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. #ifdef HAVE_DIX_CONFIG_H
  26. #include <dix-config.h>
  27. #endif
  28. #include "glxserver.h"
  29. #include "glxbyteorder.h"
  30. #include "glxext.h"
  31. #include "singlesize.h"
  32. #include "unpack.h"
  33. #include "indirect_size_get.h"
  34. #include "indirect_dispatch.h"
  35. int
  36. __glXDisp_GetCompressedTexImage(struct __GLXclientStateRec *cl, GLbyte * pc)
  37. {
  38. xGLXSingleReq *const req = (xGLXSingleReq *) pc;
  39. int error;
  40. __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
  41. ClientPtr client = cl->client;
  42. REQUEST_FIXED_SIZE(xGLXSingleReq, 8);
  43. pc += __GLX_SINGLE_HDR_SIZE;
  44. if (cx != NULL) {
  45. const GLenum target = *(GLenum *) (pc + 0);
  46. const GLint level = *(GLint *) (pc + 4);
  47. GLint compsize = 0;
  48. char *answer = NULL, answerBuffer[200];
  49. glGetTexLevelParameteriv(target, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
  50. &compsize);
  51. if (compsize != 0) {
  52. PFNGLGETCOMPRESSEDTEXIMAGEARBPROC GetCompressedTexImageARB =
  53. __glGetProcAddress("glGetCompressedTexImageARB");
  54. __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1);
  55. __glXClearErrorOccured();
  56. GetCompressedTexImageARB(target, level, answer);
  57. }
  58. if (__glXErrorOccured()) {
  59. __GLX_BEGIN_REPLY(0);
  60. __GLX_SEND_HEADER();
  61. }
  62. else {
  63. __GLX_BEGIN_REPLY(compsize);
  64. ((xGLXGetTexImageReply *) &__glXReply)->width = compsize;
  65. __GLX_SEND_HEADER();
  66. __GLX_SEND_VOID_ARRAY(compsize);
  67. }
  68. error = Success;
  69. }
  70. return error;
  71. }
  72. int
  73. __glXDispSwap_GetCompressedTexImage(struct __GLXclientStateRec *cl, GLbyte * pc)
  74. {
  75. xGLXSingleReq *const req = (xGLXSingleReq *) pc;
  76. int error;
  77. __GLXcontext *const cx =
  78. __glXForceCurrent(cl, bswap_32(req->contextTag), &error);
  79. ClientPtr client = cl->client;
  80. REQUEST_FIXED_SIZE(xGLXSingleReq, 8);
  81. pc += __GLX_SINGLE_HDR_SIZE;
  82. if (cx != NULL) {
  83. const GLenum target = (GLenum) bswap_32(*(int *) (pc + 0));
  84. const GLint level = (GLint) bswap_32(*(int *) (pc + 4));
  85. GLint compsize = 0;
  86. char *answer = NULL, answerBuffer[200];
  87. glGetTexLevelParameteriv(target, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
  88. &compsize);
  89. if (compsize != 0) {
  90. PFNGLGETCOMPRESSEDTEXIMAGEARBPROC GetCompressedTexImageARB =
  91. __glGetProcAddress("glGetCompressedTexImageARB");
  92. __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1);
  93. __glXClearErrorOccured();
  94. GetCompressedTexImageARB(target, level, answer);
  95. }
  96. if (__glXErrorOccured()) {
  97. __GLX_BEGIN_REPLY(0);
  98. __GLX_SEND_HEADER();
  99. }
  100. else {
  101. __GLX_BEGIN_REPLY(compsize);
  102. ((xGLXGetTexImageReply *) &__glXReply)->width = compsize;
  103. __GLX_SEND_HEADER();
  104. __GLX_SEND_VOID_ARRAY(compsize);
  105. }
  106. error = Success;
  107. }
  108. return error;
  109. }