コード例 #1
0
        public override void EnableLayerBrush()
        {
            factory = DXGI.CreateDXGIFactory1 <IDXGIFactory1>();

            StartDesktopDuplicator(0, 0);
            Thread.Sleep(100);
        }
コード例 #2
0
        public static IEnumerable <ComObject <T> > EnumAdapters1 <T>(this IDXGIFactory1 factory) where T : IDXGIAdapter1
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            uint i = 0;

            do
            {
                if (factory.EnumAdapters1(i++, out var adapter).IsError)
                {
                    yield break;
                }

                yield return(new ComObject <T>((T)adapter));
            }while (true);
        }
コード例 #3
0
        public static IComObject <T> GetAdapter1 <T>(this IDXGIFactory1 factory, int index) where T : IDXGIAdapter1
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            int i = 0;

            do
            {
                if (factory.EnumAdapters((uint)i, out var adapter).IsError)
                {
                    return(null);
                }

                if (i == index)
                {
                    return(new ComObject <T>((T)adapter));
                }

                i++;
            }while (true);
        }
コード例 #4
0
ファイル: SwapChainDXGI.cs プロジェクト: cagr301/engine
        protected unsafe SwapChainDXGI(
            GraphicsDevice device,
            SwapChainDescriptor descriptor,
            IDXGIFactory1 dxgiFactory,
            ComObject deviceOrCommandQueue,
            int bufferCount,
            int backBufferCount)
            : base(device, descriptor)
        {
            BackBufferCount = backBufferCount;
            var width  = Math.Max(descriptor.Width, 1);
            var height = Math.Max(descriptor.Height, 1);

            switch (descriptor.Handle)
            {
            case Win32SwapChainHandle win32Handle:
            {
                // Check tearing support.
                var dxgiFactory5 = dxgiFactory.QueryInterfaceOrNull <IDXGIFactory5>();
                var allowTearing = false;
                if (dxgiFactory5 != null)
                {
                    if (dxgiFactory5.PresentAllowTearing)
                    {
                        // Recommended to always use tearing if supported when using a sync interval of 0.
                        _syncInterval  = 0;
                        _presentFlags |= PresentFlags.AllowTearing;
                        allowTearing   = true;
                    }

                    dxgiFactory5.Dispose();
                }

                var dxgiFactory2 = dxgiFactory.QueryInterfaceOrNull <IDXGIFactory2>();
                if (dxgiFactory2 != null)
                {
                    var swapchainDesc = new SwapChainDescription1()
                    {
                        Width             = width,
                        Height            = height,
                        Format            = BackBufferFormat,
                        Stereo            = false,
                        SampleDescription = new SampleDescription(1, 0),
                        Usage             = Vortice.DirectX.Usage.RenderTargetOutput,
                        BufferCount       = bufferCount,
                        Scaling           = Scaling.Stretch,
                        SwapEffect        = allowTearing ? SwapEffect.FlipDiscard : SwapEffect.Discard,
                        AlphaMode         = AlphaMode.Ignore,
                        Flags             = allowTearing ? SwapChainFlags.AllowTearing : SwapChainFlags.None,
                    };

                    var fullscreenDescription = new SwapChainFullscreenDescription
                    {
                        Windowed = true
                    };

                    _swapChain = dxgiFactory2.CreateSwapChainForHwnd(
                        deviceOrCommandQueue,
                        win32Handle.HWnd,
                        swapchainDesc,
                        fullscreenDescription);

                    dxgiFactory2.Dispose();
                }
                else
                {
                    SwapChainDescription dxgiSCDesc = new SwapChainDescription
                    {
                        BufferCount       = bufferCount,
                        IsWindowed        = true,
                        BufferDescription = new ModeDescription(width, height, BackBufferFormat),
                        OutputWindow      = win32Handle.HWnd,
                        SampleDescription = new SampleDescription(1, 0),
                        SwapEffect        = SwapEffect.Discard,
                        Usage             = Vortice.DirectX.Usage.Backbuffer | Vortice.DirectX.Usage.RenderTargetOutput
                    };

                    _swapChain = dxgiFactory.CreateSwapChain(deviceOrCommandQueue, dxgiSCDesc);
                }

                dxgiFactory.MakeWindowAssociation(win32Handle.HWnd, WindowAssociationFlags.IgnoreAll);
            }
            break;

                //case CoreWindow coreWindowHandle:
                //    {
                //        var coreWindow = coreWindowHandle.CoreWindow;

                //        var swapchainDesc = new DXGI.SwapChainDescription1()
                //        {
                //            Width = width,
                //            Height = height,
                //            Format = DXGI.Format.B8G8R8A8_UNorm,
                //            Stereo = false,
                //            SampleDescription = new DXGI.SampleDescription(1, 0),
                //            Usage = DXGI.Usage.RenderTargetOutput,
                //            BufferCount = FrameCount,
                //            Scaling = DXGI.Scaling.AspectRatioStretch,
                //            SwapEffect = DXGI.SwapEffect.FlipDiscard,
                //            AlphaMode = DXGI.AlphaMode.Ignore,
                //            Flags = DXGI.SwapChainFlags.None,
                //        };

                //        using (var comCoreWindow = new ComObject(coreWindow))
                //        {
                //            _swapChain = new DXGI.SwapChain1(
                //                factory,
                //                device.D3DDevice,
                //                comCoreWindow,
                //                ref swapchainDesc);
                //        }
                //    }
                //    break;
            }
        }
