/// <summary>Initialize the object.</summary> public void initialize(iRenderingContext rc, Rational?displayRefresh) { if (null != renderContext) { throw new ApplicationException("Already initialized"); } dispatcher = Dispatcher.currentDispatcher; this.displayRefresh = displayRefresh; if (null == dispatcher) { throw new ApplicationException("Context.initialize requires the current thread to have a dispatcher"); } renderContext = rc; context = rc.context; swapChain = rc.swapChain; if (rc is iDiligentWindow window) { dpiScalingFactor = window.dpiScaling; } using (var device = rc.device) { isOpenGlDevice = device.isGlDevice(); var scDesc = swapChain.GetDesc(); swapChainSize = new CSize(scDesc.Width, scDesc.Height); swapChainFormats = new SwapChainFormats(scDesc.ColorBufferFormat, scDesc.DepthBufferFormat, getSampleCount(swapChain)); swapChainBuffersCount = scDesc.BufferCount; animation = new Animations(this); scene.createResources(this, device); } initializeAsync(); }
public AnimatedGameWindow(IPlatformWindow window, ISwapChain swapChain, IGraphicsDevice device) { this.Window = window; this.swapChain = swapChain; this.Device = device; this.gameTimer = new GameTimer(); }
public GraphicsDevice( IPlatformWindow window, IGraphicsDeviceAdapter graphicsDeviceAdapter, ISwapChain swapChainAdapter) { this.window = window ?? throw new ArgumentNullException(nameof(window)); this.graphicsDeviceAdapter = graphicsDeviceAdapter ?? throw new ArgumentNullException(nameof(graphicsDeviceAdapter)); this.SwapChain = swapChainAdapter ?? throw new ArgumentNullException(nameof(swapChainAdapter)); }
static byte getSampleCount(ISwapChain swapChain) { using (var rtv = swapChain.GetCurrentBackBufferRTV()) using (var texture = rtv.GetTexture()) { var desc = texture.GetDesc(); return((byte)desc.SampleCount); } }
public SwapChain(ISwapChain swapChain) { if (swapChain == null) { throw new ArgumentNullException(nameof(swapChain)); } _swapChain = swapChain; swapChain.SetCallback(new Callback(this)); Application.Current.Update += OnUpdate; }
public void CreateSwapChain() { CanvasDevice canvasDevice = ((CanvasDeviceAdapter)this.graphicsDeviceAdapter).CanvasDevice; var coreWindow = (CoreWindow)this.platformWindow.Window; float currentDpi = DisplayInformation.GetForCurrentView().LogicalDpi; this.canvasSwapChain = CanvasSwapChain.CreateForCoreWindow(canvasDevice, coreWindow, currentDpi); this.Target = this; }
private ISwapChain CreateOrUpdateRenderTarget( IGraphicsDevice device, AlphaMode newAlphaMode, float newDpi, Size newSize, ISwapChain renderTarget) { Size renderTargetSize = new Size((int)renderTarget.Width, (int)renderTarget.Height); bool needsTarget = renderTarget != null; bool alphaModeChanged = renderTarget.AlphaMode != newAlphaMode; bool dpiChanged = renderTarget.LogicalDpi != newDpi; bool sizeChanged = renderTargetSize != newSize; bool needsCreate = needsTarget || alphaModeChanged; if (!needsCreate && !sizeChanged && !dpiChanged) { return(null); } if (newSize.Width <= 0 || newSize.Height <= 0) { // Zero-sized controls don't have swap chain objects return(null); } else if ((sizeChanged || dpiChanged) && !needsCreate) { renderTarget.ResizeBuffersWithWidthAndHeightAndDpi(newSize.Width, newSize.Height, newDpi); renderTargetSize = newSize; //renderTarget.LogicalDpi = newDpi; } else { //renderTarget.Target = this.Device.CreateSwapChain( // newSize.Width, // newSize.Height, // newDpi, // newAlphaMode); renderTarget.AlphaMode = newAlphaMode; //renderTarget.LogicalDpi = newDpi; renderTargetSize = newSize; } return(renderTarget); }
void iContent.swapChainRecreated(iDiligentWindow window) { try { swapChain = window.swapChain; context = window.context; timersHardPause?.Dispose(); timersHardPause = null; var scDesc = swapChain.GetDesc(); swapChainSize = new CSize(scDesc.Width, scDesc.Height); byte samples = swapChainFormats.sampleCount; swapChainFormats = new SwapChainFormats(scDesc.ColorBufferFormat, scDesc.DepthBufferFormat, samples); swapChainBuffersCount = scDesc.BufferCount; } catch (Exception ex) { NativeContext.cacheException(ex); throw; } }
void iContent.releaseCachedResources(eReleaseResources what) { try { if (null == timersHardPause) { timersHardPause = animation.timers.hardPause(); } foreach (var rr in releaseResources) { rr(what); } ComUtils.clear(ref cachedRtv); ComUtils.clear(ref cachedDsv); context?.SetRenderTargets(0, null, null, ResourceStateTransitionMode.None); if (what == eReleaseResources.Buffers) { return; } context?.Dispose(); context = null; if (what == eReleaseResources.Context) { return; } swapChain?.Dispose(); swapChain = null; } catch (Exception ex) { NativeContext.cacheException(ex); throw; } }
protected virtual void Initialize() { Window = _gamePlatformFactory.CreateGameWindow(_options.Graphics); foreach (var inputMapping in _options.Input.InputMappings) { switch (inputMapping) { case KeyboardInputMapping keyboardInputMapping: _inputMapper.AddMap(Xacor.Input.Input.CreateKeyboardInput(inputMapping.Name, keyboardInputMapping.Key1, keyboardInputMapping.Key2)); break; case MouseInputMapping mouseInputMapping: _inputMapper.AddMap(Xacor.Input.Input.CreateMouseMovement(inputMapping.Name, mouseInputMapping.Axis)); break; } } var swapChainInfo = CreateSwapChainInfo(); _swapchain = GraphicsFactory.CreateSwapchain(swapChainInfo); BackBufferView = _swapchain.TextureView; BackBufferDepthStencilView = _swapchain.DepthStencilView; }
public void SetSwapChain(ISwapChain swapChain) { SwapChain = swapChain; }
public bool Tick(ISwapChain swapChain, bool areResourcesCreated) { throw new NotImplementedException(); }