glx: indent -br -i3 -npcs --no-tabs indirect_texture_compression.c
[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 + 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);
109 if (compsize != 0) {
110 __GLX_PUT_CHAR_ARRAY(__GLX_COMPRESSED_TEXIMAGE_CMD_HDR_SIZE,
111 data, image_size);
112 }
113 __GLX_END(cmdlen);
114 }
115 else {
116 assert(compsize != 0);
117
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,
128 data, image_size);
129 }
130 }
131
132
133 /**
134 * Internal function used for \c glCompressedTexSubImage1D and
135 * \c glCompressedTexSubImage2D.
136 */
137 static void
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)
143 {
144 __GLX_DECLARE_VARIABLES();
145
146 __GLX_LOAD_VARIABLES();
147 if (gc->currentDpy == NULL) {
148 return;
149 }
150
151 if (target == GL_PROXY_TEXTURE_3D) {
152 compsize = 0;
153 }
154 else {
155 compsize = image_size;
156 }
157
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);
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,
223 GLsizei depth, GLint border,
224 GLsizei image_size, 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 + 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,
246 data, image_size);
247 }
248 __GLX_END(cmdlen);
249 }
250 else {
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,
262 data, image_size);
263 }
264 }
265
266
267 void
268 __indirect_glCompressedTexSubImage1DARB(GLenum target, GLint level,
269 GLint xoffset,
270 GLsizei width,
271 GLenum format, GLsizei image_size,
272 const GLvoid * data)
273 {
274 CompressedTexSubImage1D2D(target, level, xoffset, 0, width, 0,
275 format, image_size, data,
276 X_GLrop_CompressedTexSubImage1D);
277 }
278
279
280 void
281 __indirect_glCompressedTexSubImage2DARB(GLenum target, GLint level,
282 GLint xoffset, GLint yoffset,
283 GLsizei width, GLsizei height,
284 GLenum format, GLsizei image_size,
285 const GLvoid * data)
286 {
287 CompressedTexSubImage1D2D(target, level, xoffset, yoffset, width, height,
288 format, image_size, data,
289 X_GLrop_CompressedTexSubImage2D);
290 }
291
292
293 void
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,
299 const GLvoid * data)
300 {
301 __GLX_DECLARE_VARIABLES();
302
303 __GLX_LOAD_VARIABLES();
304 if (gc->currentDpy == NULL) {
305 return;
306 }
307
308 cmdlen = __GLX_PAD(__GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE
309 + image_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,
324 data, image_size);
325 }
326 __GLX_END(cmdlen);
327 }
328 else {
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,
342 data, image_size);
343 }
344 }