/// <summary> /// /// </summary> private void CreateAndBindTargets() { this.surfaceD3D.SetRenderTargetDX11(null); int width = System.Math.Max((int)this.ActualWidth, 100); int height = System.Math.Max((int)this.ActualHeight, 100); Disposer.RemoveAndDispose(ref this.renderTargetView); Disposer.RemoveAndDispose(ref this.depthStencilView); Disposer.RemoveAndDispose(ref this.renderTarget); Disposer.RemoveAndDispose(ref this.depthStencil); #if MSAA Disposer.RemoveAndDispose(ref this.renderTargetNMS); // check 8,4,2,1 int sampleCount = 8; int sampleQuality = 0; if (this.IsMSAAEnabled) { do { sampleQuality = this.device.CheckMultisampleQualityLevels(Format.B8G8R8A8_UNorm, sampleCount) - 1; if (sampleQuality > 0) { break; } else { sampleCount /= 2; } if (sampleCount == 1) { sampleQuality = 0; break; } }while (true); } else { sampleCount = 1; sampleQuality = 0; } var sampleDesc = new SampleDescription(sampleCount, sampleQuality); var optionFlags = ResourceOptionFlags.None; #else var sampleDesc = new SampleDescription(1, 0); var optionFlags = ResourceOptionFlags.Shared; #endif var colordesc = new Texture2DDescription { BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Format = Format.B8G8R8A8_UNorm, Width = width, Height = height, MipLevels = 1, SampleDescription = sampleDesc, Usage = ResourceUsage.Default, OptionFlags = optionFlags, CpuAccessFlags = CpuAccessFlags.None, ArraySize = 1 }; var depthdesc = new Texture2DDescription { BindFlags = BindFlags.DepthStencil, Format = Format.D32_Float_S8X24_UInt, Width = width, Height = height, MipLevels = 1, SampleDescription = sampleDesc, Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.None, CpuAccessFlags = CpuAccessFlags.None, ArraySize = 1, }; this.renderTarget = new Texture2D(this.device, colordesc); this.depthStencil = new Texture2D(this.device, depthdesc); this.renderTargetView = new RenderTargetView(this.device, this.renderTarget); this.depthStencilView = new DepthStencilView(this.device, this.depthStencil); #if MSAA var colordescNMS = new Texture2DDescription { BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Format = Format.B8G8R8A8_UNorm, Width = width, Height = height, MipLevels = 1, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.Shared, CpuAccessFlags = CpuAccessFlags.None, ArraySize = 1 }; this.renderTargetNMS = new Texture2D(this.device, colordescNMS); this.device.ImmediateContext.ResolveSubresource(this.renderTarget, 0, this.renderTargetNMS, 0, Format.B8G8R8A8_UNorm); this.surfaceD3D.SetRenderTargetDX11(this.renderTargetNMS); #else this.surfaceD3D.SetRenderTargetDX11(this.renderTarget); #endif }
public void Dispose() { Disposer.RemoveAndDispose(ref this.VertexBuffer); Disposer.RemoveAndDispose(ref this.IndexBuffer); }