Example #1
0
        private void InitialiseBuffer()
        {
            // dispose exiting buffers
            if (this.vertices != null)
            {
                this.vertices.Dispose();
            }
            if (this.indices != null)
            {
                this.indices.Dispose();
            }

            // create new vertex buffer
            this.vertices = new DynamicVertexBuffer(device, ParticleVertex.VertexDeclaration, Capacity * 4, BufferUsage.WriteOnly);

            // set up quad corners
            var particles = new ParticleVertex[Capacity * 4];

            for (int i = 0; i < Capacity; i++)
            {
                particles[i * 4 + 0].Corner = new Short2(-1, -1);
                particles[i * 4 + 1].Corner = new Short2(1, -1);
                particles[i * 4 + 2].Corner = new Short2(1, 1);
                particles[i * 4 + 3].Corner = new Short2(-1, 1);
            }

            // copy over any exiting active particles
            int j = 0;

            for (int i = active * 4; i != free * 4; i = (i + 1) % particles.Length)
            {
                particles[j] = this.particles[i];
                j++;
            }

            // swap array over to the new larger array
            this.particles = particles;

            // create new index buffer
            ushort[] indices = new ushort[Capacity * 6];
            for (int i = 0; i < Capacity; i++)
            {
                indices[i * 6 + 0] = (ushort)(i * 4 + 0);
                indices[i * 6 + 1] = (ushort)(i * 4 + 1);
                indices[i * 6 + 2] = (ushort)(i * 4 + 2);

                indices[i * 6 + 3] = (ushort)(i * 4 + 0);
                indices[i * 6 + 4] = (ushort)(i * 4 + 2);
                indices[i * 6 + 5] = (ushort)(i * 4 + 3);
            }

            this.indices = new IndexBuffer(device, typeof(ushort), indices.Length, BufferUsage.WriteOnly);
            this.indices.SetData(indices);

            dirty = false;
        }
Example #2
0
        private void InitialiseBuffer()
        {
            // dispose exiting buffers
            if (this.vertices != null)
                this.vertices.Dispose();
            if (this.indices != null)
                this.indices.Dispose();

            // create new vertex buffer
            this.vertices = new DynamicVertexBuffer(device, ParticleVertex.VertexDeclaration, Capacity * 4, BufferUsage.WriteOnly);

            // set up quad corners
            var particles = new ParticleVertex[Capacity * 4];
            for (int i = 0; i < Capacity; i++)
            {
                particles[i * 4 + 0].Corner = new Short2(-1, -1);
                particles[i * 4 + 1].Corner = new Short2(1, -1);
                particles[i * 4 + 2].Corner = new Short2(1, 1);
                particles[i * 4 + 3].Corner = new Short2(-1, 1);
            }

            // copy over any exiting active particles
            int j = 0;
            for (int i = active *4; i != free * 4; i = (i + 1) % particles.Length)
            {
                particles[j] = this.particles[i];
                j++;
            }

            // swap array over to the new larger array
            this.particles = particles;

            // create new index buffer
            ushort[] indices = new ushort[Capacity * 6];
            for (int i = 0; i < Capacity; i++)
            {
                indices[i * 6 + 0] = (ushort)(i * 4 + 0);
                indices[i * 6 + 1] = (ushort)(i * 4 + 1);
                indices[i * 6 + 2] = (ushort)(i * 4 + 2);

                indices[i * 6 + 3] = (ushort)(i * 4 + 0);
                indices[i * 6 + 4] = (ushort)(i * 4 + 2);
                indices[i * 6 + 5] = (ushort)(i * 4 + 3);
            }

            this.indices = new IndexBuffer(device, typeof(ushort), indices.Length, BufferUsage.WriteOnly);
            this.indices.SetData(indices);

            dirty = false;
        }