Exemple #1
0
        public GraphicsDevice(IAppWindow window)
        {
            resourseHash = new ResourseRegistrHash();

            this.handle = window.Handle;

            Compilator = new D3DShaderCompilator();

            var width  = (int)window.Width;
            var height = (int)window.Height;

            var backBufferDesc = new ModeDescription(width, height, new Rational(60, 1), Format.R8G8B8A8_UNorm);

            // Descriptor for the swap chain
            var swapChainDesc = new SwapChainDescription()
            {
                ModeDescription   = backBufferDesc,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = Usage.RenderTargetOutput,
                BufferCount       = 2,
                OutputHandle      = handle,
                IsWindowed        = true
            };

            var factory = new Factory1();
            var adapter = AdapterFactory.GetBestAdapter(factory);

            VideoCardDescription = adapter.Description.Description.Trim('\0');


            /*
             *
             *  DeviceCreationFlags.Debug - not supported by default, need to install the optional feature Graphics Tools
             *
             */

            // Create device and swap chain
            SharpDX.Direct3D11.Device.CreateWithSwapChain(adapter, DeviceCreationFlags.None, swapChainDesc, out var d3dDevice, out var sch);

            swapChain = sch.QueryInterface <SwapChain4>();
            D3DDevice = d3dDevice.QueryInterface <Device5>();

            ImmediateContext = d3dDevice.ImmediateContext;

            CreateBuffers(width, height);

            //TODO: Динамический оверлей. Direct3D 11.2 https://habr.com/company/microsoft/blog/199380/
            //swapChain.SetSourceSize
            //DContext = new DeviceContext(D3DDevice);

            TexturedLoader = new TextureLoader(D3DDevice);
        }
        static Adapter GetAdapter()
        {
            var factory = new Factory1();

            return(AdapterFactory.GetBestAdapter(factory));
        }