Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions ControlApp.Tests/MotionViewerRenderingTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Windows.Interop;
using HelixToolkit.SharpDX;

using Nefarius.DsHidMini.ControlApp.Models;
using Nefarius.DsHidMini.ControlApp.Models.Motion;
Expand All @@ -11,21 +11,19 @@ namespace Nefarius.DsHidMini.ControlApp.Tests;
public class MotionViewerRenderingTests
{
[Fact]
public void Select_HardwareStaysOnTheGraphicsDriver()
public void Configuration_HardwareUsesTheGraphicsDriver()
{
Assert.Equal(RenderMode.Default, MotionViewerRendering.Select(false));
}
EffectsManagerConfiguration configuration = MotionViewerRendering.CreateConfiguration(false);

[Fact]
public void Select_SoftwareUsesTheCpuRasterizer()
{
Assert.Equal(RenderMode.SoftwareOnly, MotionViewerRendering.Select(true));
Assert.False(configuration.EnableSoftwareRendering);
}

[Fact]
public void Apply_NullWindowIsIgnored()
public void Configuration_SoftwareUsesWarp()
{
MotionViewerRendering.Apply(null, true);
EffectsManagerConfiguration configuration = MotionViewerRendering.CreateConfiguration(true);

Assert.True(configuration.EnableSoftwareRendering);
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion ControlApp/ControlApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.5" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.2" />
<PackageReference Include="HelixToolkit.Wpf" Version="3.1.2" />
<PackageReference Include="HelixToolkit.Wpf.SharpDX" Version="3.1.2" />
<PackageReference Include="WPF-UI" Version="4.2.0" />
<PackageReference Include="WPF-UI.DependencyInjection" Version="4.2.0" />
<PackageReference Include="WPF-UI.Tray" Version="4.2.0" />
Expand Down
2 changes: 1 addition & 1 deletion ControlApp/Models/ApplicationConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public class ApplicationConfiguration
public WindowState WindowState { get; set; } = WindowState.Normal;

/// <summary>
/// When true, the Motion viewer draws its 3D preview with the CPU rasterizer.
/// When true, the Motion viewer draws its 3D preview with DirectX software rendering.
/// The rest of ControlApp stays on the graphics driver.
/// </summary>
public bool MotionViewerSoftwareRendering { get; set; }
Expand Down
22 changes: 10 additions & 12 deletions ControlApp/Models/Motion/MotionViewerRendering.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
using System.Windows.Interop;
using HelixToolkit.SharpDX;

namespace Nefarius.DsHidMini.ControlApp.Models.Motion;

/// <summary>
/// Selects the rasterizer for the Motion viewer window only.
/// Software mode avoids the WPF Direct3D 9 device without changing the rest of ControlApp.
/// Creates the DirectX 11 device for the Motion viewer.
/// Software mode uses the WARP rasterizer for that viewport only.
/// </summary>
internal static class MotionViewerRendering
{
public static RenderMode Select(bool useSoftwareRendering)
public static EffectsManagerConfiguration CreateConfiguration(bool useSoftwareRendering)
{
return useSoftwareRendering ? RenderMode.SoftwareOnly : RenderMode.Default;
return new EffectsManagerConfiguration
{
EnableSoftwareRendering = useSoftwareRendering
};
}

public static void Apply(HwndSource? source, bool useSoftwareRendering)
public static DefaultEffectsManager CreateEffectsManager(bool useSoftwareRendering)
{
if (source?.CompositionTarget is null)
{
return;
}

source.CompositionTarget.RenderMode = Select(useSoftwareRendering);
return new DefaultEffectsManager(CreateConfiguration(useSoftwareRendering));
}
}
23 changes: 11 additions & 12 deletions ControlApp/Views/Windows/MotionViewerWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:h="http://helix-toolkit.org/wpf"
xmlns:hx="http://helix-toolkit.org/wpf/SharpDX"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
Title="{Binding Title}"
Expand Down Expand Up @@ -110,22 +110,21 @@
Margin="0,12,0,0"
Content="Software rendering"
IsChecked="{Binding UseSoftwareRendering, Mode=TwoWay}"
ToolTip="Draw this 3D view on the CPU if the pad or grid looks dotted, sliced, or incomplete. The rest of ControlApp stays on the graphics driver." />
ToolTip="Draw this 3D view with DirectX software rendering if the pad or grid looks dotted or incomplete. The readout stays on the graphics driver."
ToolTipService.InitialShowDelay="200" />
</StackPanel>
</DockPanel>
</ScrollViewer>
<h:HelixViewport3D
<hx:Viewport3DX
x:Name="Viewport"
Grid.Column="2"
ZoomExtentsWhenLoaded="True">
<h:DefaultLights />
<h:GridLinesVisual3D
Length="12"
MajorDistance="4"
MinorDistance="1"
Width="12" />
<ModelVisual3D x:Name="PadModel" />
</h:HelixViewport3D>
BackgroundColor="#FF111111"
EnableSwapChainRendering="True"
FXAALevel="None"
ShowCoordinateSystem="True">
<hx:AmbientLight3D Color="#FF606060" />
<hx:DirectionalLight3D Direction="-0.4,-0.2,-1" Color="White" />
</hx:Viewport3DX>
</Grid>
</DockPanel>
</ui:FluentWindow>
Loading
Loading