From c0465b73a87a8df5cd33eb0aa2425e9063446ad7 Mon Sep 17 00:00:00 2001 From: pspeed42 Date: Tue, 12 Aug 2014 03:11:43 -0400 Subject: [PATCH] Added a newFrame() method to UniformBindingManager to signal the beginning of a frame. Currently this just grabs the time and tpf values once so as to avoid per-material Float allocation and time drift within a frame. RenderManager now calls this at the beginning of the root-level render() method. --- .../java/com/jme3/renderer/RenderManager.java | 1 + .../com/jme3/shader/UniformBindingManager.java | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/renderer/RenderManager.java b/jme3-core/src/main/java/com/jme3/renderer/RenderManager.java index 8677f7322..1dfc6e0a3 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/RenderManager.java +++ b/jme3-core/src/main/java/com/jme3/renderer/RenderManager.java @@ -1035,6 +1035,7 @@ public class RenderManager { } this.shader = renderer.getCaps().contains(Caps.GLSL100); + uniformBindingManager.newFrame(); for (int i = 0; i < preViewPorts.size(); i++) { ViewPort vp = preViewPorts.get(i); diff --git a/jme3-core/src/main/java/com/jme3/shader/UniformBindingManager.java b/jme3-core/src/main/java/com/jme3/shader/UniformBindingManager.java index 9bcd24448..d194caad3 100644 --- a/jme3-core/src/main/java/com/jme3/shader/UniformBindingManager.java +++ b/jme3-core/src/main/java/com/jme3/shader/UniformBindingManager.java @@ -51,7 +51,8 @@ import java.util.List; public class UniformBindingManager { private Timer timer; - private float near, far; + private Float near, far; + private Float time, tpf; private int viewX, viewY, viewWidth, viewHeight; private Vector3f camUp = new Vector3f(), camLeft = new Vector3f(), @@ -196,10 +197,10 @@ public class UniformBindingManager { u.setValue(VarType.Vector3, camUp); break; case Time: - u.setValue(VarType.Float, timer.getTimeInSeconds()); + u.setValue(VarType.Float, time); break; case Tpf: - u.setValue(VarType.Float, timer.getTimePerFrame()); + u.setValue(VarType.Float, tpf); break; case FrameRate: u.setValue(VarType.Float, timer.getFrameRate()); @@ -251,4 +252,15 @@ public class UniformBindingManager { this.viewWidth = viewWidth; this.viewHeight = viewHeight; } + + /** + * Internal use only. Called by the RenderManager at the beginning of a + * new application frame. + */ + public void newFrame() { + // Avoid per-material Float allocations and lock in the + // time for this frame to avoid inter-frame drift. + time = timer.getTimeInSeconds(); + tpf = timer.getTimePerFrame(); + } }