summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/VertexShaderGen.cpp
diff options
context:
space:
mode:
authorJules Blok <jules.blok@gmail.com>2016-08-05 22:31:34 +0200
committerJules Blok <jules.blok@gmail.com>2016-08-15 13:11:26 +0200
commita141e91dd226885fc767d009938ca61a22f86558 (patch)
tree3b55820cbda0ba34278a4cc340f8e70ab07a3ce5 /Source/Core/VideoCommon/VertexShaderGen.cpp
parent4582853af48f67047e57b997bf923488bf444931 (diff)
OGL: Check for GL_DEPTH_CLAMP support.
It's not available in OpenGL ES and officially it's not supported on OpenGL 3.0/3.1. Fallback to old depth range code if there is no method to disable depth clipping. It's more important to have correct clipping than to have accurate depth values. Inaccurate depth values can be fixed by slow depth.
Diffstat (limited to 'Source/Core/VideoCommon/VertexShaderGen.cpp')
-rw-r--r--Source/Core/VideoCommon/VertexShaderGen.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp
index 9110cbfe99..85359ac6ee 100644
--- a/Source/Core/VideoCommon/VertexShaderGen.cpp
+++ b/Source/Core/VideoCommon/VertexShaderGen.cpp
@@ -399,13 +399,22 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da
out.Write("o.colors_1 = color1;\n");
}
- // Since we're adjusting z for the depth range before the perspective divide, we have to do our
- // own clipping.
- out.Write("o.clipDist = o.pos.z + o.pos.w;\n");
+ if (g_ActiveConfig.backend_info.bSupportsDepthClamp)
+ {
+ // Since we're adjusting z for the depth range before the perspective divide, we have to do our
+ // own clipping.
+ out.Write("o.clipDist = o.pos.z + o.pos.w;\n");
- // We have to handle the depth range in the vertex shader, because some games will use a depth range beyond
- // the normal depth range of 0..1.
- out.Write("o.pos.z = o.pos.w * " I_PIXELCENTERCORRECTION".w - o.pos.z * " I_PIXELCENTERCORRECTION".z;\n");
+ // We have to handle the depth range in the vertex shader, because some games will use a depth range beyond
+ // the normal depth range of 0..1.
+ out.Write("o.pos.z = o.pos.w * " I_PIXELCENTERCORRECTION".w - o.pos.z * " I_PIXELCENTERCORRECTION".z;\n");
+ }
+ else
+ {
+ // User-defined clipping is not supported, thus we rely on the API to handle the depth range for us.
+ // We still need to take care of the reversed depth, so we do that here.
+ out.Write("o.pos.z = -o.pos.z;\n");
+ }
// write the true depth value, if the game uses depth textures pixel shaders will override with
// the correct values
@@ -457,7 +466,8 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da
out.Write("colors_1 = o.colors_1;\n");
}
- out.Write("gl_ClipDistance[0] = o.clipDist;\n");
+ if (g_ActiveConfig.backend_info.bSupportsDepthClamp)
+ out.Write("gl_ClipDistance[0] = o.clipDist;\n");
out.Write("gl_Position = o.pos;\n");
}
else // D3D