protected virtual void Resize() {
if (_width == 0 || _height == 0) return;
DisposeHelper.Dispose(ref _renderBuffer);
DisposeHelper.Dispose(ref _renderView);
DisposeHelper.Dispose(ref _depthBuffer);
DisposeHelper.Dispose(ref _depthView);
if (_swapChain != null) {
_swapChain.ResizeBuffers(_swapChainDescription.BufferCount, _width, _height,
Format.Unknown, SwapChainFlags.None);
_renderBuffer = Resource.FromSwapChain<Texture2D>(_swapChain, 0);
} else {
_renderBuffer = new Texture2D(Device, new Texture2DDescription {
Width = _width,
Height = _height,
MipLevels = 1,
ArraySize = 1,
Format = Format.R8G8B8A8_UNorm,
SampleDescription = SampleDescription,
Usage = ResourceUsage.Default,
BindFlags = BindFlags.ShaderResource | BindFlags.RenderTarget,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None
});
}
_renderView = new RenderTargetView(Device, _renderBuffer);
_depthBuffer = new Texture2D(Device, new Texture2DDescription {
Format = FeatureLevel < FeatureLevel.Level_10_0 ? Format.D16_UNorm : Format.D32_Float,
ArraySize = 1,
MipLevels = 1,
Width = _width,
Height = _height,
SampleDescription = SampleDescription,
Usage = ResourceUsage.Default,
BindFlags = BindFlags.DepthStencil,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None
});
_depthView = new DepthStencilView(Device, _depthBuffer);
DeviceContext.Rasterizer.SetViewports(Viewport);
ResetTargets();
DeviceContext.OutputMerger.DepthStencilState = null;
Sprite?.RefreshViewport();
ResizeInner();
DeviceContextHolder.OnResize(Width, Height);
InitiallyResized = true;
}