/// <summary>
        /// Create Direct3D device and swap chain
        /// </summary>
        public void InitDevice()
        {
            device = D3DDevice.CreateDeviceAndSwapChain(host.Handle, out swapChain);

            // Create a render target view
            using (Texture2D pBuffer = swapChain.GetBuffer<Texture2D>(0))
            {
                renderTargetView = device.CreateRenderTargetView(pBuffer);
            }

            device.OM.SetRenderTargets(new RenderTargetView[] { renderTargetView }, null);

            // Setup the viewport
            Viewport vp = new Viewport()
            {
                Width = (uint)host.ActualWidth,
                Height = (uint)host.ActualHeight,
                MinDepth = 0.0f,
                MaxDepth = 1.0f,
                TopLeftX = 0,
                TopLeftY = 0
            };

            device.RS.SetViewports(new Viewport[] { vp });
        } 
        /// <summary>
        /// Create Direct3D device and swap chain
        /// </summary>
        public void InitDevice()
        {
            device    = D3DDevice.CreateDeviceAndSwapChain(host.Handle);
            swapChain = device.SwapChain;

            // Create a render target view
            using (Texture2D pBuffer = swapChain.GetBuffer <Texture2D>(0))
            {
                renderTargetView = device.CreateRenderTargetView(pBuffer);
            }

            device.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView }, null);

            // Setup the viewport
            Viewport vp = new Viewport()
            {
                Width    = (uint)host.ActualWidth,
                Height   = (uint)host.ActualHeight,
                MinDepth = 0.0f,
                MaxDepth = 1.0f,
                TopLeftX = 0,
                TopLeftY = 0
            };

            device.RS.Viewports = new Viewport[] { vp };
        }
        /// <summary>
        /// Create Direct3D device and swap chain
        /// </summary>
        protected void InitDevice()
        {
            device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle, out swapChain);

            // Create a render target view
            using (Texture2D pBuffer = swapChain.GetBuffer<Texture2D>(0))
            {
                renderTargetView = device.CreateRenderTargetView(pBuffer);
            }

            device.OM.SetRenderTargets(new RenderTargetView[] { renderTargetView });

            // Setup the viewport
            Viewport vp = new Viewport()
            {
                Width = (uint)directControl.ClientSize.Width,
                Height = (uint)directControl.ClientSize.Height,
                MinDepth = 0.0f,
                MaxDepth = 1.0f,
                TopLeftX = 0,
                TopLeftY = 0
            };

            device.RS.SetViewports(new Viewport[] { vp });
        } 
