2 * (C) Copyright IBM Corporation 2004
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:
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
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.
26 * \file glx_texture_compression.c
27 * Contains the routines required to implement GLX protocol for
28 * ARB_texture_compression and related extensions.
30 * \sa http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_compression.txt
32 * \author Ian Romanick <idr@us.ibm.com>
35 #include "packrender.h"
36 #include "packsingle.h"
42 __indirect_glGetCompressedTexImage( GLenum target
, GLint level
,
45 __GLX_SINGLE_DECLARE_VARIABLES();
46 xGLXGetTexImageReply reply
;
49 __GLX_SINGLE_LOAD_VARIABLES();
50 __GLX_SINGLE_BEGIN( X_GLsop_GetCompressedTexImage
, 8 );
51 __GLX_SINGLE_PUT_LONG( 0, target
);
52 __GLX_SINGLE_PUT_LONG( 4, level
);
53 __GLX_SINGLE_READ_XREPLY();
55 image_bytes
= reply
.width
;
56 assert( image_bytes
<= ((4 * reply
.length
) - 0) );
57 assert( image_bytes
>= ((4 * reply
.length
) - 3) );
59 if ( image_bytes
!= 0 ) {
60 _XRead( dpy
, (char *) img
, image_bytes
);
61 if ( image_bytes
< (4 * reply
.length
) ) {
62 _XEatData( dpy
, (4 * reply
.length
) - image_bytes
);
71 * Internal function used for \c glCompressedTexImage1D and
72 * \c glCompressedTexImage2D.
75 CompressedTexImage1D2D( GLenum target
, GLint level
,
76 GLenum internal_format
,
77 GLsizei width
, GLsizei height
,
78 GLint border
, GLsizei image_size
,
79 const GLvoid
*data
, CARD32 rop
)
81 __GLX_DECLARE_VARIABLES();
83 __GLX_LOAD_VARIABLES();
84 if ( gc
->currentDpy
== NULL
) {
88 if ( (target
== GL_PROXY_TEXTURE_1D
)
89 || (target
== GL_PROXY_TEXTURE_2D
)
90 || (target
== GL_PROXY_TEXTURE_CUBE_MAP
) ) {
94 compsize
= image_size
;
97 cmdlen
= __GLX_PAD( __GLX_COMPRESSED_TEXIMAGE_CMD_HDR_SIZE
99 if ( cmdlen
<= gc
->maxSmallRenderCommandSize
) {
100 __GLX_BEGIN_VARIABLE( rop
, cmdlen
);
101 __GLX_PUT_LONG( 4, target
);
102 __GLX_PUT_LONG( 8, level
);
103 __GLX_PUT_LONG( 12, internal_format
);
104 __GLX_PUT_LONG( 16, width
);
105 __GLX_PUT_LONG( 20, height
);
106 __GLX_PUT_LONG( 24, border
);
107 __GLX_PUT_LONG( 28, image_size
);
108 if ( compsize
!= 0 ) {
109 __GLX_PUT_CHAR_ARRAY( __GLX_COMPRESSED_TEXIMAGE_CMD_HDR_SIZE
,
115 assert( compsize
!= 0 );
117 __GLX_BEGIN_VARIABLE_LARGE( rop
, cmdlen
+ 4 );
118 __GLX_PUT_LONG( 8, target
);
119 __GLX_PUT_LONG( 12, level
);
120 __GLX_PUT_LONG( 16, internal_format
);
121 __GLX_PUT_LONG( 20, width
);
122 __GLX_PUT_LONG( 24, height
);
123 __GLX_PUT_LONG( 28, border
);
124 __GLX_PUT_LONG( 32, image_size
);
125 __glXSendLargeCommand( gc
, gc
->pc
,
126 __GLX_COMPRESSED_TEXIMAGE_CMD_HDR_SIZE
+ 4,
133 * Internal function used for \c glCompressedTexSubImage1D and
134 * \c glCompressedTexSubImage2D.
137 CompressedTexSubImage1D2D( GLenum target
, GLint level
,
138 GLsizei xoffset
, GLsizei yoffset
,
139 GLsizei width
, GLsizei height
,
140 GLenum format
, GLsizei image_size
,
141 const GLvoid
*data
, CARD32 rop
)
143 __GLX_DECLARE_VARIABLES();
145 __GLX_LOAD_VARIABLES();
146 if ( gc
->currentDpy
== NULL
) {
150 if ( target
== GL_PROXY_TEXTURE_3D
) {
154 compsize
= image_size
;
157 cmdlen
= __GLX_PAD( __GLX_COMPRESSED_TEXSUBIMAGE_CMD_HDR_SIZE
159 if ( cmdlen
<= gc
->maxSmallRenderCommandSize
) {
160 __GLX_BEGIN_VARIABLE( rop
, cmdlen
);
161 __GLX_PUT_LONG( 4, target
);
162 __GLX_PUT_LONG( 8, level
);
163 __GLX_PUT_LONG( 12, xoffset
);
164 __GLX_PUT_LONG( 16, yoffset
);
165 __GLX_PUT_LONG( 20, width
);
166 __GLX_PUT_LONG( 24, height
);
167 __GLX_PUT_LONG( 28, format
);
168 __GLX_PUT_LONG( 32, image_size
);
169 if ( compsize
!= 0 ) {
170 __GLX_PUT_CHAR_ARRAY( __GLX_COMPRESSED_TEXSUBIMAGE_CMD_HDR_SIZE
,
176 assert( compsize
!= 0 );
178 __GLX_BEGIN_VARIABLE_LARGE( rop
, cmdlen
+ 4 );
179 __GLX_PUT_LONG( 8, target
);
180 __GLX_PUT_LONG( 12, level
);
181 __GLX_PUT_LONG( 16, xoffset
);
182 __GLX_PUT_LONG( 20, yoffset
);
183 __GLX_PUT_LONG( 24, width
);
184 __GLX_PUT_LONG( 28, height
);
185 __GLX_PUT_LONG( 32, format
);
186 __GLX_PUT_LONG( 36, image_size
);
187 __glXSendLargeCommand( gc
, gc
->pc
,
188 __GLX_COMPRESSED_TEXSUBIMAGE_CMD_HDR_SIZE
+ 4,
195 __indirect_glCompressedTexImage1D( GLenum target
, GLint level
,
196 GLenum internal_format
, GLsizei width
,
197 GLint border
, GLsizei image_size
,
200 CompressedTexImage1D2D( target
, level
, internal_format
, width
, 0,
201 border
, image_size
, data
,
202 X_GLrop_CompressedTexImage1D
);
207 __indirect_glCompressedTexImage2D( GLenum target
, GLint level
,
208 GLenum internal_format
,
209 GLsizei width
, GLsizei height
,
210 GLint border
, GLsizei image_size
,
213 CompressedTexImage1D2D( target
, level
, internal_format
, width
, height
,
214 border
, image_size
, data
,
215 X_GLrop_CompressedTexImage2D
);
220 __indirect_glCompressedTexImage3D( GLenum target
, GLint level
,
221 GLenum internal_format
,
222 GLsizei width
, GLsizei height
, GLsizei depth
,
223 GLint border
, GLsizei image_size
,
226 __GLX_DECLARE_VARIABLES();
228 __GLX_LOAD_VARIABLES();
229 if ( gc
->currentDpy
== NULL
) {
233 cmdlen
= __GLX_PAD( __GLX_COMPRESSED_TEXIMAGE_3D_CMD_HDR_SIZE
235 if ( cmdlen
<= gc
->maxSmallRenderCommandSize
) {
236 __GLX_BEGIN_VARIABLE( X_GLrop_CompressedTexImage3D
, cmdlen
);
237 __GLX_PUT_LONG( 4, target
);
238 __GLX_PUT_LONG( 8, level
);
239 __GLX_PUT_LONG( 12, internal_format
);
240 __GLX_PUT_LONG( 16, width
);
241 __GLX_PUT_LONG( 20, height
);
242 __GLX_PUT_LONG( 24, depth
);
243 __GLX_PUT_LONG( 28, border
);
244 __GLX_PUT_LONG( 32, image_size
);
245 if ( image_size
!= 0 ) {
246 __GLX_PUT_CHAR_ARRAY( __GLX_COMPRESSED_TEXIMAGE_3D_CMD_HDR_SIZE
,
252 __GLX_BEGIN_VARIABLE_LARGE( X_GLrop_CompressedTexImage3D
,
254 __GLX_PUT_LONG( 8, target
);
255 __GLX_PUT_LONG( 12, level
);
256 __GLX_PUT_LONG( 16, internal_format
);
257 __GLX_PUT_LONG( 20, width
);
258 __GLX_PUT_LONG( 24, height
);
259 __GLX_PUT_LONG( 28, depth
);
260 __GLX_PUT_LONG( 32, border
);
261 __GLX_PUT_LONG( 36, image_size
);
262 __glXSendLargeCommand( gc
, gc
->pc
,
263 __GLX_COMPRESSED_TEXIMAGE_3D_CMD_HDR_SIZE
+ 4,
270 __indirect_glCompressedTexSubImage1D( GLenum target
, GLint level
,
273 GLenum format
, GLsizei image_size
,
276 CompressedTexSubImage1D2D( target
, level
, xoffset
, 0, width
, 0,
277 format
, image_size
, data
,
278 X_GLrop_CompressedTexSubImage1D
);
283 __indirect_glCompressedTexSubImage2D( GLenum target
, GLint level
,
284 GLint xoffset
, GLint yoffset
,
285 GLsizei width
, GLsizei height
,
286 GLenum format
, GLsizei image_size
,
289 CompressedTexSubImage1D2D( target
, level
, xoffset
, yoffset
, width
, height
,
290 format
, image_size
, data
,
291 X_GLrop_CompressedTexSubImage2D
);
296 __indirect_glCompressedTexSubImage3D( GLenum target
, GLint level
,
297 GLint xoffset
, GLint yoffset
, GLint zoffset
,
298 GLsizei width
, GLsizei height
, GLsizei depth
,
299 GLenum format
, GLsizei image_size
,
302 __GLX_DECLARE_VARIABLES();
304 __GLX_LOAD_VARIABLES();
305 if ( gc
->currentDpy
== NULL
) {
309 cmdlen
= __GLX_PAD( __GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE
311 if ( cmdlen
<= gc
->maxSmallRenderCommandSize
) {
312 __GLX_BEGIN_VARIABLE( X_GLrop_CompressedTexSubImage3D
, cmdlen
);
313 __GLX_PUT_LONG( 4, target
);
314 __GLX_PUT_LONG( 8, level
);
315 __GLX_PUT_LONG( 12, xoffset
);
316 __GLX_PUT_LONG( 16, yoffset
);
317 __GLX_PUT_LONG( 20, zoffset
);
318 __GLX_PUT_LONG( 24, width
);
319 __GLX_PUT_LONG( 28, height
);
320 __GLX_PUT_LONG( 32, depth
);
321 __GLX_PUT_LONG( 36, format
);
322 __GLX_PUT_LONG( 40, image_size
);
323 if ( image_size
!= 0 ) {
324 __GLX_PUT_CHAR_ARRAY( __GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE
,
330 __GLX_BEGIN_VARIABLE_LARGE( X_GLrop_CompressedTexSubImage3D
,
332 __GLX_PUT_LONG( 8, target
);
333 __GLX_PUT_LONG( 12, level
);
334 __GLX_PUT_LONG( 16, xoffset
);
335 __GLX_PUT_LONG( 20, yoffset
);
336 __GLX_PUT_LONG( 24, zoffset
);
337 __GLX_PUT_LONG( 28, width
);
338 __GLX_PUT_LONG( 32, height
);
339 __GLX_PUT_LONG( 36, depth
);
340 __GLX_PUT_LONG( 40, format
);
341 __GLX_PUT_LONG( 44, image_size
);
342 __glXSendLargeCommand( gc
, gc
->pc
,
343 __GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE
+ 4,