From cacfc6b71a2fba0cd904b5252265a28f123e2dab Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Sat, 14 May 2011 14:05:50 +0000 Subject: [PATCH] Properly use bitmasks on camera for checking culling ( to avoid checking against a plane if the parent node is already on the positive side of it) making culling faster git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7492 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../core/com/jme3/renderer/RenderManager.java | 10 +++++++++- .../com/jme3/renderer/queue/RenderQueue.java | 2 -- engine/src/core/com/jme3/scene/Spatial.java | 19 +++++++++---------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/engine/src/core/com/jme3/renderer/RenderManager.java b/engine/src/core/com/jme3/renderer/RenderManager.java index 0f35fb7a2..ba041188c 100644 --- a/engine/src/core/com/jme3/renderer/RenderManager.java +++ b/engine/src/core/com/jme3/renderer/RenderManager.java @@ -495,6 +495,9 @@ public class RenderManager { * @param cam */ public void renderScene(Spatial scene, ViewPort vp) { + if (scene.getParent() == null) { + vp.getCamera().setPlaneState(0); + } // check culling first. if (!scene.checkCulling(vp.getCamera())) { // move on to shadow-only render @@ -509,8 +512,13 @@ public class RenderManager { // recurse for all children Node n = (Node) scene; List children = n.getChildren(); + //saving cam state for culling + int camState = vp.getCamera().getPlaneState(); for (int i = 0; i < children.size(); i++) { + //restoring cam state before proceeding children recusively + vp.getCamera().setPlaneState(camState); renderScene(children.get(i), vp); + } } else if (scene instanceof Geometry) { @@ -619,7 +627,7 @@ public class RenderManager { // orthoMatrix.loadIdentity(); // orthoMatrix.setTranslation(translateX, translateY, 0); // orthoMatrix.setScale(scaleX, scaleY, 0); - + orthoMatrix.loadIdentity(); orthoMatrix.setTranslation(-1f, -1f, 0f); orthoMatrix.setScale(2f / cam.getWidth(), 2f / cam.getHeight(), 0f); diff --git a/engine/src/core/com/jme3/renderer/queue/RenderQueue.java b/engine/src/core/com/jme3/renderer/queue/RenderQueue.java index 29b9a2ec3..006ece7df 100644 --- a/engine/src/core/com/jme3/renderer/queue/RenderQueue.java +++ b/engine/src/core/com/jme3/renderer/queue/RenderQueue.java @@ -168,13 +168,11 @@ public class RenderQueue { for (int i = 0; i < list.size(); i++){ Spatial obj = list.get(i); assert obj != null; - //if(obj.checkCulling(cam)){ if (obj instanceof Geometry){ Geometry g = (Geometry) obj; rm.renderGeometry(g); // make sure to reset queue distance } - //} if (obj != null) obj.queueDistance = Float.NEGATIVE_INFINITY; } diff --git a/engine/src/core/com/jme3/scene/Spatial.java b/engine/src/core/com/jme3/scene/Spatial.java index 0cef13c5f..2c3b122cf 100644 --- a/engine/src/core/com/jme3/scene/Spatial.java +++ b/engine/src/core/com/jme3/scene/Spatial.java @@ -102,9 +102,8 @@ public abstract class Spatial implements Savable, Cloneable, Collidable { * Refresh flag types */ protected static final int RF_TRANSFORM = 0x01, // need light resort + combine transforms - RF_BOUND = 0x02, - RF_LIGHTLIST = 0x04; // changes in light lists - + RF_BOUND = 0x02, + RF_LIGHTLIST = 0x04; // changes in light lists protected CullHint cullHint = CullHint.Inherit; /** * Spatial's bounding volume relative to the world. @@ -150,8 +149,8 @@ public abstract class Spatial implements Savable, Cloneable, Collidable { refreshFlags |= RF_BOUND; } - - /** + + /** * Constructor instantiates a new Spatial object setting the * rotation, translation and scale value to defaults. * @@ -164,7 +163,6 @@ public abstract class Spatial implements Savable, Cloneable, Collidable { this.name = name; } - /** * Indicate that the transform of this spatial has changed and that * a refresh is required. @@ -234,11 +232,12 @@ public abstract class Spatial implements Savable, Cloneable, Collidable { if (getQueueBucket() == Bucket.Gui) { return cam.containsGui(getWorldBound()); } else { - int state = cam.getPlaneState(); + +// int state = cam.getPlaneState(); frustrumIntersects = cam.contains(getWorldBound()); - cam.setPlaneState(state); +// cam.setPlaneState(state); } } @@ -1170,9 +1169,9 @@ public abstract class Spatial implements Savable, Cloneable, Collidable { Savable s = userData.get(key); if (s instanceof UserData) { - return (T)((UserData) s).getValue(); + return (T) ((UserData) s).getValue(); } else { - return (T)s; + return (T) s; } }