コード例 #5
0
        public DeviceD3D11(IDXGIFactory1 factory, bool validation)
        {
            DXGIFactory = factory;
            var adapters = DXGIFactory.EnumAdapters1();

            for (var i = 0; i < adapters.Length; i++)
            {
                var adapter = adapters[0];
                var desc    = adapter.Description1;

                // Don't select the Basic Render Driver adapter.
                if ((desc.Flags & AdapterFlags.Software) != AdapterFlags.None)
                {
                    continue;
                }

                var creationFlags = DeviceCreationFlags.BgraSupport /* | DeviceCreationFlags.VideoSupport*/;

                if (validation)
                {
                    creationFlags |= DeviceCreationFlags.Debug;
                }

                if (D3D11CreateDevice(
                        null,
                        DriverType.Hardware,
                        creationFlags,
                        s_featureLevels,
                        out D3D11Device,
                        out FeatureLevel,
                        out D3D11DeviceContext).Failure)
                {
                    // Remove debug flag not being supported.
                    creationFlags &= ~DeviceCreationFlags.Debug;

                    if (D3D11CreateDevice(null, DriverType.Hardware,
                                          creationFlags, s_featureLevels,
                                          out D3D11Device, out FeatureLevel, out D3D11DeviceContext).Failure)
                    {
                        throw new GraphicsException("Cannot create D3D11 Device");
                    }
                }

                DXGIAdapter = adapter;
                break;
            }

            D3D11Device1 = D3D11Device.QueryInterfaceOrNull <ID3D11Device1>();

            // Detect multithreading
            FeatureDataThreading featureDataThreading = default;

            if (D3D11Device.CheckFeatureSupport(DirectX.Direct3D11.Feature.Threading, ref featureDataThreading))
            {
                SupportsConcurrentResources = featureDataThreading.DriverConcurrentCreates;
                SupportsCommandLists        = featureDataThreading.DriverCommandLists;
            }

            // Init device features.
            InitializeFeatures();

            // Create command queue's.
            _graphicsCommandQueue = new CommandQueueD3D11(this, D3D11DeviceContext);
            _computeCommandQueue  = new CommandQueueD3D11(this, CommandQueueType.Compute);
            _copyCommandQueue     = new CommandQueueD3D11(this, CommandQueueType.Copy);
        }