gsdx-ogl: add support of clip_control (depth only)

* replace the [-1;1] depth range of openGL with the DX range [0;1].
This commit is contained in:
Gregory Hainaut 2014-09-27 19:39:17 +02:00
parent 104688e3ee
commit 4659184cc1
5 changed files with 29 additions and 16 deletions

View File

@ -307,6 +307,25 @@ bool GSDeviceOGL::Create(GSWnd* wnd)
// m_date.bs->SetMask(false, false, false, false);
//#endif
// ****************************************************************
// Use DX coordinate convention
// ****************************************************************
// VS gl_position.z => [-1,-1]
// FS depth => [0, 1]
// because of -1 we loose lot of precision for small GS value
// This extension allow FS depth to range from -1 to 1. So
// gl_position.z could range from [0, 1]
#ifndef ENABLE_GLES
if (GLLoader::found_GL_ARB_clip_control) {
// Change depth convention
gl_ClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE);
} else if (GLLoader::found_GL_NV_depth_buffer_float) {
gl_DepthRangedNV(-1.0f, 1.0f);
}
#endif
// ****************************************************************
// HW renderer shader
// ****************************************************************

View File

@ -403,9 +403,8 @@ std::string GSShaderOGL::GenGlslHeader(const std::string& entry, GLenum type, co
header += "#define ENABLE_BINDLESS_TEX\n";
}
if (GLLoader::found_GL_NV_depth_buffer_float) {
// Specific nvidia extension that seem to help for z fighting
header += "#define NV_DEPTH\n";
if (GLLoader::found_GL_NV_depth_buffer_float || GLLoader::found_GL_ARB_clip_control) {
header += "#define ZERO_TO_ONE_DEPTH\n";
}
#else

View File

@ -59,17 +59,6 @@ void GSDeviceOGL::CreateTextureFX()
// Help to debug FS in apitrace
m_apitrace = CompilePS(PSSelector());
// VS gl_position.z => [-1,-1]
// FS depth => [0, 1]
// because of -1 we loose lot of precision for small GS value
// This extension allow FS depth to range from -1 to 1. So
// gl_position.z could range from [0, 1]
#ifndef ENABLE_GLES
if (GLLoader::found_GL_NV_depth_buffer_float) {
gl_DepthRangedNV(-1.0f, 1.0f);
}
#endif
}
GSDepthStencilOGL* GSDeviceOGL::CreateDepthStencil(OMDepthStencilSelector dssel)

View File

@ -664,8 +664,11 @@ static const char* tfx_glsl =
" vec2 TextureScale;\n"
"};\n"
"\n"
"#ifdef ZERO_TO_ONE_DEPTH\n"
"const float exp_min32 = exp2(-32.0f);\n"
"#else\n"
"const float exp_min31 = exp2(-31.0f);\n"
"#endif\n"
"\n"
"#ifdef SUBROUTINE_GL40\n"
"// Function pointer type\n"
@ -740,7 +743,7 @@ static const char* tfx_glsl =
" p.xy = vec2(i_p) - vec2(0.05f, 0.05f);\n"
" p.xy = p.xy * VertexScale - VertexOffset;\n"
" p.w = 1.0f;\n"
"#ifdef NV_DEPTH\n"
"#ifdef ZERO_TO_ONE_DEPTH\n"
" if(VS_LOGZ == 1) {\n"
" p.z = log2(float(1u+z)) / 32.0f;\n"
" } else {\n"

View File

@ -105,8 +105,11 @@ layout(std140, binding = 20) uniform cb20
vec2 TextureScale;
};
#ifdef ZERO_TO_ONE_DEPTH
const float exp_min32 = exp2(-32.0f);
#else
const float exp_min31 = exp2(-31.0f);
#endif
#ifdef SUBROUTINE_GL40
// Function pointer type
@ -181,7 +184,7 @@ void vs_main()
p.xy = vec2(i_p) - vec2(0.05f, 0.05f);
p.xy = p.xy * VertexScale - VertexOffset;
p.w = 1.0f;
#ifdef NV_DEPTH
#ifdef ZERO_TO_ONE_DEPTH
if(VS_LOGZ == 1) {
p.z = log2(float(1u+z)) / 32.0f;
} else {