Beispiel #4
0
        /// <summary>
        /// Create Direct3D device and swap chain
        /// </summary>
        protected void InitDevice()
        {
            device    = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle);
            swapChain = device.SwapChain;

            // Create a render target view
            using (Texture2D pBuffer = swapChain.GetBuffer <Texture2D>(0))
            {
                renderTargetView = device.CreateRenderTargetView(pBuffer);
            }

            device.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView });

            // Setup the viewport
            Viewport vp = new Viewport()
            {
                Width    = (uint)directControl.ClientSize.Width,
                Height   = (uint)directControl.ClientSize.Height,
                MinDepth = 0.0f,
                MaxDepth = 1.0f,
                TopLeftX = 0,
                TopLeftY = 0
            };

            device.RS.Viewports = new Viewport[] { vp };
        }
        void InitDevice()
        {
            // create Direct 3D device
            device    = D3DDevice.CreateDeviceAndSwapChain(renderHost.Handle);
            swapChain = device.SwapChain;

            // Create a render target view
            using (Texture2D pBuffer = swapChain.GetBuffer <Texture2D>(0))
            {
                renderTargetView = device.CreateRenderTargetView(pBuffer);
            }

            // Create depth stencil texture
            Texture2DDescription descDepth = new Texture2DDescription()
            {
                Width             = (uint)renderHost.ActualWidth,
                Height            = (uint)renderHost.ActualHeight,
                MipLevels         = 1,
                ArraySize         = 1,
                Format            = Format.D32Float,
                SampleDescription = new SampleDescription()
                {
                    Count   = 1,
                    Quality = 0
                },
                BindingOptions = BindingOptions.DepthStencil,
            };

            depthStencil = device.CreateTexture2D(descDepth);

            // Create the depth stencil view
            DepthStencilViewDescription depthStencilViewDesc = new DepthStencilViewDescription()
            {
                Format        = descDepth.Format,
                ViewDimension = DepthStencilViewDimension.Texture2D
            };

            depthStencilView = device.CreateDepthStencilView(depthStencil, depthStencilViewDesc);

            // bind the views to the device
            device.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView }, depthStencilView);

            // Setup the viewport
            Viewport vp = new Viewport()
            {
                Width    = (uint)renderHost.ActualWidth,
                Height   = (uint)renderHost.ActualHeight,
                MinDepth = 0.0f,
                MaxDepth = 1.0f,
                TopLeftX = 0,
                TopLeftY = 0
            };

            device.RS.Viewports = new Viewport[] { vp };
        }
        void InitDevice()
        {
            // create Direct 3D device
            device = D3DDevice.CreateDeviceAndSwapChain(renderHost.Handle);
            swapChain = device.SwapChain;

            // Create a render target view
            using (Texture2D pBuffer = swapChain.GetBuffer<Texture2D>(0))
            {
                renderTargetView = device.CreateRenderTargetView(pBuffer);
            }

            // Create depth stencil texture
            Texture2DDescription descDepth = new Texture2DDescription()
            {
                Width = (uint)renderHost.ActualWidth,
                Height = (uint)renderHost.ActualHeight,
                MipLevels = 1,
                ArraySize = 1,
                Format = Format.D32Float,
                SampleDescription = new SampleDescription()
                {
                    Count = 1,
                    Quality = 0
                },
                BindingOptions = BindingOptions.DepthStencil,
            };

            depthStencil = device.CreateTexture2D(descDepth);

            // Create the depth stencil view
            DepthStencilViewDescription depthStencilViewDesc = new DepthStencilViewDescription()
            {
                Format = descDepth.Format,
                ViewDimension = DepthStencilViewDimension.Texture2D
            };
            depthStencilView = device.CreateDepthStencilView(depthStencil, depthStencilViewDesc);

            // bind the views to the device
            device.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView }, depthStencilView);

            // Setup the viewport
            Viewport vp = new Viewport()
            {
                Width = (uint)renderHost.ActualWidth,
                Height = (uint)renderHost.ActualHeight,
                MinDepth = 0.0f,
                MaxDepth = 1.0f,
                TopLeftX = 0,
                TopLeftY = 0
            };
            
            device.RS.Viewports = new Viewport[] { vp };
        }
        protected virtual void BufferSizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (dxInitialized)
            {
                Texture2DDescription tdesc = new Texture2DDescription
                {
                    ArraySize         = 1,
                    Width             = (uint)e.NewSize.Width,
                    Height            = (uint)e.NewSize.Height,
                    Format            = WindowsAPICodePack.DirectX.Graphics.Format.B8G8R8A8UNorm,
                    MipLevels         = 1,
                    SampleDescription = new WindowsAPICodePack.DirectX.Graphics.SampleDescription()
                    {
                        Count = 1, Quality = 0
                    },
                    Usage          = Usage.Default,
                    BindingOptions = BindingOptions.RenderTarget | BindingOptions.ShaderResource,
                    MiscellaneousResourceOptions = MiscellaneousResourceOptions.Shared,
                    CpuAccessOptions             = CpuAccessOptions.None
                };

                using (Texture2D texture2D = device.CreateTexture2D(tdesc))
                {
                    renderTargetView = device.CreateRenderTargetView(texture2D);
                    deviceContext.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView });

                    /* Set the backbuffer, which is a ID3D11Texture2D pointer */
                    d3dImage.SetBackBufferEx(D3DResourceTypeEx.ID3D11Texture2D, texture2D.NativeInterface);
                }

                // viewport
                SwapChainDescription desc     = swapChain.Description;
                Viewport             viewport = new Viewport();
                viewport.Width    = (float)e.NewSize.Width;
                viewport.Height   = (float)e.NewSize.Height;
                viewport.MinDepth = 0.0f;
                viewport.MaxDepth = 1.0f;
                viewport.TopLeftX = 0;
                viewport.TopLeftY = 0;

                deviceContext.RS.Viewports = new Viewport[] { viewport };

                aspectRatio = e.NewSize.Width / e.NewSize.Height;

                Update();
            }
        }
        protected virtual void BufferSizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (dxInitialized)
            {
                Texture2DDescription tdesc = new Texture2DDescription
                {
                    ArraySize         = 1,
                    Width             = (uint)e.NewSize.Width,
                    Height            = (uint)e.NewSize.Height,
                    Format            = Format.B8G8R8A8_UNORM,
                    MipLevels         = 1,
                    SampleDescription = new SampleDescription {
                        Count = 1, Quality = 0
                    },
                    Usage          = Usage.Default,
                    BindFlags      = BindFlag.RenderTarget | BindFlag.ShaderResource,
                    MiscFlags      = ResourceMiscFlag.Shared,
                    CpuAccessFlags = 0
                };

                using (Texture2D texture2D = device.CreateTexture2D(tdesc))
                {
                    renderTargetView = device.CreateRenderTargetView(texture2D);
                    deviceContext.OM.SetRenderTargets(new RenderTargetView[] { renderTargetView });

                    /* Set the backbuffer, which is a ID3D11Texture2D pointer */
                    d3dImage.SetBackBufferEx(D3DResourceTypeEx.ID3D11Texture2D, texture2D.NativeInterface);
                }

                // viewport
                SwapChainDescription desc     = swapChain.Description;
                Viewport             viewport = new Viewport();
                viewport.Width    = (float)e.NewSize.Width;
                viewport.Height   = (float)e.NewSize.Height;
                viewport.MinDepth = 0.0f;
                viewport.MaxDepth = 1.0f;
                viewport.TopLeftX = 0;
                viewport.TopLeftY = 0;

                deviceContext.RS.SetViewports(new Viewport[] { viewport });

                aspectRatio = e.NewSize.Width / e.NewSize.Height;

                Update();
            }
        }
