summaryrefslogtreecommitdiffstats
path: root/src/graphui/classes/com
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-03-20 21:32:54 +0100
committerSven Gothel <[email protected]>2023-03-20 21:32:54 +0100
commit8abe939c5132e4a58c4b9a6b31f0b1fd10734516 (patch)
tree5db344e61d8c5c39ed322bb519847f22a70bee5a /src/graphui/classes/com
parent118d754af34d6d475600e6747e01e950a6cf77cf (diff)
GraphUI Shape/Label: Allow validate(..) w/o current GL context, used by e.g. Label.setText(..) and getBounds(), preparations for more animation.
Hence Shape.validate(..) is now synchronized, avoiding parallel resource modding from render- and other animating thread.
Diffstat (limited to 'src/graphui/classes/com')
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/gl/Shape.java53
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/gl/shapes/Label.java36
2 files changed, 76 insertions, 13 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/gl/Shape.java b/src/graphui/classes/com/jogamp/graph/ui/gl/Shape.java
index 7928d09f4..1876b8057 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/gl/Shape.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/gl/Shape.java
@@ -28,6 +28,7 @@
package com.jogamp.graph.ui.gl;
import java.util.ArrayList;
+import java.util.List;
import com.jogamp.nativewindow.NativeWindowException;
import com.jogamp.opengl.GL2ES2;
@@ -94,6 +95,7 @@ public abstract class Shape {
protected GLRegion region = null;
protected int regionQuality = Region.MAX_QUALITY;
+ protected List<GLRegion> dirtyRegions = new ArrayList<GLRegion>();
protected int dirty = DIRTY_SHAPE | DIRTY_STATE;
protected float shapesSharpness = OutlineShape.DEFAULT_SHARPNESS;
@@ -137,6 +139,13 @@ public abstract class Shape {
/** Enable or disable this shape, i.e. its visibility. */
public final void setEnabled(final boolean v) { enabled = v; }
+ private final void clearDirtyRegions(final GL2ES2 gl) {
+ for(final GLRegion r : dirtyRegions) {
+ r.destroy(gl);
+ }
+ dirtyRegions.clear();
+ }
+
/**
* Clears all data and reset all states as if this instance was newly created
* @param gl TODO
@@ -144,6 +153,10 @@ public abstract class Shape {
*/
public final void clear(final GL2ES2 gl, final RegionRenderer renderer) {
clearImpl(gl, renderer);
+ clearDirtyRegions(gl);
+ if( null != region ) {
+ region.clear(gl);
+ }
position[0] = 0f;
position[1] = 0f;
position[2] = 0f;
@@ -165,6 +178,11 @@ public abstract class Shape {
*/
public final void destroy(final GL2ES2 gl, final RegionRenderer renderer) {
destroyImpl(gl, renderer);
+ clearDirtyRegions(gl);
+ if( null != region ) {
+ region.destroy(gl);
+ region = null;
+ }
position[0] = 0f;
position[1] = 0f;
position[2] = 0f;
@@ -296,10 +314,7 @@ public abstract class Shape {
* @see #getBounds()
*/
public final AABBox getBounds(final GLProfile glp) {
- if( null == region ) {
- // initial creation of region, producing a valid box
- validateImpl(glp, null);
- }
+ validate(glp);
return box;
}
@@ -387,21 +402,39 @@ public abstract class Shape {
/**
* Validates the shape's underlying {@link GLRegion}.
- *
- * @param gl
+ * <p>
+ * If the region is dirty, it gets {@link GLRegion#clear(GL2ES2) cleared} and is reused.
+ * </p>
+ * @param gl current {@link GL2ES2} object
+ * @see #validate(GLProfile)
*/
public final void validate(final GL2ES2 gl) {
validateImpl(gl.getGLProfile(), gl);
}
- private final void validateImpl(final GLProfile glp, final GL2ES2 gl) {
+ /**
+ * Validates the shape's underlying {@link GLRegion} w/o a current {@link GL2ES2} object
+ * <p>
+ * If the region is dirty a new region is created
+ * and the old one gets pushed to a dirty-list to get disposed when a GL context is available.
+ * </p>
+ * @see #validate(GL2ES2)
+ */
+ public final void validate(final GLProfile glp) {
+ validateImpl(glp, null);
+ }
+ private final synchronized void validateImpl(final GLProfile glp, final GL2ES2 gl) {
+ if( null != gl ) {
+ clearDirtyRegions(gl);
+ }
if( isShapeDirty() || null == region ) {
box.reset();
if( null == region ) {
region = createGLRegion(glp);
- } else if( null != gl ) {
- region.clear(gl);
+ } else if( null == gl ) {
+ dirtyRegions.add(region);
+ region = createGLRegion(glp);
} else {
- throw new IllegalArgumentException("GL is null on non-initial validation");
+ region.clear(gl);
}
addShapeToRegion();
region.setQuality(regionQuality);
diff --git a/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/Label.java b/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/Label.java
index 5e1f88df9..ac337924a 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/Label.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/Label.java
@@ -71,7 +71,7 @@ public class Label extends Shape {
}
/**
- * Set the text to be rendered
+ * Set the text to be rendered. Shape update is pending until next {@link #draw(GL2ES2, RegionRenderer, int[])} or {@link #validate(GL2ES2)}.
* @param text the text to be set.
* @return true if text has been updated, false if unchanged.
*/
@@ -86,6 +86,36 @@ public class Label extends Shape {
}
/**
+ * Set the text to be rendered and immediately updates the shape if necessary.
+ * @param gl {@link GL2ES2} to issue {@link #validate(GL2ES2)} in case text changed to immediately update shape and {@link #getBounds()}
+ * @param text the text to be set.
+ * @return true if text has been updated, false if unchanged.
+ */
+ public boolean setText(final GL2ES2 gl, final String text) {
+ if( setText(text) ) {
+ validate(gl);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Set the text to be rendered and immediately updates the shape if necessary.
+ * @param glp {@link GLProfile} to issue {@link #validate(GLProfile)} in case text changed to immediately update shape and {@link #getBounds()}
+ * @param text the text to be set.
+ * @return true if text has been updated, false if unchanged.
+ */
+ public boolean setText(final GLProfile glp, final String text) {
+ if( setText(text) ) {
+ validate(glp);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
* Return the {@link Font} used to render the text
*/
public Font getFont() {
@@ -144,9 +174,9 @@ public class Label extends Shape {
protected void addShapeToRegion() {
tempT1.setToScale(fontScale, fontScale);
final AABBox fbox = font.processString(shapeVisitor, tempT1, text, tempT2, tempT3);
- final float[] ctr = box.getCenter();
+ final float[] ctr = fbox.getCenter();
setRotationOrigin( ctr[0], ctr[1], ctr[2]);
- box.resize(fbox);
+ box.copy(fbox);
}
@Override