Browse Source

Merge pull request #9283 from Popov72/improve-perf-dynamic-buffer

Improve performances when using dynamic vertex update
Raanan Weber 4 years ago
parent
commit
d370f1e6c5
1 changed files with 4 additions and 0 deletions
  1. 4 0
      src/Meshes/geometry.ts

+ 4 - 0
src/Meshes/geometry.ts

@@ -236,6 +236,10 @@ export class Geometry implements IGetSetVerticesData {
      * @param stride defines the stride to use (0 by default). This value is deduced from the kind value if not specified
      */
     public setVerticesData(kind: string, data: FloatArray, updatable: boolean = false, stride?: number): void {
+        if (updatable && Array.isArray(data)) {
+            // to avoid converting to Float32Array at each draw call in engine.updateDynamicVertexBuffer, we make the conversion a single time here
+            data = new Float32Array(data);
+        }
         var buffer = new VertexBuffer(this._engine, data, kind, updatable, this._meshes.length === 0, stride);
         this.setVerticesBuffer(buffer);
     }