summaryrefslogtreecommitdiffstats
path: root/o3d/cg_to_glsl
diff options
context:
space:
mode:
authoramarinichev@chromium.org <amarinichev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-20 20:01:01 +0000
committeramarinichev@chromium.org <amarinichev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-20 20:01:01 +0000
commitbe2ca9217d4ffae79966494eaf6ce58507237f61 (patch)
tree7009d2bea2dde397948a96f7e43d915bfbd4259f /o3d/cg_to_glsl
parent3c53f2e270ffa29b09a93f57de67c40fa4fbcdf5 (diff)
downloadchromium_src-be2ca9217d4ffae79966494eaf6ce58507237f61.zip
chromium_src-be2ca9217d4ffae79966494eaf6ce58507237f61.tar.gz
chromium_src-be2ca9217d4ffae79966494eaf6ce58507237f61.tar.bz2
Implemented DX clipping rules to match CG version. Uses dx_clipping varying.
Review URL: http://codereview.chromium.org/1646016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45069 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/cg_to_glsl')
-rwxr-xr-xo3d/cg_to_glsl/convert.py26
1 files changed, 22 insertions, 4 deletions
diff --git a/o3d/cg_to_glsl/convert.py b/o3d/cg_to_glsl/convert.py
index 8eb86ec..3efb3ea 100755
--- a/o3d/cg_to_glsl/convert.py
+++ b/o3d/cg_to_glsl/convert.py
@@ -18,7 +18,7 @@ import sys
#
# * changes 'uniform vecN var[N]' to 'uniform matN var';
#
-# * renames gl_Vertex and gl_MultiTexCoordN to position and texcoordsN
+# * renames gl_Vertex and gl_MultiTexCoordN to position and texcoordN
# respectively and adds attribute declarations;
#
# * prints the results to standard output, separating them with SplitMarker
@@ -77,14 +77,32 @@ def fix_glsl_body(body, input_mapping):
for n in xrange(8):
if 'gl_MultiTexCoord%d' % n in body:
- # Change gl_MultiTexCoordN (0<=N<=7) to texcoordsN and add attribute
+ # Change gl_MultiTexCoordN (0<=N<=7) to texcoordN and add attribute
# declaration.
- body = re.sub(r'\bgl_MultiTexCoord%d\b' % n, 'texcoords%d' % n, body)
- attributes.append('attribute vec4 texcoords%d;' % n)
+ body = re.sub(r'\bgl_MultiTexCoord%d\b' % n, 'texcoord%d' % n, body)
+ attributes.append('attribute vec4 texcoord%d;' % n)
# ATTRIBUTES_TO_SEMANTICS should have taken care of normals.
assert 'gl_Normal' not in body
+ if 'gl_Position' in body:
+ # If there is exactly one assignment to gl_Position, modify it similar to
+ # how RewriteVertexProgramSource in gl/effect_gl.cc does it. The input is
+ # taken from vec4 dx_clipping uniform.
+ #
+ # If there is more than one gl_Position mentioned in the shader, the
+ # converter fails.
+ assert len(re.findall('gl_Position', body)) == 1
+ attributes.append('vec4 _glPositionTemp;')
+ attributes.append('uniform vec4 dx_clipping;')
+ body = re.sub(r'\bgl_Position\b([^;]*);',
+ r'_glPositionTemp\1; gl_Position = vec4(' +
+ r'_glPositionTemp.x + _glPositionTemp.w * dx_clipping.x, ' +
+ r'dx_clipping.w * ' +
+ r'(_glPositionTemp.y + _glPositionTemp.w * dx_clipping.y), ' +
+ r'_glPositionTemp.z * 2 - _glPositionTemp.w, ' +
+ r'_glPositionTemp.w);', body)
+
return '\n'.join(attributes) + '\n\n' + body