private void Initialize() { if (!_engine.IsDisposed) { // Use the engine's default viewport if selected Viewport = (Size == Size.Empty) ? _engine.RenderViewport : new Viewport { Width = Size.Width, Height = Size.Height, MaxZ = 1 }; // Dispose the _rtsHelper if it already exists but the size has changed new Size(Viewport.Width, Viewport.Height).To(ref _rtsHelperSize, delegate { if (_rtsHelper != null) { _rtsHelper.Dispose(); _rtsHelper = null; } }); // Reset the _rtsHelper if it already exists and is still valid _rtsHelper?.OnResetDevice(); // Create the target texture and surface Texture = new Texture(_engine.Device, Viewport.Width, Viewport.Height, 1, Usage.RenderTarget, _engine.PresentParams.BackBufferFormat, Pool.Default); Surface = Texture.GetSurfaceLevel(0); } }