VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/packer/pack_texture.c@ 30013

Last change on this file since 30013 was 27983, checked in by vboxsync, 15 years ago

crOpenGL: fix 32/64bit bug

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 31.4 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
7#include "packer.h"
8#include "cr_pixeldata.h"
9#include "cr_error.h"
10#include "cr_string.h"
11#include "cr_version.h"
12#include "cr_glstate.h"
13
14void PACK_APIENTRY
15crPackTexImage1D(GLenum target, GLint level,
16 GLint internalformat, GLsizei width, GLint border,
17 GLenum format, GLenum type, const GLvoid * pixels,
18 const CRPixelPackState * unpackstate)
19{
20 unsigned char *data_ptr;
21 int packet_length;
22 int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
23
24 packet_length =
25 sizeof(target) +
26 sizeof(level) +
27 sizeof(internalformat) +
28 sizeof(width) +
29 sizeof(border) + sizeof(format) + sizeof(type) + sizeof(int) + sizeof(GLint);
30
31 if (!noimagedata)
32 {
33 packet_length += crImageSize(format, type, width, 1);
34 }
35
36 data_ptr = (unsigned char *) crPackAlloc(packet_length);
37 WRITE_DATA(0, GLenum, target);
38 WRITE_DATA(4, GLint, level);
39 WRITE_DATA(8, GLint, internalformat);
40 WRITE_DATA(12, GLsizei, width);
41 WRITE_DATA(16, GLint, border);
42 WRITE_DATA(20, GLenum, format);
43 WRITE_DATA(24, GLenum, type);
44 WRITE_DATA(28, int, noimagedata);
45 WRITE_DATA(32, GLint, (GLint)(uintptr_t) pixels);
46
47 if (!noimagedata)
48 {
49 crPixelCopy1D((void *) (data_ptr + 36), format, type,
50 pixels, format, type, width, unpackstate);
51 }
52
53 crHugePacket(CR_TEXIMAGE1D_OPCODE, data_ptr);
54 crPackFree( data_ptr );
55}
56
57void PACK_APIENTRY
58crPackTexImage2D(GLenum target, GLint level,
59 GLint internalformat, GLsizei width, GLsizei height,
60 GLint border, GLenum format, GLenum type,
61 const GLvoid * pixels, const CRPixelPackState * unpackstate)
62{
63 unsigned char *data_ptr;
64 int packet_length;
65 const int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
66 const int is_distrib = ((type == GL_TRUE) || (type == GL_FALSE));
67 int distrib_buf_len = 0;
68
69 packet_length =
70 sizeof(target) +
71 sizeof(level) +
72 sizeof(internalformat) +
73 sizeof(width) +
74 sizeof(height) +
75 sizeof(border) + sizeof(format) + sizeof(type) + sizeof(int) + sizeof(GLint);
76
77 if (!noimagedata)
78 {
79 if (is_distrib)
80 {
81 /* Pixels is a zero-terminated filename, followed by the usual image
82 * data if type == GL_TRUE.
83 * Also note that the image data can't have any unusual pixel packing
84 * parameters.
85 */
86 CRASSERT(format == GL_RGB);
87 distrib_buf_len = crStrlen(pixels) + 1 +
88 ((type == GL_TRUE) ? width * height * 3 : 0);
89 packet_length += distrib_buf_len;
90 }
91 else
92 {
93 packet_length += crImageSize(format, type, width, height);
94 }
95 }
96
97 data_ptr = (unsigned char *) crPackAlloc(packet_length);
98 WRITE_DATA(0, GLenum, target);
99 WRITE_DATA(4, GLint, level);
100 WRITE_DATA(8, GLint, internalformat);
101 WRITE_DATA(12, GLsizei, width);
102 WRITE_DATA(16, GLsizei, height);
103 WRITE_DATA(20, GLint, border);
104 WRITE_DATA(24, GLenum, format);
105 WRITE_DATA(28, GLenum, type);
106 WRITE_DATA(32, int, noimagedata);
107 WRITE_DATA(36, GLint, (GLint)(uintptr_t) pixels);
108
109 if (!noimagedata)
110 {
111 if (is_distrib)
112 {
113 crMemcpy((void *) (data_ptr + 40), pixels, distrib_buf_len);
114 }
115 else
116 {
117 crPixelCopy2D(width, height,
118 (void *) (data_ptr + 40), /* dest image addr */
119 format, type, /* dest image format/type */
120 NULL, /* dst packing (use default params) */
121 pixels, /* src image addr */
122 format, type, /* src image format/type */
123 unpackstate); /* src packing */
124 }
125 }
126
127 crHugePacket(CR_TEXIMAGE2D_OPCODE, data_ptr);
128 crPackFree( data_ptr );
129}
130
131#if defined( GL_EXT_texture3D )
132void PACK_APIENTRY
133crPackTexImage3DEXT(GLenum target, GLint level,
134 GLenum internalformat,
135 GLsizei width, GLsizei height, GLsizei depth, GLint border,
136 GLenum format, GLenum type, const GLvoid *pixels,
137 const CRPixelPackState *unpackstate )
138{
139 unsigned char *data_ptr;
140 int packet_length;
141 int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
142 int is_distrib = ( (type == GL_TRUE) || (type == GL_FALSE) ) ;
143 int distrib_buf_len = 0;
144 int tex_size = 0;
145
146 packet_length =
147 sizeof( target ) +
148 sizeof( level ) +
149 sizeof( internalformat ) +
150 sizeof( width ) +
151 sizeof( height ) +
152 sizeof( depth ) +
153 sizeof( border ) +
154 sizeof( format ) +
155 sizeof( type ) +
156 sizeof( int ) + sizeof(GLint);
157
158 if (!noimagedata)
159 {
160 if ( is_distrib )
161 {
162 distrib_buf_len = crStrlen( pixels ) + 1 +
163 ( (type == GL_TRUE) ? width*height*3 : 0 ) ;
164 packet_length += distrib_buf_len ;
165 }
166 else
167 {
168 tex_size = crTextureSize( format, type, width, height, depth );
169 packet_length += tex_size;
170 }
171 }
172
173 data_ptr = (unsigned char *) crPackAlloc( packet_length );
174 WRITE_DATA( 0, GLenum, target );
175 WRITE_DATA( 4, GLint, level );
176 WRITE_DATA( 8, GLint, internalformat );
177 WRITE_DATA( 12, GLsizei, width );
178 WRITE_DATA( 16, GLsizei, height );
179 WRITE_DATA( 20, GLsizei, depth );
180 WRITE_DATA( 24, GLint, border );
181 WRITE_DATA( 28, GLenum, format );
182 WRITE_DATA( 32, GLenum, type );
183 WRITE_DATA( 36, int, noimagedata );
184 WRITE_DATA( 40, GLint, (GLint)(uintptr_t) pixels);
185
186 if (!noimagedata)
187 {
188 if ( is_distrib )
189 {
190 crMemcpy( (void*)(data_ptr + 44), pixels, distrib_buf_len ) ;
191 }
192 else
193 {
194 crPixelCopy3D( width, height, depth,
195 (void *)(data_ptr + 44), format, type, NULL,
196 pixels, format, type, unpackstate );
197 }
198 }
199
200 crHugePacket( CR_TEXIMAGE3DEXT_OPCODE, data_ptr );
201 crPackFree( data_ptr );
202}
203#endif /* GL_EXT_texture3D */
204
205#ifdef CR_OPENGL_VERSION_1_2
206void PACK_APIENTRY
207crPackTexImage3D(GLenum target, GLint level,
208 GLint internalformat,
209 GLsizei width, GLsizei height,
210 GLsizei depth, GLint border,
211 GLenum format, GLenum type,
212 const GLvoid *pixels,
213 const CRPixelPackState *unpackstate )
214{
215 unsigned char *data_ptr;
216 int packet_length;
217 int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
218 int is_distrib = ( (type == GL_TRUE) || (type == GL_FALSE) ) ;
219 int distrib_buf_len = 0;
220 int tex_size = 0;
221
222 packet_length =
223 sizeof( target ) +
224 sizeof( level ) +
225 sizeof( internalformat ) +
226 sizeof( width ) +
227 sizeof( height ) +
228 sizeof( depth ) +
229 sizeof( border ) +
230 sizeof( format ) +
231 sizeof( type ) +
232 sizeof( int ) + sizeof(GLint);
233
234 if (!noimagedata)
235 {
236 if ( is_distrib )
237 {
238 distrib_buf_len = crStrlen( pixels ) + 1 +
239 ( (type == GL_TRUE) ? width*height*3 : 0 ) ;
240 packet_length += distrib_buf_len ;
241 }
242 else
243 {
244 tex_size = crTextureSize( format, type, width, height, depth );
245 packet_length += tex_size;
246 }
247 }
248
249 data_ptr = (unsigned char *) crPackAlloc( packet_length );
250 WRITE_DATA( 0, GLenum, target );
251 WRITE_DATA( 4, GLint, level );
252 WRITE_DATA( 8, GLint, internalformat );
253 WRITE_DATA( 12, GLsizei, width );
254 WRITE_DATA( 16, GLsizei, height );
255 WRITE_DATA( 20, GLsizei, depth );
256 WRITE_DATA( 24, GLint, border );
257 WRITE_DATA( 28, GLenum, format );
258 WRITE_DATA( 32, GLenum, type );
259 WRITE_DATA( 36, int, noimagedata );
260 WRITE_DATA( 40, GLint, (GLint)(uintptr_t) pixels);
261
262 if (!noimagedata)
263 {
264 if ( is_distrib )
265 {
266 crMemcpy( (void*)(data_ptr + 44), pixels, distrib_buf_len ) ;
267 }
268 else
269 {
270 crPixelCopy3D( width, height, depth,
271 (void *)(data_ptr + 44), format, type, NULL,
272 pixels, format, type, unpackstate );
273 }
274 }
275
276 crHugePacket( CR_TEXIMAGE3D_OPCODE, data_ptr );
277 crPackFree( data_ptr );
278}
279#endif /* CR_OPENGL_VERSION_1_2 */
280
281
282void PACK_APIENTRY
283crPackDeleteTextures(GLsizei n, const GLuint * textures)
284{
285 unsigned char *data_ptr;
286 int packet_length =
287 sizeof( n ) +
288 n * sizeof( *textures );
289
290 data_ptr = (unsigned char *) crPackAlloc(packet_length);
291 WRITE_DATA(0, GLsizei, n);
292 crMemcpy(data_ptr + 4, textures, n * sizeof(*textures));
293 crHugePacket(CR_DELETETEXTURES_OPCODE, data_ptr);
294 crPackFree( data_ptr );
295}
296
297static void
298__handleTexEnvData(GLenum target, GLenum pname, const GLfloat * params)
299{
300 GET_PACKER_CONTEXT(pc);
301 unsigned char *data_ptr;
302 int params_length;
303
304 int packet_length =
305 sizeof( int ) +
306 sizeof( target ) +
307 sizeof( pname );
308
309 if (pname == GL_TEXTURE_ENV_COLOR)
310 {
311 params_length = 4 * sizeof(*params);
312 }
313 else
314 {
315 params_length = sizeof(*params);
316 }
317
318 packet_length += params_length;
319
320 GET_BUFFERED_POINTER(pc, packet_length);
321 WRITE_DATA(0, int, packet_length);
322 WRITE_DATA(sizeof(int) + 0, GLenum, target);
323 WRITE_DATA(sizeof(int) + 4, GLenum, pname);
324 crMemcpy(data_ptr + sizeof(int) + 8, params, params_length);
325}
326
327
328void PACK_APIENTRY
329crPackTexEnvfv(GLenum target, GLenum pname, const GLfloat * params)
330{
331 GET_PACKER_CONTEXT(pc);
332 __handleTexEnvData(target, pname, params);
333 WRITE_OPCODE(pc, CR_TEXENVFV_OPCODE);
334}
335
336void PACK_APIENTRY
337crPackTexEnviv(GLenum target, GLenum pname, const GLint * params)
338{
339 /* floats and ints are the same size, so the packing should be the same */
340 GET_PACKER_CONTEXT(pc);
341 __handleTexEnvData(target, pname, (const GLfloat *) params);
342 WRITE_OPCODE(pc, CR_TEXENVIV_OPCODE);
343}
344
345void PACK_APIENTRY
346crPackTexEnvf(GLenum target, GLenum pname, GLfloat param)
347{
348 crPackTexEnvfv(target, pname, &param);
349}
350
351void PACK_APIENTRY
352crPackTexEnvi(GLenum target, GLenum pname, GLint param)
353{
354 crPackTexEnviv(target, pname, &param);
355}
356
357void PACK_APIENTRY
358crPackPrioritizeTextures(GLsizei n, const GLuint * textures,
359 const GLclampf * priorities)
360{
361 unsigned char *data_ptr;
362 int packet_length =
363 sizeof(n) +
364 n * sizeof(*textures) +
365 n * sizeof(*priorities);
366
367 data_ptr = (unsigned char *) crPackAlloc(packet_length);
368
369 WRITE_DATA(0, GLsizei, n);
370 crMemcpy(data_ptr + 4, textures, n * sizeof(*textures));
371 crMemcpy(data_ptr + 4 + n * sizeof(*textures),
372 priorities, n * sizeof(*priorities));
373
374 crHugePacket(CR_PRIORITIZETEXTURES_OPCODE, data_ptr);
375 crPackFree( data_ptr );
376}
377
378static void
379__handleTexGenData(GLenum coord, GLenum pname,
380 int sizeof_param, const GLvoid * params)
381{
382 GET_PACKER_CONTEXT(pc);
383 unsigned char *data_ptr;
384 int packet_length =
385 sizeof(int) + sizeof(coord) + sizeof(pname) + sizeof_param;
386 int params_length = sizeof_param;
387 if (pname == GL_OBJECT_PLANE || pname == GL_EYE_PLANE)
388 {
389 packet_length += 3 * sizeof_param;
390 params_length += 3 * sizeof_param;
391 }
392
393 GET_BUFFERED_POINTER(pc, packet_length);
394 WRITE_DATA(0, int, packet_length);
395 WRITE_DATA(sizeof(int) + 0, GLenum, coord);
396 WRITE_DATA(sizeof(int) + 4, GLenum, pname);
397 crMemcpy(data_ptr + sizeof(int) + 8, params, params_length);
398}
399
400void PACK_APIENTRY
401crPackTexGendv(GLenum coord, GLenum pname, const GLdouble * params)
402{
403 GET_PACKER_CONTEXT(pc);
404 __handleTexGenData(coord, pname, sizeof(*params), params);
405 WRITE_OPCODE(pc, CR_TEXGENDV_OPCODE);
406}
407
408void PACK_APIENTRY
409crPackTexGenfv(GLenum coord, GLenum pname, const GLfloat * params)
410{
411 GET_PACKER_CONTEXT(pc);
412 __handleTexGenData(coord, pname, sizeof(*params), params);
413 WRITE_OPCODE(pc, CR_TEXGENFV_OPCODE);
414}
415
416void PACK_APIENTRY
417crPackTexGeniv(GLenum coord, GLenum pname, const GLint * params)
418{
419 GET_PACKER_CONTEXT(pc);
420 __handleTexGenData(coord, pname, sizeof(*params), params);
421 WRITE_OPCODE(pc, CR_TEXGENIV_OPCODE);
422}
423
424void PACK_APIENTRY
425crPackTexGend(GLenum coord, GLenum pname, GLdouble param)
426{
427 crPackTexGendv(coord, pname, &param);
428}
429
430void PACK_APIENTRY
431crPackTexGenf(GLenum coord, GLenum pname, GLfloat param)
432{
433 crPackTexGenfv(coord, pname, &param);
434}
435
436void PACK_APIENTRY
437crPackTexGeni(GLenum coord, GLenum pname, GLint param)
438{
439 crPackTexGeniv(coord, pname, &param);
440}
441
442static GLboolean
443__handleTexParameterData(GLenum target, GLenum pname, const GLfloat * params)
444{
445 GET_PACKER_CONTEXT(pc);
446 unsigned char *data_ptr;
447 int packet_length = sizeof(int) + sizeof(target) + sizeof(pname);
448 int num_params = 0;
449
450 switch (pname)
451 {
452 case GL_TEXTURE_MIN_FILTER:
453 case GL_TEXTURE_MAG_FILTER:
454 case GL_TEXTURE_WRAP_R:
455 case GL_TEXTURE_WRAP_S:
456 case GL_TEXTURE_WRAP_T:
457#ifdef GL_TEXTURE_PRIORITY
458 case GL_TEXTURE_PRIORITY:
459#endif
460 num_params = 1;
461 break;
462 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
463 num_params = 1;
464 break;
465 case GL_TEXTURE_MIN_LOD:
466 case GL_TEXTURE_MAX_LOD:
467 case GL_TEXTURE_BASE_LEVEL:
468 case GL_TEXTURE_MAX_LEVEL:
469 num_params = 1;
470 break;
471 case GL_TEXTURE_BORDER_COLOR:
472 num_params = 4;
473 break;
474#ifdef CR_ARB_shadow
475 case GL_TEXTURE_COMPARE_MODE_ARB:
476 case GL_TEXTURE_COMPARE_FUNC_ARB:
477 num_params = 1;
478 break;
479#endif
480#ifdef CR_ARB_shadow_ambient
481 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
482 num_params = 1;
483 break;
484#endif
485#ifdef CR_ARB_depth_texture
486 case GL_DEPTH_TEXTURE_MODE_ARB:
487 num_params = 1;
488 break;
489#endif
490#ifdef CR_SGIS_generate_mipmap
491 case GL_GENERATE_MIPMAP_SGIS:
492 num_params = 1;
493 break;
494#endif
495 default:
496 num_params = __packTexParameterNumParams(pname);
497 if (!num_params)
498 {
499 __PackError(__LINE__, __FILE__, GL_INVALID_ENUM,
500 "crPackTexParameter(bad pname)");
501 return GL_FALSE;
502 }
503 }
504 packet_length += num_params * sizeof(*params);
505
506 GET_BUFFERED_POINTER(pc, packet_length);
507 WRITE_DATA(0, int, packet_length);
508 WRITE_DATA(sizeof(int) + 0, GLenum, target);
509 WRITE_DATA(sizeof(int) + 4, GLenum, pname);
510 crMemcpy(data_ptr + sizeof(int) + 8, params, num_params * sizeof(*params));
511 return GL_TRUE;
512}
513
514void PACK_APIENTRY
515crPackTexParameterfv(GLenum target, GLenum pname, const GLfloat * params)
516{
517 GET_PACKER_CONTEXT(pc);
518 if (__handleTexParameterData(target, pname, params))
519 WRITE_OPCODE(pc, CR_TEXPARAMETERFV_OPCODE);
520}
521
522void PACK_APIENTRY
523crPackTexParameteriv(GLenum target, GLenum pname, const GLint * params)
524{
525 GET_PACKER_CONTEXT(pc);
526 if (__handleTexParameterData(target, pname, (GLfloat *) params))
527 WRITE_OPCODE(pc, CR_TEXPARAMETERIV_OPCODE);
528}
529
530void PACK_APIENTRY
531crPackTexParameterf(GLenum target, GLenum pname, GLfloat param)
532{
533 crPackTexParameterfv(target, pname, &param);
534}
535
536void PACK_APIENTRY
537crPackTexParameteri(GLenum target, GLenum pname, GLint param)
538{
539 crPackTexParameteriv(target, pname, &param);
540}
541
542#ifdef CR_OPENGL_VERSION_1_2
543void PACK_APIENTRY
544crPackTexSubImage3D(GLenum target, GLint level,
545 GLint xoffset, GLint yoffset, GLint zoffset,
546 GLsizei width, GLsizei height, GLsizei depth,
547 GLenum format, GLenum type, const GLvoid * pixels,
548 const CRPixelPackState * unpackstate)
549{
550 unsigned char *data_ptr;
551 int packet_length;
552 int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
553
554 packet_length =
555 sizeof(target) +
556 sizeof(level) +
557 sizeof(xoffset) +
558 sizeof(yoffset) +
559 sizeof(zoffset) +
560 sizeof(width) +
561 sizeof(height) +
562 sizeof(depth) +
563 sizeof(format) +
564 sizeof(type) + sizeof(int) + sizeof(GLint);
565
566 if (!noimagedata)
567 {
568 packet_length += crTextureSize(format, type, width, height, depth);
569 }
570
571 data_ptr = (unsigned char *) crPackAlloc(packet_length);
572 WRITE_DATA(0, GLenum, target);
573 WRITE_DATA(4, GLint, level);
574 WRITE_DATA(8, GLint, xoffset);
575 WRITE_DATA(12, GLint, yoffset);
576 WRITE_DATA(16, GLint, zoffset);
577 WRITE_DATA(20, GLsizei, width);
578 WRITE_DATA(24, GLsizei, height);
579 WRITE_DATA(28, GLsizei, depth);
580 WRITE_DATA(32, GLenum, format);
581 WRITE_DATA(36, GLenum, type);
582 WRITE_DATA(40, GLint, noimagedata);
583 WRITE_DATA(44, GLint, (GLint)(uintptr_t) pixels);
584
585 if (!noimagedata)
586 {
587 crPixelCopy3D(width, height, depth, (GLvoid *) (data_ptr + 48), format, type, NULL, /* dst */
588 pixels, format, type, unpackstate); /* src */
589 }
590
591 crHugePacket(CR_TEXSUBIMAGE3D_OPCODE, data_ptr);
592 crPackFree( data_ptr );
593}
594#endif /* CR_OPENGL_VERSION_1_2 */
595
596void PACK_APIENTRY
597crPackTexSubImage2D(GLenum target, GLint level,
598 GLint xoffset, GLint yoffset, GLsizei width,
599 GLsizei height, GLenum format, GLenum type,
600 const GLvoid * pixels,
601 const CRPixelPackState * unpackstate)
602{
603 unsigned char *data_ptr;
604 int packet_length;
605 int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
606
607 packet_length =
608 sizeof(target) +
609 sizeof(level) +
610 sizeof(xoffset) +
611 sizeof(yoffset) +
612 sizeof(width) +
613 sizeof(height) +
614 sizeof(format) + sizeof(type) + sizeof(int) + sizeof(GLint);
615
616 if (!noimagedata)
617 {
618 packet_length += crImageSize(format, type, width, height);
619 }
620
621 data_ptr = (unsigned char *) crPackAlloc(packet_length);
622 WRITE_DATA(0, GLenum, target);
623 WRITE_DATA(4, GLint, level);
624 WRITE_DATA(8, GLint, xoffset);
625 WRITE_DATA(12, GLint, yoffset);
626 WRITE_DATA(16, GLsizei, width);
627 WRITE_DATA(20, GLsizei, height);
628 WRITE_DATA(24, GLenum, format);
629 WRITE_DATA(28, GLenum, type);
630 WRITE_DATA(32, GLint, noimagedata);
631 WRITE_DATA(36, GLint, (GLint)(uintptr_t) pixels);
632
633 if (!noimagedata)
634 {
635 crPixelCopy2D(width, height, (GLvoid *) (data_ptr + 40), format, type, NULL, /* dst */
636 pixels, format, type, unpackstate); /* src */
637 }
638
639 crHugePacket(CR_TEXSUBIMAGE2D_OPCODE, data_ptr);
640 crPackFree( data_ptr );
641}
642
643void PACK_APIENTRY
644crPackTexSubImage1D(GLenum target, GLint level,
645 GLint xoffset, GLsizei width, GLenum format, GLenum type,
646 const GLvoid * pixels,
647 const CRPixelPackState * unpackstate)
648{
649 unsigned char *data_ptr;
650 int packet_length;
651 int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
652
653 packet_length =
654 sizeof(target) +
655 sizeof(level) +
656 sizeof(xoffset) +
657 sizeof(width) +
658 sizeof(format) + sizeof(type) + sizeof(int) + sizeof(GLint);
659
660 if (!noimagedata)
661 {
662 packet_length += crImageSize(format, type, width, 1);
663 }
664
665 data_ptr = (unsigned char *) crPackAlloc(packet_length);
666 WRITE_DATA(0, GLenum, target);
667 WRITE_DATA(4, GLint, level);
668 WRITE_DATA(8, GLint, xoffset);
669 WRITE_DATA(12, GLsizei, width);
670 WRITE_DATA(16, GLenum, format);
671 WRITE_DATA(20, GLenum, type);
672 WRITE_DATA(24, GLint, noimagedata);
673 WRITE_DATA(28, GLint, (GLint)(uintptr_t) pixels);
674
675 if (!noimagedata)
676 {
677 crPixelCopy1D((GLvoid *) (data_ptr + 32), format, type,
678 pixels, format, type, width, unpackstate);
679 }
680
681 crHugePacket(CR_TEXSUBIMAGE1D_OPCODE, data_ptr);
682 crPackFree( data_ptr );
683}
684
685void PACK_APIENTRY
686crPackAreTexturesResident(GLsizei n, const GLuint * textures,
687 GLboolean * residences, GLboolean * return_val,
688 int *writeback)
689{
690 GET_PACKER_CONTEXT(pc);
691 unsigned char *data_ptr;
692 int packet_length;
693
694 (void) return_val; /* Caller must compute this from residences!!! */
695
696 packet_length = sizeof(int) + /* packet length */
697 sizeof(GLenum) + /* extend-o opcode */
698 sizeof(n) + /* num_textures */
699 n * sizeof(*textures) + /* textures */
700 8 + 8;
701
702 GET_BUFFERED_POINTER(pc, packet_length);
703 WRITE_DATA(0, int, packet_length);
704 WRITE_DATA(4, GLenum, CR_ARETEXTURESRESIDENT_EXTEND_OPCODE);
705 WRITE_DATA(8, GLsizei, n);
706 crMemcpy(data_ptr + 12, textures, n * sizeof(*textures));
707 WRITE_NETWORK_POINTER(12 + n * sizeof(*textures), (void *) residences);
708 WRITE_NETWORK_POINTER(20 + n * sizeof(*textures), (void *) writeback);
709 WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
710}
711
712
713/**********************************************************************
714 * Texture compression
715 */
716
717void PACK_APIENTRY crPackCompressedTexImage1DARB( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imagesize, const GLvoid *data )
718{
719 unsigned char *data_ptr;
720 int packet_length;
721 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
722
723 /* All extended opcodes have their first 8 bytes predefined:
724 * the first four indicate the packet size, and the next four
725 * indicate the actual extended opcode.
726 */
727 packet_length =
728 sizeof( GLenum) + /* extended opcode */
729 sizeof( target ) +
730 sizeof( level ) +
731 sizeof( internalformat ) +
732 sizeof( width ) +
733 sizeof( border ) +
734 sizeof( imagesize ) +
735 sizeof( int ) + sizeof(GLint);
736
737 if (!noimagedata)
738 {
739 packet_length += imagesize;
740 }
741
742
743 data_ptr = (unsigned char *) crPackAlloc( packet_length );
744 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXIMAGE1DARB_EXTEND_OPCODE );
745 WRITE_DATA( 4, GLenum, target );
746 WRITE_DATA( 8, GLint, level );
747 WRITE_DATA( 12, GLint, internalformat );
748 WRITE_DATA( 16, GLsizei, width );
749 WRITE_DATA( 20, GLint, border );
750 WRITE_DATA( 24, GLsizei, imagesize );
751 WRITE_DATA( 28, int, noimagedata );
752 WRITE_DATA( 32, GLint, (GLint)(uintptr_t) data);
753
754 if (!noimagedata) {
755 crMemcpy( (void *)(data_ptr + 36), (void *)data, imagesize);
756 }
757
758 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
759 crPackFree( data_ptr );
760}
761
762void PACK_APIENTRY crPackCompressedTexImage2DARB( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imagesize, const GLvoid *data )
763{
764 unsigned char *data_ptr;
765 int packet_length;
766 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
767
768 /* All extended opcodes have their first 8 bytes predefined:
769 * the first four indicate the packet size, and the next four
770 * indicate the actual extended opcode.
771 */
772 packet_length =
773 sizeof( GLenum) + /* extended opcode */
774 sizeof( target ) +
775 sizeof( level ) +
776 sizeof( internalformat ) +
777 sizeof( width ) +
778 sizeof( height ) +
779 sizeof( border ) +
780 sizeof( imagesize ) +
781 sizeof( int ) + sizeof(GLint);
782
783 if (!noimagedata)
784 {
785 packet_length += imagesize;
786 }
787
788 //crDebug( "Compressing that shit: %d", level );
789
790 data_ptr = (unsigned char *) crPackAlloc( packet_length );
791 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXIMAGE2DARB_EXTEND_OPCODE );
792 WRITE_DATA( 4, GLenum, target );
793 WRITE_DATA( 8, GLint, level );
794 WRITE_DATA( 12, GLint, internalformat );
795 WRITE_DATA( 16, GLsizei, width );
796 WRITE_DATA( 20, GLsizei, height );
797 WRITE_DATA( 24, GLint, border );
798 WRITE_DATA( 28, GLsizei, imagesize );
799 WRITE_DATA( 32, int, noimagedata );
800 WRITE_DATA( 36, GLint, (GLint)(uintptr_t) data);
801
802 if (!noimagedata) {
803 crMemcpy( (void *)(data_ptr + 40), (void *)data, imagesize);
804 }
805
806 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
807 crPackFree( data_ptr );
808}
809
810void PACK_APIENTRY crPackCompressedTexImage3DARB( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imagesize, const GLvoid *data )
811{
812 unsigned char *data_ptr;
813 int packet_length;
814 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
815
816 /* All extended opcodes have their first 8 bytes predefined:
817 * the first four indicate the packet size, and the next four
818 * indicate the actual extended opcode.
819 */
820 packet_length =
821 sizeof( GLenum) + /* extended opcode */
822 sizeof( target ) +
823 sizeof( level ) +
824 sizeof( internalformat ) +
825 sizeof( width ) +
826 sizeof( height ) +
827 sizeof( depth ) +
828 sizeof( border ) +
829 sizeof( imagesize ) +
830 sizeof( int ) + sizeof(GLint);
831
832 if (!noimagedata)
833 {
834 packet_length += imagesize;
835 }
836
837 data_ptr = (unsigned char *) crPackAlloc( packet_length );
838 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXIMAGE3DARB_EXTEND_OPCODE );
839 WRITE_DATA( 4, GLenum, target );
840 WRITE_DATA( 8, GLint, level );
841 WRITE_DATA( 12, GLint, internalformat );
842 WRITE_DATA( 16, GLsizei, width );
843 WRITE_DATA( 20, GLsizei, height );
844 WRITE_DATA( 24, GLsizei, depth );
845 WRITE_DATA( 28, GLint, border );
846 WRITE_DATA( 32, GLsizei, imagesize );
847 WRITE_DATA( 36, int, noimagedata );
848 WRITE_DATA( 40, GLint, (GLint)(uintptr_t) data);
849
850 if (!noimagedata) {
851 crMemcpy( (void *)(data_ptr + 44), (void *)data, imagesize);
852 }
853
854 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
855 crPackFree( data_ptr );
856}
857
858void PACK_APIENTRY crPackCompressedTexSubImage1DARB( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imagesize, const GLvoid *data )
859{
860 unsigned char *data_ptr;
861 int packet_length;
862 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
863
864 /* All extended opcodes have their first 8 bytes predefined:
865 * the first four indicate the packet size, and the next four
866 * indicate the actual extended opcode.
867 */
868 packet_length =
869 sizeof( GLenum) + /* extended opcode */
870 sizeof( target ) +
871 sizeof( level ) +
872 sizeof( xoffset ) +
873 sizeof( width ) +
874 sizeof( format ) +
875 sizeof( imagesize ) +
876 sizeof( int ) + sizeof(GLint);
877
878 if (!noimagedata)
879 {
880 packet_length += imagesize;
881 }
882
883 data_ptr = (unsigned char *) crPackAlloc( packet_length );
884 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXSUBIMAGE1DARB_EXTEND_OPCODE );
885 WRITE_DATA( 4, GLenum, target );
886 WRITE_DATA( 8, GLint, level );
887 WRITE_DATA( 12, GLint, xoffset );
888 WRITE_DATA( 16, GLsizei, width );
889 WRITE_DATA( 20, GLenum, format );
890 WRITE_DATA( 24, GLsizei, imagesize );
891 WRITE_DATA( 28, int, noimagedata );
892 WRITE_DATA( 32, GLint, (GLint)(uintptr_t) data);
893
894 if (!noimagedata) {
895 crMemcpy( (void *)(data_ptr + 36), (void *)data, imagesize);
896 }
897
898 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
899 crPackFree( data_ptr );
900}
901
902void PACK_APIENTRY crPackCompressedTexSubImage2DARB( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imagesize, const GLvoid *data )
903{
904 unsigned char *data_ptr;
905 int packet_length;
906 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
907
908 /* All extended opcodes have their first 8 bytes predefined:
909 * the first four indicate the packet size, and the next four
910 * indicate the actual extended opcode.
911 */
912 packet_length =
913 sizeof( GLenum) + /* extended opcode */
914 sizeof( target ) +
915 sizeof( level ) +
916 sizeof( xoffset ) +
917 sizeof( yoffset ) +
918 sizeof( width ) +
919 sizeof( height ) +
920 sizeof( format ) +
921 sizeof( imagesize ) +
922 sizeof( int ) + sizeof(GLint);
923
924 if (!noimagedata)
925 {
926 packet_length += imagesize;
927 }
928
929 data_ptr = (unsigned char *) crPackAlloc( packet_length );
930 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXSUBIMAGE2DARB_EXTEND_OPCODE );
931 WRITE_DATA( 4, GLenum, target );
932 WRITE_DATA( 8, GLint, level );
933 WRITE_DATA( 12, GLint, xoffset );
934 WRITE_DATA( 16, GLint, yoffset );
935 WRITE_DATA( 20, GLsizei, width );
936 WRITE_DATA( 24, GLsizei, height );
937 WRITE_DATA( 28, GLenum, format );
938 WRITE_DATA( 32, GLsizei, imagesize );
939 WRITE_DATA( 36, int, noimagedata );
940 WRITE_DATA( 40, GLint, (GLint)(uintptr_t) data);
941
942 if (!noimagedata) {
943 crMemcpy( (void *)(data_ptr + 44), (void *)data, imagesize);
944 }
945
946 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
947 crPackFree( data_ptr );
948}
949
950void PACK_APIENTRY crPackCompressedTexSubImage3DARB( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imagesize, const GLvoid *data )
951{
952 unsigned char *data_ptr;
953 int packet_length;
954 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
955
956 /* All extended opcodes have their first 8 bytes predefined:
957 * the first four indicate the packet size, and the next four
958 * indicate the actual extended opcode.
959 */
960 packet_length =
961 sizeof( GLenum) + /* extended opcode */
962 sizeof( target ) +
963 sizeof( level ) +
964 sizeof( xoffset ) +
965 sizeof( yoffset ) +
966 sizeof( zoffset ) +
967 sizeof( width ) +
968 sizeof( height ) +
969 sizeof( depth ) +
970 sizeof( format ) +
971 sizeof( imagesize ) +
972 sizeof( int ) + sizeof(GLint);
973
974 if (!noimagedata)
975 {
976 packet_length += imagesize;
977 }
978
979 data_ptr = (unsigned char *) crPackAlloc( packet_length );
980 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXSUBIMAGE3DARB_EXTEND_OPCODE );
981 WRITE_DATA( 4, GLenum, target );
982 WRITE_DATA( 8, GLint, level );
983 WRITE_DATA( 12, GLint, xoffset );
984 WRITE_DATA( 16, GLint, yoffset );
985 WRITE_DATA( 20, GLint, zoffset );
986 WRITE_DATA( 24, GLsizei, width );
987 WRITE_DATA( 28, GLsizei, height );
988 WRITE_DATA( 32, GLsizei, depth );
989 WRITE_DATA( 36, GLenum, format );
990 WRITE_DATA( 40, GLsizei, imagesize );
991 WRITE_DATA( 44, int, noimagedata );
992 WRITE_DATA( 48, GLint, (GLint)(uintptr_t) data);
993
994 if (!noimagedata) {
995 crMemcpy( (void *)(data_ptr + 52), (void *)data, imagesize);
996 }
997
998 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
999 crPackFree( data_ptr );
1000}
1001
1002void PACK_APIENTRY crPackGetCompressedTexImageARB( GLenum target, GLint level, GLvoid *img, int *writeback )
1003{
1004 GET_PACKER_CONTEXT(pc);
1005 int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(target)+sizeof(level)+2*8;
1006 unsigned char *data_ptr;
1007 GET_BUFFERED_POINTER( pc, packet_length );
1008
1009 WRITE_DATA_AI(int, packet_length);
1010 WRITE_DATA_AI(GLenum, CR_GETCOMPRESSEDTEXIMAGEARB_EXTEND_OPCODE);
1011 WRITE_DATA_AI(GLenum, target);
1012 WRITE_DATA_AI(GLint, level);
1013 WRITE_NETWORK_POINTER(0, (void *) img );
1014 WRITE_NETWORK_POINTER(8, (void *) writeback );
1015 WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
1016}
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