VirtualBox

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

最後變更 在這個檔案從34356是 33475,由 vboxsync 提交於 14 年 前

crOpenGL/wddm: multithreading fix

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id
檔案大小: 31.7 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 WRITE_OPCODE(pc, CR_TEXPARAMETERFV_OPCODE);
525 CR_UNLOCK_PACKER_CONTEXT(pc);
526}
527
528void PACK_APIENTRY
529crPackTexParameteriv(GLenum target, GLenum pname, const GLint * params)
530{
531 CR_GET_PACKER_CONTEXT(pc);
532 if (__handleTexParameterData(target, pname, (GLfloat *) params))
533 WRITE_OPCODE(pc, CR_TEXPARAMETERIV_OPCODE);
534 CR_UNLOCK_PACKER_CONTEXT(pc);
535}
536
537void PACK_APIENTRY
538crPackTexParameterf(GLenum target, GLenum pname, GLfloat param)
539{
540 crPackTexParameterfv(target, pname, &param);
541}
542
543void PACK_APIENTRY
544crPackTexParameteri(GLenum target, GLenum pname, GLint param)
545{
546 crPackTexParameteriv(target, pname, &param);
547}
548
549#ifdef CR_OPENGL_VERSION_1_2
550void PACK_APIENTRY
551crPackTexSubImage3D(GLenum target, GLint level,
552 GLint xoffset, GLint yoffset, GLint zoffset,
553 GLsizei width, GLsizei height, GLsizei depth,
554 GLenum format, GLenum type, const GLvoid * pixels,
555 const CRPixelPackState * unpackstate)
556{
557 unsigned char *data_ptr;
558 int packet_length;
559 int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
560
561 packet_length =
562 sizeof(target) +
563 sizeof(level) +
564 sizeof(xoffset) +
565 sizeof(yoffset) +
566 sizeof(zoffset) +
567 sizeof(width) +
568 sizeof(height) +
569 sizeof(depth) +
570 sizeof(format) +
571 sizeof(type) + sizeof(int) + sizeof(GLint);
572
573 if (!noimagedata)
574 {
575 packet_length += crTextureSize(format, type, width, height, depth);
576 }
577
578 data_ptr = (unsigned char *) crPackAlloc(packet_length);
579 WRITE_DATA(0, GLenum, target);
580 WRITE_DATA(4, GLint, level);
581 WRITE_DATA(8, GLint, xoffset);
582 WRITE_DATA(12, GLint, yoffset);
583 WRITE_DATA(16, GLint, zoffset);
584 WRITE_DATA(20, GLsizei, width);
585 WRITE_DATA(24, GLsizei, height);
586 WRITE_DATA(28, GLsizei, depth);
587 WRITE_DATA(32, GLenum, format);
588 WRITE_DATA(36, GLenum, type);
589 WRITE_DATA(40, GLint, noimagedata);
590 WRITE_DATA(44, GLint, (GLint)(uintptr_t) pixels);
591
592 if (!noimagedata)
593 {
594 crPixelCopy3D(width, height, depth, (GLvoid *) (data_ptr + 48), format, type, NULL, /* dst */
595 pixels, format, type, unpackstate); /* src */
596 }
597
598 crHugePacket(CR_TEXSUBIMAGE3D_OPCODE, data_ptr);
599 crPackFree( data_ptr );
600}
601#endif /* CR_OPENGL_VERSION_1_2 */
602
603void PACK_APIENTRY
604crPackTexSubImage2D(GLenum target, GLint level,
605 GLint xoffset, GLint yoffset, GLsizei width,
606 GLsizei height, GLenum format, GLenum type,
607 const GLvoid * pixels,
608 const CRPixelPackState * unpackstate)
609{
610 unsigned char *data_ptr;
611 int packet_length;
612 int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
613
614 packet_length =
615 sizeof(target) +
616 sizeof(level) +
617 sizeof(xoffset) +
618 sizeof(yoffset) +
619 sizeof(width) +
620 sizeof(height) +
621 sizeof(format) + sizeof(type) + sizeof(int) + sizeof(GLint);
622
623 if (!noimagedata)
624 {
625 packet_length += crImageSize(format, type, width, height);
626 }
627
628 data_ptr = (unsigned char *) crPackAlloc(packet_length);
629 WRITE_DATA(0, GLenum, target);
630 WRITE_DATA(4, GLint, level);
631 WRITE_DATA(8, GLint, xoffset);
632 WRITE_DATA(12, GLint, yoffset);
633 WRITE_DATA(16, GLsizei, width);
634 WRITE_DATA(20, GLsizei, height);
635 WRITE_DATA(24, GLenum, format);
636 WRITE_DATA(28, GLenum, type);
637 WRITE_DATA(32, GLint, noimagedata);
638 WRITE_DATA(36, GLint, (GLint)(uintptr_t) pixels);
639
640 if (!noimagedata)
641 {
642 crPixelCopy2D(width, height, (GLvoid *) (data_ptr + 40), format, type, NULL, /* dst */
643 pixels, format, type, unpackstate); /* src */
644 }
645
646 crHugePacket(CR_TEXSUBIMAGE2D_OPCODE, data_ptr);
647 crPackFree( data_ptr );
648}
649
650void PACK_APIENTRY
651crPackTexSubImage1D(GLenum target, GLint level,
652 GLint xoffset, GLsizei width, GLenum format, GLenum type,
653 const GLvoid * pixels,
654 const CRPixelPackState * unpackstate)
655{
656 unsigned char *data_ptr;
657 int packet_length;
658 int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
659
660 packet_length =
661 sizeof(target) +
662 sizeof(level) +
663 sizeof(xoffset) +
664 sizeof(width) +
665 sizeof(format) + sizeof(type) + sizeof(int) + sizeof(GLint);
666
667 if (!noimagedata)
668 {
669 packet_length += crImageSize(format, type, width, 1);
670 }
671
672 data_ptr = (unsigned char *) crPackAlloc(packet_length);
673 WRITE_DATA(0, GLenum, target);
674 WRITE_DATA(4, GLint, level);
675 WRITE_DATA(8, GLint, xoffset);
676 WRITE_DATA(12, GLsizei, width);
677 WRITE_DATA(16, GLenum, format);
678 WRITE_DATA(20, GLenum, type);
679 WRITE_DATA(24, GLint, noimagedata);
680 WRITE_DATA(28, GLint, (GLint)(uintptr_t) pixels);
681
682 if (!noimagedata)
683 {
684 crPixelCopy1D((GLvoid *) (data_ptr + 32), format, type,
685 pixels, format, type, width, unpackstate);
686 }
687
688 crHugePacket(CR_TEXSUBIMAGE1D_OPCODE, data_ptr);
689 crPackFree( data_ptr );
690}
691
692void PACK_APIENTRY
693crPackAreTexturesResident(GLsizei n, const GLuint * textures,
694 GLboolean * residences, GLboolean * return_val,
695 int *writeback)
696{
697 CR_GET_PACKER_CONTEXT(pc);
698 unsigned char *data_ptr;
699 int packet_length;
700
701 (void) return_val; /* Caller must compute this from residences!!! */
702
703 packet_length = sizeof(int) + /* packet length */
704 sizeof(GLenum) + /* extend-o opcode */
705 sizeof(n) + /* num_textures */
706 n * sizeof(*textures) + /* textures */
707 8 + 8;
708
709 CR_GET_BUFFERED_POINTER(pc, packet_length);
710 WRITE_DATA(0, int, packet_length);
711 WRITE_DATA(4, GLenum, CR_ARETEXTURESRESIDENT_EXTEND_OPCODE);
712 WRITE_DATA(8, GLsizei, n);
713 crMemcpy(data_ptr + 12, textures, n * sizeof(*textures));
714 WRITE_NETWORK_POINTER(12 + n * sizeof(*textures), (void *) residences);
715 WRITE_NETWORK_POINTER(20 + n * sizeof(*textures), (void *) writeback);
716 WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
717 CR_UNLOCK_PACKER_CONTEXT(pc);
718}
719
720
721/**********************************************************************
722 * Texture compression
723 */
724
725void PACK_APIENTRY crPackCompressedTexImage1DARB( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imagesize, const GLvoid *data )
726{
727 unsigned char *data_ptr;
728 int packet_length;
729 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
730
731 /* All extended opcodes have their first 8 bytes predefined:
732 * the first four indicate the packet size, and the next four
733 * indicate the actual extended opcode.
734 */
735 packet_length =
736 sizeof( GLenum) + /* extended opcode */
737 sizeof( target ) +
738 sizeof( level ) +
739 sizeof( internalformat ) +
740 sizeof( width ) +
741 sizeof( border ) +
742 sizeof( imagesize ) +
743 sizeof( int ) + sizeof(GLint);
744
745 if (!noimagedata)
746 {
747 packet_length += imagesize;
748 }
749
750
751 data_ptr = (unsigned char *) crPackAlloc( packet_length );
752 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXIMAGE1DARB_EXTEND_OPCODE );
753 WRITE_DATA( 4, GLenum, target );
754 WRITE_DATA( 8, GLint, level );
755 WRITE_DATA( 12, GLint, internalformat );
756 WRITE_DATA( 16, GLsizei, width );
757 WRITE_DATA( 20, GLint, border );
758 WRITE_DATA( 24, GLsizei, imagesize );
759 WRITE_DATA( 28, int, noimagedata );
760 WRITE_DATA( 32, GLint, (GLint)(uintptr_t) data);
761
762 if (!noimagedata) {
763 crMemcpy( (void *)(data_ptr + 36), (void *)data, imagesize);
764 }
765
766 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
767 crPackFree( data_ptr );
768}
769
770void PACK_APIENTRY crPackCompressedTexImage2DARB( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imagesize, const GLvoid *data )
771{
772 unsigned char *data_ptr;
773 int packet_length;
774 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
775
776 /* All extended opcodes have their first 8 bytes predefined:
777 * the first four indicate the packet size, and the next four
778 * indicate the actual extended opcode.
779 */
780 packet_length =
781 sizeof( GLenum) + /* extended opcode */
782 sizeof( target ) +
783 sizeof( level ) +
784 sizeof( internalformat ) +
785 sizeof( width ) +
786 sizeof( height ) +
787 sizeof( border ) +
788 sizeof( imagesize ) +
789 sizeof( int ) + sizeof(GLint);
790
791 if (!noimagedata)
792 {
793 packet_length += imagesize;
794 }
795
796 //crDebug( "Compressing that shit: %d", level );
797
798 data_ptr = (unsigned char *) crPackAlloc( packet_length );
799 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXIMAGE2DARB_EXTEND_OPCODE );
800 WRITE_DATA( 4, GLenum, target );
801 WRITE_DATA( 8, GLint, level );
802 WRITE_DATA( 12, GLint, internalformat );
803 WRITE_DATA( 16, GLsizei, width );
804 WRITE_DATA( 20, GLsizei, height );
805 WRITE_DATA( 24, GLint, border );
806 WRITE_DATA( 28, GLsizei, imagesize );
807 WRITE_DATA( 32, int, noimagedata );
808 WRITE_DATA( 36, GLint, (GLint)(uintptr_t) data);
809
810 if (!noimagedata) {
811 crMemcpy( (void *)(data_ptr + 40), (void *)data, imagesize);
812 }
813
814 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
815 crPackFree( data_ptr );
816}
817
818void PACK_APIENTRY crPackCompressedTexImage3DARB( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imagesize, const GLvoid *data )
819{
820 unsigned char *data_ptr;
821 int packet_length;
822 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
823
824 /* All extended opcodes have their first 8 bytes predefined:
825 * the first four indicate the packet size, and the next four
826 * indicate the actual extended opcode.
827 */
828 packet_length =
829 sizeof( GLenum) + /* extended opcode */
830 sizeof( target ) +
831 sizeof( level ) +
832 sizeof( internalformat ) +
833 sizeof( width ) +
834 sizeof( height ) +
835 sizeof( depth ) +
836 sizeof( border ) +
837 sizeof( imagesize ) +
838 sizeof( int ) + sizeof(GLint);
839
840 if (!noimagedata)
841 {
842 packet_length += imagesize;
843 }
844
845 data_ptr = (unsigned char *) crPackAlloc( packet_length );
846 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXIMAGE3DARB_EXTEND_OPCODE );
847 WRITE_DATA( 4, GLenum, target );
848 WRITE_DATA( 8, GLint, level );
849 WRITE_DATA( 12, GLint, internalformat );
850 WRITE_DATA( 16, GLsizei, width );
851 WRITE_DATA( 20, GLsizei, height );
852 WRITE_DATA( 24, GLsizei, depth );
853 WRITE_DATA( 28, GLint, border );
854 WRITE_DATA( 32, GLsizei, imagesize );
855 WRITE_DATA( 36, int, noimagedata );
856 WRITE_DATA( 40, GLint, (GLint)(uintptr_t) data);
857
858 if (!noimagedata) {
859 crMemcpy( (void *)(data_ptr + 44), (void *)data, imagesize);
860 }
861
862 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
863 crPackFree( data_ptr );
864}
865
866void PACK_APIENTRY crPackCompressedTexSubImage1DARB( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imagesize, const GLvoid *data )
867{
868 unsigned char *data_ptr;
869 int packet_length;
870 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
871
872 /* All extended opcodes have their first 8 bytes predefined:
873 * the first four indicate the packet size, and the next four
874 * indicate the actual extended opcode.
875 */
876 packet_length =
877 sizeof( GLenum) + /* extended opcode */
878 sizeof( target ) +
879 sizeof( level ) +
880 sizeof( xoffset ) +
881 sizeof( width ) +
882 sizeof( format ) +
883 sizeof( imagesize ) +
884 sizeof( int ) + sizeof(GLint);
885
886 if (!noimagedata)
887 {
888 packet_length += imagesize;
889 }
890
891 data_ptr = (unsigned char *) crPackAlloc( packet_length );
892 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXSUBIMAGE1DARB_EXTEND_OPCODE );
893 WRITE_DATA( 4, GLenum, target );
894 WRITE_DATA( 8, GLint, level );
895 WRITE_DATA( 12, GLint, xoffset );
896 WRITE_DATA( 16, GLsizei, width );
897 WRITE_DATA( 20, GLenum, format );
898 WRITE_DATA( 24, GLsizei, imagesize );
899 WRITE_DATA( 28, int, noimagedata );
900 WRITE_DATA( 32, GLint, (GLint)(uintptr_t) data);
901
902 if (!noimagedata) {
903 crMemcpy( (void *)(data_ptr + 36), (void *)data, imagesize);
904 }
905
906 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
907 crPackFree( data_ptr );
908}
909
910void PACK_APIENTRY crPackCompressedTexSubImage2DARB( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imagesize, const GLvoid *data )
911{
912 unsigned char *data_ptr;
913 int packet_length;
914 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
915
916 /* All extended opcodes have their first 8 bytes predefined:
917 * the first four indicate the packet size, and the next four
918 * indicate the actual extended opcode.
919 */
920 packet_length =
921 sizeof( GLenum) + /* extended opcode */
922 sizeof( target ) +
923 sizeof( level ) +
924 sizeof( xoffset ) +
925 sizeof( yoffset ) +
926 sizeof( width ) +
927 sizeof( height ) +
928 sizeof( format ) +
929 sizeof( imagesize ) +
930 sizeof( int ) + sizeof(GLint);
931
932 if (!noimagedata)
933 {
934 packet_length += imagesize;
935 }
936
937 data_ptr = (unsigned char *) crPackAlloc( packet_length );
938 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXSUBIMAGE2DARB_EXTEND_OPCODE );
939 WRITE_DATA( 4, GLenum, target );
940 WRITE_DATA( 8, GLint, level );
941 WRITE_DATA( 12, GLint, xoffset );
942 WRITE_DATA( 16, GLint, yoffset );
943 WRITE_DATA( 20, GLsizei, width );
944 WRITE_DATA( 24, GLsizei, height );
945 WRITE_DATA( 28, GLenum, format );
946 WRITE_DATA( 32, GLsizei, imagesize );
947 WRITE_DATA( 36, int, noimagedata );
948 WRITE_DATA( 40, GLint, (GLint)(uintptr_t) data);
949
950 if (!noimagedata) {
951 crMemcpy( (void *)(data_ptr + 44), (void *)data, imagesize);
952 }
953
954 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
955 crPackFree( data_ptr );
956}
957
958void 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 )
959{
960 unsigned char *data_ptr;
961 int packet_length;
962 int noimagedata = (data == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
963
964 /* All extended opcodes have their first 8 bytes predefined:
965 * the first four indicate the packet size, and the next four
966 * indicate the actual extended opcode.
967 */
968 packet_length =
969 sizeof( GLenum) + /* extended opcode */
970 sizeof( target ) +
971 sizeof( level ) +
972 sizeof( xoffset ) +
973 sizeof( yoffset ) +
974 sizeof( zoffset ) +
975 sizeof( width ) +
976 sizeof( height ) +
977 sizeof( depth ) +
978 sizeof( format ) +
979 sizeof( imagesize ) +
980 sizeof( int ) + sizeof(GLint);
981
982 if (!noimagedata)
983 {
984 packet_length += imagesize;
985 }
986
987 data_ptr = (unsigned char *) crPackAlloc( packet_length );
988 WRITE_DATA( 0, GLenum, CR_COMPRESSEDTEXSUBIMAGE3DARB_EXTEND_OPCODE );
989 WRITE_DATA( 4, GLenum, target );
990 WRITE_DATA( 8, GLint, level );
991 WRITE_DATA( 12, GLint, xoffset );
992 WRITE_DATA( 16, GLint, yoffset );
993 WRITE_DATA( 20, GLint, zoffset );
994 WRITE_DATA( 24, GLsizei, width );
995 WRITE_DATA( 28, GLsizei, height );
996 WRITE_DATA( 32, GLsizei, depth );
997 WRITE_DATA( 36, GLenum, format );
998 WRITE_DATA( 40, GLsizei, imagesize );
999 WRITE_DATA( 44, int, noimagedata );
1000 WRITE_DATA( 48, GLint, (GLint)(uintptr_t) data);
1001
1002 if (!noimagedata) {
1003 crMemcpy( (void *)(data_ptr + 52), (void *)data, imagesize);
1004 }
1005
1006 crHugePacket( CR_EXTEND_OPCODE, data_ptr );
1007 crPackFree( data_ptr );
1008}
1009
1010void PACK_APIENTRY crPackGetCompressedTexImageARB( GLenum target, GLint level, GLvoid *img, int *writeback )
1011{
1012 CR_GET_PACKER_CONTEXT(pc);
1013 int packet_length = sizeof(int)+sizeof(GLenum)+sizeof(target)+sizeof(level)+2*8;
1014 unsigned char *data_ptr;
1015 CR_GET_BUFFERED_POINTER( pc, packet_length );
1016
1017 WRITE_DATA_AI(int, packet_length);
1018 WRITE_DATA_AI(GLenum, CR_GETCOMPRESSEDTEXIMAGEARB_EXTEND_OPCODE);
1019 WRITE_DATA_AI(GLenum, target);
1020 WRITE_DATA_AI(GLint, level);
1021 WRITE_NETWORK_POINTER(0, (void *) img );
1022 WRITE_NETWORK_POINTER(8, (void *) writeback );
1023 WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
1024 CR_UNLOCK_PACKER_CONTEXT(pc);
1025}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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