port from perforce
This commit is contained in:
63
intromat/Intromat/Views/Previews/DxTexturePreview.xaml.cs
Normal file
63
intromat/Intromat/Views/Previews/DxTexturePreview.xaml.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Reactive.Disposables;
|
||||
using Intromat.Graphics;
|
||||
using Intromat.Pipelines;
|
||||
using Intromat.ViewModels;
|
||||
using Intromat.ViewModels.Previews;
|
||||
using ReactiveUI;
|
||||
using SharpDX.Direct3D11;
|
||||
using Splat;
|
||||
|
||||
namespace Intromat.Views.Previews
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for DxTexturePreview.xaml
|
||||
/// </summary>
|
||||
public partial class DxTexturePreview : IViewFor<DxTexturePreviewViewModel>
|
||||
{
|
||||
private DisplayTexturePipeline? _pipeline;
|
||||
|
||||
public DxTexturePreview()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
MouseDoubleClick += (_, _) =>
|
||||
{
|
||||
if (ViewModel == null)
|
||||
return;
|
||||
|
||||
var network = (CodeGenNetworkViewModel)ViewModel.Parent.Parent;
|
||||
var main = network.Document.MainViewModel;
|
||||
main.Preview2dContext = ViewModel;
|
||||
};
|
||||
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
_pipeline = Locator.Current.GetService<DisplayTexturePipeline>()!;
|
||||
this.WhenAnyObservable(v => v.ViewModel!.TextureValue).Subscribe(textureValue =>
|
||||
{
|
||||
var srv = textureValue?.ShaderResourceView;
|
||||
if (srv != null)
|
||||
{
|
||||
_pipeline.ShaderResourceView = srv;
|
||||
_dxView.Render();
|
||||
}
|
||||
}).DisposeWith(d);
|
||||
_dxView.SetUpdateHandler(UpdateFrameAction);
|
||||
});
|
||||
}
|
||||
|
||||
private void UpdateFrameAction(Device device, DeviceContext context)
|
||||
{
|
||||
_pipeline?.Apply();
|
||||
}
|
||||
|
||||
object? IViewFor.ViewModel
|
||||
{
|
||||
get => ViewModel;
|
||||
set => ViewModel = (DxTexturePreviewViewModel?)value;
|
||||
}
|
||||
|
||||
public DxTexturePreviewViewModel? ViewModel { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user