using System; #if WINDOWS_UWP using Windows.UI.Xaml; namespace ComputeSharp.Uwp; #else using Microsoft.UI.Xaml; namespace ComputeSharp.WinUI; #endif /// public sealed unsafe partial class ComputeShaderPanel { /// /// Gets or sets the instance to use to render content. /// public IShaderRunner? ShaderRunner { get => (IShaderRunner?)GetValue(ShaderFactoryProperty); set => SetValue(ShaderFactoryProperty, value); } /// /// The backing . /// public static readonly DependencyProperty ShaderFactoryProperty = DependencyProperty.Register( nameof(ShaderRunner), typeof(IShaderRunner), typeof(ComputeShaderPanel), new PropertyMetadata(null, static (d, e) => ((ComputeShaderPanel)d).shaderRunner = (IShaderRunner?)e.NewValue)); /// /// Gets or sets the resolution scale to be used to render frames. /// This can help achieve higher framerates with more complex shaders. /// /// The accepted range is [0.1 and 1] (default is 1, exceeding values will be clamped). public double ResolutionScale { get => (double)GetValue(ResolutionScaleProperty); set => SetValue(ResolutionScaleProperty, Math.Clamp(value, 0.1, 1.0)); } /// /// The backing . /// public static readonly DependencyProperty ResolutionScaleProperty = DependencyProperty.Register( nameof(ResolutionScale), typeof(double), typeof(ComputeShaderPanel), new PropertyMetadata(1.0, OnResolutionScalePropertyChanged)); /// private static void OnResolutionScalePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var @this = (ComputeShaderPanel)d; var resolutionScale = (double)e.NewValue; @this.targetResolutionScale = (float)resolutionScale; if (!@this.isDynamicResolutionEnabled) { @this.OnResize(); } } /// /// Gets or sets whether dynamic resolution is enabled. If it is, the internal render /// resolution of the shader being run will be automatically adjusted to reach 60fps. /// The default value for this property is . /// public bool IsDynamicResolutionEnabled { get => (bool)GetValue(IsDynamicResolutionEnabledProperty); set => SetValue(IsDynamicResolutionEnabledProperty, value); } /// /// The backing . /// public static readonly DependencyProperty IsDynamicResolutionEnabledProperty = DependencyProperty.Register( nameof(IsDynamicResolutionEnabled), typeof(bool), typeof(ComputeShaderPanel), new PropertyMetadata(true, OnIsDynamicResolutionEnabledPropertyChanged)); /// private static void OnIsDynamicResolutionEnabledPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var @this = (ComputeShaderPanel)d; var isDynamicResolutionEnabled = (bool)e.NewValue; @this.isDynamicResolutionEnabled = isDynamicResolutionEnabled; } /// /// Gets or sets whether or not the rendering is paused. /// public bool IsPaused { get => (bool)GetValue(IsPausedProperty); set => SetValue(IsPausedProperty, value); } /// /// The backing . /// public static readonly DependencyProperty IsPausedProperty = DependencyProperty.Register( nameof(IsPaused), typeof(bool), typeof(ComputeShaderPanel), new PropertyMetadata(false, OnIsPausedPropertyChanged)); /// private static void OnIsPausedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var @this = (ComputeShaderPanel)d; var isPaused = (bool)e.NewValue; if (isPaused) { @this.OnStopRenderLoop(); } else { @this.OnStartRenderLoop(); } } }