From 0055b8f7c7a07177868a6b94bc79f5b45b070997 Mon Sep 17 00:00:00 2001 From: Floogle <18466542+skyfloogle@users.noreply.github.com> Date: Wed, 27 Mar 2024 22:54:00 +0100 Subject: [PATCH] full-range 24-bit colour --- source/3ds/video.c | 13 +++++++++---- source/3ds/video_hard.c | 6 ++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/source/3ds/video.c b/source/3ds/video.c index 4703071..02cd83b 100644 --- a/source/3ds/video.c +++ b/source/3ds/video.c @@ -162,10 +162,6 @@ void video_init() { GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGB8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) | \ GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO)) C3D_Init(C3D_DEFAULT_CMDBUF_SIZE * 4); - finalScreen[0] = C3D_RenderTargetCreate(240, 400, GPU_RB_RGB8, -1); - C3D_RenderTargetSetOutput(finalScreen[0], GFX_TOP, GFX_LEFT, DISPLAY_TRANSFER_FLAGS); - finalScreen[1] = C3D_RenderTargetCreate(240, 400, GPU_RB_RGB8, -1); - C3D_RenderTargetSetOutput(finalScreen[1], GFX_TOP, GFX_RIGHT, DISPLAY_TRANSFER_FLAGS); sFinal_dvlb = DVLB_ParseFile((u32 *)final_shbin, final_shbin_size); shaderProgramInit(&sFinal); @@ -190,6 +186,15 @@ void video_init() { video_hard_init(); video_soft_init(); + + // The hardware renderer creates 1 * 0.75MB + 4 * 1MB framebuffers. + // The 3DS has two 3MB VRAM banks, so for this to work, 3 framebuffers must go into one bank. + // However, the allocator alternates between banks, so we need to allocate those first, + // before even the final render targets. + finalScreen[0] = C3D_RenderTargetCreate(240, 400, GPU_RB_RGB8, -1); + C3D_RenderTargetSetOutput(finalScreen[0], GFX_TOP, GFX_LEFT, DISPLAY_TRANSFER_FLAGS); + finalScreen[1] = C3D_RenderTargetCreate(240, 400, GPU_RB_RGB8, -1); + C3D_RenderTargetSetOutput(finalScreen[1], GFX_TOP, GFX_RIGHT, DISPLAY_TRANSFER_FLAGS); } void video_render(int alt_buf) { diff --git a/source/3ds/video_hard.c b/source/3ds/video_hard.c index 864d8d9..39cc182 100644 --- a/source/3ds/video_hard.c +++ b/source/3ds/video_hard.c @@ -105,14 +105,16 @@ void video_hard_init() { params.width = 512; params.height = 512; - params.format = GPU_RGBA4; + params.format = GPU_RGB8; params.onVram = true; C3D_TexInitWithParams(&screenTexHard, NULL, params); - screenTarget = C3D_RenderTargetCreateFromTex(&screenTexHard, GPU_TEX_2D, 0, GPU_RB_DEPTH16); + // Drawing backwards with a depth buffer isn't faster, so omit the depth buffer. + screenTarget = C3D_RenderTargetCreateFromTex(&screenTexHard, GPU_TEX_2D, 0, -1); C3D_RenderTargetClear(screenTarget, C3D_CLEAR_ALL, 0, 0); params.width = 512; params.height = 512; + params.format = GPU_RGBA8; for (int i = 0; i < AFFINE_CACHE_SIZE; i++) { C3D_TexInitWithParams(&tileMapCache[i].tex, NULL, params); tileMapCache[i].target = C3D_RenderTargetCreateFromTex(&tileMapCache[i].tex, GPU_TEX_2D, 0, -1);