public void Apply(DX11Texture2D texture, int w, int h, int d, SlimDX.DXGI.Format format, int slice) { format = format == SlimDX.DXGI.Format.Unknown ? texture.Format : format; if (this.rtarr != null) { if (this.rtarr.ElemCnt != d || this.rtarr.Width != w || this.rtarr.Height != h || this.rtarr.Format != format) { this.rtarr.Dispose(); this.rtarr = null; } } if (this.rtarr == null) { this.rtarr = new DX11RenderTextureArray(this.context, w, h, d, format, true, 1); } this.shader.SelectTechnique("Render"); this.quad.Bind(this.layout); int idx = VMath.Zmod(slice, d); //Push specific slice as render target this.context.RenderTargetStack.Push(this.rtarr.SliceRTV[idx]); //Call simple shader (could use full screen triangle instead) this.shader.SetBySemantic("TEXTURE", texture.SRV); this.shader.ApplyPass(0); this.quad.Draw(); this.context.RenderTargetStack.Pop(); }
public void Update(DX11RenderContext context) { Device device = context.Device; if (this.spmax == 0) { return; } if (this.updateddevices.Contains(context)) { return; } if (!this.FOutTexture[0].Contains(context)) { var result = new DX11RenderTextureArray(context, (int)this.FInSize[0].X, (int)this.FInSize[0].Y, this.FInElementCount[0], DeviceFormatHelper.GetFormat(this.FInFormat[0]), true, this.FInMips[0] ? 0 : 1, this.FInAllowUAV[0]); this.FOutTexture[0][context] = result; this.FOutDepthTexture[0][context] = new DX11DepthTextureArray(context, (int)this.FInSize[0].X, (int)this.FInSize[0].Y, this.FInElementCount[0], Format.R32_Float, true); for (int i = 0; i < this.FInElementCount[0]; i++) { DX11Texture2D slice = DX11Texture2D.FromTextureAndSRV(context, result.Resource, result.SliceRTV[i].SRV); this.FOutSliceTextures[i][context] = slice; } } this.updateddevices.Add(context); }
public void CreateSimple() { DX11RenderTextureArray array = new DX11RenderTextureArray(this.Device, 256, 256, 4, Format.R8G8B8A8_UNorm, false); Assert.IsNotNull(array.RenderView); Assert.IsNotNull(array.ShaderView); Assert.IsNull(array.Slices); array.Dispose(); }
private void WriteResult(TextureArraySetSlice generator, DX11RenderContext context) { DX11RenderTextureArray result = generator.Result; this.FOutTB[0][context] = generator.Result; for (int i = 0; i < this.FOutSliceTextures.SliceCount; i++) { DX11Texture2D slice = DX11Texture2D.FromTextureAndSRV(context, result.Resource, result.SliceRTV[i].SRV); this.FOutSliceTextures[i][context] = slice; } }
public void CreateWithSlices() { int slicecount = 4; DX11RenderTextureArray array = new DX11RenderTextureArray(this.Device, 256, 256, slicecount, Format.R8G8B8A8_UNorm, true); Assert.IsNotNull(array.RenderView); Assert.IsNotNull(array.ShaderView); Assert.IsNotNull(array.Slices); Assert.AreEqual(slicecount, array.Slices.Length); array.Dispose(); }
public void Apply(DX11Resource <DX11RenderTextureArray> textureArray, ISpread <int> slices) { int w = textureArray[context].Width; int h = textureArray[context].Height; int d = slices.SliceCount; Format f = textureArray[context].Format; Texture2DDescription descIn = textureArray[context].Resource.Description; // check if parameters match - if not, create a new rt array if (this.rtarr != null) { if (this.rtarr.ElemCnt != d || this.rtarr.Width != w || this.rtarr.Height != h || this.rtarr.Description.MipLevels != descIn.MipLevels || this.rtarr.Format != f) { this.rtarr.Dispose(); this.rtarr = null; } } if (this.rtarr == null) { this.rtarr = new DX11RenderTextureArray(this.context, w, h, d, f, true, descIn.MipLevels); } // copy the ressources over for (int i = 0; i < slices.SliceCount; i++) { int slice = VMath.Zmod(slices[i], textureArray[context].ElemCnt); SlimDX.Direct3D11.Resource source = textureArray[context].Resource; for (int mip = 0; mip < descIn.MipLevels; mip++) { //int mip = 0; int sourceSubres = SlimDX.Direct3D11.Texture2D.CalculateSubresourceIndex(mip, slice, descIn.MipLevels); int destinationSubres = SlimDX.Direct3D11.Texture2D.CalculateSubresourceIndex(mip, i, descIn.MipLevels); context.CurrentDeviceContext.CopySubresourceRegion(source, sourceSubres, this.rtarr.Resource, destinationSubres, 0, 0, 0); } } }
public void Render(DX11RenderContext context) { Device device = context.Device; //Just in case if (!this.updateddevices.Contains(context)) { this.Update(context); } if (this.rendereddevices.Contains(context)) { return; } if (this.FInEnabled[0]) { if (this.BeginQuery != null) { this.BeginQuery(context); } DX11RenderTextureArray target = this.FOutTexture[0][context]; DX11DepthTextureArray depth = this.FOutDepthTexture[0][context]; if (this.FInClear[0]) { context.CurrentDeviceContext.ClearRenderTargetView(target.RTV, this.FInBgColor[0]); if (this.FInDepthBuffer[0]) { context.CurrentDeviceContext.ClearDepthStencilView(depth.DSV, DepthStencilClearFlags.Depth, 1.0f, 0); } } if (this.FInLayer.IsConnected) { int slicecount = target.ElemCnt; if (this.FInBindTarget[0]) { if (this.FInDepthBuffer[0]) { context.RenderTargetStack.Push(depth, false, target); } else { context.RenderTargetStack.Push(target); } slicecount = 1; } for (int i = 0; i < slicecount; i++) { settings.ViewportIndex = i; settings.ViewportCount = target.ElemCnt; settings.ApplyTransforms(this.FInView[i], this.FInProjection[i], this.FInAspect[i], this.FInCrop[i]); settings.RenderWidth = target.Width; settings.RenderHeight = target.Height; settings.RenderDepth = target.ElemCnt; settings.BackBuffer = target; settings.CustomSemantics.Clear(); settings.ResourceSemantics.Clear(); if (this.FInBindTarget[0] == false) { if (this.FInDepthBuffer[0]) { context.RenderTargetStack.Push(depth.SliceDSV[i], false, target.SliceRTV[i]); } else { context.RenderTargetStack.Push(target.SliceRTV[i]); } } this.FInLayer.RenderAll(context, settings); if (this.FInBindTarget[0] == false) { context.RenderTargetStack.Pop(); } } if (this.FInBindTarget[0]) { context.RenderTargetStack.Pop(); } if (this.FInMips[0]) { context.CurrentDeviceContext.GenerateMips(this.FOutTexture[0][context].SRV); } } if (this.EndQuery != null) { this.EndQuery(context); } this.rendereddevices.Add(context); } }
public void Reset(DX11Texture2D texture, int w, int h, int d, SlimDX.DXGI.Format format) { format = format == SlimDX.DXGI.Format.Unknown ? texture.Format : format; this.rtarr.Dispose(); this.rtarr = new DX11RenderTextureArray(this.context, w, h, d, format, true, 1); }
public void Render(DX11RenderContext context) { Device device = context.Device; //Just in case if (!this.updateddevices.Contains(context)) { this.Update(null, context); } if (this.rendereddevices.Contains(context)) { return; } if (this.FInEnabled[0]) { if (this.BeginQuery != null) { this.BeginQuery(context); } DX11RenderTextureArray target = this.FOutTexture[0][context]; DX11DepthTextureArray depth = this.FOutDepthTexture[0][context]; if (this.FInClear[0]) { context.CurrentDeviceContext.ClearRenderTargetView(target.RTV, this.FInBgColor[0]); if (this.FInDepthBuffer[0]) { context.CurrentDeviceContext.ClearDepthStencilView(depth.DSV, DepthStencilClearFlags.Depth, 1.0f, 0); } } if (this.FInLayer.PluginIO.IsConnected) { for (int i = 0; i < target.ElemCnt; i++) { settings.ViewportIndex = i; settings.ViewportCount = target.ElemCnt; settings.View = this.FInView[i]; Matrix proj = this.FInProjection[i]; Matrix aspect = Matrix.Invert(this.FInAspect[i]); Matrix crop = Matrix.Invert(this.FInCrop[i]); settings.Projection = proj * aspect * crop; settings.ViewProjection = settings.View * settings.Projection; settings.RenderWidth = target.Width; settings.RenderHeight = target.Height; settings.RenderDepth = target.ElemCnt; settings.BackBuffer = null; settings.CustomSemantics.Clear(); settings.ResourceSemantics.Clear(); if (this.FInDepthBuffer[0]) { context.RenderTargetStack.Push(depth.SliceDSV[i], false, target.SliceRTV[i]); } else { context.RenderTargetStack.Push(target.SliceRTV[i]); } for (int j = 0; j < this.FInLayer.SliceCount; j++) { try { this.FInLayer[j][context].Render(this.FInLayer.PluginIO, context, settings); } catch (Exception ex) { Console.WriteLine(ex.Message); } } context.RenderTargetStack.Pop(); } } if (this.EndQuery != null) { this.EndQuery(context); } this.rendereddevices.Add(context); } }
private void WriteResult(CopySubArray generator, DX11RenderContext context) { DX11RenderTextureArray result = generator.Result; this.FTextureOutput[0][context] = generator.Result; }