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"
43 __indirect_glGetCompressedTexImageARB( GLenum target
, GLint level
,
46 __GLX_SINGLE_DECLARE_VARIABLES();
47 xGLXGetTexImageReply reply
;
50 __GLX_SINGLE_LOAD_VARIABLES();
51 __GLX_SINGLE_BEGIN( X_GLsop_GetCompressedTexImage
, 8 );
52 __GLX_SINGLE_PUT_LONG( 0, target
);
53 __GLX_SINGLE_PUT_LONG( 4, level
);
54 __GLX_SINGLE_READ_XREPLY();
56 image_bytes
= reply
.width
;
57 assert( image_bytes
<= ((4 * reply
.length
) - 0) );
58 assert( image_bytes
>= ((4 * reply
.length
) - 3) );
60 if ( image_bytes
!= 0 ) {
61 _XRead( dpy
, (char *) img
, image_bytes
);
62 if ( image_bytes
< (4 * reply
.length
) ) {
63 _XEatData( dpy
, (4 * reply
.length
) - image_bytes
);
72 * Internal function used for \c glCompressedTexImage1D and
73 * \c glCompressedTexImage2D.
76 CompressedTexImage1D2D( GLenum target
, GLint level
,
77 GLenum internal_format
,
78 GLsizei width
, GLsizei height
,
79 GLint border
, GLsizei image_size
,
80 const GLvoid
*data
, CARD32 rop
)
82 __GLX_DECLARE_VARIABLES();
84 __GLX_LOAD_VARIABLES();
85 if ( gc
->currentDpy
== NULL
) {
89 if ( (target
== GL_PROXY_TEXTURE_1D
)
90 || (target
== GL_PROXY_TEXTURE_2D
)
91 || (target
== GL_PROXY_TEXTURE_CUBE_MAP
) ) {
95 compsize
= image_size
;
98 cmdlen
= __GLX_PAD( __GLX_COMPRESSED_TEXIMAGE_CMD_HDR_SIZE
100 if ( cmdlen
<= gc
->maxSmallRenderCommandSize
) {
101 __GLX_BEGIN_VARIABLE( rop
, cmdlen
);
102 __GLX_PUT_LONG( 4, target
);
103 __GLX_PUT_LONG( 8, level
);
104 __GLX_PUT_LONG( 12, internal_format
);
105 __GLX_PUT_LONG( 16, width
);
106 __GLX_PUT_LONG( 20, height
);
107 __GLX_PUT_LONG( 24, border
);
108 __GLX_PUT_LONG( 28, image_size
);
109 if ( compsize
!= 0 ) {
110 __GLX_PUT_CHAR_ARRAY( __GLX_COMPRESSED_TEXIMAGE_CMD_HDR_SIZE
,
116 assert( compsize
!= 0 );
118 __GLX_BEGIN_VARIABLE_LARGE( rop
, cmdlen
+ 4 );
119 __GLX_PUT_LONG( 8, target
);
120 __GLX_PUT_LONG( 12, level
);
121 __GLX_PUT_LONG( 16, internal_format
);
122 __GLX_PUT_LONG( 20, width
);
123 __GLX_PUT_LONG( 24, height
);
124 __GLX_PUT_LONG( 28, border
);
125 __GLX_PUT_LONG( 32, image_size
);
126 __glXSendLargeCommand( gc
, gc
->pc
,
127 __GLX_COMPRESSED_TEXIMAGE_CMD_HDR_SIZE
+ 4,
134 * Internal function used for \c glCompressedTexSubImage1D and
135 * \c glCompressedTexSubImage2D.
138 CompressedTexSubImage1D2D( GLenum target
, GLint level
,
139 GLsizei xoffset
, GLsizei yoffset
,
140 GLsizei width
, GLsizei height
,
141 GLenum format
, GLsizei image_size
,
142 const GLvoid
*data
, CARD32 rop
)
144 __GLX_DECLARE_VARIABLES();
146 __GLX_LOAD_VARIABLES();
147 if ( gc
->currentDpy
== NULL
) {
151 if ( target
== GL_PROXY_TEXTURE_3D
) {
155 compsize
= image_size
;
158 cmdlen
= __GLX_PAD( __GLX_COMPRESSED_TEXSUBIMAGE_CMD_HDR_SIZE
160 if ( cmdlen
<= gc
->maxSmallRenderCommandSize
) {
161 __GLX_BEGIN_VARIABLE( rop
, cmdlen
);
162 __GLX_PUT_LONG( 4, target
);
163 __GLX_PUT_LONG( 8, level
);
164 __GLX_PUT_LONG( 12, xoffset
);
165 __GLX_PUT_LONG( 16, yoffset
);
166 __GLX_PUT_LONG( 20, width
);
167 __GLX_PUT_LONG( 24, height
);
168 __GLX_PUT_LONG( 28, format
);
169 __GLX_PUT_LONG( 32, image_size
);
170 if ( compsize
!= 0 ) {
171 __GLX_PUT_CHAR_ARRAY( __GLX_COMPRESSED_TEXSUBIMAGE_CMD_HDR_SIZE
,
177 assert( compsize
!= 0 );
179 __GLX_BEGIN_VARIABLE_LARGE( rop
, cmdlen
+ 4 );
180 __GLX_PUT_LONG( 8, target
);
181 __GLX_PUT_LONG( 12, level
);
182 __GLX_PUT_LONG( 16, xoffset
);
183 __GLX_PUT_LONG( 20, yoffset
);
184 __GLX_PUT_LONG( 24, width
);
185 __GLX_PUT_LONG( 28, height
);
186 __GLX_PUT_LONG( 32, format
);
187 __GLX_PUT_LONG( 36, image_size
);
188 __glXSendLargeCommand( gc
, gc
->pc
,
189 __GLX_COMPRESSED_TEXSUBIMAGE_CMD_HDR_SIZE
+ 4,
196 __indirect_glCompressedTexImage1DARB( GLenum target
, GLint level
,
197 GLenum internal_format
, GLsizei width
,
198 GLint border
, GLsizei image_size
,
201 CompressedTexImage1D2D( target
, level
, internal_format
, width
, 0,
202 border
, image_size
, data
,
203 X_GLrop_CompressedTexImage1D
);
208 __indirect_glCompressedTexImage2DARB( GLenum target
, GLint level
,
209 GLenum internal_format
,
210 GLsizei width
, GLsizei height
,
211 GLint border
, GLsizei image_size
,
214 CompressedTexImage1D2D( target
, level
, internal_format
, width
, height
,
215 border
, image_size
, data
,
216 X_GLrop_CompressedTexImage2D
);
221 __indirect_glCompressedTexImage3DARB( GLenum target
, GLint level
,
222 GLenum internal_format
,
223 GLsizei width
, GLsizei height
, GLsizei depth
,
224 GLint border
, GLsizei image_size
,
227 __GLX_DECLARE_VARIABLES();
229 __GLX_LOAD_VARIABLES();
230 if ( gc
->currentDpy
== NULL
) {
234 cmdlen
= __GLX_PAD( __GLX_COMPRESSED_TEXIMAGE_3D_CMD_HDR_SIZE
236 if ( cmdlen
<= gc
->maxSmallRenderCommandSize
) {
237 __GLX_BEGIN_VARIABLE( X_GLrop_CompressedTexImage3D
, cmdlen
);
238 __GLX_PUT_LONG( 4, target
);
239 __GLX_PUT_LONG( 8, level
);
240 __GLX_PUT_LONG( 12, internal_format
);
241 __GLX_PUT_LONG( 16, width
);
242 __GLX_PUT_LONG( 20, height
);
243 __GLX_PUT_LONG( 24, depth
);
244 __GLX_PUT_LONG( 28, border
);
245 __GLX_PUT_LONG( 32, image_size
);
246 if ( image_size
!= 0 ) {
247 __GLX_PUT_CHAR_ARRAY( __GLX_COMPRESSED_TEXIMAGE_3D_CMD_HDR_SIZE
,
253 __GLX_BEGIN_VARIABLE_LARGE( X_GLrop_CompressedTexImage3D
,
255 __GLX_PUT_LONG( 8, target
);
256 __GLX_PUT_LONG( 12, level
);
257 __GLX_PUT_LONG( 16, internal_format
);
258 __GLX_PUT_LONG( 20, width
);
259 __GLX_PUT_LONG( 24, height
);
260 __GLX_PUT_LONG( 28, depth
);
261 __GLX_PUT_LONG( 32, border
);
262 __GLX_PUT_LONG( 36, image_size
);
263 __glXSendLargeCommand( gc
, gc
->pc
,
264 __GLX_COMPRESSED_TEXIMAGE_3D_CMD_HDR_SIZE
+ 4,
271 __indirect_glCompressedTexSubImage1DARB( GLenum target
, GLint level
,
274 GLenum format
, GLsizei image_size
,
277 CompressedTexSubImage1D2D( target
, level
, xoffset
, 0, width
, 0,
278 format
, image_size
, data
,
279 X_GLrop_CompressedTexSubImage1D
);
284 __indirect_glCompressedTexSubImage2DARB( GLenum target
, GLint level
,
285 GLint xoffset
, GLint yoffset
,
286 GLsizei width
, GLsizei height
,
287 GLenum format
, GLsizei image_size
,
290 CompressedTexSubImage1D2D( target
, level
, xoffset
, yoffset
, width
, height
,
291 format
, image_size
, data
,
292 X_GLrop_CompressedTexSubImage2D
);
297 __indirect_glCompressedTexSubImage3DARB( GLenum target
, GLint level
,
298 GLint xoffset
, GLint yoffset
, GLint zoffset
,
299 GLsizei width
, GLsizei height
, GLsizei depth
,
300 GLenum format
, GLsizei image_size
,
303 __GLX_DECLARE_VARIABLES();
305 __GLX_LOAD_VARIABLES();
306 if ( gc
->currentDpy
== NULL
) {
310 cmdlen
= __GLX_PAD( __GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE
312 if ( cmdlen
<= gc
->maxSmallRenderCommandSize
) {
313 __GLX_BEGIN_VARIABLE( X_GLrop_CompressedTexSubImage3D
, cmdlen
);
314 __GLX_PUT_LONG( 4, target
);
315 __GLX_PUT_LONG( 8, level
);
316 __GLX_PUT_LONG( 12, xoffset
);
317 __GLX_PUT_LONG( 16, yoffset
);
318 __GLX_PUT_LONG( 20, zoffset
);
319 __GLX_PUT_LONG( 24, width
);
320 __GLX_PUT_LONG( 28, height
);
321 __GLX_PUT_LONG( 32, depth
);
322 __GLX_PUT_LONG( 36, format
);
323 __GLX_PUT_LONG( 40, image_size
);
324 if ( image_size
!= 0 ) {
325 __GLX_PUT_CHAR_ARRAY( __GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE
,
331 __GLX_BEGIN_VARIABLE_LARGE( X_GLrop_CompressedTexSubImage3D
,
333 __GLX_PUT_LONG( 8, target
);
334 __GLX_PUT_LONG( 12, level
);
335 __GLX_PUT_LONG( 16, xoffset
);
336 __GLX_PUT_LONG( 20, yoffset
);
337 __GLX_PUT_LONG( 24, zoffset
);
338 __GLX_PUT_LONG( 28, width
);
339 __GLX_PUT_LONG( 32, height
);
340 __GLX_PUT_LONG( 36, depth
);
341 __GLX_PUT_LONG( 40, format
);
342 __GLX_PUT_LONG( 44, image_size
);
343 __glXSendLargeCommand( gc
, gc
->pc
,
344 __GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE
+ 4,