1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
# Copyright (c) 2001, Stanford University
# All rights reserved.
#
# See the file LICENSE.txt for information on redistributing this software.
import sys
import apiutil
apiutil.CopyrightC()
print """
/* DO NOT EDIT - THIS FILE AUTOMATICALLY GENERATED BY packspu_get.py SCRIPT */
#include "packspu.h"
#include "cr_packfunctions.h"
#include "cr_net.h"
#include "cr_mem.h"
#include "packspu_proto.h"
"""
print """
GLboolean crPackIsPixelStoreParm(GLenum pname)
{
if (pname == GL_UNPACK_ALIGNMENT
|| pname == GL_UNPACK_ROW_LENGTH
|| pname == GL_UNPACK_SKIP_PIXELS
|| pname == GL_UNPACK_LSB_FIRST
|| pname == GL_UNPACK_SWAP_BYTES
#ifdef CR_OPENGL_VERSION_1_2
|| pname == GL_UNPACK_IMAGE_HEIGHT
#endif
|| pname == GL_UNPACK_SKIP_ROWS
|| pname == GL_PACK_ALIGNMENT
|| pname == GL_PACK_ROW_LENGTH
|| pname == GL_PACK_SKIP_PIXELS
|| pname == GL_PACK_LSB_FIRST
|| pname == GL_PACK_SWAP_BYTES
#ifdef CR_OPENGL_VERSION_1_2
|| pname == GL_PACK_IMAGE_HEIGHT
#endif
|| pname == GL_PACK_SKIP_ROWS)
{
return GL_TRUE;
}
return GL_FALSE;
}
"""
from get_sizes import *
easy_swaps = {
'GenTextures': '(unsigned int) n',
'GetClipPlane': '4',
'GetPolygonStipple': '0'
}
simple_funcs = [ 'GetIntegerv', 'GetFloatv', 'GetDoublev', 'GetBooleanv' ]
simple_swaps = [ 'SWAP32', 'SWAPFLOAT', 'SWAPDOUBLE', '(GLboolean) SWAP32' ]
hard_funcs = {
'GetLightfv': 'SWAPFLOAT',
'GetLightiv': 'SWAP32',
'GetMaterialfv': 'SWAPFLOAT',
'GetMaterialiv': 'SWAP32',
'GetTexEnvfv': 'SWAPFLOAT',
'GetTexEnviv': 'SWAP32',
'GetTexGendv': 'SWAPDOUBLE',
'GetTexGenfv': 'SWAPFLOAT',
'GetTexGeniv': 'SWAP32',
'GetTexLevelParameterfv': 'SWAPFLOAT',
'GetTexLevelParameteriv': 'SWAP32',
'GetTexParameterfv': 'SWAPFLOAT',
'GetTexParameteriv': 'SWAP32' }
keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt")
for func_name in keys:
params = apiutil.Parameters(func_name)
return_type = apiutil.ReturnType(func_name)
if apiutil.FindSpecial( "packspu", func_name ):
continue
if "get" in apiutil.Properties(func_name):
print '%s PACKSPU_APIENTRY packspu_%s( %s )' % ( return_type, func_name, apiutil.MakeDeclarationString( params ) )
print '{'
print '\tGET_THREAD(thread);'
print '\tint writeback = 1;'
if return_type != 'void':
print '\t%s return_val = (%s) 0;' % (return_type, return_type)
params.append( ("&return_val", "foo", 0) )
if (func_name in easy_swaps.keys() and easy_swaps[func_name] != '0') or func_name in simple_funcs or func_name in hard_funcs.keys():
print '\tunsigned int i;'
print '\tif (!CRPACKSPU_IS_WDDM_CRHGSMI() && !(pack_spu.thread[pack_spu.idxThreadInUse].netServer.conn->actual_network))'
print '\t{'
print '\t\tcrError( "packspu_%s doesn\'t work when there\'s no actual network involved!\\nTry using the simplequery SPU in your chain!" );' % func_name
print '\t}'
if func_name in simple_funcs:
print """
if (crPackIsPixelStoreParm(pname)
|| pname == GL_DRAW_BUFFER
#ifdef CR_OPENGL_VERSION_1_3
|| pname == GL_ACTIVE_TEXTURE
#endif
#ifdef CR_ARB_multitexture
|| pname == GL_ACTIVE_TEXTURE_ARB
#endif
|| pname == GL_TEXTURE_BINDING_1D
|| pname == GL_TEXTURE_BINDING_2D
#ifdef CR_NV_texture_rectangle
|| pname == GL_TEXTURE_BINDING_RECTANGLE_NV
#endif
#ifdef CR_ARB_texture_cube_map
|| pname == GL_TEXTURE_BINDING_CUBE_MAP_ARB
#endif
#ifdef CR_ARB_vertex_program
|| pname == GL_MAX_VERTEX_ATTRIBS_ARB
#endif
#ifndef GL_EXT_framebuffer_object
|| pname == GL_FRAMEBUFFER_BINDING_EXT
|| pname == GL_READ_FRAMEBUFFER_BINDING_EXT
|| pname == GL_DRAW_FRAMEBUFFER_BINDING_EXT
#endif
)
{
#ifdef DEBUG
if (!crPackIsPixelStoreParm(pname)
#ifdef CR_ARB_vertex_program
&& (pname!=GL_MAX_VERTEX_ATTRIBS_ARB)
#endif
)
{
%s localparams;
localparams = (%s) crAlloc(__numValues(pname) * sizeof(*localparams));
crState%s(pname, localparams);
crPack%s(%s, &writeback);
packspuFlush( (void *) thread );
CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
for (i=0; i<__numValues(pname); ++i)
{
if (localparams[i] != params[i])
{
crWarning("Incorrect local state in %s for %%x param %%i", pname, i);
crWarning("Expected %%i but got %%i", (int)localparams[i], (int)params[i]);
}
}
crFree(localparams);
return;
}
else
#endif
{
crState%s(pname, params);
return;
}
}
""" % (params[-1][1], params[-1][1], func_name, func_name, apiutil.MakeCallString(params), func_name, func_name)
params.append( ("&writeback", "foo", 0) )
print '\tif (pack_spu.swap)'
print '\t{'
print '\t\tcrPack%sSWAP( %s );' % (func_name, apiutil.MakeCallString( params ) )
print '\t}'
print '\telse'
print '\t{'
print '\t\tcrPack%s( %s );' % (func_name, apiutil.MakeCallString( params ) )
print '\t}'
print '\tpackspuFlush( (void *) thread );'
print '\tCRPACKSPU_WRITEBACK_WAIT(thread, writeback);'
lastParamName = params[-2][0]
if return_type != 'void':
print '\tif (pack_spu.swap)'
print '\t{'
print '\t\treturn_val = (%s) SWAP32(return_val);' % return_type
print '\t}'
print '\treturn return_val;'
if func_name in easy_swaps.keys() and easy_swaps[func_name] != '0':
limit = easy_swaps[func_name]
print '\tif (pack_spu.swap)'
print '\t{'
print '\t\tfor (i = 0 ; i < %s ; i++)' % limit
print '\t\t{'
if params[-2][1].find( "double" ) > -1:
print '\t\t\t%s[i] = SWAPDOUBLE(%s[i]);' % (lastParamName, lastParamName)
else:
print '\t\t\t%s[i] = SWAP32(%s[i]);' % (lastParamName, lastParamName)
print '\t\t}'
print '\t}'
for index in range(len(simple_funcs)):
if simple_funcs[index] == func_name:
print '\tif (pack_spu.swap)'
print '\t{'
print '\t\tfor (i = 0 ; i < __numValues( pname ) ; i++)'
print '\t\t{'
if simple_swaps[index] == 'SWAPDOUBLE':
print '\t\t\t%s[i] = %s(%s[i]);' % (lastParamName, simple_swaps[index], lastParamName)
else:
print '\t\t\t((GLuint *) %s)[i] = %s(%s[i]);' % (lastParamName, simple_swaps[index], lastParamName)
print '\t\t}'
print '\t}'
if func_name in hard_funcs.keys():
print '\tif (pack_spu.swap)'
print '\t{'
print '\t\tfor (i = 0 ; i < crStateHlpComponentsCount(pname) ; i++)'
print '\t\t{'
if hard_funcs[func_name] == 'SWAPDOUBLE':
print '\t\t\t%s[i] = %s(%s[i]);' % (lastParamName, hard_funcs[func_name], lastParamName)
else:
print '\t\t\t((GLuint *) %s)[i] = %s(%s[i]);' % (lastParamName, hard_funcs[func_name], lastParamName)
print '\t\t}'
print '\t}'
print '}\n'
|