summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/OGL/Render.cpp
diff options
context:
space:
mode:
authorJules Blok <jules.blok@gmail.com>2016-08-19 02:11:37 +0200
committerGitHub <noreply@github.com>2016-08-19 02:11:37 +0200
commit40f4308dc2120ce4e105008f3cb46b6a1c553e64 (patch)
treea3a83299c9d3f3873f94b2c75991877bb7b928a6 /Source/Core/VideoBackends/OGL/Render.cpp
parent0015d2e86b76772a57fb4554c84c4b47adce341e (diff)
parente86d7cbc999223ca113af7b4c0aac6850c1854fe (diff)
Merge pull request #4085 from Armada651/vertex-depth
VideoCommon: Implement depth range equation in vertex shader.
Diffstat (limited to 'Source/Core/VideoBackends/OGL/Render.cpp')
-rw-r--r--Source/Core/VideoBackends/OGL/Render.cpp38
1 files changed, 35 insertions, 3 deletions
diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp
index bde616deac..d637c308ca 100644
--- a/Source/Core/VideoBackends/OGL/Render.cpp
+++ b/Source/Core/VideoBackends/OGL/Render.cpp
@@ -481,6 +481,9 @@ Renderer::Renderer()
g_Config.backend_info.bSupportsBindingLayout =
GLExtensions::Supports("GL_ARB_shading_language_420pack");
+ // Clip distance support is useless without a method to clamp the depth range
+ g_Config.backend_info.bSupportsDepthClamp = GLExtensions::Supports("GL_ARB_depth_clamp");
+
g_ogl_config.bSupportsGLSLCache = GLExtensions::Supports("GL_ARB_get_program_binary");
g_ogl_config.bSupportsGLPinnedMemory = GLExtensions::Supports("GL_AMD_pinned_memory");
g_ogl_config.bSupportsGLSync = GLExtensions::Supports("GL_ARB_sync");
@@ -520,6 +523,10 @@ Renderer::Renderer()
g_ogl_config.bSupportsGLSLCache = true;
g_ogl_config.bSupportsGLSync = true;
+ // TODO: Implement support for GL_EXT_clip_cull_distance when there is an extension for
+ // depth clamping.
+ g_Config.backend_info.bSupportsDepthClamp = false;
+
if (strstr(g_ogl_config.glsl_version, "3.0"))
{
g_ogl_config.eSupportedGLSLVersion = GLSLES_300;
@@ -669,7 +676,7 @@ Renderer::Renderer()
g_ogl_config.gl_renderer, g_ogl_config.gl_version),
5000);
- WARN_LOG(VIDEO, "Missing OGL Extensions: %s%s%s%s%s%s%s%s%s%s%s%s%s",
+ WARN_LOG(VIDEO, "Missing OGL Extensions: %s%s%s%s%s%s%s%s%s%s%s%s%s%s",
g_ActiveConfig.backend_info.bSupportsDualSourceBlend ? "" : "DualSourceBlend ",
g_ActiveConfig.backend_info.bSupportsPrimitiveRestart ? "" : "PrimitiveRestart ",
g_ActiveConfig.backend_info.bSupportsEarlyZ ? "" : "EarlyZ ",
@@ -681,7 +688,8 @@ Renderer::Renderer()
g_ActiveConfig.backend_info.bSupportsSSAA ? "" : "SSAA ",
g_ActiveConfig.backend_info.bSupportsGSInstancing ? "" : "GSInstancing ",
g_ActiveConfig.backend_info.bSupportsClipControl ? "" : "ClipControl ",
- g_ogl_config.bSupportsCopySubImage ? "" : "CopyImageSubData ");
+ g_ogl_config.bSupportsCopySubImage ? "" : "CopyImageSubData ",
+ g_ActiveConfig.backend_info.bSupportsDepthClamp ? "" : "DepthClamp ");
s_last_multisamples = g_ActiveConfig.iMultisamples;
s_MSAASamples = s_last_multisamples;
@@ -724,6 +732,12 @@ Renderer::Renderer()
glClearDepthf(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
+ if (g_ActiveConfig.backend_info.bSupportsDepthClamp)
+ {
+ glEnable(GL_CLIP_DISTANCE0);
+ glEnable(GL_CLIP_DISTANCE1);
+ glEnable(GL_DEPTH_CLAMP);
+ }
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // 4-byte pixel alignment
@@ -1142,7 +1156,15 @@ void Renderer::SetViewport()
auto iceilf = [](float f) { return static_cast<GLint>(ceilf(f)); };
glViewport(iceilf(X), iceilf(Y), iceilf(Width), iceilf(Height));
}
- glDepthRangef(GLFar, GLNear);
+
+ // Set the reversed depth range. If we do depth clipping and depth range in the
+ // vertex shader we only need to ensure depth values don't exceed the maximum
+ // value supported by the console GPU. If not, we simply clamp the near/far values
+ // themselves to the maximum value as done above.
+ if (g_ActiveConfig.backend_info.bSupportsDepthClamp)
+ glDepthRangef(GX_MAX_DEPTH, 0.0f);
+ else
+ glDepthRangef(GLFar, GLNear);
}
void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable,
@@ -1647,6 +1669,11 @@ void Renderer::ResetAPIState()
glDisable(GL_BLEND);
if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL)
glDisable(GL_COLOR_LOGIC_OP);
+ if (g_ActiveConfig.backend_info.bSupportsDepthClamp)
+ {
+ glDisable(GL_CLIP_DISTANCE0);
+ glDisable(GL_CLIP_DISTANCE1);
+ }
glDepthMask(GL_FALSE);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
}
@@ -1655,6 +1682,11 @@ void Renderer::RestoreAPIState()
{
// Gets us back into a more game-like state.
glEnable(GL_SCISSOR_TEST);
+ if (g_ActiveConfig.backend_info.bSupportsDepthClamp)
+ {
+ glEnable(GL_CLIP_DISTANCE0);
+ glEnable(GL_CLIP_DISTANCE1);
+ }
SetGenerationMode();
BPFunctions::SetScissor();
SetColorMask();