OGL: Add unrestricted depth range support.
This commit is contained in:
parent
32521d1536
commit
73eec396e1
|
@ -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"))
|
||||
{
|
||||
|
|
|
@ -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<GLContext> 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<GLContext> 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<int>& 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue