Browse Source

Fix bug view/proj matrices in scene not in sync with the ubo

Popov72 4 years ago
parent
commit
7166f1ffc3
2 changed files with 14 additions and 1 deletions
  1. 5 0
      src/Materials/uniformBuffer.ts
  2. 9 1
      src/scene.ts

+ 5 - 0
src/Materials/uniformBuffer.ts

@@ -536,6 +536,11 @@ export class UniformBuffer {
         return this._buffers.length;
     }
 
+    /** @hidden */
+    public get _indexBuffer(): number {
+        return this._bufferIndex;
+    }
+
     public get name(): string {
         return this._name;
     }

+ 9 - 1
src/scene.ts

@@ -2005,11 +2005,19 @@ export class Scene extends AbstractScene implements IAnimatable, IClipPlanesHold
      */
     public setTransformMatrix(viewL: Matrix, projectionL: Matrix, viewR?: Matrix, projectionR?: Matrix): void {
         if (ThinEngine.Features.trackUbosInFrame) {
+            const indexBufferBefore = this._sceneUbo._indexBuffer;
             const viewLUpdateFlag = this._sceneUbo._getMatrixUpdateFlagFromCache("view");
             const projectionLUpdateFlag = this._sceneUbo._getMatrixUpdateFlagFromCache("projection");
+            const indexBufferAfter = this._sceneUbo._indexBuffer;
 
             if (viewLUpdateFlag === viewL.updateFlag && projectionLUpdateFlag === projectionL.updateFlag) {
-                return;
+                if (indexBufferAfter === indexBufferBefore) {
+                    return;
+                } else {
+                    // fall through
+                    // indexBufferAfter !== indexBufferBefore means we have cycled to the first buffer (because of a frame id change): this buffer is in line with
+                    // the matrices passed to setTransformMatrix but the matrices saved in the scene are (may) not (be) ok, we must update them
+                }
             }
         } else if (this._viewUpdateFlag === viewL.updateFlag && this._projectionUpdateFlag === projectionL.updateFlag) {
             return;