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 | import sys
|
---|
7 |
|
---|
8 | import apiutil
|
---|
9 |
|
---|
10 |
|
---|
11 | apiutil.CopyrightC()
|
---|
12 |
|
---|
13 | print """/* DO NOT EDIT - AUTOMATICALLY GENERATED BY packspu_beginend.py */
|
---|
14 | #include "packspu.h"
|
---|
15 | #include "assert.h"
|
---|
16 | #include "cr_packfunctions.h"
|
---|
17 | #include "packspu_proto.h"
|
---|
18 |
|
---|
19 | void PACKSPU_APIENTRY packspu_Begin( GLenum mode )
|
---|
20 | {
|
---|
21 | GET_THREAD(thread);
|
---|
22 | CRPackBuffer *buf = &thread->BeginEndBuffer;
|
---|
23 |
|
---|
24 | /* XXX comparing mode >= 0 here is not needed since mode is unsigned */
|
---|
25 | CRASSERT( mode >= GL_POINTS && mode <= GL_POLYGON );
|
---|
26 |
|
---|
27 | #if CR_ARB_vertex_buffer_object
|
---|
28 | {
|
---|
29 | GLboolean serverArrays = GL_FALSE;
|
---|
30 | GET_CONTEXT(ctx);
|
---|
31 | if (ctx->clientState->extensions.ARB_vertex_buffer_object)
|
---|
32 | serverArrays = crStateUseServerArrays();
|
---|
33 | if (serverArrays) {
|
---|
34 | CRClientState *clientState = &(ctx->clientState->client);
|
---|
35 | if (clientState->array.locked && !clientState->array.synced)
|
---|
36 | {
|
---|
37 | crPackLockArraysEXT(clientState->array.lockFirst, clientState->array.lockCount);
|
---|
38 | clientState->array.synced = GL_TRUE;
|
---|
39 | }
|
---|
40 | }
|
---|
41 | }
|
---|
42 | #endif
|
---|
43 |
|
---|
44 | if (pack_spu.swap)
|
---|
45 | {
|
---|
46 | crPackBeginSWAP( mode );
|
---|
47 | }
|
---|
48 | else
|
---|
49 | {
|
---|
50 | crPackBegin( mode );
|
---|
51 | }
|
---|
52 |
|
---|
53 | if ( thread->netServer.conn->Barf ) {
|
---|
54 | thread->BeginEndMode = mode;
|
---|
55 | thread->BeginEndState = -1;
|
---|
56 | if ( mode == GL_LINES || mode == GL_TRIANGLES || mode == GL_QUADS || mode == GL_POLYGON )
|
---|
57 | {
|
---|
58 | CRASSERT(!buf->pack);
|
---|
59 |
|
---|
60 | crPackReleaseBuffer( thread->packer );
|
---|
61 | buf->pack = crNetAlloc( thread->netServer.conn );
|
---|
62 | crPackInitBuffer( buf, buf->pack, thread->netServer.conn->buffer_size, thread->netServer.conn->mtu );
|
---|
63 | buf->holds_BeginEnd = 1;
|
---|
64 | buf->in_BeginEnd = 1;
|
---|
65 | crPackSetBuffer( thread->packer, buf );
|
---|
66 |
|
---|
67 | thread->BeginEndState = 0;
|
---|
68 | }
|
---|
69 | }
|
---|
70 | }
|
---|
71 |
|
---|
72 | void PACKSPU_APIENTRY packspu_End( void )
|
---|
73 | {
|
---|
74 | GET_THREAD(thread);
|
---|
75 | CRPackBuffer *buf = &thread->BeginEndBuffer;
|
---|
76 |
|
---|
77 | if ( thread->netServer.conn->Barf &&
|
---|
78 | (thread->BeginEndMode == GL_LINES
|
---|
79 | || thread->BeginEndMode == GL_TRIANGLES
|
---|
80 | || thread->BeginEndMode == GL_QUADS
|
---|
81 | || thread->BeginEndMode == GL_POLYGON ) )
|
---|
82 | {
|
---|
83 | CRASSERT(buf->pack);
|
---|
84 |
|
---|
85 | crPackReleaseBuffer( thread->packer );
|
---|
86 | crPackSetBuffer( thread->packer, &thread->normBuffer );
|
---|
87 | if ( !crPackCanHoldBuffer( buf ) )
|
---|
88 | packspuFlush( (void *) thread );
|
---|
89 |
|
---|
90 | crPackAppendBuffer( buf );
|
---|
91 | crNetFree( thread->netServer.conn, buf->pack );
|
---|
92 | buf->pack = NULL;
|
---|
93 | }
|
---|
94 |
|
---|
95 | if (pack_spu.swap)
|
---|
96 | {
|
---|
97 | crPackEndSWAP();
|
---|
98 | }
|
---|
99 | else
|
---|
100 | {
|
---|
101 | crPackEnd();
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | static void DoVertex( void )
|
---|
106 | {
|
---|
107 | GET_THREAD(thread);
|
---|
108 | CRPackBuffer *buf = &thread->BeginEndBuffer;
|
---|
109 | CRPackBuffer *gbuf = &thread->normBuffer;
|
---|
110 | int num_data;
|
---|
111 | int num_opcode;
|
---|
112 |
|
---|
113 | /*crDebug( "really doing Vertex" );*/
|
---|
114 | crPackReleaseBuffer( thread->packer );
|
---|
115 | num_data = buf->data_current - buf->data_start;
|
---|
116 | num_opcode = buf->opcode_start - buf->opcode_current;
|
---|
117 | crPackSetBuffer( thread->packer, gbuf );
|
---|
118 | if ( !crPackCanHoldBuffer( buf ) )
|
---|
119 | /* doesn't hold, first flush gbuf*/
|
---|
120 | packspuFlush( (void *) thread );
|
---|
121 |
|
---|
122 | crPackAppendBuffer( buf );
|
---|
123 | crPackReleaseBuffer( thread->packer );
|
---|
124 | crPackSetBuffer( thread->packer, buf );
|
---|
125 | crPackResetPointers(thread->packer);
|
---|
126 | }
|
---|
127 |
|
---|
128 | static void RunState( void )
|
---|
129 | {
|
---|
130 | GET_THREAD(thread);
|
---|
131 | if (! thread->netServer.conn->Barf ) return;
|
---|
132 | if (thread->BeginEndState == -1) return;
|
---|
133 | switch(thread->BeginEndMode) {
|
---|
134 | case GL_POLYGON:
|
---|
135 | return;
|
---|
136 | case GL_LINES:
|
---|
137 | thread->BeginEndState = (thread->BeginEndState + 1) % 2;
|
---|
138 | if (thread->BeginEndState)
|
---|
139 | return;
|
---|
140 | break;
|
---|
141 | case GL_TRIANGLES:
|
---|
142 | thread->BeginEndState = (thread->BeginEndState + 1) % 3;
|
---|
143 | if (thread->BeginEndState)
|
---|
144 | return;
|
---|
145 | break;
|
---|
146 | case GL_QUADS:
|
---|
147 | thread->BeginEndState = (thread->BeginEndState + 1) % 4;
|
---|
148 | if (thread->BeginEndState)
|
---|
149 | return;
|
---|
150 | break;
|
---|
151 | }
|
---|
152 | DoVertex();
|
---|
153 | }
|
---|
154 | """
|
---|
155 |
|
---|
156 | keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt")
|
---|
157 |
|
---|
158 | for func_name in apiutil.AllSpecials( "packspu_vertex" ):
|
---|
159 | params = apiutil.Parameters(func_name)
|
---|
160 | print 'void PACKSPU_APIENTRY packspu_%s( %s )' % ( func_name, apiutil.MakeDeclarationString(params) )
|
---|
161 | print '{'
|
---|
162 | print '\tif (pack_spu.swap)'
|
---|
163 | print '\t{'
|
---|
164 | print '\t\tcrPack%sSWAP( %s );' % ( func_name, apiutil.MakeCallString( params ) )
|
---|
165 | print '\t}'
|
---|
166 | print '\telse'
|
---|
167 | print '\t{'
|
---|
168 | print '\t\tcrPack%s( %s );' % ( func_name, apiutil.MakeCallString( params ) )
|
---|
169 | print '\t}'
|
---|
170 | print '\tRunState();'
|
---|
171 | print '}'
|
---|