diff --git a/plugins/GSdx/GSDeviceOGL.cpp b/plugins/GSdx/GSDeviceOGL.cpp index a7d178d121..e03da76c4f 100644 --- a/plugins/GSdx/GSDeviceOGL.cpp +++ b/plugins/GSdx/GSDeviceOGL.cpp @@ -940,7 +940,7 @@ void GSDeviceOGL::StretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture return; } - bool draw_in_depth = (ps == m_convert.ps[12] || ps == m_convert.ps[13]); + bool draw_in_depth = (ps == m_convert.ps[12] || ps == m_convert.ps[13] || ps == m_convert.ps[14]); // Performance optimization. It might be faster to use a framebuffer blit for standard case // instead to emulate it with shader diff --git a/plugins/GSdx/GSDeviceOGL.h b/plugins/GSdx/GSDeviceOGL.h index f1efcfbc7a..898654c28e 100644 --- a/plugins/GSdx/GSDeviceOGL.h +++ b/plugins/GSdx/GSDeviceOGL.h @@ -500,7 +500,7 @@ class GSDeviceOGL : public GSDevice struct { GLuint vs; // program object - GLuint ps[15]; // program object + GLuint ps[16]; // program object GLuint ln; // sampler object GLuint pt; // sampler object GSDepthStencilOGL* dss; diff --git a/plugins/GSdx/GSTextureCache.cpp b/plugins/GSdx/GSTextureCache.cpp index 3839b7238c..67c139c0d4 100644 --- a/plugins/GSdx/GSTextureCache.cpp +++ b/plugins/GSdx/GSTextureCache.cpp @@ -283,7 +283,8 @@ GSTextureCache::Target* GSTextureCache::LookupTarget(const GIFRegTEX0& TEX0, int if (type == DepthStencil) { GL_CACHE("TC: Lookup Target(Depth) %dx%d, hit Color (0x%x, F:0x%x)", w, h, bp, TEX0.PSM); - int shader = (TEX0.PSM & 1) ? 13 : 12; + int shader = 12 + GSLocalMemory::m_psm[TEX0.PSM].fmt; + ASSERT(shader <= 14); m_renderer->m_dev->StretchRect(t->m_texture, sRect, dst->m_texture, dRect, shader, false); } else { GL_CACHE("TC: Lookup Target(Color) %dx%d, hit Depth (0x%x, F:0x%x)", w, h, bp, TEX0.PSM); @@ -861,7 +862,7 @@ GSTextureCache::Source* GSTextureCache::CreateSource(const GIFRegTEX0& TEX0, con if (is_8bits) { GL_INS("Reading RT as a packed-indexed 8 bits format"); - shader = 14; // ask a conversion to 8 bits format + shader = 15; // ask a conversion to 8 bits format } #ifdef ENABLE_OGL_DEBUG diff --git a/plugins/GSdx/res/glsl/convert.glsl b/plugins/GSdx/res/glsl/convert.glsl index 0ed4b16a18..33bb05a803 100644 --- a/plugins/GSdx/res/glsl/convert.glsl +++ b/plugins/GSdx/res/glsl/convert.glsl @@ -194,17 +194,30 @@ void ps_main12() //out float gl_FragDepth; void ps_main13() { - // Same as above but without the alpha channel + // Same as above but without the alpha channel (24 bits Z) // Convert a RRGBA texture into a float depth texture // FIXME: I'm afraid of the accuracy - const vec4 bitSh = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 0.0) * vec4(255.0/256.0); - gl_FragDepth = dot(sample_c(), bitSh); + const vec3 bitSh = vec3(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0) * vec3(255.0/256.0); + gl_FragDepth = dot(sample_c().rgb, bitSh); } #endif #ifdef ps_main14 +//out float gl_FragDepth; void ps_main14() +{ + // Same as above but without the A/B channels (16 bits Z) + + // Convert a RRGBA texture into a float depth texture + // FIXME: I'm afraid of the accuracy + const vec2 bitSh = vec2(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0)) * vec2(255.0/256.0); + gl_FragDepth = dot(sample_c().rg, bitSh); +} +#endif + +#ifdef ps_main15 +void ps_main15() { // Potential speed optimization. There is a high probability that diff --git a/plugins/GSdx/res/glsl_source.h b/plugins/GSdx/res/glsl_source.h index c1d638e4ea..75f270d9bb 100644 --- a/plugins/GSdx/res/glsl_source.h +++ b/plugins/GSdx/res/glsl_source.h @@ -219,18 +219,31 @@ static const char* convert_glsl = "//out float gl_FragDepth;\n" "void ps_main13()\n" "{\n" - " // Same as above but without the alpha channel\n" + " // Same as above but without the alpha channel (24 bits Z)\n" "\n" " // Convert a RRGBA texture into a float depth texture\n" " // FIXME: I'm afraid of the accuracy\n" - " const vec4 bitSh = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 0.0) * vec4(255.0/256.0);\n" - " gl_FragDepth = dot(sample_c(), bitSh);\n" + " const vec3 bitSh = vec3(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0) * vec3(255.0/256.0);\n" + " gl_FragDepth = dot(sample_c().rgb, bitSh);\n" "}\n" "#endif\n" "\n" "#ifdef ps_main14\n" + "//out float gl_FragDepth;\n" "void ps_main14()\n" "{\n" + " // Same as above but without the A/B channels (16 bits Z)\n" + "\n" + " // Convert a RRGBA texture into a float depth texture\n" + " // FIXME: I'm afraid of the accuracy\n" + " const vec2 bitSh = vec2(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0)) * vec2(255.0/256.0);\n" + " gl_FragDepth = dot(sample_c().rg, bitSh);\n" + "}\n" + "#endif\n" + "\n" + "#ifdef ps_main15\n" + "void ps_main15()\n" + "{\n" "\n" " // Potential speed optimization. There is a high probability that\n" " // game only want to extract a single channel (blue). It will allow\n"