public void UpdateTextures(GraphicsDevice graphicsDevice) { if (_mustRecreateTextures) { _consoleHandle.LogInfo("Recreating shared textures in game host..."); if (_sharedTextures != null) { for (var i = 0; i < _sharedTextures.Length; i++) { _sharedTextures[i].Dispose(); } } if (_sharedTexturePointers != null) { _sharedTextures = new RenderTarget2D[_sharedTexturePointers.Length]; } else { _sharedTextures = null; } if (_sharedTextures != null) { for (var i = 0; i < _sharedTexturePointers.Length; i++) { _sharedTextures[i] = RenderTarget2D.FromSharedResourceHandle( graphicsDevice, _sharedTexturePointers[i]); } } } }
public void UpdateHandles(IntPtr[] sharedResourceHandles, int currentWriteIndex) { _currentWriteIndex = currentWriteIndex; if (GraphicsDevice == null && sharedResourceHandles[_currentWriteIndex] != IntPtr.Zero) { // We have been requested to create a graphics device. var parameters = new PresentationParameters(); parameters.BackBufferWidth = 1; parameters.BackBufferHeight = 1; parameters.BackBufferFormat = SurfaceFormat.Color; parameters.DepthStencilFormat = DepthFormat.Depth24; parameters.DeviceWindowHandle = IntPtr.Zero; parameters.PresentationInterval = PresentInterval.Immediate; parameters.IsFullScreen = false; GraphicsDevice = new GraphicsDevice( GraphicsAdapter.DefaultAdapter, GraphicsProfile.HiDef, parameters); DeviceCreated?.Invoke(this, EventArgs.Empty); } if (GraphicsDevice != null && sharedResourceHandles[_currentWriteIndex] == IntPtr.Zero) { DeviceDisposing?.Invoke(this, EventArgs.Empty); GraphicsDevice.Dispose(); GraphicsDevice = null; } if (_sharedResourceHandles[_currentWriteIndex] != sharedResourceHandles[_currentWriteIndex]) { for (var i = 0; i < RenderTargetBufferConfiguration.RTBufferSize; i++) { _renderTargets[i]?.Dispose(); _renderTargets[i] = null; } for (var i = 0; i < RenderTargetBufferConfiguration.RTBufferSize; i++) { if (GraphicsDevice != null) { _renderTargets[i] = RenderTarget2D.FromSharedResourceHandle( GraphicsDevice, sharedResourceHandles[i]); } } _sharedResourceHandles = sharedResourceHandles; } }