Example #1
0
        public static void Render(GraphicsDevice device, Effect effect, bool delete)
        {
            BlendState origBlen = device.BlendState;

            device.BlendState = BlendState.AlphaBlend;

            RasterizerState newState = RasterizerState.CullNone;
            RasterizerState oldState = device.RasterizerState;

            device.RasterizerState = newState;

            effect.CurrentTechnique = effect.Techniques["Untextured"];
            effect.Parameters["xWorld"].SetValue(Matrix.Identity);

            DrawCommand3D.LineStrip strips = new DrawCommand3D.LineStrip()
            {
                Vertices = new List <VertexPositionColor>()
            };
            foreach (DrawCommand3D command in Commands)
            {
                command.AccumulateStrips(strips);
            }

            if (strips.Vertices.Count > 0 && strips.NumTriangles > 0)
            {
                foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    device.DrawUserPrimitives(PrimitiveType.TriangleStrip, strips.Vertices.ToArray(), 0, Math.Min(strips.Vertices.Count - 2, short.MaxValue));
                }
            }


            effect.CurrentTechnique = effect.Techniques["Textured"];

            if (oldState != null)
            {
                device.RasterizerState = oldState;
            }

            if (origBlen != null)
            {
                device.BlendState = origBlen;
            }


            if (!delete)
            {
                return;
            }

            while (Commands.Count > 0)
            {
                DrawCommand3D result = null;
                Commands.TryTake(out result);
            }
        }
Example #2
0
        public static void Render(GraphicsDevice device, Shader effect, bool delete)
        {
            BlendState origBlen = device.BlendState;

            device.BlendState = BlendState.NonPremultiplied;

            RasterizerState newState = RasterizerState.CullNone;
            RasterizerState oldState = device.RasterizerState;

            device.RasterizerState = newState;

            effect.CurrentTechnique = effect.Techniques[Shader.Technique.Untextured];
            effect.World            = Matrix.Identity;


            DrawCommand3D.LineStrip strips = new DrawCommand3D.LineStrip()
            {
                Vertices = new List <VertexPositionColor>()
            };
            foreach (DrawCommand3D command in Commands)
            {
                if (command.DrawAccumlatedStrips)
                {
                    command.AccumulateStrips(strips);
                }
            }

            if (strips.Vertices.Count > 0 &&
                (StripVertices == null ||
                 strips.Vertices.Count > StripVertices.Count()))
            {
                StripVertices = new VertexPositionColor[strips.Vertices.Count * 2];
                StripBuffer   = new DynamicVertexBuffer(device, VertexPositionColor.VertexDeclaration, strips.Vertices.Count * 2, BufferUsage.WriteOnly);
            }

            if (strips.Vertices.Count > 0)
            {
                strips.Vertices.CopyTo(StripVertices);
                MaxStripVertex = strips.Vertices.Count;

                if (MaxStripVertex > 0 && StripBuffer != null)
                {
                    StripBuffer.SetData(StripVertices, 0, MaxStripVertex);
                    foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                    {
                        pass.Apply();
                        device.SetVertexBuffer(StripBuffer);
                        device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, strips.Vertices.Count - 2);
                    }
                }
            }

            effect.CurrentTechnique = effect.Techniques[Shader.Technique.Textured];

            foreach (DrawCommand3D command in Commands)
            {
                if (!command.DrawAccumlatedStrips)
                {
                    command.Render(device, effect);
                }
            }

            if (oldState != null)
            {
                device.RasterizerState = oldState;
            }

            if (origBlen != null)
            {
                device.BlendState = origBlen;
            }


            if (!delete)
            {
                return;
            }

            while (Commands.Count > 0)
            {
                DrawCommand3D result = null;
                Commands.TryTake(out result);
            }
        }