Exemple #1
0
        /// <summary>
        /// Creates device resources.
        /// </summary>
        /// <remarks>
        /// This method is called at the initialization of this instance.
        /// </remarks>
        protected virtual void CreateDeviceResources()
        {
            // Dispose previous references and set to null
            SafeDispose(ref d3dDevice);
            SafeDispose(ref d3dContext);
            SafeDispose(ref d2dDevice);
            SafeDispose(ref d2dContext);

            // Allocate new references
            // Enable compatibility with Direct2D
            // Retrieve the Direct3D 11.1 device amd device context
            var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.VideoSupport | SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport;

#if DEBUG
            creationFlags |= SharpDX.Direct3D11.DeviceCreationFlags.Debug;
#endif
            using (var defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, creationFlags))
                d3dDevice = defaultDevice.QueryInterface <SharpDX.Direct3D11.Device1>();
            featureLevel = d3dDevice.FeatureLevel;

            // Get Direct3D 11.1 context
            d3dContext = ToDispose(d3dDevice.ImmediateContext.QueryInterface <SharpDX.Direct3D11.DeviceContext1>());

            // Create Direct2D device
            using (var dxgiDevice = d3dDevice.QueryInterface <SharpDX.DXGI.Device>())
                d2dDevice = ToDispose(new SharpDX.Direct2D1.Device(d2dFactory, dxgiDevice));

            // Create Direct2D context
            d2dContext = ToDispose(new SharpDX.Direct2D1.DeviceContext(d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None));
        }
Exemple #2
0
        internal CommandList(GraphicsDevice device) : base(device)
        {
            nativeDeviceContext  = device.NativeDeviceContext;
            nativeDeviceContext1 = new SharpDX.Direct3D11.DeviceContext1(nativeDeviceContext.NativePointer);
            nativeDeviceProfiler = device.IsDebugMode ? SharpDX.ComObject.QueryInterfaceOrNull <SharpDX.Direct3D11.UserDefinedAnnotation>(nativeDeviceContext.NativePointer) : null;
            InitializeStages();

            ClearState();
        }
        internal CommandList(GraphicsDevice device) : base(device)
        {
            nativeDeviceContext = device.NativeDeviceContext;
            nativeDeviceContext1 = new SharpDX.Direct3D11.DeviceContext1(nativeDeviceContext.NativePointer);
            nativeDeviceProfiler = device.IsDebugMode ? SharpDX.ComObject.QueryInterfaceOrNull<SharpDX.Direct3D11.UserDefinedAnnotation>(nativeDeviceContext.NativePointer) : null;
            InitializeStages();

            ClearState();
        }
Exemple #4
0
            public void Run()
            {
                Debug.WriteLine("Run");

                // First, create the Direct3D device.

                // This flag is required in order to enable compatibility with Direct2D.
                var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport;

#if DEBUG
                // If the project is in a debug build, enable debugging via SDK Layers with this flag.
                creationFlags |= SharpDX.Direct3D11.DeviceCreationFlags.Debug;
#endif

                // This array defines the ordering of feature levels that D3D should attempt to create.
                var featureLevels = new SharpDX.Direct3D.FeatureLevel[]
                {
                    SharpDX.Direct3D.FeatureLevel.Level_11_1,
                    SharpDX.Direct3D.FeatureLevel.Level_11_0,
                };

                using (var d3dDevice = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware
                                                                     , creationFlags, featureLevels))
                {
                    m_d3dDevice = d3dDevice.QueryInterface <SharpDX.Direct3D11.Device1>();
                }
                m_d3dDeviceContext = m_d3dDevice.ImmediateContext1;

                // After the D3D device is created, create additional application resources.
                CreateWindowSizeDependentResources();

                // Enter the render loop.  Note that Windows Store apps should never exit.
                while (true)
                {
                    // Process events incoming to the window.
                    m_window.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent);

                    // Specify the render target we created as the output target.
                    m_d3dDeviceContext.OutputMerger.SetRenderTargets(null,
                                                                     m_renderTargetView
                                                                     );

                    // Clear the render target to a solid color.
                    m_d3dDeviceContext.ClearRenderTargetView(
                        m_renderTargetView,
                        new SharpDX.Color4(0.071f, 0.04f, 0.561f, 1.0f)
                        );

                    // Present the rendered image to the window.  Because the maximum frame latency is set to 1,
                    // the render loop will generally be throttled to the screen refresh rate, typically around
                    // 60Hz, by sleeping the application on Present until the screen is refreshed.
                    m_swapChain.Present(1, 0);
                }
            }
