diff options
-rwxr-xr-x | o3d/cg_to_glsl/convert.py | 31 | ||||
-rw-r--r-- | o3d/converter/cross/converter_main.cc | 1 | ||||
-rw-r--r-- | o3d/import/cross/collada.cc | 10 |
3 files changed, 33 insertions, 9 deletions
diff --git a/o3d/cg_to_glsl/convert.py b/o3d/cg_to_glsl/convert.py index 1aa28f1..570b502 100755 --- a/o3d/cg_to_glsl/convert.py +++ b/o3d/cg_to_glsl/convert.py @@ -24,13 +24,15 @@ import sys # * prints the results to standard output, separating them with SplitMarker # instruction and keeping the MatrixLoadOrder instruction as is. +# Cygwin lies about the OS name ("posix" instead of "nt"), the line +# separator, and perhaps other things. For most robust behavior, try +# to find cgc on disk. -if os.name == 'nt': - CGC = 'c:/Program Files/NVIDIA Corporation/Cg/bin/cgc.exe' +CGC = '/usr/bin/cgc' +if not os.path.exists(CGC): + CGC = 'c:/Program Files (x86)/NVIDIA Corporation/Cg/bin/cgc.exe' if not os.path.exists(CGC): CGC = 'c:/Program Files (x86)/NVIDIA Corporation/Cg/bin/cgc.exe' -else: - CGC = '/usr/bin/cgc' # cgc complains about TANGENT1 and BINORMAL1 semantics, so we hack it by # replacing standard semantics with ATTR8-ATTR12 and then renaming them back to @@ -85,8 +87,10 @@ def get_input_mapping(header): new_name = new_name[:new_name.index('[')] if new_name.startswith('$'): new_name = new_name[1:] - ret[new_name] = (correct_semantic_case(semantic) if semantic - else old_name_and_type.split(' ')[2]) + if semantic: + ret[new_name] = correct_semantic_case(semantic) + else: + ret[new_name] = old_name_and_type.split(' ')[2] return ret @@ -144,8 +148,14 @@ def fix_glsl_body(body, input_mapping): def fix_glsl(glsl_shader): - header, body = re.split(os.linesep*2, glsl_shader, 1) - assert all(l.startswith('//') for l in header.splitlines()) + # Hack for Cygwin lying about os.linesep and being POSIX on Windows. + if '\r\n' in glsl_shader: + header, body = re.split('\r\n'*2, glsl_shader, 1) + else: + header, body = re.split(os.linesep*2, glsl_shader, 1) + + for l in header.splitlines(): + assert l.startswith('//') input_mapping = get_input_mapping(header) return header + '\n\n' + fix_glsl_body(body, input_mapping) @@ -217,7 +227,10 @@ if __name__ == '__main__': check_cg() try: - f = sys.stdin if options.file is None else open(options.file) + if options.file is None: + f = sys.stdin + else: + f = open(options.file) input = f.read() except KeyboardInterrupt: input = None diff --git a/o3d/converter/cross/converter_main.cc b/o3d/converter/cross/converter_main.cc index ab72b61..7822fe0 100644 --- a/o3d/converter/cross/converter_main.cc +++ b/o3d/converter/cross/converter_main.cc @@ -115,6 +115,7 @@ int CrossMain(int argc, char**argv) { << " writes six separate PNGs with suffixes _posx, _negx, etc.\n" << "--convert-cg-to-glsl\n" << " Convert shaders using an external tool.\n" + << " Requires python on PATH.\n" << "--converter-tool=<filename> [default: " << converter_tool.value() << "]\n" << " Specifies the shader converter tool.\n"; diff --git a/o3d/import/cross/collada.cc b/o3d/import/cross/collada.cc index cb6dcac..7de80af 100644 --- a/o3d/import/cross/collada.cc +++ b/o3d/import/cross/collada.cc @@ -520,9 +520,19 @@ bool ConvertCgToGlsl(const FilePath& converter, String* effect_string) { return false; fwrite(effect_string->c_str(), 1, effect_string->length(), temporary_file); + effect_string->clear(); file_util::CloseFile(temporary_file); +#if defined(OS_WIN) + // Assumes python.exe is in PATH. Doesn't seem there's an easy way + // to test whether it is without launching a process. + FilePath python(FILE_PATH_LITERAL("python.exe")); + CommandLine cmd_line(python); + cmd_line.AppendLooseValue(FilePathToWide(converter)); +#else CommandLine cmd_line(converter); +#endif + cmd_line.AppendLooseValue(L"-i"); cmd_line.AppendLooseValue(o3d::FilePathToWide(temporary_file_name)); bool rc = ::base::GetAppOutput(cmd_line, effect_string); |