Ejemplo n.º 1
0
        /// <summary>
        /// Initializes the graphics.
        /// </summary>
        public void Initialize()
        {
            var swapChainDesc = new SwapChainDescription
            {
                BufferCount     = 2,
                Usage           = Usage.RenderTargetOutput,
                OutputHandle    = SGL.Components.Get <RenderTarget>().Handle,
                IsWindowed      = true,
                ModeDescription =
                    new ModeDescription(_graphicsDevice.BackBuffer.Width, _graphicsDevice.BackBuffer.Height,
                                        new Rational(60, 1), Format.R8G8B8A8_UNorm),
                SampleDescription = new SampleDescription(1, 0),
                Flags             = SwapChainFlags.AllowModeSwitch,
                SwapEffect        = SwapEffect.Discard
            };

            _swapChainDesc = swapChainDesc;

            swapChainDesc.ModeDescription.Scaling = _graphicsDevice.BackBuffer.Scaling
                ? DisplayModeScaling.Stretched
                : DisplayModeScaling.Centered;

            Device    device;
            SwapChain swapChain;

            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, swapChainDesc, out device,
                                       out swapChain);
            _swapChain = swapChain;


            // Get back buffer in a Direct2D-compatible format (DXGI surface)
            SharpDX.DXGI.Surface backBuffer = SharpDX.DXGI.Surface.FromSwapChain(swapChain, 0);

            var renderTarget = new SharpDX.Direct2D1.RenderTarget(DirectXHelper.D2DFactory, backBuffer,
                                                                  new RenderTargetProperties
            {
                DpiX        = 96,
                DpiY        = 96,
                MinLevel    = FeatureLevel.Level_DEFAULT,
                PixelFormat = new PixelFormat(Format.R8G8B8A8_UNorm, AlphaMode.Ignore),
                Type        = RenderTargetType.Hardware,
                Usage       = RenderTargetUsage.None
            })
            {
                TextAntialiasMode = TextAntialiasMode.Cleartype
            };

            DirectXHelper.RenderTarget = renderTarget;
            DirectXHelper.RenderTarget.AntialiasMode = SmoothingMode == SmoothingMode.AntiAlias
                ? AntialiasMode.Aliased
                : AntialiasMode.PerPrimitive;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the graphics.
        /// </summary>
        public void Initialize()
        {
            var swapChainDesc = new SwapChainDescription
            {
                BufferCount = 2,
                Usage = Usage.RenderTargetOutput,
                OutputHandle = SGL.Components.Get<RenderTarget>().Handle,
                IsWindowed = true,
                ModeDescription =
                    new ModeDescription(_graphicsDevice.BackBuffer.Width, _graphicsDevice.BackBuffer.Height,
                        new Rational(60, 1), Format.R8G8B8A8_UNorm),
                SampleDescription = new SampleDescription(1, 0),
                Flags = SwapChainFlags.AllowModeSwitch,
                SwapEffect = SwapEffect.Discard
            };

            _swapChainDesc = swapChainDesc;

            swapChainDesc.ModeDescription.Scaling = _graphicsDevice.BackBuffer.Scaling
                ? DisplayModeScaling.Stretched
                : DisplayModeScaling.Centered;

            Device device;
            SwapChain swapChain;
            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, swapChainDesc, out device,
                out swapChain);
            _swapChain = swapChain;

            // Get back buffer in a Direct2D-compatible format (DXGI surface)
            SharpDX.DXGI.Surface backBuffer = SharpDX.DXGI.Surface.FromSwapChain(swapChain, 0);

            var renderTarget = new SharpDX.Direct2D1.RenderTarget(DirectXHelper.D2DFactory, backBuffer,
                new RenderTargetProperties
                {
                    DpiX = 96,
                    DpiY = 96,
                    MinLevel = FeatureLevel.Level_DEFAULT,
                    PixelFormat = new PixelFormat(Format.R8G8B8A8_UNorm, AlphaMode.Ignore),
                    Type = RenderTargetType.Hardware,
                    Usage = RenderTargetUsage.None
                }) {TextAntialiasMode = TextAntialiasMode.Cleartype};
            DirectXHelper.RenderTarget = renderTarget;
            DirectXHelper.RenderTarget.AntialiasMode = SmoothingMode == SmoothingMode.AntiAlias
                ? AntialiasMode.Aliased
                : AntialiasMode.PerPrimitive;
        }