VirtualBox

source: vbox/trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_pixel.c@ 42227

Last change on this file since 42227 was 38772, checked in by vboxsync, 13 years ago

crOpenGL: fix PBOs with compressed tex images

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 25.2 KB
Line 
1/* Copyright (c) 2001, Stanford University
2 All rights reserved.
3
4 See the file LICENSE.txt for information on redistributing this software. */
5
6#include "cr_packfunctions.h"
7#include "cr_glstate.h"
8#include "cr_pixeldata.h"
9#include "cr_version.h"
10#include "packspu.h"
11#include "packspu_proto.h"
12
13static GLboolean packspu_CheckTexImageFormat(GLenum format)
14{
15 if (format!=GL_COLOR_INDEX
16 && format!=GL_RED
17 && format!=GL_GREEN
18 && format!=GL_BLUE
19 && format!=GL_ALPHA
20 && format!=GL_RGB
21 && format!=GL_BGR
22 && format!=GL_RGBA
23 && format!=GL_BGRA
24 && format!=GL_LUMINANCE
25 && format!=GL_LUMINANCE_ALPHA
26 && format!=GL_DEPTH_COMPONENT
27 && format!=GL_DEPTH_STENCIL)
28 {
29 /*crWarning("crPackCheckTexImageFormat FAILED format 0x%x isn't valid", format);*/
30 return GL_FALSE;
31 }
32
33 return GL_TRUE;
34}
35
36static GLboolean packspu_CheckTexImageType(GLenum type)
37{
38 if (type!=GL_UNSIGNED_BYTE
39 && type!=GL_BYTE
40 && type!=GL_BITMAP
41 && type!=GL_UNSIGNED_SHORT
42 && type!=GL_SHORT
43 && type!=GL_UNSIGNED_INT
44 && type!=GL_INT
45 && type!=GL_FLOAT
46 && type!=GL_UNSIGNED_BYTE_3_3_2
47 && type!=GL_UNSIGNED_BYTE_2_3_3_REV
48 && type!=GL_UNSIGNED_SHORT_5_6_5
49 && type!=GL_UNSIGNED_SHORT_5_6_5_REV
50 && type!=GL_UNSIGNED_SHORT_4_4_4_4
51 && type!=GL_UNSIGNED_SHORT_4_4_4_4_REV
52 && type!=GL_UNSIGNED_SHORT_5_5_5_1
53 && type!=GL_UNSIGNED_SHORT_1_5_5_5_REV
54 && type!=GL_UNSIGNED_INT_8_8_8_8
55 && type!=GL_UNSIGNED_INT_8_8_8_8_REV
56 && type!=GL_UNSIGNED_INT_10_10_10_2
57 && type!=GL_UNSIGNED_INT_2_10_10_10_REV
58 && type!=GL_UNSIGNED_INT_24_8)
59 {
60 /*crWarning("crPackCheckTexImageType FAILED type 0x%x isn't valid", type);*/
61 return GL_FALSE;
62 }
63
64 return GL_TRUE;
65}
66
67static GLboolean packspu_CheckTexImageInternalFormat(GLint internalformat)
68{
69 if (internalformat!=1
70 && internalformat!=2
71 && internalformat!=3
72 && internalformat!=4
73 && internalformat!=GL_ALPHA
74 && internalformat!=GL_ALPHA4
75 && internalformat!=GL_ALPHA8
76 && internalformat!=GL_ALPHA12
77 && internalformat!=GL_ALPHA16
78 && internalformat!=GL_COMPRESSED_ALPHA
79 && internalformat!=GL_COMPRESSED_LUMINANCE
80 && internalformat!=GL_COMPRESSED_LUMINANCE_ALPHA
81 && internalformat!=GL_COMPRESSED_INTENSITY
82 && internalformat!=GL_COMPRESSED_RGB
83 && internalformat!=GL_COMPRESSED_RGBA
84 && internalformat!=GL_DEPTH_COMPONENT
85 && internalformat!=GL_DEPTH_COMPONENT16
86 && internalformat!=GL_DEPTH_COMPONENT24
87 && internalformat!=GL_DEPTH_COMPONENT32
88 && internalformat!=GL_DEPTH24_STENCIL8
89 && internalformat!=GL_LUMINANCE
90 && internalformat!=GL_LUMINANCE4
91 && internalformat!=GL_LUMINANCE8
92 && internalformat!=GL_LUMINANCE12
93 && internalformat!=GL_LUMINANCE16
94 && internalformat!=GL_LUMINANCE_ALPHA
95 && internalformat!=GL_LUMINANCE4_ALPHA4
96 && internalformat!=GL_LUMINANCE6_ALPHA2
97 && internalformat!=GL_LUMINANCE8_ALPHA8
98 && internalformat!=GL_LUMINANCE12_ALPHA4
99 && internalformat!=GL_LUMINANCE12_ALPHA12
100 && internalformat!=GL_LUMINANCE16_ALPHA16
101 && internalformat!=GL_INTENSITY
102 && internalformat!=GL_INTENSITY4
103 && internalformat!=GL_INTENSITY8
104 && internalformat!=GL_INTENSITY12
105 && internalformat!=GL_INTENSITY16
106 && internalformat!=GL_R3_G3_B2
107 && internalformat!=GL_RGB
108 && internalformat!=GL_RGB4
109 && internalformat!=GL_RGB5
110 && internalformat!=GL_RGB8
111 && internalformat!=GL_RGB10
112 && internalformat!=GL_RGB12
113 && internalformat!=GL_RGB16
114 && internalformat!=GL_RGBA
115 && internalformat!=GL_RGBA2
116 && internalformat!=GL_RGBA4
117 && internalformat!=GL_RGB5_A1
118 && internalformat!=GL_RGBA8
119 && internalformat!=GL_RGB10_A2
120 && internalformat!=GL_RGBA12
121 && internalformat!=GL_RGBA16
122 && internalformat!=GL_SLUMINANCE
123 && internalformat!=GL_SLUMINANCE8
124 && internalformat!=GL_SLUMINANCE_ALPHA
125 && internalformat!=GL_SLUMINANCE8_ALPHA8
126 && internalformat!=GL_SRGB
127 && internalformat!=GL_SRGB8
128 && internalformat!=GL_SRGB_ALPHA
129 && internalformat!=GL_SRGB8_ALPHA8
130#ifdef CR_EXT_texture_compression_s3tc
131 && internalformat!=GL_COMPRESSED_RGB_S3TC_DXT1_EXT
132 && internalformat!=GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
133 && internalformat!=GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
134 && internalformat!=GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
135# ifdef CR_EXT_texture_sRGB
136 && internalformat!=GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
137 && internalformat!=GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
138 && internalformat!=GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
139 && internalformat!=GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
140# endif
141#endif
142 /*@todo ARB_texture_float*/
143 && internalformat!=GL_RGBA32F_ARB
144 && internalformat!=GL_RGB32F_ARB
145 && internalformat!=GL_ALPHA32F_ARB
146 && internalformat!=GL_INTENSITY32F_ARB
147 && internalformat!=GL_LUMINANCE32F_ARB
148 && internalformat!=GL_LUMINANCE_ALPHA32F_ARB
149 && internalformat!=GL_RGBA16F_ARB
150 && internalformat!=GL_RGB16F_ARB
151 && internalformat!=GL_ALPHA16F_ARB
152 && internalformat!=GL_INTENSITY16F_ARB
153 && internalformat!=GL_LUMINANCE16F_ARB
154 && internalformat!=GL_LUMINANCE_ALPHA16F_ARB
155 )
156 {
157 /*crWarning("crPackCheckTexImageInternalFormat FAILED internalformat 0x%x isn't valid", internalformat);*/
158 return GL_FALSE;
159 }
160
161 return GL_TRUE;
162}
163
164static GLboolean packspu_CheckTexImageParams(GLint internalformat, GLenum format, GLenum type)
165{
166 return packspu_CheckTexImageFormat(format)
167 && packspu_CheckTexImageType(type)
168 && packspu_CheckTexImageInternalFormat(internalformat);
169}
170
171static GLboolean packspu_CheckTexImageFormatType(GLenum format, GLenum type)
172{
173 return packspu_CheckTexImageFormat(format)
174 && packspu_CheckTexImageType(type);
175}
176
177static const CRPixelPackState _defaultPacking = {
178 0, /* rowLength */
179 0, /* skipRows */
180 0, /* skipPixels */
181 1, /* alignment */
182 0, /* imageHeight */
183 0, /* skipImages */
184 GL_FALSE, /* swapBytes */
185 GL_FALSE, /* psLSBFirst */
186};
187
188#define APPLY_IF_NEQ(state, field, enum) \
189 if (state.field != _defaultPacking.field) \
190 { \
191 crPackPixelStorei(enum, state.field); \
192 }
193
194#define RESTORE_IF_NEQ(state, field, enum) \
195 if (state.field != _defaultPacking.field) \
196 { \
197 crPackPixelStorei(enum, _defaultPacking.field); \
198 }
199
200static void packspu_ApplyUnpackState()
201{
202 GET_THREAD(thread);
203 ContextInfo *ctx = thread->currentContext;
204 CRClientState *clientState = &(ctx->clientState->client);
205
206 APPLY_IF_NEQ(clientState->unpack, rowLength, GL_UNPACK_ROW_LENGTH);
207 APPLY_IF_NEQ(clientState->unpack, skipRows, GL_UNPACK_SKIP_ROWS);
208 APPLY_IF_NEQ(clientState->unpack, skipPixels, GL_UNPACK_SKIP_PIXELS);
209 APPLY_IF_NEQ(clientState->unpack, alignment, GL_UNPACK_ALIGNMENT);
210 APPLY_IF_NEQ(clientState->unpack, imageHeight, GL_UNPACK_IMAGE_HEIGHT);
211 APPLY_IF_NEQ(clientState->unpack, skipImages, GL_UNPACK_SKIP_IMAGES);
212 APPLY_IF_NEQ(clientState->unpack, swapBytes, GL_UNPACK_SWAP_BYTES);
213 APPLY_IF_NEQ(clientState->unpack, psLSBFirst, GL_UNPACK_LSB_FIRST);
214}
215
216static void packspu_RestoreUnpackState()
217{
218 GET_THREAD(thread);
219 ContextInfo *ctx = thread->currentContext;
220 CRClientState *clientState = &(ctx->clientState->client);
221
222 RESTORE_IF_NEQ(clientState->unpack, rowLength, GL_UNPACK_ROW_LENGTH);
223 RESTORE_IF_NEQ(clientState->unpack, skipRows, GL_UNPACK_SKIP_ROWS);
224 RESTORE_IF_NEQ(clientState->unpack, skipPixels, GL_UNPACK_SKIP_PIXELS);
225 RESTORE_IF_NEQ(clientState->unpack, alignment, GL_UNPACK_ALIGNMENT);
226 RESTORE_IF_NEQ(clientState->unpack, imageHeight, GL_UNPACK_IMAGE_HEIGHT);
227 RESTORE_IF_NEQ(clientState->unpack, skipImages, GL_UNPACK_SKIP_IMAGES);
228 RESTORE_IF_NEQ(clientState->unpack, swapBytes, GL_UNPACK_SWAP_BYTES);
229 RESTORE_IF_NEQ(clientState->unpack, psLSBFirst, GL_UNPACK_LSB_FIRST);
230}
231
232static void packspu_ApplyPackState()
233{
234 GET_THREAD(thread);
235 ContextInfo *ctx = thread->currentContext;
236 CRClientState *clientState = &(ctx->clientState->client);
237
238 APPLY_IF_NEQ(clientState->pack, rowLength, GL_PACK_ROW_LENGTH);
239 APPLY_IF_NEQ(clientState->pack, skipRows, GL_PACK_SKIP_ROWS);
240 APPLY_IF_NEQ(clientState->pack, skipPixels, GL_PACK_SKIP_PIXELS);
241 APPLY_IF_NEQ(clientState->pack, alignment, GL_PACK_ALIGNMENT);
242 APPLY_IF_NEQ(clientState->pack, imageHeight, GL_PACK_IMAGE_HEIGHT);
243 APPLY_IF_NEQ(clientState->pack, skipImages, GL_PACK_SKIP_IMAGES);
244 APPLY_IF_NEQ(clientState->pack, swapBytes, GL_PACK_SWAP_BYTES);
245 APPLY_IF_NEQ(clientState->pack, psLSBFirst, GL_PACK_LSB_FIRST);
246}
247
248static void packspu_RestorePackState()
249{
250 GET_THREAD(thread);
251 ContextInfo *ctx = thread->currentContext;
252 CRClientState *clientState = &(ctx->clientState->client);
253
254 RESTORE_IF_NEQ(clientState->pack, rowLength, GL_PACK_ROW_LENGTH);
255 RESTORE_IF_NEQ(clientState->pack, skipRows, GL_PACK_SKIP_ROWS);
256 RESTORE_IF_NEQ(clientState->pack, skipPixels, GL_PACK_SKIP_PIXELS);
257 RESTORE_IF_NEQ(clientState->pack, alignment, GL_PACK_ALIGNMENT);
258 RESTORE_IF_NEQ(clientState->pack, imageHeight, GL_PACK_IMAGE_HEIGHT);
259 RESTORE_IF_NEQ(clientState->pack, skipImages, GL_PACK_SKIP_IMAGES);
260 RESTORE_IF_NEQ(clientState->pack, swapBytes, GL_PACK_SWAP_BYTES);
261 RESTORE_IF_NEQ(clientState->pack, psLSBFirst, GL_PACK_LSB_FIRST);
262}
263
264void PACKSPU_APIENTRY packspu_PixelStoref( GLenum pname, GLfloat param )
265{
266 /* NOTE: we do not send pixel store parameters to the server!
267 * When we pack a glDrawPixels or glTexImage2D image we interpret
268 * the user's pixel store parameters at that time and pack the
269 * image in a canonical layout (see util/pixel.c).
270 */
271 crStatePixelStoref( pname, param );
272}
273
274void PACKSPU_APIENTRY packspu_PixelStorei( GLenum pname, GLint param )
275{
276 crStatePixelStorei( pname, param );
277}
278
279void PACKSPU_APIENTRY packspu_DrawPixels( GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels )
280{
281 GET_THREAD(thread);
282 ContextInfo *ctx = thread->currentContext;
283 CRClientState *clientState = &(ctx->clientState->client);
284
285 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
286 {
287 packspu_ApplyUnpackState();
288 }
289
290 crPackDrawPixels( width, height, format, type, pixels, &(clientState->unpack) );
291
292 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
293 {
294 packspu_RestoreUnpackState();
295 }
296}
297
298void PACKSPU_APIENTRY packspu_ReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels )
299{
300 GET_THREAD(thread);
301 ContextInfo *ctx = thread->currentContext;
302 CRClientState *clientState = &(ctx->clientState->client);
303 int writeback;
304
305 if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
306 {
307 packspu_ApplyPackState();
308 }
309
310 crPackReadPixels(x, y, width, height, format, type, pixels, &(clientState->pack), &writeback);
311
312 if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
313 {
314 packspu_RestorePackState();
315 }
316
317#ifdef CR_ARB_pixel_buffer_object
318 if (!crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
319#endif
320 {
321 pack_spu.ReadPixels++;
322
323 packspuFlush((void *) thread);
324 while (pack_spu.ReadPixels)
325 crNetRecv();
326 }
327}
328
329/*@todo check with pbo's*/
330void PACKSPU_APIENTRY packspu_CopyPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum type )
331{
332 GET_THREAD(thread);
333 if (pack_spu.swap)
334 crPackCopyPixelsSWAP( x, y, width, height, type );
335 else
336 crPackCopyPixels( x, y, width, height, type );
337 /* XXX why flush here? */
338 packspuFlush( (void *) thread );
339}
340
341void PACKSPU_APIENTRY packspu_Bitmap( GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte *bitmap )
342{
343 GET_CONTEXT(ctx);
344 CRClientState *clientState = &(ctx->clientState->client);
345
346 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
347 {
348 packspu_ApplyUnpackState();
349 }
350
351 crPackBitmap(width, height, xorig, yorig, xmove, ymove, bitmap, &(clientState->unpack));
352
353 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
354 {
355 packspu_RestoreUnpackState();
356 }
357}
358
359void PACKSPU_APIENTRY packspu_TexImage1D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
360{
361 GET_CONTEXT(ctx);
362 CRClientState *clientState = &(ctx->clientState->client);
363
364 if (!packspu_CheckTexImageParams(internalformat, format, type))
365 {
366 if (pixels || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
367 {
368 crWarning("packspu_TexImage1D invalid internalFormat(%x)/format(%x)/type(%x)", internalformat, format, type);
369 return;
370 }
371 internalformat = packspu_CheckTexImageInternalFormat(internalformat) ? internalformat:GL_RGBA;
372 format = packspu_CheckTexImageFormat(format) ? format:GL_RGBA;
373 type = packspu_CheckTexImageType(type) ? type:GL_UNSIGNED_BYTE;
374 }
375
376 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
377 {
378 packspu_ApplyUnpackState();
379 }
380
381 if (pack_spu.swap)
382 crPackTexImage1DSWAP( target, level, internalformat, width, border, format, type, pixels, &(clientState->unpack) );
383 else
384 crPackTexImage1D( target, level, internalformat, width, border, format, type, pixels, &(clientState->unpack) );
385
386 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
387 {
388 packspu_RestoreUnpackState();
389 }
390}
391
392void PACKSPU_APIENTRY packspu_TexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
393{
394 GET_CONTEXT(ctx);
395 CRClientState *clientState = &(ctx->clientState->client);
396
397 if (!packspu_CheckTexImageParams(internalformat, format, type))
398 {
399 if (pixels || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
400 {
401 crWarning("packspu_TexImage2D invalid internalFormat(%x)/format(%x)/type(%x)", internalformat, format, type);
402 return;
403 }
404 internalformat = packspu_CheckTexImageInternalFormat(internalformat) ? internalformat:GL_RGBA;
405 format = packspu_CheckTexImageFormat(format) ? format:GL_RGBA;
406 type = packspu_CheckTexImageType(type) ? type:GL_UNSIGNED_BYTE;
407 }
408
409 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
410 {
411 packspu_ApplyUnpackState();
412 }
413
414 if (pack_spu.swap)
415 crPackTexImage2DSWAP( target, level, internalformat, width, height, border, format, type, pixels, &(clientState->unpack) );
416 else
417 crPackTexImage2D( target, level, internalformat, width, height, border, format, type, pixels, &(clientState->unpack) );
418
419 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
420 {
421 packspu_RestoreUnpackState();
422 }
423}
424
425#ifdef GL_EXT_texture3D
426void PACKSPU_APIENTRY packspu_TexImage3DEXT( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
427{
428 GET_CONTEXT(ctx);
429 CRClientState *clientState = &(ctx->clientState->client);
430
431 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
432 {
433 packspu_ApplyUnpackState();
434 }
435
436 if (pack_spu.swap)
437 crPackTexImage3DEXTSWAP( target, level, internalformat, width, height, depth, border, format, type, pixels, &(clientState->unpack) );
438 else
439 crPackTexImage3DEXT( target, level, internalformat, width, height, depth, border, format, type, pixels, &(clientState->unpack) );
440
441 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
442 {
443 packspu_RestoreUnpackState();
444 }
445}
446#endif
447
448#ifdef CR_OPENGL_VERSION_1_2
449void PACKSPU_APIENTRY packspu_TexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
450{
451 GET_CONTEXT(ctx);
452 CRClientState *clientState = &(ctx->clientState->client);
453
454 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
455 {
456 packspu_ApplyUnpackState();
457 }
458
459 if (pack_spu.swap)
460 crPackTexImage3DSWAP( target, level, internalformat, width, height, depth, border, format, type, pixels, &(clientState->unpack) );
461 else
462 crPackTexImage3D( target, level, internalformat, width, height, depth, border, format, type, pixels, &(clientState->unpack) );
463
464 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
465 {
466 packspu_RestoreUnpackState();
467 }
468}
469#endif /* CR_OPENGL_VERSION_1_2 */
470
471void PACKSPU_APIENTRY packspu_TexSubImage1D( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels )
472{
473 GET_CONTEXT(ctx);
474 CRClientState *clientState = &(ctx->clientState->client);
475
476 if (!packspu_CheckTexImageFormatType(format, type))
477 {
478 crWarning("packspu_TexSubImage1D invalid format(%x)/type(%x)", format, type);
479 return;
480 }
481
482 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
483 {
484 packspu_ApplyUnpackState();
485 }
486
487 if (pack_spu.swap)
488 crPackTexSubImage1DSWAP( target, level, xoffset, width, format, type, pixels, &(clientState->unpack) );
489 else
490 crPackTexSubImage1D( target, level, xoffset, width, format, type, pixels, &(clientState->unpack) );
491
492 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
493 {
494 packspu_RestoreUnpackState();
495 }
496}
497
498void PACKSPU_APIENTRY packspu_TexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels )
499{
500 GET_CONTEXT(ctx);
501 CRClientState *clientState = &(ctx->clientState->client);
502
503 if (!packspu_CheckTexImageFormatType(format, type))
504 {
505 crWarning("packspu_TexSubImage2D invalid format(%x)/type(%x)", format, type);
506 return;
507 }
508
509 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
510 {
511 packspu_ApplyUnpackState();
512 }
513
514 if (pack_spu.swap)
515 crPackTexSubImage2DSWAP( target, level, xoffset, yoffset, width, height, format, type, pixels, &(clientState->unpack) );
516 else
517 crPackTexSubImage2D( target, level, xoffset, yoffset, width, height, format, type, pixels, &(clientState->unpack) );
518
519 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
520 {
521 packspu_RestoreUnpackState();
522 }
523}
524
525#ifdef CR_OPENGL_VERSION_1_2
526void PACKSPU_APIENTRY packspu_TexSubImage3D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels )
527{
528 GET_CONTEXT(ctx);
529 CRClientState *clientState = &(ctx->clientState->client);
530
531 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
532 {
533 packspu_ApplyUnpackState();
534 }
535
536 if (pack_spu.swap)
537 crPackTexSubImage3DSWAP( target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels, &(clientState->unpack) );
538 else
539 crPackTexSubImage3D( target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels, &(clientState->unpack) );
540
541 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
542 {
543 packspu_RestoreUnpackState();
544 }
545}
546#endif /* CR_OPENGL_VERSION_1_2 */
547
548void PACKSPU_APIENTRY packspu_ZPixCR( GLsizei width, GLsizei height, GLenum format, GLenum type, GLenum ztype, GLint zparm, GLint length, const GLvoid *pixels )
549{
550 GET_CONTEXT(ctx);
551 CRClientState *clientState = &(ctx->clientState->client);
552 if (pack_spu.swap)
553 crPackZPixCRSWAP( width, height, format, type, ztype, zparm, length, pixels, &(clientState->unpack) );
554 else
555 crPackZPixCR( width, height, format, type, ztype, zparm, length, pixels, &(clientState->unpack) );
556}
557
558void PACKSPU_APIENTRY packspu_GetTexImage (GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels)
559{
560 GET_THREAD(thread);
561 ContextInfo *ctx = thread->currentContext;
562 CRClientState *clientState = &(ctx->clientState->client);
563 int writeback = 1;
564
565 /* XXX note: we're not observing the pixel pack parameters here unless PACK PBO is bound
566 * To do so, we'd have to allocate a temporary image buffer (how large???)
567 * and copy the image to the user's buffer using the pixel pack params.
568 */
569
570 if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
571 {
572 packspu_ApplyPackState();
573 }
574
575 if (pack_spu.swap)
576 crPackGetTexImageSWAP( target, level, format, type, pixels, &(clientState->pack), &writeback );
577 else
578 crPackGetTexImage( target, level, format, type, pixels, &(clientState->pack), &writeback );
579
580 if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
581 {
582 packspu_RestorePackState();
583 }
584
585#ifdef CR_ARB_pixel_buffer_object
586 if (!crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
587#endif
588 {
589 packspuFlush( (void *) thread );
590 while (writeback)
591 crNetRecv();
592 }
593}
594
595void PACKSPU_APIENTRY packspu_GetCompressedTexImageARB( GLenum target, GLint level, GLvoid * img )
596{
597 GET_THREAD(thread);
598 int writeback = 1;
599
600 if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
601 {
602 packspu_ApplyPackState();
603 }
604
605 if (pack_spu.swap)
606 {
607 crPackGetCompressedTexImageARBSWAP( target, level, img, &writeback );
608 }
609 else
610 {
611 crPackGetCompressedTexImageARB( target, level, img, &writeback );
612 }
613
614 if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
615 {
616 packspu_RestorePackState();
617 }
618
619#ifdef CR_ARB_pixel_buffer_object
620 if (!crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
621#endif
622 {
623 packspuFlush( (void *) thread );
624 while (writeback)
625 crNetRecv();
626 }
627}
628
629void PACKSPU_APIENTRY
630packspu_CompressedTexImage1DARB(GLenum target, GLint level, GLenum internalformat, GLsizei width,
631 GLint border, GLsizei imagesize, const GLvoid *data)
632{
633 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
634 {
635 packspu_ApplyUnpackState();
636 }
637
638 crPackCompressedTexImage1DARB(target, level, internalformat, width, border, imagesize, data);
639
640 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
641 {
642 packspu_RestoreUnpackState();
643 }
644}
645
646void PACKSPU_APIENTRY
647packspu_CompressedTexImage2DARB(GLenum target, GLint level, GLenum internalformat, GLsizei width,
648 GLsizei height, GLint border, GLsizei imagesize, const GLvoid *data)
649{
650 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
651 {
652 packspu_ApplyUnpackState();
653 }
654
655 crPackCompressedTexImage2DARB(target, level, internalformat, width, height, border, imagesize, data);
656
657 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
658 {
659 packspu_RestoreUnpackState();
660 }
661}
662
663void PACKSPU_APIENTRY
664packspu_CompressedTexImage3DARB(GLenum target, GLint level, GLenum internalformat, GLsizei width,
665 GLsizei height, GLsizei depth, GLint border, GLsizei imagesize, const GLvoid *data)
666{
667 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
668 {
669 packspu_ApplyUnpackState();
670 }
671
672 crPackCompressedTexImage3DARB(target, level, internalformat, width, height, depth, border, imagesize, data);
673
674 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
675 {
676 packspu_RestoreUnpackState();
677 }
678}
679
680void PACKSPU_APIENTRY
681packspu_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset, GLsizei width,
682 GLenum format, GLsizei imagesize, const GLvoid *data)
683{
684 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
685 {
686 packspu_ApplyUnpackState();
687 }
688
689 crPackCompressedTexSubImage1DARB(target, level, xoffset, width, format, imagesize, data);
690
691 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
692 {
693 packspu_RestoreUnpackState();
694 }
695}
696
697void PACKSPU_APIENTRY
698packspu_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset, GLint yoffset,
699 GLsizei width, GLsizei height, GLenum format, GLsizei imagesize, const GLvoid *data)
700{
701 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
702 {
703 packspu_ApplyUnpackState();
704 }
705
706 crPackCompressedTexSubImage2DARB(target, level, xoffset, yoffset, width, height, format, imagesize, data);
707
708 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
709 {
710 packspu_RestoreUnpackState();
711 }
712}
713
714void PACKSPU_APIENTRY
715packspu_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, GLint yoffset,
716 GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format,
717 GLsizei imagesize, const GLvoid *data)
718{
719 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
720 {
721 packspu_ApplyUnpackState();
722 }
723
724 crPackCompressedTexSubImage3DARB(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imagesize, data);
725
726 if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
727 {
728 packspu_RestoreUnpackState();
729 }
730}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette