From 4afbb18eabab8fc1b25d50e77a46fd598d9194b9 Mon Sep 17 00:00:00 2001 From: rogerman Date: Mon, 20 Sep 2021 15:06:34 -0700 Subject: [PATCH] GPU: Correctly resolve the 18-bit and 24-bit colorspaces to 32-bit when auto-resolving is enabled. Fixes #471. - Also revert commits e1cadfe and 77d38b1. Using masterNativeBuffer16 was the correct choice here after all. --- desmume/src/GPU.cpp | 88 ++++++++++++++----------- desmume/src/frontend/posix/cli/main.cpp | 2 +- 2 files changed, 49 insertions(+), 41 deletions(-) diff --git a/desmume/src/GPU.cpp b/desmume/src/GPU.cpp index 6d0ca1e3b..891a1295b 100644 --- a/desmume/src/GPU.cpp +++ b/desmume/src/GPU.cpp @@ -6328,61 +6328,69 @@ void NDSDisplay::ResolveLinesDisplayedNative() void NDSDisplay::ResolveFramebufferToCustom(NDSDisplayInfo &mutableInfo) { - if (this->DidPerformCustomRender()) - { - return; - } - - if (!mutableInfo.isCustomSizeRequested) - { - memcpy(this->_customBuffer, this->_nativeBuffer16, GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT * mutableInfo.pixelBytes); - return; - } - // All lines should be 15-bit native-sized lines. // // This method is called to transfer these lines into the customBuffer portion of the current // framebuffer page so that clients can access a single continuous buffer. - const u16 *__restrict src = this->_nativeBuffer16; - u32 *__restrict working = this->_workingNativeBuffer32; - - switch (mutableInfo.colorFormat) + if (this->DidPerformCustomRender()) { - case NDSColorFormat_BGR666_Rev: - ColorspaceConvertBuffer555To6665Opaque(src, working, GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT); - break; - - case NDSColorFormat_BGR888_Rev: - ColorspaceConvertBuffer555To8888Opaque(src, working, GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT); - break; - - default: - break; + return; } - if (mutableInfo.pixelBytes == 2) + if (mutableInfo.isCustomSizeRequested) { - u16 *__restrict dst = (u16 *__restrict)this->_customBuffer; + const u16 *__restrict src = this->_nativeBuffer16; + u32 *__restrict working = this->_workingNativeBuffer32; - for (size_t y = 0; y < GPU_FRAMEBUFFER_NATIVE_HEIGHT; y++) + switch (mutableInfo.colorFormat) { - const GPUEngineLineInfo &lineInfo = GPU->GetLineInfoAtIndex(y); - CopyLineExpandHinted<0x3FFF, true, false, false, 2>(lineInfo, src, dst); - src += GPU_FRAMEBUFFER_NATIVE_WIDTH; - dst += lineInfo.pixelCount; + case NDSColorFormat_BGR666_Rev: + case NDSColorFormat_BGR888_Rev: + ColorspaceConvertBuffer555To8888Opaque(src, working, GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT); + break; + + default: + break; + } + + if (mutableInfo.pixelBytes == 2) + { + u16 *__restrict dst = (u16 *__restrict)this->_customBuffer; + + for (size_t y = 0; y < GPU_FRAMEBUFFER_NATIVE_HEIGHT; y++) + { + const GPUEngineLineInfo &lineInfo = GPU->GetLineInfoAtIndex(y); + CopyLineExpandHinted<0x3FFF, true, false, false, 2>(lineInfo, src, dst); + src += GPU_FRAMEBUFFER_NATIVE_WIDTH; + dst += lineInfo.pixelCount; + } + } + else if (mutableInfo.pixelBytes == 4) + { + u32 *__restrict dst = (u32 *__restrict)this->_customBuffer; + + for (size_t y = 0; y < GPU_FRAMEBUFFER_NATIVE_HEIGHT; y++) + { + const GPUEngineLineInfo &lineInfo = GPU->GetLineInfoAtIndex(y); + CopyLineExpandHinted<0x3FFF, true, false, false, 4>(lineInfo, working, dst); + working += GPU_FRAMEBUFFER_NATIVE_WIDTH; + dst += lineInfo.pixelCount; + } } } - else if (mutableInfo.pixelBytes == 4) + else { - u32 *__restrict dst = (u32 *__restrict)this->_customBuffer; - - for (size_t y = 0; y < GPU_FRAMEBUFFER_NATIVE_HEIGHT; y++) + switch (mutableInfo.colorFormat) { - const GPUEngineLineInfo &lineInfo = GPU->GetLineInfoAtIndex(y); - CopyLineExpandHinted<0x3FFF, true, false, false, 4>(lineInfo, working, dst); - working += GPU_FRAMEBUFFER_NATIVE_WIDTH; - dst += lineInfo.pixelCount; + case NDSColorFormat_BGR555_Rev: + memcpy(this->_customBuffer, this->_nativeBuffer16, GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT * sizeof(u16)); + break; + + case NDSColorFormat_BGR666_Rev: + case NDSColorFormat_BGR888_Rev: + ColorspaceConvertBuffer555To8888Opaque(this->_nativeBuffer16, (u32 *)this->_customBuffer, GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT); + break; } } diff --git a/desmume/src/frontend/posix/cli/main.cpp b/desmume/src/frontend/posix/cli/main.cpp index 898fbdadc..d5d420d53 100644 --- a/desmume/src/frontend/posix/cli/main.cpp +++ b/desmume/src/frontend/posix/cli/main.cpp @@ -708,7 +708,7 @@ int main(int argc, char ** argv) { // Now that gtk port draws to RGBA buffer directly, the other one // has to use ugly ways to make HUD rendering work again. // desmume gtk: Sorry desmume-cli :( - T_AGG_RGB555 agg_targetScreen_cli((u8 *)GPU->GetDisplayInfo().masterCustomBuffer, 256, 384, 512); + T_AGG_RGB555 agg_targetScreen_cli((u8 *)GPU->GetDisplayInfo().masterNativeBuffer16, 256, 384, 512); aggDraw.hud = &agg_targetScreen_cli; aggDraw.hud->setFont("verdana18_bold");