Example #1
0
        private static D3D11MetaResource CreateCore(Adapter adapter, DriverType type,
                                                    DeviceCreationFlags creationFlags,
                                                    SwapChainDescription1?description, FeatureLevel[] levels, bool allowWarpFallbackDriver,
                                                    SwapChainTarget target)
        {
            SwapChainDescription1 desc;

            if (description.HasValue)
            {
                desc = description.Value;
            }
            else
            {
                GetDefaultSwapChainDescription(out desc, target);
            }

#if DEBUG
            // Note: These have no impact on solution outside
            // of this project. This is only for internal testing
            // purposes
            creationFlags |= DeviceCreationFlags.Debug;
#endif

            return(new D3D11MetaResource(new D3D11MetaResourceOptions
            {
                Adapter = adapter,
                SwapChainDescription = desc,
                Target = target,
                Type = type,
                WarpFallbackEnabled = allowWarpFallbackDriver,
                CreationFlags = creationFlags,
                Levels = levels
            }));
        }
Example #2
0
        /// <summary>
        /// Creates the device manager and image source when the viewport is loaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param>
        private void Viewport3DXLoaded(object sender, RoutedEventArgs e)
        {
            var logicalDpi  = DisplayInformation.GetForCurrentView().LogicalDpi;
            int pixelWidth  = (int)(this.ActualWidth * logicalDpi / 96.0);
            int pixelHeight = (int)(this.ActualHeight * logicalDpi / 96.0);

            // Safely dispose any previous instance
            // Creates a new DeviceManager (Direct3D, Direct2D, DirectWrite, WIC)
            this.deviceManager = new DeviceManager();

            // Use CoreWindowTarget as the rendering target (Initialize SwapChain, RenderTargetView, DepthStencilView, BitmapTarget)
            this.d3dTarget = new SwapChainTarget((SwapChainPanel)this.ItemsPanelRoot, pixelWidth, pixelHeight);

            this.deviceManager.OnInitialize += this.d3dTarget.Initialize;
            this.deviceManager.OnInitialize += this.Initialize;

            this.d3dTarget.OnRender += this.Render;

            // Initialize the device manager and all registered deviceManager.OnInitialize
            this.deviceManager.Initialize(DisplayInformation.GetForCurrentView().LogicalDpi);

            // Setup rendering callback
            CompositionTarget.Rendering += this.CompositionTargetRendering;

            // Callback on DpiChanged
            DisplayProperties.LogicalDpiChanged += this.DisplayPropertiesLogicalDpiChanged;
        }
Example #3
0
 public static void GetDefaultSwapChainDescription(out SwapChainDescription1 swapChainDescription,
                                                   SwapChainTarget target)
 {
     swapChainDescription = new SwapChainDescription1
     {
         SampleDescription = new SampleDescription(1, 0),
         Usage             = Usage.RenderTargetOutput,
         BufferCount       = 2,
         // OutputHandle is also set by the resource manager
         SwapEffect = GetBestSwapEffectForPlatform(),
         Scaling    = Scaling.Stretch,
         Format     = Format.B8G8R8A8_UNorm,
         AlphaMode  = target == SwapChainTarget.Window ? AlphaMode.Ignore : AlphaMode.Premultiplied,
         Width      = 0,
         Height     = 0
     };
 }