Browse Source

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
rem..om 14 years ago
parent
commit
cacfc6b71a

+ 9 - 1
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<Spatial> 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);

+ 0 - 2
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;
         }

+ 9 - 10
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 <code>Spatial</code> 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;
         }
     }