Clone of mesa.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

glx_texture_compression.c 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. /*
  2. * (C) Copyright IBM Corporation 2004
  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. * on the rights to use, copy, modify, merge, publish, distribute, sub
  9. * license, and/or sell copies of the Software, and to permit persons to whom
  10. * the 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 AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
  20. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  21. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  22. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. /**
  25. * \file glx_texture_compression.c
  26. * Contains the routines required to implement GLX protocol for
  27. * ARB_texture_compression and related extensions.
  28. *
  29. * \sa http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_compression.txt
  30. *
  31. * \author Ian Romanick <idr@us.ibm.com>
  32. */
  33. #include "packrender.h"
  34. #include "packsingle.h"
  35. #include "indirect.h"
  36. #include <assert.h>
  37. void
  38. __indirect_glGetCompressedTexImageARB( GLenum target, GLint level,
  39. GLvoid * img )
  40. {
  41. __GLX_SINGLE_DECLARE_VARIABLES();
  42. xGLXGetTexImageReply reply;
  43. size_t image_bytes;
  44. __GLX_SINGLE_LOAD_VARIABLES();
  45. __GLX_SINGLE_BEGIN( X_GLsop_GetCompressedTexImage, 8 );
  46. __GLX_SINGLE_PUT_LONG( 0, target );
  47. __GLX_SINGLE_PUT_LONG( 4, level );
  48. __GLX_SINGLE_READ_XREPLY();
  49. image_bytes = reply.width;
  50. assert( image_bytes <= ((4 * reply.length) - 0) );
  51. assert( image_bytes >= ((4 * reply.length) - 3) );
  52. if ( image_bytes != 0 ) {
  53. _XRead( dpy, (char *) img, image_bytes );
  54. if ( image_bytes < (4 * reply.length) ) {
  55. _XEatData( dpy, (4 * reply.length) - image_bytes );
  56. }
  57. }
  58. __GLX_SINGLE_END();
  59. }
  60. /**
  61. * Internal function used for \c glCompressedTexImage1D and
  62. * \c glCompressedTexImage2D.
  63. */
  64. static void
  65. CompressedTexImage1D2D( GLenum target, GLint level,
  66. GLenum internal_format,
  67. GLsizei width, GLsizei height,
  68. GLint border, GLsizei image_size,
  69. const GLvoid *data, CARD32 rop )
  70. {
  71. __GLX_DECLARE_VARIABLES();
  72. __GLX_LOAD_VARIABLES();
  73. if ( gc->currentDpy == NULL ) {
  74. return;
  75. }
  76. if ( (target == GL_PROXY_TEXTURE_1D)
  77. || (target == GL_PROXY_TEXTURE_2D)
  78. || (target == GL_PROXY_TEXTURE_CUBE_MAP) ) {
  79. compsize = 0;
  80. }
  81. else {
  82. compsize = image_size;
  83. }
  84. cmdlen = __GLX_PAD( __GLX_COMPRESSED_TEXIMAGE_CMD_HDR_SIZE
  85. + compsize );
  86. if ( cmdlen <= gc->maxSmallRenderCommandSize ) {
  87. __GLX_BEGIN_VARIABLE( rop, cmdlen );
  88. __GLX_PUT_LONG( 4, target );
  89. __GLX_PUT_LONG( 8, level );
  90. __GLX_PUT_LONG( 12, internal_format );
  91. __GLX_PUT_LONG( 16, width );
  92. __GLX_PUT_LONG( 20, height );
  93. __GLX_PUT_LONG( 24, border );
  94. __GLX_PUT_LONG( 28, image_size );
  95. if ( compsize != 0 ) {
  96. __GLX_PUT_CHAR_ARRAY( __GLX_COMPRESSED_TEXIMAGE_CMD_HDR_SIZE,
  97. data, image_size );
  98. }
  99. __GLX_END( cmdlen );
  100. }
  101. else {
  102. assert( compsize != 0 );
  103. __GLX_BEGIN_VARIABLE_LARGE( rop, cmdlen + 4 );
  104. __GLX_PUT_LONG( 8, target );
  105. __GLX_PUT_LONG( 12, level );
  106. __GLX_PUT_LONG( 16, internal_format );
  107. __GLX_PUT_LONG( 20, width );
  108. __GLX_PUT_LONG( 24, height );
  109. __GLX_PUT_LONG( 28, border );
  110. __GLX_PUT_LONG( 32, image_size );
  111. __glXSendLargeCommand( gc, gc->pc,
  112. __GLX_COMPRESSED_TEXIMAGE_CMD_HDR_SIZE + 4,
  113. data, image_size );
  114. }
  115. }
  116. /**
  117. * Internal function used for \c glCompressedTexSubImage1D and
  118. * \c glCompressedTexSubImage2D.
  119. */
  120. static void
  121. CompressedTexSubImage1D2D( GLenum target, GLint level,
  122. GLsizei xoffset, GLsizei yoffset,
  123. GLsizei width, GLsizei height,
  124. GLenum format, GLsizei image_size,
  125. const GLvoid *data, CARD32 rop )
  126. {
  127. __GLX_DECLARE_VARIABLES();
  128. __GLX_LOAD_VARIABLES();
  129. if ( gc->currentDpy == NULL ) {
  130. return;
  131. }
  132. if ( target == GL_PROXY_TEXTURE_3D ) {
  133. compsize = 0;
  134. }
  135. else {
  136. compsize = image_size;
  137. }
  138. cmdlen = __GLX_PAD( __GLX_COMPRESSED_TEXSUBIMAGE_CMD_HDR_SIZE
  139. + compsize );
  140. if ( cmdlen <= gc->maxSmallRenderCommandSize ) {
  141. __GLX_BEGIN_VARIABLE( rop, cmdlen );
  142. __GLX_PUT_LONG( 4, target );
  143. __GLX_PUT_LONG( 8, level );
  144. __GLX_PUT_LONG( 12, xoffset );
  145. __GLX_PUT_LONG( 16, yoffset );
  146. __GLX_PUT_LONG( 20, width );
  147. __GLX_PUT_LONG( 24, height );
  148. __GLX_PUT_LONG( 28, format );
  149. __GLX_PUT_LONG( 32, image_size );
  150. if ( compsize != 0 ) {
  151. __GLX_PUT_CHAR_ARRAY( __GLX_COMPRESSED_TEXSUBIMAGE_CMD_HDR_SIZE,
  152. data, image_size );
  153. }
  154. __GLX_END( cmdlen );
  155. }
  156. else {
  157. assert( compsize != 0 );
  158. __GLX_BEGIN_VARIABLE_LARGE( rop, cmdlen + 4 );
  159. __GLX_PUT_LONG( 8, target );
  160. __GLX_PUT_LONG( 12, level );
  161. __GLX_PUT_LONG( 16, xoffset );
  162. __GLX_PUT_LONG( 20, yoffset );
  163. __GLX_PUT_LONG( 24, width );
  164. __GLX_PUT_LONG( 28, height );
  165. __GLX_PUT_LONG( 32, format );
  166. __GLX_PUT_LONG( 36, image_size );
  167. __glXSendLargeCommand( gc, gc->pc,
  168. __GLX_COMPRESSED_TEXSUBIMAGE_CMD_HDR_SIZE + 4,
  169. data, image_size );
  170. }
  171. }
  172. void
  173. __indirect_glCompressedTexImage1DARB( GLenum target, GLint level,
  174. GLenum internal_format, GLsizei width,
  175. GLint border, GLsizei image_size,
  176. const GLvoid *data )
  177. {
  178. CompressedTexImage1D2D( target, level, internal_format, width, 0,
  179. border, image_size, data,
  180. X_GLrop_CompressedTexImage1D );
  181. }
  182. void
  183. __indirect_glCompressedTexImage2DARB( GLenum target, GLint level,
  184. GLenum internal_format,
  185. GLsizei width, GLsizei height,
  186. GLint border, GLsizei image_size,
  187. const GLvoid *data )
  188. {
  189. CompressedTexImage1D2D( target, level, internal_format, width, height,
  190. border, image_size, data,
  191. X_GLrop_CompressedTexImage2D );
  192. }
  193. void
  194. __indirect_glCompressedTexImage3DARB( GLenum target, GLint level,
  195. GLenum internal_format,
  196. GLsizei width, GLsizei height, GLsizei depth,
  197. GLint border, GLsizei image_size,
  198. const GLvoid *data )
  199. {
  200. __GLX_DECLARE_VARIABLES();
  201. __GLX_LOAD_VARIABLES();
  202. if ( gc->currentDpy == NULL ) {
  203. return;
  204. }
  205. cmdlen = __GLX_PAD( __GLX_COMPRESSED_TEXIMAGE_3D_CMD_HDR_SIZE
  206. + image_size );
  207. if ( cmdlen <= gc->maxSmallRenderCommandSize ) {
  208. __GLX_BEGIN_VARIABLE( X_GLrop_CompressedTexImage3D, cmdlen );
  209. __GLX_PUT_LONG( 4, target );
  210. __GLX_PUT_LONG( 8, level );
  211. __GLX_PUT_LONG( 12, internal_format );
  212. __GLX_PUT_LONG( 16, width );
  213. __GLX_PUT_LONG( 20, height );
  214. __GLX_PUT_LONG( 24, depth );
  215. __GLX_PUT_LONG( 28, border );
  216. __GLX_PUT_LONG( 32, image_size );
  217. if ( image_size != 0 ) {
  218. __GLX_PUT_CHAR_ARRAY( __GLX_COMPRESSED_TEXIMAGE_3D_CMD_HDR_SIZE,
  219. data, image_size );
  220. }
  221. __GLX_END( cmdlen );
  222. }
  223. else {
  224. __GLX_BEGIN_VARIABLE_LARGE( X_GLrop_CompressedTexImage3D,
  225. cmdlen + 4 );
  226. __GLX_PUT_LONG( 8, target );
  227. __GLX_PUT_LONG( 12, level );
  228. __GLX_PUT_LONG( 16, internal_format );
  229. __GLX_PUT_LONG( 20, width );
  230. __GLX_PUT_LONG( 24, height );
  231. __GLX_PUT_LONG( 28, depth );
  232. __GLX_PUT_LONG( 32, border );
  233. __GLX_PUT_LONG( 36, image_size );
  234. __glXSendLargeCommand( gc, gc->pc,
  235. __GLX_COMPRESSED_TEXIMAGE_3D_CMD_HDR_SIZE + 4,
  236. data, image_size );
  237. }
  238. }
  239. void
  240. __indirect_glCompressedTexSubImage1DARB( GLenum target, GLint level,
  241. GLint xoffset,
  242. GLsizei width,
  243. GLenum format, GLsizei image_size,
  244. const GLvoid *data )
  245. {
  246. CompressedTexSubImage1D2D( target, level, xoffset, 0, width, 0,
  247. format, image_size, data,
  248. X_GLrop_CompressedTexSubImage1D );
  249. }
  250. void
  251. __indirect_glCompressedTexSubImage2DARB( GLenum target, GLint level,
  252. GLint xoffset, GLint yoffset,
  253. GLsizei width, GLsizei height,
  254. GLenum format, GLsizei image_size,
  255. const GLvoid *data )
  256. {
  257. CompressedTexSubImage1D2D( target, level, xoffset, yoffset, width, height,
  258. format, image_size, data,
  259. X_GLrop_CompressedTexSubImage2D );
  260. }
  261. void
  262. __indirect_glCompressedTexSubImage3DARB( GLenum target, GLint level,
  263. GLint xoffset, GLint yoffset, GLint zoffset,
  264. GLsizei width, GLsizei height, GLsizei depth,
  265. GLenum format, GLsizei image_size,
  266. const GLvoid *data )
  267. {
  268. __GLX_DECLARE_VARIABLES();
  269. __GLX_LOAD_VARIABLES();
  270. if ( gc->currentDpy == NULL ) {
  271. return;
  272. }
  273. cmdlen = __GLX_PAD( __GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE
  274. + image_size );
  275. if ( cmdlen <= gc->maxSmallRenderCommandSize ) {
  276. __GLX_BEGIN_VARIABLE( X_GLrop_CompressedTexSubImage3D, cmdlen );
  277. __GLX_PUT_LONG( 4, target );
  278. __GLX_PUT_LONG( 8, level );
  279. __GLX_PUT_LONG( 12, xoffset );
  280. __GLX_PUT_LONG( 16, yoffset );
  281. __GLX_PUT_LONG( 20, zoffset );
  282. __GLX_PUT_LONG( 24, width );
  283. __GLX_PUT_LONG( 28, height );
  284. __GLX_PUT_LONG( 32, depth );
  285. __GLX_PUT_LONG( 36, format );
  286. __GLX_PUT_LONG( 40, image_size );
  287. if ( image_size != 0 ) {
  288. __GLX_PUT_CHAR_ARRAY( __GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE,
  289. data, image_size );
  290. }
  291. __GLX_END( cmdlen );
  292. }
  293. else {
  294. __GLX_BEGIN_VARIABLE_LARGE( X_GLrop_CompressedTexSubImage3D,
  295. cmdlen + 4 );
  296. __GLX_PUT_LONG( 8, target );
  297. __GLX_PUT_LONG( 12, level );
  298. __GLX_PUT_LONG( 16, xoffset );
  299. __GLX_PUT_LONG( 20, yoffset );
  300. __GLX_PUT_LONG( 24, zoffset );
  301. __GLX_PUT_LONG( 28, width );
  302. __GLX_PUT_LONG( 32, height );
  303. __GLX_PUT_LONG( 36, depth );
  304. __GLX_PUT_LONG( 40, format );
  305. __GLX_PUT_LONG( 44, image_size );
  306. __glXSendLargeCommand( gc, gc->pc,
  307. __GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE + 4,
  308. data, image_size );
  309. }
  310. }