protected GraphicsDeviceTestBase(GraphicsBackend backend, bool validation = false) { switch (backend) { case GraphicsBackend.Direct3D11: if (!D3D11GraphicsDeviceFactory.IsSupported()) { throw new GraphicsException($"Backend {backend} is not supported"); } _graphicsDeviceFactory = new D3D11GraphicsDeviceFactory(validation); break; case GraphicsBackend.Direct3D12: if (!D3D12GraphicsDeviceFactory.IsSupported()) { throw new GraphicsException($"Backend {backend} is not supported"); } _graphicsDeviceFactory = new D3D12GraphicsDeviceFactory(validation); break; default: throw new GraphicsException($"Backend {backend} is not supported"); } _graphicsDevice = _graphicsDeviceFactory.CreateDevice(PowerPreference.Default); }
public void Run() { if (IsRunning) { throw new InvalidOperationException("Cannot run this instance while it is already running"); } try { // Create GPU device first. _graphicsDeviceFactory = CreateGraphicsFactory(validation: true); _graphicsDevice = _graphicsDeviceFactory.CreateDevice(PowerPreference.Default); MainView.SetDevice(_graphicsDevice); // Enter main loop. _host.Run(); if (!_host.IsAsyncLoop) { // If the previous call was blocking, then we can call Endrun EndRun(); } else { // EndRun will be executed on Exit _endRunRequired = true; } } finally { if (!_endRunRequired) { IsRunning = false; } } }
public override void ConfigureServices(IServiceCollection services) { base.ConfigureServices(services); services.AddSingleton(_graphicsDeviceFactory.CreateDevice()); }