From 4627c106e4dd280ad198b48557ec179d7d52bba3 Mon Sep 17 00:00:00 2001 From: Themaister Date: Mon, 7 Oct 2013 23:06:41 +0200 Subject: [PATCH] Fix NTSC shaders by preprocessing first. If vertex shader is in an #include, it wouldn't get column_major fix applied. --- tools/cg2glsl.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tools/cg2glsl.py b/tools/cg2glsl.py index ee8f1ce74c..5b13cc58fc 100755 --- a/tools/cg2glsl.py +++ b/tools/cg2glsl.py @@ -546,11 +546,19 @@ def preprocess_vertex(source_data): return '\n'.join(ret) def convert(source, dest): - vert_cmd = ['cgc', '-profile', 'glesv', '-entry', 'main_vertex', '-quiet', '-I', os.path.split(source)[0]] - with open(source, 'r') as f: - source_data = f.read() + # Have to preprocess first to resolve #includes so we can hack potential vertex shaders. + vert_cmd_preprocess = ['cgc', '-E', '-I', os.path.split(source)[0], source] + p = subprocess.Popen(vert_cmd_preprocess, stderr = subprocess.PIPE, stdout = subprocess.PIPE) + source_data, stderr_ret = p.communicate() + log(stderr_ret.decode()) + + if p.returncode != 0: + log('Vertex preprocessing failed ...') + + source_data = preprocess_vertex(source_data.decode()) + + vert_cmd = ['cgc', '-profile', 'glesv', '-entry', 'main_vertex', '-quiet'] p = subprocess.Popen(vert_cmd, stdin = subprocess.PIPE, stderr = subprocess.PIPE, stdout = subprocess.PIPE) - source_data = preprocess_vertex(source_data) vertex_source, stderr_ret = p.communicate(input = source_data.encode()) log(stderr_ret.decode()) vertex_source = vertex_source.decode() @@ -559,9 +567,9 @@ def convert(source, dest): log('Vertex compilation failed ...') return 1 - frag_cmd = ['cgc', '-profile', 'glesf', '-entry', 'main_fragment', '-quiet', source] - p = subprocess.Popen(frag_cmd, stderr = subprocess.PIPE, stdout = subprocess.PIPE) - fragment_source, stderr_ret = p.communicate() + frag_cmd = ['cgc', '-profile', 'glesf', '-entry', 'main_fragment', '-quiet'] + p = subprocess.Popen(frag_cmd, stdin = subprocess.PIPE, stderr = subprocess.PIPE, stdout = subprocess.PIPE) + fragment_source, stderr_ret = p.communicate(input = source_data.encode()) log(stderr_ret.decode()) fragment_source = fragment_source.decode()