68
68
CRPackBuffer *currentBuffer;
69
70
char *file; /**< for debugging only */
70
71
int line; /**< for debugging only */
74
75
extern DECLEXPORT(CRPackContext *) crPackNewContext(int swapping);
76
extern DECLEXPORT(void) crPackDeleteContext(CRPackContext *pc);
75
77
extern DECLEXPORT(void) crPackSetContext( CRPackContext *pc );
76
78
extern DECLEXPORT(CRPackContext *) crPackGetContext( void );
138
140
#ifdef CHROMIUM_THREADSAFE
139
141
extern CRtsd _PackerTSD;
140
#define GET_PACKER_CONTEXT(C) CRPackContext *C = (CRPackContext *) crGetTSD(&_PackerTSD)
142
#define CR_GET_PACKER_CONTEXT(C) CRPackContext *C = (CRPackContext *) crGetTSD(&_PackerTSD)
143
#define CR_LOCK_PACKER_CONTEXT(PC) crLockMutex(&((PC)->mutex))
144
#define CR_UNLOCK_PACKER_CONTEXT(PC) crUnlockMutex(&((PC)->mutex))
142
146
extern DLLDATA(CRPackContext) cr_packer_globals;
143
#define GET_PACKER_CONTEXT(C) CRPackContext *C = &cr_packer_globals
147
#define CR_GET_PACKER_CONTEXT(C) CRPackContext *C = &cr_packer_globals
148
#define CR_LOCK_PACKER_CONTEXT(PC)
149
#define CR_UNLOCK_PACKER_CONTEXT(PC)
188
194
* Alloc space for a message of 'len' bytes (plus 1 opcode).
189
195
* Only flush if buffer is full.
191
#define GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH( pc, len ) \
193
THREADASSERT( pc ); \
194
CRASSERT( pc->currentBuffer ); \
195
if ( !crPackCanHoldOpcode( pc, 1, (len) ) ) { \
196
pc->Flush( pc->flush_arg ); \
197
CRASSERT(crPackCanHoldOpcode( pc, 1, (len) ) ); \
199
data_ptr = pc->buffer.data_current; \
200
pc->buffer.data_current += (len); \
197
#define CR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH(pc, len, lock) \
199
THREADASSERT( pc ); \
200
if (lock) CR_LOCK_PACKER_CONTEXT(pc); \
201
CRASSERT( pc->currentBuffer ); \
202
if ( !crPackCanHoldOpcode( pc, 1, (len) ) ) { \
203
pc->Flush( pc->flush_arg ); \
204
CRASSERT(crPackCanHoldOpcode( pc, 1, (len) ) ); \
206
data_ptr = pc->buffer.data_current; \
207
pc->buffer.data_current += (len); \
205
212
* As above, flush if the buffer contains vertex data and we're
206
213
* no longer inside glBegin/glEnd.
208
#define GET_BUFFERED_POINTER( pc, len ) \
210
CRASSERT( pc->currentBuffer ); \
211
if ( pc->buffer.holds_BeginEnd && !pc->buffer.in_BeginEnd ) { \
212
pc->Flush( pc->flush_arg ); \
213
pc->buffer.holds_BeginEnd = 0; \
215
GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH( pc, len ); \
215
#define CR_GET_BUFFERED_POINTER( pc, len ) \
217
CR_LOCK_PACKER_CONTEXT(pc); \
218
CRASSERT( pc->currentBuffer ); \
219
if ( pc->buffer.holds_BeginEnd && !pc->buffer.in_BeginEnd ) { \
220
pc->Flush( pc->flush_arg ); \
221
pc->buffer.holds_BeginEnd = 0; \
223
CR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH( pc, len, GL_FALSE ); \
227
* As above, but without lock.
229
#define CR_GET_BUFFERED_POINTER_NOLOCK( pc, len ) \
231
CRASSERT( pc->currentBuffer ); \
232
if ( pc->buffer.holds_BeginEnd && !pc->buffer.in_BeginEnd ) { \
233
pc->Flush( pc->flush_arg ); \
234
pc->buffer.holds_BeginEnd = 0; \
236
CR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH( pc, len, GL_FALSE ); \
220
241
* As above, but for vertex data between glBegin/End (counts vertices).
222
#define GET_BUFFERED_COUNT_POINTER( pc, len ) \
224
CRASSERT( pc->currentBuffer ); \
225
if ( !crPackCanHoldOpcode( pc, 1, (len) ) ) { \
226
pc->Flush( pc->flush_arg ); \
243
#define CR_GET_BUFFERED_COUNT_POINTER( pc, len ) \
245
CR_LOCK_PACKER_CONTEXT(pc); \
246
CRASSERT( pc->currentBuffer ); \
247
if ( !crPackCanHoldOpcode( pc, 1, (len) ) ) { \
248
pc->Flush( pc->flush_arg ); \
227
249
CRASSERT( crPackCanHoldOpcode( pc, 1, (len) ) ); \
229
data_ptr = pc->buffer.data_current; \
230
pc->current.vtx_count++; \
231
pc->buffer.data_current += (len); \
251
data_ptr = pc->buffer.data_current; \
252
pc->current.vtx_count++; \
253
pc->buffer.data_current += (len); \
236
258
* Allocate space for a msg/command that has no arguments, such
239
#define GET_BUFFERED_POINTER_NO_ARGS( pc ) \
240
GET_BUFFERED_POINTER( pc, 4 ); \
261
#define CR_GET_BUFFERED_POINTER_NO_ARGS( pc ) \
262
CR_GET_BUFFERED_POINTER( pc, 4 ); \
241
263
WRITE_DATA( 0, GLuint, 0xdeadbeef )
243
265
#define WRITE_DATA( offset, type, data ) \