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
3.0
rem..om 14 years ago
parent 3430cd93d1
commit cacfc6b71a
  1. 8
      engine/src/core/com/jme3/renderer/RenderManager.java
  2. 2
      engine/src/core/com/jme3/renderer/queue/RenderQueue.java
  3. 17
      engine/src/core/com/jme3/scene/Spatial.java

@ -495,6 +495,9 @@ public class RenderManager {
* @param cam * @param cam
*/ */
public void renderScene(Spatial scene, ViewPort vp) { public void renderScene(Spatial scene, ViewPort vp) {
if (scene.getParent() == null) {
vp.getCamera().setPlaneState(0);
}
// check culling first. // check culling first.
if (!scene.checkCulling(vp.getCamera())) { if (!scene.checkCulling(vp.getCamera())) {
// move on to shadow-only render // move on to shadow-only render
@ -509,8 +512,13 @@ public class RenderManager {
// recurse for all children // recurse for all children
Node n = (Node) scene; Node n = (Node) scene;
List<Spatial> children = n.getChildren(); List<Spatial> children = n.getChildren();
//saving cam state for culling
int camState = vp.getCamera().getPlaneState();
for (int i = 0; i < children.size(); i++) { for (int i = 0; i < children.size(); i++) {
//restoring cam state before proceeding children recusively
vp.getCamera().setPlaneState(camState);
renderScene(children.get(i), vp); renderScene(children.get(i), vp);
} }
} else if (scene instanceof Geometry) { } else if (scene instanceof Geometry) {

@ -168,13 +168,11 @@ public class RenderQueue {
for (int i = 0; i < list.size(); i++){ for (int i = 0; i < list.size(); i++){
Spatial obj = list.get(i); Spatial obj = list.get(i);
assert obj != null; assert obj != null;
//if(obj.checkCulling(cam)){
if (obj instanceof Geometry){ if (obj instanceof Geometry){
Geometry g = (Geometry) obj; Geometry g = (Geometry) obj;
rm.renderGeometry(g); rm.renderGeometry(g);
// make sure to reset queue distance // make sure to reset queue distance
} }
//}
if (obj != null) if (obj != null)
obj.queueDistance = Float.NEGATIVE_INFINITY; obj.queueDistance = Float.NEGATIVE_INFINITY;
} }

@ -102,9 +102,8 @@ public abstract class Spatial implements Savable, Cloneable, Collidable {
* Refresh flag types * Refresh flag types
*/ */
protected static final int RF_TRANSFORM = 0x01, // need light resort + combine transforms protected static final int RF_TRANSFORM = 0x01, // need light resort + combine transforms
RF_BOUND = 0x02, RF_BOUND = 0x02,
RF_LIGHTLIST = 0x04; // changes in light lists RF_LIGHTLIST = 0x04; // changes in light lists
protected CullHint cullHint = CullHint.Inherit; protected CullHint cullHint = CullHint.Inherit;
/** /**
* Spatial's bounding volume relative to the world. * Spatial's bounding volume relative to the world.
@ -151,7 +150,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable {
refreshFlags |= RF_BOUND; refreshFlags |= RF_BOUND;
} }
/** /**
* Constructor instantiates a new <code>Spatial</code> object setting the * Constructor instantiates a new <code>Spatial</code> object setting the
* rotation, translation and scale value to defaults. * rotation, translation and scale value to defaults.
* *
@ -164,7 +163,6 @@ public abstract class Spatial implements Savable, Cloneable, Collidable {
this.name = name; this.name = name;
} }
/** /**
* Indicate that the transform of this spatial has changed and that * Indicate that the transform of this spatial has changed and that
* a refresh is required. * a refresh is required.
@ -234,11 +232,12 @@ public abstract class Spatial implements Savable, Cloneable, Collidable {
if (getQueueBucket() == Bucket.Gui) { if (getQueueBucket() == Bucket.Gui) {
return cam.containsGui(getWorldBound()); return cam.containsGui(getWorldBound());
} else { } else {
int state = cam.getPlaneState();
// int state = cam.getPlaneState();
frustrumIntersects = cam.contains(getWorldBound()); 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); Savable s = userData.get(key);
if (s instanceof UserData) { if (s instanceof UserData) {
return (T)((UserData) s).getValue(); return (T) ((UserData) s).getValue();
} else { } else {
return (T)s; return (T) s;
} }
} }

Loading…
Cancel
Save