diff options
author | amarinichev@chromium.org <amarinichev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-20 20:01:01 +0000 |
---|---|---|
committer | amarinichev@chromium.org <amarinichev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-20 20:01:01 +0000 |
commit | be2ca9217d4ffae79966494eaf6ce58507237f61 (patch) | |
tree | 7009d2bea2dde397948a96f7e43d915bfbd4259f | |
parent | 3c53f2e270ffa29b09a93f57de67c40fa4fbcdf5 (diff) | |
download | chromium_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
-rwxr-xr-x | o3d/cg_to_glsl/convert.py | 26 | ||||
-rw-r--r-- | o3d/core/cross/gles2/effect_gles2.cc | 2 | ||||
-rw-r--r-- | o3d/core/cross/gles2/param_cache_gles2.cc | 3 | ||||
-rw-r--r-- | o3d/core/cross/gles2/renderer_gles2.cc | 22 | ||||
-rw-r--r-- | o3d/core/cross/gles2/renderer_gles2.h | 6 |
5 files changed, 53 insertions, 6 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 diff --git a/o3d/core/cross/gles2/effect_gles2.cc b/o3d/core/cross/gles2/effect_gles2.cc index 060f46b..88157b0 100644 --- a/o3d/core/cross/gles2/effect_gles2.cc +++ b/o3d/core/cross/gles2/effect_gles2.cc @@ -404,6 +404,8 @@ void EffectGLES2::UpdateShaderUniformsFromEffect( GLES2Parameter gl_param = i->first; i->second->SetEffectParam(renderer_, gl_param); } + renderer_->UpdateDxClippingUniform( + glGetUniformLocation(gl_program_, "dx_clipping")); CHECK_GL_ERROR(); } diff --git a/o3d/core/cross/gles2/param_cache_gles2.cc b/o3d/core/cross/gles2/param_cache_gles2.cc index 5a6fc85..4dc4d50 100644 --- a/o3d/core/cross/gles2/param_cache_gles2.cc +++ b/o3d/core/cross/gles2/param_cache_gles2.cc @@ -601,7 +601,8 @@ static void ScanVaryingParameters(GLuint gl_program, gl_program, ii, max_len + 1, &length, &size, &type, name_buffer.get()); // TODO(gman): Should we check for error? GLint location = glGetAttribLocation(gl_program, name_buffer.get()); - param_cache_gl->varying_map().insert(std::make_pair(location, ii)); + if (location != -1) + param_cache_gl->varying_map().insert(std::make_pair(location, ii)); } } diff --git a/o3d/core/cross/gles2/renderer_gles2.cc b/o3d/core/cross/gles2/renderer_gles2.cc index e6012f4..71d5c72 100644 --- a/o3d/core/cross/gles2/renderer_gles2.cc +++ b/o3d/core/cross/gles2/renderer_gles2.cc @@ -1343,7 +1343,27 @@ void RendererGLES2::UpdateHelperConstant(float width, float height) { // If render-targets are active, pass -1 to invert the Y axis. OpenGLES2 uses // a different viewport orientation than DX. Without the inversion, the // output of render-target rendering will be upside down. - // TODO(piman): actually implement this. + CHECK_GL_ERROR(); + + if (RenderSurfaceActive()) { + dx_clipping_[0] = 1.f / width; + dx_clipping_[1] = -1.f / height; + dx_clipping_[2] = 2.f; + dx_clipping_[3] = -1.f; + } else { + dx_clipping_[0] = (1.0f + 2.0f * (-dest_x_offset())) / width; + dx_clipping_[1] = (-1.0f + 2.0f * dest_y_offset()) / height; + dx_clipping_[2] = 2.0f; + dx_clipping_[3] = 1.0f; + } +} + +// Programs the helper constants into the hardware. +void RendererGLES2::UpdateDxClippingUniform(GLint location) { + // For some reason, if location is -1 an error is signalled, despite the spec + // saying it is OK. + if (location != -1) + glUniform4fv(location, 1, dx_clipping_); CHECK_GL_ERROR(); } diff --git a/o3d/core/cross/gles2/renderer_gles2.h b/o3d/core/cross/gles2/renderer_gles2.h index 289101c..6036c73 100644 --- a/o3d/core/cross/gles2/renderer_gles2.h +++ b/o3d/core/cross/gles2/renderer_gles2.h @@ -179,6 +179,9 @@ class RendererGLES2 : public Renderer { return next_texture_unit_++; } + // Programs the helper constants into the hardware. + void UpdateDxClippingUniform(GLint location); + protected: // Keep the constructor protected so only factory methods can create // renderers. @@ -354,6 +357,9 @@ class RendererGLES2 : public Renderer { // The next texture unit to use. This is reset with ResetTextureUnit // and retrieved with GetNextTextureUnit. GLenum next_texture_unit_; + + // Transform matrix coefficients to match DX clipping rules. + GLfloat dx_clipping_[4]; }; } // namespace o3d |