예제 #1
0
        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.updateddevices.Contains(context)) { return; }
            if (reset || !this.FOutGeom[0].Contains(context))
            {
                this.DisposeBuffers(context);

                // int vsize = customlayout ? size : ig.VertexSize;
                SlimDX.Direct3D11.Buffer vbo = BufferHelper.CreateStreamOutBuffer(context, vsize, this.cnt);

                //Copy a new Vertex buffer with stream out
                DX11VertexGeometry vg = new DX11VertexGeometry(context);
                vg.AssignDrawer(new DX11VertexAutoDrawer());
                vg.HasBoundingBox = false;
                vg.InputLayout = this.FInLayout.ToArray();
                vg.Topology = PrimitiveTopology.TriangleList;
                vg.VertexBuffer = vbo;
                vg.VertexSize = vsize;
                vg.VerticesCount = this.cnt;

                this.buffer = vbo;

                this.FOutGeom[0][context] = vg;

                if (context.ComputeShaderSupport)
                {
                    this.FOutBuffer[0][context] = new DX11RawBuffer(context, vbo);
                }
                else
                {
                    this.FOutBuffer[0][context] = null;
                }
            }

            this.updateddevices.Add(context);
        }