Beispiel #9
0
        private void SetViews()
        {
            Texture2D texture2D = swapChain.GetBuffer <Texture2D>(0);

            renderTargetView = device.CreateRenderTargetView(texture2D);
            deviceContext.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView });
            texture2D.Dispose();

            // viewport
            SwapChainDescription desc     = swapChain.Description;
            Viewport             viewport = new Viewport();

            viewport.Width    = desc.BufferDescription.Width;
            viewport.Height   = desc.BufferDescription.Height;
            viewport.MinDepth = 0.0f;
            viewport.MaxDepth = 1.0f;
            viewport.TopLeftX = 0;
            viewport.TopLeftY = 0;

            deviceContext.RS.Viewports = new Viewport[] { viewport };
        }
        private void InitializeDX()
        {
            //perform DX Device and Context initialization
            HwndSource hwnd = new HwndSource(0, 0, 0, 0, 0, "dxPlotterElement", IntPtr.Zero);

            device        = D3DDevice.CreateDeviceAndSwapChain(hwnd.Handle);
            swapChain     = device.SwapChain;
            deviceContext = device.ImmediateContext;

            CompositionTarget.Rendering += OnRenderingProccessReady;

            Texture2DDescription tdesc = new Texture2DDescription
            {
                ArraySize         = 1,
                Width             = 1,
                Height            = 1,
                Format            = Format.B8G8R8A8UNorm,
                MipLevels         = 1,
                SampleDescription = new SampleDescription {
                    Count = 1, Quality = 0
                },
                Usage          = Usage.Default,
                BindingOptions = BindingOptions.RenderTarget | BindingOptions.ShaderResource,
                MiscellaneousResourceOptions = MiscellaneousResourceOptions.Shared,
                CpuAccessOptions             = CpuAccessOptions.None
            };

            using (Texture2D texture2D = device.CreateTexture2D(tdesc))
            {
                renderTargetView = device.CreateRenderTargetView(texture2D);
                deviceContext.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView });

                d3dImage.SetBackBufferEx(D3DResourceTypeEx.ID3D11Texture2D, texture2D.NativeInterface);
            }

            dxInitialized = true;
            OnDeviceInitialized();
        }
