summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/graph/geom
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-02-24 13:32:34 +0100
committerSven Gothel <[email protected]>2014-02-24 13:32:34 +0100
commitc3621221b9a563495b4f54fe60e18e8db8cc57fb (patch)
tree00aded20f3582e517372c12f58e19d3524582099 /src/jogl/classes/com/jogamp/graph/geom
parentf69df875d0b9f969a816d143ed589b25e50cd9e7 (diff)
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.
Diffstat (limited to 'src/jogl/classes/com/jogamp/graph/geom')
-rw-r--r--src/jogl/classes/com/jogamp/graph/geom/Outline.java9
-rw-r--r--src/jogl/classes/com/jogamp/graph/geom/SVertex.java (renamed from src/jogl/classes/com/jogamp/graph/geom/opengl/SVertex.java)62
-rw-r--r--src/jogl/classes/com/jogamp/graph/geom/Triangle.java67
-rw-r--r--src/jogl/classes/com/jogamp/graph/geom/Vertex.java4
4 files changed, 111 insertions, 31 deletions
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<Outline> {
* 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/opengl/SVertex.java b/src/jogl/classes/com/jogamp/graph/geom/SVertex.java
index b27604a44..99f10a694 100644
--- a/src/jogl/classes/com/jogamp/graph/geom/opengl/SVertex.java
+++ b/src/jogl/classes/com/jogamp/graph/geom/SVertex.java
@@ -25,9 +25,8 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of JogAmp Community.
*/
-package com.jogamp.graph.geom.opengl;
+package com.jogamp.graph.geom;
-import com.jogamp.graph.geom.Vertex;
import com.jogamp.opengl.math.VectorUtil;
/** A Simple Vertex Implementation. Where the coordinates, and other attributes are
@@ -35,10 +34,10 @@ import com.jogamp.opengl.math.VectorUtil;
*
*/
public class SVertex implements Vertex {
- private int id = Integer.MAX_VALUE;
- protected float[] coord = new float[3];
+ private int id;
+ protected final float[] coord = new float[3];
protected boolean onCurve;
- private float[] texCoord = new float[2];
+ private final float[] texCoord = new float[2];
static final Factory factory = new Factory();
@@ -50,8 +49,17 @@ public class SVertex implements Vertex {
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(float x, float y, float z, boolean onCurve) {
+ public SVertex create(final float x, final float y, final float z, final boolean onCurve) {
return new SVertex(x, y, z, onCurve);
}
@@ -62,30 +70,46 @@ public class SVertex implements Vertex {
}
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(float x, float y, float z, boolean onCurve) {
+ 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(float[] coordsBuffer, int offset, int length, boolean 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, int offset, int length,
- float[] texCoordsBuffer, int offsetTC, int lengthTC, boolean onCurve) {
- setCoord(coordsBuffer, offset, length);
- setTexCoord(texCoordsBuffer, offsetTC, lengthTC);
+ 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) {
- this.coord[0] = x;
- this.coord[1] = y;
- this.coord[2] = z;
+ coord[0] = x;
+ coord[1] = y;
+ coord[2] = z;
}
@Override
@@ -175,8 +199,8 @@ public class SVertex implements Vertex {
@Override
public final void setTexCoord(float s, float t) {
- this.texCoord[0] = s;
- this.texCoord[1] = t;
+ texCoord[0] = s;
+ texCoord[1] = t;
}
@Override
@@ -185,11 +209,11 @@ public class SVertex implements Vertex {
}
/**
- * @return deep clone of this Vertex, but keeping the id blank
+ * @return deep clone of this Vertex elements
*/
@Override
public SVertex clone(){
- return new SVertex(this.coord, 0, 3, this.texCoord, 0, 2, this.onCurve);
+ return new SVertex(this.coord, this.texCoord, this.onCurve);
}
@Override
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 extends Vertex> {
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);