예제 #1
0
        /// <summary>
        /// Add the renderable entity to the render list.
        /// </summary>
        public static void AddToRenderList(IRenderable renderable)
        {
            if (renderable.Mesh.Length <= 0)
            {
                return;
            }

            var vb = new DynamicVertexBuffer(Graphics.GraphicsDevice, typeof(VertexPositionColor), renderable.Mesh.Count(), BufferUsage.WriteOnly);

            // Set Tag for updating.
            if (renderable is SubChunk)
            {
                Chunk.Chunk c = ((SubChunk)renderable).Parent;
                vb.Tag = new Vector3(c.ChunkPosition.X, ((SubChunk)renderable).Index, c.ChunkPosition.Y);
            }

            vb.SetData <VertexPositionColor>(renderable.Mesh);

            RenderList.Add(vb);
        }
예제 #2
0
        public static void RemoveVertexBuffer(IRenderable renderable)
        {
            // Set Tag for updating.
            if (!(renderable is SubChunk))
            {
                return;
            }

            // Create new tag
            Chunk.Chunk c   = ((SubChunk)renderable).Parent;
            Vector3     tag = new Vector3(c.ChunkPosition.X, ((SubChunk)renderable).Index, c.ChunkPosition.Y);

            // Find buffer to udpate
            DynamicVertexBuffer vb = RenderList.SingleOrDefault(b => b.Tag != null && (Vector3)b.Tag == tag);

            // Check if not null
            if (vb is null)
            {
                return;
            }

            vb.Dispose();
            RenderList.Remove(vb);
        }
예제 #3
0
        public static void UpdateVertexBuffer(IRenderable renderable)
        {
            // Set Tag for updating.
            if (!(renderable is SubChunk))
            {
                return;
            }

            // Create new tag
            Chunk.Chunk c   = ((SubChunk)renderable).Parent;
            Vector3     tag = new Vector3(c.ChunkPosition.X, ((SubChunk)renderable).Index, c.ChunkPosition.Y);

            // Find buffer to udpate
            DynamicVertexBuffer vb = RenderList.SingleOrDefault(b => b.Tag != null && (Vector3)b.Tag == tag);

            // Check if not null
            if (vb is null)
            {
                return;
            }

            if (renderable.Mesh.Length < 1)
            {
                return;
            }

            // add the updated one.
            var nvb = new DynamicVertexBuffer(Graphics.GraphicsDevice, typeof(VertexPositionColor), renderable.Mesh.Count(), BufferUsage.WriteOnly)
            {
                Tag = tag
            };

            nvb.SetData(renderable.Mesh);

            RenderList[RenderList.IndexOf(vb)] = nvb;
        }