X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=scripts%2Fbuiltin_funcs.py;h=24cc3643c418eb6a7b106b7be609dd5c7977af8b;hp=0022f40c7e5125c9db01d9826f05f084e085ab59;hb=305b62cf4f7e2a4ca3cc56109003aed6bde61c25;hpb=9e44b553e200a9377901bd8e4c9de2b1465ec86a diff --git a/scripts/builtin_funcs.py b/scripts/builtin_funcs.py index 0022f40c..24cc3643 100755 --- a/scripts/builtin_funcs.py +++ b/scripts/builtin_funcs.py @@ -41,6 +41,7 @@ traits = { float32vectypes = ("vec2", "vec3", "vec4") float32types = ("float",)+float32vectypes +floatvectypes = float32vectypes floattypes = float32types int32vectypes = ("ivec2", "ivec3", "ivec4") int32types = ("int",)+int32vectypes @@ -91,28 +92,23 @@ shared_funcs = [ ("T ceil(T x)", floattypes), ("T fract(T x)", floattypes), ("T mod(T x, T y)", floattypes), - ("T mod(T x, T::Base y)", floattypes), - ("T modf(T x, out T y)", floattypes), + ("T mod(T x, T::Base y)", "mod(x, T(y))", floatvectypes), ("T min(T x, T y)", arithmetictypes), - ("T min(T x, T::Base y)", arithmetictypes), + ("T min(T x, T::Base y)", "min(x, T(y))", arithmeticvectypes), ("T max(T x, T y)", arithmetictypes), - ("T max(T x, T::Base y)", arithmetictypes), + ("T max(T x, T::Base y)", "max(x, T(y))", arithmeticvectypes), ("T clamp(T x, T minVal, T maxVal)", arithmetictypes), - ("T clamp(T x, T::Base minVal, T::Base maxVal)", arithmetictypes), + ("T clamp(T x, T::Base minVal, T::Base maxVal)", "clamp(x, T(minVal), T(maxVal))", arithmeticvectypes), ("T mix(T x, T y, T a)", floattypes), - ("T mix(T x, T y, T::Base a)", floattypes), + ("T mix(T x, T y, T::Base a)", "mix(x, y, T(a))", floattypes), ("T mix(T x, T y, bool[T::Dim] a)", arithmetictypes), ("T step(T edge, T x)", floattypes), - ("T step(T::Base edge, T x)", floattypes), + ("T step(T::Base edge, T x)", "step(T(edge), x)", floatvectypes), ("T smoothstep(T edge0, T edge1, T x)", floattypes), - ("T smoothstep(T::Base edge0, T::Base edge1, T x)", floattypes), + ("T smoothstep(T::Base edge0, T::Base edge1, T x)", "smoothstep(T(edge0), T(edge1), x)", floatvectypes), ("bool[T::Dim] isnan(T x)", floattypes), ("bool[T::Dim] isinf(T x)", floattypes), - ("int[T::Dim] floatBitsToInt(T value)", float32types), - ("T intBitsToFloat(int[T::Dim] value)", float32types), ("T fma(T a, T b, T c)", floattypes), - ("T frexp(T x, out int[T::Dim] exp)", floattypes), - ("T ldexp(T x, int[T::Dim] exp)", floattypes), # Geometric ("T::Base length(T x)", floattypes), @@ -121,8 +117,8 @@ shared_funcs = [ "vec3 cross(vec3 x)", ("T normalize(T x)", floattypes), ("T faceforward(T N, T I, T Nref)", floattypes), - ("T reflect(T N, T I)", floattypes), - ("T refract(T N, T I, float eta)", floattypes), + ("T reflect(T I, T N)", floattypes), + ("T refract(T I, T N, float eta)", floattypes), # Matrix ("T matrixCompMult(T x, T y)", matrixtypes), @@ -143,7 +139,6 @@ shared_funcs = [ ("bool not(T x)", boolvectypes), # Integer - ("void imulExtended(T x, T y, out T msb, out T lsb)", int32types), ("T bitfieldExtract(T value, int offset, int bits)", int32types), ("T bitfieldInsert(T value, T insert, int offset, int bits)", int32types), ("T bitfieldReverse(T value)", int32types), @@ -156,7 +151,7 @@ shared_funcs = [ ("vec4 texture(T sampler, float[T::CDim] P)", colorsamplertypes), ("float texture(T sampler, float[T::CDim] P)", tuple(s for s in shadowsamplertypes if "CubeArray" not in s)), "float texture(samplerCubeArrayShadow sampler, vec4 P, float compare)", - ("vec4 textureLod(T sampler, float[T::CDim] P)", colorsamplertypes), + ("vec4 textureLod(T sampler, float[T::CDim] P, float lod)", colorsamplertypes), ("vec4 texelFetch(T sampler, int[T::CDim] P, int lod)", flatsamplertypes) ] @@ -235,10 +230,9 @@ def expand_template(template, gentype): result += " " special = not t[0].isalpha() - if t==",": - result += ", " - else: - result += t + result += t + if t[-1]==",": + result += " " i += advance @@ -249,10 +243,14 @@ def generate_functions(funcs): generated = set() for f in funcs: if type(f)==tuple: - for t in f[1]: + for t in f[-1]: decl = expand_template(f[0], t) + if len(f)>=3: + decl += " {{ return {}; }}".format(expand_template(f[1], t)) + else: + decl += ";" if not decl in generated: - out_lines.append(decl+";\n") + out_lines.append(decl+"\n") generated.add(decl) else: out_lines.append(f+";\n")