diff --git a/plugins/GSdx/GSDeviceOGL.cpp b/plugins/GSdx/GSDeviceOGL.cpp index d90aa7a82a..2b8fa0fc43 100644 --- a/plugins/GSdx/GSDeviceOGL.cpp +++ b/plugins/GSdx/GSDeviceOGL.cpp @@ -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 // **************************************************************** diff --git a/plugins/GSdx/GSShaderOGL.cpp b/plugins/GSdx/GSShaderOGL.cpp index dbe106e885..ec5a76e9fb 100644 --- a/plugins/GSdx/GSShaderOGL.cpp +++ b/plugins/GSdx/GSShaderOGL.cpp @@ -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 diff --git a/plugins/GSdx/GSTextureFXOGL.cpp b/plugins/GSdx/GSTextureFXOGL.cpp index 09b1ae98d3..98589c8aa7 100644 --- a/plugins/GSdx/GSTextureFXOGL.cpp +++ b/plugins/GSdx/GSTextureFXOGL.cpp @@ -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) diff --git a/plugins/GSdx/res/glsl_source.h b/plugins/GSdx/res/glsl_source.h index d68b6c8637..c85b7429d2 100644 --- a/plugins/GSdx/res/glsl_source.h +++ b/plugins/GSdx/res/glsl_source.h @@ -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" diff --git a/plugins/GSdx/res/tfx.glsl b/plugins/GSdx/res/tfx.glsl index 35cc49fc45..dbbd64b014 100644 --- a/plugins/GSdx/res/tfx.glsl +++ b/plugins/GSdx/res/tfx.glsl @@ -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 {