diff options
author | Rami Santina <[email protected]> | 2011-04-08 18:06:21 +0300 |
---|---|---|
committer | Rami Santina <[email protected]> | 2011-04-08 18:06:21 +0300 |
commit | 1218f8e4d4146831ed729cd1eac33d704529a072 (patch) | |
tree | 17bd30d50ed74ce5422e59168d6990f1983176fe /src/jogl/classes/com/jogamp/graph/curve | |
parent | e6de1dcd253ef4d6ba9f584b4ed3540c85c66d2c (diff) | |
parent | c004a86e24fcc1cd026a7d1d52f61e8eafc8058a (diff) |
Merge: merged with sgothel
Diffstat (limited to 'src/jogl/classes/com/jogamp/graph/curve')
3 files changed, 74 insertions, 21 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java index 40161f067..cc21af859 100755 --- a/src/jogl/classes/com/jogamp/graph/curve/Region.java +++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java @@ -30,6 +30,8 @@ package com.jogamp.graph.curve; import java.util.ArrayList;
import com.jogamp.graph.geom.AABBox;
+import jogamp.opengl.Debug;
+
import com.jogamp.graph.geom.Triangle;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.opengl.util.PMVMatrix;
@@ -45,14 +47,23 @@ import com.jogamp.opengl.util.PMVMatrix; * @see RegionFactory, OutlineShape
*/
public interface Region {
+ public static final boolean DEBUG = Debug.debug("graph.curve");
+
/** The vertices index in an OGL object
*/
public static int VERTEX_ATTR_IDX = 0;
+ public static String VERTEX_ATTR_NAME = "v_position";
/** The Texture Coord index in an OGL object
*/
public static int TEXCOORD_ATTR_IDX = 1;
+ public static String TEXCOORD_ATTR_NAME = "texCoord";
+ /** The color index in an OGL object
+ */
+ public static int COLOR_ATTR_IDX = 2;
+ public static String COLOR_ATTR_NAME = "v_color";
+
/** single pass rendering, fast, but AA might not be perfect */
public static int SINGLE_PASS = 1;
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java index c9661b52a..ce3e83692 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java @@ -6,13 +6,14 @@ import javax.media.opengl.fixedfunc.GLMatrixFunc; import jogamp.opengl.Debug; +import com.jogamp.graph.curve.Region; import com.jogamp.graph.geom.Vertex; import com.jogamp.graph.geom.opengl.SVertex; import com.jogamp.opengl.util.PMVMatrix; import com.jogamp.opengl.util.glsl.ShaderState; public abstract class Renderer { - protected static final boolean DEBUG = Debug.debug("CurveRenderer"); + protected static final boolean DEBUG = Region.DEBUG; protected abstract boolean initImpl(GL2ES2 gl); diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java index 44d9a9be3..ee8dfb372 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java @@ -15,7 +15,6 @@ import com.jogamp.graph.font.Font; import com.jogamp.graph.geom.Vertex; public abstract class TextRenderer extends Renderer { - /** * Create a Hardware accelerated Text Renderer. * @param factory optional Point.Factory for Vertex construction. Default is Vertex.Factory. @@ -50,6 +49,9 @@ public abstract class TextRenderer extends Renderer { * @return the resulting GlyphString inclusive the generated region */ public GlyphString createString(GL2ES2 gl, Font font, int size, String str, float sharpness) { + if(DEBUG) { + System.err.println("createString: "+getCacheSize()+"/"+getCacheLimit()+" - "+Font.NAME_UNIQUNAME + " - " + str + " - " + size); + } AffineTransform affineTransform = new AffineTransform(pointFactory); Path2D[] paths = new Path2D[str.length()]; @@ -77,32 +79,71 @@ public abstract class TextRenderer extends Renderer { flushCache(); } - public final void setCacheMaxSize(int newSize ) { stringCacheMaxSize = newSize; validateCache(0); } - public final int getCacheMaxSize() { return stringCacheMaxSize; } + /** + * Sets the cache limit for reusing GlyphString's and their Region. + * Default is {@link #DEFAULT_CACHE_LIMIT}, -1 unlimited, 0 turns cache off, >0 limited + * + * @param newLimit new cache size + * + * @see #DEFAULT_CACHE_LIMIT + */ + public final void setCacheLimit(int newLimit ) { stringCacheLimit = newLimit; validateCache(0); } + public final int getCacheLimit() { return stringCacheLimit; } + + /** + * @return the current utilized cache size, <= {@link #getCacheLimit()} + */ public final int getCacheSize() { return stringCacheArray.size(); } - protected void validateCache(int space) { - while ( getCacheSize() + space > getCacheMaxSize() ) { - String key = stringCacheArray.remove(0); - stringCacheMap.remove(key); + protected final void validateCache(int space) { + if ( getCacheLimit() > 0 ) { + while ( getCacheSize() + space > getCacheLimit() ) { + removeCachedGlyphString(0); + } + } + } + + protected final GlyphString getCachedGlyphString(Font font, String str, int fontSize) { + return stringCacheMap.get(getKey(font, str, fontSize)); + } + + protected final void addCachedGlyphString(Font font, String str, int fontSize, GlyphString glyphString) { + if ( 0 != getCacheLimit() ) { + final String key = getKey(font, str, fontSize); + GlyphString oldGlyphString = stringCacheMap.put(key, glyphString); + if ( null == oldGlyphString ) { + // new entry .. + validateCache(1); + stringCacheArray.add(stringCacheArray.size(), key); + } /// else overwrite is nop .. } } - protected GlyphString getCachedGlyphString(Font font, String str, int fontSize) { - final String key = font.getName(Font.NAME_UNIQUNAME) + "." + str.hashCode() + "." + fontSize; - return stringCacheMap.get(key); + protected final void removeCachedGlyphString(Font font, String str, int fontSize) { + final String key = getKey(font, str, fontSize); + GlyphString glyphString = stringCacheMap.remove(key); + if(null != glyphString) { + glyphString.destroy(); + } + stringCacheArray.remove(key); } - protected void addCachedGlyphString(Font font, String str, int fontSize, GlyphString glyphString) { - final String key = font.getName(Font.NAME_UNIQUNAME) + "." + str.hashCode() + "." + fontSize; - validateCache(1); - stringCacheMap.put(key, glyphString); - stringCacheArray.add(stringCacheArray.size(), key); + protected final void removeCachedGlyphString(int idx) { + final String key = stringCacheArray.remove(idx); + final GlyphString glyphString = stringCacheMap.remove(key); + if(null != glyphString) { + glyphString.destroy(); + } + } + + protected final String getKey(Font font, String str, int fontSize) { + return font.getName(Font.NAME_UNIQUNAME) + "." + str.hashCode() + "." + fontSize; } - // Cache is adding at the end of the array - public static final int DEFAULT_CACHE_SIZE = 32; - private HashMap<String, GlyphString> stringCacheMap = new HashMap<String, GlyphString>(DEFAULT_CACHE_SIZE); - private ArrayList<String> stringCacheArray = new ArrayList<String>(DEFAULT_CACHE_SIZE); - private int stringCacheMaxSize = DEFAULT_CACHE_SIZE; // -1 unlimited, 0 off, >0 limited + /** Default cache limit, see {@link #setCacheLimit(int)} */ + public static final int DEFAULT_CACHE_LIMIT = 256; + + private HashMap<String, GlyphString> stringCacheMap = new HashMap<String, GlyphString>(DEFAULT_CACHE_LIMIT); + private ArrayList<String> stringCacheArray = new ArrayList<String>(DEFAULT_CACHE_LIMIT); + private int stringCacheLimit = DEFAULT_CACHE_LIMIT; }
\ No newline at end of file |