From 52c12f01e5fc7a97de5ccad2243e68693b0c45b9 Mon Sep 17 00:00:00 2001 From: M4xw Date: Tue, 16 Jun 2020 20:01:40 +0100 Subject: [PATCH 1/6] Nativeres shit --- GLideN64/src/DisplayWindow.h | 14 +++++++--- .../mupen64plus/mupen64plus_DisplayWindow.cpp | 4 +-- GLideN64/src/VI.cpp | 18 +++++++++++- libretro/libretro.c | 28 ++++++++++++++++++- 4 files changed, 56 insertions(+), 8 deletions(-) diff --git a/GLideN64/src/DisplayWindow.h b/GLideN64/src/DisplayWindow.h index 3e4dbd452..d4489bb13 100644 --- a/GLideN64/src/DisplayWindow.h +++ b/GLideN64/src/DisplayWindow.h @@ -1,6 +1,12 @@ #pragma once #include "Types.h" #include "GraphicsDrawer.h" +#include "VI.h" + +extern uint32_t retro_screen_width; +extern uint32_t retro_screen_height; +extern uint32_t max_retro_screen_width; +extern uint32_t max_retro_screen_height; class DisplayWindow { @@ -28,10 +34,10 @@ class DisplayWindow f32 getScaleY() const { return m_scaleY; } f32 getAdjustScale() const { return m_adjustScale; } u32 getBuffersSwapCount() const { return m_buffersSwapCount; } - u32 getWidth() const { return m_width; } - u32 getHeight() const { return m_height; } - u32 getScreenWidth() const { return m_screenWidth; } - u32 getScreenHeight() const { return m_screenHeight; } + u32 getWidth() const { return retro_screen_width; } + u32 getHeight() const { return retro_screen_height; } + u32 getScreenWidth() const { return max_retro_screen_width; } + u32 getScreenHeight() const { return max_retro_screen_height; } u32 getHeightOffset() const { return m_heightOffset; } bool isFullscreen() const { return m_bFullscreen; } bool isAdjustScreen() const { return m_bAdjustScreen; } diff --git a/GLideN64/src/Graphics/OpenGLContext/mupen64plus/mupen64plus_DisplayWindow.cpp b/GLideN64/src/Graphics/OpenGLContext/mupen64plus/mupen64plus_DisplayWindow.cpp index a9a4ea360..f9300e02f 100644 --- a/GLideN64/src/Graphics/OpenGLContext/mupen64plus/mupen64plus_DisplayWindow.cpp +++ b/GLideN64/src/Graphics/OpenGLContext/mupen64plus/mupen64plus_DisplayWindow.cpp @@ -103,8 +103,8 @@ bool DisplayWindowMupen64plus::_resizeWindow() { _setAttributes(); m_bFullscreen = true; - m_width = m_screenWidth = m_resizeWidth; - m_height = m_screenHeight = m_resizeHeight; + m_width = m_resizeWidth; + m_height = m_resizeHeight; opengl::Utils::isGLError(); // reset GL error. return true; diff --git a/GLideN64/src/VI.cpp b/GLideN64/src/VI.cpp index 92ebaadda..0b8a61c2f 100644 --- a/GLideN64/src/VI.cpp +++ b/GLideN64/src/VI.cpp @@ -98,6 +98,14 @@ void VI_UpdateSize() VI.rheight = VI.height != 0 ? 1.0f / VI.height : 0.0f; } +extern uint32_t retro_screen_width; +extern uint32_t retro_screen_height; +extern uint32_t EnableNativeResFactor; +extern "C" { + uint32_t last_vi_width = retro_screen_width; + uint32_t last_vi_height = retro_screen_height; +} + void VI_UpdateScreen() { if (VI.lastOrigin == -1) // Workaround for Mupen64Plus issue with initialization @@ -108,8 +116,16 @@ void VI_UpdateScreen() if (ConfigOpen) return; - perf.increaseVICount(); DisplayWindow & wnd = dwnd(); + if(VI.lastOrigin != -1 && (VI.height != last_vi_height || VI.width != last_vi_width)) + { + printf("VI_UpdateScreen Origin: %08x, Old origin: %08x, width: %d, height: %d\n", *REG.VI_ORIGIN, VI.lastOrigin, VI.width, VI.height); + last_vi_width = retro_screen_width = VI.width; + last_vi_height = retro_screen_height = VI.height; + //wnd.setWindowSize(last_vi_width, last_vi_height); + } + + perf.increaseVICount(); if (wnd.changeWindow()) return; if (wnd.resizeWindow()) diff --git a/libretro/libretro.c b/libretro/libretro.c index dd1a06d72..e8cdf7b38 100644 --- a/libretro/libretro.c +++ b/libretro/libretro.c @@ -144,6 +144,13 @@ uint32_t *blitter_buf = NULL; uint32_t *blitter_buf_lock = NULL; uint32_t retro_screen_width = 640; uint32_t retro_screen_height = 480; +uint32_t max_retro_screen_width = 320; +uint32_t max_retro_screen_height = 240; +uint32_t last_retro_screen_width = 320; +uint32_t last_retro_screen_height = 240; +struct retro_game_geometry active_geometry; +extern uint32_t last_vi_width; +extern uint32_t last_vi_height; uint32_t screen_pitch = 0; float retro_screen_aspect = 4.0 / 3.0; @@ -445,13 +452,22 @@ void retro_get_system_av_info(struct retro_system_av_info *info) info->geometry.base_height = retro_screen_height; info->geometry.max_width = retro_screen_width; info->geometry.max_height = retro_screen_height; - info->geometry.aspect_ratio = retro_screen_aspect; + info->geometry.aspect_ratio = ((float)retro_screen_width) / ((float)retro_screen_height); #ifdef HAVE_PARALLEL_RDP if (current_rdp_type == RDP_PLUGIN_PARALLEL) parallel_get_geometry(&info->geometry); #endif info->timing.fps = vi_expected_refresh_rate_from_tv_standard(ROM_PARAMS.systemtype); info->timing.sample_rate = 44100.0; + memcpy(&active_geometry, &info->geometry, sizeof(struct retro_game_geometry)); +} + +void retro_set_geometry_runtime(uint32_t width, uint32_t height) +{ + active_geometry.base_height = height; + active_geometry.base_width = width; + active_geometry.aspect_ratio = ((float)retro_screen_width) / ((float)retro_screen_height); + environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &active_geometry); } unsigned retro_get_region (void) @@ -1048,6 +1064,9 @@ static void update_variables(bool startup) // Force factor to 1 for low resolutions, unless set manually EnableNativeResFactor = !EnableNativeResFactor ? 1 : EnableNativeResFactor; } + // Save active configuration as max value + max_retro_screen_width = retro_screen_width; + max_retro_screen_height = retro_screen_height; } // If we use Angrylion, we force 640x480 @@ -1644,6 +1663,13 @@ void retro_run (void) glsm_ctl(GLSM_CTL_STATE_UNBIND, NULL); } + if(last_vi_height != last_retro_screen_height && last_vi_width != last_retro_screen_width) + { + last_retro_screen_height = last_vi_height; + last_retro_screen_width = last_vi_width; + retro_set_geometry_runtime(last_retro_screen_width, last_retro_screen_height); + } + if (libretro_swap_buffer) { if(current_rdp_type == RDP_PLUGIN_GLIDEN64) From eae58c94a97be010112f6e3c3fc795155eaf4bf7 Mon Sep 17 00:00:00 2001 From: David Lawson Date: Wed, 17 Jun 2020 22:38:48 +0100 Subject: [PATCH 2/6] Remove unnecessary extern --- GLideN64/src/VI.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/GLideN64/src/VI.cpp b/GLideN64/src/VI.cpp index 0b8a61c2f..265eb9133 100644 --- a/GLideN64/src/VI.cpp +++ b/GLideN64/src/VI.cpp @@ -100,7 +100,6 @@ void VI_UpdateSize() extern uint32_t retro_screen_width; extern uint32_t retro_screen_height; -extern uint32_t EnableNativeResFactor; extern "C" { uint32_t last_vi_width = retro_screen_width; uint32_t last_vi_height = retro_screen_height; From 9f9bbd694b036503b60f450304d2f92191e05350 Mon Sep 17 00:00:00 2001 From: David Lawson Date: Wed, 17 Jun 2020 23:54:04 +0100 Subject: [PATCH 3/6] Set info->geometry.max_width/height = retro_screen_width/height --- GLideN64/src/VI.cpp | 1 - libretro/libretro.c | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/GLideN64/src/VI.cpp b/GLideN64/src/VI.cpp index 265eb9133..06e09813d 100644 --- a/GLideN64/src/VI.cpp +++ b/GLideN64/src/VI.cpp @@ -121,7 +121,6 @@ void VI_UpdateScreen() printf("VI_UpdateScreen Origin: %08x, Old origin: %08x, width: %d, height: %d\n", *REG.VI_ORIGIN, VI.lastOrigin, VI.width, VI.height); last_vi_width = retro_screen_width = VI.width; last_vi_height = retro_screen_height = VI.height; - //wnd.setWindowSize(last_vi_width, last_vi_height); } perf.increaseVICount(); diff --git a/libretro/libretro.c b/libretro/libretro.c index e8cdf7b38..d7b74fb52 100644 --- a/libretro/libretro.c +++ b/libretro/libretro.c @@ -450,8 +450,8 @@ void retro_get_system_av_info(struct retro_system_av_info *info) { info->geometry.base_width = retro_screen_width; info->geometry.base_height = retro_screen_height; - info->geometry.max_width = retro_screen_width; - info->geometry.max_height = retro_screen_height; + info->geometry.max_width = max_retro_screen_width; + info->geometry.max_height = max_retro_screen_height; info->geometry.aspect_ratio = ((float)retro_screen_width) / ((float)retro_screen_height); #ifdef HAVE_PARALLEL_RDP if (current_rdp_type == RDP_PLUGIN_PARALLEL) From 112d7a0c047f9131f22cb3de6fb8369cf6582efc Mon Sep 17 00:00:00 2001 From: David Lawson Date: Fri, 26 Jun 2020 07:40:33 +0100 Subject: [PATCH 4/6] Set initial max_retro_screen_width/height and last_retro_screen_width/height to 640x480 --- libretro/libretro.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libretro/libretro.c b/libretro/libretro.c index d7b74fb52..d0f61417e 100644 --- a/libretro/libretro.c +++ b/libretro/libretro.c @@ -144,10 +144,10 @@ uint32_t *blitter_buf = NULL; uint32_t *blitter_buf_lock = NULL; uint32_t retro_screen_width = 640; uint32_t retro_screen_height = 480; -uint32_t max_retro_screen_width = 320; -uint32_t max_retro_screen_height = 240; -uint32_t last_retro_screen_width = 320; -uint32_t last_retro_screen_height = 240; +uint32_t max_retro_screen_width = 640; +uint32_t max_retro_screen_height = 480; +uint32_t last_retro_screen_width = 640; +uint32_t last_retro_screen_height = 480; struct retro_game_geometry active_geometry; extern uint32_t last_vi_width; extern uint32_t last_vi_height; From 4c29e5a12d4445b02f44ad26d8e192287429d379 Mon Sep 17 00:00:00 2001 From: David Lawson Date: Fri, 26 Jun 2020 07:45:03 +0100 Subject: [PATCH 5/6] Call retro_set_geometry_runtime when width OR height has changed --- libretro/libretro.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libretro/libretro.c b/libretro/libretro.c index d0f61417e..2b2145ef5 100644 --- a/libretro/libretro.c +++ b/libretro/libretro.c @@ -1663,7 +1663,7 @@ void retro_run (void) glsm_ctl(GLSM_CTL_STATE_UNBIND, NULL); } - if(last_vi_height != last_retro_screen_height && last_vi_width != last_retro_screen_width) + if(last_vi_height != last_retro_screen_height || last_vi_width != last_retro_screen_width) { last_retro_screen_height = last_vi_height; last_retro_screen_width = last_vi_width; From 6e9a06a8ce287805e288c4cc2a346f3b6df7068f Mon Sep 17 00:00:00 2001 From: David Lawson Date: Sat, 27 Jun 2020 11:23:21 +0100 Subject: [PATCH 6/6] Factor out getting VI.width/height to make it easier to try stuff --- GLideN64/src/VI.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/GLideN64/src/VI.cpp b/GLideN64/src/VI.cpp index 06e09813d..d2736b416 100644 --- a/GLideN64/src/VI.cpp +++ b/GLideN64/src/VI.cpp @@ -116,11 +116,14 @@ void VI_UpdateScreen() return; DisplayWindow & wnd = dwnd(); - if(VI.lastOrigin != -1 && (VI.height != last_vi_height || VI.width != last_vi_width)) + + uint32_t width = VI.width; + uint32_t height = VI.height; + if(VI.lastOrigin != -1 && (height != last_vi_height || width != last_vi_width)) { printf("VI_UpdateScreen Origin: %08x, Old origin: %08x, width: %d, height: %d\n", *REG.VI_ORIGIN, VI.lastOrigin, VI.width, VI.height); - last_vi_width = retro_screen_width = VI.width; - last_vi_height = retro_screen_height = VI.height; + last_vi_width = retro_screen_width = width; + last_vi_height = retro_screen_height = height; } perf.increaseVICount();