1 /* -*- mode: c; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 3; coding: utf-8-unix -*- */
3 * (C) Copyright IBM Corporation 2004
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * on the rights to use, copy, modify, merge, publish, distribute, sub
10 * license, and/or sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * THE COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 * USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * \file glx_texture_compression.c
28 * Contains the routines required to implement GLX protocol for
29 * ARB_texture_compression and related extensions.
31 * \sa http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_compression.txt
33 * \author Ian Romanick <idr@us.ibm.com>
36 #include "packrender.h"
37 #include "packsingle.h"
44 __indirect_glGetCompressedTexImageARB( GLenum target
, GLint level
,
47 __GLX_SINGLE_DECLARE_VARIABLES();
48 xGLXGetTexImageReply reply
;
51 __GLX_SINGLE_LOAD_VARIABLES();
52 __GLX_SINGLE_BEGIN( X_GLsop_GetCompressedTexImage
, 8 );
53 __GLX_SINGLE_PUT_LONG( 0, target
);
54 __GLX_SINGLE_PUT_LONG( 4, level
);
55 __GLX_SINGLE_READ_XREPLY();
57 image_bytes
= reply
.width
;
58 assert( image_bytes
<= ((4 * reply
.length
) - 0) );
59 assert( image_bytes
>= ((4 * reply
.length
) - 3) );
61 if ( image_bytes
!= 0 ) {
62 _XRead( dpy
, (char *) img
, image_bytes
);
63 if ( image_bytes
< (4 * reply
.length
) ) {
64 _XEatData( dpy
, (4 * reply
.length
) - image_bytes
);
73 * Internal function used for \c glCompressedTexImage1D and
74 * \c glCompressedTexImage2D.
77 CompressedTexImage1D2D( GLenum target
, GLint level
,
78 GLenum internal_format
,
79 GLsizei width
, GLsizei height
,
80 GLint border
, GLsizei image_size
,
81 const GLvoid
*data
, CARD32 rop
)
83 __GLX_DECLARE_VARIABLES();
85 __GLX_LOAD_VARIABLES();
86 if ( gc
->currentDpy
== NULL
) {
90 if ( (target
== GL_PROXY_TEXTURE_1D
)
91 || (target
== GL_PROXY_TEXTURE_2D
)
92 || (target
== GL_PROXY_TEXTURE_CUBE_MAP
) ) {
96 compsize
= image_size
;
99 cmdlen
= __GLX_PAD( __GLX_COMPRESSED_TEXIMAGE_CMD_HDR_SIZE
101 if ( cmdlen
<= gc
->maxSmallRenderCommandSize
) {
102 __GLX_BEGIN_VARIABLE( rop
, cmdlen
);
103 __GLX_PUT_LONG( 4, target
);
104 __GLX_PUT_LONG( 8, level
);
105 __GLX_PUT_LONG( 12, internal_format
);
106 __GLX_PUT_LONG( 16, width
);
107 __GLX_PUT_LONG( 20, height
);
108 __GLX_PUT_LONG( 24, border
);
109 __GLX_PUT_LONG( 28, image_size
);
110 if ( compsize
!= 0 ) {
111 __GLX_PUT_CHAR_ARRAY( __GLX_COMPRESSED_TEXIMAGE_CMD_HDR_SIZE
,
117 assert( compsize
!= 0 );
119 __GLX_BEGIN_VARIABLE_LARGE( rop
, cmdlen
+ 4 );
120 __GLX_PUT_LONG( 8, target
);
121 __GLX_PUT_LONG( 12, level
);
122 __GLX_PUT_LONG( 16, internal_format
);
123 __GLX_PUT_LONG( 20, width
);
124 __GLX_PUT_LONG( 24, height
);
125 __GLX_PUT_LONG( 28, border
);
126 __GLX_PUT_LONG( 32, image_size
);
127 __glXSendLargeCommand( gc
, gc
->pc
,
128 __GLX_COMPRESSED_TEXIMAGE_CMD_HDR_SIZE
+ 4,
135 * Internal function used for \c glCompressedTexSubImage1D and
136 * \c glCompressedTexSubImage2D.
139 CompressedTexSubImage1D2D( GLenum target
, GLint level
,
140 GLsizei xoffset
, GLsizei yoffset
,
141 GLsizei width
, GLsizei height
,
142 GLenum format
, GLsizei image_size
,
143 const GLvoid
*data
, CARD32 rop
)
145 __GLX_DECLARE_VARIABLES();
147 __GLX_LOAD_VARIABLES();
148 if ( gc
->currentDpy
== NULL
) {
152 if ( target
== GL_PROXY_TEXTURE_3D
) {
156 compsize
= image_size
;
159 cmdlen
= __GLX_PAD( __GLX_COMPRESSED_TEXSUBIMAGE_CMD_HDR_SIZE
161 if ( cmdlen
<= gc
->maxSmallRenderCommandSize
) {
162 __GLX_BEGIN_VARIABLE( rop
, cmdlen
);
163 __GLX_PUT_LONG( 4, target
);
164 __GLX_PUT_LONG( 8, level
);
165 __GLX_PUT_LONG( 12, xoffset
);
166 __GLX_PUT_LONG( 16, yoffset
);
167 __GLX_PUT_LONG( 20, width
);
168 __GLX_PUT_LONG( 24, height
);
169 __GLX_PUT_LONG( 28, format
);
170 __GLX_PUT_LONG( 32, image_size
);
171 if ( compsize
!= 0 ) {
172 __GLX_PUT_CHAR_ARRAY( __GLX_COMPRESSED_TEXSUBIMAGE_CMD_HDR_SIZE
,
178 assert( compsize
!= 0 );
180 __GLX_BEGIN_VARIABLE_LARGE( rop
, cmdlen
+ 4 );
181 __GLX_PUT_LONG( 8, target
);
182 __GLX_PUT_LONG( 12, level
);
183 __GLX_PUT_LONG( 16, xoffset
);
184 __GLX_PUT_LONG( 20, yoffset
);
185 __GLX_PUT_LONG( 24, width
);
186 __GLX_PUT_LONG( 28, height
);
187 __GLX_PUT_LONG( 32, format
);
188 __GLX_PUT_LONG( 36, image_size
);
189 __glXSendLargeCommand( gc
, gc
->pc
,
190 __GLX_COMPRESSED_TEXSUBIMAGE_CMD_HDR_SIZE
+ 4,
197 __indirect_glCompressedTexImage1DARB( GLenum target
, GLint level
,
198 GLenum internal_format
, GLsizei width
,
199 GLint border
, GLsizei image_size
,
202 CompressedTexImage1D2D( target
, level
, internal_format
, width
, 0,
203 border
, image_size
, data
,
204 X_GLrop_CompressedTexImage1D
);
209 __indirect_glCompressedTexImage2DARB( GLenum target
, GLint level
,
210 GLenum internal_format
,
211 GLsizei width
, GLsizei height
,
212 GLint border
, GLsizei image_size
,
215 CompressedTexImage1D2D( target
, level
, internal_format
, width
, height
,
216 border
, image_size
, data
,
217 X_GLrop_CompressedTexImage2D
);
222 __indirect_glCompressedTexImage3DARB( GLenum target
, GLint level
,
223 GLenum internal_format
,
224 GLsizei width
, GLsizei height
, GLsizei depth
,
225 GLint border
, GLsizei image_size
,
228 __GLX_DECLARE_VARIABLES();
230 __GLX_LOAD_VARIABLES();
231 if ( gc
->currentDpy
== NULL
) {
235 cmdlen
= __GLX_PAD( __GLX_COMPRESSED_TEXIMAGE_3D_CMD_HDR_SIZE
237 if ( cmdlen
<= gc
->maxSmallRenderCommandSize
) {
238 __GLX_BEGIN_VARIABLE( X_GLrop_CompressedTexImage3D
, cmdlen
);
239 __GLX_PUT_LONG( 4, target
);
240 __GLX_PUT_LONG( 8, level
);
241 __GLX_PUT_LONG( 12, internal_format
);
242 __GLX_PUT_LONG( 16, width
);
243 __GLX_PUT_LONG( 20, height
);
244 __GLX_PUT_LONG( 24, depth
);
245 __GLX_PUT_LONG( 28, border
);
246 __GLX_PUT_LONG( 32, image_size
);
247 if ( image_size
!= 0 ) {
248 __GLX_PUT_CHAR_ARRAY( __GLX_COMPRESSED_TEXIMAGE_3D_CMD_HDR_SIZE
,
254 __GLX_BEGIN_VARIABLE_LARGE( X_GLrop_CompressedTexImage3D
,
256 __GLX_PUT_LONG( 8, target
);
257 __GLX_PUT_LONG( 12, level
);
258 __GLX_PUT_LONG( 16, internal_format
);
259 __GLX_PUT_LONG( 20, width
);
260 __GLX_PUT_LONG( 24, height
);
261 __GLX_PUT_LONG( 28, depth
);
262 __GLX_PUT_LONG( 32, border
);
263 __GLX_PUT_LONG( 36, image_size
);
264 __glXSendLargeCommand( gc
, gc
->pc
,
265 __GLX_COMPRESSED_TEXIMAGE_3D_CMD_HDR_SIZE
+ 4,
272 __indirect_glCompressedTexSubImage1DARB( GLenum target
, GLint level
,
275 GLenum format
, GLsizei image_size
,
278 CompressedTexSubImage1D2D( target
, level
, xoffset
, 0, width
, 0,
279 format
, image_size
, data
,
280 X_GLrop_CompressedTexSubImage1D
);
285 __indirect_glCompressedTexSubImage2DARB( GLenum target
, GLint level
,
286 GLint xoffset
, GLint yoffset
,
287 GLsizei width
, GLsizei height
,
288 GLenum format
, GLsizei image_size
,
291 CompressedTexSubImage1D2D( target
, level
, xoffset
, yoffset
, width
, height
,
292 format
, image_size
, data
,
293 X_GLrop_CompressedTexSubImage2D
);
298 __indirect_glCompressedTexSubImage3DARB( GLenum target
, GLint level
,
299 GLint xoffset
, GLint yoffset
, GLint zoffset
,
300 GLsizei width
, GLsizei height
, GLsizei depth
,
301 GLenum format
, GLsizei image_size
,
304 __GLX_DECLARE_VARIABLES();
306 __GLX_LOAD_VARIABLES();
307 if ( gc
->currentDpy
== NULL
) {
311 cmdlen
= __GLX_PAD( __GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE
313 if ( cmdlen
<= gc
->maxSmallRenderCommandSize
) {
314 __GLX_BEGIN_VARIABLE( X_GLrop_CompressedTexSubImage3D
, cmdlen
);
315 __GLX_PUT_LONG( 4, target
);
316 __GLX_PUT_LONG( 8, level
);
317 __GLX_PUT_LONG( 12, xoffset
);
318 __GLX_PUT_LONG( 16, yoffset
);
319 __GLX_PUT_LONG( 20, zoffset
);
320 __GLX_PUT_LONG( 24, width
);
321 __GLX_PUT_LONG( 28, height
);
322 __GLX_PUT_LONG( 32, depth
);
323 __GLX_PUT_LONG( 36, format
);
324 __GLX_PUT_LONG( 40, image_size
);
325 if ( image_size
!= 0 ) {
326 __GLX_PUT_CHAR_ARRAY( __GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE
,
332 __GLX_BEGIN_VARIABLE_LARGE( X_GLrop_CompressedTexSubImage3D
,
334 __GLX_PUT_LONG( 8, target
);
335 __GLX_PUT_LONG( 12, level
);
336 __GLX_PUT_LONG( 16, xoffset
);
337 __GLX_PUT_LONG( 20, yoffset
);
338 __GLX_PUT_LONG( 24, zoffset
);
339 __GLX_PUT_LONG( 28, width
);
340 __GLX_PUT_LONG( 32, height
);
341 __GLX_PUT_LONG( 36, depth
);
342 __GLX_PUT_LONG( 40, format
);
343 __GLX_PUT_LONG( 44, image_size
);
344 __glXSendLargeCommand( gc
, gc
->pc
,
345 __GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE
+ 4,