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 builtins_dir
= path
.join(path
.dirname(path
.abspath(__file__
)), "..")
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")
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")
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)
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)
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")
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")
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)
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")
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)
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")
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")
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")
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)
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)