Beispiel #11
0
        private void SetViews()
        {
            // Create a render target view
            using (Texture2D pBuffer = swapChain.GetBuffer <Texture2D>(0))
            {
                renderTargetView = device.CreateRenderTargetView(pBuffer);
            }

            device.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView }, null);

            // Setup the viewport
            Viewport vp = new Viewport()
            {
                Width    = (uint)directControl.ClientSize.Width,
                Height   = (uint)directControl.ClientSize.Height,
                MinDepth = 0.0f,
                MaxDepth = 1.0f,
                TopLeftX = 0,
                TopLeftY = 0
            };

            device.RS.Viewports = new Viewport[] { vp };
        }
        private void SetViews()
        {
            // Create a render target view
            using (Texture2D buffer = swapChain.GetBuffer <Texture2D>(0))
            {
                renderTargetView = device.CreateRenderTargetView(buffer);
            }

            //bind the views to the device
            device.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView });

            // Setup the viewport
            Viewport vp = new Viewport()
            {
                Width    = (uint)host.ActualWidth,
                Height   = (uint)host.ActualHeight,
                MinDepth = 0.0f,
                MaxDepth = 1.0f,
                TopLeftX = 0,
                TopLeftY = 0
            };

            device.RS.Viewports = new Viewport[] { vp };
        }
        /// <summary>
        /// Create Direct3D device and swap chain
        /// </summary>
        protected void InitDevice()
        {
            device = D3DDevice.CreateDeviceAndSwapChain(this.Handle);
            swapChain = device.SwapChain;

            // Create a render target view
            using (Texture2D pBuffer = swapChain.GetBuffer<Texture2D>(0))
            {
                renderTargetView = device.CreateRenderTargetView(pBuffer);
            }
            device.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView }, null);

            // Setup the viewport
            Viewport vp = new Viewport()
            {
                Width = (uint)this.ClientSize.Width,
                Height = (uint)this.ClientSize.Height,
                MinDepth = 0.0f,
                MaxDepth = 1.0f,
                TopLeftX = 0,
                TopLeftY = 0
            };

            device.RS.Viewports = new Viewport[] { vp };
        } 
        private void InitializeDX()
        {
            //perform DX Device and Context initialization
            HwndSource hwnd = new HwndSource(0, 0, 0, 0, 0, "dxPlotterElement", IntPtr.Zero);
            device = D3DDevice.CreateDeviceAndSwapChain(hwnd.Handle, out swapChain);
            deviceContext = device.GetImmediateContext();

            CompositionTarget.Rendering += OnRenderingProccessReady; 

            Texture2DDescription tdesc = new Texture2DDescription
            {
                ArraySize = 1,
                Width = 1,
                Height = 1,
                Format = Format.B8G8R8A8_UNORM,
                MipLevels = 1,
                SampleDescription = new SampleDescription { Count = 1, Quality = 0 },
                Usage = Usage.Default,
                BindFlags = BindFlag.RenderTarget | BindFlag.ShaderResource,
                MiscFlags = ResourceMiscFlag.Shared,
                CpuAccessFlags = 0
            };

            using (Texture2D texture2D = device.CreateTexture2D(tdesc))
            {
                renderTargetView = device.CreateRenderTargetView(texture2D);
                deviceContext.OM.SetRenderTargets(new RenderTargetView[] { renderTargetView });

                d3dImage.SetBackBufferEx(D3DResourceTypeEx.ID3D11Texture2D, texture2D.NativeInterface);
            }

            dxInitialized = true;
            OnDeviceInitialized();

        }
Beispiel #15
0
        void Window1_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (device != null)
            {
                //need to remove the reference to the swapchain's backbuffer to enable ResizeBuffers() call
                renderTargetView.Dispose();
                SwapChainDescription sd = swapChain.Description;
                swapChain.ResizeBuffers(
                    sd.BufferCount,
                    (uint)renderHost.ActualWidth,
                    (uint)renderHost.ActualHeight,
                    sd.BufferDescription.Format,
                    sd.Options);

                using (Texture2D pBuffer = swapChain.GetBuffer <Texture2D>(0))
                {
                    renderTargetView = device.CreateRenderTargetView(pBuffer);
                }

                // Create depth stencil texture
                Texture2DDescription descDepth = new Texture2DDescription()
                {
                    Width             = (uint)renderHost.ActualWidth,
                    Height            = (uint)renderHost.ActualHeight,
                    MipLevels         = 1,
                    ArraySize         = 1,
                    Format            = Format.D32Float,
                    SampleDescription = new SampleDescription()
                    {
                        Count   = 1,
                        Quality = 0
                    },
                    BindingOptions = BindingOptions.DepthStencil,
                };

                depthStencil = device.CreateTexture2D(descDepth);

                // Create the depth stencil view
                DepthStencilViewDescription depthStencilViewDesc = new DepthStencilViewDescription()
                {
                    Format        = descDepth.Format,
                    ViewDimension = DepthStencilViewDimension.Texture2D
                };
                depthStencilView = device.CreateDepthStencilView(depthStencil, depthStencilViewDesc);

                // bind the views to the device
                device.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView }, depthStencilView);

                // Setup the viewport
                Viewport vp = new Viewport()
                {
                    Width    = (uint)renderHost.ActualWidth,
                    Height   = (uint)renderHost.ActualHeight,
                    MinDepth = 0.0f,
                    MaxDepth = 1.0f,
                    TopLeftX = 0,
                    TopLeftY = 0
                };

                device.RS.Viewports = new Viewport[] { vp };
            }
        }