summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/graph
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-03-07 19:05:05 +0100
committerSven Gothel <[email protected]>2023-03-07 19:05:05 +0100
commit3bad09f6b7c7f9c93a6cf385abb51a6563e8aec0 (patch)
tree456cf2320e4d8b6970bc401f25d68efa28ad2ae6 /src/jogl/classes/com/jogamp/graph
parent5e79fea8981a13d155e0b958aa3e20a546c533bb (diff)
Graph Perf: Add Region.countOutlineShape(), Font.processString(Visitor2,..), TextRegionUtil.countStringRegion() allowing to use Region.setBufferCapacity()
Diffstat (limited to 'src/jogl/classes/com/jogamp/graph')
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java11
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/Region.java37
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java21
-rw-r--r--src/jogl/classes/com/jogamp/graph/font/Font.java14
4 files changed, 79 insertions, 4 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
index b287a833f..fc8d41660 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
@@ -140,6 +140,17 @@ public final class OutlineShape implements Comparable<OutlineShape> {
public void visit(final OutlineShape shape, final AffineTransform t);
}
+ /**
+ * Constrained {@link OutlineShape} visitor w/o {@link AffineTransform}.
+ */
+ public static interface Visitor2 {
+ /**
+ * Visiting the given {@link OutlineShape}.
+ * @param shape may be used as is, otherwise a copy shall be made if intended to be modified.
+ */
+ public void visit(final OutlineShape shape);
+ }
+
/** Initial {@link #getSharpness()} value, which can be modified via {@link #setSharpness(float)}. */
public static final float DEFAULT_SHARPNESS = 0.5f;
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java
index 5147008a1..22e63a3f7 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/Region.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java
@@ -441,6 +441,43 @@ public abstract class Region {
public PerfCounterCtrl perfCounter() { return perfCounterCtrl; }
/**
+ * Count required number of vertices and indices adding to given int[2] `vertIndexCount` array.
+ * <p>
+ * The region's buffer can be either set using {@link Region#setBufferCapacity(int, int)} or grown using {@link Region#growBuffer(int, int)}.
+ * </p>
+ * @param shape the {@link OutlineShape} to count
+ * @param vertIndexCount the int[2] storage where the counted vertices and indices are added, vertices at [0] and indices at [1]
+ * @see #setBufferCapacity(int, int)
+ * @see #growBuffer(int, int)
+ */
+ public final void countOutlineShape(final OutlineShape shape, final int[/*2*/] vertIndexCount) {
+ final List<Triangle> trisIn = shape.getTriangles(OutlineShape.VerticesState.QUADRATIC_NURBS);
+ final ArrayList<Vertex> vertsIn = shape.getVertices();
+ {
+ final int verticeCount = vertsIn.size() + shape.getAddedVerticeCount();
+ final int indexCount = trisIn.size() * 3;
+ vertIndexCount[0] += verticeCount;
+ vertIndexCount[1] += Math.min( Math.ceil(verticeCount * 0.6), indexCount );
+ }
+ }
+
+ /**
+ * Count required number of vertices and indices adding to given int[2] `vertIndexCount` array.
+ * <p>
+ * The region's buffer can be either set using {@link Region#setBufferCapacity(int, int)} or grown using {@link Region#growBuffer(int, int)}.
+ * </p>
+ * @param shapes list of {@link OutlineShape} to count
+ * @param vertIndexCount the int[2] storage where the counted vertices and indices are added, vertices at [0] and indices at [1]
+ * @see #setBufferCapacity(int, int)
+ * @see #growBuffer(int, int)
+ */
+ public final void countOutlineShapes(final List<OutlineShape> shapes, final int[/*2*/] vertIndexCount) {
+ for (int i = 0; i < shapes.size(); i++) {
+ countOutlineShape(shapes.get(i), vertIndexCount);
+ }
+ }
+
+ /**
* Add the given {@link OutlineShape} to this region with the given optional {@link AffineTransform}.
* <p>
* In case {@link #setFrustum(Frustum) frustum culling is set}, the {@link OutlineShape}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java
index 0547d994a..8d55c6136 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java
@@ -115,6 +115,27 @@ public class TextRegionUtil {
}
/**
+ * Count required number of vertices and indices adding to given int[2] `vertIndexCount` array.
+ * <p>
+ * The region's buffer can be either set using {@link Region#setBufferCapacity(int, int)} or grown using {@link Region#growBuffer(int, int)}.
+ * </p>
+ * @param region the {@link GLRegion} sink
+ * @param font the target {@link Font}
+ * @param str string text
+ * @param vertIndexCount the int[2] storage where the counted vertices and indices are added, vertices at [0] and indices at [1]
+ * @see Region#setBufferCapacity(int, int)
+ * @see Region#growBuffer(int, int)
+ */
+ public static void countStringRegion(final Region region, final Font font, final CharSequence str, final int[/*2*/] vertIndexCount) {
+ final OutlineShape.Visitor2 visitor = new OutlineShape.Visitor2() {
+ @Override
+ public final void visit(final OutlineShape shape) {
+ region.countOutlineShape(shape, vertIndexCount);
+ } };
+ font.processString(visitor, str);
+ }
+
+ /**
* Render the string in 3D space w.r.t. the font int font em-size [0..1] at the end of an internally cached {@link GLRegion}.
* <p>
* The shapes added to the GLRegion are in font em-size [0..1].
diff --git a/src/jogl/classes/com/jogamp/graph/font/Font.java b/src/jogl/classes/com/jogamp/graph/font/Font.java
index 8d3ed2d8e..f296c77b3 100644
--- a/src/jogl/classes/com/jogamp/graph/font/Font.java
+++ b/src/jogl/classes/com/jogamp/graph/font/Font.java
@@ -27,9 +27,6 @@
*/
package com.jogamp.graph.font;
-import java.io.PrintStream;
-
-import com.jogamp.common.util.PerfCounterCtrl;
import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.graph.geom.plane.AffineTransform;
import com.jogamp.opengl.math.geom.AABBox;
@@ -412,7 +409,7 @@ public interface Font {
* Visit each {@link Glyph}'s {@link OutlineShape} of the string with the {@link OutlineShape.Visitor}
* while passing the progressed {@link AffineTransform}.
* <p>
- * The produced shapes are in font em-size [0..1], but can be adjusted with the given transform, progressed and passed to the visitor.
+ * The processed shapes are in font em-size [0..1], but can be adjusted with the given transform, progressed and passed to the visitor.
* </p>
* @param visitor handling each glyph's outline shape in font em-size [0..1] and the given {@link AffineTransform}
* @param transform optional given transform
@@ -426,6 +423,15 @@ public interface Font {
final CharSequence string,
final AffineTransform temp1, final AffineTransform temp2);
+ /**
+ * Visit each {@link Glyph}'s {@link OutlineShape} of the string with the constrained {@link OutlineShape.Visitor2}.
+ * <p>
+ * The processed shapes are in font em-size [0..1].
+ * </p>
+ * @param visitor handling each glyph's outline shape in font em-size [0..1]
+ * @param string string text
+ */
+ void processString(final OutlineShape.Visitor2 visitor, final CharSequence string);
/** Returns {@link #getFullFamilyName()} */
@Override