glx: add a line of Emacs helping variables
[mesa.git] / src / glx / x11 / indirect_texture_compression.c
1 /* -*- mode: c; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 3; coding: utf-8-unix -*- */
2 /*
3 * (C) Copyright IBM Corporation 2004
4 * All Rights Reserved.
5 *
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:
12 *
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
15 * Software.
16 *
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.
24 */
25
26 /**
27 * \file glx_texture_compression.c
28 * Contains the routines required to implement GLX protocol for
29 * ARB_texture_compression and related extensions.
30 *
31 * \sa http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_compression.txt
32 *
33 * \author Ian Romanick <idr@us.ibm.com>
34 */
35
36 #include "packrender.h"
37 #include "packsingle.h"
38 #include "indirect.h"
39
40 #include <assert.h>
41
42
43 void
44 __indirect_glGetCompressedTexImageARB( GLenum target, GLint level,
45 GLvoid * img )
46 {
47 __GLX_SINGLE_DECLARE_VARIABLES();
48 xGLXGetTexImageReply reply;
49 size_t image_bytes;
50
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();
56
57 image_bytes = reply.width;
58 assert( image_bytes <= ((4 * reply.length) - 0) );
59 assert( image_bytes >= ((4 * reply.length) - 3) );
60
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 );
65 }
66 }
67
68 __GLX_SINGLE_END();
69 }
70
71
72 /**
73 * Internal function used for \c glCompressedTexImage1D and
74 * \c glCompressedTexImage2D.
75 */
76 static void
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 )
82 {
83 __GLX_DECLARE_VARIABLES();
84
85 __GLX_LOAD_VARIABLES();
86 if ( gc->currentDpy == NULL ) {
87 return;
88 }
89
90 if ( (target == GL_PROXY_TEXTURE_1D)
91 || (target == GL_PROXY_TEXTURE_2D)
92 || (target == GL_PROXY_TEXTURE_CUBE_MAP) ) {
93 compsize = 0;
94 }
95 else {
96 compsize = image_size;
97 }
98
99 cmdlen = __GLX_PAD( __GLX_COMPRESSED_TEXIMAGE_CMD_HDR_SIZE
100 + compsize );
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,
112 data, image_size );
113 }
114 __GLX_END( cmdlen );
115 }
116 else {
117 assert( compsize != 0 );
118
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,
129 data, image_size );
130 }
131 }
132
133
134 /**
135 * Internal function used for \c glCompressedTexSubImage1D and
136 * \c glCompressedTexSubImage2D.
137 */
138 static void
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 )
144 {
145 __GLX_DECLARE_VARIABLES();
146
147 __GLX_LOAD_VARIABLES();
148 if ( gc->currentDpy == NULL ) {
149 return;
150 }
151
152 if ( target == GL_PROXY_TEXTURE_3D ) {
153 compsize = 0;
154 }
155 else {
156 compsize = image_size;
157 }
158
159 cmdlen = __GLX_PAD( __GLX_COMPRESSED_TEXSUBIMAGE_CMD_HDR_SIZE
160 + compsize );
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,
173 data, image_size );
174 }
175 __GLX_END( cmdlen );
176 }
177 else {
178 assert( compsize != 0 );
179
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,
191 data, image_size );
192 }
193 }
194
195
196 void
197 __indirect_glCompressedTexImage1DARB( GLenum target, GLint level,
198 GLenum internal_format, GLsizei width,
199 GLint border, GLsizei image_size,
200 const GLvoid *data )
201 {
202 CompressedTexImage1D2D( target, level, internal_format, width, 0,
203 border, image_size, data,
204 X_GLrop_CompressedTexImage1D );
205 }
206
207
208 void
209 __indirect_glCompressedTexImage2DARB( GLenum target, GLint level,
210 GLenum internal_format,
211 GLsizei width, GLsizei height,
212 GLint border, GLsizei image_size,
213 const GLvoid *data )
214 {
215 CompressedTexImage1D2D( target, level, internal_format, width, height,
216 border, image_size, data,
217 X_GLrop_CompressedTexImage2D );
218 }
219
220
221 void
222 __indirect_glCompressedTexImage3DARB( GLenum target, GLint level,
223 GLenum internal_format,
224 GLsizei width, GLsizei height, GLsizei depth,
225 GLint border, GLsizei image_size,
226 const GLvoid *data )
227 {
228 __GLX_DECLARE_VARIABLES();
229
230 __GLX_LOAD_VARIABLES();
231 if ( gc->currentDpy == NULL ) {
232 return;
233 }
234
235 cmdlen = __GLX_PAD( __GLX_COMPRESSED_TEXIMAGE_3D_CMD_HDR_SIZE
236 + image_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,
249 data, image_size );
250 }
251 __GLX_END( cmdlen );
252 }
253 else {
254 __GLX_BEGIN_VARIABLE_LARGE( X_GLrop_CompressedTexImage3D,
255 cmdlen + 4 );
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,
266 data, image_size );
267 }
268 }
269
270
271 void
272 __indirect_glCompressedTexSubImage1DARB( GLenum target, GLint level,
273 GLint xoffset,
274 GLsizei width,
275 GLenum format, GLsizei image_size,
276 const GLvoid *data )
277 {
278 CompressedTexSubImage1D2D( target, level, xoffset, 0, width, 0,
279 format, image_size, data,
280 X_GLrop_CompressedTexSubImage1D );
281 }
282
283
284 void
285 __indirect_glCompressedTexSubImage2DARB( GLenum target, GLint level,
286 GLint xoffset, GLint yoffset,
287 GLsizei width, GLsizei height,
288 GLenum format, GLsizei image_size,
289 const GLvoid *data )
290 {
291 CompressedTexSubImage1D2D( target, level, xoffset, yoffset, width, height,
292 format, image_size, data,
293 X_GLrop_CompressedTexSubImage2D );
294 }
295
296
297 void
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,
302 const GLvoid *data )
303 {
304 __GLX_DECLARE_VARIABLES();
305
306 __GLX_LOAD_VARIABLES();
307 if ( gc->currentDpy == NULL ) {
308 return;
309 }
310
311 cmdlen = __GLX_PAD( __GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE
312 + image_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,
327 data, image_size );
328 }
329 __GLX_END( cmdlen );
330 }
331 else {
332 __GLX_BEGIN_VARIABLE_LARGE( X_GLrop_CompressedTexSubImage3D,
333 cmdlen + 4 );
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,
346 data, image_size );
347 }
348 }