Esempio n. 1
0
        /// <summary>
        /// Creates the instancing buffer
        /// </summary>
        private void CreateInstancingBuffers()
        {
            int instances = this.TotalInstances;

            if (instances <= 0)
            {
                return;
            }

            this.instancingBufferOffset        = vertexBuffers.Count;
            this.instancingBufferBindingOffset = vertexBufferBindings.Count;

            var instancingData = new VertexInstancingData[instances];

            var buffer  = CreateInstancingBuffer(this.game.Graphics, instancingData);
            var binding = new VertexBufferBinding(buffer, instancingData[0].GetStride(), 0);

            this.vertexBuffers.Add(buffer);
            this.vertexBufferBindings.Add(binding);

            foreach (var item in this.vertexData)
            {
                if (item.Instances > 0)
                {
                    item.AddInstancingInputs(VertexInstancingData.Input(instancingBufferOffset));
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Reallocates the instance data
        /// </summary>
        private void ReallocateInstances()
        {
            int instances = this.TotalInstances;

            if (instances <= 0)
            {
                return;
            }

            //Dipose current buffer
            var instancingBuffer = this.vertexBuffers[this.vertexBuffers.Count - 1];

            instancingBuffer.Dispose();

            //Recreate the buffer and binding
            var data    = new VertexInstancingData[instances];
            var buffer  = CreateInstancingBuffer(game.Graphics, data);
            var binding = new VertexBufferBinding(buffer, data[0].GetStride(), 0);

            this.vertexBuffers[this.instancingBufferOffset] = buffer;
            this.vertexBufferBindings[this.instancingBufferBindingOffset] = binding;
        }