OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 import optparse | 2 import optparse |
3 import os | 3 import os |
4 import re | 4 import re |
5 import subprocess | 5 import subprocess |
6 import sys | 6 import sys |
7 | 7 |
8 # This script takes an o3d cg shader from standard input and does the following: | 8 # This script takes an o3d cg shader from standard input and does the following: |
9 # | 9 # |
10 # * it extracts entry points to vertex and fragment shaders as specified by | 10 # * it extracts entry points to vertex and fragment shaders as specified by |
11 # VertexShaderEntryPoint and PixelShaderEntryPoint instructions; | 11 # VertexShaderEntryPoint and PixelShaderEntryPoint instructions; |
12 # | 12 # |
13 # * renames NORMAL, TANGENT{,1} and BINORMAL{,1} attributes to ATTR8-12; | 13 # * renames NORMAL, TANGENT{,1} and BINORMAL{,1} attributes to ATTR8-12; |
14 # | 14 # |
15 # * runs cgc with glslv and glslf profiles with those entry points; | 15 # * runs cgc with glslv and glslf profiles with those entry points; |
16 # | 16 # |
17 # * renames attributes and uniforms back to their orignal names; | 17 # * renames attributes and uniforms back to their orignal names; |
18 # | 18 # |
19 # * changes 'uniform vecN var[N]' to 'uniform matN var'; | 19 # * changes 'uniform vecN var[N]' to 'uniform matN var'; |
20 # | 20 # |
21 # * renames gl_Vertex and gl_MultiTexCoordN to position and texcoordN | 21 # * renames gl_Vertex and gl_MultiTexCoordN to position and texCoordN |
22 # respectively and adds attribute declarations; | 22 # respectively and adds attribute declarations; |
23 # | 23 # |
24 # * prints the results to standard output, separating them with SplitMarker | 24 # * prints the results to standard output, separating them with SplitMarker |
25 # instruction and keeping the MatrixLoadOrder instruction as is. | 25 # instruction and keeping the MatrixLoadOrder instruction as is. |
26 | 26 |
27 # Cygwin lies about the OS name ("posix" instead of "nt"), the line | 27 # Cygwin lies about the OS name ("posix" instead of "nt"), the line |
28 # separator, and perhaps other things. For most robust behavior, try | 28 # separator, and perhaps other things. For most robust behavior, try |
29 # to find cgc on disk. | 29 # to find cgc on disk. |
30 | 30 |
31 def find_o3d_root(): | 31 def find_o3d_root(): |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 body) | 157 body) |
158 | 158 |
159 attributes = [] | 159 attributes = [] |
160 if 'gl_Vertex' in body: | 160 if 'gl_Vertex' in body: |
161 # Change gl_Vertex to position and add attribute declaration. | 161 # Change gl_Vertex to position and add attribute declaration. |
162 body = re.sub(r'\bgl_Vertex\b', 'position', body) | 162 body = re.sub(r'\bgl_Vertex\b', 'position', body) |
163 attributes.append('attribute vec4 position;') | 163 attributes.append('attribute vec4 position;') |
164 | 164 |
165 for n in xrange(8): | 165 for n in xrange(8): |
166 if 'gl_MultiTexCoord%d' % n in body: | 166 if 'gl_MultiTexCoord%d' % n in body: |
167 # Change gl_MultiTexCoordN (0<=N<=7) to texcoordN and add attribute | 167 # Change gl_MultiTexCoordN (0<=N<=7) to texCoordN and add attribute |
168 # declaration. | 168 # declaration. |
169 body = re.sub(r'\bgl_MultiTexCoord%d\b' % n, 'texcoord%d' % n, body) | 169 body = re.sub(r'\bgl_MultiTexCoord%d\b' % n, 'texCoord%d' % n, body) |
170 attributes.append('attribute vec4 texcoord%d;' % n) | 170 attributes.append('attribute vec4 texCoord%d;' % n) |
171 | 171 |
172 # ATTRIBUTES_TO_SEMANTICS should have taken care of normals. | 172 # ATTRIBUTES_TO_SEMANTICS should have taken care of normals. |
173 assert 'gl_Normal' not in body | 173 assert 'gl_Normal' not in body |
174 | 174 |
175 if 'gl_Position' in body: | 175 if 'gl_Position' in body: |
176 # If there is exactly one assignment to gl_Position, modify it similar to | 176 # If there is exactly one assignment to gl_Position, modify it similar to |
177 # how RewriteVertexProgramSource in gl/effect_gl.cc does it. The input is | 177 # how RewriteVertexProgramSource in gl/effect_gl.cc does it. The input is |
178 # taken from vec4 dx_clipping uniform. | 178 # taken from vec4 dx_clipping uniform. |
179 # | 179 # |
180 # If there is more than one gl_Position mentioned in the shader, the | 180 # If there is more than one gl_Position mentioned in the shader, the |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 else: | 272 else: |
273 f = open(options.file) | 273 f = open(options.file) |
274 input = f.read() | 274 input = f.read() |
275 except KeyboardInterrupt: | 275 except KeyboardInterrupt: |
276 input = None | 276 input = None |
277 | 277 |
278 if not input: | 278 if not input: |
279 cmdline_parser.print_help() | 279 cmdline_parser.print_help() |
280 else: | 280 else: |
281 main(input, CGC) | 281 main(input, CGC) |
OLD | NEW |