aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/jogamp/graph/curve/opengl
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-04-01 06:48:52 +0200
committerSven Gothel <[email protected]>2011-04-01 06:48:52 +0200
commit4b8bd5ec58cb2edfb51bd9ee930beb9c539a8a0b (patch)
tree5567f56606ea248707fe002015b90a9635250e91 /src/com/jogamp/graph/curve/opengl
parente8c69e69374b6650e37594ebf104602fb06b548b (diff)
Final core and demo changes for jogl merge
Core: - Region: Cleanup up constant names - Renderer: Add getRenderType() - TextRenderer: Add cache size limit - JavaFontLoader: Add FIXME 'Add cache size to limit memory usage' - UbuntuFontLoader: Add cache and FIXME 'Add cache size to limit memory usage' - TypecastFont: Add FIXME 'Add cache size to limit memory usage ??' Demos: - Relocated and split (main/listener) for jogl merge - Add 's' for screenshot - Text: - Add 'i' for live editing mode (until CR, backspace supported)
Diffstat (limited to 'src/com/jogamp/graph/curve/opengl')
-rw-r--r--src/com/jogamp/graph/curve/opengl/RegionRenderer.java4
-rw-r--r--src/com/jogamp/graph/curve/opengl/Renderer.java14
-rw-r--r--src/com/jogamp/graph/curve/opengl/TextRenderer.java46
3 files changed, 47 insertions, 17 deletions
diff --git a/src/com/jogamp/graph/curve/opengl/RegionRenderer.java b/src/com/jogamp/graph/curve/opengl/RegionRenderer.java
index 746eba636..c1fec10b8 100644
--- a/src/com/jogamp/graph/curve/opengl/RegionRenderer.java
+++ b/src/com/jogamp/graph/curve/opengl/RegionRenderer.java
@@ -59,7 +59,7 @@ public abstract class RegionRenderer extends Renderer {
* @return the resulting Region.
*/
protected Region createRegion(GL2ES2 gl, OutlineShape outlineShape, float sharpness) {
- Region region = RegionFactory.create(gl.getContext(), st, regionType);
+ Region region = RegionFactory.create(gl.getContext(), st, renderType);
outlineShape.transformOutlines(OutlineShape.QUADRATIC_NURBS);
@@ -78,7 +78,7 @@ public abstract class RegionRenderer extends Renderer {
* @return the resulting Region inclusive the generated region
*/
protected Region createRegion(GL2ES2 gl, OutlineShape[] outlineShapes, float sharpness) {
- Region region = RegionFactory.create(gl.getContext(), st, regionType);
+ Region region = RegionFactory.create(gl.getContext(), st, renderType);
int numVertices = region.getNumVertices();
diff --git a/src/com/jogamp/graph/curve/opengl/Renderer.java b/src/com/jogamp/graph/curve/opengl/Renderer.java
index a36cf870b..863928ed4 100644
--- a/src/com/jogamp/graph/curve/opengl/Renderer.java
+++ b/src/com/jogamp/graph/curve/opengl/Renderer.java
@@ -6,7 +6,6 @@ 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;
@@ -34,15 +33,20 @@ public abstract class Renderer {
protected ShaderState st = new ShaderState();
protected PMVMatrix pmvMatrix = new PMVMatrix();
protected GLUniformData mgl_PMVMatrix;
- protected int regionType = Region.SINGLE_PASS;
+ protected int renderType;
protected int vp_width = 0;
protected int vp_height = 0;
private boolean vboSupported = false;
private boolean initialized = false;
- protected Renderer(Vertex.Factory<? extends Vertex> factory, int type) {
- this.regionType = type;
+ /**
+ *
+ * @param factory
+ * @param renderType either {@link com.jogamp.graph.curve.Region#SINGLE_PASS} or {@link com.jogamp.graph.curve.Region#TWO_PASS}
+ */
+ protected Renderer(Vertex.Factory<? extends Vertex> factory, int renderType) {
+ this.renderType = renderType;
this.pointFactory = (null != factory) ? factory : SVertex.factory();
}
@@ -52,6 +56,8 @@ public abstract class Renderer {
public final boolean isVBOSupported() { return vboSupported; }
+ public final int getRenderType() { return renderType; }
+
public final int getWidth() { return vp_width; }
public final int getHeight() { return vp_height; }
diff --git a/src/com/jogamp/graph/curve/opengl/TextRenderer.java b/src/com/jogamp/graph/curve/opengl/TextRenderer.java
index 83f2c93ca..2bb99d27c 100644
--- a/src/com/jogamp/graph/curve/opengl/TextRenderer.java
+++ b/src/com/jogamp/graph/curve/opengl/TextRenderer.java
@@ -1,5 +1,6 @@
package com.jogamp.graph.curve.opengl;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -15,8 +16,6 @@ import com.jogamp.graph.geom.Vertex;
public abstract class TextRenderer extends Renderer {
- protected HashMap<String, GlyphString> strings = new HashMap<String, GlyphString>();
-
/**
* Create a Hardware accelerated Text Renderer.
* @param factory optional Point.Factory for Vertex construction. Default is Vertex.Factory.
@@ -58,22 +57,47 @@ public abstract class TextRenderer extends Renderer {
GlyphString glyphString = new GlyphString(pointFactory, font.getName(), str);
glyphString.createfromFontPath(paths, affineTransform);
- glyphString.generateRegion(gl.getContext(), sharpness, st, regionType);
+ glyphString.generateRegion(gl.getContext(), sharpness, st, renderType);
return glyphString;
}
- protected static String getTextHashCode(Font font, String str, int fontSize) {
- // FIXME: use integer hash code
- return font.getName() + "." + str.hashCode() + "." + fontSize;
- }
-
public void flushCache() {
- Iterator<GlyphString> iterator = strings.values().iterator();
+ Iterator<GlyphString> iterator = stringCacheMap.values().iterator();
while(iterator.hasNext()){
GlyphString glyphString = iterator.next();
glyphString.destroy();
}
- strings.clear();
- }
+ stringCacheMap.clear();
+ stringCacheArray.clear();
+ }
+
+ public final void setCacheMaxSize(int newSize ) { stringCacheMaxSize = newSize; validateCache(0); }
+ public final int getCacheMaxSize() { return stringCacheMaxSize; }
+ 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 GlyphString getCachedGlyphString(Font font, String str, int fontSize) {
+ final String key = font.getName() + "." + str.hashCode() + "." + fontSize;
+ return stringCacheMap.get(key);
+ }
+
+ protected void addCachedGlyphString(Font font, String str, int fontSize, GlyphString glyphString) {
+ final String key = font.getName() + "." + str.hashCode() + "." + fontSize;
+ validateCache(1);
+ stringCacheMap.put(key, glyphString);
+ stringCacheArray.add(stringCacheArray.size(), key);
+ }
+
+ // 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
} \ No newline at end of file