From c3621221b9a563495b4f54fe60e18e8db8cc57fb Mon Sep 17 00:00:00 2001
From: Sven Gothel
Date: Mon, 24 Feb 2014 13:32:34 +0100
Subject: Bug 802: Graph TextRenderer Performance Part-1 (incomplete, rendering
artifacts)
Strategy Change:
- Font.Glyph itself holds it's OutlineShape
with it's default scaling.
Triangulation is done only once per glyph!
- A CharSequence produces a Region
by translating and scaling each Glyphs's OutlineShape.
This removes the need for re-triangulate - see above.
See: TextRendererUtil
- The indices of re-added Triangles are
offset to the new vertices (FIXME, seems not be be accurate yet).
- OutlineShape's vertices and triangles are reused if 'clean'.
- Simplified code
- Reduced copies
API Changes:
- OutlineShape, Region, ...: See above
- Removed TextRenderer, GlyphShape and GlyphString: Redundant
- Added TextRendererUtil to produce the Region from CharSequence
Result:
- Over 600 fps while changing text for each frame.
Previously only ~60fps max.
TODO:
- Region shall not hold the triangles itself,
but the indices instead.
This will remove the need to swizzle w/ vertices in the Region Renderer impl
and easies reusage of OutlineShapes.
---
.../com/jogamp/graph/curve/OutlineShape.java | 125 ++++++--
.../classes/com/jogamp/graph/curve/Region.java | 84 ++++--
.../jogamp/graph/curve/opengl/TextRenderUtil.java | 332 +++++++++++++++++++++
.../jogamp/graph/curve/opengl/TextRenderer.java | 199 ------------
.../com/jogamp/graph/curve/tess/Triangulator.java | 13 +-
src/jogl/classes/com/jogamp/graph/font/Font.java | 9 +-
.../classes/com/jogamp/graph/geom/Outline.java | 9 +-
.../classes/com/jogamp/graph/geom/SVertex.java | 225 ++++++++++++++
.../classes/com/jogamp/graph/geom/Triangle.java | 67 ++++-
src/jogl/classes/com/jogamp/graph/geom/Vertex.java | 4 +
.../com/jogamp/graph/geom/opengl/SVertex.java | 201 -------------
.../graph/curve/opengl/TextRendererImpl01.java | 108 -------
.../jogamp/graph/curve/opengl/VBORegionSPES2.java | 49 +--
.../jogamp/graph/curve/tess/CDTriangulator2D.java | 45 ++-
src/jogl/classes/jogamp/graph/curve/tess/Loop.java | 6 +-
.../jogamp/graph/curve/text/GlyphShape.java | 112 -------
.../jogamp/graph/curve/text/GlyphString.java | 234 ---------------
src/jogl/classes/jogamp/graph/font/FontInt.java | 3 +
.../jogamp/graph/font/typecast/TypecastFont.java | 15 +-
.../jogamp/graph/font/typecast/TypecastGlyph.java | 27 +-
.../graph/font/typecast/TypecastRenderer.java | 137 ++++++++-
.../jogamp/graph/geom/plane/AffineTransform.java | 32 +-
.../classes/jogamp/graph/geom/plane/Path2D.java | 2 +-
23 files changed, 1022 insertions(+), 1016 deletions(-)
create mode 100644 src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderUtil.java
delete mode 100644 src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java
create mode 100644 src/jogl/classes/com/jogamp/graph/geom/SVertex.java
delete mode 100644 src/jogl/classes/com/jogamp/graph/geom/opengl/SVertex.java
delete mode 100644 src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
delete mode 100644 src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java
delete mode 100644 src/jogl/classes/jogamp/graph/curve/text/GlyphString.java
(limited to 'src/jogl/classes')
diff --git a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
index c8d5a9db6..ee1dae4ca 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
@@ -107,15 +107,27 @@ public class OutlineShape implements Comparable {
}
public static final int DIRTY_BOUNDS = 1 << 0;
+ /**
+ * Modified shape, requires to update the vertices and triangles, here: vertices.
+ */
+ public static final int DIRTY_VERTICES = 1 << 1;
+ /**
+ * Modified shape, requires to update the vertices and triangles, here: triangulation.
+ */
+ public static final int DIRTY_TRIANGLES = 1 << 2;
private final Vertex.Factory extends Vertex> vertexFactory;
- private VerticesState outlineState;
/** The list of {@link Outline}s that are part of this
* outline shape.
*/
- /* pp */ ArrayList outlines;
+ /* pp */ final ArrayList outlines;
+
private final AABBox bbox;
+ private final ArrayList triangles;
+ private final ArrayList vertices;
+
+ private VerticesState outlineState;
/** dirty bits DIRTY_BOUNDS */
private int dirtyBits;
@@ -128,6 +140,8 @@ public class OutlineShape implements Comparable {
this.outlines.add(new Outline());
this.outlineState = VerticesState.UNDEFINED;
this.bbox = new AABBox();
+ this.triangles = new ArrayList();
+ this.vertices = new ArrayList();
this.dirtyBits = 0;
}
@@ -137,6 +151,8 @@ public class OutlineShape implements Comparable {
outlines.add(new Outline());
outlineState = VerticesState.UNDEFINED;
bbox.reset();
+ vertices.clear();
+ triangles.clear();
dirtyBits = 0;
}
@@ -200,6 +216,8 @@ public class OutlineShape implements Comparable {
if( 0 == ( dirtyBits & DIRTY_BOUNDS ) ) {
bbox.resize(outline.getBounds());
}
+ // vertices.addAll(outline.getVertices()); // FIXME: can do and remove DIRTY_VERTICES ?
+ dirtyBits |= DIRTY_TRIANGLES | DIRTY_VERTICES;
return;
}
}
@@ -207,6 +225,7 @@ public class OutlineShape implements Comparable {
if( 0 == ( dirtyBits & DIRTY_BOUNDS ) ) {
bbox.resize(outline.getBounds());
}
+ dirtyBits |= DIRTY_TRIANGLES | DIRTY_VERTICES;
}
/** Insert the {@link OutlineShape} elements of type {@link Outline}, .. at the end of this shape,
@@ -239,7 +258,7 @@ public class OutlineShape implements Comparable {
throw new NullPointerException("outline is null");
}
outlines.set(position, outline);
- dirtyBits |= DIRTY_BOUNDS;
+ dirtyBits |= DIRTY_BOUNDS | DIRTY_TRIANGLES | DIRTY_VERTICES;
}
/** Removes the {@link Outline} element at the given {@code position}.
@@ -249,7 +268,7 @@ public class OutlineShape implements Comparable {
* @throws IndexOutOfBoundsException if position is out of range (position < 0 || position >= getOutlineNumber())
*/
public final Outline removeOutline(int position) throws IndexOutOfBoundsException {
- dirtyBits |= DIRTY_BOUNDS;
+ dirtyBits |= DIRTY_BOUNDS | DIRTY_TRIANGLES | DIRTY_VERTICES;
return outlines.remove(position);
}
@@ -278,6 +297,8 @@ public class OutlineShape implements Comparable {
if( 0 == ( dirtyBits & DIRTY_BOUNDS ) ) {
bbox.resize(lo.getBounds());
}
+ // vertices.add(v); // FIXME: can do and remove DIRTY_VERTICES ?
+ dirtyBits |= DIRTY_TRIANGLES | DIRTY_VERTICES;
}
/** Adds a vertex to the last open outline in the shape.
@@ -291,6 +312,7 @@ public class OutlineShape implements Comparable {
if( 0 == ( dirtyBits & DIRTY_BOUNDS ) ) {
bbox.resize(lo.getBounds());
}
+ dirtyBits |= DIRTY_TRIANGLES | DIRTY_VERTICES;
}
/** Add a 2D {@link Vertex} to the last outline by defining the coordniate attribute
@@ -338,7 +360,9 @@ public class OutlineShape implements Comparable {
* is equal to the first.
*/
public void closeLastOutline() {
- getLastOutline().setClosed(true);
+ if( getLastOutline().setClosed(true) ) {
+ dirtyBits |= DIRTY_TRIANGLES | DIRTY_VERTICES;
+ }
}
/**
@@ -348,7 +372,8 @@ public class OutlineShape implements Comparable {
return outlineState;
}
- /** Ensure the outlines represent
+ /**
+ * Ensure the outlines represent
* the specified destinationType.
* and removes all overlaps in boundary triangles
* @param destinationType the target outline's vertices state. Currently only
@@ -376,6 +401,7 @@ public class OutlineShape implements Comparable {
outline.addVertex(index, vertexFactory.create(v1, 0, 3, false));
outline.addVertex(index+2, vertexFactory.create(v3, 0, 3, false));
+ dirtyBits |= DIRTY_VERTICES;
}
/** Check overlaps between curved triangles
@@ -480,10 +506,12 @@ public class OutlineShape implements Comparable {
i++;
vertexCount++;
outline.addVertex(i, v);
+ dirtyBits |= DIRTY_VERTICES;
}
}
if(vertexCount <= 0) {
outlines.remove(outline);
+ dirtyBits |= DIRTY_VERTICES;
cc--;
count--;
continue;
@@ -511,37 +539,90 @@ public class OutlineShape implements Comparable {
}
}
- /** @return the list of concatenated vertices associated with all
- * {@code Outline}s of this object
+ /**
+ * Return list of concatenated vertices associated with all
+ * {@code Outline}s of this object.
+ *
+ * Vertices are cached until marked dirty.
+ *
+ * FIXME: Add memory optimization, i.e. VBO layout
*/
public ArrayList getVertices() {
- ArrayList vertices = new ArrayList();
- for(int i=0; i
+ * Triangles are cached until marked dirty.
+ *
* @return an arraylist of triangles representing the filled region
* which is produced by the combination of the outlines
+ * FIXME: Add memory optimization, i.e. VBO layout
*/
- public ArrayList triangulate() {
- if(outlines.size() == 0){
- return null;
+ public ArrayList getTriangles() {
+ final boolean updated;
+ if( 0 != ( DIRTY_TRIANGLES & dirtyBits ) ) {
+ transformOutlines(OutlineShape.VerticesState.QUADRATIC_NURBS);
+ triangulateImpl();
+ updated = true;
+ } else {
+ updated = false;
}
- sortOutlines();
- generateVertexIds();
-
- Triangulator triangulator2d = Triangulation.create();
- for(int index = 0; index triangles = triangulator2d.generate();
- triangulator2d.reset();
+ return triangles;
+ }
+ /**
+ * Triangulate the {@link OutlineShape} generating a list of triangles,
+ * while {@link #transformOutlines(VerticesState)} beforehand.
+ *
+ * Triangles are cached until marked dirty.
+ *
+ * @return an arraylist of triangles representing the filled region
+ * which is produced by the combination of the outlines
+ * FIXME: Add memory optimization, i.e. VBO layout
+ */
+ public ArrayList getTriangles(VerticesState destinationType) {
+ final boolean updated;
+ if( 0 != ( DIRTY_TRIANGLES & dirtyBits ) ) {
+ transformOutlines(destinationType);
+ triangulateImpl();
+ updated = true;
+ } else {
+ updated = false;
+ }
+ if(Region.DEBUG_INSTANCE) {
+ System.err.println("OutlineShape.getTriangles().2: "+triangles.size()+", updated "+updated);
+ }
return triangles;
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java
index e36e37c26..2b6da2084 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/Region.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java
@@ -31,6 +31,7 @@ import java.util.ArrayList;
import java.util.List;
import jogamp.graph.curve.opengl.RegionFactory;
+import jogamp.graph.geom.plane.AffineTransform;
import jogamp.opengl.Debug;
import com.jogamp.graph.curve.opengl.GLRegion;
@@ -46,8 +47,7 @@ public abstract class Region {
/** Debug flag for region impl (graph.curve) */
public static final boolean DEBUG = Debug.debug("graph.curve");
-
- public static final boolean DEBUG_INSTANCE = false;
+ public static final boolean DEBUG_INSTANCE = Debug.debug("graph.curve.instance");
/** View based Anti-Aliasing, A Two pass region rendering, slower and more
* resource hungry (FBO), but AA is perfect. Otherwise the default fast one
@@ -65,7 +65,9 @@ public abstract class Region {
private boolean dirty = true;
protected int numVertices = 0;
protected final AABBox box = new AABBox();
+ /** FIXME: Think about a rendering storage optimization (VBO ... )! */
protected ArrayList triangles = new ArrayList();
+ /** FIXME: Think about a rendering storage optimization (VBO ... )! */
protected ArrayList vertices = new ArrayList();
public static boolean isVBAA(int renderModes) {
@@ -99,7 +101,7 @@ public abstract class Region {
*/
public static Region create(OutlineShape outlineShape, int renderModes) {
final Region region = RegionFactory.create(renderModes);
- region.addOutlineShape(outlineShape);
+ region.addOutlineShape(outlineShape, null);
return region;
}
@@ -136,27 +138,32 @@ public abstract class Region {
return numVertices;
}
- /** Adds a {@link Triangle} object to the Region This triangle will be bound
- * to OGL objects on the next call to {@code update}
- *
- * @param tri
- * a triangle object
- *
- * @see update(GL2ES2) */
- public void addTriangle(Triangle tri) {
- triangles.add(tri);
- setDirty(true);
- }
-
/** Adds a list of {@link Triangle} objects to the Region These triangles are
* to be binded to OGL objects on the next call to {@code update}
*
* @param tris
* a list of triangle objects
+ * @param idxOffset TODO
*
* @see update(GL2ES2) */
- public void addTriangles(List tris) {
- triangles.addAll(tris);
+ public void addTriangles(List tris, AffineTransform t, int idxOffset) {
+ if( true && null != t ) {
+ for(int i=0; i verts) {
vertices.addAll(verts);
numVertices = vertices.size();
+ if(DEBUG_INSTANCE) {
+ System.err.println("Region.addVertices(): tris: "+triangles.size()+", verts "+vertices.size());
+ }
setDirty(true);
}
- public void addOutlineShape(OutlineShape shape) {
- shape.transformOutlines(OutlineShape.VerticesState.QUADRATIC_NURBS);
- List tris = shape.triangulate();
+ public void addOutlineShape(OutlineShape shape, AffineTransform t) {
+ final List tris = shape.getTriangles(OutlineShape.VerticesState.QUADRATIC_NURBS);
if(null != tris) {
- triangles.addAll(tris);
+ if( false && null != t ) {
+ for(int i=0; i verts = shape.getVertices();
+ // vertices.addAll(verts);
for (int j = 0; j < shape.outlines.size(); j++) {
final ArrayList sovs = shape.outlines.get(j).getVertices();
for (int k = 0; k < sovs.size(); k++) {
- final Vertex v = sovs.get(k);
+ final Vertex v;
+ if( null != t ) {
+ v = t.transform(sovs.get(k), null);
+ } else {
+ v = sovs.get(k);
+ }
v.setId(numVertices++);
vertices.add(v);
}
}
+ // numVertices = vertices.size();
+ }
+ if(DEBUG_INSTANCE) {
+ System.err.println("Region.addOutlineShape(): tris: "+triangles.size()+", verts "+vertices.size());
}
setDirty(true);
}
public void addOutlineShapes(List shapes) {
for (int i = 0; i < shapes.size(); i++) {
- addOutlineShape(shapes.get(i));
+ addOutlineShape(shapes.get(i), null);
+ }
+ if(DEBUG_INSTANCE) {
+ System.err.println("Region.addOutlineShapes(): tris: "+triangles.size()+", verts "+vertices.size());
}
setDirty(true);
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderUtil.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderUtil.java
new file mode 100644
index 000000000..cef589f4f
--- /dev/null
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderUtil.java
@@ -0,0 +1,332 @@
+/**
+ * Copyright 2014 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.graph.curve.opengl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GLException;
+
+import jogamp.graph.curve.opengl.RegionFactory;
+import jogamp.graph.geom.plane.AffineTransform;
+
+import com.jogamp.graph.curve.OutlineShape;
+import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.font.Font;
+import com.jogamp.graph.font.Font.Glyph;
+import com.jogamp.graph.geom.Triangle;
+import com.jogamp.graph.geom.Vertex;
+import com.jogamp.graph.geom.Vertex.Factory;
+
+/**
+ *
+ * FIXME: Add VBO Vertex Factory for drawString3D !
+ *
+ */
+public class TextRenderUtil {
+
+ public final Renderer renderer;
+
+ public TextRenderUtil(final Renderer renderer) {
+ this.renderer = renderer;
+ }
+
+ /**
+ * Generate a Region to represent this Object.
+ *
+ * Each glyph is cached and reused.
+ *
+ *
+ * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#VBAA_RENDERING_BIT}
+ * @param vertexFactory vertex impl factory {@link Factory}
+ * @param font the target {@link Font}
+ * @param str string text
+ * @param pixelSize
+ */
+ public static GLRegion createRegion(final int renderModes, final Factory extends Vertex> vertexFactory,
+ final Font font, final CharSequence str, final int pixelSize) {
+ final int charCount = str.length();
+
+ final GLRegion region = RegionFactory.create(renderModes);
+ // region.setFlipped(true);
+ final Font.Metrics metrics = font.getMetrics();
+
+ final float lineGap = metrics.getLineGap(pixelSize) ;
+ final float ascent = metrics.getAscent(pixelSize) ;
+ final float descent = metrics.getDescent(pixelSize) ;
+ final float advanceY = lineGap - descent + ascent;
+ final float scale = metrics.getScale(pixelSize);
+ final AffineTransform transform = new AffineTransform(vertexFactory);
+ final AffineTransform t = new AffineTransform(vertexFactory);
+
+ float y = 0;
+ float advanceTotal = 0;
+ int numVertices = region.getNumVertices();
+
+ for(int i=0; i< charCount; i++) {
+ final char character = str.charAt(i);
+ if( '\n' == character ) {
+ y += advanceY;
+ advanceTotal = 0;
+ } else if (character == ' ') {
+ advanceTotal += font.getAdvanceWidth(Glyph.ID_SPACE, pixelSize);
+ } else {
+ if(Region.DEBUG_INSTANCE) {
+ System.err.println("XXXXXXXXXXXXXXx char: "+character+", scale: "+scale+"; translate: "+advanceTotal+", "+y);
+ }
+ t.setTransform(transform); // reset transform
+ t.translate(advanceTotal, y);
+ t.scale(scale, scale);
+
+ final Font.Glyph glyph = font.getGlyph(character);
+ final OutlineShape glyphShape = glyph.getShape();
+ if( null == glyphShape || glyphShape.getVertices().size() < 3 ) {
+ continue;
+ }
+ // glyphShape.closeLastOutline();
+
+ if( false ) {
+ region.addOutlineShape(glyphShape, t);
+ } else {
+ final ArrayList trisIn = glyphShape.getTriangles();
+ region.addTriangles(trisIn, t, numVertices);
+
+ final ArrayList gVertices = glyphShape.getVertices();
+ for(int j=0; j vertexFactory,
+ final Font font, final CharSequence str, final int pixelSize) {
+ final List shapesIn = font.getOutlineShapes(null, str, pixelSize, vertexFactory);
+ final ArrayList shapesOut = new ArrayList();
+ final int numGlyps = shapesIn.size();
+ for (int index=0;index gtris = shape.getTriangles();
+ region.addTriangles(gtris, null, 0);
+
+ final ArrayList gVertices = shape.getVertices();
+ for(int j=0; j iterator = stringCacheMap.values().iterator();
+ while(iterator.hasNext()){
+ GlyphString glyphString = iterator.next();
+ glyphString.destroy(gl, rs);
+ }
+ stringCacheMap.clear();
+ stringCacheArray.clear();
+ } */
+
+ public void destroy(GL2ES2 gl) {
+ // fluchCache(gl) already called
+ final Iterator iterator = stringCacheMap.values().iterator();
+ while(iterator.hasNext()){
+ final GLRegion region = iterator.next();
+ region.destroy(gl, renderer.getRenderState());
+ }
+ stringCacheMap.clear();
+ stringCacheArray.clear();
+ }
+
+ /**
+ * 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
+ *
+ * The cache will be validate when the next string rendering happens.
+ *
+ * @param newLimit new cache size
+ *
+ * @see #DEFAULT_CACHE_LIMIT
+ */
+ public final void setCacheLimit(int newLimit ) { stringCacheLimit = newLimit; }
+
+ /**
+ * Sets the cache limit, see {@link #setCacheLimit(int)} and validates the cache.
+ *
+ * @see #setCacheLimit(int)
+ *
+ * @param gl current GL used to remove cached objects if required
+ * @param newLimit new cache size
+ */
+ public final void setCacheLimit(GL2ES2 gl, int newLimit ) { stringCacheLimit = newLimit; validateCache(gl, 0); }
+
+ /**
+ * @return the current cache limit
+ */
+ public final int getCacheLimit() { return stringCacheLimit; }
+
+ /**
+ * @return the current utilized cache size, <= {@link #getCacheLimit()}
+ */
+ public final int getCacheSize() { return stringCacheArray.size(); }
+
+ protected final void validateCache(GL2ES2 gl, int space) {
+ if ( getCacheLimit() > 0 ) {
+ while ( getCacheSize() + space > getCacheLimit() ) {
+ removeCachedRegion(gl, 0);
+ }
+ }
+ }
+
+ protected final GLRegion getCachedRegion(Font font, CharSequence str, int fontSize) {
+ return stringCacheMap.get(getKey(font, str, fontSize));
+ }
+
+ protected final void addCachedRegion(GL2ES2 gl, Font font, CharSequence str, int fontSize, GLRegion glyphString) {
+ if ( 0 != getCacheLimit() ) {
+ final String key = getKey(font, str, fontSize);
+ final GLRegion oldRegion = stringCacheMap.put(key, glyphString);
+ if ( null == oldRegion ) {
+ // new entry ..
+ validateCache(gl, 1);
+ stringCacheArray.add(stringCacheArray.size(), key);
+ } /// else overwrite is nop ..
+ }
+ }
+
+ protected final void removeCachedRegion(GL2ES2 gl, Font font, CharSequence str, int fontSize) {
+ final String key = getKey(font, str, fontSize);
+ GLRegion region = stringCacheMap.remove(key);
+ if(null != region) {
+ region.destroy(gl, renderer.getRenderState());
+ }
+ stringCacheArray.remove(key);
+ }
+
+ protected final void removeCachedRegion(GL2ES2 gl, int idx) {
+ final String key = stringCacheArray.remove(idx);
+ final GLRegion region = stringCacheMap.remove(key);
+ if(null != region) {
+ region.destroy(gl, renderer.getRenderState());
+ }
+ }
+
+ protected final String getKey(Font font, CharSequence str, int fontSize) {
+ final StringBuilder sb = new StringBuilder();
+ return font.getName(sb, Font.NAME_UNIQUNAME)
+ .append(".").append(str.hashCode()).append(".").append(fontSize).toString();
+ }
+
+ /** Default cache limit, see {@link #setCacheLimit(int)} */
+ public static final int DEFAULT_CACHE_LIMIT = 256;
+
+ private final HashMap stringCacheMap = new HashMap(DEFAULT_CACHE_LIMIT);
+ private final ArrayList stringCacheArray = new ArrayList(DEFAULT_CACHE_LIMIT);
+ private int stringCacheLimit = DEFAULT_CACHE_LIMIT;
+}
\ No newline at end of file
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java
deleted file mode 100644
index 44007ca79..000000000
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/**
- * Copyright 2010 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are
- * permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those of the
- * authors and should not be interpreted as representing official policies, either expressed
- * or implied, of JogAmp Community.
- */
-package com.jogamp.graph.curve.opengl;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-
-import javax.media.opengl.GL2ES2;
-
-import jogamp.graph.curve.text.GlyphString;
-
-import com.jogamp.graph.curve.OutlineShape;
-import com.jogamp.graph.font.Font;
-import com.jogamp.graph.geom.Vertex.Factory;
-
-/**
- * @deprecated use {@link com.jogamp.graph.font.Font#getOutlineShapes(java.util.List, CharSequence, float, Factory)},
- * {@link com.jogamp.graph.curve.Region#create(OutlineShape, int)}
- * and a {@link com.jogamp.graph.curve.opengl.RegionRenderer}.
- */
-public abstract class TextRenderer extends Renderer {
- /**
- * Create a Hardware accelerated Text Renderer.
- * @param rs the used {@link RenderState}
- * @param renderModes either {@link com.jogamp.graph.curve.opengl.GLRegion#SINGLE_PASS} or {@link com.jogamp.graph.curve.Region#VBAA_RENDERING_BIT}
- */
- public static TextRenderer create(RenderState rs, int renderModes) {
- return new jogamp.graph.curve.opengl.TextRendererImpl01(rs, renderModes);
- }
-
- protected TextRenderer(RenderState rs, int type) {
- super(rs, type);
- }
-
-
- /** Render the String in 3D space wrt to the font provided at the position provided
- * the outlines will be generated, if not yet generated
- * @param gl the current GL state
- * @param font {@link Font} to be used
- * @param str text to be rendered
- * @param fontSize font size
- * @param texWidth desired texture width for multipass-rendering.
- * The actual used texture-width is written back when mp rendering is enabled, otherwise the store is untouched.
- * @throws Exception if TextRenderer not initialized
- */
- public abstract void drawString3D(GL2ES2 gl, Font font,
- String str, int fontSize, int[/*1*/] texSize);
-
- /**Create the resulting {@link GlyphString} that represents
- * the String wrt to the font.
- * @param font {@link Font} to be used
- * @param size font size
- * @param str {@link String} to be created
- * @return the resulting GlyphString inclusive the generated region
- */
- public GlyphString createString(GL2ES2 gl, Font font, int size, String str) {
- if(DEBUG_INSTANCE) {
- System.err.println("createString: "+getCacheSize()+"/"+getCacheLimit()+" - "+Font.NAME_UNIQUNAME + " - " + str + " - " + size);
- }
- final GlyphString glyphString = GlyphString.createString(null, rs.getVertexFactory(), font, size, str);
- glyphString.createRegion(gl, renderModes);
- return glyphString;
- }
-
- /** FIXME
- public void flushCache(GL2ES2 gl) {
- Iterator iterator = stringCacheMap.values().iterator();
- while(iterator.hasNext()){
- GlyphString glyphString = iterator.next();
- glyphString.destroy(gl, rs);
- }
- stringCacheMap.clear();
- stringCacheArray.clear();
- } */
-
- @Override
- protected void destroyImpl(GL2ES2 gl) {
- // fluchCache(gl) already called
- Iterator iterator = stringCacheMap.values().iterator();
- while(iterator.hasNext()){
- GlyphString glyphString = iterator.next();
- glyphString.destroy(gl, rs);
- }
- stringCacheMap.clear();
- stringCacheArray.clear();
- }
-
- /**
- * 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
- *
- * The cache will be validate when the next string rendering happens.
- *
- * @param newLimit new cache size
- *
- * @see #DEFAULT_CACHE_LIMIT
- */
- public final void setCacheLimit(int newLimit ) { stringCacheLimit = newLimit; }
-
- /**
- * Sets the cache limit, see {@link #setCacheLimit(int)} and validates the cache.
- *
- * @see #setCacheLimit(int)
- *
- * @param gl current GL used to remove cached objects if required
- * @param newLimit new cache size
- */
- public final void setCacheLimit(GL2ES2 gl, int newLimit ) { stringCacheLimit = newLimit; validateCache(gl, 0); }
-
- /**
- * @return the current cache limit
- */
- public final int getCacheLimit() { return stringCacheLimit; }
-
- /**
- * @return the current utilized cache size, <= {@link #getCacheLimit()}
- */
- public final int getCacheSize() { return stringCacheArray.size(); }
-
- protected final void validateCache(GL2ES2 gl, int space) {
- if ( getCacheLimit() > 0 ) {
- while ( getCacheSize() + space > getCacheLimit() ) {
- removeCachedGlyphString(gl, 0);
- }
- }
- }
-
- protected final GlyphString getCachedGlyphString(Font font, String str, int fontSize) {
- return stringCacheMap.get(getKey(font, str, fontSize));
- }
-
- protected final void addCachedGlyphString(GL2ES2 gl, 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(gl, 1);
- stringCacheArray.add(stringCacheArray.size(), key);
- } /// else overwrite is nop ..
- }
- }
-
- protected final void removeCachedGlyphString(GL2ES2 gl, Font font, String str, int fontSize) {
- final String key = getKey(font, str, fontSize);
- GlyphString glyphString = stringCacheMap.remove(key);
- if(null != glyphString) {
- glyphString.destroy(gl, rs);
- }
- stringCacheArray.remove(key);
- }
-
- protected final void removeCachedGlyphString(GL2ES2 gl, int idx) {
- final String key = stringCacheArray.remove(idx);
- final GlyphString glyphString = stringCacheMap.remove(key);
- if(null != glyphString) {
- glyphString.destroy(gl, rs);
- }
- }
-
- protected final String getKey(Font font, String str, int fontSize) {
- final StringBuilder sb = new StringBuilder();
- return font.getName(sb, Font.NAME_UNIQUNAME)
- .append(".").append(str.hashCode()).append(".").append(fontSize).toString();
- }
-
- /** Default cache limit, see {@link #setCacheLimit(int)} */
- public static final int DEFAULT_CACHE_LIMIT = 256;
-
- private final HashMap stringCacheMap = new HashMap(DEFAULT_CACHE_LIMIT);
- private final ArrayList stringCacheArray = new ArrayList(DEFAULT_CACHE_LIMIT);
- private int stringCacheLimit = DEFAULT_CACHE_LIMIT;
-}
\ No newline at end of file
diff --git a/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java b/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java
index 4e8c400e0..39e84171b 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java
@@ -28,7 +28,7 @@
package com.jogamp.graph.curve.tess;
-import java.util.ArrayList;
+import java.util.List;
import com.jogamp.graph.geom.Outline;
import com.jogamp.graph.geom.Triangle;
@@ -49,18 +49,19 @@ import com.jogamp.graph.geom.Triangle;
*/
public interface Triangulator {
- /** Add a curve to the list of Outlines
+ /**
+ * Add a curve to the list of Outlines
* describing the shape
+ * @param sink list where the generated triangles will be added
* @param outline a bounding {@link Outline}
*/
- public void addCurve(Outline outline);
+ public void addCurve(List sink, Outline outline);
/** Generate the triangulation of the provided
* List of {@link Outline}s
- * @return an arraylist of {@link Triangle}s resembling the
- * final shape.
+ * @param sink list where the generated triangles will be added
*/
- public ArrayList generate();
+ public void generate(List sink);
/** Reset the triangulation to initial state
* Clearing cached data
diff --git a/src/jogl/classes/com/jogamp/graph/font/Font.java b/src/jogl/classes/com/jogamp/graph/font/Font.java
index 6c0041de9..1e0572037 100644
--- a/src/jogl/classes/com/jogamp/graph/font/Font.java
+++ b/src/jogl/classes/com/jogamp/graph/font/Font.java
@@ -91,6 +91,7 @@ public interface Font {
public float getScale(float pixelSize);
public AABBox getBBox(float pixelSize);
public float getAdvance(float pixelSize, boolean useFrationalMetrics);
+ public OutlineShape getShape();
public int hashCode();
}
@@ -117,13 +118,7 @@ public interface Font {
public boolean isPrintableChar( char c );
/**
- * @param glyph source of the created OutlineShape
- * @param vertexFactory factory for vertices
- * @return OutlineShape of the glyph
- */
- public OutlineShape getOutlineShape(Glyph glyph, Factory extends Vertex> vertexFactory);
-
- /**
+ * @deprecated Remove altogether - use {@link #getOutlineShape(Glyph, Factory)
* @param shapes optional storage of OutlineShapes passed by user, new shapes are appended
* @param string source of the created OutlineShapes
* @param pixelSize
diff --git a/src/jogl/classes/com/jogamp/graph/geom/Outline.java b/src/jogl/classes/com/jogamp/graph/geom/Outline.java
index 77a318078..26eba2741 100644
--- a/src/jogl/classes/com/jogamp/graph/geom/Outline.java
+++ b/src/jogl/classes/com/jogamp/graph/geom/Outline.java
@@ -156,17 +156,20 @@ public class Outline implements Cloneable, Comparable {
* equal to the first vertex. If not Equal adds a
* vertex at the end to the list.
* @param closed
+ * @return true if closing performed, otherwise false for NOP
*/
- public final void setClosed(boolean closed) {
+ public final boolean setClosed(boolean closed) {
this.closed = closed;
if( closed && !isEmpty() ) {
- Vertex first = vertices.get(0);
- Vertex last = getLastVertex();
+ final Vertex first = vertices.get(0);
+ final Vertex last = getLastVertex();
if(!VectorUtil.checkEquality(first.getCoord(), last.getCoord())){
Vertex v = first.clone();
vertices.add(v);
+ return true;
}
}
+ return false;
}
/** Compare two outlines with Bounding Box area
diff --git a/src/jogl/classes/com/jogamp/graph/geom/SVertex.java b/src/jogl/classes/com/jogamp/graph/geom/SVertex.java
new file mode 100644
index 000000000..99f10a694
--- /dev/null
+++ b/src/jogl/classes/com/jogamp/graph/geom/SVertex.java
@@ -0,0 +1,225 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.graph.geom;
+
+import com.jogamp.opengl.math.VectorUtil;
+
+/** A Simple Vertex Implementation. Where the coordinates, and other attributes are
+ * float based, and the coordinates and texture coordinates are saved in two float arrays.
+ *
+ */
+public class SVertex implements Vertex {
+ private int id;
+ protected final float[] coord = new float[3];
+ protected boolean onCurve;
+ private final float[] texCoord = new float[2];
+
+ static final Factory factory = new Factory();
+
+ public static Factory factory() { return factory; }
+
+ public static class Factory implements Vertex.Factory {
+ @Override
+ public SVertex create() {
+ return new SVertex();
+ }
+
+ public SVertex create(final Vertex src) {
+ return new SVertex(src);
+ }
+
+ @Override
+ public SVertex create(final int id, final boolean onCurve, final float[] texCoordsBuffer) {
+ return new SVertex(id, onCurve, texCoordsBuffer);
+ }
+
+ @Override
+ public SVertex create(final float x, final float y, final float z, final boolean onCurve) {
+ return new SVertex(x, y, z, onCurve);
+ }
+
+ @Override
+ public SVertex create(float[] coordsBuffer, int offset, int length, boolean onCurve) {
+ return new SVertex(coordsBuffer, offset, length, onCurve);
+ }
+ }
+
+ public SVertex() {
+ this.id = Integer.MAX_VALUE;
+ }
+
+ public SVertex(final Vertex src) {
+ this.id = src.getId();
+ System.arraycopy(src.getCoord(), 0, coord, 0, 3);
+ setOnCurve(src.isOnCurve());
+ System.arraycopy(src.getTexCoord(), 0, texCoord, 0, 2);
+ }
+
+ public SVertex(final int id, final boolean onCurve, final float[] texCoordsBuffer) {
+ this.id = id;
+ this.onCurve = onCurve;
+ System.arraycopy(texCoordsBuffer, 0, texCoord, 0, 2);
+ }
+
+ public SVertex(final float x, final float y, final float z, final boolean onCurve) {
+ this.id = Integer.MAX_VALUE;
+ setCoord(x, y, z);
+ setOnCurve(onCurve);
+ }
+
+ public SVertex(final float[] coordsBuffer, final int offset, final int length, final boolean onCurve) {
+ this.id = Integer.MAX_VALUE;
+ setCoord(coordsBuffer, offset, length);
+ setOnCurve(onCurve);
+ }
+
+ public SVertex(float[] coordsBuffer, float[] texCoordsBuffer, boolean onCurve) {
+ this.id = Integer.MAX_VALUE;
+ System.arraycopy(coordsBuffer, 0, coord, 0, 3);
+ System.arraycopy(texCoordsBuffer, 0, texCoord, 0, 2);
+ setOnCurve(onCurve);
+ }
+
+ @Override
+ public final void setCoord(float x, float y, float z) {
+ coord[0] = x;
+ coord[1] = y;
+ coord[2] = z;
+ }
+
+ @Override
+ public final void setCoord(float[] coordsBuffer, int offset, int length) {
+ System.arraycopy(coordsBuffer, offset, coord, 0, length);
+ }
+
+ @Override
+ public int getCoordCount() {
+ return 3;
+ }
+
+ @Override
+ public final float[] getCoord() {
+ return coord;
+ }
+
+ @Override
+ public final void setX(float x) {
+ this.coord[0] = x;
+ }
+
+ @Override
+ public final void setY(float y) {
+ this.coord[1] = y;
+ }
+
+ @Override
+ public final void setZ(float z) {
+ this.coord[2] = z;
+ }
+
+ @Override
+ public final float getX() {
+ return this.coord[0];
+ }
+
+ @Override
+ public final float getY() {
+ return this.coord[1];
+ }
+
+ @Override
+ public final float getZ() {
+ return this.coord[2];
+ }
+
+ @Override
+ public final boolean isOnCurve() {
+ return onCurve;
+ }
+
+ @Override
+ public final void setOnCurve(boolean onCurve) {
+ this.onCurve = onCurve;
+ }
+
+ @Override
+ public final int getId(){
+ return id;
+ }
+
+ @Override
+ public final void setId(int id){
+ this.id = id;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if( obj == this) {
+ return true;
+ }
+ if( null == obj || !(obj instanceof Vertex) ) {
+ return false;
+ }
+ final Vertex v = (Vertex) obj;
+ return this == v ||
+ isOnCurve() == v.isOnCurve() &&
+ VectorUtil.checkEqualityVec2(getTexCoord(), v.getTexCoord()) &&
+ VectorUtil.checkEquality(getCoord(), v.getCoord()) ;
+ }
+
+ @Override
+ public final float[] getTexCoord() {
+ return texCoord;
+ }
+
+ @Override
+ public final void setTexCoord(float s, float t) {
+ texCoord[0] = s;
+ texCoord[1] = t;
+ }
+
+ @Override
+ public final void setTexCoord(float[] texCoordsBuffer, int offset, int length) {
+ System.arraycopy(texCoordsBuffer, offset, texCoord, 0, length);
+ }
+
+ /**
+ * @return deep clone of this Vertex elements
+ */
+ @Override
+ public SVertex clone(){
+ return new SVertex(this.coord, this.texCoord, this.onCurve);
+ }
+
+ @Override
+ public String toString() {
+ return "[ID: " + id + ", onCurve: " + onCurve +
+ ": p " + coord[0] + ", " + coord[1] + ", " + coord[2] +
+ ", t " + texCoord[0] + ", " + texCoord[1] + "]";
+ }
+}
diff --git a/src/jogl/classes/com/jogamp/graph/geom/Triangle.java b/src/jogl/classes/com/jogamp/graph/geom/Triangle.java
index a01cd834f..6de99c48b 100644
--- a/src/jogl/classes/com/jogamp/graph/geom/Triangle.java
+++ b/src/jogl/classes/com/jogamp/graph/geom/Triangle.java
@@ -27,14 +27,52 @@
*/
package com.jogamp.graph.geom;
+import com.jogamp.graph.curve.Region;
+
+import jogamp.graph.geom.plane.AffineTransform;
+
public class Triangle {
- private int id = Integer.MAX_VALUE;
- final private Vertex[] vertices;
- private boolean[] boundaryEdges = new boolean[3];
+ private final Vertex[] vertices = new Vertex[3];
+ private final boolean[] boundaryEdges = new boolean[3];
private boolean[] boundaryVertices = null;
+ private int id;
+
+ public Triangle(Vertex v1, Vertex v2, Vertex v3) {
+ id = Integer.MAX_VALUE;
+ vertices[0] = v1;
+ vertices[1] = v2;
+ vertices[2] = v3;
+ }
+
+ public Triangle(Triangle src) {
+ id = src.id;
+ vertices[0] = src.vertices[0].clone();
+ vertices[1] = src.vertices[1].clone();
+ vertices[2] = src.vertices[2].clone();
+ System.arraycopy(src.boundaryEdges, 0, boundaryEdges, 0, 3);
+ boundaryVertices = src.boundaryVertices;
+ }
+
+ private Triangle(final int id, final boolean[] boundaryEdges, final boolean[] boundaryVertices){
+ this.id = id;
+ System.arraycopy(boundaryEdges, 0, this.boundaryEdges, 0, 3);
+ this.boundaryVertices = boundaryVertices;
+ /**
+ if( null != boundaryVertices ) {
+ this.boundaryVertices = new boolean[3];
+ System.arraycopy(boundaryVertices, 0, this.boundaryVertices, 0, 3);
+ } */
+ }
- public Triangle(Vertex ... v123){
- vertices = v123;
+ /**
+ * Returns a transformed a clone of this instance using the given AffineTransform.
+ */
+ public Triangle transform(AffineTransform t) {
+ final Triangle tri = new Triangle(id, boundaryEdges, boundaryVertices);
+ tri.vertices[0] = t.transform(vertices[0], null);
+ tri.vertices[1] = t.transform(vertices[1], null);
+ tri.vertices[2] = t.transform(vertices[2], null);
+ return tri;
}
public int getId() {
@@ -45,6 +83,21 @@ public class Triangle {
this.id = id;
}
+ public void addVertexIndicesOffset(int offset) {
+ if( 0 < offset ) {
+ final int i0 = vertices[0].getId();
+ if( Integer.MAX_VALUE-offset > i0 ) { // Integer.MAX_VALUE != i0 // FIXME: renderer uses SHORT!
+ if(Region.DEBUG_INSTANCE) {
+ System.err.println("Triangle.addVertexIndicesOffset: "+i0+" + "+offset+" -> "+(i0+offset));
+ }
+ vertices[0].setId(i0+offset);
+ vertices[1].setId(vertices[1].getId()+offset);
+ vertices[2].setId(vertices[2].getId()+offset);
+ }
+ }
+ }
+
+ /** Returns array of 3 vertices, denominating the triangle. */
public Vertex[] getVertices() {
return vertices;
}
@@ -57,10 +110,6 @@ public class Triangle {
return boundaryVertices[0] || boundaryVertices[1] || boundaryVertices[2];
}
- public void setEdgesBoundary(boolean[] boundary) {
- this.boundaryEdges = boundary;
- }
-
public boolean[] getEdgeBoundary() {
return boundaryEdges;
}
diff --git a/src/jogl/classes/com/jogamp/graph/geom/Vertex.java b/src/jogl/classes/com/jogamp/graph/geom/Vertex.java
index 994253f71..fc9590ae7 100644
--- a/src/jogl/classes/com/jogamp/graph/geom/Vertex.java
+++ b/src/jogl/classes/com/jogamp/graph/geom/Vertex.java
@@ -37,6 +37,10 @@ public interface Vertex extends Vert3fImmutable, Cloneable {
public static interface Factory {
T create();
+ T create(Vertex src);
+
+ T create(int id, boolean onCurve, float[] texCoordsBuffer);
+
T create(float x, float y, float z, boolean onCurve);
T create(float[] coordsBuffer, int offset, int length, boolean onCurve);
diff --git a/src/jogl/classes/com/jogamp/graph/geom/opengl/SVertex.java b/src/jogl/classes/com/jogamp/graph/geom/opengl/SVertex.java
deleted file mode 100644
index b27604a44..000000000
--- a/src/jogl/classes/com/jogamp/graph/geom/opengl/SVertex.java
+++ /dev/null
@@ -1,201 +0,0 @@
-/**
- * Copyright 2010 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are
- * permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those of the
- * authors and should not be interpreted as representing official policies, either expressed
- * or implied, of JogAmp Community.
- */
-package com.jogamp.graph.geom.opengl;
-
-import com.jogamp.graph.geom.Vertex;
-import com.jogamp.opengl.math.VectorUtil;
-
-/** A Simple Vertex Implementation. Where the coordinates, and other attributes are
- * float based, and the coordinates and texture coordinates are saved in two float arrays.
- *
- */
-public class SVertex implements Vertex {
- private int id = Integer.MAX_VALUE;
- protected float[] coord = new float[3];
- protected boolean onCurve;
- private float[] texCoord = new float[2];
-
- static final Factory factory = new Factory();
-
- public static Factory factory() { return factory; }
-
- public static class Factory implements Vertex.Factory {
- @Override
- public SVertex create() {
- return new SVertex();
- }
-
- @Override
- public SVertex create(float x, float y, float z, boolean onCurve) {
- return new SVertex(x, y, z, onCurve);
- }
-
- @Override
- public SVertex create(float[] coordsBuffer, int offset, int length, boolean onCurve) {
- return new SVertex(coordsBuffer, offset, length, onCurve);
- }
- }
-
- public SVertex() {
- }
-
- public SVertex(float x, float y, float z, boolean onCurve) {
- setCoord(x, y, z);
- setOnCurve(onCurve);
- }
-
- public SVertex(float[] coordsBuffer, int offset, int length, boolean onCurve) {
- setCoord(coordsBuffer, offset, length);
- setOnCurve(onCurve);
- }
-
- public SVertex(float[] coordsBuffer, int offset, int length,
- float[] texCoordsBuffer, int offsetTC, int lengthTC, boolean onCurve) {
- setCoord(coordsBuffer, offset, length);
- setTexCoord(texCoordsBuffer, offsetTC, lengthTC);
- setOnCurve(onCurve);
- }
-
- @Override
- public final void setCoord(float x, float y, float z) {
- this.coord[0] = x;
- this.coord[1] = y;
- this.coord[2] = z;
- }
-
- @Override
- public final void setCoord(float[] coordsBuffer, int offset, int length) {
- System.arraycopy(coordsBuffer, offset, coord, 0, length);
- }
-
- @Override
- public int getCoordCount() {
- return 3;
- }
-
- @Override
- public final float[] getCoord() {
- return coord;
- }
-
- @Override
- public final void setX(float x) {
- this.coord[0] = x;
- }
-
- @Override
- public final void setY(float y) {
- this.coord[1] = y;
- }
-
- @Override
- public final void setZ(float z) {
- this.coord[2] = z;
- }
-
- @Override
- public final float getX() {
- return this.coord[0];
- }
-
- @Override
- public final float getY() {
- return this.coord[1];
- }
-
- @Override
- public final float getZ() {
- return this.coord[2];
- }
-
- @Override
- public final boolean isOnCurve() {
- return onCurve;
- }
-
- @Override
- public final void setOnCurve(boolean onCurve) {
- this.onCurve = onCurve;
- }
-
- @Override
- public final int getId(){
- return id;
- }
-
- @Override
- public final void setId(int id){
- this.id = id;
- }
-
- @Override
- public boolean equals(Object obj) {
- if( obj == this) {
- return true;
- }
- if( null == obj || !(obj instanceof Vertex) ) {
- return false;
- }
- final Vertex v = (Vertex) obj;
- return this == v ||
- isOnCurve() == v.isOnCurve() &&
- VectorUtil.checkEqualityVec2(getTexCoord(), v.getTexCoord()) &&
- VectorUtil.checkEquality(getCoord(), v.getCoord()) ;
- }
-
- @Override
- public final float[] getTexCoord() {
- return texCoord;
- }
-
- @Override
- public final void setTexCoord(float s, float t) {
- this.texCoord[0] = s;
- this.texCoord[1] = t;
- }
-
- @Override
- public final void setTexCoord(float[] texCoordsBuffer, int offset, int length) {
- System.arraycopy(texCoordsBuffer, offset, texCoord, 0, length);
- }
-
- /**
- * @return deep clone of this Vertex, but keeping the id blank
- */
- @Override
- public SVertex clone(){
- return new SVertex(this.coord, 0, 3, this.texCoord, 0, 2, this.onCurve);
- }
-
- @Override
- public String toString() {
- return "[ID: " + id + ", onCurve: " + onCurve +
- ": p " + coord[0] + ", " + coord[1] + ", " + coord[2] +
- ", t " + texCoord[0] + ", " + texCoord[1] + "]";
- }
-}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java b/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
deleted file mode 100644
index c3c7e0cac..000000000
--- a/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * Copyright 2010 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are
- * permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those of the
- * authors and should not be interpreted as representing official policies, either expressed
- * or implied, of JogAmp Community.
- */
-package jogamp.graph.curve.opengl;
-
-import javax.media.opengl.GL2ES2;
-import javax.media.opengl.GLException;
-
-import jogamp.graph.curve.opengl.shader.AttributeNames;
-import jogamp.graph.curve.text.GlyphString;
-
-import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.curve.opengl.TextRenderer;
-import com.jogamp.graph.font.Font;
-import com.jogamp.opengl.GLExtensions;
-import com.jogamp.opengl.util.glsl.ShaderCode;
-import com.jogamp.opengl.util.glsl.ShaderProgram;
-import com.jogamp.opengl.util.glsl.ShaderState;
-
-public class TextRendererImpl01 extends TextRenderer {
- public TextRendererImpl01(RenderState rs, int type) {
- super(rs, type);
- }
-
- @Override
- protected boolean initShaderProgram(GL2ES2 gl){
- final ShaderState st = rs.getShaderState();
-
- final ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, TextRendererImpl01.class, "shader",
- "shader/bin", getVertexShaderName(), true);
- final ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, TextRendererImpl01.class, "shader",
- "shader/bin", getFragmentShaderName(), true);
- rsVp.defaultShaderCustomization(gl, true, true);
- // rsFp.defaultShaderCustomization(gl, true, true);
- int pos = rsFp.addGLSLVersion(gl);
- if( gl.isGLES() ) {
- pos = rsFp.insertShaderSource(0, pos, ShaderCode.createExtensionDirective(GLExtensions.OES_standard_derivatives, ShaderCode.ENABLE));
- }
- final String rsFpDefPrecision = getFragmentShaderPrecision(gl);
- if( null != rsFpDefPrecision ) {
- rsFp.insertShaderSource(0, pos, rsFpDefPrecision);
- }
-
- final ShaderProgram sp = new ShaderProgram();
- sp.add(rsVp);
- sp.add(rsFp);
-
- if( !sp.init(gl) ) {
- throw new GLException("RegionRenderer: Couldn't init program: "+sp);
- }
- st.attachShaderProgram(gl, sp, false);
- st.bindAttribLocation(gl, AttributeNames.VERTEX_ATTR_IDX, AttributeNames.VERTEX_ATTR_NAME);
- st.bindAttribLocation(gl, AttributeNames.TEXCOORD_ATTR_IDX, AttributeNames.TEXCOORD_ATTR_NAME);
-
- if(!sp.link(gl, System.err)) {
- throw new GLException("TextRendererImpl01: Couldn't link program: "+sp);
- }
- st.useProgram(gl, true);
-
- if(DEBUG) {
- System.err.println("TextRendererImpl01 initialized: " + Thread.currentThread()+" "+st);
- }
- return true;
- }
-
- @Override
- protected void destroyImpl(GL2ES2 gl) {
- super.destroyImpl(gl);
- }
-
- @Override
- public void drawString3D(GL2ES2 gl, Font font, String str, int fontSize, int[/*1*/] texSize) {
- if(!isInitialized()){
- throw new GLException("TextRendererImpl01: not initialized!");
- }
- GlyphString glyphString = getCachedGlyphString(font, str, fontSize);
- if(null == glyphString) {
- glyphString = createString(gl, font, fontSize, str);
- addCachedGlyphString(gl, font, str, fontSize, glyphString);
- }
-
- glyphString.renderString3D(gl, rs, vp_width, vp_height, texSize);
- }
-}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
index 9feb18a12..3cc6152b2 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
@@ -42,7 +42,7 @@ import com.jogamp.opengl.util.glsl.ShaderState;
public class VBORegionSPES2 extends GLRegion {
private GLArrayDataServer verticeAttr = null;
private GLArrayDataServer texCoordAttr = null;
- private GLArrayDataServer indices = null;
+ private GLArrayDataServer indicesBuffer = null;
protected VBORegionSPES2(int renderModes) {
super(renderModes);
@@ -54,11 +54,11 @@ public class VBORegionSPES2 extends GLRegion {
return;
}
- if(null == indices) {
+ if(null == indicesBuffer) {
final int initialElementCount = 256;
final ShaderState st = rs.getShaderState();
- indices = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ indicesBuffer = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
verticeAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT,
false, initialElementCount, GL.GL_STATIC_DRAW);
@@ -73,9 +73,12 @@ public class VBORegionSPES2 extends GLRegion {
}
}
+ if(DEBUG_INSTANCE) {
+ System.err.println("VBORegionSPES2 Indices of "+triangles.size()+", triangles");
+ }
// process triangles
- indices.seal(gl, false);
- indices.rewind();
+ indicesBuffer.seal(gl, false);
+ indicesBuffer.rewind();
for(int i=0; i loops;
- private ArrayList vertices;
+ // FIXME ? private ArrayList vertices;
- private ArrayList triangles;
private int maxTriID = 0;
@@ -68,13 +67,12 @@ public class CDTriangulator2D implements Triangulator{
@Override
public void reset() {
maxTriID = 0;
- vertices = new ArrayList();
- triangles = new ArrayList(3);
+ // vertices = new ArrayList();
loops = new ArrayList();
}
@Override
- public void addCurve(Outline polyline) {
+ public void addCurve(List sink, Outline polyline) {
Loop loop = null;
if(!loops.isEmpty()) {
@@ -82,27 +80,27 @@ public class CDTriangulator2D implements Triangulator{
}
if(loop == null) {
- GraphOutline outline = new GraphOutline(polyline);
- GraphOutline innerPoly = extractBoundaryTriangles(outline, false);
- vertices.addAll(polyline.getVertices());
+ final GraphOutline outline = new GraphOutline(polyline);
+ final GraphOutline innerPoly = extractBoundaryTriangles(sink, outline, false);
+ // vertices.addAll(polyline.getVertices());
loop = new Loop(innerPoly, VectorUtil.Winding.CCW);
loops.add(loop);
} else {
- GraphOutline outline = new GraphOutline(polyline);
- GraphOutline innerPoly = extractBoundaryTriangles(outline, true);
- vertices.addAll(innerPoly.getVertices());
+ final GraphOutline outline = new GraphOutline(polyline);
+ final GraphOutline innerPoly = extractBoundaryTriangles(sink, outline, true);
+ // vertices.addAll(innerPoly.getVertices());
loop.addConstraintCurve(innerPoly);
}
}
@Override
- public ArrayList generate() {
+ public void generate(List sink) {
for(int i=0;i size){
tri = loop.cut(false);
}
@@ -115,7 +113,7 @@ public class CDTriangulator2D implements Triangulator{
numTries = 0;
size--;
tri.setId(maxTriID++);
- triangles.add(tri);
+ sink.add(tri);
if(DEBUG){
System.err.println(tri);
}
@@ -127,15 +125,14 @@ public class CDTriangulator2D implements Triangulator{
break;
}
}
- Triangle tri = loop.cut(true);
+ final Triangle tri = loop.cut(true);
if(tri != null) {
- triangles.add(tri);
+ sink.add(tri);
}
}
- return triangles;
}
- private GraphOutline extractBoundaryTriangles(GraphOutline outline, boolean hole) {
+ private GraphOutline extractBoundaryTriangles(List sink, GraphOutline outline, boolean hole) {
GraphOutline innerOutline = new GraphOutline();
ArrayList outVertices = outline.getGraphPoint();
int size = outVertices.size();
@@ -146,9 +143,9 @@ public class CDTriangulator2D implements Triangulator{
GraphVertex gv1 = currentVertex;
if(!currentVertex.getPoint().isOnCurve()) {
- Vertex v0 = gv0.getPoint().clone();
- Vertex v2 = gv2.getPoint().clone();
- Vertex v1 = gv1.getPoint().clone();
+ final Vertex v0 = gv0.getPoint().clone();
+ final Vertex v2 = gv2.getPoint().clone();
+ final Vertex v1 = gv1.getPoint().clone();
gv0.setBoundaryContained(true);
gv1.setBoundaryContained(true);
@@ -164,7 +161,7 @@ public class CDTriangulator2D implements Triangulator{
t = new Triangle(v2, v1, v0);
}
t.setId(maxTriID++);
- triangles.add(t);
+ sink.add(t);
if(DEBUG){
System.err.println(t);
}
diff --git a/src/jogl/classes/jogamp/graph/curve/tess/Loop.java b/src/jogl/classes/jogamp/graph/curve/tess/Loop.java
index c1dafc0d1..5810e3bc9 100644
--- a/src/jogl/classes/jogamp/graph/curve/tess/Loop.java
+++ b/src/jogl/classes/jogamp/graph/curve/tess/Loop.java
@@ -37,7 +37,7 @@ import com.jogamp.opengl.math.geom.AABBox;
public class Loop {
private HEdge root = null;
- private AABBox box = new AABBox();
+ private final AABBox box = new AABBox();
private GraphOutline initialOutline = null;
public Loop(GraphOutline polyline, VectorUtil.Winding winding){
@@ -272,13 +272,13 @@ public class Loop {
* @return the triangle iff it satisfies, null otherwise
*/
private Triangle createTriangle(Vertex v1, Vertex v2, Vertex v3, HEdge rootT){
- Triangle t = new Triangle(v1, v2, v3);
+ final Triangle t = new Triangle(v1, v2, v3);
t.setVerticesBoundary(checkVerticesBoundary(rootT));
return t;
}
private boolean[] checkVerticesBoundary(HEdge rootT) {
- boolean[] boundary = new boolean[3];
+ final boolean[] boundary = new boolean[3];
HEdge e1 = rootT;
HEdge e2 = rootT.getNext();
HEdge e3 = rootT.getNext().getNext();
diff --git a/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java b/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java
deleted file mode 100644
index 8c214dd0b..000000000
--- a/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/**
- * Copyright 2010 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are
- * permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those of the
- * authors and should not be interpreted as representing official policies, either expressed
- * or implied, of JogAmp Community.
- */
-package jogamp.graph.curve.text;
-
-import java.util.ArrayList;
-
-import com.jogamp.graph.font.Font.Glyph;
-import com.jogamp.graph.geom.Vertex;
-import com.jogamp.graph.geom.Triangle;
-import com.jogamp.graph.geom.Vertex.Factory;
-import com.jogamp.graph.curve.OutlineShape;
-// import com.jogamp.opengl.math.Quaternion;
-
-public class GlyphShape {
-
- // private Quaternion quat= null;
- private Glyph glyph;
- private OutlineShape shape;
-
- /** Create a new Glyph shape
- * based on Parametric curve control polyline
- */
- public GlyphShape(Vertex.Factory extends Vertex> factory){
- this.shape = new OutlineShape(factory);
- this.glyph = null;
- }
-
- /** Create a new GlyphShape from a {@link OutlineShape}
- * @param factory vertex impl factory {@link Factory}
- * @param shape {@link OutlineShape} representation of the Glyph
- */
- public GlyphShape(Vertex.Factory extends Vertex> factory, Glyph glyph, OutlineShape shape){
- this(factory);
- this.shape = shape;
- this.shape.transformOutlines(OutlineShape.VerticesState.QUADRATIC_NURBS);
- this.glyph = glyph;
- }
-
- public final void destroy() {
- shape.clear();
- shape = null;
- glyph = null;
- }
-
- public final Vertex.Factory extends Vertex> vertexFactory() { return shape.vertexFactory(); }
-
- public final Glyph getGlyph() {
- return glyph;
- }
-
- public final OutlineShape getShape() {
- return shape;
- }
-
- public final int getNumVertices() {
- return shape.getVertices().size();
- }
-
- /** Get the rotational quaternion attached to this Shape.
- * @return the Quaternion Object
- public final Quaternion getQuat() {
- return quat;
- }
-
- /**
- * Set the Quaternion that shall define the rotation
- * of this shape.
- * @param quat
- public final void setQuat(Quaternion quat) {
- this.quat = quat;
- }
- */
-
- /** Triangluate the glyph shape
- * @return ArrayList of triangles which define this shape
- */
- public final ArrayList triangulate(){
- return shape.triangulate();
- }
-
- /** Get the list of Vertices of this Object
- * @return arrayList of Vertices
- */
- public final ArrayList getVertices(){
- return shape.getVertices();
- }
-}
diff --git a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java b/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java
deleted file mode 100644
index 5fb547e69..000000000
--- a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/**
- * Copyright 2010 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are
- * permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those of the
- * authors and should not be interpreted as representing official policies, either expressed
- * or implied, of JogAmp Community.
- */
-package jogamp.graph.curve.text;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.jogamp.graph.font.Font;
-import com.jogamp.graph.geom.Vertex;
-import com.jogamp.graph.geom.Triangle;
-import com.jogamp.graph.geom.Vertex.Factory;
-import com.jogamp.graph.geom.opengl.SVertex;
-
-import javax.media.opengl.GL2ES2;
-
-import jogamp.graph.curve.opengl.RegionFactory;
-import jogamp.graph.geom.plane.AffineTransform;
-
-import com.jogamp.graph.curve.OutlineShape;
-import com.jogamp.graph.curve.Region;
-import com.jogamp.graph.curve.opengl.GLRegion;
-import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.opengl.math.geom.AABBox;
-import com.jogamp.opengl.util.PMVMatrix;
-
-/**
- * @deprecated use {@link com.jogamp.graph.font.Font#getOutlineShapes(java.util.List, CharSequence, float, Factory)},
- * {@link com.jogamp.graph.curve.Region#create(OutlineShape, int)}
- * and a {@link com.jogamp.graph.curve.opengl.RegionRenderer}.
- */
-public class GlyphString {
- /** Static font size for all default font OutlineShape generations via {@link #createString(OutlineShape, Factory, Font, String)}.
- * The actual font size shall be accomplished by the GL PMV matrix.
- */
- public static final int STATIC_FONT_SIZE = 10;
-
- private final ArrayList glyphs = new ArrayList();
- private final CharSequence str;
- private final String fontname;
- private GLRegion region;
-
- private final SVertex origin = new SVertex();
-
- /**
- * Uses {@link #STATIC_FONT_SIZE}.
- * No caching is performed.
- *
- * @param shape is not null, add all {@link GlyphShape}'s {@link Outline} to this instance.
- * @param vertexFactory vertex impl factory {@link Factory}
- * @param font the target {@link Font}
- * @param str string text
- * @return the created {@link GlyphString} instance
- */
- public static GlyphString createString(OutlineShape shape, Factory extends Vertex> vertexFactory, Font font, String str) {
- return createString(shape, vertexFactory, font, STATIC_FONT_SIZE, str);
- }
-
- /**
- * No caching is performed.
- *
- * @param shape is not null, add all {@link GlyphShape}'s {@link Outline} to this instance.
- * @param vertexFactory vertex impl factory {@link Factory}
- * @param font the target {@link Font}
- * @param fontSize font size
- * @param str string text
- * @return the created {@link GlyphString} instance
- */
- public static GlyphString createString(OutlineShape shape, Factory extends Vertex> vertexFactory, Font font, int fontSize, CharSequence str) {
- List shapes = font.getOutlineShapes(null, str, fontSize, vertexFactory);
-
- GlyphString glyphString = new GlyphString(font.getName(Font.NAME_UNIQUNAME), str);
- glyphString.createfromOutlineShapes(vertexFactory, font, str, shapes);
- if(null != shape) {
- for(int i=0; i vertexFactory, Font font, CharSequence str, List shapes) {
- if(shapes.size() != str.length()) {
- throw new InternalError("XXX");
- }
- final int numGlyps = shapes.size();
- for (int index=0;index gtris = glyphShape.triangulate();
- region.addTriangles(gtris);
-
- final ArrayList gVertices = glyphShape.getVertices();
- for(int j=0; j vertexFactory = SVertex.factory();
final OTFontCollection fontset;
final OTFont font;
TypecastHMetrics metrics;
final CmapFormat cmapFormat;
int cmapentries;
-
// FIXME: Add cache size to limit memory usage ??
IntObjectHashMap char2Glyph;
@@ -201,8 +202,10 @@ class TypecastFont implements FontInt {
if(null == glyph) {
throw new RuntimeException("Could not retrieve glyph for symbol: <"+symbol+"> "+(int)symbol+" -> glyph id "+code);
}
- Path2D path = TypecastRenderer.buildPath(glyph);
- result = new TypecastGlyph(this, symbol, code, glyph.getBBox(), glyph.getAdvanceWidth(), path);
+ final OutlineShape shape = TypecastRenderer.buildShape(glyph, vertexFactory);
+ // FIXME: Remove Path2D
+ final Path2D path = TypecastRenderer.buildPath(glyph);
+ result = new TypecastGlyph(this, symbol, code, glyph.getBBox(), glyph.getAdvanceWidth(), path, shape);
if(DEBUG) {
System.err.println("New glyph: " + (int)symbol + " ( " + symbol +" ) -> " + code + ", contours " + glyph.getPointCount() + ": " + path);
}
@@ -225,11 +228,7 @@ class TypecastFont implements FontInt {
return result;
}
- @Override
- public OutlineShape getOutlineShape(Glyph glyph, Factory extends Vertex> vertexFactory) {
- return TypecastRenderer.getOutlineShape(this, glyph, vertexFactory);
- }
-
+ // FIXME: Remove altogether
@Override
public List getOutlineShapes(List shapes, CharSequence string, float pixelSize, Factory extends Vertex> vertexFactory) {
AffineTransform transform = new AffineTransform(vertexFactory);
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java
index 302366647..40727826b 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java
@@ -33,6 +33,7 @@ import jogamp.graph.font.FontInt;
import jogamp.graph.geom.plane.AffineTransform;
import jogamp.graph.geom.plane.Path2D;
+import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.graph.font.Font;
import com.jogamp.opengl.math.geom.AABBox;
@@ -136,30 +137,36 @@ public class TypecastGlyph implements FontInt.GlyphInt {
public static final short MAX_ID = (short)((1 << 16) - 2);
private final Font font;
+ protected final char symbol;
+ protected final OutlineShape shape; // in EM units
+
+ protected final Path2D path; // in EM units FIXME remove!
- char symbol;
short id;
int advance;
Metrics metrics;
- protected Path2D path; // in EM units
- protected Path2D pathSized;
- protected float numberSized;
+ protected Path2D pathSized; // FIXME remove!
+ protected float numberSized; // FIXME remove!
protected TypecastGlyph(Font font, char symbol) {
this.font = font;
this.symbol = symbol;
+ this.shape = null;
+ this.path = null;
}
protected TypecastGlyph(Font font,
- char symbol, short id, AABBox bbox, int advance, Path2D path) {
+ char symbol, short id, AABBox bbox, int advance, Path2D path, OutlineShape shape) {
this.font = font;
this.symbol = symbol;
+ this.shape = shape;
+ this.path = path;
+
this.advance = advance;
init(id, bbox, advance);
- this.path = path;
this.pathSized = null;
this.numberSized = 0.0f;
}
@@ -170,10 +177,11 @@ public class TypecastGlyph implements FontInt.GlyphInt {
this.metrics = new Metrics(this.font, bbox, this.advance);
}
+ /**
public void reset(Path2D path) {
this.path = path;
this.metrics.reset();
- }
+ } */
@Override
public Font getFont() {
@@ -222,6 +230,11 @@ public class TypecastGlyph implements FontInt.GlyphInt {
return this.metrics.getAdvance(pixelSize, useFrationalMetrics);
}
+ @Override
+ public OutlineShape getShape() {
+ return this.shape;
+ }
+
@Override
public Path2D getPath() {
return this.path;
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java
index d7f8497b3..83ccadab3 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java
@@ -55,25 +55,27 @@ public class TypecastRenderer {
if (string == null) {
return;
}
- Font.Metrics metrics = font.getMetrics();
- float advanceTotal = 0;
- float lineGap = metrics.getLineGap(pixelSize) ;
- float ascent = metrics.getAscent(pixelSize) ;
- float descent = metrics.getDescent(pixelSize) ;
+ final Font.Metrics metrics = font.getMetrics();
+ final float lineGap = metrics.getLineGap(pixelSize) ;
+ final float ascent = metrics.getAscent(pixelSize) ;
+ final float descent = metrics.getDescent(pixelSize) ;
+ final float advanceY = lineGap - descent + ascent;
+ final float scale = metrics.getScale(pixelSize);
if (transform == null) {
transform = new AffineTransform();
}
- AffineTransform t = new AffineTransform();
+ final AffineTransform t = new AffineTransform(transform.getFactory());
final int len = string.length();
- float advanceY = lineGap - descent + ascent;
+
+ float advanceTotal = 0;
float y = 0;
+
for (int i=0; i vertexFactory) {
+ // FIXME: Remove Path2D
Path2D path = ((GlyphInt)glyph).getPath();
AffineTransform transform = new AffineTransform(vertexFactory);
OutlineShape shape = new OutlineShape(vertexFactory);
@@ -109,6 +112,8 @@ public class TypecastRenderer {
}
public static List getOutlineShapes(List shapes, TypecastFont font, CharSequence string, float pixelSize, AffineTransform transform, Factory extends Vertex> vertexFactory) {
+ // FIXME: Remove Path2D
+ // FIXME: Remove altogether
Path2D[] paths = new Path2D[string.length()];
getPaths(font, string, pixelSize, transform, paths);
@@ -161,6 +166,118 @@ public class TypecastRenderer {
}
}
+ private static void addShapeMoveTo(final OutlineShape shape, Factory extends Vertex> vertexFactory, Point p1) {
+ shape.closeLastOutline();
+ shape.addEmptyOutline();
+ shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, true)); // p1.onCurve));
+ // shape.addVertex(0, vertexFactory.create(coords, 0, 2, true));
+ }
+ private static void addShapeLineTo(final OutlineShape shape, Factory extends Vertex> vertexFactory, Point p1) {
+ shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, true)); // p1.onCurve));
+ // shape.addVertex(0, vertexFactory.create(coords, 0, 2, true));
+ }
+ private static void addShapeQuadTo(final OutlineShape shape, Factory extends Vertex> vertexFactory, Point p1, Point p2) {
+ shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, false)); // p1.onCurve));
+ shape.addVertex(0, vertexFactory.create(p2.x, p2.y, 0, true)); // p2.onCurve));
+ // shape.addVertex(0, vertexFactory.create(coords, 0, 2, false));
+ // shape.addVertex(0, vertexFactory.create(coords, 2, 2, true));
+ }
+ private static void addShapeQuadTo(final OutlineShape shape, Factory extends Vertex> vertexFactory, Point p1, int p2x, int p2y) {
+ shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, false)); // p1.onCurve));
+ shape.addVertex(0, vertexFactory.create(p2x, p2y, 0, true)); // p2.onCurve));
+ // shape.addVertex(0, vertexFactory.create(coords, 0, 2, false));
+ // shape.addVertex(0, vertexFactory.create(coords, 2, 2, true));
+ }
+ /**
+ private static void addShapeCubicTo(final OutlineShape shape, Factory extends Vertex> vertexFactory, Point p1, Point p2, Point p3) {
+ shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, false)); // p1.onCurve));
+ shape.addVertex(0, vertexFactory.create(p2.x, p2.y, 0, false)); // p2.onCurve));
+ shape.addVertex(0, vertexFactory.create(p3.x, p3.y, 0, true)); // p3.onCurve));
+ // shape.addVertex(0, vertexFactory.create(coords, 0, 2, false));
+ // shape.addVertex(0, vertexFactory.create(coords, 2, 2, false));
+ // shape.addVertex(0, vertexFactory.create(coords, 4, 2, true));
+
+ }
+ private static void addShapeClose(final OutlineShape shape, Factory extends Vertex> vertexFactory) {
+ shape.closeLastOutline();
+ } */
+
+ public static OutlineShape buildShape(OTGlyph glyph, Factory extends Vertex> vertexFactory) {
+
+ if (glyph == null) {
+ return null;
+ }
+
+ final OutlineShape shape = new OutlineShape(vertexFactory);
+
+ // Iterate through all of the points in the glyph. Each time we find a
+ // contour end point, add the point range to the path.
+ int startIndex = 0;
+ int count = 0;
+ for (int i = 0; i < glyph.getPointCount(); i++) {
+ count++;
+ if (glyph.getPoint(i).endOfContour) {
+ {
+ int offset = 0;
+ while (offset < count) {
+ final Point point = glyph.getPoint(startIndex + offset%count);
+ final Point point_plus1 = glyph.getPoint(startIndex + (offset+1)%count);
+ final Point point_plus2 = glyph.getPoint(startIndex + (offset+2)%count);
+ if(offset == 0)
+ {
+ addShapeMoveTo(shape, vertexFactory, point);
+ // gp.moveTo(point.x, point.y);
+ }
+
+ if (point.onCurve) {
+ if (point_plus1.onCurve) {
+ // s = new Line2D.Float(point.x, point.y, point_plus1.x, point_plus1.y);
+ addShapeLineTo(shape, vertexFactory, point_plus1);
+ // gp.lineTo( point_plus1.x, point_plus1.y );
+ offset++;
+ } else {
+ if (point_plus2.onCurve) {
+ // s = new QuadCurve2D.Float( point.x, point.y, point_plus1.x, point_plus1.y, point_plus2.x, point_plus2.y);
+ addShapeQuadTo(shape, vertexFactory, point_plus1, point_plus2);
+ // gp.quadTo(point_plus1.x, point_plus1.y, point_plus2.x, point_plus2.y);
+ offset+=2;
+ } else {
+ // s = new QuadCurve2D.Float(point.x,point.y,point_plus1.x,point_plus1.y,
+ // midValue(point_plus1.x, point_plus2.x), midValue(point_plus1.y, point_plus2.y));
+ addShapeQuadTo(shape, vertexFactory, point_plus1, midValue(point_plus1.x, point_plus2.x), midValue(point_plus1.y, point_plus2.y));
+ // gp.quadTo(point_plus1.x, point_plus1.y, midValue(point_plus1.x, point_plus2.x), midValue(point_plus1.y, point_plus2.y));
+ offset+=2;
+ }
+ }
+ } else {
+ if (point_plus1.onCurve) {
+ // s = new QuadCurve2D.Float(midValue(point_minus1.x, point.x), midValue(point_minus1.y, point.y),
+ // point.x, point.y, point_plus1.x, point_plus1.y);
+ //gp.curve3(point_plus1.x, point_plus1.y, point.x, point.y);
+ addShapeQuadTo(shape, vertexFactory, point, point_plus1);
+ // gp.quadTo(point.x, point.y, point_plus1.x, point_plus1.y);
+ offset++;
+
+ } else {
+ // s = new QuadCurve2D.Float(midValue(point_minus1.x, point.x), midValue(point_minus1.y, point.y), point.x, point.y,
+ // midValue(point.x, point_plus1.x), midValue(point.y, point_plus1.y));
+ //gp.curve3(midValue(point.x, point_plus1.x), midValue(point.y, point_plus1.y), point.x, point.y);
+ addShapeQuadTo(shape, vertexFactory, point, midValue(point.x, point_plus1.x), midValue(point.y, point_plus1.y));
+ // gp.quadTo(point.x, point.y, midValue(point.x, point_plus1.x), midValue(point.y, point_plus1.y));
+ offset++;
+ }
+ }
+ }
+
+ }
+ startIndex = i + 1;
+ count = 0;
+ }
+ }
+ shape.closeLastOutline();
+ return shape;
+ }
+
/**
* Build a {@link com.jogamp.graph.geom.Path2D Path2D} from a
* {@link jogamp.graph.font.typecast.ot.OTGlyph Glyph}. This glyph path can then
diff --git a/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java b/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java
index 32e2b6a39..f5cf8dd95 100644
--- a/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java
+++ b/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java
@@ -121,6 +121,8 @@ public class AffineTransform implements Cloneable, Serializable {
}
}
+ public final Vertex.Factory extends Vertex> getFactory() { return pointFactory; }
+
/*
* Method returns type of affine transformation.
*
@@ -403,12 +405,10 @@ public class AffineTransform implements Cloneable, Serializable {
public Vertex transform(Vertex src, Vertex dst) {
if (dst == null) {
- dst = pointFactory.create();
+ dst = pointFactory.create(src.getId(), src.isOnCurve(), src.getTexCoord());
}
-
- float x = src.getX();
- float y = src.getY();
-
+ final float x = src.getX();
+ final float y = src.getY();
dst.setCoord(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12, 0f);
return dst;
}
@@ -416,12 +416,12 @@ public class AffineTransform implements Cloneable, Serializable {
public void transform(Vertex[] src, int srcOff, Vertex[] dst, int dstOff, int length) {
while (--length >= 0) {
Vertex srcPoint = src[srcOff++];
- float x = srcPoint.getX();
- float y = srcPoint.getY();
Vertex dstPoint = dst[dstOff];
if (dstPoint == null) {
throw new IllegalArgumentException("dst["+dstOff+"] is null");
}
+ final float x = srcPoint.getX();
+ final float y = srcPoint.getY();
dstPoint.setCoord(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12, 0f);
dst[dstOff++] = dstPoint;
}
@@ -446,12 +446,10 @@ public class AffineTransform implements Cloneable, Serializable {
public Vertex deltaTransform(Vertex src, Vertex dst) {
if (dst == null) {
- dst = pointFactory.create();
+ dst = pointFactory.create(src.getId(), src.isOnCurve(), src.getTexCoord());
}
-
- float x = src.getX();
- float y = src.getY();
-
+ final float x = src.getX();
+ final float y = src.getY();
dst.setCoord(x * m00 + y * m01, x * m10 + y * m11, 0f);
return dst;
}
@@ -471,12 +469,10 @@ public class AffineTransform implements Cloneable, Serializable {
throw new NoninvertibleTransformException(determinantIsZero);
}
if (dst == null) {
- dst = pointFactory.create();
+ dst = pointFactory.create(src.getId(), src.isOnCurve(), src.getTexCoord());
}
-
- float x = src.getX() - m02;
- float y = src.getY() - m12;
-
+ final float x = src.getX() - m02;
+ final float y = src.getY() - m12;
dst.setCoord((x * m11 - y * m01) / det, (y * m00 - x * m10) / det, 0f);
return dst;
}
@@ -502,7 +498,7 @@ public class AffineTransform implements Cloneable, Serializable {
return null;
}
if (src instanceof Path2D) {
- return ((Path2D)src).createTransformedShape(this);
+ return src.createTransformedShape(this);
}
PathIterator path = src.iterator(this);
Path2D dst = new Path2D(path.getWindingRule());
diff --git a/src/jogl/classes/jogamp/graph/geom/plane/Path2D.java b/src/jogl/classes/jogamp/graph/geom/plane/Path2D.java
index 33b80d6b8..a87c0a0a1 100644
--- a/src/jogl/classes/jogamp/graph/geom/plane/Path2D.java
+++ b/src/jogl/classes/jogamp/graph/geom/plane/Path2D.java
@@ -21,8 +21,8 @@ package jogamp.graph.geom.plane;
import java.util.NoSuchElementException;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.graph.geom.Vertex;
-import com.jogamp.graph.geom.opengl.SVertex;
import com.jogamp.opengl.math.geom.AABBox;
--
cgit v1.2.3