From 2cb29e91c6dfee3cc2929fb28aca8df63d990427 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Wed, 13 Nov 2024 14:04:36 +0100 Subject: [PATCH] port: only run the menu blur filter once --- port/fast3d/gfx_pc.cpp | 49 +++++++++++++++++++----------------------- src/game/menugfx.c | 34 ++++++++++++++++++++--------- 2 files changed, 46 insertions(+), 37 deletions(-) diff --git a/port/fast3d/gfx_pc.cpp b/port/fast3d/gfx_pc.cpp index df813796e..571e03f05 100644 --- a/port/fast3d/gfx_pc.cpp +++ b/port/fast3d/gfx_pc.cpp @@ -1637,34 +1637,27 @@ static void gfx_sp_extra_geometry_mode(uint32_t clear, uint32_t set) { } static void gfx_adjust_viewport_or_scissor(XYWidthHeight* area, bool preserve_aspect = false) { - if (!fbActive) { - area->width *= RATIO_X; - area->x *= RATIO_X; - area->height *= RATIO_Y; - area->y = SCREEN_HEIGHT - area->y; - area->y *= RATIO_Y; - if (preserve_aspect) { - // preserve native aspect ratio - const float ratio = gfx_current_native_aspect / gfx_current_dimensions.aspect_ratio; - const float midx = gfx_current_dimensions.width * 0.5f; - area->x = midx + (area->x - midx) * ratio; - area->x += rsp.aspect_ofs * gfx_current_dimensions.width * 0.5f; - area->width *= ratio; - } + // HACK: assume all target framebuffers have the same aspect + area->width *= RATIO_X; + area->x *= RATIO_X; + area->height *= RATIO_Y; + area->y = SCREEN_HEIGHT - area->y; + area->y *= RATIO_Y; + if (preserve_aspect) { + // preserve native aspect ratio + const float ratio = gfx_current_native_aspect / gfx_current_dimensions.aspect_ratio; + const float midx = gfx_current_dimensions.width * 0.5f; + area->x = midx + (area->x - midx) * ratio; + area->x += rsp.aspect_ofs * gfx_current_dimensions.width * 0.5f; + area->width *= ratio; + } - if (!game_renders_to_framebuffer || - (gfx_msaa_level > 1 && gfx_current_dimensions.width == gfx_current_game_window_viewport.width && - gfx_current_dimensions.height == gfx_current_game_window_viewport.height)) { - area->x += gfx_current_game_window_viewport.x; - area->y += gfx_current_window_dimensions.height - - (gfx_current_game_window_viewport.y + gfx_current_game_window_viewport.height); - } - } else { - area->width *= RATIO_Y; - area->height *= RATIO_Y; - area->x *= RATIO_Y; - area->y = active_fb->second.orig_height - area->y; - area->y *= RATIO_Y; + if (!game_renders_to_framebuffer || + (gfx_msaa_level > 1 && gfx_current_dimensions.width == gfx_current_game_window_viewport.width && + gfx_current_dimensions.height == gfx_current_game_window_viewport.height)) { + area->x += gfx_current_game_window_viewport.x; + area->y += gfx_current_window_dimensions.height - + (gfx_current_game_window_viewport.y + gfx_current_game_window_viewport.height); } } @@ -2726,6 +2719,7 @@ extern "C" void gfx_resize_framebuffer(int fb, uint32_t width, uint32_t height, extern "C" void gfx_set_framebuffer(int fb, float noise_scale) { gfx_rapi->start_draw_to_framebuffer(fb, noise_scale); gfx_rapi->clear_framebuffer(true, true); + active_fb = framebuffers.find(fb); } extern "C" void gfx_copy_framebuffer(int fb_dst, int fb_src, int left, int top, int use_back) { @@ -2750,4 +2744,5 @@ extern "C" void gfx_copy_framebuffer(int fb_dst, int fb_src, int left, int top, extern "C" void gfx_reset_framebuffer(void) { gfx_rapi->start_draw_to_framebuffer(0, (float)gfx_current_dimensions.height / SCREEN_HEIGHT); + active_fb = framebuffers.end(); } diff --git a/src/game/menugfx.c b/src/game/menugfx.c index 273e2c6f1..daa4aa00c 100644 --- a/src/game/menugfx.c +++ b/src/game/menugfx.c @@ -19,6 +19,7 @@ #include "types.h" #ifndef PLATFORM_N64 #include "video.h" +#include "game/bondview.h" #endif #define NUM_SUCCESS_PARTICLES 280 @@ -30,7 +31,8 @@ #define PXTOBYTES(val) ((val) * 2) #ifndef PLATFORM_N64 -s32 g_MenuBlurFb = 0; +static s32 g_MenuBlurFb = 0; +static bool g_MenuBlurDone = false; #endif /** @@ -127,6 +129,8 @@ void menugfxCreateBlur(void) } // copy full viewport and downscale to 40x30 videoCopyFramebuffer(g_MenuBlurFb, 0, -1, -1); + // we'll generate a blurred version later + g_MenuBlurDone = false; #endif } @@ -144,6 +148,23 @@ Gfx *menugfxRenderBgBlur(Gfx *gdl, u32 colour, s16 arg2, s16 arg3) return menugfxRenderGradient(gdl, 0, 0, viGetWidth(), viGetHeight(), 0xff, 0xff, 0xff); } +#ifndef PLATFORM_N64 + width = viGetWidth(); + height = viGetHeight(); + if (g_MenuBlurFb && !g_MenuBlurDone) { + // blit the small blur texture onto a screen-sized framebuffer while blurring it + g_MenuBlurDone = true; + g_BlurFbDirty = true; + gdl = bviewPrepareStaticRgba16(gdl, 0xffffffff, 0xff); + gDPSetTextureFilter(gdl++, G_TF_BLUR_EXT); + gDPSetFramebufferTextureEXT(gdl++, G_IM_FMT_RGBA, G_IM_SIZ_16b, BLURIMG_WIDTH, g_MenuBlurFb); + gDPSetFramebufferTargetEXT(gdl++, G_IM_FMT_RGBA, G_IM_SIZ_16b, width, g_BlurFb); + gSPImageRectangleEXT(gdl++, 0, 0, 0, 0, width << 2, height << 2, BLURIMG_WIDTH, BLURIMG_HEIGHT, 0, BLURIMG_WIDTH, BLURIMG_HEIGHT); + gDPSetFramebufferTargetEXT(gdl++, G_IM_FMT_RGBA, G_IM_SIZ_16b, width, 0); + gDPSetFramebufferTextureEXT(gdl++, G_IM_FMT_RGBA, G_IM_SIZ_16b, BLURIMG_WIDTH, 0); + } +#endif + colours = gfxAllocateColours(1); vertices = gfxAllocateVertices(4); @@ -155,8 +176,8 @@ Gfx *menugfxRenderBgBlur(Gfx *gdl, u32 colour, s16 arg2, s16 arg3) G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); #ifndef PLATFORM_N64 - // let gDPLoadTextureBlock above set the size, then overwrite the texture selection with our fb texture - gDPSetFramebufferTextureEXT(gdl++, G_IM_FMT_RGBA, G_IM_SIZ_16b, BLURIMG_WIDTH, g_MenuBlurFb); + // LoadTextureBlock will set up the sizes, but we'll use the framebuffer instead of g_BlurBuffer + gDPSetFramebufferTextureEXT(gdl++, G_IM_FMT_RGBA, G_IM_SIZ_16b, width, g_BlurFb); #endif gDPPipeSync(gdl++); @@ -164,14 +185,7 @@ Gfx *menugfxRenderBgBlur(Gfx *gdl, u32 colour, s16 arg2, s16 arg3) gDPSetAlphaCompare(gdl++, G_AC_NONE); gDPSetCombineMode(gdl++, G_CC_MODULATEI, G_CC_MODULATEI); gSPClearGeometryMode(gdl++, G_CULL_BOTH); - -#ifdef PLATFORM_N64 gDPSetTextureFilter(gdl++, G_TF_BILERP); -#else - // enable blur filter for the texture - gDPSetTextureFilter(gdl++, G_TF_BLUR_EXT); -#endif - gDPSetRenderMode(gdl++, G_RM_XLU_SURF, G_RM_XLU_SURF2); #if VERSION >= VERSION_JPN_FINAL