diff --git a/.gitignore b/.gitignore index d059ea13..c0069465 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ old_scripts/ dist/lib/ dist/truss dist/truss.exe +dist/save *.exe *.pdb *.idb @@ -19,3 +20,6 @@ dist/truss.exe *.bin *.ilk trusslog.txt +shader_errors.txt +console_log.txt +error.txt diff --git a/dist/shaders/raw/compile_shaders.py b/dist/shaders/raw/compile_shaders.py index 829af618..2b8af7cf 100644 --- a/dist/shaders/raw/compile_shaders.py +++ b/dist/shaders/raw/compile_shaders.py @@ -3,9 +3,11 @@ # runs shaders in shaders/raw through shaderc to produce # compiled shaders +from __future__ import print_function import sys, os -from os.path import join, isfile +from os.path import join, isfile, normpath import errno +import subprocess def make_sure_path_exists(path): try: @@ -14,45 +16,65 @@ def make_sure_path_exists(path): if exception.errno != errno.EEXIST: raise -dx11cmd_fs = "shadercRelease -f {} -o {} --type f -i common\ --platform windows -p ps_4_0 -O 3" -dx11cmd_vs = "shadercRelease -f {} -o {} --type v -i common\ --platform windows -p vs_4_0 -O 3" - -dx9cmd_fs = "shadercRelease -f {} -o {} --type f -i common\ --platform windows -p ps_3_0 -O 3" -dx9cmd_vs = "shadercRelease -f {} -o {} --type v -i common\ --platform windows -p vs_3_0 -O 3" - -glcmd_fs = "shadercRelease -f {} -o {} --type f -i common\ --platform linux -p 120" -glcmd_vs = "shadercRelease -f {} -o {} --type v -i common\ --platform linux -p 120" +def make_cmd(shader_type, platform, input_fn, output_fn): + if platform == "linux": + args = ["./shadercRelease"] + else: + args = ["shadercRelease"] + args.extend(["-f", input_fn, "-o", output_fn]) + args.extend(["--type", shader_type]) + args.extend(["-i", normpath("common/")]) + args.extend(["--platform", platform]) + if platform == "linux": + args.extend(["-p", "120"]) + elif platform == "windows": + if shader_type == "f": + args.extend(["-p", "ps_4_0"]) + elif shader_type == "v": + args.extend(["-p", "vs_4_0"]) + else: + print("Unknown shader_type {}".format(shader_type)) + return None + args.extend(["-O", "3"]) + else: + print("Unknown platform {}".format(platform)) + return None + return args if os.name == "posix": - cmds_vs = [("./" + glcmd_vs, "glsl")] - cmds_fs = [("./" + glcmd_fs, "glsl")] + platforms = [("linux", "glsl")] else: - cmds_vs = [(dx11cmd_vs, "dx11"), (dx9cmd_vs, "dx9"), (glcmd_vs, "glsl")] - cmds_fs = [(dx11cmd_fs, "dx11"), (dx9cmd_fs, "dx9"), (glcmd_fs, "glsl")] + platforms = [("windows","dx11"), ("linux","glsl")] # compile gl even on windows def make_directories(): - for (cmd, desttype) in cmds_vs: + for platform, desttype in platforms: print("Making sure directory " + desttype + " exists.") make_sure_path_exists(join("..", desttype)) -def processFile(prefix, dirname, filename): - print("Processing {}, {}, {}".format(prefix, dirname, filename)) - - cmds = [] +def processFile(prefix, dirname, filename, errdest, errlist): if prefix == "vs": - cmds = cmds_vs + shader_type = "v" elif prefix == "fs": - cmds = cmds_fs + shader_type = "f" else: print("Unknown prefix {}".format(prefix)) + return -1 infile = join(dirname, filename) - for (cmd, desttype) in cmds: + nerrors = 0 + for platform, desttype in platforms: outfile = join("..", desttype, filename[0:-3] + ".bin") - fullcmd = cmd.format(infile, outfile) - print(fullcmd) - os.system(fullcmd) + cmdargs = make_cmd(shader_type, platform, infile, outfile) + res = subprocess.call(cmdargs, stderr = errdest) + if res > 0: + errname = "{} | {}".format(infile, desttype) + errlist.append(errname) + errdest.write("^^^ Error in {}\n\n\n".format(errname)) + errdest.flush() + nerrors = nerrors + 1 + + return nerrors def listdirs(dirname): allthings = [join(dirname, f) for f in os.listdir(dirname)] @@ -62,17 +84,35 @@ def listfiles(dirname): allthings = os.listdir(dirname) return [ f for f in allthings if isfile(join(dirname, f)) ] +def pad(s, pad_to): + padding = " " * max(0, pad_to - len(s)) + return "{}{}".format(s, padding) + def main(): make_directories() dirs = listdirs(".") + errdest = open("shader_errors.txt", "wt") + errlist = [] for dirname in dirs: files = listfiles(dirname) - print(files) + print(pad(dirname, 30) + " | ", end="") for filename in files: prefix = filename[0:2] suffix = filename[-3:] if suffix == ".sc" and (prefix == "vs" or prefix == "fs"): - processFile(prefix, dirname, filename) + nerrs = processFile(prefix, dirname, filename, errdest, errlist) + if nerrs < 0: + print("?", end="") + elif nerrs == 0: + print(".", end="") + elif nerrs > 0: + print("x", end="") + print("") + errdest.close() + if len(errlist) > 0: + print("Some shaders had errors, see shader_errors.txt for details.") + for errfn in errlist[0:10]: + print(errfn) if __name__ == '__main__': main()