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 | #ifndef CR_PACK_H
|
---|
8 | #define CR_PACK_H
|
---|
9 |
|
---|
10 | #include "cr_compiler.h"
|
---|
11 | #include "cr_error.h"
|
---|
12 | #include "cr_protocol.h"
|
---|
13 | #include "cr_opcodes.h"
|
---|
14 | #include "cr_endian.h"
|
---|
15 | #include "state/cr_statetypes.h"
|
---|
16 | #include "state/cr_currentpointers.h"
|
---|
17 | #include "state/cr_client.h"
|
---|
18 | #ifdef CHROMIUM_THREADSAFE
|
---|
19 | #include "cr_threads.h"
|
---|
20 | #endif
|
---|
21 |
|
---|
22 | #include <iprt/types.h>
|
---|
23 |
|
---|
24 | #ifdef __cplusplus
|
---|
25 | extern "C" {
|
---|
26 | #endif
|
---|
27 |
|
---|
28 | typedef struct CRPackContext_t CRPackContext;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Packer buffer
|
---|
32 | */
|
---|
33 | typedef struct
|
---|
34 | {
|
---|
35 | void *pack; /**< the actual storage space/buffer */
|
---|
36 | unsigned int size; /**< size of pack[] buffer */
|
---|
37 | unsigned int mtu;
|
---|
38 | unsigned char *data_start, *data_current, *data_end;
|
---|
39 | unsigned char *opcode_start, *opcode_current, *opcode_end;
|
---|
40 | GLboolean geometry_only; /**< just used for debugging */
|
---|
41 | GLboolean holds_BeginEnd;
|
---|
42 | GLboolean in_BeginEnd;
|
---|
43 | GLboolean canBarf;
|
---|
44 | GLboolean holds_List;
|
---|
45 | GLboolean in_List;
|
---|
46 | CRPackContext *context;
|
---|
47 | } CRPackBuffer;
|
---|
48 |
|
---|
49 | typedef void (*CRPackFlushFunc)(void *arg);
|
---|
50 | typedef void (*CRPackSendHugeFunc)(CROpcode, void *);
|
---|
51 | typedef void (*CRPackErrorHandlerFunc)(int line, const char *file, GLenum error, const char *info);
|
---|
52 |
|
---|
53 | #define CRPACKBLOCKSTATE_OP_BEGIN 0x01
|
---|
54 | #define CRPACKBLOCKSTATE_OP_NEWLIST 0x02
|
---|
55 | #define CRPACKBLOCKSTATE_OP_BEGINQUERY 0x04
|
---|
56 | #define CRPACKBLOCKSTATE_OP_ALL 0x07
|
---|
57 |
|
---|
58 | #define CRPACKBLOCKSTATE_IS_OP_STARTED(_state, _op) (!!((_state) & (_op)))
|
---|
59 |
|
---|
60 | #define CRPACKBLOCKSTATE_IS_STARTED(_state) (!!(_state))
|
---|
61 |
|
---|
62 | #define CRPACKBLOCKSTATE_OP_START(_state, _op) do { \
|
---|
63 | Assert(!CRPACKBLOCKSTATE_IS_OP_STARTED(_state, _op)); \
|
---|
64 | (_state) |= (_op); \
|
---|
65 | } while (0)
|
---|
66 |
|
---|
67 | #define CRPACKBLOCKSTATE_OP_STOP(_state, _op) do { \
|
---|
68 | Assert(CRPACKBLOCKSTATE_IS_OP_STARTED(_state, _op)); \
|
---|
69 | (_state) &= ~(_op); \
|
---|
70 | } while (0)
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Packer context
|
---|
74 | */
|
---|
75 | struct CRPackContext_t
|
---|
76 | {
|
---|
77 | CRPackBuffer buffer; /**< not a pointer, see comments in pack_buffer.c */
|
---|
78 | CRPackFlushFunc Flush;
|
---|
79 | void *flush_arg;
|
---|
80 | CRPackSendHugeFunc SendHuge;
|
---|
81 | CRPackErrorHandlerFunc Error;
|
---|
82 | CRCurrentStatePointers current;
|
---|
83 | uint32_t u32CmdBlockState;
|
---|
84 | GLvectorf bounds_min, bounds_max;
|
---|
85 | int updateBBOX;
|
---|
86 | int swapping;
|
---|
87 | CRPackBuffer *currentBuffer;
|
---|
88 | #ifdef CHROMIUM_THREADSAFE
|
---|
89 | CRmutex mutex;
|
---|
90 | #endif
|
---|
91 | char *file; /**< for debugging only */
|
---|
92 | int line; /**< for debugging only */
|
---|
93 | };
|
---|
94 |
|
---|
95 | #if !defined(IN_RING0)
|
---|
96 | # define CR_PACKER_CONTEXT_ARGSINGLEDECL
|
---|
97 | # define CR_PACKER_CONTEXT_ARGDECL
|
---|
98 | # define CR_PACKER_CONTEXT_ARG
|
---|
99 | # define CR_PACKER_CONTEXT_ARGCTX(C)
|
---|
100 | # ifdef CHROMIUM_THREADSAFE
|
---|
101 | extern CRtsd _PackerTSD;
|
---|
102 | # define CR_GET_PACKER_CONTEXT(C) CRPackContext *C = (CRPackContext *) crGetTSD(&_PackerTSD)
|
---|
103 | # define CR_LOCK_PACKER_CONTEXT(PC) crLockMutex(&((PC)->mutex))
|
---|
104 | # define CR_UNLOCK_PACKER_CONTEXT(PC) crUnlockMutex(&((PC)->mutex))
|
---|
105 | # else
|
---|
106 | extern DLLDATA(CRPackContext) cr_packer_globals;
|
---|
107 | # define CR_GET_PACKER_CONTEXT(C) CRPackContext *C = &cr_packer_globals
|
---|
108 | # define CR_LOCK_PACKER_CONTEXT(PC)
|
---|
109 | # define CR_UNLOCK_PACKER_CONTEXT(PC)
|
---|
110 | # endif
|
---|
111 | extern int cr_packer_cmd_blocks_enabled;
|
---|
112 | #else /* if defined IN_RING0 */
|
---|
113 | # define CR_PACKER_CONTEXT_ARGSINGLEDECL CRPackContext *_pCtx
|
---|
114 | # define CR_PACKER_CONTEXT_ARGDECL CR_PACKER_CONTEXT_ARGSINGLEDECL,
|
---|
115 | # define CR_PACKER_CONTEXT_ARG _pCtx,
|
---|
116 | # define CR_PACKER_CONTEXT_ARGCTX(C) C,
|
---|
117 | # define CR_GET_PACKER_CONTEXT(C) CRPackContext *C = _pCtx
|
---|
118 | # define CR_LOCK_PACKER_CONTEXT(PC)
|
---|
119 | # define CR_UNLOCK_PACKER_CONTEXT(PC)
|
---|
120 | #endif
|
---|
121 |
|
---|
122 | extern DECLEXPORT(CRPackContext *) crPackNewContext(int swapping);
|
---|
123 | extern DECLEXPORT(void) crPackDeleteContext(CRPackContext *pc);
|
---|
124 | extern DECLEXPORT(void) crPackSetContext( CRPackContext *pc );
|
---|
125 | extern DECLEXPORT(CRPackContext *) crPackGetContext( void );
|
---|
126 |
|
---|
127 | extern DECLEXPORT(void) crPackSetBuffer( CRPackContext *pc, CRPackBuffer *buffer );
|
---|
128 | extern DECLEXPORT(void) crPackSetBufferDEBUG( const char *file, int line, CRPackContext *pc, CRPackBuffer *buffer );
|
---|
129 | extern DECLEXPORT(void) crPackReleaseBuffer( CRPackContext *pc );
|
---|
130 | extern DECLEXPORT(void) crPackResetPointers( CRPackContext *pc );
|
---|
131 |
|
---|
132 | extern DECLEXPORT(int) crPackMaxOpcodes( int buffer_size );
|
---|
133 | extern DECLEXPORT(int) crPackMaxData( int buffer_size );
|
---|
134 | extern DECLEXPORT(void) crPackInitBuffer( CRPackBuffer *buffer, void *buf, int size, int mtu
|
---|
135 | #ifdef IN_RING0
|
---|
136 | , unsigned int num_opcodes
|
---|
137 | #endif
|
---|
138 | );
|
---|
139 |
|
---|
140 | extern DECLEXPORT(void) crPackFlushFunc( CRPackContext *pc, CRPackFlushFunc ff );
|
---|
141 | extern DECLEXPORT(void) crPackFlushArg( CRPackContext *pc, void *flush_arg );
|
---|
142 | extern DECLEXPORT(void) crPackSendHugeFunc( CRPackContext *pc, CRPackSendHugeFunc shf );
|
---|
143 | extern DECLEXPORT(void) crPackErrorFunction( CRPackContext *pc, CRPackErrorHandlerFunc errf );
|
---|
144 | extern DECLEXPORT(void) crPackOffsetCurrentPointers( int offset );
|
---|
145 | extern DECLEXPORT(void) crPackNullCurrentPointers( void );
|
---|
146 |
|
---|
147 | extern DECLEXPORT(void) crPackResetBoundingBox( CRPackContext *pc );
|
---|
148 | extern DECLEXPORT(GLboolean) crPackGetBoundingBox( CRPackContext *pc,
|
---|
149 | GLfloat *xmin, GLfloat *ymin, GLfloat *zmin,
|
---|
150 | GLfloat *xmax, GLfloat *ymax, GLfloat *zmax);
|
---|
151 |
|
---|
152 | extern DECLEXPORT(void) crPackAppendBuffer( CR_PACKER_CONTEXT_ARGDECL const CRPackBuffer *buffer );
|
---|
153 | extern DECLEXPORT(void) crPackAppendBoundedBuffer( CR_PACKER_CONTEXT_ARGDECL const CRPackBuffer *buffer, const CRrecti *bounds );
|
---|
154 | extern DECLEXPORT(int) crPackCanHoldBuffer( CR_PACKER_CONTEXT_ARGDECL const CRPackBuffer *buffer );
|
---|
155 | extern DECLEXPORT(int) crPackCanHoldBoundedBuffer( CR_PACKER_CONTEXT_ARGDECL const CRPackBuffer *buffer );
|
---|
156 |
|
---|
157 | #if defined(LINUX) || defined(WINDOWS)
|
---|
158 | #define CR_UNALIGNED_ACCESS_OKAY
|
---|
159 | #else
|
---|
160 | #undef CR_UNALIGNED_ACCESS_OKAY
|
---|
161 | #endif
|
---|
162 | #ifndef IN_RING0
|
---|
163 | extern DECLEXPORT(void) crWriteUnalignedDouble( void *buffer, double d );
|
---|
164 | extern DECLEXPORT(void) crWriteSwappedDouble( void *buffer, double d );
|
---|
165 | #endif
|
---|
166 |
|
---|
167 | extern DECLEXPORT(void) *crPackAlloc( CR_PACKER_CONTEXT_ARGDECL unsigned int len );
|
---|
168 | extern DECLEXPORT(void) crHugePacket( CR_PACKER_CONTEXT_ARGDECL CROpcode op, void *ptr );
|
---|
169 | extern DECLEXPORT(void) crPackFree( CR_PACKER_CONTEXT_ARGDECL void *ptr );
|
---|
170 | extern DECLEXPORT(void) crNetworkPointerWrite( CRNetworkPointer *, void * );
|
---|
171 |
|
---|
172 | extern DECLEXPORT(void) crPackExpandDrawArrays(GLenum mode, GLint first, GLsizei count, CRClientState *c, const GLfloat *pZva);
|
---|
173 | extern DECLEXPORT(void) crPackExpandDrawArraysSWAP(GLenum mode, GLint first, GLsizei count, CRClientState *c, const GLfloat *pZva);
|
---|
174 |
|
---|
175 | extern DECLEXPORT(void) crPackUnrollDrawElements(GLsizei count, GLenum type, const GLvoid *indices);
|
---|
176 | extern DECLEXPORT(void) crPackUnrollDrawElementsSWAP(GLsizei count, GLenum type, const GLvoid *indices);
|
---|
177 |
|
---|
178 | extern DECLEXPORT(void) crPackExpandDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, CRClientState *c, const GLfloat *pZva);
|
---|
179 | extern DECLEXPORT(void) crPackExpandDrawElementsSWAP(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, CRClientState *c, const GLfloat *pZva);
|
---|
180 |
|
---|
181 | extern DECLEXPORT(void) crPackExpandDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, CRClientState *c, const GLfloat *pZva);
|
---|
182 | extern DECLEXPORT(void) crPackExpandDrawRangeElementsSWAP(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, CRClientState *c, const GLfloat *pZva);
|
---|
183 |
|
---|
184 | extern DECLEXPORT(void) crPackExpandArrayElement(GLint index, CRClientState *c, const GLfloat *pZva);
|
---|
185 | extern DECLEXPORT(void) crPackExpandArrayElementSWAP(GLint index, CRClientState *c, const GLfloat *pZva);
|
---|
186 |
|
---|
187 | extern DECLEXPORT(void) crPackExpandMultiDrawArraysEXT( GLenum mode, GLint *first, GLsizei *count, GLsizei primcount, CRClientState *c, const GLfloat *pZva );
|
---|
188 | extern DECLEXPORT(void) crPackExpandMultiDrawArraysEXTSWAP( GLenum mode, GLint *first, GLsizei *count, GLsizei primcount, CRClientState *c, const GLfloat *pZva );
|
---|
189 |
|
---|
190 | extern DECLEXPORT(void) crPackExpandMultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount, CRClientState *c, const GLfloat *pZva );
|
---|
191 | extern DECLEXPORT(void) crPackExpandMultiDrawElementsEXTSWAP( GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount, CRClientState *c, const GLfloat *pZva );
|
---|
192 |
|
---|
193 | extern DECLEXPORT(void) crPackCmdBlocksEnable();
|
---|
194 |
|
---|
195 |
|
---|
196 | /**
|
---|
197 | * Return number of opcodes in given buffer.
|
---|
198 | */
|
---|
199 | static INLINE int
|
---|
200 | crPackNumOpcodes(const CRPackBuffer *buffer)
|
---|
201 | {
|
---|
202 | CRASSERT(buffer->opcode_start - buffer->opcode_current >= 0);
|
---|
203 | return buffer->opcode_start - buffer->opcode_current;
|
---|
204 | }
|
---|
205 |
|
---|
206 | DECLINLINE(bool) crPackBufferIsEmpty(CRPackBuffer *buffer)
|
---|
207 | {
|
---|
208 | return crPackNumOpcodes(buffer) == 0;
|
---|
209 | }
|
---|
210 |
|
---|
211 | /**
|
---|
212 | * Return amount of data (in bytes) in buffer.
|
---|
213 | */
|
---|
214 | static INLINE int
|
---|
215 | crPackNumData(const CRPackBuffer *buffer)
|
---|
216 | {
|
---|
217 | CRASSERT(buffer->data_current - buffer->data_start >= 0);
|
---|
218 | return buffer->data_current - buffer->data_start; /* in bytes */
|
---|
219 | }
|
---|
220 |
|
---|
221 |
|
---|
222 | static INLINE int
|
---|
223 | crPackCanHoldOpcode(const CRPackContext *pc, int num_opcode, int num_data)
|
---|
224 | {
|
---|
225 | int fitsInMTU, opcodesFit, dataFits;
|
---|
226 |
|
---|
227 | CRASSERT(pc->currentBuffer);
|
---|
228 |
|
---|
229 | fitsInMTU = (((pc->buffer.data_current - pc->buffer.opcode_current - 1
|
---|
230 | + num_opcode + num_data
|
---|
231 | + 0x3 ) & ~0x3) + sizeof(CRMessageOpcodes)
|
---|
232 | <= pc->buffer.mtu);
|
---|
233 | opcodesFit = (pc->buffer.opcode_current - num_opcode >= pc->buffer.opcode_end);
|
---|
234 | dataFits = (pc->buffer.data_current + num_data <= pc->buffer.data_end);
|
---|
235 |
|
---|
236 | return fitsInMTU && opcodesFit && dataFits;
|
---|
237 | }
|
---|
238 |
|
---|
239 |
|
---|
240 | #define CR_PACK_SPECIAL_OP( _pc, _op) \
|
---|
241 | do { \
|
---|
242 | data_ptr = pc->buffer.data_current; \
|
---|
243 | (_pc)->buffer.data_current += 4; \
|
---|
244 | WRITE_OPCODE( (_pc), (_op) ); \
|
---|
245 | WRITE_DATA( 0, GLuint, 0xdeadbeef ); \
|
---|
246 | data_ptr = NULL; /* <- sanity*/ \
|
---|
247 | } while (0)
|
---|
248 |
|
---|
249 | #define CR_CMDBLOCK_OP( _pc, _op) \
|
---|
250 | do { \
|
---|
251 | CR_PACK_SPECIAL_OP( _pc, _op); \
|
---|
252 | } while (0)
|
---|
253 |
|
---|
254 |
|
---|
255 | #define CR_CMDBLOCK_BEGIN( pc, op ) \
|
---|
256 | do { \
|
---|
257 | CR_LOCK_PACKER_CONTEXT(pc); \
|
---|
258 | if (!cr_packer_cmd_blocks_enabled) break; \
|
---|
259 | if (!CRPACKBLOCKSTATE_IS_STARTED(pc->u32CmdBlockState)) { \
|
---|
260 | THREADASSERT( pc ); \
|
---|
261 | CRASSERT( pc->currentBuffer ); \
|
---|
262 | if (!crPackBufferIsEmpty(&pc->buffer)) { \
|
---|
263 | if ((*pc->buffer.opcode_start) != CR_NOP_OPCODE) { \
|
---|
264 | pc->Flush( pc->flush_arg ); \
|
---|
265 | Assert(crPackCanHoldOpcode( pc, 1, 4 ) ); \
|
---|
266 | CR_CMDBLOCK_OP( pc, CR_CMDBLOCKBEGIN_OPCODE ); \
|
---|
267 | } \
|
---|
268 | else { \
|
---|
269 | (*pc->buffer.opcode_start) = CR_CMDBLOCKBEGIN_OPCODE; \
|
---|
270 | } \
|
---|
271 | } \
|
---|
272 | else { \
|
---|
273 | Assert(crPackCanHoldOpcode( pc, 1, 4 ) ); \
|
---|
274 | CR_CMDBLOCK_OP( pc, CR_CMDBLOCKBEGIN_OPCODE ); \
|
---|
275 | } \
|
---|
276 | } \
|
---|
277 | CRPACKBLOCKSTATE_OP_START(pc->u32CmdBlockState, op); \
|
---|
278 | } while (0)
|
---|
279 |
|
---|
280 | #define CR_CMDBLOCK_END( pc, op ) \
|
---|
281 | do { \
|
---|
282 | if (!cr_packer_cmd_blocks_enabled) break; \
|
---|
283 | CRPACKBLOCKSTATE_OP_STOP(pc->u32CmdBlockState, op); \
|
---|
284 | if (!CRPACKBLOCKSTATE_IS_STARTED(pc->u32CmdBlockState)) { \
|
---|
285 | THREADASSERT( pc ); \
|
---|
286 | CRASSERT( pc->currentBuffer ); \
|
---|
287 | if (!crPackBufferIsEmpty(&pc->buffer)) { \
|
---|
288 | if ((*pc->buffer.opcode_start) != CR_CMDBLOCKBEGIN_OPCODE) {\
|
---|
289 | if ( !crPackCanHoldOpcode( pc, 1, 4 ) ) { \
|
---|
290 | pc->Flush( pc->flush_arg ); \
|
---|
291 | Assert(crPackCanHoldOpcode( pc, 1, 4 ) ); \
|
---|
292 | } \
|
---|
293 | CR_CMDBLOCK_OP( pc, CR_CMDBLOCKEND_OPCODE ); \
|
---|
294 | pc->Flush( pc->flush_arg ); \
|
---|
295 | } \
|
---|
296 | else { \
|
---|
297 | (*pc->buffer.opcode_start) = CR_NOP_OPCODE; \
|
---|
298 | } \
|
---|
299 | } \
|
---|
300 | else { \
|
---|
301 | Assert(crPackCanHoldOpcode( pc, 1, 4 ) ); \
|
---|
302 | CR_CMDBLOCK_OP( pc, CR_CMDBLOCKEND_OPCODE ); \
|
---|
303 | pc->Flush( pc->flush_arg ); \
|
---|
304 | } \
|
---|
305 | } \
|
---|
306 | } while (0)
|
---|
307 |
|
---|
308 | /**
|
---|
309 | * Alloc space for a message of 'len' bytes (plus 1 opcode).
|
---|
310 | * Only flush if buffer is full.
|
---|
311 | */
|
---|
312 | #define CR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH(pc, len, lock) \
|
---|
313 | do { \
|
---|
314 | THREADASSERT( pc ); \
|
---|
315 | if (lock) CR_LOCK_PACKER_CONTEXT(pc); \
|
---|
316 | CRASSERT( pc->currentBuffer ); \
|
---|
317 | if ( !crPackCanHoldOpcode( pc, 1, (len) ) ) { \
|
---|
318 | pc->Flush( pc->flush_arg ); \
|
---|
319 | CRASSERT(crPackCanHoldOpcode( pc, 1, (len) ) ); \
|
---|
320 | } \
|
---|
321 | data_ptr = pc->buffer.data_current; \
|
---|
322 | pc->buffer.data_current += (len); \
|
---|
323 | } while (0)
|
---|
324 |
|
---|
325 | /**
|
---|
326 | * As above, flush if the buffer contains vertex data and we're
|
---|
327 | * no longer inside glBegin/glEnd.
|
---|
328 | */
|
---|
329 | #define CR_GET_BUFFERED_POINTER( pc, len ) \
|
---|
330 | do { \
|
---|
331 | CR_LOCK_PACKER_CONTEXT(pc); \
|
---|
332 | CRASSERT( pc->currentBuffer ); \
|
---|
333 | if ( pc->buffer.holds_BeginEnd && !pc->buffer.in_BeginEnd ) { \
|
---|
334 | CRASSERT( 0 ); /* should never be here currently */ \
|
---|
335 | pc->Flush( pc->flush_arg ); \
|
---|
336 | pc->buffer.holds_BeginEnd = 0; \
|
---|
337 | } \
|
---|
338 | CR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH( pc, len, GL_FALSE ); \
|
---|
339 | } while (0)
|
---|
340 |
|
---|
341 | /**
|
---|
342 | * As above, but without lock.
|
---|
343 | */
|
---|
344 | #define CR_GET_BUFFERED_POINTER_NOLOCK( pc, len ) \
|
---|
345 | do { \
|
---|
346 | CRASSERT( pc->currentBuffer ); \
|
---|
347 | if ( pc->buffer.holds_BeginEnd && !pc->buffer.in_BeginEnd ) { \
|
---|
348 | CRASSERT( 0 ); /* should never be here currently */ \
|
---|
349 | pc->Flush( pc->flush_arg ); \
|
---|
350 | pc->buffer.holds_BeginEnd = 0; \
|
---|
351 | } \
|
---|
352 | CR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH( pc, len, GL_FALSE ); \
|
---|
353 | } while (0)
|
---|
354 |
|
---|
355 |
|
---|
356 | /**
|
---|
357 | * As above, but for vertex data between glBegin/End (counts vertices).
|
---|
358 | */
|
---|
359 | #define CR_GET_BUFFERED_COUNT_POINTER( pc, len ) \
|
---|
360 | do { \
|
---|
361 | CR_LOCK_PACKER_CONTEXT(pc); \
|
---|
362 | CRASSERT( pc->currentBuffer ); \
|
---|
363 | if ( !crPackCanHoldOpcode( pc, 1, (len) ) ) { \
|
---|
364 | pc->Flush( pc->flush_arg ); \
|
---|
365 | CRASSERT( crPackCanHoldOpcode( pc, 1, (len) ) ); \
|
---|
366 | } \
|
---|
367 | data_ptr = pc->buffer.data_current; \
|
---|
368 | pc->current.vtx_count++; \
|
---|
369 | pc->buffer.data_current += (len); \
|
---|
370 | } while (0)
|
---|
371 |
|
---|
372 |
|
---|
373 | /**
|
---|
374 | * Allocate space for a msg/command that has no arguments, such
|
---|
375 | * as glFinish().
|
---|
376 | */
|
---|
377 | #define CR_GET_BUFFERED_POINTER_NO_ARGS( pc ) \
|
---|
378 | CR_GET_BUFFERED_POINTER( pc, 4 ); \
|
---|
379 | WRITE_DATA( 0, GLuint, 0xdeadbeef )
|
---|
380 |
|
---|
381 | #define WRITE_DATA( offset, type, data ) \
|
---|
382 | *( (type *) (data_ptr + (offset))) = (data)
|
---|
383 |
|
---|
384 | /* Write data to current location and auto increment */
|
---|
385 | #define WRITE_DATA_AI(type, data) \
|
---|
386 | { \
|
---|
387 | *((type*) (data_ptr)) = (data); \
|
---|
388 | data_ptr += sizeof(type); \
|
---|
389 | }
|
---|
390 |
|
---|
391 | #ifdef CR_UNALIGNED_ACCESS_OKAY
|
---|
392 | #define WRITE_DOUBLE( offset, data ) \
|
---|
393 | WRITE_DATA( offset, GLdouble, data )
|
---|
394 | #else
|
---|
395 | # ifndef IN_RING0
|
---|
396 | # define WRITE_DOUBLE( offset, data ) \
|
---|
397 | crWriteUnalignedDouble( data_ptr + (offset), (data) )
|
---|
398 | # else
|
---|
399 | # define WRITE_DOUBLE( offset, data ) \
|
---|
400 | AssertReleaseFailed()
|
---|
401 | # endif
|
---|
402 | #endif
|
---|
403 |
|
---|
404 | #ifndef IN_RING0
|
---|
405 | #define WRITE_SWAPPED_DOUBLE( offset, data ) \
|
---|
406 | crWriteSwappedDouble( data_ptr + (offset), (data) )
|
---|
407 | #else
|
---|
408 | #define WRITE_SWAPPED_DOUBLE( offset, data ) \
|
---|
409 | AssertReleaseFailed()
|
---|
410 | #endif
|
---|
411 |
|
---|
412 | #define WRITE_OPCODE( pc, opcode ) \
|
---|
413 | *(pc->buffer.opcode_current--) = (unsigned char) opcode
|
---|
414 |
|
---|
415 | #define WRITE_NETWORK_POINTER( offset, data ) \
|
---|
416 | crNetworkPointerWrite( (CRNetworkPointer *) ( data_ptr + (offset) ), (data) )
|
---|
417 |
|
---|
418 | #ifdef __cplusplus
|
---|
419 | }
|
---|
420 | #endif
|
---|
421 |
|
---|
422 | #endif /* CR_PACK_H */
|
---|