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 uint32_t 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) crPackCapsSet(uint32_t u32Caps);
|
---|
194 |
|
---|
195 | /**
|
---|
196 | * Return number of opcodes in given buffer.
|
---|
197 | */
|
---|
198 | static INLINE int
|
---|
199 | crPackNumOpcodes(const CRPackBuffer *buffer)
|
---|
200 | {
|
---|
201 | CRASSERT(buffer->opcode_start - buffer->opcode_current >= 0);
|
---|
202 | return buffer->opcode_start - buffer->opcode_current;
|
---|
203 | }
|
---|
204 |
|
---|
205 | DECLINLINE(bool) crPackBufferIsEmpty(CRPackBuffer *buffer)
|
---|
206 | {
|
---|
207 | return crPackNumOpcodes(buffer) == 0;
|
---|
208 | }
|
---|
209 |
|
---|
210 | /**
|
---|
211 | * Return amount of data (in bytes) in buffer.
|
---|
212 | */
|
---|
213 | static INLINE int
|
---|
214 | crPackNumData(const CRPackBuffer *buffer)
|
---|
215 | {
|
---|
216 | CRASSERT(buffer->data_current - buffer->data_start >= 0);
|
---|
217 | return buffer->data_current - buffer->data_start; /* in bytes */
|
---|
218 | }
|
---|
219 |
|
---|
220 |
|
---|
221 | static INLINE int
|
---|
222 | crPackCanHoldOpcode(const CRPackContext *pc, int num_opcode, int num_data)
|
---|
223 | {
|
---|
224 | int fitsInMTU, opcodesFit, dataFits;
|
---|
225 |
|
---|
226 | CRASSERT(pc->currentBuffer);
|
---|
227 |
|
---|
228 | fitsInMTU = (((pc->buffer.data_current - pc->buffer.opcode_current - 1
|
---|
229 | + num_opcode + num_data
|
---|
230 | + 0x3 ) & ~0x3) + sizeof(CRMessageOpcodes)
|
---|
231 | <= pc->buffer.mtu);
|
---|
232 | opcodesFit = (pc->buffer.opcode_current - num_opcode >= pc->buffer.opcode_end);
|
---|
233 | dataFits = (pc->buffer.data_current + num_data <= pc->buffer.data_end);
|
---|
234 |
|
---|
235 | return fitsInMTU && opcodesFit && dataFits;
|
---|
236 | }
|
---|
237 |
|
---|
238 |
|
---|
239 | #define CR_PACK_SPECIAL_OP( _pc, _op) \
|
---|
240 | do { \
|
---|
241 | data_ptr = pc->buffer.data_current; \
|
---|
242 | (_pc)->buffer.data_current += 4; \
|
---|
243 | WRITE_OPCODE( (_pc), (_op) ); \
|
---|
244 | WRITE_DATA( 0, GLuint, 0xdeadbeef ); \
|
---|
245 | data_ptr = NULL; /* <- sanity*/ \
|
---|
246 | } while (0)
|
---|
247 |
|
---|
248 | #define CR_CMDBLOCK_OP( _pc, _op) \
|
---|
249 | do { \
|
---|
250 | CR_PACK_SPECIAL_OP( _pc, _op); \
|
---|
251 | } while (0)
|
---|
252 |
|
---|
253 | #define CR_CMDBLOCK_IS_STARTED( pc, op ) CRPACKBLOCKSTATE_IS_OP_STARTED((pc)->u32CmdBlockState, op)
|
---|
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 | Assert(!CRPACKBLOCKSTATE_IS_OP_STARTED((pc)->u32CmdBlockState, op)); \
|
---|
278 | CRPACKBLOCKSTATE_OP_START((pc)->u32CmdBlockState, op); \
|
---|
279 | Assert(CRPACKBLOCKSTATE_IS_OP_STARTED((pc)->u32CmdBlockState, op)); \
|
---|
280 | } while (0)
|
---|
281 |
|
---|
282 | #define CR_CMDBLOCK_END( pc, op ) \
|
---|
283 | do { \
|
---|
284 | if (!cr_packer_cmd_blocks_enabled) break; \
|
---|
285 | Assert(CRPACKBLOCKSTATE_IS_OP_STARTED((pc)->u32CmdBlockState, op)); \
|
---|
286 | CRPACKBLOCKSTATE_OP_STOP((pc)->u32CmdBlockState, op); \
|
---|
287 | Assert(!CRPACKBLOCKSTATE_IS_OP_STARTED((pc)->u32CmdBlockState, op)); \
|
---|
288 | if (!CRPACKBLOCKSTATE_IS_STARTED((pc)->u32CmdBlockState)) { \
|
---|
289 | THREADASSERT( pc ); \
|
---|
290 | CRASSERT( (pc)->currentBuffer ); \
|
---|
291 | if (!crPackBufferIsEmpty(&(pc)->buffer)) { \
|
---|
292 | if ((*(pc)->buffer.opcode_start) != CR_CMDBLOCKBEGIN_OPCODE) {\
|
---|
293 | if ( !crPackCanHoldOpcode( pc, 1, 4 ) ) { \
|
---|
294 | (pc)->Flush( (pc)->flush_arg ); \
|
---|
295 | Assert(crPackCanHoldOpcode( pc, 1, 4 ) ); \
|
---|
296 | } \
|
---|
297 | CR_CMDBLOCK_OP( pc, CR_CMDBLOCKEND_OPCODE ); \
|
---|
298 | (pc)->Flush( (pc)->flush_arg ); \
|
---|
299 | } \
|
---|
300 | else { \
|
---|
301 | (*(pc)->buffer.opcode_start) = CR_NOP_OPCODE; \
|
---|
302 | } \
|
---|
303 | } \
|
---|
304 | else { \
|
---|
305 | Assert(crPackCanHoldOpcode( pc, 1, 4 ) ); \
|
---|
306 | CR_CMDBLOCK_OP( pc, CR_CMDBLOCKEND_OPCODE ); \
|
---|
307 | (pc)->Flush( pc->flush_arg ); \
|
---|
308 | } \
|
---|
309 | } \
|
---|
310 | } while (0)
|
---|
311 |
|
---|
312 | #define CR_CMDBLOCK_CHECK_FLUSH( pc ) \
|
---|
313 | do { \
|
---|
314 | if (!(cr_packer_cmd_blocks_enabled & CR_VBOX_CAP_CMDBLOCKS_FLUSH)) break; \
|
---|
315 | if(!CRPACKBLOCKSTATE_IS_OP_STARTED((pc)->u32CmdBlockState, CRPACKBLOCKSTATE_OP_NEWLIST)) break; \
|
---|
316 | THREADASSERT( pc ); \
|
---|
317 | CRASSERT( (pc)->currentBuffer ); \
|
---|
318 | if ( !crPackCanHoldOpcode( pc, 1, 4 ) ) { \
|
---|
319 | (pc)->Flush( (pc)->flush_arg ); \
|
---|
320 | Assert(crPackCanHoldOpcode( pc, 1, 4 ) ); \
|
---|
321 | } \
|
---|
322 | CR_CMDBLOCK_OP( pc, CR_CMDBLOCKFLUSH_OPCODE ); \
|
---|
323 | (pc)->Flush( (pc)->flush_arg ); \
|
---|
324 | } while (0)
|
---|
325 |
|
---|
326 | /**
|
---|
327 | * Alloc space for a message of 'len' bytes (plus 1 opcode).
|
---|
328 | * Only flush if buffer is full.
|
---|
329 | */
|
---|
330 | #define CR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH(pc, len, lock) \
|
---|
331 | do { \
|
---|
332 | THREADASSERT( pc ); \
|
---|
333 | if (lock) CR_LOCK_PACKER_CONTEXT(pc); \
|
---|
334 | CRASSERT( pc->currentBuffer ); \
|
---|
335 | if ( !crPackCanHoldOpcode( pc, 1, (len) ) ) { \
|
---|
336 | pc->Flush( pc->flush_arg ); \
|
---|
337 | CRASSERT(crPackCanHoldOpcode( pc, 1, (len) ) ); \
|
---|
338 | } \
|
---|
339 | data_ptr = pc->buffer.data_current; \
|
---|
340 | pc->buffer.data_current += (len); \
|
---|
341 | } while (0)
|
---|
342 |
|
---|
343 | /**
|
---|
344 | * As above, flush if the buffer contains vertex data and we're
|
---|
345 | * no longer inside glBegin/glEnd.
|
---|
346 | */
|
---|
347 | #define CR_GET_BUFFERED_POINTER( pc, len ) \
|
---|
348 | do { \
|
---|
349 | CR_LOCK_PACKER_CONTEXT(pc); \
|
---|
350 | CRASSERT( pc->currentBuffer ); \
|
---|
351 | if ( pc->buffer.holds_BeginEnd && !pc->buffer.in_BeginEnd ) { \
|
---|
352 | CRASSERT( 0 ); /* should never be here currently */ \
|
---|
353 | pc->Flush( pc->flush_arg ); \
|
---|
354 | pc->buffer.holds_BeginEnd = 0; \
|
---|
355 | } \
|
---|
356 | CR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH( pc, len, GL_FALSE ); \
|
---|
357 | } while (0)
|
---|
358 |
|
---|
359 | /**
|
---|
360 | * As above, but without lock.
|
---|
361 | */
|
---|
362 | #define CR_GET_BUFFERED_POINTER_NOLOCK( pc, len ) \
|
---|
363 | do { \
|
---|
364 | CRASSERT( pc->currentBuffer ); \
|
---|
365 | if ( pc->buffer.holds_BeginEnd && !pc->buffer.in_BeginEnd ) { \
|
---|
366 | CRASSERT( 0 ); /* should never be here currently */ \
|
---|
367 | pc->Flush( pc->flush_arg ); \
|
---|
368 | pc->buffer.holds_BeginEnd = 0; \
|
---|
369 | } \
|
---|
370 | CR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH( pc, len, GL_FALSE ); \
|
---|
371 | } while (0)
|
---|
372 |
|
---|
373 |
|
---|
374 | /**
|
---|
375 | * As above, but for vertex data between glBegin/End (counts vertices).
|
---|
376 | */
|
---|
377 | #define CR_GET_BUFFERED_COUNT_POINTER( pc, len ) \
|
---|
378 | do { \
|
---|
379 | CR_LOCK_PACKER_CONTEXT(pc); \
|
---|
380 | CRASSERT( pc->currentBuffer ); \
|
---|
381 | if ( !crPackCanHoldOpcode( pc, 1, (len) ) ) { \
|
---|
382 | pc->Flush( pc->flush_arg ); \
|
---|
383 | CRASSERT( crPackCanHoldOpcode( pc, 1, (len) ) ); \
|
---|
384 | } \
|
---|
385 | data_ptr = pc->buffer.data_current; \
|
---|
386 | pc->current.vtx_count++; \
|
---|
387 | pc->buffer.data_current += (len); \
|
---|
388 | } while (0)
|
---|
389 |
|
---|
390 |
|
---|
391 | /**
|
---|
392 | * Allocate space for a msg/command that has no arguments, such
|
---|
393 | * as glFinish().
|
---|
394 | */
|
---|
395 | #define CR_GET_BUFFERED_POINTER_NO_ARGS( pc ) \
|
---|
396 | CR_GET_BUFFERED_POINTER( pc, 4 ); \
|
---|
397 | WRITE_DATA( 0, GLuint, 0xdeadbeef )
|
---|
398 |
|
---|
399 | #define WRITE_DATA( offset, type, data ) \
|
---|
400 | *( (type *) (data_ptr + (offset))) = (data)
|
---|
401 |
|
---|
402 | /* Write data to current location and auto increment */
|
---|
403 | #define WRITE_DATA_AI(type, data) \
|
---|
404 | { \
|
---|
405 | *((type*) (data_ptr)) = (data); \
|
---|
406 | data_ptr += sizeof(type); \
|
---|
407 | }
|
---|
408 |
|
---|
409 | #ifdef CR_UNALIGNED_ACCESS_OKAY
|
---|
410 | #define WRITE_DOUBLE( offset, data ) \
|
---|
411 | WRITE_DATA( offset, GLdouble, data )
|
---|
412 | #else
|
---|
413 | # ifndef IN_RING0
|
---|
414 | # define WRITE_DOUBLE( offset, data ) \
|
---|
415 | crWriteUnalignedDouble( data_ptr + (offset), (data) )
|
---|
416 | # else
|
---|
417 | # define WRITE_DOUBLE( offset, data ) \
|
---|
418 | AssertReleaseFailed()
|
---|
419 | # endif
|
---|
420 | #endif
|
---|
421 |
|
---|
422 | #ifndef IN_RING0
|
---|
423 | #define WRITE_SWAPPED_DOUBLE( offset, data ) \
|
---|
424 | crWriteSwappedDouble( data_ptr + (offset), (data) )
|
---|
425 | #else
|
---|
426 | #define WRITE_SWAPPED_DOUBLE( offset, data ) \
|
---|
427 | AssertReleaseFailed()
|
---|
428 | #endif
|
---|
429 |
|
---|
430 | #define WRITE_OPCODE( pc, opcode ) \
|
---|
431 | *(pc->buffer.opcode_current--) = (unsigned char) opcode
|
---|
432 |
|
---|
433 | #define WRITE_NETWORK_POINTER( offset, data ) \
|
---|
434 | crNetworkPointerWrite( (CRNetworkPointer *) ( data_ptr + (offset) ), (data) )
|
---|
435 |
|
---|
436 | #ifdef __cplusplus
|
---|
437 | }
|
---|
438 | #endif
|
---|
439 |
|
---|
440 | #endif /* CR_PACK_H */
|
---|