VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/packer/pack_pixels.c@ 16469

Last change on this file since 16469 was 15532, checked in by vboxsync, 16 years ago

crOpenGL: export to OSE

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