diff --git a/Source/Core/VideoBackends/OGL/OGLConfig.cpp b/Source/Core/VideoBackends/OGL/OGLConfig.cpp index db369a157d..f245289c9b 100644 --- a/Source/Core/VideoBackends/OGL/OGLConfig.cpp +++ b/Source/Core/VideoBackends/OGL/OGLConfig.cpp @@ -349,6 +349,8 @@ bool PopulateConfig(GLContext* m_main_gl_context) GLExtensions::Supports("GL_ARB_derivative_control") || GLExtensions::Version() >= 450; g_Config.backend_info.bSupportsTextureQueryLevels = GLExtensions::Supports("GL_ARB_texture_query_levels") || GLExtensions::Version() >= 430; + g_Config.backend_info.bSupportsUnrestrictedDepthRange = + GLExtensions::Supports("GL_NV_depth_buffer_float"); if (GLExtensions::Supports("GL_ARB_shader_storage_buffer_object")) { diff --git a/Source/Core/VideoBackends/OGL/OGLGfx.cpp b/Source/Core/VideoBackends/OGL/OGLGfx.cpp index fa20a76d11..b63d6db014 100644 --- a/Source/Core/VideoBackends/OGL/OGLGfx.cpp +++ b/Source/Core/VideoBackends/OGL/OGLGfx.cpp @@ -118,6 +118,16 @@ static void APIENTRY ClearDepthf(GLfloat depthval) glClearDepth(depthval); } +// Two small overrides to support unrestricted depth range +static void APIENTRY DepthRangefNV(GLfloat neardepth, GLfloat fardepth) +{ + glDepthRangedNV(neardepth, fardepth); +} +static void APIENTRY ClearDepthfNV(GLfloat depthval) +{ + glClearDepthdNV(depthval); +} + OGLGfx::OGLGfx(std::unique_ptr main_gl_context, float backbuffer_scale) : m_main_gl_context(std::move(main_gl_context)), m_current_rasterization_state(RenderState::GetInvalidRasterizationState()), @@ -137,11 +147,16 @@ OGLGfx::OGLGfx(std::unique_ptr main_gl_context, float backbuffer_scal if (!m_main_gl_context->IsGLES()) { - // OpenGL 3 doesn't provide GLES like float functions for depth. - // They are in core in OpenGL 4.1, so almost every driver should support them. - // But for the oldest ones, we provide fallbacks to the old double functions. - if (!GLExtensions::Supports("GL_ARB_ES2_compatibility")) + if (g_ActiveConfig.backend_info.bSupportsUnrestrictedDepthRange) { + glDepthRangef = DepthRangefNV; + glClearDepthf = ClearDepthfNV; + } + else if (!GLExtensions::Supports("GL_ARB_ES2_compatibility")) + { + // OpenGL 3 doesn't provide GLES like float functions for depth. + // They are in core in OpenGL 4.1, so almost every driver should support them. + // But for the oldest ones, we provide fallbacks to the old double functions. glDepthRangef = DepthRangef; glClearDepthf = ClearDepthf; } @@ -387,7 +402,10 @@ void OGLGfx::ClearRegion(const MathUtil::Rectangle& target_rc, bool colorEn if (zEnable) { glDepthMask(zEnable ? GL_TRUE : GL_FALSE); - glClearDepthf(float(z & 0xFFFFFF) / 16777216.0f); + if (g_ActiveConfig.backend_info.bSupportsUnrestrictedDepthRange) + glClearDepthf(float(z & 0xFFFFFF)); + else + glClearDepthf(float(z & 0xFFFFFF) / 16777216.0f); clear_mask |= GL_DEPTH_BUFFER_BIT; } diff --git a/Source/Core/VideoBackends/OGL/OGLTexture.cpp b/Source/Core/VideoBackends/OGL/OGLTexture.cpp index 58f1b10a04..9529ad74a7 100644 --- a/Source/Core/VideoBackends/OGL/OGLTexture.cpp +++ b/Source/Core/VideoBackends/OGL/OGLTexture.cpp @@ -44,9 +44,15 @@ GLenum OGLTexture::GetGLInternalFormatForTextureFormat(AbstractTextureFormat for case AbstractTextureFormat::D24_S8: return GL_DEPTH24_STENCIL8; case AbstractTextureFormat::D32F: - return GL_DEPTH_COMPONENT32F; + if (g_ActiveConfig.backend_info.bSupportsUnrestrictedDepthRange) + return GL_DEPTH_COMPONENT32F_NV; + else + return GL_DEPTH_COMPONENT32F; case AbstractTextureFormat::D32F_S8: - return GL_DEPTH32F_STENCIL8; + if (g_ActiveConfig.backend_info.bSupportsUnrestrictedDepthRange) + return GL_DEPTH32F_STENCIL8_NV; + else + return GL_DEPTH32F_STENCIL8; default: PanicAlertFmt("Unhandled texture format."); return storage ? GL_RGBA8 : GL_RGBA;