VirtualBox

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

Last change on this file since 31988 was 27410, checked in by vboxsync, 15 years ago

crOpenGL: fix incorrect rendering for couple of oZone tests

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 16.0 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 {
28 /*crWarning("crPackCheckTexImageFormat FAILED format 0x%x isn't valid", format);*/
29 return GL_FALSE;
30 }
31
32 return GL_TRUE;
33}
34
35static GLboolean packspu_CheckTexImageType(GLenum type)
36{
37 if (type!=GL_UNSIGNED_BYTE
38 && type!=GL_BYTE
39 && type!=GL_BITMAP
40 && type!=GL_UNSIGNED_SHORT
41 && type!=GL_SHORT
42 && type!=GL_UNSIGNED_INT
43 && type!=GL_INT
44 && type!=GL_FLOAT
45 && type!=GL_UNSIGNED_BYTE_3_3_2
46 && type!=GL_UNSIGNED_BYTE_2_3_3_REV
47 && type!=GL_UNSIGNED_SHORT_5_6_5
48 && type!=GL_UNSIGNED_SHORT_5_6_5_REV
49 && type!=GL_UNSIGNED_SHORT_4_4_4_4
50 && type!=GL_UNSIGNED_SHORT_4_4_4_4_REV
51 && type!=GL_UNSIGNED_SHORT_5_5_5_1
52 && type!=GL_UNSIGNED_SHORT_1_5_5_5_REV
53 && type!=GL_UNSIGNED_INT_8_8_8_8
54 && type!=GL_UNSIGNED_INT_8_8_8_8_REV
55 && type!=GL_UNSIGNED_INT_10_10_10_2
56 && type!=GL_UNSIGNED_INT_2_10_10_10_REV)
57 {
58 /*crWarning("crPackCheckTexImageType FAILED type 0x%x isn't valid", type);*/
59 return GL_FALSE;
60 }
61
62 return GL_TRUE;
63}
64
65static GLboolean packspu_CheckTexImageInternalFormat(GLint internalformat)
66{
67 if (internalformat!=1
68 && internalformat!=2
69 && internalformat!=3
70 && internalformat!=4
71 && internalformat!=GL_ALPHA
72 && internalformat!=GL_ALPHA4
73 && internalformat!=GL_ALPHA8
74 && internalformat!=GL_ALPHA12
75 && internalformat!=GL_ALPHA16
76 && internalformat!=GL_COMPRESSED_ALPHA
77 && internalformat!=GL_COMPRESSED_LUMINANCE
78 && internalformat!=GL_COMPRESSED_LUMINANCE_ALPHA
79 && internalformat!=GL_COMPRESSED_INTENSITY
80 && internalformat!=GL_COMPRESSED_RGB
81 && internalformat!=GL_COMPRESSED_RGBA
82 && internalformat!=GL_DEPTH_COMPONENT
83 && internalformat!=GL_DEPTH_COMPONENT16
84 && internalformat!=GL_DEPTH_COMPONENT24
85 && internalformat!=GL_DEPTH_COMPONENT32
86 && internalformat!=GL_LUMINANCE
87 && internalformat!=GL_LUMINANCE4
88 && internalformat!=GL_LUMINANCE8
89 && internalformat!=GL_LUMINANCE12
90 && internalformat!=GL_LUMINANCE16
91 && internalformat!=GL_LUMINANCE_ALPHA
92 && internalformat!=GL_LUMINANCE4_ALPHA4
93 && internalformat!=GL_LUMINANCE6_ALPHA2
94 && internalformat!=GL_LUMINANCE8_ALPHA8
95 && internalformat!=GL_LUMINANCE12_ALPHA4
96 && internalformat!=GL_LUMINANCE12_ALPHA12
97 && internalformat!=GL_LUMINANCE16_ALPHA16
98 && internalformat!=GL_INTENSITY
99 && internalformat!=GL_INTENSITY4
100 && internalformat!=GL_INTENSITY8
101 && internalformat!=GL_INTENSITY12
102 && internalformat!=GL_INTENSITY16
103 && internalformat!=GL_R3_G3_B2
104 && internalformat!=GL_RGB
105 && internalformat!=GL_RGB4
106 && internalformat!=GL_RGB5
107 && internalformat!=GL_RGB8
108 && internalformat!=GL_RGB10
109 && internalformat!=GL_RGB12
110 && internalformat!=GL_RGB16
111 && internalformat!=GL_RGBA
112 && internalformat!=GL_RGBA2
113 && internalformat!=GL_RGBA4
114 && internalformat!=GL_RGB5_A1
115 && internalformat!=GL_RGBA8
116 && internalformat!=GL_RGB10_A2
117 && internalformat!=GL_RGBA12
118 && internalformat!=GL_RGBA16
119 && internalformat!=GL_SLUMINANCE
120 && internalformat!=GL_SLUMINANCE8
121 && internalformat!=GL_SLUMINANCE_ALPHA
122 && internalformat!=GL_SLUMINANCE8_ALPHA8
123 && internalformat!=GL_SRGB
124 && internalformat!=GL_SRGB8
125 && internalformat!=GL_SRGB_ALPHA
126 && internalformat!=GL_SRGB8_ALPHA8
127#ifdef CR_EXT_texture_compression_s3tc
128 && internalformat!=GL_COMPRESSED_RGB_S3TC_DXT1_EXT
129 && internalformat!=GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
130 && internalformat!=GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
131 && internalformat!=GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
132# ifdef CR_EXT_texture_sRGB
133 && internalformat!=GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
134 && internalformat!=GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
135 && internalformat!=GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
136 && internalformat!=GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
137# endif
138#endif
139 /*@todo ARB_texture_float*/
140 && internalformat!=GL_RGBA32F_ARB
141 && internalformat!=GL_RGB32F_ARB
142 && internalformat!=GL_ALPHA32F_ARB
143 && internalformat!=GL_INTENSITY32F_ARB
144 && internalformat!=GL_LUMINANCE32F_ARB
145 && internalformat!=GL_LUMINANCE_ALPHA32F_ARB
146 && internalformat!=GL_RGBA16F_ARB
147 && internalformat!=GL_RGB16F_ARB
148 && internalformat!=GL_ALPHA16F_ARB
149 && internalformat!=GL_INTENSITY16F_ARB
150 && internalformat!=GL_LUMINANCE16F_ARB
151 && internalformat!=GL_LUMINANCE_ALPHA16F_ARB
152 )
153 {
154 /*crWarning("crPackCheckTexImageInternalFormat FAILED internalformat 0x%x isn't valid", internalformat);*/
155 return GL_FALSE;
156 }
157
158 return GL_TRUE;
159}
160
161static GLboolean packspu_CheckTexImageParams(GLint internalformat, GLenum format, GLenum type)
162{
163 return packspu_CheckTexImageFormat(format)
164 && packspu_CheckTexImageType(type)
165 && packspu_CheckTexImageInternalFormat(internalformat);
166}
167
168static GLboolean packspu_CheckTexImageFormatType(GLenum format, GLenum type)
169{
170 return packspu_CheckTexImageFormat(format)
171 && packspu_CheckTexImageType(type);
172}
173
174void PACKSPU_APIENTRY packspu_PixelStoref( GLenum pname, GLfloat param )
175{
176 /* NOTE: we do not send pixel store parameters to the server!
177 * When we pack a glDrawPixels or glTexImage2D image we interpret
178 * the user's pixel store parameters at that time and pack the
179 * image in a canonical layout (see util/pixel.c).
180 */
181 crStatePixelStoref( pname, param );
182}
183
184void PACKSPU_APIENTRY packspu_PixelStorei( GLenum pname, GLint param )
185{
186 crStatePixelStorei( pname, param );
187}
188
189void PACKSPU_APIENTRY packspu_DrawPixels( GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels )
190{
191 GET_THREAD(thread);
192 ContextInfo *ctx = thread->currentContext;
193 CRClientState *clientState = &(ctx->clientState->client);
194 if (pack_spu.swap)
195 crPackDrawPixelsSWAP( width, height, format, type, pixels, &(clientState->unpack) );
196 else
197 crPackDrawPixels( width, height, format, type, pixels, &(clientState->unpack) );
198}
199
200void PACKSPU_APIENTRY packspu_ReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels )
201{
202 GET_THREAD(thread);
203 ContextInfo *ctx = thread->currentContext;
204 CRClientState *clientState = &(ctx->clientState->client);
205 int writeback;
206
207 if (pack_spu.swap)
208 {
209 crPackReadPixelsSWAP(x, y, width, height, format, type, pixels,
210 &(clientState->pack), &writeback);
211 }
212 else
213 {
214 crPackReadPixels(x, y, width, height, format, type, pixels,
215 &(clientState->pack), &writeback);
216 }
217
218#ifdef CR_ARB_pixel_buffer_object
219 if (!crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
220#endif
221 {
222 pack_spu.ReadPixels++;
223
224 packspuFlush((void *) thread);
225 while (pack_spu.ReadPixels)
226 crNetRecv();
227 }
228}
229
230void PACKSPU_APIENTRY packspu_CopyPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum type )
231{
232 GET_THREAD(thread);
233 if (pack_spu.swap)
234 crPackCopyPixelsSWAP( x, y, width, height, type );
235 else
236 crPackCopyPixels( x, y, width, height, type );
237 /* XXX why flush here? */
238 packspuFlush( (void *) thread );
239}
240
241void PACKSPU_APIENTRY packspu_Bitmap( GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte *bitmap )
242{
243 GET_CONTEXT(ctx);
244 CRClientState *clientState = &(ctx->clientState->client);
245 if (pack_spu.swap)
246 crPackBitmapSWAP( width, height, xorig, yorig, xmove, ymove, bitmap, &(clientState->unpack) );
247 else
248 crPackBitmap( width, height, xorig, yorig, xmove, ymove, bitmap, &(clientState->unpack) );
249}
250
251void PACKSPU_APIENTRY packspu_TexImage1D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
252{
253 GET_CONTEXT(ctx);
254 CRClientState *clientState = &(ctx->clientState->client);
255
256 if (!packspu_CheckTexImageParams(internalformat, format, type))
257 {
258 if (pixels || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
259 {
260 crWarning("packspu_TexImage1D invalid internalFormat(%x)/format(%x)/type(%x)", internalformat, format, type);
261 return;
262 }
263 internalformat = packspu_CheckTexImageInternalFormat(internalformat) ? internalformat:GL_RGBA;
264 format = packspu_CheckTexImageFormat(format) ? format:GL_RGBA;
265 type = packspu_CheckTexImageType(type) ? type:GL_UNSIGNED_BYTE;
266 }
267
268 if (pack_spu.swap)
269 crPackTexImage1DSWAP( target, level, internalformat, width, border, format, type, pixels, &(clientState->unpack) );
270 else
271 crPackTexImage1D( target, level, internalformat, width, border, format, type, pixels, &(clientState->unpack) );
272}
273
274void PACKSPU_APIENTRY packspu_TexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )
275{
276 GET_CONTEXT(ctx);
277 CRClientState *clientState = &(ctx->clientState->client);
278
279 if (!packspu_CheckTexImageParams(internalformat, format, type))
280 {
281 if (pixels || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
282 {
283 crWarning("packspu_TexImage2D invalid internalFormat(%x)/format(%x)/type(%x)", internalformat, format, type);
284 return;
285 }
286 internalformat = packspu_CheckTexImageInternalFormat(internalformat) ? internalformat:GL_RGBA;
287 format = packspu_CheckTexImageFormat(format) ? format:GL_RGBA;
288 type = packspu_CheckTexImageType(type) ? type:GL_UNSIGNED_BYTE;
289 }
290
291 if (pack_spu.swap)
292 crPackTexImage2DSWAP( target, level, internalformat, width, height, border, format, type, pixels, &(clientState->unpack) );
293 else
294 crPackTexImage2D( target, level, internalformat, width, height, border, format, type, pixels, &(clientState->unpack) );
295}
296
297#ifdef GL_EXT_texture3D
298void 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 )
299{
300 GET_CONTEXT(ctx);
301 CRClientState *clientState = &(ctx->clientState->client);
302
303 if (pack_spu.swap)
304 crPackTexImage3DEXTSWAP( target, level, internalformat, width, height, depth, border, format, type, pixels, &(clientState->unpack) );
305 else
306 crPackTexImage3DEXT( target, level, internalformat, width, height, depth, border, format, type, pixels, &(clientState->unpack) );
307}
308#endif
309
310#ifdef CR_OPENGL_VERSION_1_2
311void 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 )
312{
313 GET_CONTEXT(ctx);
314 CRClientState *clientState = &(ctx->clientState->client);
315 if (pack_spu.swap)
316 crPackTexImage3DSWAP( target, level, internalformat, width, height, depth, border, format, type, pixels, &(clientState->unpack) );
317 else
318 crPackTexImage3D( target, level, internalformat, width, height, depth, border, format, type, pixels, &(clientState->unpack) );
319}
320#endif /* CR_OPENGL_VERSION_1_2 */
321
322void PACKSPU_APIENTRY packspu_TexSubImage1D( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels )
323{
324 GET_CONTEXT(ctx);
325 CRClientState *clientState = &(ctx->clientState->client);
326
327 if (!packspu_CheckTexImageFormatType(format, type))
328 {
329 crWarning("packspu_TexSubImage1D invalid format(%x)/type(%x)", format, type);
330 return;
331 }
332
333 if (pack_spu.swap)
334 crPackTexSubImage1DSWAP( target, level, xoffset, width, format, type, pixels, &(clientState->unpack) );
335 else
336 crPackTexSubImage1D( target, level, xoffset, width, format, type, pixels, &(clientState->unpack) );
337}
338
339void PACKSPU_APIENTRY packspu_TexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels )
340{
341 GET_CONTEXT(ctx);
342 CRClientState *clientState = &(ctx->clientState->client);
343
344 if (!packspu_CheckTexImageFormatType(format, type))
345 {
346 crWarning("packspu_TexSubImage2D invalid format(%x)/type(%x)", format, type);
347 return;
348 }
349
350 if (pack_spu.swap)
351 crPackTexSubImage2DSWAP( target, level, xoffset, yoffset, width, height, format, type, pixels, &(clientState->unpack) );
352 else
353 crPackTexSubImage2D( target, level, xoffset, yoffset, width, height, format, type, pixels, &(clientState->unpack) );
354}
355
356#ifdef CR_OPENGL_VERSION_1_2
357void 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 )
358{
359 GET_CONTEXT(ctx);
360 CRClientState *clientState = &(ctx->clientState->client);
361 if (pack_spu.swap)
362 crPackTexSubImage3DSWAP( target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels, &(clientState->unpack) );
363 else
364 crPackTexSubImage3D( target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels, &(clientState->unpack) );
365}
366#endif /* CR_OPENGL_VERSION_1_2 */
367
368void PACKSPU_APIENTRY packspu_ZPixCR( GLsizei width, GLsizei height, GLenum format, GLenum type, GLenum ztype, GLint zparm, GLint length, const GLvoid *pixels )
369{
370 GET_CONTEXT(ctx);
371 CRClientState *clientState = &(ctx->clientState->client);
372 if (pack_spu.swap)
373 crPackZPixCRSWAP( width, height, format, type, ztype, zparm, length, pixels, &(clientState->unpack) );
374 else
375 crPackZPixCR( width, height, format, type, ztype, zparm, length, pixels, &(clientState->unpack) );
376}
377
378void PACKSPU_APIENTRY packspu_GetTexImage (GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels)
379{
380 GET_THREAD(thread);
381 ContextInfo *ctx = thread->currentContext;
382 CRClientState *clientState = &(ctx->clientState->client);
383 int writeback = 1;
384 /* XXX note: we're not observing the pixel pack parameters here.
385 * To do so, we'd have to allocate a temporary image buffer (how large???)
386 * and copy the image to the user's buffer using the pixel pack params.
387 */
388 if (pack_spu.swap)
389 crPackGetTexImageSWAP( target, level, format, type, pixels, &(clientState->pack), &writeback );
390 else
391 crPackGetTexImage( target, level, format, type, pixels, &(clientState->pack), &writeback );
392
393#ifdef CR_ARB_pixel_buffer_object
394 if (!crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
395#endif
396 {
397 packspuFlush( (void *) thread );
398 while (writeback)
399 crNetRecv();
400 }
401}
402
403void PACKSPU_APIENTRY packspu_GetCompressedTexImageARB( GLenum target, GLint level, GLvoid * img )
404{
405 GET_THREAD(thread);
406 int writeback = 1;
407
408 if (pack_spu.swap)
409 {
410 crPackGetCompressedTexImageARBSWAP( target, level, img, &writeback );
411 }
412 else
413 {
414 crPackGetCompressedTexImageARB( target, level, img, &writeback );
415 }
416
417#ifdef CR_ARB_pixel_buffer_object
418 if (!crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
419#endif
420 {
421 packspuFlush( (void *) thread );
422 while (writeback)
423 crNetRecv();
424 }
425}
Note: See TracBrowser for help on using the repository browser.

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