From 3bad09f6b7c7f9c93a6cf385abb51a6563e8aec0 Mon Sep 17 00:00:00 2001 From: Sven Gothel <sgothel@jausoft.com> Date: Tue, 7 Mar 2023 19:05:05 +0100 Subject: Graph Perf: Add Region.countOutlineShape(), Font.processString(Visitor2,..), TextRegionUtil.countStringRegion() allowing to use Region.setBufferCapacity() --- .../classes/com/jogamp/graph/curve/Region.java | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/jogl/classes/com/jogamp/graph/curve/Region.java') 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 @@ -440,6 +440,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> -- cgit v1.2.3