/// <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.colorBufferView); Disposer.RemoveAndDispose(ref this.depthStencilBufferView); Disposer.RemoveAndDispose(ref this.colorBuffer); Disposer.RemoveAndDispose(ref this.depthStencilBuffer); #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.D24_UNorm_S8_UInt, 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.colorBuffer = new Texture2D(this.device, colordesc); this.depthStencilBuffer = new Texture2D(this.device, depthdesc); this.colorBufferView = new RenderTargetView(this.device, this.colorBuffer); this.depthStencilBufferView = new DepthStencilView(this.device, this.depthStencilBuffer); #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.colorBuffer, 0, this.renderTargetNMS, 0, Format.B8G8R8A8_UNorm); this.surfaceD3D.SetRenderTargetDX11(this.renderTargetNMS); #else this.surfaceD3D.SetRenderTargetDX11(this.colorBuffer); #endif }
private void EndD3D() { Disposer.RemoveAndDispose(ref renderTarget); Disposer.RemoveAndDispose(ref device); Disposer.RemoveAndDispose(ref context); }
public void CreateTextureViews(Device device, CustomMaterialGeometryModel3D model) { if (material != null) { /// --- has texture if (material.DiffuseMap != null && model.RenderDiffuseMap) { Disposer.RemoveAndDispose(ref this.texDiffuseMapView); this.texDiffuseMapView = TextureLoader.FromMemoryAsShaderResourceView(device, material.DiffuseMap); } if (material.DiffuseAlphaMap != null) { Disposer.RemoveAndDispose(ref this.texDiffuseAlphaMapView); this.texDiffuseAlphaMapView = TextureLoader.FromMemoryAsShaderResourceView(device, material.DiffuseAlphaMap); } // --- has bumpmap if (material.NormalMap != null && model.RenderNormalMap) { var geometry = model.geometryInternal as MeshGeometry3D; if (geometry != null) { if (geometry.Tangents == null) { //System.Windows.MessageBox.Show(string.Format("No Tangent-Space found. NormalMap will be omitted."), "Warrning", MessageBoxButton.OK); material.NormalMap = null; } else { Disposer.RemoveAndDispose(ref this.texNormalMapView); this.texNormalMapView = TextureLoader.FromMemoryAsShaderResourceView(device, material.NormalMap); } } } // --- has displacement map if (material.DisplacementMap != null && model.RenderDisplacementMap) { Disposer.RemoveAndDispose(ref this.texDisplacementMapView); this.texDisplacementMapView = TextureLoader.FromMemoryAsShaderResourceView(device, material.DisplacementMap); } // --- has color table if (material.ColorTable != null && model.RenderColorTable) { Disposer.RemoveAndDispose(ref this.texColorTableView); this.texColorTableView = TextureLoader.FromMemoryAsShaderResourceView(device, material.ColorTable); } // --- has mask map if (material.MaskMap != null && model.RenderMaskMap) { Disposer.RemoveAndDispose(ref this.texMaskMapView); this.texMaskMapView = TextureLoader.FromMemoryAsShaderResourceView(device, material.MaskMap); } // --- has specular map if (material.SpecularMap != null && model.RenderSpecularMap) { Disposer.RemoveAndDispose(ref this.texSpecularMapView); this.texSpecularMapView = TextureLoader.FromMemoryAsShaderResourceView(device, material.SpecularMap); } } }
/// <summary> /// /// </summary> protected override void OnDetach() { Disposer.RemoveAndDispose(ref this.effectMaterial); base.OnDetach(); }
/// <summary> /// /// </summary> private void CreateAndBindTargets() { //surfaceD3D.SetRenderTargetDX11(null); int width = System.Math.Max((int)ActualWidth, 100); int height = System.Math.Max((int)ActualHeight, 100); device.ImmediateContext.OutputMerger.ResetTargets(); Disposer.RemoveAndDispose(ref colorBufferView); Disposer.RemoveAndDispose(ref colorBuffer); Disposer.RemoveAndDispose(ref backBuffer); Disposer.RemoveAndDispose(ref depthStencilBufferView); Disposer.RemoveAndDispose(ref depthStencilBuffer); CreateSwapChain(); backBuffer = Texture2D.FromSwapChain <Texture2D>(swapChain, 0); #if DoubleBuffer int sampleCount = 1; int sampleQuality = 0; if (MSAA != MSAALevel.Disable) { do { var newSampleCount = sampleCount * 2; var newSampleQuality = device.CheckMultisampleQualityLevels(Format.B8G8R8A8_UNorm, newSampleCount) - 1; if (newSampleQuality < 0) { break; } sampleCount = newSampleCount; sampleQuality = newSampleQuality; if (sampleCount == (int)MSAA) { break; } } while (sampleCount < 32); } var sampleDesc = new SampleDescription(sampleCount, sampleQuality); 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 = ResourceOptionFlags.None, CpuAccessFlags = CpuAccessFlags.None, ArraySize = 1 }; colorBuffer = new Texture2D(device, colordesc); colorBufferView = new RenderTargetView(device, colorBuffer); #else var sampleDesc = swapChain.Description1.SampleDescription; colorBufferView = new RenderTargetView(device, backBuffer); #endif var depthdesc = new Texture2DDescription { BindFlags = BindFlags.DepthStencil, //Format = Format.D24_UNorm_S8_UInt, 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, }; depthStencilBuffer = new Texture2D(device, depthdesc); depthStencilBufferView = new DepthStencilView(device, depthStencilBuffer); this.device.ImmediateContext.Rasterizer.SetScissorRectangle(0, 0, width, height); }
/// <summary> /// /// </summary> private void CreateAndBindTargets() { surfaceD3D.SetRenderTargetDX11(null); int width = System.Math.Max((int)ActualWidth, 100); int height = System.Math.Max((int)ActualHeight, 100); Disposer.RemoveAndDispose(ref colorBufferView); Disposer.RemoveAndDispose(ref depthStencilBufferView); Disposer.RemoveAndDispose(ref colorBuffer); Disposer.RemoveAndDispose(ref depthStencilBuffer); #if MSAA Disposer.RemoveAndDispose(ref renderTargetNMS); int sampleCount = 1; int sampleQuality = 0; if (MSAA != MSAALevel.Disable) { do { var newSampleCount = sampleCount * 2; var newSampleQuality = device.CheckMultisampleQualityLevels(Format.B8G8R8A8_UNorm, newSampleCount) - 1; if (newSampleQuality < 0) { break; } sampleCount = newSampleCount; sampleQuality = newSampleQuality; if (sampleCount == (int)MSAA) { break; } } while (sampleCount < 32); } 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.D24_UNorm_S8_UInt, 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, }; colorBuffer = new Texture2D(device, colordesc); depthStencilBuffer = new Texture2D(device, depthdesc); colorBufferView = new RenderTargetView(device, colorBuffer); depthStencilBufferView = new DepthStencilView(device, depthStencilBuffer); #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 }; renderTargetNMS = new Texture2D(device, colordescNMS); device.ImmediateContext.ResolveSubresource(colorBuffer, 0, renderTargetNMS, 0, Format.B8G8R8A8_UNorm); surfaceD3D.SetRenderTargetDX11(renderTargetNMS); #else this.surfaceD3D.SetRenderTargetDX11(this.colorBuffer); #endif }
/// <summary> /// /// </summary> public override void Detach() { Disposer.RemoveAndDispose(ref vTessellationVariables); Disposer.RemoveAndDispose(ref shaderPass); base.Detach(); }
protected override void OnDetach() { base.OnDetach(); instanceParamBuffer.Dispose(); Disposer.RemoveAndDispose(ref hasInstanceParamVar); }
protected override void OnDetach() { Disposer.RemoveAndDispose(ref this.bHasInstances); instanceBuffer.Dispose(); base.OnDetach(); }