コード例 #1
0
        /// <summary>
        /// <see cref="PrepareForDraw"/> prepares and updates the Material, ShapeBuilder and VertexBuilder if necessary
        /// </summary>
        public void PrepareForDraw(out bool vertexBufferHasChanged, out int vertexSize, out int vertexCount)
        {
            var fieldsList = new ParticlePoolFieldsList(pool);

            // User changes to materials might cause vertex layout change
            Material.PrepareVertexLayout(fieldsList);

            // User changes to shape builders might cause vertex layout change
            ShapeBuilder.PrepareVertexLayout(fieldsList);

            // Recalculate the required vertex count and stride
            VertexBuilder.SetRequiredQuads(ShapeBuilder.QuadsPerParticle, pool.LivingParticles, pool.ParticleCapacity);

            vertexBufferHasChanged = (Material.HasVertexLayoutChanged || ShapeBuilder.VertexLayoutHasChanged || VertexBuilder.IsBufferDirty);

            // Update the vertex builder and the vertex layout if needed
            if (vertexBufferHasChanged)
            {
                VertexBuilder.ResetVertexElementList();

                Material.UpdateVertexBuilder(VertexBuilder);

                ShapeBuilder.UpdateVertexBuilder(VertexBuilder);

                VertexBuilder.UpdateVertexLayout();
            }

            vertexSize  = VertexBuilder.VertexDeclaration.CalculateSize();
            vertexCount = VertexBuilder.VertexCount;
            VertexBuilder.SetDirty(false);
        }