/// <summary> /// Creates a <see cref = "T:SharpDX.Direct3D10.DepthStencilView" /> for accessing resource data. /// </summary> /// <param name = "device">The device to use when creating this <see cref = "T:SharpDX.Direct3D10.DepthStencilView" />.</param> /// <param name = "resource">The resource that represents the render-target surface. This surface must have been created with the <see cref = "T:SharpDX.Direct3D10.BindFlags">DepthStencil</see> flag.</param> /// <param name = "description">A structure describing the <see cref = "T:SharpDX.Direct3D10.DepthStencilView" /> to be created.</param> /// <unmanaged>ID3D10Device::CreateDepthStencilView</unmanaged> public DepthStencilView(Device device, Resource resource, DepthStencilViewDescription description) : base(IntPtr.Zero) { device.CreateDepthStencilView(resource, description, this); }
void CreateBuffers() { DisposeBuffers(); // New RenderTargetView from the backbuffer using (var bb = Texture2D.FromSwapChain<Texture2D>(_swapChain, 0)) { renderView = new RenderTargetView(_device, bb); renderViews[0] = renderView; } Texture2DDescription gBufferDesc = new Texture2DDescription() { ArraySize = 1, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = Format.R8G8B8A8_UNorm, Width = _width, Height = _height, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default }; gBufferLight = new Texture2D(_device, gBufferDesc); gBufferLightView = new RenderTargetView(_device, gBufferLight); gBufferNormal = new Texture2D(_device, gBufferDesc); gBufferNormalView = new RenderTargetView(_device, gBufferNormal); gBufferDiffuse = new Texture2D(_device, gBufferDesc); gBufferDiffuseView = new RenderTargetView(_device, gBufferDiffuse); gBufferViews = new RenderTargetView[] { gBufferLightView, gBufferNormalView, gBufferDiffuseView }; ShaderResourceViewDescription gBufferResourceDesc = new ShaderResourceViewDescription() { Format = Format.R8G8B8A8_UNorm, Dimension = ShaderResourceViewDimension.Texture2D, Texture2D = new ShaderResourceViewDescription.Texture2DResource() { MipLevels = 1, MostDetailedMip = 0 } }; lightBufferRes = new ShaderResourceView(_device, gBufferLight, gBufferResourceDesc); normalBufferRes = new ShaderResourceView(_device, gBufferNormal, gBufferResourceDesc); diffuseBufferRes = new ShaderResourceView(_device, gBufferDiffuse, gBufferResourceDesc); Texture2DDescription depthDesc = new Texture2DDescription() { ArraySize = 1, BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = Format.R32_Typeless, Width = _width, Height = _height, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default }; DepthStencilViewDescription depthViewDesc = new DepthStencilViewDescription() { Dimension = DepthStencilViewDimension.Texture2D, Format = Format.D32_Float, }; ShaderResourceViewDescription resourceDesc = new ShaderResourceViewDescription() { Format = Format.R32_Float, Dimension = ShaderResourceViewDimension.Texture2D, Texture2D = new ShaderResourceViewDescription.Texture2DResource() { MipLevels = 1, MostDetailedMip = 0 } }; depthTexture = new Texture2D(_device, depthDesc); depthView = new DepthStencilView(_device, depthTexture, depthViewDesc); depthRes = new ShaderResourceView(_device, depthTexture, resourceDesc); lightDepthTexture = new Texture2D(_device, depthDesc); lightDepthView = new DepthStencilView(_device, lightDepthTexture, depthViewDesc); lightDepthRes = new ShaderResourceView(_device, lightDepthTexture, resourceDesc); lightBufferVar = effect2.GetVariableByName("lightBuffer").AsShaderResource(); normalBufferVar = effect2.GetVariableByName("normalBuffer").AsShaderResource(); diffuseBufferVar = effect2.GetVariableByName("diffuseBuffer").AsShaderResource(); depthMapVar = effect2.GetVariableByName("depthMap").AsShaderResource(); lightDepthMapVar = effect2.GetVariableByName("lightDepthMap").AsShaderResource(); _device.Rasterizer.SetViewports(new Viewport(0, 0, _width, _height)); }