Make the transition to script-genereated GLX code easier.
[mesa.git] / src / glx / x11 / glx_texture_compression.c
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 /**
26 * \file glx_texture_compression.c
27 * Contains the routines required to implement GLX protocol for
28 * ARB_texture_compression and related extensions.
29 *
30 * \sa http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_compression.txt
31 *
32 * \author Ian Romanick <idr@us.ibm.com>
33 */
34
35 #include "packrender.h"
36 #include "packsingle.h"
37
38 #include <assert.h>
39
40
41 void
42 __indirect_glGetCompressedTexImageARB( GLenum target, GLint level,
43 GLvoid * img )
44 {
45 __GLX_SINGLE_DECLARE_VARIABLES();
46 xGLXGetTexImageReply reply;
47 size_t image_bytes;
48
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();
54
55 image_bytes = reply.width;
56 assert( image_bytes <= ((4 * reply.length) - 0) );
57 assert( image_bytes >= ((4 * reply.length) - 3) );
58
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 );
63 }
64 }
65
66 __GLX_SINGLE_END();
67 }
68
69
70 /**
71 * Internal function used for \c glCompressedTexImage1D and
72 * \c glCompressedTexImage2D.
73 */
74 static void
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 )
80 {
81 __GLX_DECLARE_VARIABLES();
82
83 __GLX_LOAD_VARIABLES();
84 if ( gc->currentDpy == NULL ) {
85 return;
86 }
87
88 if ( (target == GL_PROXY_TEXTURE_1D)
89 || (target == GL_PROXY_TEXTURE_2D)
90 || (target == GL_PROXY_TEXTURE_CUBE_MAP) ) {
91 compsize = 0;
92 }
93 else {
94 compsize = image_size;
95 }
96
97 cmdlen = __GLX_PAD( __GLX_COMPRESSED_TEXIMAGE_CMD_HDR_SIZE
98 + compsize );
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,
110 data, image_size );
111 }
112 __GLX_END( cmdlen );
113 }
114 else {
115 assert( compsize != 0 );
116
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,
127 data, image_size );
128 }
129 }
130
131
132 /**
133 * Internal function used for \c glCompressedTexSubImage1D and
134 * \c glCompressedTexSubImage2D.
135 */
136 static void
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 )
142 {
143 __GLX_DECLARE_VARIABLES();
144
145 __GLX_LOAD_VARIABLES();
146 if ( gc->currentDpy == NULL ) {
147 return;
148 }
149
150 if ( target == GL_PROXY_TEXTURE_3D ) {
151 compsize = 0;
152 }
153 else {
154 compsize = image_size;
155 }
156
157 cmdlen = __GLX_PAD( __GLX_COMPRESSED_TEXSUBIMAGE_CMD_HDR_SIZE
158 + 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 );
169 if ( compsize != 0 ) {
170 __GLX_PUT_CHAR_ARRAY( __GLX_COMPRESSED_TEXSUBIMAGE_CMD_HDR_SIZE,
171 data, image_size );
172 }
173 __GLX_END( cmdlen );
174 }
175 else {
176 assert( compsize != 0 );
177
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,
189 data, image_size );
190 }
191 }
192
193
194 void
195 __indirect_glCompressedTexImage1DARB( GLenum target, GLint level,
196 GLenum internal_format, GLsizei width,
197 GLint border, GLsizei image_size,
198 const GLvoid *data )
199 {
200 CompressedTexImage1D2D( target, level, internal_format, width, 0,
201 border, image_size, data,
202 X_GLrop_CompressedTexImage1D );
203 }
204
205
206 void
207 __indirect_glCompressedTexImage2DARB( GLenum target, GLint level,
208 GLenum internal_format,
209 GLsizei width, GLsizei height,
210 GLint border, GLsizei image_size,
211 const GLvoid *data )
212 {
213 CompressedTexImage1D2D( target, level, internal_format, width, height,
214 border, image_size, data,
215 X_GLrop_CompressedTexImage2D );
216 }
217
218
219 void
220 __indirect_glCompressedTexImage3DARB( GLenum target, GLint level,
221 GLenum internal_format,
222 GLsizei width, GLsizei height, GLsizei depth,
223 GLint border, GLsizei image_size,
224 const GLvoid *data )
225 {
226 __GLX_DECLARE_VARIABLES();
227
228 __GLX_LOAD_VARIABLES();
229 if ( gc->currentDpy == NULL ) {
230 return;
231 }
232
233 cmdlen = __GLX_PAD( __GLX_COMPRESSED_TEXIMAGE_3D_CMD_HDR_SIZE
234 + image_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,
247 data, image_size );
248 }
249 __GLX_END( cmdlen );
250 }
251 else {
252 __GLX_BEGIN_VARIABLE_LARGE( X_GLrop_CompressedTexImage3D,
253 cmdlen + 4 );
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,
264 data, image_size );
265 }
266 }
267
268
269 void
270 __indirect_glCompressedTexSubImage1DARB( GLenum target, GLint level,
271 GLint xoffset,
272 GLsizei width,
273 GLenum format, GLsizei image_size,
274 const GLvoid *data )
275 {
276 CompressedTexSubImage1D2D( target, level, xoffset, 0, width, 0,
277 format, image_size, data,
278 X_GLrop_CompressedTexSubImage1D );
279 }
280
281
282 void
283 __indirect_glCompressedTexSubImage2DARB( GLenum target, GLint level,
284 GLint xoffset, GLint yoffset,
285 GLsizei width, GLsizei height,
286 GLenum format, GLsizei image_size,
287 const GLvoid *data )
288 {
289 CompressedTexSubImage1D2D( target, level, xoffset, yoffset, width, height,
290 format, image_size, data,
291 X_GLrop_CompressedTexSubImage2D );
292 }
293
294
295 void
296 __indirect_glCompressedTexSubImage3DARB( GLenum target, GLint level,
297 GLint xoffset, GLint yoffset, GLint zoffset,
298 GLsizei width, GLsizei height, GLsizei depth,
299 GLenum format, GLsizei image_size,
300 const GLvoid *data )
301 {
302 __GLX_DECLARE_VARIABLES();
303
304 __GLX_LOAD_VARIABLES();
305 if ( gc->currentDpy == NULL ) {
306 return;
307 }
308
309 cmdlen = __GLX_PAD( __GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE
310 + image_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,
325 data, image_size );
326 }
327 __GLX_END( cmdlen );
328 }
329 else {
330 __GLX_BEGIN_VARIABLE_LARGE( X_GLrop_CompressedTexSubImage3D,
331 cmdlen + 4 );
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,
344 data, image_size );
345 }
346 }