public void Update(DX11RenderContext context) { for (int i = 0; i < this.FIn.SliceCount; i++) { IDX11Geometry geom = this.FIn[i][context]; if (geom is DX11IndexedGeometry) { DX11IndexedGeometry g = (DX11IndexedGeometry)geom; this.FOutBuffer[i][context] = g.IndexBuffer; this.FOutValid[i] = true; } else if (geom is DX11IndexOnlyGeometry) { DX11IndexOnlyGeometry g = (DX11IndexOnlyGeometry)geom; this.FOutBuffer[i][context] = g.IndexBuffer; this.FOutValid[i] = true; } else { this.FOutBuffer[i][context] = null; this.FOutValid[i] = false; } } }
private void BuildBuffer(DX11RenderContext context,int[] data, Pin<DX11Resource<DX11IndexOnlyGeometry>> respin) { DX11IndexOnlyGeometry geom = new DX11IndexOnlyGeometry(context); geom.HasBoundingBox = false; geom.Topology = PrimitiveTopology.LineList; geom.InputLayout = new InputElement[0]; var indexstream = new DataStream(data.Length * 4, true, true); indexstream.WriteRange(data); indexstream.Position = 0; geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); respin[0][context] = geom; }
public void Update(IPluginIO pin, DX11RenderContext context) { if (this.CalculateSpreadMax() == 0) { return; } Device device = context.Device; DeviceContext ctx = context.CurrentDeviceContext; if (!this.deviceshaderdata.ContainsKey(context)) { this.deviceshaderdata.Add(context, new DX11ShaderData(context)); this.deviceshaderdata[context].SetEffect(this.FShader); } DX11ShaderData shaderdata = this.deviceshaderdata[context]; if (this.shaderupdated) { shaderdata.SetEffect(this.FShader); shaderdata.Update(this.FInTechnique[0].Index, 0, this.FIn); this.shaderupdated = false; } if (this.FInEnabled[0] && this.FIn.PluginIO.IsConnected) { //Clear shader stages (important here) shaderdata.ResetShaderStages(ctx); if (this.FIn.IsChanged || this.FInTechnique.IsChanged || shaderdata.LayoutValid.Count == 0) { shaderdata.Update(this.FInTechnique[0].Index, 0, this.FIn); } if (shaderdata.IsLayoutValid(0) && this.varmanager.SetGlobalSettings(shaderdata.ShaderInstance, this.settings)) { this.OnBeginQuery(context); this.settings = new DX11RenderSettings(); this.settings.RenderWidth = 1; this.settings.RenderHeight = 1; this.settings.View = this.FInView[0]; this.settings.Projection = this.FInProjection[0]; this.settings.ViewProjection = this.settings.View * this.settings.Projection; this.settings.RenderDepth = 1; this.settings.BackBuffer = null; if (this.FInSemantics.PluginIO.IsConnected) { this.settings.CustomSemantics.AddRange(this.FInSemantics.ToArray()); } if (this.FInResSemantics.PluginIO.IsConnected) { this.settings.ResourceSemantics.AddRange(this.FInResSemantics.ToArray()); } this.varmanager.ApplyGlobal(shaderdata.ShaderInstance); if (this.clone == null || this.FIn.IsChanged || this.FInAsAuto.IsChanged || this.FInMaxElements.IsChanged || this.FInLayout.IsChanged || this.FInAutoLayout.IsChanged) { if (this.buffer != null) { this.buffer.Dispose(); } bool customlayout = this.FInLayout.PluginIO.IsConnected || this.FInAutoLayout[0]; InputElement[] elems = null; int size = 0; if (this.FInAutoLayout[0]) { elems = this.FShader.DefaultEffect.GetTechniqueByIndex(tid).GetPassByIndex(0).GetStreamOutputLayout(out size); } else { if (customlayout) { elems = this.BindInputLayout(out size); } } #region Vertex Geom if (this.FIn[0][context] is DX11VertexGeometry) { if (!this.FInAsAuto[0]) { DX11VertexGeometry vg = (DX11VertexGeometry)this.FIn[0][context].ShallowCopy(); int vsize = customlayout ? size : vg.VertexSize; Buffer vbo = BufferHelper.CreateStreamOutBuffer(context, vsize, vg.VerticesCount); if (customlayout) { vg.VertexSize = vsize; } vg.VertexBuffer = vbo; this.clone = vg; this.buffer = vbo; } else { DX11VertexGeometry vg = (DX11VertexGeometry)this.FIn[0][context].ShallowCopy(); int maxv = vg.VerticesCount; if (this.FInMaxElements[0] > 0) { maxv = this.FInMaxElements[0]; } int vsize = customlayout ? size : vg.VertexSize; Buffer vbo = BufferHelper.CreateStreamOutBuffer(context, vsize, maxv); vg.VertexBuffer = vbo; vg.AssignDrawer(new DX11VertexAutoDrawer()); if (customlayout) { vg.VertexSize = vsize; } this.clone = vg; this.buffer = vbo; } } #endregion #region Inxexed geom if (this.FIn[0][context] is DX11IndexedGeometry) { if (!this.FInAsAuto[0]) { DX11IndexedGeometry ig = (DX11IndexedGeometry)this.FIn[0][context].ShallowCopy(); int vsize = customlayout ? size : ig.VertexSize; Buffer vbo = BufferHelper.CreateStreamOutBuffer(context, vsize, ig.VerticesCount); ig.VertexBuffer = vbo; if (customlayout) { ig.VertexSize = vsize; } this.clone = ig; this.buffer = vbo; } else { //Need to rebind indexed geom as vertex DX11IndexedGeometry ig = (DX11IndexedGeometry)this.FIn[0][context]; int maxv = ig.VerticesCount; if (this.FInMaxElements[0] > 0) { maxv = this.FInMaxElements[0]; } int vsize = customlayout ? size : ig.VertexSize; Buffer vbo = BufferHelper.CreateStreamOutBuffer(context, vsize, maxv); //Copy a new Vertex buffer with stream out DX11VertexGeometry vg = new DX11VertexGeometry(context); vg.AssignDrawer(new DX11VertexAutoDrawer()); vg.BoundingBox = ig.BoundingBox; vg.HasBoundingBox = ig.HasBoundingBox; vg.InputLayout = ig.InputLayout; vg.Topology = ig.Topology; vg.VertexBuffer = vbo; vg.VertexSize = ig.VertexSize; vg.VerticesCount = ig.VerticesCount; if (customlayout) { vg.VertexSize = vsize; } this.clone = vg; this.buffer = vbo; } } #endregion #region Null geom if (this.FIn[0][context] is DX11NullGeometry) { DX11NullGeometry ng = (DX11NullGeometry)this.FIn[0][context]; Buffer vbo = BufferHelper.CreateStreamOutBuffer(context, size, this.FInMaxElements[0]); //Copy a new Vertex buffer with stream out DX11VertexGeometry vg = new DX11VertexGeometry(context); vg.AssignDrawer(new DX11VertexAutoDrawer()); vg.BoundingBox = ng.BoundingBox; vg.HasBoundingBox = ng.HasBoundingBox; vg.InputLayout = ng.InputLayout; vg.Topology = ng.Topology; vg.VertexBuffer = vbo; vg.VertexSize = size; vg.VerticesCount = this.FInMaxElements[0]; this.clone = vg; this.buffer = vbo; } #endregion #region Index Only geom if (this.FIn[0][context] is DX11IndexOnlyGeometry) { DX11IndexOnlyGeometry ng = (DX11IndexOnlyGeometry)this.FIn[0][context]; Buffer vbo = BufferHelper.CreateStreamOutBuffer(context, size, this.FInMaxElements[0]); //Copy a new Vertex buffer with stream out DX11VertexGeometry vg = new DX11VertexGeometry(context); vg.AssignDrawer(new DX11VertexAutoDrawer()); vg.BoundingBox = ng.BoundingBox; vg.HasBoundingBox = ng.HasBoundingBox; vg.InputLayout = ng.InputLayout; vg.Topology = ng.Topology; vg.VertexBuffer = vbo; vg.VertexSize = size; vg.VerticesCount = this.FInMaxElements[0]; this.clone = vg; this.buffer = vbo; } #endregion if (customlayout) { this.clone.InputLayout = elems; } if (this.FOutBuffer[0][context] != null) { this.FOutBuffer[0][context].SRV.Dispose(); } if (context.ComputeShaderSupport) { this.FOutBuffer[0][context] = new DX11RawBuffer(context, this.buffer); } else { this.FOutBuffer[0][context] = null; } } ctx.StreamOutput.SetTargets(new StreamOutputBufferBinding(this.buffer, 0)); shaderdata.SetInputAssembler(ctx, this.FIn[0][context], 0); DX11ObjectRenderSettings ors = new DX11ObjectRenderSettings(); ors.DrawCallIndex = 0; ors.Geometry = this.FIn[0][context]; ors.WorldTransform = Matrix.Identity; this.varmanager.ApplyPerObject(context, shaderdata.ShaderInstance, ors, 0); shaderdata.ApplyPass(ctx); this.FIn[0][context].Draw(); ctx.StreamOutput.SetTargets(null); this.FOut[0][context] = this.clone; this.OnEndQuery(context); } else { this.FOut[0][context] = this.FIn[0][context]; } } else { this.FOut[0][context] = this.FIn[0][context]; } }
public void Update(IPluginIO pin, DX11RenderContext context) { if (this.FInvalidate || this.FEmpty) { for (int i = 0; i < this.scenes.Count; i++) { if (scenes[i] != null) { AssimpScene scene = scenes[i]; for (int j = 0; j < scene.MeshCount; j++) { AssimpMesh assimpmesh = scene.Meshes[j]; List <int> inds = assimpmesh.Indices; if (inds.Count > 0 && assimpmesh.VerticesCount > 0) { var indexstream = new DataStream(inds.Count * 4, true, true); indexstream.WriteRange(inds.ToArray()); indexstream.Position = 0; DX11IndexOnlyGeometry geom = new DX11IndexOnlyGeometry(context); geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.InputLayout = assimpmesh.GetInputElements().ToArray(); geom.Topology = PrimitiveTopology.TriangleList; geom.HasBoundingBox = true; geom.BoundingBox = assimpmesh.BoundingBox; DX11DynamicStructuredBuffer <Vector3> p = new DX11DynamicStructuredBuffer <Vector3>(context, assimpmesh.PositionPointer, assimpmesh.VerticesCount); DX11DynamicStructuredBuffer <Vector3> n = new DX11DynamicStructuredBuffer <Vector3>(context, assimpmesh.NormalsPointer, assimpmesh.VerticesCount); if (assimpmesh.UvChannelCount > 0) { DX11DynamicStructuredBuffer <Vector3> u = new DX11DynamicStructuredBuffer <Vector3>(context, assimpmesh.GetUvPointer(0), assimpmesh.VerticesCount); this.FOutUvs[i][j][context] = u; } DX11RawBuffer rb = new DX11RawBuffer(context, geom.IndexBuffer.Buffer); this.FOutPosition[i][j][context] = p; this.FOutNormals[i][j][context] = n; this.FOutGeom[i][j][context] = geom; this.FOutIndices[i][j][context] = rb; } } } } this.FInvalidate = false; this.FEmpty = false; } }