VirtualBox

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

Last change on this file since 37216 was 35919, checked in by vboxsync, 14 years ago

crOpenGL: fix deadlock for apps passing invalid args to TexParameter[fi]v

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 31.7 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 CR_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 CR_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 CR_GET_PACKER_CONTEXT(pc);
332 __handleTexEnvData(target, pname, params);
333 WRITE_OPCODE(pc, CR_TEXENVFV_OPCODE);
334 CR_UNLOCK_PACKER_CONTEXT(pc);
335}
336
337void PACK_APIENTRY
338crPackTexEnviv(GLenum target, GLenum pname, const GLint * params)
339{
340 /* floats and ints are the same size, so the packing should be the same */
341 CR_GET_PACKER_CONTEXT(pc);
342 __handleTexEnvData(target, pname, (const GLfloat *) params);
343 WRITE_OPCODE(pc, CR_TEXENVIV_OPCODE);
344 CR_UNLOCK_PACKER_CONTEXT(pc);
345}
346
347void PACK_APIENTRY
348crPackTexEnvf(GLenum target, GLenum pname, GLfloat param)
349{
350 crPackTexEnvfv(target, pname, &param);
351}
352
353void PACK_APIENTRY
354crPackTexEnvi(GLenum target, GLenum pname, GLint param)
355{
356 crPackTexEnviv(target, pname, &param);
357}
358
359void PACK_APIENTRY
360crPackPrioritizeTextures(GLsizei n, const GLuint * textures,
361 const GLclampf * priorities)
362{
363 unsigned char *data_ptr;
364 int packet_length =
365 sizeof(n) +
366 n * sizeof(*textures) +
367 n * sizeof(*priorities);
368
369 data_ptr = (unsigned char *) crPackAlloc(packet_length);
370
371 WRITE_DATA(0, GLsizei, n);
372 crMemcpy(data_ptr + 4, textures, n * sizeof(*textures));
373 crMemcpy(data_ptr + 4 + n * sizeof(*textures),
374 priorities, n * sizeof(*priorities));
375
376 crHugePacket(CR_PRIORITIZETEXTURES_OPCODE, data_ptr);
377 crPackFree( data_ptr );
378}
379
380static void
381__handleTexGenData(GLenum coord, GLenum pname,
382 int sizeof_param, const GLvoid * params)
383{
384 CR_GET_PACKER_CONTEXT(pc);
385 unsigned char *data_ptr;
386 int packet_length =
387 sizeof(int) + sizeof(coord) + sizeof(pname) + sizeof_param;
388 int params_length = sizeof_param;
389 if (pname == GL_OBJECT_PLANE || pname == GL_EYE_PLANE)
390 {
391 packet_length += 3 * sizeof_param;
392 params_length += 3 * sizeof_param;
393 }
394
395 CR_GET_BUFFERED_POINTER(pc, packet_length);
396 WRITE_DATA(0, int, packet_length);
397 WRITE_DATA(sizeof(int) + 0, GLenum, coord);
398 WRITE_DATA(sizeof(int) + 4, GLenum, pname);
399 crMemcpy(data_ptr + sizeof(int) + 8, params, params_length);
400}
401
402void PACK_APIENTRY
403crPackTexGendv(GLenum coord, GLenum pname, const GLdouble * params)
404{
405 CR_GET_PACKER_CONTEXT(pc);
406 __handleTexGenData(coord, pname, sizeof(*params), params);
407 WRITE_OPCODE(pc, CR_TEXGENDV_OPCODE);
408 CR_UNLOCK_PACKER_CONTEXT(pc);
409}
410
411void PACK_APIENTRY
412crPackTexGenfv(GLenum coord, GLenum pname, const GLfloat * params)
413{
414 CR_GET_PACKER_CONTEXT(pc);
415 __handleTexGenData(coord, pname, sizeof(*params), params);
416 WRITE_OPCODE(pc, CR_TEXGENFV_OPCODE);
417 CR_UNLOCK_PACKER_CONTEXT(pc);
418}
419
420void PACK_APIENTRY
421crPackTexGeniv(GLenum coord, GLenum pname, const GLint * params)
422{
423 CR_GET_PACKER_CONTEXT(pc);
424 __handleTexGenData(coord, pname, sizeof(*params), params);
425 WRITE_OPCODE(pc, CR_TEXGENIV_OPCODE);
426 CR_UNLOCK_PACKER_CONTEXT(pc);
427}
428
429void PACK_APIENTRY
430crPackTexGend(GLenum coord, GLenum pname, GLdouble param)
431{
432 crPackTexGendv(coord, pname, &param);
433}
434
435void PACK_APIENTRY
436crPackTexGenf(GLenum coord, GLenum pname, GLfloat param)
437{
438 crPackTexGenfv(coord, pname, &param);
439}
440
441void PACK_APIENTRY
442crPackTexGeni(GLenum coord, GLenum pname, GLint param)
443{
444 crPackTexGeniv(coord, pname, &param);
445}
446
447static GLboolean
448__handleTexParameterData(GLenum target, GLenum pname, const GLfloat * params)
449{
450 CR_GET_PACKER_CONTEXT(pc);
451 unsigned char *data_ptr;
452 int packet_length = sizeof(int) + sizeof(target) + sizeof(pname);
453 int num_params = 0;
454
455 switch (pname)
456 {
457 case GL_TEXTURE_MIN_FILTER:
458 case GL_TEXTURE_MAG_FILTER:
459 case GL_TEXTURE_WRAP_R:
460 case GL_TEXTURE_WRAP_S:
461 case GL_TEXTURE_WRAP_T:
462#ifdef GL_TEXTURE_PRIORITY
463 case GL_TEXTURE_PRIORITY:
464#endif
465 num_params = 1;
466 break;
467 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
468 num_params = 1;
469 break;
470 case GL_TEXTURE_MIN_LOD:
471 case GL_TEXTURE_MAX_LOD:
472 case GL_TEXTURE_BASE_LEVEL:
473 case GL_TEXTURE_MAX_LEVEL:
474 num_params = 1;
475 break;
476 case GL_TEXTURE_BORDER_COLOR:
477 num_params = 4;
478 break;
479#ifdef CR_ARB_shadow
480 case GL_TEXTURE_COMPARE_MODE_ARB:
481 case GL_TEXTURE_COMPARE_FUNC_ARB:
482 num_params = 1;
483 break;
484#endif
485#ifdef CR_ARB_shadow_ambient
486 case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
487 num_params = 1;
488 break;
489#endif
490#ifdef CR_ARB_depth_texture
491 case GL_DEPTH_TEXTURE_MODE_ARB:
492 num_params = 1;
493 break;
494#endif
495#ifdef CR_SGIS_generate_mipmap
496 case GL_GENERATE_MIPMAP_SGIS:
497 num_params = 1;
498 break;
499#endif
500 default:
501 num_params = __packTexParameterNumParams(pname);
502 if (!num_params)
503 {
504 __PackError(__LINE__, __FILE__, GL_INVALID_ENUM,
505 "crPackTexParameter(bad pname)");
506 return GL_FALSE;
507 }
508 }
509 packet_length += num_params * sizeof(*params);
510
511 CR_GET_BUFFERED_POINTER(pc, packet_length);
512 WRITE_DATA(0, int, packet_length);
513 WRITE_DATA(sizeof(int) + 0, GLenum, target);
514 WRITE_DATA(sizeof(int) + 4, GLenum, pname);
515 crMemcpy(data_ptr + sizeof(int) + 8, params, num_params * sizeof(*params));
516 return GL_TRUE;
517}
518
519void PACK_APIENTRY
520crPackTexParameterfv(GLenum target, GLenum pname, const GLfloat * params)
521{
522 CR_GET_PACKER_CONTEXT(pc);
523 if (__handleTexParameterData(target, pname, params))
524 {
525 WRITE_OPCODE(pc, CR_TEXPARAMETERFV_OPCODE);
526 CR_UNLOCK_PACKER_CONTEXT(pc);
527 }
528}
529
530void PACK_APIENTRY
531crPackTexParameteriv(GLenum target, GLenum pname, const GLint * params)
532{
533 CR_GET_PACKER_CONTEXT(pc);
534 if (__handleTexParameterData(target, pname, (GLfloat *) params))
535 {
536 WRITE_OPCODE(pc, CR_TEXPARAMETERIV_OPCODE);
537 CR_UNLOCK_PACKER_CONTEXT(pc);
538 }
539}
540
541void PACK_APIENTRY
542crPackTexParameterf(GLenum target, GLenum pname, GLfloat param)
543{
544 crPackTexParameterfv(target, pname, &param);
545}
546
547void PACK_APIENTRY
548crPackTexParameteri(GLenum target, GLenum pname, GLint param)
549{
550 crPackTexParameteriv(target, pname, &param);
551}
552
553#ifdef CR_OPENGL_VERSION_1_2
554void PACK_APIENTRY
555crPackTexSubImage3D(GLenum target, GLint level,
556 GLint xoffset, GLint yoffset, GLint zoffset,
557 GLsizei width, GLsizei height, GLsizei depth,
558 GLenum format, GLenum type, const GLvoid * pixels,
559 const CRPixelPackState * unpackstate)
560{
561 unsigned char *data_ptr;
562 int packet_length;
563 int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
564
565 packet_length =
566 sizeof(target) +
567 sizeof(level) +
568 sizeof(xoffset) +
569 sizeof(yoffset) +
570 sizeof(zoffset) +
571 sizeof(width) +
572 sizeof(height) +
573 sizeof(depth) +
574 sizeof(format) +
575 sizeof(type) + sizeof(int) + sizeof(GLint);
576
577 if (!noimagedata)
578 {
579 packet_length += crTextureSize(format, type, width, height, depth);
580 }
581
582 data_ptr = (unsigned char *) crPackAlloc(packet_length);
583 WRITE_DATA(0, GLenum, target);
584 WRITE_DATA(4, GLint, level);
585 WRITE_DATA(8, GLint, xoffset);
586 WRITE_DATA(12, GLint, yoffset);
587 WRITE_DATA(16, GLint, zoffset);
588 WRITE_DATA(20, GLsizei, width);
589 WRITE_DATA(24, GLsizei, height);
590 WRITE_DATA(28, GLsizei, depth);
591 WRITE_DATA(32, GLenum, format);
592 WRITE_DATA(36, GLenum, type);
593 WRITE_DATA(40, GLint, noimagedata);
594 WRITE_DATA(44, GLint, (GLint)(uintptr_t) pixels);
595
596 if (!noimagedata)
597 {
598 crPixelCopy3D(width, height, depth, (GLvoid *) (data_ptr + 48), format, type, NULL, /* dst */
599 pixels, format, type, unpackstate); /* src */
600 }
601
602 crHugePacket(CR_TEXSUBIMAGE3D_OPCODE, data_ptr);
603 crPackFree( data_ptr );
604}
605#endif /* CR_OPENGL_VERSION_1_2 */
606
607void PACK_APIENTRY
608crPackTexSubImage2D(GLenum target, GLint level,
609 GLint xoffset, GLint yoffset, GLsizei width,
610 GLsizei height, GLenum format, GLenum type,
611 const GLvoid * pixels,
612 const CRPixelPackState * unpackstate)
613{
614 unsigned char *data_ptr;
615 int packet_length;
616 int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
617
618 packet_length =
619 sizeof(target) +
620 sizeof(level) +
621 sizeof(xoffset) +
622 sizeof(yoffset) +
623 sizeof(width) +
624 sizeof(height) +
625 sizeof(format) + sizeof(type) + sizeof(int) + sizeof(GLint);
626
627 if (!noimagedata)
628 {
629 packet_length += crImageSize(format, type, width, height);
630 }
631
632 data_ptr = (unsigned char *) crPackAlloc(packet_length);
633 WRITE_DATA(0, GLenum, target);
634 WRITE_DATA(4, GLint, level);
635 WRITE_DATA(8, GLint, xoffset);
636 WRITE_DATA(12, GLint, yoffset);
637 WRITE_DATA(16, GLsizei, width);
638 WRITE_DATA(20, GLsizei, height);
639 WRITE_DATA(24, GLenum, format);
640 WRITE_DATA(28, GLenum, type);
641 WRITE_DATA(32, GLint, noimagedata);
642 WRITE_DATA(36, GLint, (GLint)(uintptr_t) pixels);
643
644 if (!noimagedata)
645 {
646 crPixelCopy2D(width, height, (GLvoid *) (data_ptr + 40), format, type, NULL, /* dst */
647 pixels, format, type, unpackstate); /* src */
648 }
649
650 crHugePacket(CR_TEXSUBIMAGE2D_OPCODE, data_ptr);
651 crPackFree( data_ptr );
652}
653
654void PACK_APIENTRY
655crPackTexSubImage1D(GLenum target, GLint level,
656 GLint xoffset, GLsizei width, GLenum format, GLenum type,
657 const GLvoid * pixels,
658 const CRPixelPackState * unpackstate)
659{
660 unsigned char *data_ptr;
661 int packet_length;
662 int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
663
664 packet_length =
665 sizeof(target) +
666 sizeof(level) +
667 sizeof(xoffset) +
668 sizeof(width) +
669 sizeof(format) + sizeof(type) + sizeof(int) + sizeof(GLint);
670
671 if (!noimagedata)
672 {
673 packet_length += crImageSize(format, type, width, 1);
674 }
675
676 data_ptr = (unsigned char *) crPackAlloc(packet_length);
677 WRITE_DATA(0, GLenum, target);
678 WRITE_DATA(4, GLint, level);
679 WRITE_DATA(8, GLint, xoffset);
680 WRITE_DATA(12, GLsizei, width);
681 WRITE_DATA(16, GLenum, format);
682 WRITE_DATA(20, GLenum, type);
683 WRITE_DATA(24, GLint, noimagedata);
684 WRITE_DATA(28, GLint, (GLint)(uintptr_t) pixels);
685
686 if (!noimagedata)
687 {
688 crPixelCopy1D((GLvoid *) (data_ptr + 32), format, type,
689 pixels, format, type, width, unpackstate);
690 }
691
692 crHugePacket(CR_TEXSUBIMAGE1D_OPCODE, data_ptr);
693 crPackFree( data_ptr );
694}
695
696void PACK_APIENTRY
697crPackAreTexturesResident(GLsizei n, const GLuint * textures,
698 GLboolean * residences, GLboolean * return_val,
699 int *writeback)
700{
701 CR_GET_PACKER_CONTEXT(pc);
702 unsigned char *data_ptr;
703 int packet_length;
704
705 (void) return_val; /* Caller must compute this from residences!!! */
706
707 packet_length = sizeof(int) + /* packet length */
708 sizeof(GLenum) + /* extend-o opcode */
709 sizeof(n) + /* num_textures */
710 n * sizeof(*textures) + /* textures */
711 8 + 8;
712
713 CR_GET_BUFFERED_POINTER(pc, packet_length);
714 WRITE_DATA(0, int, packet_length);
715 WRITE_DATA(4, GLenum, CR_ARETEXTURESRESIDENT_EXTEND_OPCODE);
716 WRITE_DATA(8, GLsizei, n);
717 crMemcpy(data_ptr + 12, textures, n * sizeof(*textures));
718 WRITE_NETWORK_POINTER(12 + n * sizeof(*textures), (void *) residences);
719 WRITE_NETWORK_POINTER(20 + n * sizeof(*textures), (void *) writeback);
720 WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
721 CR_UNLOCK_PACKER_CONTEXT(pc);
722}
723
724
725/**********************************************************************
726 * Texture compression
727 */
728
729void PACK_APIENTRY crPackCompressedTexImage1DARB( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imagesize, const GLvoid *data )
730{
731 unsigned char *data_ptr;
732 int packet_length;
733 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
734
735 /* All extended opcodes have their first 8 bytes predefined:
736 * the first four indicate the packet size, and the next four
737 * indicate the actual extended opcode.
738 */
739 packet_length =
740 sizeof( GLenum) + /* extended opcode */
741 sizeof( target ) +
742 sizeof( level ) +
743 sizeof( internalformat ) +
744 sizeof( width ) +
745 sizeof( border ) +
746 sizeof( imagesize ) +
747 sizeof( int ) + sizeof(GLint);
748
749 if (!noimagedata)
750 {
751 packet_length += imagesize;
752 }
753
754
755 data_ptr = (unsigned char *) crPackAlloc( packet_length );
756 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXIMAGE1DARB_EXTEND_OPCODE );
757 WRITE_DATA( 4, GLenum, target );
758 WRITE_DATA( 8, GLint, level );
759 WRITE_DATA( 12, GLint, internalformat );
760 WRITE_DATA( 16, GLsizei, width );
761 WRITE_DATA( 20, GLint, border );
762 WRITE_DATA( 24, GLsizei, imagesize );
763 WRITE_DATA( 28, int, noimagedata );
764 WRITE_DATA( 32, GLint, (GLint)(uintptr_t) data);
765
766 if (!noimagedata) {
767 crMemcpy( (void *)(data_ptr + 36), (void *)data, imagesize);
768 }
769
770 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
771 crPackFree( data_ptr );
772}
773
774void PACK_APIENTRY crPackCompressedTexImage2DARB( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imagesize, const GLvoid *data )
775{
776 unsigned char *data_ptr;
777 int packet_length;
778 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
779
780 /* All extended opcodes have their first 8 bytes predefined:
781 * the first four indicate the packet size, and the next four
782 * indicate the actual extended opcode.
783 */
784 packet_length =
785 sizeof( GLenum) + /* extended opcode */
786 sizeof( target ) +
787 sizeof( level ) +
788 sizeof( internalformat ) +
789 sizeof( width ) +
790 sizeof( height ) +
791 sizeof( border ) +
792 sizeof( imagesize ) +
793 sizeof( int ) + sizeof(GLint);
794
795 if (!noimagedata)
796 {
797 packet_length += imagesize;
798 }
799
800 //crDebug( "Compressing that shit: %d", level );
801
802 data_ptr = (unsigned char *) crPackAlloc( packet_length );
803 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXIMAGE2DARB_EXTEND_OPCODE );
804 WRITE_DATA( 4, GLenum, target );
805 WRITE_DATA( 8, GLint, level );
806 WRITE_DATA( 12, GLint, internalformat );
807 WRITE_DATA( 16, GLsizei, width );
808 WRITE_DATA( 20, GLsizei, height );
809 WRITE_DATA( 24, GLint, border );
810 WRITE_DATA( 28, GLsizei, imagesize );
811 WRITE_DATA( 32, int, noimagedata );
812 WRITE_DATA( 36, GLint, (GLint)(uintptr_t) data);
813
814 if (!noimagedata) {
815 crMemcpy( (void *)(data_ptr + 40), (void *)data, imagesize);
816 }
817
818 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
819 crPackFree( data_ptr );
820}
821
822void PACK_APIENTRY crPackCompressedTexImage3DARB( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imagesize, const GLvoid *data )
823{
824 unsigned char *data_ptr;
825 int packet_length;
826 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
827
828 /* All extended opcodes have their first 8 bytes predefined:
829 * the first four indicate the packet size, and the next four
830 * indicate the actual extended opcode.
831 */
832 packet_length =
833 sizeof( GLenum) + /* extended opcode */
834 sizeof( target ) +
835 sizeof( level ) +
836 sizeof( internalformat ) +
837 sizeof( width ) +
838 sizeof( height ) +
839 sizeof( depth ) +
840 sizeof( border ) +
841 sizeof( imagesize ) +
842 sizeof( int ) + sizeof(GLint);
843
844 if (!noimagedata)
845 {
846 packet_length += imagesize;
847 }
848
849 data_ptr = (unsigned char *) crPackAlloc( packet_length );
850 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXIMAGE3DARB_EXTEND_OPCODE );
851 WRITE_DATA( 4, GLenum, target );
852 WRITE_DATA( 8, GLint, level );
853 WRITE_DATA( 12, GLint, internalformat );
854 WRITE_DATA( 16, GLsizei, width );
855 WRITE_DATA( 20, GLsizei, height );
856 WRITE_DATA( 24, GLsizei, depth );
857 WRITE_DATA( 28, GLint, border );
858 WRITE_DATA( 32, GLsizei, imagesize );
859 WRITE_DATA( 36, int, noimagedata );
860 WRITE_DATA( 40, GLint, (GLint)(uintptr_t) data);
861
862 if (!noimagedata) {
863 crMemcpy( (void *)(data_ptr + 44), (void *)data, imagesize);
864 }
865
866 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
867 crPackFree( data_ptr );
868}
869
870void PACK_APIENTRY crPackCompressedTexSubImage1DARB( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imagesize, const GLvoid *data )
871{
872 unsigned char *data_ptr;
873 int packet_length;
874 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
875
876 /* All extended opcodes have their first 8 bytes predefined:
877 * the first four indicate the packet size, and the next four
878 * indicate the actual extended opcode.
879 */
880 packet_length =
881 sizeof( GLenum) + /* extended opcode */
882 sizeof( target ) +
883 sizeof( level ) +
884 sizeof( xoffset ) +
885 sizeof( width ) +
886 sizeof( format ) +
887 sizeof( imagesize ) +
888 sizeof( int ) + sizeof(GLint);
889
890 if (!noimagedata)
891 {
892 packet_length += imagesize;
893 }
894
895 data_ptr = (unsigned char *) crPackAlloc( packet_length );
896 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXSUBIMAGE1DARB_EXTEND_OPCODE );
897 WRITE_DATA( 4, GLenum, target );
898 WRITE_DATA( 8, GLint, level );
899 WRITE_DATA( 12, GLint, xoffset );
900 WRITE_DATA( 16, GLsizei, width );
901 WRITE_DATA( 20, GLenum, format );
902 WRITE_DATA( 24, GLsizei, imagesize );
903 WRITE_DATA( 28, int, noimagedata );
904 WRITE_DATA( 32, GLint, (GLint)(uintptr_t) data);
905
906 if (!noimagedata) {
907 crMemcpy( (void *)(data_ptr + 36), (void *)data, imagesize);
908 }
909
910 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
911 crPackFree( data_ptr );
912}
913
914void PACK_APIENTRY crPackCompressedTexSubImage2DARB( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imagesize, const GLvoid *data )
915{
916 unsigned char *data_ptr;
917 int packet_length;
918 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
919
920 /* All extended opcodes have their first 8 bytes predefined:
921 * the first four indicate the packet size, and the next four
922 * indicate the actual extended opcode.
923 */
924 packet_length =
925 sizeof( GLenum) + /* extended opcode */
926 sizeof( target ) +
927 sizeof( level ) +
928 sizeof( xoffset ) +
929 sizeof( yoffset ) +
930 sizeof( width ) +
931 sizeof( height ) +
932 sizeof( format ) +
933 sizeof( imagesize ) +
934 sizeof( int ) + sizeof(GLint);
935
936 if (!noimagedata)
937 {
938 packet_length += imagesize;
939 }
940
941 data_ptr = (unsigned char *) crPackAlloc( packet_length );
942 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXSUBIMAGE2DARB_EXTEND_OPCODE );
943 WRITE_DATA( 4, GLenum, target );
944 WRITE_DATA( 8, GLint, level );
945 WRITE_DATA( 12, GLint, xoffset );
946 WRITE_DATA( 16, GLint, yoffset );
947 WRITE_DATA( 20, GLsizei, width );
948 WRITE_DATA( 24, GLsizei, height );
949 WRITE_DATA( 28, GLenum, format );
950 WRITE_DATA( 32, GLsizei, imagesize );
951 WRITE_DATA( 36, int, noimagedata );
952 WRITE_DATA( 40, GLint, (GLint)(uintptr_t) data);
953
954 if (!noimagedata) {
955 crMemcpy( (void *)(data_ptr + 44), (void *)data, imagesize);
956 }
957
958 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
959 crPackFree( data_ptr );
960}
961
962void 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 )
963{
964 unsigned char *data_ptr;
965 int packet_length;
966 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
967
968 /* All extended opcodes have their first 8 bytes predefined:
969 * the first four indicate the packet size, and the next four
970 * indicate the actual extended opcode.
971 */
972 packet_length =
973 sizeof( GLenum) + /* extended opcode */
974 sizeof( target ) +
975 sizeof( level ) +
976 sizeof( xoffset ) +
977 sizeof( yoffset ) +
978 sizeof( zoffset ) +
979 sizeof( width ) +
980 sizeof( height ) +
981 sizeof( depth ) +
982 sizeof( format ) +
983 sizeof( imagesize ) +
984 sizeof( int ) + sizeof(GLint);
985
986 if (!noimagedata)
987 {
988 packet_length += imagesize;
989 }
990
991 data_ptr = (unsigned char *) crPackAlloc( packet_length );
992 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXSUBIMAGE3DARB_EXTEND_OPCODE );
993 WRITE_DATA( 4, GLenum, target );
994 WRITE_DATA( 8, GLint, level );
995 WRITE_DATA( 12, GLint, xoffset );
996 WRITE_DATA( 16, GLint, yoffset );
997 WRITE_DATA( 20, GLint, zoffset );
998 WRITE_DATA( 24, GLsizei, width );
999 WRITE_DATA( 28, GLsizei, height );
1000 WRITE_DATA( 32, GLsizei, depth );
1001 WRITE_DATA( 36, GLenum, format );
1002 WRITE_DATA( 40, GLsizei, imagesize );
1003 WRITE_DATA( 44, int, noimagedata );
1004 WRITE_DATA( 48, GLint, (GLint)(uintptr_t) data);
1005
1006 if (!noimagedata) {
1007 crMemcpy( (void *)(data_ptr + 52), (void *)data, imagesize);
1008 }
1009
1010 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
1011 crPackFree( data_ptr );
1012}
1013
1014void PACK_APIENTRY crPackGetCompressedTexImageARB( GLenum target, GLint level, GLvoid *img, int *writeback )
1015{
1016 CR_GET_PACKER_CONTEXT(pc);
1017 int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(target)+sizeof(level)+2*8;
1018 unsigned char *data_ptr;
1019 CR_GET_BUFFERED_POINTER( pc, packet_length );
1020
1021 WRITE_DATA_AI(int, packet_length);
1022 WRITE_DATA_AI(GLenum, CR_GETCOMPRESSEDTEXIMAGEARB_EXTEND_OPCODE);
1023 WRITE_DATA_AI(GLenum, target);
1024 WRITE_DATA_AI(GLint, level);
1025 WRITE_NETWORK_POINTER(0, (void *) img );
1026 WRITE_NETWORK_POINTER(8, (void *) writeback );
1027 WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
1028 CR_UNLOCK_PACKER_CONTEXT(pc);
1029}
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