aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogamp/graph
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/jogamp/graph
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/jogamp/graph')
-rw-r--r--src/jogamp/graph/curve/opengl/TextRendererImpl01.java5
-rw-r--r--src/jogamp/graph/curve/opengl/VBORegion2PES2.java16
-rw-r--r--src/jogamp/graph/curve/opengl/VBORegionSPES2.java8
-rw-r--r--src/jogamp/graph/font/JavaFontLoader.java43
-rw-r--r--src/jogamp/graph/font/UbuntuFontLoader.java35
-rw-r--r--src/jogamp/graph/font/typecast/TypecastFont.java2
6 files changed, 69 insertions, 40 deletions
diff --git a/src/jogamp/graph/curve/opengl/TextRendererImpl01.java b/src/jogamp/graph/curve/opengl/TextRendererImpl01.java
index aa3202805..cebe7a19e 100644
--- a/src/jogamp/graph/curve/opengl/TextRendererImpl01.java
+++ b/src/jogamp/graph/curve/opengl/TextRendererImpl01.java
@@ -176,11 +176,10 @@ public class TextRendererImpl01 extends TextRenderer {
if(!isInitialized()){
throw new GLException("TextRendererImpl01: not initialized!");
}
- String fontStrHash = getTextHashCode(font, str, fontSize);
- GlyphString glyphString = strings.get(fontStrHash);
+ GlyphString glyphString = getCachedGlyphString(font, str, fontSize);
if(null == glyphString) {
glyphString = createString(gl, font, fontSize, str, mgl_sharpness.floatValue());
- strings.put(fontStrHash, glyphString);
+ addCachedGlyphString(font, str, fontSize, glyphString);
}
glyphString.renderString3D(pmvMatrix, vp_width, vp_height, texSize);
diff --git a/src/jogamp/graph/curve/opengl/VBORegion2PES2.java b/src/jogamp/graph/curve/opengl/VBORegion2PES2.java
index c424c4ddd..c7c370f6d 100644
--- a/src/jogamp/graph/curve/opengl/VBORegion2PES2.java
+++ b/src/jogamp/graph/curve/opengl/VBORegion2PES2.java
@@ -192,12 +192,12 @@ public class VBORegion2PES2 implements Region{
gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, t_vboIds.get(0));
- gl.glEnableVertexAttribArray(VERTEX_POS_INDX);
- gl.glVertexAttribPointer(VERTEX_POS_INDX, 3, GL2ES2.GL_FLOAT, false, 3 * Buffers.SIZEOF_FLOAT, 0);
+ gl.glEnableVertexAttribArray(VERTEX_ATTR_IDX);
+ gl.glVertexAttribPointer(VERTEX_ATTR_IDX, 3, GL2ES2.GL_FLOAT, false, 3 * Buffers.SIZEOF_FLOAT, 0);
gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, t_vboIds.get(1));
- gl.glEnableVertexAttribArray(TEX_COORD);
- gl.glVertexAttribPointer(TEX_COORD, 2, GL2ES2.GL_FLOAT, false, 2 * Buffers.SIZEOF_FLOAT, 0);
+ gl.glEnableVertexAttribArray(TEXCOORD_ATTR_IDX);
+ gl.glVertexAttribPointer(TEXCOORD_ATTR_IDX, 2, GL2ES2.GL_FLOAT, false, 2 * Buffers.SIZEOF_FLOAT, 0);
gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, t_vboIds.get(2));
gl.glDrawElements(GL2ES2.GL_TRIANGLES, 2 * 3, GL2ES2.GL_UNSIGNED_SHORT, 0);
@@ -332,12 +332,12 @@ public class VBORegion2PES2 implements Region{
GL2ES2 gl = context.getGL().getGL2ES2();
gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, vboIds.get(0));
- gl.glEnableVertexAttribArray(VERTEX_POS_INDX);
- gl.glVertexAttribPointer(VERTEX_POS_INDX, 3, GL2ES2.GL_FLOAT, false, 3 * Buffers.SIZEOF_FLOAT, 0);
+ gl.glEnableVertexAttribArray(VERTEX_ATTR_IDX);
+ gl.glVertexAttribPointer(VERTEX_ATTR_IDX, 3, GL2ES2.GL_FLOAT, false, 3 * Buffers.SIZEOF_FLOAT, 0);
gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, vboIds.get(1));
- gl.glEnableVertexAttribArray(TEX_COORD);
- gl.glVertexAttribPointer(TEX_COORD, 2, GL2ES2.GL_FLOAT, false, 2 * Buffers.SIZEOF_FLOAT, 0);
+ gl.glEnableVertexAttribArray(TEXCOORD_ATTR_IDX);
+ gl.glVertexAttribPointer(TEXCOORD_ATTR_IDX, 2, GL2ES2.GL_FLOAT, false, 2 * Buffers.SIZEOF_FLOAT, 0);
gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, vboIds.get(2));
gl.glDrawElements(GL2ES2.GL_TRIANGLES, triangles.size() * 3, GL2ES2.GL_UNSIGNED_SHORT, 0);
diff --git a/src/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogamp/graph/curve/opengl/VBORegionSPES2.java
index f509dbd58..701549d46 100644
--- a/src/jogamp/graph/curve/opengl/VBORegionSPES2.java
+++ b/src/jogamp/graph/curve/opengl/VBORegionSPES2.java
@@ -134,12 +134,12 @@ public class VBORegionSPES2 implements Region{
GL2ES2 gl = context.getGL().getGL2ES2();
gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, vboIds.get(0));
- gl.glEnableVertexAttribArray(VERTEX_POS_INDX);
- gl.glVertexAttribPointer(VERTEX_POS_INDX, 3, GL2ES2.GL_FLOAT, false, 3 * Buffers.SIZEOF_FLOAT, 0);
+ gl.glEnableVertexAttribArray(VERTEX_ATTR_IDX);
+ gl.glVertexAttribPointer(VERTEX_ATTR_IDX, 3, GL2ES2.GL_FLOAT, false, 3 * Buffers.SIZEOF_FLOAT, 0);
gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, vboIds.get(1));
- gl.glEnableVertexAttribArray(TEX_COORD);
- gl.glVertexAttribPointer(TEX_COORD, 2, GL2ES2.GL_FLOAT, false, 2 * Buffers.SIZEOF_FLOAT, 0);
+ gl.glEnableVertexAttribArray(TEXCOORD_ATTR_IDX);
+ gl.glVertexAttribPointer(TEXCOORD_ATTR_IDX, 2, GL2ES2.GL_FLOAT, false, 2 * Buffers.SIZEOF_FLOAT, 0);
gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, vboIds.get(2));
gl.glDrawElements(GL2ES2.GL_TRIANGLES, triangles.size() * 3, GL2ES2.GL_UNSIGNED_SHORT, 0);
diff --git a/src/jogamp/graph/font/JavaFontLoader.java b/src/jogamp/graph/font/JavaFontLoader.java
index 6769a691a..33505e797 100644
--- a/src/jogamp/graph/font/JavaFontLoader.java
+++ b/src/jogamp/graph/font/JavaFontLoader.java
@@ -58,8 +58,13 @@ public class JavaFontLoader implements FontSet {
javaFontPath = System.getProperty("java.home") + "/lib/fonts/";
}
+ // FIXME: Add cache size to limit memory usage
static final IntObjectHashMap fontMap = new IntObjectHashMap();
+ static boolean is(int bits, int bit) {
+ return 0 != ( bits & bit ) ;
+ }
+
public Font getDefault() {
return get(FAMILY_REGULAR, 0) ; // Sans Serif Regular
}
@@ -71,12 +76,13 @@ public class JavaFontLoader implements FontSet {
}
// 1st process Sans Serif (2 fonts)
- if( 0 == ( style & STYLE_SERIF ) ) {
- if( 0 != ( style & STYLE_BOLD ) ) {
- font = abspath(availableFontFileNames[5]);
+ if( is(style, STYLE_SERIF) ) {
+ if( is(style, STYLE_BOLD) ) {
+ font = abspath(availableFontFileNames[5], family, style);
} else {
- font = abspath(availableFontFileNames[4]);
+ font = abspath(availableFontFileNames[4], family, style);
}
+ fontMap.put( ( family << 8 ) | style, font );
return font;
}
@@ -86,24 +92,24 @@ public class JavaFontLoader implements FontSet {
case FAMILY_MEDIUM:
case FAMILY_CONDENSED:
case FAMILY_REGULAR:
- if( 0 != ( style & STYLE_BOLD ) ) {
- if( 0 != ( style & STYLE_ITALIC ) ) {
- font = abspath(availableFontFileNames[3]);
+ if( is(style, STYLE_BOLD) ) {
+ if( is(style, STYLE_ITALIC) ) {
+ font = abspath(availableFontFileNames[3], family, style);
} else {
- font = abspath(availableFontFileNames[2]);
+ font = abspath(availableFontFileNames[2], family, style);
}
- } else if( 0 != ( style & STYLE_ITALIC ) ) {
- font = abspath(availableFontFileNames[1]);
+ } else if( is(style, STYLE_ITALIC) ) {
+ font = abspath(availableFontFileNames[1], family, style);
} else {
- font = abspath(availableFontFileNames[0]);
+ font = abspath(availableFontFileNames[0], family, style);
}
break;
case FAMILY_MONOSPACED:
- if( 0 != ( style & STYLE_BOLD ) ) {
- font = abspath(availableFontFileNames[7]);
+ if( is(style, STYLE_BOLD) ) {
+ font = abspath(availableFontFileNames[7], family, style);
} else {
- font = abspath(availableFontFileNames[6]);
+ font = abspath(availableFontFileNames[6], family, style);
}
break;
}
@@ -111,8 +117,13 @@ public class JavaFontLoader implements FontSet {
return font;
}
- Font abspath(String fname) {
- return FontFactory.getFontConstr().create(javaFontPath+fname);
+ Font abspath(String fname, int family, int style) {
+ final Font f = FontFactory.getFontConstr().create(javaFontPath+fname);
+ if(null != f) {
+ fontMap.put( ( family << 8 ) | style, f );
+ }
+ return f;
+
}
}
diff --git a/src/jogamp/graph/font/UbuntuFontLoader.java b/src/jogamp/graph/font/UbuntuFontLoader.java
index 77d2cea03..e09ea85e5 100644
--- a/src/jogamp/graph/font/UbuntuFontLoader.java
+++ b/src/jogamp/graph/font/UbuntuFontLoader.java
@@ -27,6 +27,7 @@
*/
package jogamp.graph.font;
+import com.jogamp.common.util.IntObjectHashMap;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontSet;
import com.jogamp.graph.font.FontFactory;
@@ -58,6 +59,9 @@ public class UbuntuFontLoader implements FontSet {
private UbuntuFontLoader() {
}
+ // FIXME: Add cache size to limit memory usage
+ static final IntObjectHashMap fontMap = new IntObjectHashMap();
+
static boolean is(int bits, int bit) {
return 0 != ( bits & bit ) ;
}
@@ -68,7 +72,10 @@ public class UbuntuFontLoader implements FontSet {
public Font get(int family, int style)
{
- Font font = null;
+ Font font = (Font)fontMap.get( ( family << 8 ) | style );
+ if (font != null) {
+ return font;
+ }
switch (family) {
case FAMILY_MONOSPACED:
@@ -76,30 +83,30 @@ public class UbuntuFontLoader implements FontSet {
case FAMILY_REGULAR:
if( is(style, STYLE_BOLD) ) {
if( is(style, STYLE_ITALIC) ) {
- font = abspath(availableFontFileNames[3]);
+ font = abspath(availableFontFileNames[3], family, style);
} else {
- font = abspath(availableFontFileNames[2]);
+ font = abspath(availableFontFileNames[2], family, style);
}
} else if( is(style, STYLE_ITALIC) ) {
- font = abspath(availableFontFileNames[1]);
+ font = abspath(availableFontFileNames[1], family, style);
} else {
- font = abspath(availableFontFileNames[0]);
+ font = abspath(availableFontFileNames[0], family, style);
}
break;
case FAMILY_LIGHT:
if( is(style, STYLE_ITALIC) ) {
- font = abspath(availableFontFileNames[5]);
+ font = abspath(availableFontFileNames[5], family, style);
} else {
- font = abspath(availableFontFileNames[4]);
+ font = abspath(availableFontFileNames[4], family, style);
}
break;
case FAMILY_MEDIUM:
if( is(style, STYLE_ITALIC) ) {
- font = abspath(availableFontFileNames[6]);
+ font = abspath(availableFontFileNames[6], family, style);
} else {
- font = abspath(availableFontFileNames[7]);
+ font = abspath(availableFontFileNames[7], family, style);
}
break;
}
@@ -110,6 +117,16 @@ public class UbuntuFontLoader implements FontSet {
Font abspath(String fname) {
return FontFactory.getFontConstr().create(
Locator.getResource(UbuntuFontLoader.class, relPath+fname).getPath() );
+ }
+
+ Font abspath(String fname, int family, int style) {
+ final Font f = FontFactory.getFontConstr().create(
+ Locator.getResource(UbuntuFontLoader.class, relPath+fname).getPath() );
+ if(null != f) {
+ fontMap.put( ( family << 8 ) | style, f );
+ }
+ return f;
}
+
}
diff --git a/src/jogamp/graph/font/typecast/TypecastFont.java b/src/jogamp/graph/font/typecast/TypecastFont.java
index 546eb85e3..0d018a314 100644
--- a/src/jogamp/graph/font/typecast/TypecastFont.java
+++ b/src/jogamp/graph/font/typecast/TypecastFont.java
@@ -49,6 +49,8 @@ class TypecastFont implements FontInt {
TypecastHMetrics metrics;
final CmapFormat cmapFormat;
int cmapentries;
+
+ // FIXME: Add cache size to limit memory usage ??
IntObjectHashMap char2Glyph;
public TypecastFont(OTFontCollection fontset) {