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
+ compsize
);
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
);
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
+ compsize
);
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
);
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_glCompressedTexImage1DARB(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_glCompressedTexImage2DARB(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_glCompressedTexImage3DARB(GLenum target
, GLint level
,
221 GLenum internal_format
,
222 GLsizei width
, GLsizei height
,
223 GLsizei depth
, GLint border
,
224 GLsizei image_size
, const GLvoid
* data
)
226 __GLX_DECLARE_VARIABLES();
228 __GLX_LOAD_VARIABLES();
229 if (gc
->currentDpy
== NULL
) {
233 cmdlen
= __GLX_PAD(__GLX_COMPRESSED_TEXIMAGE_3D_CMD_HDR_SIZE
+ image_size
);
234 if (cmdlen
<= gc
->maxSmallRenderCommandSize
) {
235 __GLX_BEGIN_VARIABLE(X_GLrop_CompressedTexImage3D
, cmdlen
);
236 __GLX_PUT_LONG(4, target
);
237 __GLX_PUT_LONG(8, level
);
238 __GLX_PUT_LONG(12, internal_format
);
239 __GLX_PUT_LONG(16, width
);
240 __GLX_PUT_LONG(20, height
);
241 __GLX_PUT_LONG(24, depth
);
242 __GLX_PUT_LONG(28, border
);
243 __GLX_PUT_LONG(32, image_size
);
244 if (image_size
!= 0) {
245 __GLX_PUT_CHAR_ARRAY(__GLX_COMPRESSED_TEXIMAGE_3D_CMD_HDR_SIZE
,
251 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_CompressedTexImage3D
, cmdlen
+ 4);
252 __GLX_PUT_LONG(8, target
);
253 __GLX_PUT_LONG(12, level
);
254 __GLX_PUT_LONG(16, internal_format
);
255 __GLX_PUT_LONG(20, width
);
256 __GLX_PUT_LONG(24, height
);
257 __GLX_PUT_LONG(28, depth
);
258 __GLX_PUT_LONG(32, border
);
259 __GLX_PUT_LONG(36, image_size
);
260 __glXSendLargeCommand(gc
, gc
->pc
,
261 __GLX_COMPRESSED_TEXIMAGE_3D_CMD_HDR_SIZE
+ 4,
268 __indirect_glCompressedTexSubImage1DARB(GLenum target
, GLint level
,
271 GLenum format
, GLsizei image_size
,
274 CompressedTexSubImage1D2D(target
, level
, xoffset
, 0, width
, 0,
275 format
, image_size
, data
,
276 X_GLrop_CompressedTexSubImage1D
);
281 __indirect_glCompressedTexSubImage2DARB(GLenum target
, GLint level
,
282 GLint xoffset
, GLint yoffset
,
283 GLsizei width
, GLsizei height
,
284 GLenum format
, GLsizei image_size
,
287 CompressedTexSubImage1D2D(target
, level
, xoffset
, yoffset
, width
, height
,
288 format
, image_size
, data
,
289 X_GLrop_CompressedTexSubImage2D
);
294 __indirect_glCompressedTexSubImage3DARB(GLenum target
, GLint level
,
295 GLint xoffset
, GLint yoffset
,
296 GLint zoffset
, GLsizei width
,
297 GLsizei height
, GLsizei depth
,
298 GLenum format
, GLsizei image_size
,
301 __GLX_DECLARE_VARIABLES();
303 __GLX_LOAD_VARIABLES();
304 if (gc
->currentDpy
== NULL
) {
308 cmdlen
= __GLX_PAD(__GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE
310 if (cmdlen
<= gc
->maxSmallRenderCommandSize
) {
311 __GLX_BEGIN_VARIABLE(X_GLrop_CompressedTexSubImage3D
, cmdlen
);
312 __GLX_PUT_LONG(4, target
);
313 __GLX_PUT_LONG(8, level
);
314 __GLX_PUT_LONG(12, xoffset
);
315 __GLX_PUT_LONG(16, yoffset
);
316 __GLX_PUT_LONG(20, zoffset
);
317 __GLX_PUT_LONG(24, width
);
318 __GLX_PUT_LONG(28, height
);
319 __GLX_PUT_LONG(32, depth
);
320 __GLX_PUT_LONG(36, format
);
321 __GLX_PUT_LONG(40, image_size
);
322 if (image_size
!= 0) {
323 __GLX_PUT_CHAR_ARRAY(__GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE
,
329 __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_CompressedTexSubImage3D
, cmdlen
+ 4);
330 __GLX_PUT_LONG(8, target
);
331 __GLX_PUT_LONG(12, level
);
332 __GLX_PUT_LONG(16, xoffset
);
333 __GLX_PUT_LONG(20, yoffset
);
334 __GLX_PUT_LONG(24, zoffset
);
335 __GLX_PUT_LONG(28, width
);
336 __GLX_PUT_LONG(32, height
);
337 __GLX_PUT_LONG(36, depth
);
338 __GLX_PUT_LONG(40, format
);
339 __GLX_PUT_LONG(44, image_size
);
340 __glXSendLargeCommand(gc
, gc
->pc
,
341 __GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE
+ 4,