From 1a9176e12f6400091e02edd02b8d4e844db465c5 Mon Sep 17 00:00:00 2001 From: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com> Date: Sat, 1 Jun 2024 14:01:01 -0700 Subject: [PATCH] Fix "double rendering" in Lua/ApiHawk gui stuff --- src/BizHawk.Bizware.Graphics/Interfaces/I2DRenderer.cs | 6 ++++++ src/BizHawk.Bizware.Graphics/Renderers/ImGui2DRenderer.cs | 3 +++ src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs | 2 +- .../DisplayManager/DisplayManagerBase.cs | 8 ++++++++ src/BizHawk.Client.Common/IMainFormForApi.cs | 2 +- src/BizHawk.Client.EmuHawk/IMainFormForTools.cs | 2 +- src/BizHawk.Client.EmuHawk/MainForm.cs | 8 +++++++- 7 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/BizHawk.Bizware.Graphics/Interfaces/I2DRenderer.cs b/src/BizHawk.Bizware.Graphics/Interfaces/I2DRenderer.cs index bf80dd8cd09..6946de88e7e 100644 --- a/src/BizHawk.Bizware.Graphics/Interfaces/I2DRenderer.cs +++ b/src/BizHawk.Bizware.Graphics/Interfaces/I2DRenderer.cs @@ -29,6 +29,12 @@ public interface I2DRenderer : IDisposable /// void Clear(); + /// + /// Discards any pending draw calls. + /// Similar to Clear(), except this won't insert a command to clear the target texture + /// + void Discard(); + CompositingMode CompositingMode { set; } void DrawBezier(Color color, Point pt1, Point pt2, Point pt3, Point pt4); diff --git a/src/BizHawk.Bizware.Graphics/Renderers/ImGui2DRenderer.cs b/src/BizHawk.Bizware.Graphics/Renderers/ImGui2DRenderer.cs index afe48c4c14b..394d293d4ca 100644 --- a/src/BizHawk.Bizware.Graphics/Renderers/ImGui2DRenderer.cs +++ b/src/BizHawk.Bizware.Graphics/Renderers/ImGui2DRenderer.cs @@ -302,6 +302,9 @@ public void Clear() _hasClearPending = true; } + public void Discard() + => ResetDrawList(); + protected bool EnableBlending { get; private set; } private bool _pendingBlendEnable; diff --git a/src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs b/src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs index a1c4aa63c2a..113cfcce531 100644 --- a/src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs +++ b/src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs @@ -90,7 +90,7 @@ public void Dispose() public void DoFrameAdvance() { - _mainForm.FrameAdvance(); + _mainForm.FrameAdvance(discardApiHawkSurfaces: false); // we're rendering, so we don't want to discard _mainForm.StepRunLoop_Throttle(); _mainForm.Render(); } diff --git a/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs b/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs index caa38a4ba45..566a6fdd93d 100644 --- a/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs +++ b/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs @@ -933,5 +933,13 @@ public void ClearApiHawkSurfaces() renderer.Clear(); } } + + public void DiscardApiHawkSurfaces() + { + foreach (var renderer in _apiHawkIDTo2DRenderer.Values) + { + renderer.Discard(); + } + } } } diff --git a/src/BizHawk.Client.Common/IMainFormForApi.cs b/src/BizHawk.Client.Common/IMainFormForApi.cs index 343aeff4ce6..b835fa02ed0 100644 --- a/src/BizHawk.Client.Common/IMainFormForApi.cs +++ b/src/BizHawk.Client.Common/IMainFormForApi.cs @@ -52,7 +52,7 @@ public interface IMainFormForApi bool FlushSaveRAM(bool autosave = false); /// only referenced from EmuClientApi - void FrameAdvance(); + void FrameAdvance(bool discardApiHawkSurfaces = true); void FrameBufferResized(); diff --git a/src/BizHawk.Client.EmuHawk/IMainFormForTools.cs b/src/BizHawk.Client.EmuHawk/IMainFormForTools.cs index dcc52ea5f1f..db3b8031ff8 100644 --- a/src/BizHawk.Client.EmuHawk/IMainFormForTools.cs +++ b/src/BizHawk.Client.EmuHawk/IMainFormForTools.cs @@ -56,7 +56,7 @@ public interface IMainFormForTools : IDialogController bool EnsureCoreIsAccurate(); /// only referenced from - void FrameAdvance(); + void FrameAdvance(bool discardApiHawkSurfaces = true); /// only referenced from void FrameBufferResized(); diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index cb3d706d3d7..34e200ccbe3 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -2477,6 +2477,7 @@ private void SaveSlotSelectedMessage() { if (Config.DispSpeedupFeatures == 0) { + DisplayManager.DiscardApiHawkSurfaces(); return; } @@ -3069,16 +3070,21 @@ private void LoadConfigFile(string iniPath) _throttle.Step(Config, Sound, allowSleep: true, forceFrameSkip: -1); } - public void FrameAdvance() + public void FrameAdvance(bool discardApiHawkSurfaces) { PressFrameAdvance = true; StepRunLoop_Core(true); + if (discardApiHawkSurfaces) + { + DisplayManager.DiscardApiHawkSurfaces(); + } } public void SeekFrameAdvance() { PressFrameAdvance = true; StepRunLoop_Core(true); + DisplayManager.DiscardApiHawkSurfaces(); PressFrameAdvance = false; }