Esempio n. 1
0
        private void SetupTexture(Size2 size)
        {
            if (size.Width <= 0 || size.Height <= 0)
            {
                size = new Size2(512, 512);
            }

            var resourceManager = ResourceManager.Instance();
            var device          = resourceManager.Device;

            _texture = new Texture2D(device,
                                     new Texture2DDescription
            {
                ArraySize         = 1,
                BindFlags         = BindFlags.RenderTarget | BindFlags.ShaderResource | BindFlags.UnorderedAccess,
                CpuAccessFlags    = CpuAccessFlags.None,
                Format            = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                Width             = size.Width,
                Height            = size.Height,
                MipLevels         = 0,
                OptionFlags       = ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = ResourceUsage.Default
            });
            _textureSrv = new ShaderResourceView(device, _texture);
            //resourceManager.CreateShaderResourceView(_textureResId, "", ref ShaderResourceView.Value);

            Texture.DirtyFlag.Clear();
            ShaderResourceView.DirtyFlag.Clear();
        }
Esempio n. 2
0
        private void SetupMediaFoundation()
        {
            using var mediaEngineAttributes = new MediaEngineAttributes()
                  {
                      // _SRGB doesn't work :/ Getting invalid argument exception later in TransferVideoFrame
                      AudioCategory     = SharpDX.Multimedia.AudioStreamCategory.GameMedia,
                      AudioEndpointRole = SharpDX.Multimedia.AudioEndpointRole.Multimedia,
                      VideoOutputFormat = (int)SharpDX.DXGI.Format.B8G8R8A8_UNorm
                  };

            //var graphicsDevice = renderDrawContextHandle.Resource.GraphicsDevice;
            var device = ResourceManager.Instance().Device;

            //var device = SharpDXInterop.GetNativeDevice(graphicsDevice) as Device;
            if (device != null)
            {
                // Add multi thread protection on device (MF is multi-threaded)
                using var deviceMultithread = device.QueryInterface <DeviceMultithread>();
                deviceMultithread.SetMultithreadProtected(true);

                // Reset device
                using var manager = new DXGIDeviceManager();
                manager.ResetDevice(device);
                mediaEngineAttributes.DxgiManager = manager;
            }

            // using var classFactory = new MediaEngineClassFactory();
            // try
            // {
            //
            //     _engine = new MediaEngine(classFactory, mediaEngineAttributes);
            //     _engine.PlaybackEvent += Engine_PlaybackEvent;
            // }
            // catch (SharpDXException e)
            // {
            //     Log.Error("Failed to setup MediaEngine: " + e.Message);
            // }

            // Setup Media Engine attributes
            // Create a DXGI Device Manager
            dxgiDeviceManager = new DXGIDeviceManager();
            dxgiDeviceManager.ResetDevice(device);
            var attributes = new MediaEngineAttributes
            {
                DxgiManager       = dxgiDeviceManager,
                VideoOutputFormat = (int)SharpDX.DXGI.Format.B8G8R8A8_UNorm
            };

            MediaManager.Startup();
            using (var factory = new MediaEngineClassFactory())
                _engine = new MediaEngine(factory, attributes, MediaEngineCreateFlags.WaitForStableState, Engine_PlaybackEvent);
        }