Ejemplo n.º 1
0
        public void Initialize()
        {
            SwapChainDescription scdesc = new SwapChainDescription()
            {
                BufferCount = 1, IsWindowed = true, Flags = SwapChainFlags.None, ModeDescription = new ModeDescription(Width, Height, new Rational(60, 1), Format.B8G8R8A8_UNorm), OutputHandle = Handle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput
            };
            DeviceCreationFlags flags = DeviceCreationFlags.BgraSupport;

#if DEBUG
            flags |= DeviceCreationFlags.Debug;
#endif
            SharpDX.Direct3D11.Device.CreateWithSwapChain(SharpDX.Direct3D.DriverType.Hardware, flags, scdesc, out SharpDX.Direct3D11.Device device, out SwapChain sc);
            DXGISwapChain = sc;
            D3DDevice     = device;
            D3DContext    = D3DDevice.ImmediateContext;

            Backbuffer    = DXGISwapChain.GetBackBuffer <Texture2D>(0);
            BackbufferRTV = new RenderTargetView(D3DDevice, Backbuffer);
            D3DContext.OutputMerger.SetRenderTargets(BackbufferRTV);

            Screen.OnCreate();

            D3DContext.Rasterizer.SetViewport(new Viewport(0, 0, Width, Height));
            Screen.OnCreateBuffers();

            watch = new System.Diagnostics.Stopwatch();
            watch.Start();

            Application.Idle += OnTick;
        }
Ejemplo n.º 2
0
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);

            if (D3DContext == null)
            {
                return;
            }

            if (Width == 0 || Height == 0)
            {
                return;
            }

            D3DContext.OutputMerger.SetRenderTargets((RenderTargetView)null);
            BackbufferRTV.Dispose();
            Backbuffer.Dispose();
            Screen.OnDisposeBuffers();

            D3DContext.Rasterizer.SetViewport(new Viewport(0, 0, Width, Height));
            DXGISwapChain.ResizeBuffers(1, Width, Height, Format.Unknown, SwapChainFlags.None);
            Screen.OnResizeBuffers();

            Backbuffer    = DXGISwapChain.GetBackBuffer <Texture2D>(0);
            BackbufferRTV = new RenderTargetView(D3DDevice, Backbuffer);
            D3DContext.OutputMerger.SetRenderTargets(BackbufferRTV);
            Screen.OnCreateBuffers();
        }