コード例 #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);
        }
コード例 #2
0
        internal GraphicsDevice(DirectX11Proxy proxy, GraphicSurfaceSize size, AdapterDescription adapterDescription)
        {
            resourseHash = new ResourseRegistrHash();
            Compilator   = new D3DShaderCompilator();
            Adapter      = adapterDescription;

            int width  = size.Width;
            int height = size.Height;

            directX = proxy;
            directX.Resize(width, height);
            CreateBuffers(width, height);

            TexturedLoader = new TextureLoader(directX.D3DDevice);
        }