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)); }
/// <summary> /// Creates a <see cref = "T:SharpDX.Direct3D10.ShaderResourceView" /> for accessing resource data. /// </summary> /// <param name = "device">The device to use when creating this <see cref = "T:SharpDX.Direct3D10.ShaderResourceView" />.</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">ShaderResource</see> flag.</param> /// <param name = "description">A structure describing the <see cref = "T:SharpDX.Direct3D10.ShaderResourceView" /> to be created.</param> /// <unmanaged>ID3D10Device::CreateShaderResourceView</unmanaged> public ShaderResourceView(Device device, Resource resource, ShaderResourceViewDescription description) : base(IntPtr.Zero) { device.CreateShaderResourceView(resource, description, this); }
void videoPanelViewModel_VideoOpened(Object sender, EventArgs e) { for (int i = 0; i < nrTextures; i++) { Disposer.RemoveAndDispose(ref this.yuvTexture[i]); Disposer.RemoveAndDispose(ref this.textureView[i]); } if (videoPlayerViewModel.DecodedVideoFormat == VideoLib.VideoPlayer.DecodedVideoFormat.YUV420P) { int width = videoPlayerViewModel.Width; int height = videoPlayerViewModel.Height; yuvTexture[0] = createTexture(width, height, Format.R8_UNorm); yuvTexture[1] = createTexture(width / 2, height / 2, Format.R8_UNorm); yuvTexture[2] = createTexture(width / 2, height / 2, Format.R8_UNorm); nrTextures = 3; } else { yuvTexture[0] = createTexture(videoPlayerViewModel.Width, videoPlayerViewModel.Height, Format.B8G8R8A8_UNorm); nrTextures = 1; } Device device = Host.Device; for (int i = 0; i < nrTextures; i++) { ShaderResourceViewDescription desc = new ShaderResourceViewDescription(); desc.Format = yuvTexture[i].Description.Format; desc.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D; desc.Texture2D.MipLevels = yuvTexture[i].Description.MipLevels; desc.Texture2D.MostDetailedMip = yuvTexture[i].Description.MipLevels - 1; textureView[i] = new ShaderResourceView(device, yuvTexture[i], desc); } viewport = setupViewport(videoPlayerViewModel.Width, videoPlayerViewModel.Height); device.Flush(); DPFCanvas canvas = (DPFCanvas)Host; canvas.StartRendering(); }