Esempio n. 1
0
#pragma warning restore CS8618 // Non-nullable field is uninitialized. Consider declaring as nullable.

        #endregion

        #region Initialization

        private void InitializeDevices()
        {
            var createdDevice = Direct3D11Helper.CreateDevice();

            device = createdDevice ?? throw new Exception("Failed to create Direct3D device.");

            var createdSharpDXDevice = Direct3D11Helper.CreateSharpDXDevice(device);

            sharpDXDevice = createdSharpDXDevice ?? throw new Exception("Failed to create SharpDX device.");

            multithread = sharpDXDevice.QueryInterface <Multithread>();
            multithread.SetMultithreadProtected(true);
        }
        public void StartCapture()
        {
            _multithread = _sharpDxD3dDevice.QueryInterface <SharpDX.Direct3D11.Multithread>();
            _multithread.SetMultithreadProtected(true);
            _frameEvent  = new ManualResetEvent(false);
            _closedEvent = new ManualResetEvent(false);
            _events      = new[] { _closedEvent, _frameEvent };

            _captureItem.Closed += OnClosed;
            _framePool           = Direct3D11CaptureFramePool.CreateFreeThreaded(
                _device,
                DirectXPixelFormat.B8G8R8A8UIntNormalized,
                1,
                _captureItem.Size);
            _framePool.FrameArrived += OnFrameArrived;
            _session = _framePool.CreateCaptureSession(_captureItem);
            _session.StartCapture();
        }