From eb0ea71f24c77234e875f36a5fd30188a22684a5 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 29 Dec 2013 13:02:04 -0800 Subject: [PATCH] softgpu: Use region for debugger buffer previews. It's fine if it resizes or etc., but this should generally be the interesting area of vram to show, without any confusing noise on the side/etc. --- GPU/Software/Rasterizer.cpp | 12 +++++++----- GPU/Software/SoftGpu.cpp | 34 ++++++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/GPU/Software/Rasterizer.cpp b/GPU/Software/Rasterizer.cpp index 5c46dbb292..0aad8f6206 100644 --- a/GPU/Software/Rasterizer.cpp +++ b/GPU/Software/Rasterizer.cpp @@ -1260,14 +1260,16 @@ void DrawLine(const VertexData &v0, const VertexData &v1) bool GetCurrentStencilbuffer(GPUDebugBuffer &buffer) { - buffer.Allocate(gstate.DepthBufStride(), 512, GPU_DBG_FORMAT_8BIT); + int w = gstate.getRegionX2() - gstate.getRegionX1() + 1; + int h = gstate.getRegionY2() - gstate.getRegionY1() + 1; + buffer.Allocate(w, h, GPU_DBG_FORMAT_8BIT); u8 *row = buffer.GetData(); - for (int y = 0; y < 512; ++y) { - for (int x = 0; x < gstate.DepthBufStride(); ++x) { - row[x] = GetPixelStencil(x, y); + for (int y = gstate.getRegionY1(); y <= gstate.getRegionY2(); ++y) { + for (int x = gstate.getRegionX1(); x <= gstate.getRegionX2(); ++x) { + row[x - gstate.getRegionX1()] = GetPixelStencil(x, y); } - row += gstate.DepthBufStride(); + row += w; } return true; } diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index 32e5461eda..864a9c3042 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -865,17 +865,39 @@ bool SoftGPU::FramebufferDirty() { bool SoftGPU::GetCurrentFramebuffer(GPUDebugBuffer &buffer) { - // We don't know the height, so just use 512, which should be the max (hopefully?) - // TODO: Could check clipping and such, though...? - buffer = GPUDebugBuffer(fb.data, gstate.FrameBufStride(), 512, gstate.FrameBufFormat()); + int w = gstate.getRegionX2() - gstate.getRegionX1() + 1; + int h = gstate.getRegionY2() - gstate.getRegionY1() + 1; + buffer.Allocate(w, h, gstate.FrameBufFormat()); + + u8 *src = fb.data; + u8 *dst = buffer.GetData(); + for (int y = gstate.getRegionY1(); y <= gstate.getRegionY2(); ++y) { + if (gstate.FrameBufFormat() == GE_FORMAT_8888) { + memcpy(dst, src + gstate.getRegionX1(), (gstate.getRegionX2() + 1) * 4); + dst += w * 4; + src += gstate.FrameBufStride() * 4; + } else { + memcpy(dst, src + gstate.getRegionX1(), (gstate.getRegionX2() + 1) * 2); + dst += w * 2; + src += gstate.FrameBufStride() * 2; + } + } return true; } bool SoftGPU::GetCurrentDepthbuffer(GPUDebugBuffer &buffer) { - // We don't know the height, so just use 512, which should be the max (hopefully?) - // TODO: Could check clipping and such, though...? - buffer = GPUDebugBuffer(depthbuf.data, gstate.DepthBufStride(), 512, GPU_DBG_FORMAT_16BIT); + int w = gstate.getRegionX2() - gstate.getRegionX1() + 1; + int h = gstate.getRegionY2() - gstate.getRegionY1() + 1; + buffer.Allocate(w, h, GPU_DBG_FORMAT_16BIT); + + u8 *src = depthbuf.data; + u8 *dst = buffer.GetData(); + for (int y = gstate.getRegionY1(); y <= gstate.getRegionY2(); ++y) { + memcpy(dst, src + gstate.getRegionX1(), (gstate.getRegionX2() + 1) * 2); + dst += w * 2; + src += gstate.DepthBufStride() * 2; + } return true; }