From 67b62d9861634cd3a5a414b66a395b23234c8d1a Mon Sep 17 00:00:00 2001 From: ManIsCat2 Date: Tue, 6 Jan 2026 16:53:21 +0330 Subject: [PATCH] shift support --- src/pc/gfx/gfx.h | 1 + src/pc/gfx/gfx_pc.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/pc/gfx/gfx.h b/src/pc/gfx/gfx.h index e5ff61b77..e9a6a88bc 100644 --- a/src/pc/gfx/gfx.h +++ b/src/pc/gfx/gfx.h @@ -67,6 +67,7 @@ struct TextureTile { uint8_t fmt; uint8_t siz; uint8_t cms, cmt; + uint8_t shifts, shiftt; uint16_t uls, ult, lrs, lrt; // U10.2 uint32_t line_size_bytes; }; diff --git a/src/pc/gfx/gfx_pc.c b/src/pc/gfx/gfx_pc.c index a89bcac74..2446a0e25 100644 --- a/src/pc/gfx/gfx_pc.c +++ b/src/pc/gfx/gfx_pc.c @@ -1166,6 +1166,24 @@ static void OPTIMIZE_O3 gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t if (use_texture) { float u = (v_arr[i]->u - rdp.texture_tile.uls * 8) / 32.0f; float v = (v_arr[i]->v - rdp.texture_tile.ult * 8) / 32.0f; + + int shifts = rdp.texture_tile.shifts; + int shiftt = rdp.texture_tile.shiftt; + if (shifts != 0) { + if (shifts <= 10) { + u /= 1 << shifts; + } else { + u *= 1 << (16 - shifts); + } + } + if (shiftt != 0) { + if (shiftt <= 10) { + v /= 1 << shiftt; + } else { + v *= 1 << (16 - shiftt); + } + } + if ((rdp.other_mode_h & (3U << G_MDSFT_TEXTFILT)) != G_TF_POINT) { // Linear filter adds 0.5f to the coordinates (why?) u += 0.5f; @@ -1404,6 +1422,8 @@ static void gfx_dp_set_tile(uint8_t fmt, uint32_t siz, uint32_t line, uint32_t t rdp.texture_tile.siz = siz; rdp.texture_tile.cms = cms; rdp.texture_tile.cmt = cmt; + rdp.texture_tile.shifts = shifts; + rdp.texture_tile.shiftt = shiftt; rdp.texture_tile.line_size_bytes = line * 8; if (!sOnlyTextureChangeOnAddrChange) { // I don't know if we ever need to set these...