13 return g
+ "vec" + str(size
)
15 # Get the base dimension - i.e. sampler3D gives 3
16 # Array samplers also get +1 here since the layer is really an extra coordinate
17 def get_coord_dim(sampler_type
):
18 if sampler_type
[0].isdigit():
19 coord_dim
= int(sampler_type
[0])
20 elif sampler_type
.startswith("Cube"):
23 assert False ("coord_dim: invalid sampler_type: " + sampler_type
)
25 if sampler_type
.find("Array") != -1:
29 # Get the number of extra vector components (i.e. shadow comparitor)
30 def get_extra_dim(sampler_type
, use_proj
, unused_fields
):
31 extra_dim
= unused_fields
32 if sampler_type
.find("Shadow") != -1:
38 def generate_sigs(g
, tex_inst
, sampler_type
, use_proj
= False, unused_fields
= 0):
39 coord_dim
= get_coord_dim(sampler_type
)
40 extra_dim
= get_extra_dim(sampler_type
, use_proj
, unused_fields
)
43 print " (signature " + g
+ "vec4"
45 print " (declare (in) " + g
+ "sampler" + sampler_type
+ " sampler)"
46 print " (declare (in) " + vec_type("i" if tex_inst
== "txf" else "", coord_dim
+ extra_dim
) + " P)",
48 print "\n (declare (in) float bias)",
49 elif tex_inst
== "txl":
50 print "\n (declare (in) float lod)",
51 elif tex_inst
== "txf":
52 print "\n (declare (in) int lod)",
53 elif tex_inst
== "txd":
54 grad_type
= vec_type("", coord_dim
)
55 print "\n (declare (in) " + grad_type
+ " dPdx)",
56 print "\n (declare (in) " + grad_type
+ " dPdy)",
58 print ")\n ((return (" + tex_inst
+ " (var_ref sampler)",
62 print "(swiz " + "xyzw"[:coord_dim
] + " (var_ref P))",
72 print "(swiz " + "xyzw"[coord_dim
+ extra_dim
-1] + " (var_ref P))",
77 if sampler_type
== "2DArrayShadow": # a special case:
78 print "(swiz w (var_ref P))", # ...array layer is z; shadow is w
79 elif sampler_type
.endswith("Shadow"):
80 print "(swiz z (var_ref P))",
84 # Bias/explicit LOD/gradient:
86 print "(var_ref bias)",
87 elif tex_inst
== "txl" or tex_inst
== "txf":
88 print "(var_ref lod)",
89 elif tex_inst
== "txd":
90 print "((var_ref dPdx) (var_ref dPdy))",
93 def generate_fiu_sigs(tex_inst
, sampler_type
, use_proj
= False, unused_fields
= 0):
94 generate_sigs("", tex_inst
, sampler_type
, use_proj
, unused_fields
)
95 generate_sigs("i", tex_inst
, sampler_type
, use_proj
, unused_fields
)
96 generate_sigs("u", tex_inst
, sampler_type
, use_proj
, unused_fields
)
98 def start_function(name
):
99 sys
.stdout
= StringIO
.StringIO()
100 print "((function " + name
102 def end_function(fs
, name
):
104 fs
[name
] = sys
.stdout
.getvalue();
107 # Generate all the functions and store them in the supplied dictionary.
108 # This is better than writing them to actual files since they should never be
109 # edited; it'd also be easy to confuse them with the many hand-generated files.
111 # Takes a dictionary as an argument.
112 def generate_texture_functions(fs
):
113 start_function("texture")
114 generate_fiu_sigs("tex", "1D")
115 generate_fiu_sigs("tex", "2D")
116 generate_fiu_sigs("tex", "3D")
117 generate_fiu_sigs("tex", "Cube")
118 generate_fiu_sigs("tex", "1DArray")
119 generate_fiu_sigs("tex", "2DArray")
121 generate_fiu_sigs("txb", "1D")
122 generate_fiu_sigs("txb", "2D")
123 generate_fiu_sigs("txb", "3D")
124 generate_fiu_sigs("txb", "Cube")
125 generate_fiu_sigs("txb", "1DArray")
126 generate_fiu_sigs("txb", "2DArray")
127 end_function(fs
, "texture")
129 start_function("textureProj")
130 generate_fiu_sigs("tex", "1D", True)
131 generate_fiu_sigs("tex", "1D", True, 2)
132 generate_fiu_sigs("tex", "2D", True)
133 generate_fiu_sigs("tex", "2D", True, 1)
134 generate_fiu_sigs("tex", "3D", True)
136 generate_fiu_sigs("txb", "1D", True)
137 generate_fiu_sigs("txb", "1D", True, 2)
138 generate_fiu_sigs("txb", "2D", True)
139 generate_fiu_sigs("txb", "2D", True, 1)
140 generate_fiu_sigs("txb", "3D", True)
141 end_function(fs
, "textureProj")
143 start_function("textureLod")
144 generate_fiu_sigs("txl", "1D")
145 generate_fiu_sigs("txl", "2D")
146 generate_fiu_sigs("txl", "3D")
147 generate_fiu_sigs("txl", "Cube")
148 generate_fiu_sigs("txl", "1DArray")
149 generate_fiu_sigs("txl", "2DArray")
150 end_function(fs
, "textureLod")
152 start_function("texelFetch")
153 generate_fiu_sigs("txf", "1D")
154 generate_fiu_sigs("txf", "2D")
155 generate_fiu_sigs("txf", "3D")
156 generate_fiu_sigs("txf", "1DArray")
157 generate_fiu_sigs("txf", "2DArray")
158 end_function(fs
, "texelFetch")
160 start_function("textureProjLod")
161 generate_fiu_sigs("txl", "1D", True)
162 generate_fiu_sigs("txl", "1D", True, 2)
163 generate_fiu_sigs("txl", "2D", True)
164 generate_fiu_sigs("txl", "2D", True, 1)
165 generate_fiu_sigs("txl", "3D", True)
166 end_function(fs
, "textureProjLod")
168 start_function("textureGrad")
169 generate_fiu_sigs("txd", "1D")
170 generate_fiu_sigs("txd", "2D")
171 generate_fiu_sigs("txd", "3D")
172 generate_fiu_sigs("txd", "Cube")
173 generate_fiu_sigs("txd", "1DArray")
174 generate_fiu_sigs("txd", "2DArray")
175 end_function(fs
, "textureGrad")
177 start_function("textureProjGrad")
178 generate_fiu_sigs("txd", "1D", True)
179 generate_fiu_sigs("txd", "1D", True, 2)
180 generate_fiu_sigs("txd", "2D", True)
181 generate_fiu_sigs("txd", "2D", True, 1)
182 generate_fiu_sigs("txd", "3D", True)
183 end_function(fs
, "textureProjGrad")
185 # ARB_texture_rectangle extension
186 start_function("texture2DRect")
187 generate_sigs("", "tex", "2DRect")
188 end_function(fs
, "texture2DRect")
190 start_function("texture2DRectProj")
191 generate_sigs("", "tex", "2DRect", True)
192 generate_sigs("", "tex", "2DRect", True, 1)
193 end_function(fs
, "texture2DRectProj")
195 start_function("shadow2DRect")
196 generate_sigs("", "tex", "2DRectShadow")
197 end_function(fs
, "shadow2DRect")
199 start_function("shadow2DRectProj")
200 generate_sigs("", "tex", "2DRectShadow", True)
201 end_function(fs
, "shadow2DRectProj")
203 # EXT_texture_array extension
204 start_function("texture1DArray")
205 generate_sigs("", "tex", "1DArray")
206 generate_sigs("", "txb", "1DArray")
207 end_function(fs
, "texture1DArray")
209 start_function("texture1DArrayLod")
210 generate_sigs("", "txl", "1DArray")
211 end_function(fs
, "texture1DArrayLod")
213 start_function("texture2DArray")
214 generate_sigs("", "tex", "2DArray")
215 generate_sigs("", "txb", "2DArray")
216 end_function(fs
, "texture2DArray")
218 start_function("texture2DArrayLod")
219 generate_sigs("", "txl", "2DArray")
220 end_function(fs
, "texture2DArrayLod")
222 start_function("shadow1DArray")
223 generate_sigs("", "tex", "1DArrayShadow")
224 generate_sigs("", "txb", "1DArrayShadow")
225 end_function(fs
, "shadow1DArray")
227 start_function("shadow1DArrayLod")
228 generate_sigs("", "txl", "1DArrayShadow")
229 end_function(fs
, "shadow1DArrayLod")
231 start_function("shadow2DArray")
232 generate_sigs("", "tex", "2DArrayShadow")
233 end_function(fs
, "shadow2DArray")
235 # Deprecated (110/120 style) functions with silly names:
236 start_function("texture1D")
237 generate_sigs("", "tex", "1D")
238 generate_sigs("", "txb", "1D")
239 end_function(fs
, "texture1D")
241 start_function("texture1DLod")
242 generate_sigs("", "txl", "1D")
243 end_function(fs
, "texture1DLod")
245 start_function("texture1DProj")
246 generate_sigs("", "tex", "1D", True)
247 generate_sigs("", "tex", "1D", True, 2)
248 generate_sigs("", "txb", "1D", True)
249 generate_sigs("", "txb", "1D", True, 2)
250 end_function(fs
, "texture1DProj")
252 start_function("texture1DProjLod")
253 generate_sigs("", "txl", "1D", True)
254 generate_sigs("", "txl", "1D", True, 2)
255 end_function(fs
, "texture1DProjLod")
257 start_function("texture2D")
258 generate_sigs("", "tex", "2D")
259 generate_sigs("", "txb", "2D")
260 end_function(fs
, "texture2D")
262 start_function("texture2DLod")
263 generate_sigs("", "txl", "2D")
264 end_function(fs
, "texture2DLod")
266 start_function("texture2DProj")
267 generate_sigs("", "tex", "2D", True)
268 generate_sigs("", "tex", "2D", True, 1)
269 generate_sigs("", "txb", "2D", True)
270 generate_sigs("", "txb", "2D", True, 1)
271 end_function(fs
, "texture2DProj")
273 start_function("texture2DProjLod")
274 generate_sigs("", "txl", "2D", True)
275 generate_sigs("", "txl", "2D", True, 1)
276 end_function(fs
, "texture2DProjLod")
278 start_function("texture3D")
279 generate_sigs("", "tex", "3D")
280 generate_sigs("", "txb", "3D")
281 end_function(fs
, "texture3D")
283 start_function("texture3DLod")
284 generate_sigs("", "txl", "3D")
285 end_function(fs
, "texture3DLod")
287 start_function("texture3DProj")
288 generate_sigs("", "tex", "3D", True)
289 generate_sigs("", "txb", "3D", True)
290 end_function(fs
, "texture3DProj")
292 start_function("texture3DProjLod")
293 generate_sigs("", "txl", "3D", True)
294 end_function(fs
, "texture3DProjLod")
296 start_function("textureCube")
297 generate_sigs("", "tex", "Cube")
298 generate_sigs("", "txb", "Cube")
299 end_function(fs
, "textureCube")
301 start_function("textureCubeLod")
302 generate_sigs("", "txl", "Cube")
303 end_function(fs
, "textureCubeLod")
305 start_function("shadow1D")
306 generate_sigs("", "tex", "1DShadow", False, 1)
307 generate_sigs("", "txb", "1DShadow", False, 1)
308 end_function(fs
, "shadow1D")
310 start_function("shadow1DLod")
311 generate_sigs("", "txl", "1DShadow", False, 1)
312 end_function(fs
, "shadow1DLod")
314 start_function("shadow1DProj")
315 generate_sigs("", "tex", "1DShadow", True, 1)
316 generate_sigs("", "txb", "1DShadow", True, 1)
317 end_function(fs
, "shadow1DProj")
319 start_function("shadow1DProjLod")
320 generate_sigs("", "txl", "1DShadow", True, 1)
321 end_function(fs
, "shadow1DProjLod")
323 start_function("shadow2D")
324 generate_sigs("", "tex", "2DShadow")
325 generate_sigs("", "txb", "2DShadow")
326 end_function(fs
, "shadow2D")
328 start_function("shadow2DLod")
329 generate_sigs("", "txl", "2DShadow")
330 end_function(fs
, "shadow2DLod")
332 start_function("shadow2DProj")
333 generate_sigs("", "tex", "2DShadow", True)
334 generate_sigs("", "txb", "2DShadow", True)
335 end_function(fs
, "shadow2DProj")
337 start_function("shadow2DProjLod")
338 generate_sigs("", "txl", "2DShadow", True)
339 end_function(fs
, "shadow2DProjLod")
341 sys
.stdout
= sys
.__stdout
__
344 # If you actually run this script, it'll print out all the functions.
345 if __name__
== "__main__":
347 generate_texture_functions(fs
);
348 for k
, v
in fs
.iteritems():