texture_builtins.py: Fix cut and paste errors in function names.
[mesa.git] / src / glsl / builtins / tools / texture_builtins.py
1 #!/usr/bin/python
2
3 from os import path
4 import sys
5
6 def vec_type(g, size):
7 if size == 1:
8 if g == "i":
9 return "int"
10 elif g == "u":
11 return "uint"
12 return "float"
13 return g + "vec" + str(size)
14
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"):
21 coord_dim = 3
22 else:
23 assert False ("coord_dim: invalid sampler_type: " + sampler_type)
24
25 if sampler_type.find("Array") != -1:
26 coord_dim += 1
27 return coord_dim
28
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:
33 extra_dim += 1
34 if use_proj:
35 extra_dim += 1
36 return extra_dim
37
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)
41
42 # Print parameters
43 print " (signature " + g + "vec4"
44 print " (parameters"
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)",
47 if tex_inst == "txb":
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)",
57
58 print ")\n ((return (" + tex_inst + " (var_ref sampler)",
59
60 # Coordinate
61 if extra_dim > 0:
62 print "(swiz " + "xyzw"[:coord_dim] + " (var_ref P))",
63 else:
64 print "(var_ref P)",
65
66 # Offset
67 print "(0 0 0)",
68
69 if tex_inst != "txf":
70 # Projective divisor
71 if use_proj:
72 print "(swiz " + "xyzw"[coord_dim + extra_dim-1] + " (var_ref P))",
73 else:
74 print "1",
75
76 # Shadow comparitor
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))",
81 else:
82 print "()",
83
84 # Bias/explicit LOD/gradient:
85 if tex_inst == "txb":
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))",
91 print "))))\n"
92
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)
97
98 builtins_dir = path.join(path.dirname(path.abspath(__file__)), "..")
99
100 with open(path.join(builtins_dir, "130", "texture"), 'w') as sys.stdout:
101 print "((function texture"
102 generate_fiu_sigs("tex", "1D")
103 generate_fiu_sigs("tex", "2D")
104 generate_fiu_sigs("tex", "3D")
105 generate_fiu_sigs("tex", "Cube")
106 generate_fiu_sigs("tex", "1DArray")
107 generate_fiu_sigs("tex", "2DArray")
108 print "))"
109
110 # txb variants are only allowed within a fragment shader (GLSL 1.30 p. 86)
111 with open(path.join(builtins_dir, "130_fs", "texture"), 'w') as sys.stdout:
112 print "((function texture"
113 generate_fiu_sigs("txb", "1D")
114 generate_fiu_sigs("txb", "2D")
115 generate_fiu_sigs("txb", "3D")
116 generate_fiu_sigs("txb", "Cube")
117 generate_fiu_sigs("txb", "1DArray")
118 generate_fiu_sigs("txb", "2DArray")
119 print "))"
120
121 with open(path.join(builtins_dir, "130", "textureProj"), 'w') as sys.stdout:
122 print "((function textureProj"
123 generate_fiu_sigs("tex", "1D", True)
124 generate_fiu_sigs("tex", "1D", True, 2)
125 generate_fiu_sigs("tex", "2D", True)
126 generate_fiu_sigs("tex", "2D", True, 1)
127 generate_fiu_sigs("tex", "3D", True)
128 print "))"
129
130 with open(path.join(builtins_dir, "130_fs", "textureProj"), 'w') as sys.stdout:
131 print "((function textureProj"
132 generate_fiu_sigs("txb", "1D", True)
133 generate_fiu_sigs("txb", "1D", True, 2)
134 generate_fiu_sigs("txb", "2D", True)
135 generate_fiu_sigs("txb", "2D", True, 1)
136 generate_fiu_sigs("txb", "3D", True)
137 print "))"
138
139 with open(path.join(builtins_dir, "130", "textureLod"), 'w') as sys.stdout:
140 print "((function textureLod"
141 generate_fiu_sigs("txl", "1D")
142 generate_fiu_sigs("txl", "2D")
143 generate_fiu_sigs("txl", "3D")
144 generate_fiu_sigs("txl", "Cube")
145 generate_fiu_sigs("txl", "1DArray")
146 generate_fiu_sigs("txl", "2DArray")
147 print "))"
148
149 with open(path.join(builtins_dir, "130", "texelFetch"), 'w') as sys.stdout:
150 print "((function texelFetch"
151 generate_fiu_sigs("txf", "1D")
152 generate_fiu_sigs("txf", "2D")
153 generate_fiu_sigs("txf", "3D")
154 generate_fiu_sigs("txf", "1DArray")
155 generate_fiu_sigs("txf", "2DArray")
156 print "))"
157
158 with open(path.join(builtins_dir, "130", "textureProjLod"), 'w') as sys.stdout:
159 print "((function textureProjLod"
160 generate_fiu_sigs("txl", "1D", True)
161 generate_fiu_sigs("txl", "1D", True, 2)
162 generate_fiu_sigs("txl", "2D", True)
163 generate_fiu_sigs("txl", "2D", True, 1)
164 generate_fiu_sigs("txl", "3D", True)
165 print "))"
166
167 with open(path.join(builtins_dir, "130", "textureGrad"), 'w') as sys.stdout:
168 print "((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 print ")\n)"
176
177 with open(path.join(builtins_dir, "130", "textureProjGrad"), 'w') as sys.stdout:
178 print "((function textureProjGrad"
179 generate_fiu_sigs("txd", "1D", True)
180 generate_fiu_sigs("txd", "1D", True, 2)
181 generate_fiu_sigs("txd", "2D", True)
182 generate_fiu_sigs("txd", "2D", True, 1)
183 generate_fiu_sigs("txd", "3D", True)
184 print "))"
185
186 # ARB_texture_rectangle extension
187 with open(path.join(builtins_dir, "ARB_texture_rectangle", "textures"), 'w') as sys.stdout:
188 print "((function texture2DRect"
189 generate_sigs("", "tex", "2DRect")
190 print ")\n (function shadow2DRect"
191 generate_sigs("", "tex", "2DRectShadow")
192 print "))"
193
194 # EXT_texture_array extension
195 with open(path.join(builtins_dir, "EXT_texture_array", "textures"), 'w') as sys.stdout:
196 print "((function texture1DArray"
197 generate_sigs("", "tex", "1DArray")
198 print ")\n (function texture1DArrayLod"
199 generate_sigs("", "txl", "1DArray")
200 print ")\n (function texture2DArray"
201 generate_sigs("", "tex", "2DArray")
202 print ")\n (function texture2DArrayLod"
203 generate_sigs("", "txl", "2DArray")
204 print ")\n (function shadow1DArray"
205 generate_sigs("", "tex", "1DArrayShadow")
206 print ")\n (function shadow1DArrayLod"
207 generate_sigs("", "txl", "1DArrayShadow")
208 print ")\n (function shadow2DArray"
209 generate_sigs("", "tex", "2DArrayShadow")
210 print "))"
211
212 with open(path.join(builtins_dir, "EXT_texture_array_fs", "textures"), 'w') as sys.stdout:
213 print "((function texture1DArray"
214 generate_sigs("", "txb", "1DArray") # MOVE TO _fs
215 print ")\n (function texture2DArray"
216 generate_sigs("", "txb", "2DArray") # MOVE TO _fs
217 print ")\n (function shadow1DArray"
218 generate_sigs("", "txb", "1DArrayShadow")
219 print "))"
220
221 # Deprecated (110/120 style) functions with silly names:
222 with open(path.join(builtins_dir, "110", "textures"), 'w') as sys.stdout:
223 print "((function texture1D"
224 generate_sigs("", "tex", "1D")
225 print ")\n (function texture1DLod"
226 generate_sigs("", "txl", "1D")
227 print ")\n (function texture1DProj"
228 generate_sigs("", "tex", "1D", True)
229 generate_sigs("", "tex", "1D", True, 2)
230 print ")\n (function texture1DProjLod"
231 generate_sigs("", "txl", "1D", True)
232 generate_sigs("", "txl", "1D", True, 2)
233 print ")\n (function texture2D"
234 generate_sigs("", "tex", "2D")
235 print ")\n(function texture2DLod"
236 generate_sigs("", "txl", "2D")
237 print ")\n (function texture2DProj"
238 generate_sigs("", "tex", "2D", True)
239 generate_sigs("", "tex", "2D", True, 1)
240 print ")\n (function texture2DProjLod"
241 generate_sigs("", "txl", "2D", True)
242 generate_sigs("", "txl", "2D", True, 1)
243 print ")\n (function texture3D"
244 generate_sigs("", "tex", "3D")
245 print ")\n (function texture3DLod"
246 generate_sigs("", "txl", "3D")
247 print ")\n (function texture3DProj"
248 generate_sigs("", "tex", "3D", True)
249 print ")\n (function texture3DProjLod"
250 generate_sigs("", "txl", "3D", True)
251 print ")\n (function textureCube"
252 generate_sigs("", "tex", "Cube")
253 print ")\n (function textureCubeLod"
254 generate_sigs("", "txl", "Cube")
255 print ")\n (function shadow1D"
256 generate_sigs("", "tex", "1DShadow", False, 1)
257 print ")\n (function shadow1DLod"
258 generate_sigs("", "txl", "1DShadow", False, 1)
259 print ")\n (function shadow1DProj"
260 generate_sigs("", "tex", "1DShadow", True, 1)
261 print ")\n (function shadow1DProjLod"
262 generate_sigs("", "txl", "1DShadow", True, 1)
263 print ")\n (function shadow2D"
264 generate_sigs("", "tex", "2DShadow")
265 print ")\n (function shadow2DLod"
266 generate_sigs("", "txl", "2DShadow")
267 print ")\n (function shadow2DProj"
268 generate_sigs("", "tex", "2DShadow", True)
269 print ")\n (function shadow2DProjLod"
270 generate_sigs("", "txl", "2DShadow", True)
271 print "))"
272
273 with open(path.join(builtins_dir, "110_fs", "textures"), 'w') as sys.stdout:
274 print "((function texture1D"
275 generate_sigs("", "txb", "1D")
276 print ")\n (function texture1DProj"
277 generate_sigs("", "txb", "1D", True)
278 generate_sigs("", "txb", "1D", True, 2)
279 print ")\n (function texture2D"
280 generate_sigs("", "txb", "2D")
281 print ")\n (function texture2DProj"
282 generate_sigs("", "txb", "2D", True)
283 generate_sigs("", "txb", "2D", True, 1)
284 print ")\n (function texture3D"
285 generate_sigs("", "txb", "3D")
286 print ")\n (function texture3DProj"
287 generate_sigs("", "txb", "3D", True)
288 print ")\n (function textureCube"
289 generate_sigs("", "txb", "Cube")
290 print ")\n (function shadow1D"
291 generate_sigs("", "txb", "1DShadow", False, 1)
292 print ")\n (function shadow1DProj"
293 generate_sigs("", "txb", "1DShadow", True, 1)
294 print ")\n (function shadow2D"
295 generate_sigs("", "txb", "2DShadow")
296 print ")\n (function shadow2DProj"
297 generate_sigs("", "txb", "2DShadow", True)
298 print "))"