From be1403cdc27e683fc305b5e6edabcbcf49901ed8 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Mon, 29 Jun 2015 21:41:36 +0200 Subject: [PATCH] gsdx-ogl: support texture shuffling on !FST Mostly fix "Finding Nemo" It remains a shadows issue when you enable accurate_fbmask and depth --- plugins/GSdx/GSRendererOGL.cpp | 73 ++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 21 deletions(-) diff --git a/plugins/GSdx/GSRendererOGL.cpp b/plugins/GSdx/GSRendererOGL.cpp index 1bf66eb724..9b02d411fd 100644 --- a/plugins/GSdx/GSRendererOGL.cpp +++ b/plugins/GSdx/GSRendererOGL.cpp @@ -260,34 +260,65 @@ void GSRendererOGL::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sour int pos = (v[0].XYZ.X - o.OFX) & 0xFF; bool write_ba = (pos > 112 && pos < 136); // Read texture is 8 to 16 pixels (same as above) - int tex_pos = v[0].U & 0xFF; + float tw = (float)(1u << context->TEX0.TW); + int tex_pos = (PRIM->FST) ? v[0].U : tw * v[0].ST.S; + tex_pos &= 0xFF; ps_sel.read_ba = (tex_pos > 112 && tex_pos < 144); - //GL_INS("First vertex is P: %d => %d T: %d => %d", v[0].XYZ.X, v[1].XYZ.X, v[0].U, v[1].U); - // Convert the vertex info to a 32 bits color format equivalent - for(size_t i = 0; i < count; i += 2) { - if (write_ba) - v[i].XYZ.X -= 128u; - else - v[i+1].XYZ.X += 128u; + if (PRIM->FST) { + GL_INS("First vertex is P: %d => %d T: %d => %d", v[0].XYZ.X, v[1].XYZ.X, v[0].U, v[1].U); - if (ps_sel.read_ba) - v[i].U -= 128u; - else - v[i+1].U += 128u; + for(size_t i = 0; i < count; i += 2) { + if (write_ba) + v[i].XYZ.X -= 128u; + else + v[i+1].XYZ.X += 128u; - // Height is too big (2x). - int tex_offset = v[i].V & 0xF; - GSVector4i offset(o.OFY, tex_offset, o.OFY, tex_offset); + if (ps_sel.read_ba) + v[i].U -= 128u; + else + v[i+1].U += 128u; - GSVector4i tmp(v[i].XYZ.Y, v[i].V, v[i+1].XYZ.Y, v[i+1].V); - tmp = GSVector4i(tmp - offset).srl32(1) + offset; + // Height is too big (2x). + int tex_offset = v[i].V & 0xF; + GSVector4i offset(o.OFY, tex_offset, o.OFY, tex_offset); - v[i].XYZ.Y = tmp.x; - v[i].V = tmp.y; - v[i+1].XYZ.Y = tmp.z; - v[i+1].V = tmp.w; + GSVector4i tmp(v[i].XYZ.Y, v[i].V, v[i+1].XYZ.Y, v[i+1].V); + tmp = GSVector4i(tmp - offset).srl32(1) + offset; + + v[i].XYZ.Y = tmp.x; + v[i].V = tmp.y; + v[i+1].XYZ.Y = tmp.z; + v[i+1].V = tmp.w; + } + } else { + const float offset_8pix = 8.0f / tw; + GL_INS("First vertex is P: %d => %d T: %f => %f (offset %f)", v[0].XYZ.X, v[1].XYZ.X, v[0].ST.S, v[1].ST.S, offset_8pix); + + for(size_t i = 0; i < count; i += 2) { + if (write_ba) + v[i].XYZ.X -= 128u; + else + v[i+1].XYZ.X += 128u; + + if (ps_sel.read_ba) + v[i].ST.S -= offset_8pix; + else + v[i+1].ST.S += offset_8pix; + + // Height is too big (2x). + GSVector4i offset(o.OFY, o.OFY); + + GSVector4i tmp(v[i].XYZ.Y, v[i+1].XYZ.Y); + tmp = GSVector4i(tmp - offset).srl32(1) + offset; + + //fprintf(stderr, "Before %d, After %d\n", v[i+1].XYZ.Y, tmp.y); + v[i].XYZ.Y = tmp.x; + v[i].ST.T /= 2.0f; + v[i+1].XYZ.Y = tmp.y; + v[i+1].ST.T /= 2.0f; + } } // Please bang my head against the wall!