From 8fbb5bb2f4312b52c24375db3055198a18d66319 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 7 Mar 2023 05:25:07 +0100 Subject: Graph: Bring back passing through temp AffineTransform instances (optional, but recommended) --- .../jogamp/graph/curve/opengl/TextRegionUtil.java | 31 ++++++++++++++++++---- src/jogl/classes/com/jogamp/graph/font/Font.java | 30 ++++++++++++--------- .../jogamp/graph/font/typecast/TypecastFont.java | 13 ++++++--- 3 files changed, 53 insertions(+), 21 deletions(-) (limited to 'src/jogl/classes') 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 547a07fba..0547d994a 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java @@ -155,6 +155,15 @@ public class TextRegionUtil { return res; } + /** + * Try using {@link #drawString3D(GL2ES2, int, RegionRenderer, Font, CharSequence, float[], int[], AffineTransform, AffineTransform)} to reuse {@link AffineTransform} instances. + */ + public static AABBox drawString3D(final GL2ES2 gl, final int renderModes, + final RegionRenderer renderer, final Font font, final CharSequence str, + final float[] rgbaColor, final int[/*1*/] sampleCount) { + return drawString3D(gl, renderModes, renderer, font, str, rgbaColor, sampleCount, new AffineTransform(), new AffineTransform()); + } + /** * Render the string in 3D space w.r.t. the font in font em-size [0..1] at the end of an internally temporary {@link GLRegion}. *

@@ -166,7 +175,7 @@ public class TextRegionUtil { *

* In case of a multisampling region renderer, i.e. {@link Region#VBAA_RENDERING_BIT}, recreating the {@link GLRegion} * is a huge performance impact. - * In such case better use {@link #drawString3D(GL2ES2, GLRegion, RegionRenderer, Font, CharSequence, float[], int[])} + * In such case better use {@link #drawString3D(GL2ES2, GLRegion, RegionRenderer, Font, CharSequence, float[], int[], AffineTransform, AffineTransform)} * instead. *

* @param gl the current GL state @@ -176,22 +185,32 @@ public class TextRegionUtil { * @param rgbaColor if {@link Region#hasColorChannel()} RGBA color must be passed, otherwise value is ignored. * @param sampleCount desired multisampling sample count for msaa-rendering. * The actual used scample-count is written back when msaa-rendering is enabled, otherwise the store is untouched. + * @param tmp1 temp {@link AffineTransform} to be reused + * @param tmp2 temp {@link AffineTransform} to be reused * @throws Exception if TextRenderer not initialized * @return the bounding box of the given string from the produced and rendered GLRegion */ public static AABBox drawString3D(final GL2ES2 gl, final int renderModes, final RegionRenderer renderer, final Font font, final CharSequence str, - final float[] rgbaColor, final int[/*1*/] sampleCount) { + final float[] rgbaColor, final int[/*1*/] sampleCount, final AffineTransform tmp1, final AffineTransform tmp2) { if(!renderer.isInitialized()){ throw new GLException("TextRendererImpl01: not initialized!"); } final GLRegion region = GLRegion.create(gl.getGLProfile(), renderModes, null); - final AABBox res = addStringToRegion(region, font, null, str, rgbaColor); + final AABBox res = addStringToRegion(region, font, null, str, rgbaColor, tmp1, tmp2); region.draw(gl, renderer, sampleCount); region.destroy(gl); return res; } + /** + * Try using {@link #drawString3D(GL2ES2, GLRegion, RegionRenderer, Font, CharSequence, float[], int[], AffineTransform, AffineTransform)} to reuse {@link AffineTransform} instances. + */ + public static AABBox drawString3D(final GL2ES2 gl, final GLRegion region, final RegionRenderer renderer, + final Font font, final CharSequence str, final float[] rgbaColor, final int[/*1*/] sampleCount) { + return drawString3D(gl, region, renderer, font, str, rgbaColor, sampleCount, new AffineTransform(), new AffineTransform()); + } + /** * Render the string in 3D space w.r.t. the font in font em-size [0..1] at the end of the given {@link GLRegion}. *

@@ -211,16 +230,18 @@ public class TextRegionUtil { * @param rgbaColor if {@link Region#hasColorChannel()} RGBA color must be passed, otherwise value is ignored. * @param sampleCount desired multisampling sample count for msaa-rendering. * The actual used scample-count is written back when msaa-rendering is enabled, otherwise the store is untouched. + * @param tmp1 temp {@link AffineTransform} to be reused + * @param tmp2 temp {@link AffineTransform} to be reused * @return the bounding box of the given string from the produced and rendered GLRegion * @throws Exception if TextRenderer not initialized */ public static AABBox drawString3D(final GL2ES2 gl, final GLRegion region, final RegionRenderer renderer, final Font font, final CharSequence str, final float[] rgbaColor, - final int[/*1*/] sampleCount) { + final int[/*1*/] sampleCount, final AffineTransform tmp1, final AffineTransform tmp2) { if(!renderer.isInitialized()){ throw new GLException("TextRendererImpl01: not initialized!"); } - final AABBox res = addStringToRegion(region, font, null, str, rgbaColor); + final AABBox res = addStringToRegion(region, font, null, str, rgbaColor, tmp1, tmp2); region.draw(gl, renderer, sampleCount); return res; } diff --git a/src/jogl/classes/com/jogamp/graph/font/Font.java b/src/jogl/classes/com/jogamp/graph/font/Font.java index 907bbde8a..ebebbda06 100644 --- a/src/jogl/classes/com/jogamp/graph/font/Font.java +++ b/src/jogl/classes/com/jogamp/graph/font/Font.java @@ -328,18 +328,30 @@ public interface Font { */ AABBox getMetricBounds(final CharSequence string); + /** + * Try using {@link #getGlyphBounds(CharSequence, AffineTransform, AffineTransform)} to reuse {@link AffineTransform} instances. + */ + AABBox getGlyphBounds(final CharSequence string); + /** * Returns accurate bounding box by taking each glyph's font em-sized bounding box into account. *

* Glyph bounds is based on each glyph's bounding box and `hhea' composed line height. *

* @param string string text + * @param tmp1 temp {@link AffineTransform} to be reused + * @param tmp2 temp {@link AffineTransform} to be reused * @return the bounding box of the given string in font em-size [0..1] * @see #getGlyphBoundsFU(CharSequence) * @see #getGlyphShapeBounds(CharSequence) * @see #getMetricBounds(CharSequence) */ - AABBox getGlyphBounds(final CharSequence string); + AABBox getGlyphBounds(final CharSequence string, final AffineTransform tmp1, final AffineTransform tmp2); + + /** + * Try using {@link #getGlyphBoundsFU(CharSequence, AffineTransform, AffineTransform)} to reuse {@link AffineTransform} instances. + */ + AABBox getGlyphBoundsFU(final CharSequence string); /** * Returns accurate bounding box by taking each glyph's font-units sized bounding box into account. @@ -347,10 +359,12 @@ public interface Font { * Glyph bounds is based on each glyph's bounding box and `hhea' composed line height. *

* @param string string text + * @param tmp1 temp {@link AffineTransform} to be reused + * @param tmp2 temp {@link AffineTransform} to be reused * @return the bounding box of the given string in font-units [0..1] * @see #getGlyphBounds(CharSequence) */ - AABBox getGlyphBoundsFU(final CharSequence string); + AABBox getGlyphBoundsFU(final CharSequence string, final AffineTransform tmp1, final AffineTransform tmp2); /** * Returns accurate bounding box by taking each glyph's font em-sized {@link OutlineShape} into account. @@ -388,16 +402,8 @@ public interface Font { boolean isPrintableChar(final char c); /** - * Visit each {@link Glyph}'s {@link OutlineShape} of the string with the {@link OutlineShape.Visitor} - * while passing the progressed {@link AffineTransform}. - *

- * The produced shapes are in font em-size [0..1], but can be adjusted with the given transform, progressed and passed to the visitor. - *

- * @param visitor handling each glyph's outline shape in font em-size [0..1] and the given {@link AffineTransform} - * @param transform optional given transform - * @param font the target {@link Font} - * @param string string text - * @return the bounding box of the given string by taking each glyph's font em-sized [0..1] {@link OutlineShape} into account. + * Try using {@link #processString(com.jogamp.graph.curve.OutlineShape.Visitor, AffineTransform, CharSequence, AffineTransform, AffineTransform)} + * to reuse {@link AffineTransform} instances. */ AABBox processString(final OutlineShape.Visitor visitor, final AffineTransform transform, final CharSequence string); diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java index aba7d6807..d2137ae36 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java @@ -291,17 +291,22 @@ class TypecastFont implements Font { @Override public AABBox getGlyphBounds(final CharSequence string) { - return getGlyphBoundsFU(string).scale2(1.0f/metrics.getUnitsPerEM(), new float[3]); + return getGlyphBounds(string, new AffineTransform(), new AffineTransform()); + } + @Override + public AABBox getGlyphBounds(final CharSequence string, final AffineTransform tmp1, final AffineTransform tmp2) { + return getGlyphBoundsFU(string, tmp1, tmp2).scale2(1.0f/metrics.getUnitsPerEM(), new float[3]); } @Override public AABBox getGlyphBoundsFU(final CharSequence string) { + return getGlyphBoundsFU(string, new AffineTransform(), new AffineTransform()); + } + @Override + public AABBox getGlyphBoundsFU(final CharSequence string, final AffineTransform temp1, final AffineTransform temp2) { if (null == string || 0 == string.length() ) { return new AABBox(); } - final AffineTransform temp1 = new AffineTransform(); - final AffineTransform temp2 = new AffineTransform(); - final AABBox res = new AABBox(); final int charCount = string.length(); -- cgit v1.2.3