From abc833631e0ab30a06c7aff47a39a551544fd735 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 2 Apr 2014 19:25:16 +0200 Subject: Bug 801: Reduce temp. object creation, i.e. GC load --- .../jogamp/graph/curve/opengl/TextRegionUtil.java | 54 ++++++++++++++++------ 1 file changed, 39 insertions(+), 15 deletions(-) (limited to 'src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java') 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 16b1224bd..f944843e9 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java @@ -63,6 +63,17 @@ public class TextRegionUtil { public void visit(final OutlineShape shape, final AffineTransform t); } + public static int getCharCount(final String s, final char c) { + final int sz = s.length(); + int count = 0; + for(int i=0; i vertexFactory, - final Font font, final float pixelSize, final CharSequence str, final float[] rgbaColor) { + final Font font, final float pixelSize, final CharSequence str, final float[] rgbaColor, + final AffineTransform temp1, final AffineTransform temp2) { final ShapeVisitor visitor = new ShapeVisitor() { public final void visit(final OutlineShape shape, final AffineTransform t) { region.addOutlineShape(shape, t, region.hasColorChannel() ? rgbaColor : null); } }; - processString(visitor, null, font, pixelSize, str); + processString(visitor, null, font, pixelSize, str, temp1, temp2); } /** @@ -163,7 +179,7 @@ public class TextRegionUtil { GLRegion region = getCachedRegion(font, str, pixelSize, special); if(null == region) { region = GLRegion.create(renderModes); - addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str, rgbaColor); + addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str, rgbaColor, tempT1, tempT2); addCachedRegion(gl, font, str, pixelSize, special, region); } region.draw(gl, renderer, sampleCount); @@ -175,7 +191,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, float, CharSequence, float[], int[])} + * In such case better use {@link #drawString3D(GL2ES2, GLRegion, RegionRenderer, Font, float, CharSequence, float[], int[], AffineTransform, AffineTransform)} * instead. *

* @param gl the current GL state @@ -186,16 +202,19 @@ 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 temp1 temporary AffineTransform storage, mandatory + * @param temp2 temporary AffineTransform storage, mandatory * @throws Exception if TextRenderer not initialized */ public static void drawString3D(final GL2ES2 gl, final int renderModes, final RegionRenderer renderer, final Font font, final float pixelSize, - final CharSequence str, final float[] rgbaColor, final int[/*1*/] sampleCount) { + final CharSequence str, final float[] rgbaColor, final int[/*1*/] sampleCount, + final AffineTransform temp1, final AffineTransform temp2) { if(!renderer.isInitialized()){ throw new GLException("TextRendererImpl01: not initialized!"); } final GLRegion region = GLRegion.create(renderModes); - addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str, rgbaColor); + addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str, rgbaColor, temp1, temp2); region.draw(gl, renderer, sampleCount); region.destroy(gl); } @@ -210,16 +229,19 @@ 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 temp1 temporary AffineTransform storage, mandatory + * @param temp2 temporary AffineTransform storage, mandatory * @throws Exception if TextRenderer not initialized */ public static void drawString3D(final GL2ES2 gl, final GLRegion region, final RegionRenderer renderer, final Font font, final float pixelSize, final CharSequence str, - final float[] rgbaColor, final int[/*1*/] sampleCount) { + final float[] rgbaColor, final int[/*1*/] sampleCount, + final AffineTransform temp1, final AffineTransform temp2) { if(!renderer.isInitialized()){ throw new GLException("TextRendererImpl01: not initialized!"); } region.clear(gl); - addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str, rgbaColor); + addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str, rgbaColor, temp1, temp2); region.draw(gl, renderer, sampleCount); } @@ -321,6 +343,8 @@ public class TextRegionUtil { /** Default cache limit, see {@link #setCacheLimit(int)} */ public static final int DEFAULT_CACHE_LIMIT = 256; + public final AffineTransform tempT1 = new AffineTransform(); + public final AffineTransform tempT2 = new AffineTransform(); private final HashMap stringCacheMap = new HashMap(DEFAULT_CACHE_LIMIT); private final ArrayList stringCacheArray = new ArrayList(DEFAULT_CACHE_LIMIT); private int stringCacheLimit = DEFAULT_CACHE_LIMIT; -- cgit v1.2.3