Exemplo n.º 1
0
        public void Init(IntPtr hWnd, ApplicationInfo appInfo)
        {
            if (m_ApplicationInfo != null)
            {
                throw new InvalidOperationException("context already initialized");
            }

            m_ApplicationInfo = appInfo;

            var swapChainDesc = new DXGI.SwapChainDescription
            {
                ModeDescription = new DXGI.ModeDescription
                {
                    Width       = m_ApplicationInfo.Width,
                    Height      = m_ApplicationInfo.Height,
                    RefreshRate = new DXGI.Rational(60, 1),
                    Format      = DXGI.Format.R8G8B8A8_UNorm
                },
                SampleDescription = new DXGI.SampleDescription
                {
                    Count = 4
                },
                BufferCount  = 1,
                Usage        = DXGI.Usage.RenderTargetOutput,
                OutputHandle = hWnd,
                IsWindowed   = !m_ApplicationInfo.FullScreen,
                SwapEffect   = DXGI.SwapEffect.Discard,
                Flags        = DXGI.SwapChainFlags.AllowModeSwitch
            };

            D3D11.Device.CreateWithSwapChain(D3D.DriverType.Hardware,
                                             D3D11.DeviceCreationFlags.BgraSupport | D3D11.DeviceCreationFlags.Debug, new[] { m_FeatureLevel },
                                             swapChainDesc, out D3D11.Device dev, out DXGI.SwapChain swapChain);
            Dev       = dev;
            DevCon    = Dev.ImmediateContext;
            SwapChain = swapChain;

            D2DFactory    = new D2D1.Factory(D2D1.FactoryType.SingleThreaded, D2D1.DebugLevel.Information);
            DWriteFactory = new DirectWrite.Factory(DirectWrite.FactoryType.Shared);

            m_MSAAQuality = Dev.CheckMultisampleQualityLevels(DXGI.Format.R8G8B8A8_UNorm, 4);

            D3D11.DeviceDebug d3dDebug = dev.QueryInterface <D3D11.DeviceDebug>();
            if (d3dDebug != null)
            {
                D3D11.InfoQueue infoQueue = dev.QueryInterface <D3D11.InfoQueue>();
                if (infoQueue != null)
                {
                    D3D11.MessageId[] hide =
                    {
                        D3D11.MessageId.MessageIdDeviceDrawSamplerNotSet
                    };
                    infoQueue.AddStorageFilterEntries(new D3D11.InfoQueueFilter()
                    {
                        DenyList = new D3D11.InfoQueueFilterDescription {
                            Ids = hide
                        }
                    });
                }
            }

            Resize();

            CreateBlendStates();
            CreateDepthStencilStates();
            CreateRasterizerStates();

            SetBlend(false);
            SetDepthTesting(true);
            SetWireframe(false);

            SharpDX.DXGI.Device             dxgiDev     = Dev.QueryInterface <SharpDX.DXGI.Device>();
            SharpDX.DXGI.AdapterDescription adapterDesc = dxgiDev.Adapter.Description;

            Console.WriteLine("----------------------------------");
            Console.WriteLine(" Direct3D 11:");
            Console.WriteLine("    " + adapterDesc.Description);
            Console.WriteLine("    VRAM: " + adapterDesc.DedicatedVideoMemory / 1024 / 1024 + " MB");
            Console.WriteLine("----------------------------------");

            dxgiDev.Dispose();
        }
Exemplo n.º 2
0
        protected override void _render()
        {
            if (_brush == null)
                _brush = new SolidColorBrush(Device.RenderTarget, Color);

            if (Factory == null)
                Factory = new DirectWrite.Factory();

            if (_font == null)
                _font = new SlimDX.DirectWrite.TextFormat(
                    this.Factory,
                    this.Typeface,
                    this.Fontweight,
                    this.Fontstyle,
                    this.Fontstretch,
                    this.Fontsize,
                    "en-us"
                );

            Device.RenderTarget.DrawText(String, _font, _rectangle, _brush);
        }