diff options
-rw-r--r-- | src/graphui/classes/com/jogamp/graph/ui/Group.java | 11 | ||||
-rw-r--r-- | src/graphui/classes/com/jogamp/graph/ui/Scene.java | 6 | ||||
-rw-r--r-- | src/graphui/classes/com/jogamp/graph/ui/Shape.java | 15 | ||||
-rw-r--r-- | src/graphui/classes/jogamp/graph/ui/TreeTool.java | 30 |
4 files changed, 57 insertions, 5 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Group.java b/src/graphui/classes/com/jogamp/graph/ui/Group.java index 245400700..f482605ea 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Group.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Group.java @@ -399,6 +399,7 @@ public class Group extends Shape implements Container { final Shape[] shapeArray = shapes.toArray(drawShapeArray); // local-backup drawShapeArray = shapeArray; // keep backup Arrays.sort(shapeArray, 0, shapeCount, Shape.ZAscendingComparator); + // TreeTool.cullShapes(shapeArray, shapeCount); final List<Shape> iShapes = renderedShapes == renderedShapesB0 ? renderedShapesB1 : renderedShapesB0; iShapes.clear(); @@ -412,7 +413,7 @@ public class Group extends Shape implements Container { for(int i=0; i<shapeCount; i++) { final Shape shape = shapeArray[i]; - if( shape.isVisible() ) { + if( shape.isVisible() ) { // && !shape.isDiscarded() ) { pmv.pushMv(); shape.applyMatToMv(pmv); @@ -424,6 +425,9 @@ public class Group extends Shape implements Container { { shape.draw(gl, renderer); iShapes.add(shape); + shape.setDiscarded(false); + } else { + shape.setDiscarded(true); } pmv.popMv(); } @@ -432,12 +436,15 @@ public class Group extends Shape implements Container { } else { for(int i=0; i<shapeCount; i++) { final Shape shape = shapeArray[i]; - if( shape.isVisible() ) { + if( shape.isVisible() ) { // && !shape.isDiscarded() ) { pmv.pushMv(); shape.applyMatToMv(pmv); if( !doFrustumCulling || !pmv.getFrustum().isOutside( shape.getBounds() ) ) { shape.draw(gl, renderer); iShapes.add(shape); + shape.setDiscarded(false); + } else { + shape.setDiscarded(true); } pmv.popMv(); } diff --git a/src/graphui/classes/com/jogamp/graph/ui/Scene.java b/src/graphui/classes/com/jogamp/graph/ui/Scene.java index b515a55e6..ff1bebbd5 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Scene.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Scene.java @@ -488,6 +488,7 @@ public final class Scene implements Container, GLEventListener { final Shape[] shapeArray = shapes.toArray(displayShapeArray); // local-backup displayShapeArray = shapeArray; // keep backup Arrays.sort(shapeArray, 0, shapeCount, Shape.ZAscendingComparator); + // TreeTool.cullShapes(shapeArray, shapeCount); final List<Shape> iShapes = renderedShapes == renderedShapesB0 ? renderedShapesB1 : renderedShapesB0; iShapes.clear(); @@ -504,13 +505,16 @@ public final class Scene implements Container, GLEventListener { for(int i=0; i<shapeCount; i++) { final Shape shape = shapeArray[i]; - if( shape.isVisible() ) { + if( shape.isVisible() ) { // && !shape.isDiscarded() ) { pmv.pushMv(); shape.applyMatToMv(pmv); if( !doFrustumCulling || !pmv.getFrustum().isOutside( shape.getBounds() ) ) { shape.draw(gl, renderer); iShapes.add(shape); + shape.setDiscarded(false); + } else { + shape.setDiscarded(true); } pmv.popMv(); } diff --git a/src/graphui/classes/com/jogamp/graph/ui/Shape.java b/src/graphui/classes/com/jogamp/graph/ui/Shape.java index 183f8901e..6e5a904ee 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Shape.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Shape.java @@ -270,6 +270,7 @@ public abstract class Shape { private static final int IO_RESIZABLE = 1 << 5; private static final int IO_RESIZE_FIXED_RATIO = 1 << 6; private static final int IO_ACTIVE = 1 << 7; + private static final int IO_DISCARDED = 1 << 25; private static final int IO_DOWN = 1 << 26; private static final int IO_TOGGLE = 1 << 27; private static final int IO_DRAG_FIRST = 1 << 28; @@ -1523,12 +1524,13 @@ public abstract class Shape { } else { rotateS = ""; } - final String activeS = ", active["+(isIO(IO_ACTIVE) ? "SELF," : "")+(isGroup() && isActive()?"GROUP":"")+", adjZ "+getAdjustedZ()+"]"; + final String discS = isDiscarded()?", DISCARDED":""; + final String activeS = isActive()?", ACTIVE[adjZ "+getAdjustedZ()+"]":""; final String ps = hasPadding() ? padding.toString()+", " : ""; final String bs = hasBorder() ? "border[l "+getBorderThickness()+", c "+getBorderColor()+"], " : ""; final String idS = -1 != id ? ", id "+id : ""; final String nameS = "noname" != name ? ", '"+name+"'" : ""; - return getDirtyString()+idS+nameS+", visible "+isIO(IO_VISIBLE)+activeS+", toggle "+isIO(IO_TOGGLE)+ + return getDirtyString()+idS+nameS+", visible "+isIO(IO_VISIBLE)+discS+activeS+", toggle "+isIO(IO_TOGGLE)+ ", able[toggle "+isIO(IO_TOGGLEABLE)+", iactive "+isInteractive()+", resize "+isResizable()+", drag "+this.isDraggable()+ "], pos["+position+"], "+pivotS+scaleS+rotateS+iMatS+ ps+bs+"box"+box; @@ -1709,6 +1711,15 @@ public abstract class Shape { public final boolean isActivable() { return isIO(IO_ACTIVABLE); } /** + * Set whether this shape is discarded in last {@link #draw(GL2ES2, RegionRenderer)}, + * i.e. culled via frustum or occlusion criteria. + */ + public final Shape setDiscarded(final boolean v) { return setIO(IO_DISCARDED, v); } + + /** Returns whether this shape is discarded in last {@link #draw(GL2ES2, RegionRenderer)}, i.e. culled via frustum or occlusion criteria.*/ + public final boolean isDiscarded() { return isIO(IO_DISCARDED); } + + /** * Set whether this shape is draggable, * i.e. translated by 1-pointer-click and drag. * <p> diff --git a/src/graphui/classes/jogamp/graph/ui/TreeTool.java b/src/graphui/classes/jogamp/graph/ui/TreeTool.java index dcb847932..979c6a3b1 100644 --- a/src/graphui/classes/jogamp/graph/ui/TreeTool.java +++ b/src/graphui/classes/jogamp/graph/ui/TreeTool.java @@ -27,6 +27,7 @@ */ package jogamp.graph.ui; +import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.List; @@ -36,6 +37,7 @@ import com.jogamp.graph.ui.Scene; import com.jogamp.graph.ui.Shape; import com.jogamp.graph.ui.Shape.Visitor1; import com.jogamp.graph.ui.Shape.Visitor2; +import com.jogamp.math.geom.AABBox; import com.jogamp.math.util.PMVMatrix4f; /** Generic static {@link Shape} tree traversal tools, utilized by {@link Scene} and {@link Container} implementations. */ @@ -245,4 +247,32 @@ public class TreeTool { }); return res[0]; } + + public static boolean isCovered(final List<AABBox> coverage, final AABBox box) { + for(final AABBox b : coverage) { + if( b.contains(box) ) { + return true; + } + } + return false; + } + + public static void cullShapes(final Shape[] shapesZAsc, final int shapeCount) { + final List<AABBox> coverage = new ArrayList<AABBox>(); + for(int i=shapeCount-1; i>=0; --i) { + final Shape s = shapesZAsc[i]; + if( coverage.size() == 0 ) { + coverage.add(s.getBounds()); + s.setDiscarded(false); + } else { + final AABBox b = s.getBounds(); + if( isCovered(coverage, b) ) { + s.setDiscarded(true); + } else { + coverage.add(b); + s.setDiscarded(false); + } + } + } + } } |