/// <summary>
        /// Initializes a new instance of the <see cref="EngineAdapterInfo" /> class.
        /// </summary>
        internal EngineAdapterInfo(int adapterIndex, DXGI.Adapter1 adapter)
        {
            m_outputs      = new List <EngineOutputInfo>();
            m_adapter      = adapter;
            m_adapterIndex = adapterIndex;

            m_adapterDescription = adapter.Description;
            m_isSoftware         =
                (m_adapterDescription.Description == "Microsoft Basic Render Driver") ||
                ((!string.IsNullOrEmpty(m_adapterDescription.Description)) && m_adapterDescription.Description.Contains("Software")) ||
                ((!string.IsNullOrEmpty(m_adapterDescription.Description)) && m_adapterDescription.Description.Contains("Microsoft Basic Render Driver"));

            m_d3d11FeatureLevel = D3D11.Device.GetSupportedFeatureLevel(adapter);

            //Query for output information
            DXGI.Output[] outputs = adapter.Outputs;
            for (int loop = 0; loop < outputs.Length; loop++)
            {
                try
                {
                    DXGI.Output actOutput = outputs[loop];
                    try
                    {
                        m_outputs.Add(new EngineOutputInfo(adapterIndex, loop, actOutput));
                    }
                    finally
                    {
                        actOutput.Dispose();
                    }
                }
                catch (Exception)
                {
                    //Query for output information not possible
                    // .. no special handling needed here
                }
            }
        }
Example #2
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();
        }