VirtualBox

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

最後變更 在這個檔案從71007是 69392,由 vboxsync 提交於 7 年 前

GuestHost/OpenGL: scm updates

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id Revision
檔案大小: 31.8 KB
 
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_CMDBLOCK_CHECK_FLUSH(pc);
722 CR_UNLOCK_PACKER_CONTEXT(pc);
723}
724
725
726/**********************************************************************
727 * Texture compression
728 */
729
730void PACK_APIENTRY crPackCompressedTexImage1DARB( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imagesize, const GLvoid *data )
731{
732 unsigned char *data_ptr;
733 int packet_length;
734 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
735
736 /* All extended opcodes have their first 8 bytes predefined:
737 * the first four indicate the packet size, and the next four
738 * indicate the actual extended opcode.
739 */
740 packet_length =
741 sizeof( GLenum) + /* extended opcode */
742 sizeof( target ) +
743 sizeof( level ) +
744 sizeof( internalformat ) +
745 sizeof( width ) +
746 sizeof( border ) +
747 sizeof( imagesize ) +
748 sizeof( int ) + sizeof(GLint);
749
750 if (!noimagedata)
751 {
752 packet_length += imagesize;
753 }
754
755
756 data_ptr = (unsigned char *) crPackAlloc( packet_length );
757 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXIMAGE1DARB_EXTEND_OPCODE );
758 WRITE_DATA( 4, GLenum, target );
759 WRITE_DATA( 8, GLint, level );
760 WRITE_DATA( 12, GLint, internalformat );
761 WRITE_DATA( 16, GLsizei, width );
762 WRITE_DATA( 20, GLint, border );
763 WRITE_DATA( 24, GLsizei, imagesize );
764 WRITE_DATA( 28, int, noimagedata );
765 WRITE_DATA( 32, GLint, (GLint)(uintptr_t) data);
766
767 if (!noimagedata) {
768 crMemcpy( (void *)(data_ptr + 36), (void *)data, imagesize);
769 }
770
771 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
772 crPackFree( data_ptr );
773}
774
775void PACK_APIENTRY crPackCompressedTexImage2DARB( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imagesize, const GLvoid *data )
776{
777 unsigned char *data_ptr;
778 int packet_length;
779 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
780
781 /* All extended opcodes have their first 8 bytes predefined:
782 * the first four indicate the packet size, and the next four
783 * indicate the actual extended opcode.
784 */
785 packet_length =
786 sizeof( GLenum) + /* extended opcode */
787 sizeof( target ) +
788 sizeof( level ) +
789 sizeof( internalformat ) +
790 sizeof( width ) +
791 sizeof( height ) +
792 sizeof( border ) +
793 sizeof( imagesize ) +
794 sizeof( int ) + sizeof(GLint);
795
796 if (!noimagedata)
797 {
798 packet_length += imagesize;
799 }
800
801 /*crDebug( "Compressing that shit: %d", level );*/
802
803 data_ptr = (unsigned char *) crPackAlloc( packet_length );
804 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXIMAGE2DARB_EXTEND_OPCODE );
805 WRITE_DATA( 4, GLenum, target );
806 WRITE_DATA( 8, GLint, level );
807 WRITE_DATA( 12, GLint, internalformat );
808 WRITE_DATA( 16, GLsizei, width );
809 WRITE_DATA( 20, GLsizei, height );
810 WRITE_DATA( 24, GLint, border );
811 WRITE_DATA( 28, GLsizei, imagesize );
812 WRITE_DATA( 32, int, noimagedata );
813 WRITE_DATA( 36, GLint, (GLint)(uintptr_t) data);
814
815 if (!noimagedata) {
816 crMemcpy( (void *)(data_ptr + 40), (void *)data, imagesize);
817 }
818
819 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
820 crPackFree( data_ptr );
821}
822
823void PACK_APIENTRY crPackCompressedTexImage3DARB( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imagesize, const GLvoid *data )
824{
825 unsigned char *data_ptr;
826 int packet_length;
827 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
828
829 /* All extended opcodes have their first 8 bytes predefined:
830 * the first four indicate the packet size, and the next four
831 * indicate the actual extended opcode.
832 */
833 packet_length =
834 sizeof( GLenum) + /* extended opcode */
835 sizeof( target ) +
836 sizeof( level ) +
837 sizeof( internalformat ) +
838 sizeof( width ) +
839 sizeof( height ) +
840 sizeof( depth ) +
841 sizeof( border ) +
842 sizeof( imagesize ) +
843 sizeof( int ) + sizeof(GLint);
844
845 if (!noimagedata)
846 {
847 packet_length += imagesize;
848 }
849
850 data_ptr = (unsigned char *) crPackAlloc( packet_length );
851 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXIMAGE3DARB_EXTEND_OPCODE );
852 WRITE_DATA( 4, GLenum, target );
853 WRITE_DATA( 8, GLint, level );
854 WRITE_DATA( 12, GLint, internalformat );
855 WRITE_DATA( 16, GLsizei, width );
856 WRITE_DATA( 20, GLsizei, height );
857 WRITE_DATA( 24, GLsizei, depth );
858 WRITE_DATA( 28, GLint, border );
859 WRITE_DATA( 32, GLsizei, imagesize );
860 WRITE_DATA( 36, int, noimagedata );
861 WRITE_DATA( 40, GLint, (GLint)(uintptr_t) data);
862
863 if (!noimagedata) {
864 crMemcpy( (void *)(data_ptr + 44), (void *)data, imagesize);
865 }
866
867 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
868 crPackFree( data_ptr );
869}
870
871void PACK_APIENTRY crPackCompressedTexSubImage1DARB( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imagesize, const GLvoid *data )
872{
873 unsigned char *data_ptr;
874 int packet_length;
875 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
876
877 /* All extended opcodes have their first 8 bytes predefined:
878 * the first four indicate the packet size, and the next four
879 * indicate the actual extended opcode.
880 */
881 packet_length =
882 sizeof( GLenum) + /* extended opcode */
883 sizeof( target ) +
884 sizeof( level ) +
885 sizeof( xoffset ) +
886 sizeof( width ) +
887 sizeof( format ) +
888 sizeof( imagesize ) +
889 sizeof( int ) + sizeof(GLint);
890
891 if (!noimagedata)
892 {
893 packet_length += imagesize;
894 }
895
896 data_ptr = (unsigned char *) crPackAlloc( packet_length );
897 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXSUBIMAGE1DARB_EXTEND_OPCODE );
898 WRITE_DATA( 4, GLenum, target );
899 WRITE_DATA( 8, GLint, level );
900 WRITE_DATA( 12, GLint, xoffset );
901 WRITE_DATA( 16, GLsizei, width );
902 WRITE_DATA( 20, GLenum, format );
903 WRITE_DATA( 24, GLsizei, imagesize );
904 WRITE_DATA( 28, int, noimagedata );
905 WRITE_DATA( 32, GLint, (GLint)(uintptr_t) data);
906
907 if (!noimagedata) {
908 crMemcpy( (void *)(data_ptr + 36), (void *)data, imagesize);
909 }
910
911 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
912 crPackFree( data_ptr );
913}
914
915void PACK_APIENTRY crPackCompressedTexSubImage2DARB( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imagesize, const GLvoid *data )
916{
917 unsigned char *data_ptr;
918 int packet_length;
919 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
920
921 /* All extended opcodes have their first 8 bytes predefined:
922 * the first four indicate the packet size, and the next four
923 * indicate the actual extended opcode.
924 */
925 packet_length =
926 sizeof( GLenum) + /* extended opcode */
927 sizeof( target ) +
928 sizeof( level ) +
929 sizeof( xoffset ) +
930 sizeof( yoffset ) +
931 sizeof( width ) +
932 sizeof( height ) +
933 sizeof( format ) +
934 sizeof( imagesize ) +
935 sizeof( int ) + sizeof(GLint);
936
937 if (!noimagedata)
938 {
939 packet_length += imagesize;
940 }
941
942 data_ptr = (unsigned char *) crPackAlloc( packet_length );
943 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXSUBIMAGE2DARB_EXTEND_OPCODE );
944 WRITE_DATA( 4, GLenum, target );
945 WRITE_DATA( 8, GLint, level );
946 WRITE_DATA( 12, GLint, xoffset );
947 WRITE_DATA( 16, GLint, yoffset );
948 WRITE_DATA( 20, GLsizei, width );
949 WRITE_DATA( 24, GLsizei, height );
950 WRITE_DATA( 28, GLenum, format );
951 WRITE_DATA( 32, GLsizei, imagesize );
952 WRITE_DATA( 36, int, noimagedata );
953 WRITE_DATA( 40, GLint, (GLint)(uintptr_t) data);
954
955 if (!noimagedata) {
956 crMemcpy( (void *)(data_ptr + 44), (void *)data, imagesize);
957 }
958
959 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
960 crPackFree( data_ptr );
961}
962
963void 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 )
964{
965 unsigned char *data_ptr;
966 int packet_length;
967 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
968
969 /* All extended opcodes have their first 8 bytes predefined:
970 * the first four indicate the packet size, and the next four
971 * indicate the actual extended opcode.
972 */
973 packet_length =
974 sizeof( GLenum) + /* extended opcode */
975 sizeof( target ) +
976 sizeof( level ) +
977 sizeof( xoffset ) +
978 sizeof( yoffset ) +
979 sizeof( zoffset ) +
980 sizeof( width ) +
981 sizeof( height ) +
982 sizeof( depth ) +
983 sizeof( format ) +
984 sizeof( imagesize ) +
985 sizeof( int ) + sizeof(GLint);
986
987 if (!noimagedata)
988 {
989 packet_length += imagesize;
990 }
991
992 data_ptr = (unsigned char *) crPackAlloc( packet_length );
993 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXSUBIMAGE3DARB_EXTEND_OPCODE );
994 WRITE_DATA( 4, GLenum, target );
995 WRITE_DATA( 8, GLint, level );
996 WRITE_DATA( 12, GLint, xoffset );
997 WRITE_DATA( 16, GLint, yoffset );
998 WRITE_DATA( 20, GLint, zoffset );
999 WRITE_DATA( 24, GLsizei, width );
1000 WRITE_DATA( 28, GLsizei, height );
1001 WRITE_DATA( 32, GLsizei, depth );
1002 WRITE_DATA( 36, GLenum, format );
1003 WRITE_DATA( 40, GLsizei, imagesize );
1004 WRITE_DATA( 44, int, noimagedata );
1005 WRITE_DATA( 48, GLint, (GLint)(uintptr_t) data);
1006
1007 if (!noimagedata) {
1008 crMemcpy( (void *)(data_ptr + 52), (void *)data, imagesize);
1009 }
1010
1011 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
1012 crPackFree( data_ptr );
1013}
1014
1015void PACK_APIENTRY crPackGetCompressedTexImageARB( GLenum target, GLint level, GLvoid *img, int *writeback )
1016{
1017 CR_GET_PACKER_CONTEXT(pc);
1018 int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(target)+sizeof(level)+2*8;
1019 unsigned char *data_ptr;
1020 CR_GET_BUFFERED_POINTER( pc, packet_length );
1021
1022 WRITE_DATA_AI(int, packet_length);
1023 WRITE_DATA_AI(GLenum, CR_GETCOMPRESSEDTEXIMAGEARB_EXTEND_OPCODE);
1024 WRITE_DATA_AI(GLenum, target);
1025 WRITE_DATA_AI(GLint, level);
1026 WRITE_NETWORK_POINTER(0, (void *) img );
1027 WRITE_NETWORK_POINTER(8, (void *) writeback );
1028 WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
1029 CR_UNLOCK_PACKER_CONTEXT(pc);
1030}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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