Exemple #1
0
 internal static D3D.Viewport ToD3DViewport(Viewport vp)
 {
     D3D.Viewport d3dvp = new SlimDX.Direct3D10.Viewport();
     d3dvp.Height = vp.Height;
     d3dvp.Width  = vp.Width;
     d3dvp.MaxZ   = vp.MaxDepth;
     d3dvp.MinZ   = vp.MinDepth;
     d3dvp.X      = vp.X;
     d3dvp.Y      = vp.Y;
     return(d3dvp);
 }
        public void SetSize(int width, int height)
        {
            if (DepthBuffer != null) DepthBuffer.Dispose();
            if (DepthBufferView != null) DepthBufferView.Dispose();
            if (RenderTarget != null) RenderTarget.Dispose();

            SwapChain.ResizeBuffers(1, width, height, DXGI.Format.R8G8B8A8_UNorm, DXGI.SwapChainFlags.None);

            RenderTarget = new Texturing.RenderTarget(this, width, height);

            D3D.Texture2DDescription depthbufferdesc = new D3D.Texture2DDescription()
            {
                Width = width,
                Height = height,
                MipLevels = 1,
                ArraySize = 1,
                Format = SlimDX.DXGI.Format.D24_UNorm_S8_UInt,
                SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0),
                Usage = D3D.ResourceUsage.Default,
                BindFlags = D3D.BindFlags.DepthStencil,
                CpuAccessFlags = D3D.CpuAccessFlags.None,
                OptionFlags = D3D.ResourceOptionFlags.None
            };

            DepthBuffer = new D3D.Texture2D(Device, depthbufferdesc);
            DepthBufferView = new D3D.DepthStencilView(Device, DepthBuffer);

            Viewport = new D3D.Viewport()
            {
                X = 0,
                Y = 0,
                Width = width,
                Height = height,
                MinZ = 0.0f,
                MaxZ = 1.0f
            };
            Device.Rasterizer.SetViewports(Viewport);
            SetOutputTargets();
        }
Exemple #3
0
        public void Initialize()
        {
            var description = new SwapChainDescription
                                  {
                                      BufferCount = 1,
                                      Usage = Usage.RenderTargetOutput,
                                      OutputHandle = _form.Handle,
                                      IsWindowed = true,
                                      ModeDescription = new ModeDescription
                                                            {
                                                                Width = 0,
                                                                Height = 0,
                                                                Format = Format.R8G8B8A8_UNorm,
                                                                RefreshRate = new Rational(60, 1),
                                                                Scaling = DisplayModeScaling.Unspecified,
                                                                ScanlineOrdering = DisplayModeScanlineOrdering.Unspecified
                                                            },
                                      SampleDescription = new SampleDescription
                                                              {
                                                                  Count = 1,
                                                                  Quality = 0
                                                              },
                                      Flags = SwapChainFlags.AllowModeSwitch,
                                      SwapEffect = SwapEffect.Discard
                                  };

            // Create device
            SlimDX.Direct3D10_1.Device1.CreateWithSwapChain(null, DriverType.Hardware, DeviceCreationFlags.None,
                                                            description, out _device, out _swapChain);

            using (var resource = Resource.FromSwapChain<Texture2D>(_swapChain, 0))
            {
                _renderTargetView = new RenderTargetView(_device, resource);
            }

            InitializeDepthBuffer();
            InitializeMeshes();
            InitializeWritableTexture();
            InitializeShaders("passthrough.fx");

            _viewport = new Viewport(0, 0, _form.ClientSize.Width, _form.ClientSize.Height, 0.0f, 1.0f);
            _device.Rasterizer.SetViewports(_viewport);
            _device.OutputMerger.SetTargets(_depthStencilView, _renderTargetView);

            _rasterizerState = RasterizerState.FromDescription(_device, new RasterizerStateDescription
                                                                            {
                                                                                IsDepthClipEnabled = false,
                                                                                FillMode = FillMode.Solid,
                                                                                CullMode = CullMode.None
                                                                            });
            _device.Rasterizer.State = _rasterizerState;

            _form.UserResized += (sender, e) =>
                                     {
                                         _renderTargetView.Dispose();

                                         _swapChain.ResizeBuffers(2, 0, 0, Format.R8G8B8A8_UNorm,
                                                                  SwapChainFlags.AllowModeSwitch);
                                         using (var resource = Resource.FromSwapChain<Texture2D>(_swapChain, 0))
                                         {
                                             _renderTargetView = new RenderTargetView(_device, resource);
                                         }

                                         InitializeDepthBuffer();
                                         InitializeWritableTexture();

                                         _device.OutputMerger.SetTargets(_depthStencilView, _renderTargetView);
                                     };
        }