Refactor AppState and rendering pipeline components

Changed the `AppStateMachine` to implement `IDisposable` and `IAsyncDisposable` for better resource management.
Changed the `IAppState` interface to include asynchronous methods for state transitions.
Changed the `App` class to start the host asynchronously and added an `OnClosed` method for proper shutdown.
Changed the `EditorState` class to ensure the window closes correctly when exiting the state.
Changed the `LandingState` class to improve window activation and deactivation management.
Changed the `HostHelper` class to register `LandingWindow` and `EngineEditorWindow` as singletons for better performance.
Changed the `ScenePage` class to utilize a new interface for swap chain management.
Changed the `OpenProjectPage` and `CreateProjectPage` classes to enhance navigation handling.
Changed the `ConsoleViewModel` to improve log update handling with a new context structure.
Changed the `OpenProjectViewModel` to clear project lists when navigating away.
Changed the `EngineCore` class to start the graphics pipeline asynchronously.
Changed the `Logger` class to use a new context structure for log changes.
Added the `ICommandBuffer`, `IGraphicsDevice`, and `IRenderView` interfaces to enhance the rendering pipeline.
Changed the `DX12CommandBuffer`, `DX12GraphicsDevice`, and `DX12RenderView` classes for improved resource management and rendering efficiency.
Refactored the `Mesh` class to use a new `Vertex` structure for simplified vertex management.
Added the `TextureUtility` class for texture management utilities, including mip count calculation.
Changed the `launchSettings.json` to include a new profile for the graphics project with native debugging enabled.
Changed the `MeshBuilder` class to utilize the new `Vertex` structure for vertex creation.
This commit is contained in:
2025-06-29 11:38:29 +09:00
parent 4110c166cf
commit 8fd1222780
34 changed files with 1479 additions and 269 deletions

View File

@@ -2,8 +2,7 @@ using Ghost.Editor.Controls.Internal;
using Ghost.Graphics;
using Ghost.Graphics.Contracts;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
using SharpGen.Runtime;
using Vortice.WinUI;
using WinRT;
namespace Ghost.Editor.View.Pages.EngineEditor;
@@ -11,6 +10,7 @@ namespace Ghost.Editor.View.Pages.EngineEditor;
internal sealed partial class ScenePage : NavigationTabPage
{
private IRenderView? _renderer;
private ISwapChainPanelNative2? _swapChainPanelNative;
public ScenePage()
{
@@ -28,19 +28,19 @@ internal sealed partial class ScenePage : NavigationTabPage
private void SwapChainPanel_Loaded(object sender, RoutedEventArgs e)
{
var guid = typeof(Vortice.WinUI.ISwapChainPanelNative).GUID;
Result result = ((IWinRTObject)SwapChainPanel).NativeObject.TryAs(guid, out var swapChainPanelNativeHandle);
result.CheckError();
var guid = typeof(ISwapChainPanelNative2).GUID;
((IWinRTObject)SwapChainPanel).NativeObject.TryAs(guid, out var swapChainPanelNativeHandle);
var swapChainPanelNative = new Vortice.WinUI.ISwapChainPanelNative(swapChainPanelNativeHandle);
_renderer = GraphicsPipeline.GraphicsDevice.CreateRenderView(new(swapChainPanelNative, (uint)SwapChainPanel.ActualWidth, (uint)SwapChainPanel.ActualHeight));
_swapChainPanelNative = new ISwapChainPanelNative2(swapChainPanelNativeHandle);
_renderer = GraphicsPipeline.GraphicsDevice.CreateRenderView(new(_swapChainPanelNative, (uint)SwapChainPanel.ActualWidth, (uint)SwapChainPanel.ActualHeight));
CompositionTarget.Rendering += OnRendering;
//CompositionTarget.Rendering += OnRendering;
}
private void SwapChainPanel_Unloaded(object sender, RoutedEventArgs e)
{
CompositionTarget.Rendering -= OnRendering;
//CompositionTarget.Rendering -= OnRendering;
_swapChainPanelNative?.Dispose();
_renderer?.Dispose();
}
@@ -48,7 +48,7 @@ internal sealed partial class ScenePage : NavigationTabPage
{
if (e.NewSize.Width > 8.0 && e.NewSize.Height > 8.0)
{
_renderer?.Resize((uint)e.NewSize.Width, (uint)e.NewSize.Height);
_renderer?.RequestResize((uint)e.NewSize.Width, (uint)e.NewSize.Height);
}
}
}

View File

@@ -23,4 +23,10 @@ internal sealed partial class CreateProjectPage : Page
base.OnNavigatedTo(e);
ViewModel.OnNavigatedTo(e.Parameter);
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
ViewModel.OnNavigatedFrom();
}
}

View File

@@ -1,5 +1,5 @@
using Ghost.Editor.ViewModels.Pages.Landing;
using Ghost.Data.Models;
using Ghost.Data.Models;
using Ghost.Editor.ViewModels.Pages.Landing;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Navigation;
@@ -26,7 +26,7 @@ internal sealed partial class OpenProjectPage : Page
ViewModel.OnNavigatedTo(e.Parameter);
}
override protected void OnNavigatedFrom(NavigationEventArgs e)
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
ViewModel.OnNavigatedFrom();
@@ -65,7 +65,8 @@ internal sealed partial class OpenProjectPage : Page
{
if (e.ClickedItem is ProjectMetadataInfo project)
{
await ViewModel.LoadProject(project);
await Task.Yield();
await ViewModel.OpenProjectAsync(project);
}
}
}