Skip to content

Commit 66f718f

Browse files
sampavlovicscomitch
authored andcommitted
Make MSAA setting work on editor SceneRenderingWidgets (#3539)
* Make MSAA setting work on editor SceneRenderingWidgets MSAA settings never worked with editor viewport, only on game tab, now with playmode it always takes highest MSAA value from hardware regardless of what Two things from this PR: * Pass current engine MSAA setting when creating SceneRenderingWidget swapchain * Add callback when video settings are changed, recreate swapchain when so Replicates fine for all SceneRenderingWidgets, applies instantly https://files.facepunch.com/sampavlovic/1b0311b1/sbox-dev_bjEMrrYe71.mp4 * Push RenderMultisampleType_t nMSAAAmount on interop
1 parent 2fe292b commit 66f718f

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

engine/Definitions/tools/widgetutil.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ native static class WidgetUtil Native.WidgetUtil
1717
static void PostKeyEvent( QWidget target, int key );
1818

1919
static void PaintSetFont( QPainter painter, string fontName, int size, int weight, bool italic, bool heightInPixels );
20-
static SwapChainHandle_t CreateSwapChain( QWidget target );
20+
static SwapChainHandle_t CreateSwapChain( QWidget target, RenderMultisampleType_t nMSAAAmount );
2121

2222
static void SetWindowNoActivate( QWidget widget );
2323

engine/Sandbox.Engine/Systems/Render/Settings/RenderSettings.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using NativeEngine;
1+
using System;
2+
using NativeEngine;
3+
24

35
namespace Sandbox.Engine.Settings;
46

@@ -11,6 +13,7 @@ public partial class RenderSettings
1113

1214
internal CookieContainer VideoSettings { get; } = new( "video", true );
1315

16+
public event Action OnVideoSettingsChanged;
1417
internal RenderQualityProfiles Config { get; } = new();
1518

1619
internal RenderSettings()
@@ -100,6 +103,8 @@ public void Apply()
100103
{
101104
ApplyVideoMode();
102105

106+
OnVideoSettingsChanged?.Invoke();
107+
103108
VideoSettings.Save();
104109
}
105110

engine/Sandbox.Tools/Qt/SceneRenderingWidget.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
22

3+
using Sandbox.Engine.Settings;
4+
35
namespace Editor;
46

57
/// <summary>
@@ -35,7 +37,8 @@ public SceneRenderingWidget( Widget parent = null ) : base( parent )
3537
SetFlag( Flag.WA_NoSystemBackground, true );
3638
SetFlag( Flag.WA_OpaquePaintEvent, true );
3739

38-
SwapChain = WidgetUtil.CreateSwapChain( _widget );
40+
SwapChain = WidgetUtil.CreateSwapChain( _widget, RenderSettings.Instance.AntiAliasQuality.ToEngine() );
41+
RenderSettings.Instance.OnVideoSettingsChanged += HandleVideoChanged;
3942

4043
FocusMode = FocusMode.Click; // If we're focused we're probably accepting input, don't let tab blur us
4144

@@ -47,6 +50,7 @@ internal override void NativeShutdown()
4750
base.NativeShutdown();
4851

4952
All.Remove( this );
53+
RenderSettings.Instance.OnVideoSettingsChanged -= HandleVideoChanged;
5054

5155
// The swapchain might still be in use by native, so defer its destruction until the end of the frame.
5256
// Otherwise, a race condition could occur where render targets are accessed after destruction, causing a delayed crash.
@@ -126,6 +130,8 @@ void Render()
126130
if ( !Scene.IsValid() ) return;
127131
if ( !Visible ) return;
128132

133+
if ( SwapChain == default ) return;
134+
129135
using ( Scene.Push() )
130136
{
131137
using ( GizmoInstance.Push() )
@@ -199,6 +205,22 @@ public Ray GetRay( Vector2 localPosition )
199205
return camera.GetRay( localPosition, Size );
200206
}
201207

208+
internal void HandleVideoChanged()
209+
{
210+
var oldSwapChain = SwapChain;
211+
SwapChain = WidgetUtil.CreateSwapChain( _widget, RenderSettings.Instance.AntiAliasQuality.ToEngine() );
212+
if ( SwapChain == default )
213+
{
214+
SwapChain = oldSwapChain;
215+
return;
216+
}
217+
218+
if ( oldSwapChain != default )
219+
{
220+
EngineLoop.DisposeAtFrameEnd( new Sandbox.Utility.DisposeAction( () => g_pRenderDevice.DestroySwapChain( oldSwapChain ) ) );
221+
}
222+
}
223+
202224
internal static void RenderAll()
203225
{
204226
foreach ( var widget in All )

0 commit comments

Comments
 (0)