Exemple #5
0
        /// <summary>
        /// Creates device resources.
        /// </summary>
        /// <remarks>
        /// This method is called at the initialization of this instance.
        /// </remarks>
        protected virtual void CreateDeviceResources()
        {
            // Dispose previous references and set to null
            if (d3dDevice != null)
            {
                RemoveAndDispose(ref d3dDevice);
            }

            if (d3dContext != null)
            {
                RemoveAndDispose(ref d3dContext);
            }

            if (d2dDevice != null)
            {
                RemoveAndDispose(ref d2dDevice);
            }

            if (d2dContext != null)
            {
                RemoveAndDispose(ref d2dContext);
            }

            // Allocate new references
            // Enable compatibility with Direct2D
            // Retrieve the Direct3D 11.1 device amd device context
            var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.VideoSupport | SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport;

            // Decomment this line to have Debug. Unfortunately, debug is sometimes crashing applications, so it is disable by default
            try
            {
                // Try to create it with Video Support
                // If it is not working, we just use BGRA
                // Force to FeatureLevel.Level_9_1
                using (var defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, creationFlags))
                    d3dDevice = defaultDevice.QueryInterface <SharpDX.Direct3D11.Device1>();
            } catch (Exception)
            {
                creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport;
                using (var defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, creationFlags))
                    d3dDevice = defaultDevice.QueryInterface <SharpDX.Direct3D11.Device1>();
            }
            featureLevel = d3dDevice.FeatureLevel;

            // Get Direct3D 11.1 context
            d3dContext = Collect(d3dDevice.ImmediateContext.QueryInterface <SharpDX.Direct3D11.DeviceContext1>());

            // Create Direct2D device
            using (var dxgiDevice = d3dDevice.QueryInterface <SharpDX.DXGI.Device>())
                d2dDevice = Collect(new SharpDX.Direct2D1.Device(d2dFactory, dxgiDevice));

            // Create Direct2D context
            d2dContext = Collect(new SharpDX.Direct2D1.DeviceContext(d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None));
        }
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateY | ManipulationModes.TranslateInertia | ManipulationModes.Scale;

            tileBackground.ImageSource = "Assets/bgline.JPG";

            onePointWait.Visibility = Visibility.Collapsed;
            twoPointWait.Visibility = Visibility.Collapsed;

            double val = -Math.PI / 2;

            foreach (UIElement child in colorSelect.Children)
            {
                child.SetValue(Canvas.LeftProperty, Math.Cos(val) * 70);
                child.SetValue(Canvas.TopProperty, Math.Sin(val) * 70);
                val += Math.PI / 5;
            }

            var debugLevel = SharpDX.Direct2D1.DebugLevel.None;

            d2dFactory = new SharpDX.Direct2D1.Factory1(SharpDX.Direct2D1.FactoryType.SingleThreaded, debugLevel);

            var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport;

            using (var defaultDevice = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, creationFlags))
                d3dDevice = defaultDevice.QueryInterface <SharpDX.Direct3D11.Device1>();

            d3dContext = d3dDevice.ImmediateContext.QueryInterface <SharpDX.Direct3D11.DeviceContext1>();

            using (dxgiDevice = d3dDevice.QueryInterface <SharpDX.DXGI.Device2>())
                d2dDevice = new SharpDX.Direct2D1.Device(d2dFactory, dxgiDevice);

            d2dContext = new SharpDX.Direct2D1.DeviceContext(d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None);

            DisplayProperties.LogicalDpiChanged += LogicalDpiChanged;
        }
        /// <summary>
        /// Creates device resources. 
        /// </summary>
        /// <remarks>
        /// This method is called at the initialization of this instance.
        /// </remarks>
        protected virtual void CreateDeviceResources()
        {
            // Dispose previous references and set to null
            RemoveAndDispose(ref d3dDevice);
            RemoveAndDispose(ref d3dContext);
            RemoveAndDispose(ref d2dDevice);
            RemoveAndDispose(ref d2dContext);

            // Allocate new references
            // Enable compatibility with Direct2D
            // Retrieve the Direct3D 11.1 device amd device context
            var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.VideoSupport | SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport;

            // Decomment this line to have Debug. Unfortunately, debug is sometimes crashing applications, so it is disable by default
            try
            {
                // Try to create it with Video Support
                // If it is not working, we just use BGRA
                // Force to FeatureLevel.Level_9_1
                using (var defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, creationFlags))
                    d3dDevice = defaultDevice.QueryInterface<SharpDX.Direct3D11.Device1>();
            } catch (Exception)
            {
                creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport;
                using (var defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, creationFlags))
                    d3dDevice = defaultDevice.QueryInterface<SharpDX.Direct3D11.Device1>();
            }
            featureLevel = d3dDevice.FeatureLevel;

            // Get Direct3D 11.1 context
            d3dContext = ToDispose(d3dDevice.ImmediateContext.QueryInterface<SharpDX.Direct3D11.DeviceContext1>());

            // Create Direct2D device
            using (var dxgiDevice = d3dDevice.QueryInterface<SharpDX.DXGI.Device>())
                d2dDevice = ToDispose(new SharpDX.Direct2D1.Device(d2dFactory, dxgiDevice));

            // Create Direct2D context
            d2dContext = ToDispose(new SharpDX.Direct2D1.DeviceContext(d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None));
        }
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateY | ManipulationModes.TranslateInertia | ManipulationModes.Scale;

            tileBackground.ImageSource = "Assets/bgline.JPG";

            onePointWait.Visibility = Visibility.Collapsed;
            twoPointWait.Visibility = Visibility.Collapsed;

            double val = -Math.PI / 2;
            foreach (UIElement child in colorSelect.Children)
            {
                child.SetValue(Canvas.LeftProperty, Math.Cos(val) * 70);
                child.SetValue(Canvas.TopProperty, Math.Sin(val) * 70);
                val += Math.PI / 5;
            }

            var debugLevel = SharpDX.Direct2D1.DebugLevel.None;
            d2dFactory = new SharpDX.Direct2D1.Factory1(SharpDX.Direct2D1.FactoryType.SingleThreaded, debugLevel);

            var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport;

            using (var defaultDevice = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, creationFlags))
                d3dDevice = defaultDevice.QueryInterface<SharpDX.Direct3D11.Device1>();

            d3dContext = d3dDevice.ImmediateContext.QueryInterface<SharpDX.Direct3D11.DeviceContext1>();

            using (dxgiDevice = d3dDevice.QueryInterface<SharpDX.DXGI.Device2>())
                d2dDevice = new SharpDX.Direct2D1.Device(d2dFactory, dxgiDevice);

            d2dContext = new SharpDX.Direct2D1.DeviceContext(d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None);

            DisplayProperties.LogicalDpiChanged += LogicalDpiChanged;
        }
        public override void Initialize(DeviceManager deviceManager)
        {
            base.Initialize(deviceManager);

            // Save the context instance
            this.deviceContext = deviceManager.DeviceDirect3D.ImmediateContext1;

            // We have to take into account pixel scaling; Windows Phone 8.1 uses virtual resolutions smaller than the physical screen size.
            float pixelScale = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().LogicalDpi / 96.0f;

            // Properties of the swap chain
            SharpDX.DXGI.SwapChainDescription1 swapChainDescription = new SharpDX.DXGI.SwapChainDescription1()
            {
                // No transparency.
                AlphaMode = SharpDX.DXGI.AlphaMode.Ignore,
                // Double buffer.
                BufferCount = 2,
                // BGRA 32bit pixel format.
                Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                // Unlike in CoreWindow swap chains, the dimensions must be set.
                Height = (int)(this.swapChainPanel.RenderSize.Height * pixelScale),
                Width  = (int)(this.swapChainPanel.RenderSize.Width * pixelScale),
                // Default multisampling.
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                // In case the control is resized, stretch the swap chain accordingly.
                Scaling = SharpDX.DXGI.Scaling.Stretch,
                // No support for stereo display.
                Stereo = false,
                // Sequential displaying for double buffering.
                SwapEffect = SharpDX.DXGI.SwapEffect.FlipSequential,
                // This swapchain is going to be used as the back buffer.
                Usage = SharpDX.DXGI.Usage.BackBuffer | SharpDX.DXGI.Usage.RenderTargetOutput,
            };

            // Retrive the DXGI device associated to the Direct3D device.
            using (SharpDX.DXGI.Device3 dxgiDevice3 = deviceManager.DeviceDirect3D.QueryInterface <SharpDX.DXGI.Device3>())
            {
                // Get the DXGI factory automatically created when initializing the Direct3D device.
                using (SharpDX.DXGI.Factory3 dxgiFactory3 = dxgiDevice3.Adapter.GetParent <SharpDX.DXGI.Factory3>())
                {
                    // Create the swap chain and get the highest version available.
                    using (SharpDX.DXGI.SwapChain1 swapChain1 = new SharpDX.DXGI.SwapChain1(dxgiFactory3, deviceManager.DeviceDirect3D, ref swapChainDescription))
                    {
                        this.swapChain = swapChain1.QueryInterface <SharpDX.DXGI.SwapChain2>();
                    }
                }
            }

            // Obtain a reference to the native COM object of the SwapChainPanel.
            using (SharpDX.DXGI.ISwapChainPanelNative nativeObject = SharpDX.ComObject.As <SharpDX.DXGI.ISwapChainPanelNative>(this.swapChainPanel))
            {
                // Set its swap chain.
                nativeObject.SwapChain = this.swapChain;
            }

            // Create a descriptor for the depth/stencil buffer.
            // Allocate a 2-D surface as the depth/stencil buffer.
            // Create a DepthStencil view on this surface to use on bind.
            // TODO: Recreate a DepthStencilBuffer is inefficient. We should only have one depth buffer. Shared depth buffer?
            using (var depthBuffer = new SharpDX.Direct3D11.Texture2D(DeviceManager.DeviceDirect3D, new SharpDX.Direct3D11.Texture2DDescription()
            {
                Format = SharpDX.DXGI.Format.D24_UNorm_S8_UInt,
                ArraySize = 1,
                MipLevels = 1,
                Width = (int)swapChainDescription.Width,
                Height = (int)swapChainDescription.Height,
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                BindFlags = SharpDX.Direct3D11.BindFlags.DepthStencil,
            }))

                this.depthStencilView = Collect(new SharpDX.Direct3D11.DepthStencilView(DeviceManager.DeviceDirect3D, depthBuffer, new SharpDX.Direct3D11.DepthStencilViewDescription()
                {
                    Dimension = SharpDX.Direct3D11.DepthStencilViewDimension.Texture2D
                }));

            // Create a Texture2D from the existing swap chain to use as
            this.backBuffer       = SharpDX.Direct3D11.Texture2D.FromSwapChain <SharpDX.Direct3D11.Texture2D>(this.swapChain, 0);
            this.renderTargetView = new SharpDX.Direct3D11.RenderTargetView(deviceManager.DeviceDirect3D, this.backBuffer);

            var viewport = new SharpDX.ViewportF(0, 0, (float)swapChainDescription.Width, (float)swapChainDescription.Height, 0.0f, 1.0f);

            RenderTargetBounds = new Rect(viewport.X, viewport.Y, viewport.Width, viewport.Height);

            //DeviceManager.ContextDirect2D.Target = this.backBuffer.as;

            DeviceManager.ContextDirect3D.Rasterizer.SetViewport(viewport);
        }
