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