28package com.jogamp.graph.ui;
30import java.util.ArrayList;
31import java.util.Arrays;
32import java.util.Collection;
33import java.util.Comparator;
35import java.util.concurrent.CopyOnWriteArrayList;
37import com.jogamp.graph.curve.Region;
38import com.jogamp.graph.curve.opengl.RegionRenderer;
39import com.jogamp.graph.ui.layout.Padding;
40import com.jogamp.graph.ui.shapes.Rectangle;
41import com.jogamp.math.FloatUtil;
42import com.jogamp.math.Matrix4f;
43import com.jogamp.math.Vec2f;
44import com.jogamp.math.Vec3f;
45import com.jogamp.math.Vec4f;
46import com.jogamp.math.geom.AABBox;
47import com.jogamp.math.geom.Cube;
48import com.jogamp.math.geom.Frustum;
49import com.jogamp.math.util.PMVMatrix4f;
50import com.jogamp.opengl.GL2ES2;
51import com.jogamp.opengl.GLProfile;
53import jogamp.graph.ui.TreeTool;
83 private final List<Shape> shapes =
new CopyOnWriteArrayList<Shape>();
85 private final List<Shape> renderedShapesB0 =
new ArrayList<Shape>();
86 private final List<Shape> renderedShapesB1 =
new ArrayList<Shape>();
87 private final List<Shape> renderedShapesB2 =
new ArrayList<Shape>();
88 private volatile List<Shape> renderedShapes = renderedShapesB1;
89 private int renderedShapesIdx = 1;
95 private boolean relayoutOnDirtyShapes =
true;
96 private Scene topLevelHolder =
null;
97 private boolean clipOnBounds =
false;
98 private Frustum clipFrustum =
null;
107 this(
null,
null,
null,
null);
118 this(
null, l,
null,
null);
138 if(
null != fixedSize ) {
147 public final boolean isGroup() {
return true; }
238 final int idx = shapes.indexOf(
remove);
242 if(
null == shapes.remove(idx) ) {
245 remove.setParent(
null);
246 shapes.add(idx, replacement);
254 if( shapes.remove(s) ) {
265 for(
final Shape s : shapes) {
272 if( shapes.remove(s) ) {
283 public void addShapes(
final Collection<? extends Shape> shapes) {
284 for(
final Shape s : shapes) {
290 for(
final Shape s : shapes) {
297 final int count = shapes.size();
298 for(
int i=count-1; i>=0; --i) {
311 for(
final Shape s : shapes) {
312 s.clear(gl, renderer);
315 drawShapeArray =
new Shape[0];
316 renderedShapesB0.
clear();
317 renderedShapesB1.clear();
318 renderedShapesB2.clear();
319 renderedShapes = renderedShapesB1;
320 renderedShapesIdx = 1;
326 for(
final Shape s : shapes) {
328 s.destroy(gl, renderer);
331 drawShapeArray =
new Shape[0];
332 renderedShapesB0.
clear();
333 renderedShapesB1.clear();
334 renderedShapesB2.clear();
335 renderedShapes = renderedShapesB1;
336 renderedShapesIdx = 1;
337 if(
null != border ) {
343 private boolean doFrustumCulling =
false;
352 public final boolean isCullingEnabled() {
return doFrustumCulling || clipOnBounds ||
null != clipFrustum; }
357 final boolean useClipFrustum =
null != clipFrustum;
358 if( useClipFrustum || clipOnBounds ) {
371 }
else if( doFrustumCulling ){
384 final boolean useClipFrustum =
null != clipFrustum;
385 if( useClipFrustum || clipOnBounds ) {
395 }
else if( doFrustumCulling ){
405 final int shapeCount = shapes.size();
406 Arrays.fill(drawShapeArray,
null);
407 final Shape[] shapeArray = shapes.toArray(drawShapeArray);
408 drawShapeArray = shapeArray;
412 final List<Shape> iShapes;
414 switch(renderedShapesIdx) {
415 case 0: iShapeIdx = 1; iShapes = renderedShapesB1;
break;
416 case 1: iShapeIdx = 2; iShapes = renderedShapesB2;
break;
417 default: iShapeIdx = 0; iShapes = renderedShapesB0;
break;
419 final boolean useClipFrustum =
null != clipFrustum;
420 if( useClipFrustum || clipOnBounds ) {
426 synchronized( iShapes ) {
428 for(
int i=0; i<shapeCount; i++) {
429 final Shape shape = shapeArray[i];
437 if( ( !frustumMv.
isOutside( shapeMv ) ) &&
440 shape.
draw(gl, renderer);
452 synchronized( iShapes ) {
454 for(
int i=0; i<shapeCount; i++) {
455 final Shape shape = shapeArray[i];
460 shape.
draw(gl, renderer);
471 renderedShapes = iShapes;
472 renderedShapesIdx = iShapeIdx;
473 if(
null != border && border.
isVisible() ) {
474 border.
draw(gl, renderer);
478 private final Cube tempC00 =
new Cube();
479 private final Cube tempC01 =
new Cube();
481 @SuppressWarnings({
"unchecked",
"rawtypes" })
485 final Object[] shapesS = shapes.toArray();
488 final int shapeCount = shapesS.length;
489 for(
int i=0; i<shapeCount; i++) {
501 if(
null != border && border.
isVisible() ) {
536 topLevelHolder = scene;
537 scene.addTopLevel(
this);
542 final Scene tlh = topLevelHolder;
543 topLevelHolder =
null;
545 tlh.removeTopLevel(
this);
562 if( relayoutOnDirtyShapes ) {
566 for(
final Shape s : shapes) {
567 if( s.isShapeDirty() ) {
572 return super.isShapeDirty();
578 final boolean needsRMs =
hasBorder() &&
null == border;
583 if(
null != layouter ) {
584 if( 0 == shapes.size() ) {
587 for(
final Shape s : shapes) {
588 if( needsRMs &&
null == firstGS && s instanceof
GraphShape ) {
596 }
else if( 0 == shapes.size() ) {
600 for(
final Shape s : shapes) {
601 if( needsRMs &&
null == firstGS && s instanceof
GraphShape ) {
607 s.getBounds().transform(pmv.
getMv(), tsbox);
621 final boolean useClipping =
null != clipFrustum || clipOnBounds;
622 if( useFixedSize || useClipping ) {
624 final boolean adjustZ = useClipping || ( useFixedSize && Float.isNaN(fixedSize.z()) );
630 lo.
add( 0, 0, -(1f*zAdjustment));
633 hi.
add(fixedSize.x(), fixedSize.y(), oldDepth+(2f*zAdjustment));
636 hi.
add( 0, 0, oldDepth+(1f*zAdjustment));
639 }
else if( useFixedSize ) {
642 hi.
add(fixedSize.x(), fixedSize.y(), fixedSize.z());
650 if(
null == border ) {
651 final int firstRMs =
null != firstGS ? firstGS.
getRenderModes() : 0;
652 final int myRMs =
Region.
isVBAA(firstRMs) ? Region.VBAA_RENDERING_BIT : 0;
659 }
else if(
null != border ) {
667 return TreeTool.contains(
this, s);
674 return shapes.get(
id);
678 return TreeTool.getShapeByID(
this,
id);
682 return TreeTool.getShapeByName(
this, name);
690 if(
null == shape ) {
693 TreeTool.forOne(
this, pmv, shape, () -> {
701 return super.getSubString()+
", shapes "+shapes.size();
Abstract Outline shape representation define the method an OutlineShape(s) is bound and rendered.
static boolean isVBAA(final int renderModes)
Returns true if given renderModes has Region#VBAA_RENDERING_BIT set.
final PMVMatrix4f getMatrix()
Borrow the current PMVMatrix4f.
final void setClipFrustum(final Frustum clipFrustum)
Set the optional clipping Frustum, which shall be pre-multiplied with the Mv-matrix or null to disabl...
final Frustum getClipFrustum()
Returns the optional Mv-premultiplied clipping Frustum or null if unused.
Graph based GLRegion Shape.
final int getRenderModes()
Returns validated Graph Region render modes, see create(..).
Group of Shapes, optionally utilizing a Group.Layout.
Group()
Create a group of Shapes w/o Group.Layout.
final boolean isOutside(final PMVMatrix4f pmv, final Shape shape)
Returns whether the given Shape is completely outside of this container.
Group setFixedSize(final Vec2f v)
Enforce size of this group to given 2 dimensions, adjusting the 3D z-axis getBounds() giving room for...
boolean removeShape(final GL2ES2 gl, final RegionRenderer renderer, final Shape s)
Removes given shape with Shape#destroy(GL2ES2, RegionRenderer), if contained.
int getShapeCount()
Returns number of Shapes, see getShapes().
Vec2f getFixedSize(final Vec2f out)
Returns given Vec2f instance set with 2 dimensions, see setFixedSize(Vec2f).
final boolean isTopLevelWidget()
Returns whether setTopLevelWidget(boolean) is enabled or disabled.
boolean hasColorChannel()
Returns true if implementation uses an extra color channel or texture which will be modulated with th...
Group(final Layout l)
Create a group of Shapes w/ given Group.Layout.
final void drawToSelectImpl0(final GL2ES2 gl, final RegionRenderer renderer)
Actual draw implementation, called by drawToSelect(GL2ES2, RegionRenderer).
Shape getShapeByIdx(final int id)
void addShape(final Shape s)
Adds a Shape.
void removeAllShapes(final GL2ES2 gl, final RegionRenderer renderer)
Removes all contained shapes with Shape#destroy(GL2ES2, RegionRenderer).
boolean getRelayoutOnDirtyShapes()
final boolean isCullingEnabled()
Return whether Project-Modelview (PMv) frustum culling or Group's Modelview (Mv) frustum clipping is ...
List< Shape > getRenderedShapes()
Returns added shapes which are rendered and sorted by z-axis in ascending order toward z-near.
boolean replaceShape(final Shape remove, final Shape replacement)
Atomic replacement of the given Shape remove with Shape replacement.
final boolean isPMvCullingEnabled()
Return whether Project-Modelview (PMv) frustum culling is enabled for this container.
List< Shape > getShapes()
Returns added Shapes.
Group setClipOnBounds(final boolean v)
Enable Modelview (Mv) Frustum clipping on getBounds() for this group and its shapes as follows.
final Group enableTopLevelWidget(final Scene scene)
Enables top-level widget behavior for this group, default is disabled.
void validateImpl(final GL2ES2 gl, final GLProfile glp)
final boolean isGroup()
Returns true if this shape denotes a Group, otherwise false.
Group(final String name, final Layout l, final Vec2f fixedSize, final Shape s)
Create a group of Shapes w/ given Group.Layout and Shape.
Layout getLayout()
Return current Group.Layout.
void removeShapes(final GL2ES2 gl, final RegionRenderer renderer, final Collection<? extends Shape > shapes)
Removes all given shapes with Shape#destroy(GL2ES2, RegionRenderer).
final void setPMvCullingEnabled(final boolean v)
Enable or disable Project-Modelview (PMv) frustum culling per Shape for this container.
AABBox getBounds(final PMVMatrix4f pmv, final Shape shape)
Returns AABBox dimension of given Shape from this container's perspective, i.e.
void setRelayoutOnDirtyShapes(final boolean v)
Set relayout on dirty shapes mode, defaults to true.
boolean isOutside2(final Matrix4f mvCont, final Shape shape, final PMVMatrix4f pmvShape)
Returns whether the given Shape is completely outside of this container.
Group setFixedSize(final Vec3f v)
Enforce size of this group for all given 3 dimensions getBounds() without adjusting 3D z-axis like se...
boolean getClipOnBounds()
Returns setClipOnBounds(boolean) value.
final Group disableTopLevelWidget()
Disables top-level widget behavior as potentially set via enableTopLevelWidget(Scene).
Shape removeShape(final Shape s)
Removes given shape, w/o Shape#destroy(GL2ES2, RegionRenderer).
void addShapes(final Collection<? extends Shape > shapes)
Frustum getClipMvFrustum()
Returns setClipMvFrustum(Frustum) value.
Group setLayout(final Layout l)
Set Group.Layout.
Group setClipMvFrustum(final Frustum v)
Enable Modelview (Mv) Frustum clipping on explicit given pre-multiplied w/ Mv-matrix clip-box for thi...
Shape getShapeByID(final int id)
Shape getShapeByName(final String name)
boolean contains(final Shape s)
void removeShapes(final Collection<? extends Shape > shapes)
Removes all given shapes, w/o Shape#destroy(GL2ES2, RegionRenderer).
Vec3f getFixedSize()
Returns borrowed fixed size instance, see setFixedSize(Vec3f) and setFixedSize(Vec2f).
void drawImpl0(final GL2ES2 gl, final RegionRenderer renderer, final Vec4f rgba)
Actual draw implementation, called by draw(GL2ES2, RegionRenderer).
boolean isShapeDirty()
Returns the shape's dirty state, see markShapeDirty().
void clearImpl0(final GL2ES2 gl, final RegionRenderer renderer)
Custom clear(GL2ES2, RegionRenderer) task, called 1st.
void destroyImpl0(final GL2ES2 gl, final RegionRenderer renderer)
Custom destroy(GL2ES2, RegionRenderer) task, called 1st.
static final float DEFAULT_ACTIVE_ZOFFSET_SCALE
Default Z precision scale, i.e.
static final float DEFAULT_Z16_EPSILON
Default Z precision on 16-bit depth buffer using DEFAULT_SCENE_DIST z-position and DEFAULT_ZNEAR.
Generic Shape, potentially using a Graph via GraphShape or other means of representing content.
Padding getPadding()
Returns unscaled Padding of this shape, which is included in unscaled getBounds() and also includes t...
Shape setColor(final float r, final float g, final float b, final float a)
Set base color.
Shape setName(final String name)
Set a symbolic name for this shape for identification.
Shape()
Create a generic UI Shape.
final Shape setInteractive(final boolean v)
Set whether this shape is interactive in general, i.e.
void draw(final GL2ES2 gl, final RegionRenderer renderer)
Renders the shape.
boolean hasPadding()
Returns true if setPaddding(Padding) added a non Padding#zeroSize() spacing to this shape.
final Shape setDiscarded(final boolean v)
Set whether this shape is discarded in last draw(GL2ES2, RegionRenderer), i.e.
final boolean hasBorder()
Returns true if a border has been enabled via setBorder(float, Padding).
final void clear(final GL2ES2 gl, final RegionRenderer renderer)
Clears all data and reset all states as if this instance was newly created.
final float getBorderThickness()
Returns the border thickness, see setBorder(float, Padding).
static Comparator< Shape > ZAscendingComparator
void setParent(final Group c)
final Vec4f getBorderColor()
final AABBox getBounds()
Returns the unscaled bounding AABBox for this shape, borrowing internal instance.
final boolean isVisible()
Returns true if this shape is set visible by the user, otherwise false.
void drawToSelect(final GL2ES2 gl, final RegionRenderer renderer)
Experimental selection draw command used by Scene.
final Shape validate(final GL2ES2 gl)
Validates the shape's underlying GLRegion.
final void markShapeDirty()
Marks the shape dirty, causing next draw() to recreate the Graph shape and reset the region.
final void destroy(final GL2ES2 gl, final RegionRenderer renderer)
Destroys all data.
final void applyMatToMv(final PMVMatrix4f pmv)
Applies the internal Matrix4f to the given modelview matrix, i.e.
final Shape setVisible(final boolean v)
Enable (default) or disable this shape's visibility.
final Shape setRotationPivot(final float px, final float py, final float pz)
Set unscaled rotation origin, aka pivot.
GraphUI CSS property Padding, unscaled space belonging to the element and included in the element's s...
final float top
Top value (unscaled)
final float left
Left value (unscaled)
final float right
Right value (unscaled)
final float bottom
Bottom value (unscaled)
A GraphUI rectangle GraphShape.
void setBounds(final AABBox abox, final float lineWidth)
Basic Float math utility functions.
static boolean isZero(final float a, final float epsilon)
Returns true if value is zero, i.e.
Basic 4x4 float matrix implementation using fields for intensive use-cases (host operations).
2D Vector based upon two float components.
void set(final Vec2f o)
this = o, returns this.
3D Vector based upon three float components.
Vec3f set(final Vec3f o)
this = o, returns this.
Vec3f add(final float dx, final float dy, final float dz)
this = this + { dx, dy, dz }, returns this.
4D Vector based upon four float components.
Axis Aligned Bounding Box.
final Vec3f getHigh()
Returns the maximum right-top-near (xyz) coordinate.
final Vec3f getLow()
Returns the minimum left-bottom-far (xyz) coordinate.
final AABBox setSize(final float[] low, final float[] high)
Set size of the AABBox specifying the coordinates of the low and high.
final AABBox resize(final AABBox newBox)
Resize the AABBox to encapsulate another AABox.
final Vec3f getCenter()
Returns computed center of this AABBox of getLow() and getHigh().
Simple 8-point Vec3f cube compound having z-far <= z-near @endiliteral.
Frustum updateFrustumPlanes(final Frustum frustum)
Calculate the frustum planes using this Cube.
Cube transform(final Matrix4f mat)
Affine 3f-vector transformation of all 8-points with given matrix, Matrix4f#mulVec3f(Vec3f).
Cube set(final AABBox box)
Setting this cube to given AABBox minimum and maximum.
Providing frustum planes derived by different inputs (P*MV, ..) used to classify objects.
final boolean isOutside(final AABBox box)
Returns whether the given AABBox is completely outside of this frustum.
PMVMatrix4f implements the basic computer graphics Matrix4f pack using projection (P),...
void reset()
Issues Matrix4f#loadIdentity() on all matrices and resets all internal states.
final Matrix4f getMv()
Returns the modelview matrix (Mv).
final Frustum getFrustum()
Returns the frustum, derived from projection x modelview.
final PMVMatrix4f popMv()
Pop the modelview matrix from its stack.
final PMVMatrix4f pushMv()
Push the modelview matrix to its stack, while preserving its values.
Specifies the the OpenGL profile.
Container interface of UI Shapes.
Layout for the GraphUI Group, called @ Shape#validate(GL2ES2) or Shape#validate(GLProfile).
void preValidate(final Shape s)
Prepare given Shape before validation, e.g.
void layout(final Group g, final AABBox box, final PMVMatrix4f pmv)
Performing the layout of Group#getShapes(), called @ Shape#validate(GL2ES2) or Shape#validate(GLProfi...