Exemple #10
0
        /// <summary>
        /// Creates device resources. 
        /// </summary>
        /// <remarks>
        /// This method is called at the initialization of this instance.
        /// </remarks>
        protected virtual void CreateDeviceResources()
        {
            // Dispose previous references and set to null
            SafeDispose(ref d3dDevice);
            SafeDispose(ref d3dContext);
            SafeDispose(ref d2dDevice);
            SafeDispose(ref d2dContext);

            // Allocate new references
            // Enable compatibility with Direct2D
            // Retrieve the Direct3D 11.1 device amd device context
            var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.VideoSupport | SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport;
            #if DEBUG
            creationFlags |= SharpDX.Direct3D11.DeviceCreationFlags.Debug;
            #endif
            using (var defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, creationFlags))
                d3dDevice = defaultDevice.QueryInterface<SharpDX.Direct3D11.Device1>();
            featureLevel = d3dDevice.FeatureLevel;

            // Get Direct3D 11.1 context
            d3dContext = ToDispose(d3dDevice.ImmediateContext.QueryInterface<SharpDX.Direct3D11.DeviceContext1>());

            // Create Direct2D device
            using (var dxgiDevice = d3dDevice.QueryInterface<SharpDX.DXGI.Device>())
                d2dDevice = ToDispose(new SharpDX.Direct2D1.Device(d2dFactory, dxgiDevice));

            // Create Direct2D context
            d2dContext = ToDispose(new SharpDX.Direct2D1.DeviceContext(d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None));
        }
        public override void Initialize(DeviceManager deviceManager)
        {
            base.Initialize(deviceManager);

            // Save the context instance
            this.deviceContext = deviceManager.DeviceDirect3D.ImmediateContext1;

            // We have to take into account pixel scaling; Windows Phone 8.1 uses virtual resolutions smaller than the physical screen size.
            float pixelScale = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().LogicalDpi / 96.0f;

            // Properties of the swap chain
            SharpDX.DXGI.SwapChainDescription1 swapChainDescription = new SharpDX.DXGI.SwapChainDescription1()
            {
                // No transparency.
                AlphaMode = SharpDX.DXGI.AlphaMode.Ignore,
                // Double buffer.
                BufferCount = 2,
                // BGRA 32bit pixel format.
                Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                // Unlike in CoreWindow swap chains, the dimensions must be set.
                Height = (int)(this.swapChainPanel.RenderSize.Height * pixelScale),
                Width = (int)(this.swapChainPanel.RenderSize.Width * pixelScale),
                // Default multisampling.
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                // In case the control is resized, stretch the swap chain accordingly.
                Scaling = SharpDX.DXGI.Scaling.Stretch,
                // No support for stereo display.
                Stereo = false,
                // Sequential displaying for double buffering.
                SwapEffect = SharpDX.DXGI.SwapEffect.FlipSequential,
                // This swapchain is going to be used as the back buffer.
                Usage = SharpDX.DXGI.Usage.BackBuffer | SharpDX.DXGI.Usage.RenderTargetOutput,
            };

            // Retrive the DXGI device associated to the Direct3D device.
            using (SharpDX.DXGI.Device3 dxgiDevice3 = deviceManager.DeviceDirect3D.QueryInterface<SharpDX.DXGI.Device3>())
            {
                // Get the DXGI factory automatically created when initializing the Direct3D device.
                using (SharpDX.DXGI.Factory3 dxgiFactory3 = dxgiDevice3.Adapter.GetParent<SharpDX.DXGI.Factory3>())
                {
                    // Create the swap chain and get the highest version available.
                    using (SharpDX.DXGI.SwapChain1 swapChain1 = new SharpDX.DXGI.SwapChain1(dxgiFactory3, deviceManager.DeviceDirect3D, ref swapChainDescription))
                    {
                        this.swapChain = swapChain1.QueryInterface<SharpDX.DXGI.SwapChain2>();
                    }
                }
            }

            // Obtain a reference to the native COM object of the SwapChainPanel.
            using (SharpDX.DXGI.ISwapChainPanelNative nativeObject = SharpDX.ComObject.As<SharpDX.DXGI.ISwapChainPanelNative>(this.swapChainPanel))
            {
                // Set its swap chain.
                nativeObject.SwapChain = this.swapChain;
            }

            // Create a descriptor for the depth/stencil buffer.
            // Allocate a 2-D surface as the depth/stencil buffer.
            // Create a DepthStencil view on this surface to use on bind.
            // TODO: Recreate a DepthStencilBuffer is inefficient. We should only have one depth buffer. Shared depth buffer?
            using (var depthBuffer = new SharpDX.Direct3D11.Texture2D(DeviceManager.DeviceDirect3D, new SharpDX.Direct3D11.Texture2DDescription()
            {
                Format = SharpDX.DXGI.Format.D24_UNorm_S8_UInt,
                ArraySize = 1,
                MipLevels = 1,
                Width = (int)swapChainDescription.Width,
                Height = (int)swapChainDescription.Height,
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                BindFlags = SharpDX.Direct3D11.BindFlags.DepthStencil,
            }))

            this.depthStencilView = Collect(new SharpDX.Direct3D11.DepthStencilView(DeviceManager.DeviceDirect3D, depthBuffer, new SharpDX.Direct3D11.DepthStencilViewDescription() { Dimension = SharpDX.Direct3D11.DepthStencilViewDimension.Texture2D }));

            // Create a Texture2D from the existing swap chain to use as 
            this.backBuffer = SharpDX.Direct3D11.Texture2D.FromSwapChain<SharpDX.Direct3D11.Texture2D>(this.swapChain, 0);
            this.renderTargetView = new SharpDX.Direct3D11.RenderTargetView(deviceManager.DeviceDirect3D, this.backBuffer);

            var viewport = new SharpDX.ViewportF(0, 0, (float)swapChainDescription.Width, (float)swapChainDescription.Height, 0.0f, 1.0f);

            RenderTargetBounds = new Rect(viewport.X, viewport.Y, viewport.Width, viewport.Height);

            //DeviceManager.ContextDirect2D.Target = this.backBuffer.as;

            DeviceManager.ContextDirect3D.Rasterizer.SetViewport(viewport);
        }