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_mem.h"
|
---|
11 | #include "cr_version.h"
|
---|
12 |
|
---|
13 |
|
---|
14 | void PACK_APIENTRY crPackDrawPixels(GLsizei width, GLsizei height,
|
---|
15 | GLenum format, GLenum type,
|
---|
16 | const GLvoid *pixels,
|
---|
17 | const CRPixelPackState *unpackstate )
|
---|
18 | {
|
---|
19 | unsigned char *data_ptr;
|
---|
20 | int packet_length, imagesize;
|
---|
21 | int noimagedata = (pixels == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
|
---|
22 |
|
---|
23 | packet_length =
|
---|
24 | sizeof( width ) +
|
---|
25 | sizeof( height ) +
|
---|
26 | sizeof( format ) +
|
---|
27 | sizeof( type ) + sizeof(int) + sizeof(uintptr_t);
|
---|
28 |
|
---|
29 | if (!noimagedata)
|
---|
30 | {
|
---|
31 | imagesize = crImageSize( format, type, width, height );
|
---|
32 |
|
---|
33 | if (imagesize<=0)
|
---|
34 | {
|
---|
35 | crDebug("crPackDrawPixels: 0 image size, ignoring");
|
---|
36 | return;
|
---|
37 | }
|
---|
38 | packet_length += imagesize;
|
---|
39 | }
|
---|
40 |
|
---|
41 | data_ptr = (unsigned char *) crPackAlloc( packet_length );
|
---|
42 | WRITE_DATA( 0, GLsizei, width );
|
---|
43 | WRITE_DATA( 4, GLsizei, height );
|
---|
44 | WRITE_DATA( 8, GLenum, format );
|
---|
45 | WRITE_DATA( 12, GLenum, type );
|
---|
46 | WRITE_DATA( 16, GLint, noimagedata );
|
---|
47 | WRITE_DATA( 20, uintptr_t, (uintptr_t) pixels );
|
---|
48 |
|
---|
49 | if (!noimagedata)
|
---|
50 | {
|
---|
51 | crPixelCopy2D(width, height,
|
---|
52 | (void *) (data_ptr + 24), format, type, NULL, /* dst */
|
---|
53 | pixels, format, type, unpackstate); /* src */
|
---|
54 | }
|
---|
55 |
|
---|
56 | crHugePacket( CR_DRAWPIXELS_OPCODE, data_ptr );
|
---|
57 | crPackFree( data_ptr );
|
---|
58 | }
|
---|
59 |
|
---|
60 | void PACK_APIENTRY crPackReadPixels(GLint x, GLint y, GLsizei width,
|
---|
61 | GLsizei height, GLenum format,
|
---|
62 | GLenum type, GLvoid *pixels,
|
---|
63 | const CRPixelPackState *packstate,
|
---|
64 | int *writeback)
|
---|
65 | {
|
---|
66 | GET_PACKER_CONTEXT(pc);
|
---|
67 | unsigned char *data_ptr;
|
---|
68 | GLint stride = 0;
|
---|
69 | GLint bytes_per_row;
|
---|
70 | int bytes_per_pixel;
|
---|
71 | (void)writeback;
|
---|
72 |
|
---|
73 | bytes_per_pixel = crPixelSize(format, type);
|
---|
74 | if (bytes_per_pixel <= 0) {
|
---|
75 | char string[80];
|
---|
76 | sprintf(string, "crPackReadPixels(format 0x%x or type 0x%x)", format, type);
|
---|
77 | __PackError(__LINE__, __FILE__, GL_INVALID_ENUM, string);
|
---|
78 | return;
|
---|
79 | }
|
---|
80 |
|
---|
81 | /* default bytes_per_row so crserver can allocate memory */
|
---|
82 | bytes_per_row = width * bytes_per_pixel;
|
---|
83 |
|
---|
84 | stride = bytes_per_row;
|
---|
85 | if (packstate->alignment != 1) {
|
---|
86 | GLint remainder = bytes_per_row % packstate->alignment;
|
---|
87 | if (remainder)
|
---|
88 | stride = bytes_per_row + (packstate->alignment - remainder);
|
---|
89 | }
|
---|
90 |
|
---|
91 | GET_BUFFERED_POINTER(pc, 48 + sizeof(CRNetworkPointer) );
|
---|
92 | WRITE_DATA( 0, GLint, x );
|
---|
93 | WRITE_DATA( 4, GLint, y );
|
---|
94 | WRITE_DATA( 8, GLsizei, width );
|
---|
95 | WRITE_DATA( 12, GLsizei, height );
|
---|
96 | WRITE_DATA( 16, GLenum, format );
|
---|
97 | WRITE_DATA( 20, GLenum, type );
|
---|
98 | WRITE_DATA( 24, GLint, stride ); /* XXX not really used! */
|
---|
99 | WRITE_DATA( 28, GLint, packstate->alignment );
|
---|
100 | WRITE_DATA( 32, GLint, packstate->skipRows );
|
---|
101 | WRITE_DATA( 36, GLint, packstate->skipPixels );
|
---|
102 | WRITE_DATA( 40, GLint, bytes_per_row );
|
---|
103 | WRITE_DATA( 44, GLint, packstate->rowLength );
|
---|
104 | WRITE_NETWORK_POINTER( 48, (char *) pixels );
|
---|
105 | WRITE_OPCODE( pc, CR_READPIXELS_OPCODE );
|
---|
106 | }
|
---|
107 |
|
---|
108 | /* Round N up to the next multiple of 8 */
|
---|
109 | #define CEIL8(N) (((N) + 7) & ~0x7)
|
---|
110 |
|
---|
111 | void PACK_APIENTRY crPackBitmap(GLsizei width, GLsizei height,
|
---|
112 | GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove,
|
---|
113 | const GLubyte *bitmap, const CRPixelPackState *unpack )
|
---|
114 | {
|
---|
115 | const int noimagedata = (bitmap == NULL) || crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB);
|
---|
116 | unsigned char *data_ptr;
|
---|
117 | int data_length = 0;
|
---|
118 | GLubyte *destBitmap = NULL;
|
---|
119 | int packet_length =
|
---|
120 | sizeof( width ) +
|
---|
121 | sizeof( height ) +
|
---|
122 | sizeof( xorig ) +
|
---|
123 | sizeof( yorig ) +
|
---|
124 | sizeof( xmove ) +
|
---|
125 | sizeof( ymove ) +
|
---|
126 | sizeof( GLuint ) + sizeof(uintptr_t);
|
---|
127 |
|
---|
128 | if (!noimagedata)
|
---|
129 | {
|
---|
130 | data_length = CEIL8(width) * height / 8;
|
---|
131 | packet_length += data_length;
|
---|
132 | }
|
---|
133 |
|
---|
134 | data_ptr = (unsigned char *) crPackAlloc( packet_length );
|
---|
135 |
|
---|
136 | WRITE_DATA( 0, GLsizei, width );
|
---|
137 | WRITE_DATA( 4, GLsizei, height );
|
---|
138 | WRITE_DATA( 8, GLfloat, xorig );
|
---|
139 | WRITE_DATA( 12, GLfloat, yorig );
|
---|
140 | WRITE_DATA( 16, GLfloat, xmove );
|
---|
141 | WRITE_DATA( 20, GLfloat, ymove );
|
---|
142 | WRITE_DATA( 24, GLuint, noimagedata );
|
---|
143 | WRITE_DATA( 28, uintptr_t, (uintptr_t) bitmap);
|
---|
144 |
|
---|
145 | crBitmapCopy(width, height, (GLubyte *)(data_ptr + 32), bitmap, unpack);
|
---|
146 |
|
---|
147 | crHugePacket( CR_BITMAP_OPCODE, data_ptr );
|
---|
148 | crPackFree( data_ptr );
|
---|
149 | }
|
---|
150 | /*
|
---|
151 | ZPix - compressed DrawPixels
|
---|
152 | */
|
---|
153 | void PACK_APIENTRY crPackZPixCR( GLsizei width, GLsizei height,
|
---|
154 | GLenum format, GLenum type,
|
---|
155 | GLenum ztype, GLint zparm, GLint length,
|
---|
156 | const GLvoid *pixels,
|
---|
157 | const CRPixelPackState *unpackstate )
|
---|
158 | {
|
---|
159 | unsigned char *data_ptr;
|
---|
160 | int packet_length;
|
---|
161 | (void)unpackstate;
|
---|
162 |
|
---|
163 | if (pixels == NULL)
|
---|
164 | {
|
---|
165 | return;
|
---|
166 | }
|
---|
167 |
|
---|
168 | packet_length =
|
---|
169 | sizeof( int ) + /* packet size */
|
---|
170 | sizeof( GLenum ) + /* extended opcode */
|
---|
171 | sizeof( width ) +
|
---|
172 | sizeof( height ) +
|
---|
173 | sizeof( format ) +
|
---|
174 | sizeof( type ) +
|
---|
175 | sizeof( ztype ) +
|
---|
176 | sizeof( zparm ) +
|
---|
177 | sizeof( length );
|
---|
178 |
|
---|
179 | packet_length += length;
|
---|
180 |
|
---|
181 | /* XXX JAG
|
---|
182 | crDebug("PackZPixCR: fb %d x %d, state %d, zlen = %d, plen = %d",
|
---|
183 | width, height, ztype, length, packet_length);
|
---|
184 | */
|
---|
185 | data_ptr = (unsigned char *) crPackAlloc( packet_length );
|
---|
186 | WRITE_DATA( 0, GLenum , CR_ZPIXCR_EXTEND_OPCODE );
|
---|
187 | WRITE_DATA( 4, GLsizei, width );
|
---|
188 | WRITE_DATA( 8, GLsizei, height );
|
---|
189 | WRITE_DATA( 12, GLenum, format );
|
---|
190 | WRITE_DATA( 16, GLenum, type );
|
---|
191 | WRITE_DATA( 20, GLenum, ztype );
|
---|
192 | WRITE_DATA( 24, GLint, zparm );
|
---|
193 | WRITE_DATA( 28, GLint, length );
|
---|
194 |
|
---|
195 | crMemcpy((void *) (data_ptr+32), pixels, length);
|
---|
196 |
|
---|
197 | crHugePacket( CR_EXTEND_OPCODE, data_ptr );
|
---|
198 | crPackFree( data_ptr );
|
---|
199 | }
|
---|
200 |
|
---|
201 |
|
---|
202 | void PACK_APIENTRY
|
---|
203 | crPackGetTexImage( GLenum target, GLint level, GLenum format, GLenum type,
|
---|
204 | GLvoid * pixels, const CRPixelPackState * packstate,
|
---|
205 | int * writeback )
|
---|
206 | {
|
---|
207 | GET_PACKER_CONTEXT(pc);
|
---|
208 | unsigned char *data_ptr;
|
---|
209 | (void) pc;
|
---|
210 | GET_BUFFERED_POINTER( pc, 40 );
|
---|
211 | WRITE_DATA( 0, GLint, 40 );
|
---|
212 | WRITE_DATA( 4, GLenum, CR_GETTEXIMAGE_EXTEND_OPCODE );
|
---|
213 | WRITE_DATA( 8, GLenum, target );
|
---|
214 | WRITE_DATA( 12, GLint, level );
|
---|
215 | WRITE_DATA( 16, GLenum, format );
|
---|
216 | WRITE_DATA( 20, GLenum, type );
|
---|
217 | WRITE_NETWORK_POINTER( 24, (void *) pixels );
|
---|
218 | WRITE_NETWORK_POINTER( 32, (void *) writeback );
|
---|
219 | WRITE_OPCODE( pc, CR_EXTEND_OPCODE );
|
---|
220 | }
|
---|