summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--LICENSE.txt2
-rw-r--r--make/scripts/tests.sh13
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java299
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/Region.java273
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java130
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java369
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java302
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java316
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java193
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java14
-rw-r--r--src/jogl/classes/com/jogamp/graph/font/Font.java69
-rw-r--r--src/jogl/classes/com/jogamp/graph/font/FontFactory.java25
-rw-r--r--src/jogl/classes/com/jogamp/graph/font/FontSet.java24
-rw-r--r--src/jogl/classes/com/jogamp/graph/geom/Outline.java42
-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.java55
-rw-r--r--src/jogl/classes/com/jogamp/graph/geom/Vertex.java4
-rw-r--r--src/jogl/classes/com/jogamp/opengl/FBObject.java4
-rw-r--r--src/jogl/classes/com/jogamp/opengl/math/FloatUtil.java26
-rw-r--r--src/jogl/classes/com/jogamp/opengl/math/Quaternion.java9
-rw-r--r--src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java288
-rw-r--r--src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java117
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java5
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/av/AudioSink.java6
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/RegionFactory.java74
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java19
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java108
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java343
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java411
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java408
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java134
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass_norm-weight.fp (renamed from src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass-weight.fp)27
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass_norm.fp (renamed from src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass.fp)35
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass-weight.fp97
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass.fp91
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa-weight.fp76
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa.fp88
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa-weight.fp109
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa.fp103
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl7
-rw-r--r--src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java94
-rw-r--r--src/jogl/classes/jogamp/graph/curve/tess/Loop.java6
-rw-r--r--src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java99
-rw-r--r--src/jogl/classes/jogamp/graph/curve/text/GlyphString.java213
-rw-r--r--src/jogl/classes/jogamp/graph/font/FontInt.java47
-rw-r--r--src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java2
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java102
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java94
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java6
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java300
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/ot/Point.java5
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfCompositeDescript.java7
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/t2/T2Interpreter.java6
-rw-r--r--src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java168
-rw-r--r--src/jogl/classes/jogamp/graph/geom/plane/Path2D.java2
-rw-r--r--src/newt/classes/com/jogamp/newt/MonitorDevice.java28
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java179
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java383
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java98
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java101
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java225
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener01.java46
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java100
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java25
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java25
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionRendererListenerBase01.java8
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java138
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextGLListener0A.java33
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java28
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java49
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo03.java96
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java310
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java327
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java2
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo02.java2
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/MSAATool.java29
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java74
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java203
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java116
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java62
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java23
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java295
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UITextShape.java37
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/opengl/UIRegion.java77
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/GLReadBuffer00Base.java22
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java15
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java62
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java45
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java73
89 files changed, 5283 insertions, 3981 deletions
diff --git a/LICENSE.txt b/LICENSE.txt
index 6da9f545e..e8c5a52d1 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -246,7 +246,7 @@ A.3) The JOGL source tree contains code from David Schweinsberg
Typecast is a font development environment for OpenType font technology.
- <http://typecast.dev.java.net/>
+ <https://java.net/projects/typecast>
Author: David Schweinsberg
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh
index 18f488bc9..a8807b09e 100644
--- a/make/scripts/tests.sh
+++ b/make/scripts/tests.sh
@@ -229,6 +229,8 @@ function jrun() {
#D_ARGS="-Dnativewindow.osx.calayer.bugfree"
#D_ARGS="-Dnativewindow.debug.ToolkitLock"
#D_ARGS="-Djogl.debug.graph.curve"
+ #D_ARGS="-Djogl.debug.graph.curve -Djogl.debug.graph.curve.instance"
+ #D_ARGS="-Djogl.debug.graph.curve.instance"
#D_ARGS="-Djogl.debug.graph.curve -Djogl.debug.GLSLCode -Djogl.debug.TraceGL"
#D_ARGS="-Djogl.debug.graph.curve -Djogl.debug.GLSLState"
#D_ARGS="-Djogamp.debug.TempJarCache -Djogamp.debug.JarUtil -Djogamp.debug.IOUtil"
@@ -729,17 +731,22 @@ testawt com.jogamp.opengl.test.junit.jogl.acore.TestGLReadBuffer01GLCanvasAWT $*
#
# Graph
#
-#testnoawt com.jogamp.opengl.test.junit.graph.TestTextRendererNEWT10 $*
-#testnoawt com.jogamp.opengl.test.junit.graph.TestTextRendererNEWT00 $*
#testnoawt com.jogamp.opengl.test.junit.graph.TestRegionRendererNEWT01 $*
+#testnoawt com.jogamp.opengl.test.junit.graph.TestTextRendererNEWT00 $*
#testnoawt com.jogamp.opengl.test.junit.graph.TestTextRendererNEWT01 $*
+#testnoawt com.jogamp.opengl.test.junit.graph.TestTextRendererNEWTPerf01 $*
+#testnoawt com.jogamp.opengl.test.junit.graph.TestTextRendererNEWT10 $*
#testnoawt com.jogamp.opengl.test.junit.graph.demos.ui.UINewtDemo01 $*
#testnoawt com.jogamp.opengl.test.junit.graph.demos.GPUTextNewtDemo01 $*
-#testnoawt com.jogamp.opengl.test.junit.graph.demos.GPUTextNewtDemo02 $*
+testnoawt com.jogamp.opengl.test.junit.graph.demos.GPUTextNewtDemo02 $*
+#testnoawt com.jogamp.opengl.test.junit.graph.demos.GPUTextNewtDemo03 $*
#testnoawt com.jogamp.opengl.test.junit.graph.demos.GPURegionNewtDemo01 $*
#testnoawt com.jogamp.opengl.test.junit.graph.demos.GPURegionNewtDemo02 $*
#testnoawt com.jogamp.opengl.test.junit.graph.demos.GPUUISceneNewtDemo01 $*
#testnoawt com.jogamp.opengl.test.junit.graph.demos.GPUUISceneNewtDemo02 $*
+#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieCube $*
+#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieSimple $*
+#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLReadBuffer01GLWindowNEWT $*
#
# OSX bugs
diff --git a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
index 226e57f07..cb99fbfa4 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
@@ -39,8 +39,9 @@ import com.jogamp.opengl.math.VectorUtil;
import com.jogamp.opengl.math.geom.AABBox;
-/** A Generic shape objects which is defined by a list of Outlines.
- * This Shape can be transformed to Triangulations.
+/**
+ * A Generic shape objects which is defined by a list of Outlines.
+ * This Shape can be transformed to triangulations.
* The list of triangles generated are render-able by a Region object.
* The triangulation produced by this Shape will define the
* closed region defined by the outlines.
@@ -107,19 +108,37 @@ public class OutlineShape implements Comparable<OutlineShape> {
}
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.
*/
- private ArrayList<Outline> outlines;
- private AABBox bbox;
+ /* pp */ final ArrayList<Outline> outlines;
+
+ private final AABBox bbox;
+ private final ArrayList<Triangle> triangles;
+ private final ArrayList<Vertex> vertices;
+
+ private VerticesState outlineState;
/** dirty bits DIRTY_BOUNDS */
private int dirtyBits;
+ private float sharpness;
+
+ private final float[] tmpV1 = new float[3];
+ private final float[] tmpV2 = new float[3];
+ private final float[] tmpV3 = new float[3];
+
/** Create a new Outline based Shape
*/
public OutlineShape(Vertex.Factory<? extends Vertex> factory) {
@@ -128,7 +147,19 @@ public class OutlineShape implements Comparable<OutlineShape> {
this.outlines.add(new Outline());
this.outlineState = VerticesState.UNDEFINED;
this.bbox = new AABBox();
+ this.triangles = new ArrayList<Triangle>();
+ this.vertices = new ArrayList<Vertex>();
this.dirtyBits = 0;
+ this.sharpness = 0.5f;
+ }
+
+ public float getSharpness() { return sharpness; }
+
+ public void setSharpness(final float s) {
+ if( this.sharpness != s ) {
+ clearCache();
+ sharpness=s;
+ }
}
/** Clears all data and reset all states as if this instance was newly created */
@@ -137,32 +168,44 @@ public class OutlineShape implements Comparable<OutlineShape> {
outlines.add(new Outline());
outlineState = VerticesState.UNDEFINED;
bbox.reset();
+ vertices.clear();
+ triangles.clear();
dirtyBits = 0;
}
- /** Returns the associated vertex factory of this outline shape
+ /** Clears cached triangulated data, i.e. {@link #getTriangles(VerticesState)} and {@link #getVertices()}. */
+ public void clearCache() {
+ vertices.clear();
+ triangles.clear();
+ dirtyBits |= DIRTY_TRIANGLES | DIRTY_VERTICES;
+ }
+
+ /**
+ * Returns the associated vertex factory of this outline shape
* @return Vertex.Factory object
*/
public final Vertex.Factory<? extends Vertex> vertexFactory() { return vertexFactory; }
- public int getOutlineNumber() {
+ public final int getOutlineNumber() {
return outlines.size();
}
- /** Add a new empty {@link Outline}
+ /**
+ * Add a new empty {@link Outline}
* to the end of this shape's outline list.
* <p>If the {@link #getLastOutline()} is empty already, no new one will be added.</p>
*
* After a call to this function all new vertices added
* will belong to the new outline
*/
- public void addEmptyOutline() {
+ public final void addEmptyOutline() {
if( !getLastOutline().isEmpty() ) {
outlines.add(new Outline());
}
}
- /** Appends the {@link Outline} element to the end,
+ /**
+ * Appends the {@link Outline} element to the end,
* ensuring a clean tail.
*
* <p>A clean tail is ensured, no double empty Outlines are produced
@@ -171,11 +214,12 @@ public class OutlineShape implements Comparable<OutlineShape> {
* @param outline Outline object to be added
* @throws NullPointerException if the {@link Outline} element is null
*/
- public void addOutline(Outline outline) throws NullPointerException {
+ public final void addOutline(Outline outline) throws NullPointerException {
addOutline(outlines.size(), outline);
}
- /** Insert the {@link Outline} element at the given {@code position}.
+ /**
+ * Insert the {@link Outline} element at the given {@code position}.
*
* <p>If the {@code position} indicates the end of this list,
* a clean tail is ensured, no double empty Outlines are produced
@@ -186,7 +230,7 @@ public class OutlineShape implements Comparable<OutlineShape> {
* @throws NullPointerException if the {@link Outline} element is null
* @throws IndexOutOfBoundsException if position is out of range (position < 0 || position > getOutlineNumber())
*/
- public void addOutline(int position, Outline outline) throws NullPointerException, IndexOutOfBoundsException {
+ public final void addOutline(int position, Outline outline) throws NullPointerException, IndexOutOfBoundsException {
if (null == outline) {
throw new NullPointerException("outline is null");
}
@@ -200,6 +244,8 @@ public class OutlineShape implements Comparable<OutlineShape> {
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,26 +253,29 @@ public class OutlineShape implements Comparable<OutlineShape> {
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,
+ /**
+ * Insert the {@link OutlineShape} elements of type {@link Outline}, .. at the end of this shape,
* using {@link #addOutline(Outline)} for each element.
- * <p>Closes the current last outline via {@link #closeLastOutline()} before adding the new ones.</p>
+ * <p>Closes the current last outline via {@link #closeLastOutline(boolean)} before adding the new ones.</p>
* @param outlineShape OutlineShape elements to be added.
* @throws NullPointerException if the {@link OutlineShape} is null
* @throws IndexOutOfBoundsException if position is out of range (position < 0 || position > getOutlineNumber())
*/
- public void addOutlineShape(OutlineShape outlineShape) throws NullPointerException {
+ public final void addOutlineShape(OutlineShape outlineShape) throws NullPointerException {
if (null == outlineShape) {
throw new NullPointerException("OutlineShape is null");
}
- closeLastOutline();
+ closeLastOutline(true);
for(int i=0; i<outlineShape.getOutlineNumber(); i++) {
addOutline(outlineShape.getOutline(i));
}
}
- /** Replaces the {@link Outline} element at the given {@code position}.
+ /**
+ * Replaces the {@link Outline} element at the given {@code position}.
* <p>Sets the bounding box dirty, hence a next call to {@link #getBounds()} will validate it.</p>
*
* @param position of the replaced Outline
@@ -234,26 +283,28 @@ public class OutlineShape implements Comparable<OutlineShape> {
* @throws NullPointerException if the {@link Outline} element is null
* @throws IndexOutOfBoundsException if position is out of range (position < 0 || position >= getOutlineNumber())
*/
- public void setOutline(int position, Outline outline) throws NullPointerException, IndexOutOfBoundsException {
+ public final void setOutline(int position, Outline outline) throws NullPointerException, IndexOutOfBoundsException {
if (null == outline) {
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}.
+ /**
+ * Removes the {@link Outline} element at the given {@code position}.
* <p>Sets the bounding box dirty, hence a next call to {@link #getBounds()} will validate it.</p>
*
* @param position of the to be removed Outline
* @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);
}
- /** Get the last added outline to the list
+ /**
+ * Get the last added outline to the list
* of outlines that define the shape
* @return the last outline
*/
@@ -261,15 +312,16 @@ public class OutlineShape implements Comparable<OutlineShape> {
return outlines.get(outlines.size()-1);
}
- /** @return the {@code Outline} at {@code position}
+ /**
+ * Returns the {@code Outline} at {@code position}
* @throws IndexOutOfBoundsException if position is out of range (position < 0 || position >= getOutlineNumber())
*/
- public Outline getOutline(int position) throws IndexOutOfBoundsException {
+ public final Outline getOutline(int position) throws IndexOutOfBoundsException {
return outlines.get(position);
}
- /** Adds a vertex to the last open outline in the
- * shape.
+ /**
+ * Adds a vertex to the last open outline to the shape's tail.
* @param v the vertex to be added to the OutlineShape
*/
public final void addVertex(Vertex v) {
@@ -278,10 +330,12 @@ public class OutlineShape implements Comparable<OutlineShape> {
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.
- * at {@code position}
+ /**
+ * Adds a vertex to the last open outline to the shape at {@code position}
* @param position indx at which the vertex will be added
* @param v the vertex to be added to the OutlineShape
*/
@@ -291,9 +345,11 @@ public class OutlineShape implements Comparable<OutlineShape> {
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
+ /**
+ * Add a 2D {@link Vertex} to the last outline by defining the coordinate attribute
* of the vertex. The 2D vertex will be represented as Z=0.
*
* @param x the x coordinate
@@ -305,7 +361,8 @@ public class OutlineShape implements Comparable<OutlineShape> {
addVertex(vertexFactory.create(x, y, 0f, onCurve));
}
- /** Add a 3D {@link Vertex} to the last outline by defining the coordniate attribute
+ /**
+ * Add a 3D {@link Vertex} to the last outline by defining the coordniate attribute
* of the vertex.
* @param x the x coordinate
* @param y the y coordinate
@@ -317,7 +374,8 @@ public class OutlineShape implements Comparable<OutlineShape> {
addVertex(vertexFactory.create(x, y, z, onCurve));
}
- /** Add a vertex to the last outline by passing a float array and specifying the
+ /**
+ * Add a vertex to the last outline by passing a float array and specifying the
* offset and length in which. The attributes of the vertex are located.
* The attributes should be continuous (stride = 0).
* Attributes which value are not set (when length less than 3)
@@ -332,29 +390,37 @@ public class OutlineShape implements Comparable<OutlineShape> {
addVertex(vertexFactory.create(coordsBuffer, offset, length, onCurve));
}
- /** Closes the last outline in the shape.
- * <p>If last vertex is not equal to first vertex.
- * A new temp vertex is added at the end which
- * is equal to the first.</p>
+ /**
+ * Closes the last outline in the shape.
+ * <p>
+ * Checks whether the last vertex equals to the first of the last outline.
+ * If not equal, it either appends a clone of the first vertex
+ * or prepends a clone of the last vertex, depending on <code>closeTail</code>.
+ * </p>
+ * @param closeTail if true, a clone of the first vertex will be appended,
+ * otherwise a clone of the last vertex will be prepended.
*/
- public void closeLastOutline() {
- getLastOutline().setClosed(true);
+ public final void closeLastOutline(boolean closeTail) {
+ if( getLastOutline().setClosed(true) ) {
+ dirtyBits |= DIRTY_TRIANGLES | DIRTY_VERTICES;
+ }
}
/**
- * @return the outline's vertices state, {@link OutlineShape.VerticesState}
+ * Return the outline's vertices state, {@link OutlineShape.VerticesState}
*/
public final VerticesState getOutlineState() {
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
* {@link OutlineShape.VerticesState#QUADRATIC_NURBS} are supported.
*/
- public void transformOutlines(VerticesState destinationType) {
+ protected final void transformOutlines(VerticesState destinationType) {
if(outlineState != destinationType){
if(destinationType == VerticesState.QUADRATIC_NURBS){
transformOutlines2Quadratic();
@@ -366,29 +432,30 @@ public class OutlineShape implements Comparable<OutlineShape> {
}
private void subdivideTriangle(final Outline outline, Vertex a, Vertex b, Vertex c, int index){
- float[] v1 = VectorUtil.mid(a.getCoord(), b.getCoord());
- float[] v3 = VectorUtil.mid(b.getCoord(), c.getCoord());
- float[] v2 = VectorUtil.mid(v1, v3);
+ VectorUtil.mid(tmpV1, a.getCoord(), b.getCoord());
+ VectorUtil.mid(tmpV3, b.getCoord(), c.getCoord());
+ VectorUtil.mid(tmpV2, tmpV1, tmpV3);
//drop off-curve vertex to image on the curve
- b.setCoord(v2, 0, 3);
+ b.setCoord(tmpV2, 0, 3);
b.setOnCurve(true);
- outline.addVertex(index, vertexFactory.create(v1, 0, 3, false));
- outline.addVertex(index+2, vertexFactory.create(v3, 0, 3, false));
+ outline.addVertex(index, vertexFactory.create(tmpV1, 0, 3, false));
+ outline.addVertex(index+2, vertexFactory.create(tmpV3, 0, 3, false));
}
- /** Check overlaps between curved triangles
- * first check if any vertex in triangle a is in triangle b
- * second check if edges of triangle a intersect segments of triangle b
- * if any of the two tests is true we divide current triangle
- * and add the other to the list of overlaps
+ /**
+ * Check overlaps between curved triangles
+ * first check if any vertex in triangle a is in triangle b
+ * second check if edges of triangle a intersect segments of triangle b
+ * if any of the two tests is true we divide current triangle
+ * and add the other to the list of overlaps
*
- * Loop until overlap array is empty. (check only in first pass)
+ * Loop until overlap array is empty. (check only in first pass)
*/
private void checkOverlaps() {
- ArrayList<Vertex> overlaps = new ArrayList<Vertex>(3);
- int count = getOutlineNumber();
+ final ArrayList<Vertex> overlaps = new ArrayList<Vertex>(3);
+ final int count = getOutlineNumber();
boolean firstpass = true;
do {
for (int cc = 0; cc < count; cc++) {
@@ -416,8 +483,9 @@ public class OutlineShape implements Comparable<OutlineShape> {
vertexCount+=2;
if(overlap != null && !overlap.isOnCurve()) {
- if(!overlaps.contains(overlap))
+ if(!overlaps.contains(overlap)) {
overlaps.add(overlap);
+ }
}
}
}
@@ -445,15 +513,14 @@ public class OutlineShape implements Comparable<OutlineShape> {
continue;
}
- if(VectorUtil.vertexInTriangle(a.getCoord(), b.getCoord(), c.getCoord(), current.getCoord())
- || VectorUtil.vertexInTriangle(a.getCoord(), b.getCoord(), c.getCoord(), nextV.getCoord())
- || VectorUtil.vertexInTriangle(a.getCoord(), b.getCoord(), c.getCoord(), prevV.getCoord())) {
-
+ if( VectorUtil.vertexInTriangle3(a.getCoord(), b.getCoord(), c.getCoord(),
+ current.getCoord(), nextV.getCoord(), prevV.getCoord(),
+ tmpV1, tmpV2, tmpV3) ) {
return current;
}
- if(VectorUtil.tri2SegIntersection(a, b, c, prevV, current)
- || VectorUtil.tri2SegIntersection(a, b, c, current, nextV)
- || VectorUtil.tri2SegIntersection(a, b, c, prevV, nextV)) {
+ if(VectorUtil.testTri2SegIntersection(a, b, c, prevV, current) ||
+ VectorUtil.testTri2SegIntersection(a, b, c, current, nextV) ||
+ VectorUtil.testTri2SegIntersection(a, b, c, prevV, nextV)) {
return current;
}
}
@@ -471,9 +538,8 @@ public class OutlineShape implements Comparable<OutlineShape> {
final Vertex currentVertex = outline.getVertex(i);
final Vertex nextVertex = outline.getVertex((i+1)%vertexCount);
if ( !currentVertex.isOnCurve() && !nextVertex.isOnCurve() ) {
- final float[] newCoords = VectorUtil.mid(currentVertex.getCoord(),
- nextVertex.getCoord());
- final Vertex v = vertexFactory.create(newCoords, 0, 3, true);
+ VectorUtil.mid(tmpV1, currentVertex.getCoord(), nextVertex.getCoord());
+ final Vertex v = vertexFactory.create(tmpV1, 0, 3, true);
i++;
vertexCount++;
outline.addVertex(i, v);
@@ -496,49 +562,84 @@ public class OutlineShape implements Comparable<OutlineShape> {
outlineState = VerticesState.QUADRATIC_NURBS;
}
- private void generateVertexIds() {
+ private int generateVertexIds() {
int maxVertexId = 0;
for(int i=0; i<outlines.size(); i++) {
final ArrayList<Vertex> vertices = outlines.get(i).getVertices();
for(int pos=0; pos<vertices.size(); pos++) {
- Vertex vert = vertices.get(pos);
- vert.setId(maxVertexId);
- maxVertexId++;
+ vertices.get(pos).setId(maxVertexId++);
}
}
+ return maxVertexId;
}
- /** @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.
+ * <p>
+ * Vertices are cached until marked dirty.
+ * </p>
+ * <p>
+ * Should always be called <i>after</i> {@link #getTriangles(VerticesState)},
+ * since the latter will mark all cached vertices dirty!
+ * </p>
*/
- public ArrayList<Vertex> getVertices() {
- ArrayList<Vertex> vertices = new ArrayList<Vertex>();
- for(int i=0; i<outlines.size(); i++) {
- vertices.addAll(outlines.get(i).getVertices());
+ public final ArrayList<Vertex> getVertices() {
+ final boolean updated;
+ if( 0 != ( DIRTY_VERTICES & dirtyBits ) ) {
+ vertices.clear();
+ for(int i=0; i<outlines.size(); i++) {
+ vertices.addAll(outlines.get(i).getVertices());
+ }
+ dirtyBits &= ~DIRTY_VERTICES;
+ updated = true;
+ } else {
+ updated = false;
+ }
+ if(Region.DEBUG_INSTANCE) {
+ System.err.println("OutlineShape.getVertices(): o "+outlines.size()+", v "+vertices.size()+", updated "+updated);
}
return vertices;
}
+ private void triangulateImpl() {
+ if( 0 < outlines.size() ) {
+ sortOutlines();
+ generateVertexIds();
+
+ triangles.clear();
+ final Triangulator triangulator2d = Triangulation.create();
+ for(int index = 0; index<outlines.size(); index++) {
+ triangulator2d.addCurve(triangles, outlines.get(index), sharpness);
+ }
+ triangulator2d.generate(triangles);
+ triangulator2d.reset();
+ }
+ }
+
/**
- * Triangulate the {@link OutlineShape} generating a list of triangles
+ * Triangulate the {@link OutlineShape} generating a list of triangles,
+ * while {@link #transformOutlines(VerticesState)} beforehand.
+ * <p>
+ * Triangles are cached until marked dirty.
+ * </p>
* @return an arraylist of triangles representing the filled region
* which is produced by the combination of the outlines
*/
- public ArrayList<Triangle> triangulate() {
- if(outlines.size() == 0){
- return null;
+ public ArrayList<Triangle> getTriangles(VerticesState destinationType) {
+ final boolean updated;
+ if( 0 != ( DIRTY_TRIANGLES & dirtyBits ) ) {
+ transformOutlines(destinationType);
+ triangulateImpl();
+ updated = true;
+ dirtyBits |= DIRTY_VERTICES;
+ dirtyBits &= ~DIRTY_TRIANGLES;
+ } else {
+ updated = false;
}
- sortOutlines();
- generateVertexIds();
-
- Triangulator triangulator2d = Triangulation.create();
- for(int index = 0; index<outlines.size(); index++) {
- triangulator2d.addCurve(outlines.get(index));
+ if(Region.DEBUG_INSTANCE) {
+ System.err.println("OutlineShape.getTriangles().2: "+triangles.size()+", updated "+updated);
}
-
- ArrayList<Triangle> triangles = triangulator2d.generate();
- triangulator2d.reset();
-
return triangles;
}
@@ -550,24 +651,24 @@ public class OutlineShape implements Comparable<OutlineShape> {
Collections.reverse(outlines);
}
- /** Compare two outline shapes with Bounding Box area
+ /**
+ * Compare two outline shapes with Bounding Box area
* as criteria.
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
- public final int compareTo(OutlineShape outline) {
- float size = getBounds().getSize();
- float newSize = outline.getBounds().getSize();
- if(size < newSize){
+ public final int compareTo(final OutlineShape other) {
+ final float thisSize = getBounds().getSize();
+ final float otherSize = other.getBounds().getSize();
+ if( thisSize < otherSize ){
return -1;
- }
- else if(size > newSize){
+ } else if( thisSize > otherSize ) {
return 1;
}
- return 0;
+ return 0; // FIXME: No epsilon, i.e. smallest accurate float value ?
}
- private final void validateBoundingBox() {
+ private void validateBoundingBox() {
dirtyBits &= ~DIRTY_BOUNDS;
bbox.reset();
for (int i=0; i<outlines.size(); i++) {
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java
index a9779523a..8e68b7913 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/Region.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java
@@ -28,159 +28,248 @@
package com.jogamp.graph.curve;
import java.util.ArrayList;
+import java.util.List;
+import jogamp.graph.curve.opengl.VBORegion2PVBAAES2;
+import jogamp.graph.curve.opengl.VBORegion2PMSAAES2;
+import jogamp.graph.curve.opengl.VBORegionSPES2;
+import jogamp.graph.geom.plane.AffineTransform;
import jogamp.opengl.Debug;
+import com.jogamp.graph.curve.opengl.GLRegion;
import com.jogamp.graph.geom.Triangle;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.opengl.math.geom.AABBox;
-/** Abstract Outline shape GL representation
- * define the method an OutlineShape(s) is
- * binded rendered.
+/**
+ * Abstract Outline shape representation define the method an OutlineShape(s)
+ * is bound and rendered.
*
- * @see GLRegion
- */
+ * @see GLRegion */
public abstract class Region {
- /** Debug flag for region impl (graph.curve)
- */
+ /** Debug flag for region impl (graph.curve) */
public static final boolean DEBUG = Debug.debug("graph.curve");
+ public static final boolean DEBUG_INSTANCE = Debug.debug("graph.curve.instance");
- public static final boolean DEBUG_INSTANCE = false;
+ /**
+ * MSAA based Anti-Aliasing, a two pass region rendering, slower and more
+ * resource hungry (FBO), but providing fast MSAA in case
+ * the whole scene is not rendered with MSAA.
+ */
+ public static final int MSAA_RENDERING_BIT = 1 << 0;
- /** View based Anti-Aliasing, A Two pass region rendering, slower
- * and more resource hungry (FBO), but AA is perfect.
- * Otherwise the default fast one pass MSAA region rendering is being used.
+ /**
+ * View based Anti-Aliasing, a two pass region rendering, slower and more
+ * resource hungry (FBO), but AA is perfect. Otherwise the default fast one
+ * pass MSAA region rendering is being used.
*/
- public static final int VBAA_RENDERING_BIT = 1 << 0;
+ public static final int VBAA_RENDERING_BIT = 1 << 1;
- /** Use non uniform weights [0.0 .. 1.9] for curve region rendering.
- * Otherwise the default weight 1.0 for uniform curve region rendering is being applied.
+ /**
+ * Use non uniform weights [0.0 .. 1.9] for curve region rendering.
+ * Otherwise the default weight 1.0 for uniform curve region rendering is
+ * being applied.
*/
- public static final int VARIABLE_CURVE_WEIGHT_BIT = 1 << 1;
+ public static final int VARIABLE_CURVE_WEIGHT_BIT = 1 << 8;
public static final int TWO_PASS_DEFAULT_TEXTURE_UNIT = 0;
private final int renderModes;
private boolean dirty = true;
- protected int numVertices = 0;
+ private int numVertices = 0;
protected final AABBox box = new AABBox();
- protected ArrayList<Triangle> triangles = new ArrayList<Triangle>();
- protected ArrayList<Vertex> vertices = new ArrayList<Vertex>();
public static boolean isVBAA(int renderModes) {
- return 0 != ( renderModes & Region.VBAA_RENDERING_BIT );
+ return 0 != (renderModes & Region.VBAA_RENDERING_BIT);
+ }
+ public static boolean isMSAA(int renderModes) {
+ return 0 != (renderModes & Region.MSAA_RENDERING_BIT);
+ }
+ public static String getRenderModeString(int renderModes) {
+ if( Region.isVBAA(renderModes) ) {
+ return "vbaa";
+ } else if( Region.isMSAA(renderModes) ) {
+ return "msaa";
+ } else {
+ return "norm" ;
+ }
}
- /** Check if render mode capable of non uniform weights
- * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT},
- * {@link Region#VBAA_RENDERING_BIT}
- * @return true of capable of non uniform weights
- */
+ /**
+ * Check if render mode capable of non uniform weights
+ *
+ * @param renderModes
+ * bit-field of modes, e.g.
+ * {@link Region#VARIABLE_CURVE_WEIGHT_BIT},
+ * {@link Region#VBAA_RENDERING_BIT}
+ * @return true of capable of non uniform weights */
public static boolean isNonUniformWeight(int renderModes) {
- return 0 != ( renderModes & Region.VARIABLE_CURVE_WEIGHT_BIT );
+ return 0 != (renderModes & Region.VARIABLE_CURVE_WEIGHT_BIT);
+ }
+
+ /**
+ * Create a Region using the passed render mode
+ *
+ * <p> In case {@link Region#VBAA_RENDERING_BIT} is being requested the default texture unit
+ * {@link Region#TWO_PASS_DEFAULT_TEXTURE_UNIT} is being used.</p>
+ *
+ * @param rs the RenderState to be used
+ * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#VBAA_RENDERING_BIT}
+ */
+ public static GLRegion create(int renderModes) {
+ if( isVBAA(renderModes) ) {
+ return new VBORegion2PVBAAES2(renderModes, Region.TWO_PASS_DEFAULT_TEXTURE_UNIT);
+ } else if( isMSAA(renderModes) ) {
+ return new VBORegion2PMSAAES2(renderModes, Region.TWO_PASS_DEFAULT_TEXTURE_UNIT);
+ } else {
+ return new VBORegionSPES2(renderModes);
+ }
}
protected Region(int regionRenderModes) {
this.renderModes = regionRenderModes;
}
- /** Get current Models
- * @return bit-field of render modes
+ // FIXME: Better handling of impl. buffer growth .. !
+
+ protected abstract void pushVertex(float[] coords, float[] texParams);
+ protected abstract void pushIndex(int idx);
+
+ /**
+ * Return bit-field of render modes, see {@link #create(int)}.
*/
public final int getRenderModes() {
return renderModes;
}
- /** Check if current Region is using VBAA
- * @return true if capable of two pass rendering - VBAA
- */
- public boolean isVBAA() {
- return Region.isVBAA(renderModes);
+ protected void clearImpl() {
+ dirty = true;
+ numVertices = 0;
+ box.reset();
}
- /** Check if current instance uses non uniform weights
- * @return true if capable of nonuniform weights
+ /**
+ * Return true if capable of two pass rendering - VBAA, otherwise false.
*/
- public boolean isNonUniformWeight() {
- return Region.isNonUniformWeight(renderModes);
+ public final boolean isVBAA() {
+ return isVBAA(renderModes);
}
- /** Get the current number of vertices associated
- * with this region. This number is not necessary equal to
- * the OGL bound number of vertices.
- * @return vertices count
+ /**
+ * Return true if capable of two pass rendering - MSAA, otherwise false.
*/
- public final int getNumVertices(){
- return numVertices;
+ public final boolean isMSAA() {
+ return isMSAA(renderModes);
}
- /** 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)
+ /**
+ * Return true if capable of nonuniform weights, otherwise false.
*/
- public void addTriangle(Triangle tri) {
- triangles.add(tri);
- setDirty(true);
+ public final boolean isNonUniformWeight() {
+ return Region.isNonUniformWeight(renderModes);
}
- /** 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 an arraylist of triangle objects
- *
- * @see update(GL2ES2)
- */
- public void addTriangles(ArrayList<Triangle> tris) {
- triangles.addAll(tris);
- setDirty(true);
- }
+ final float[] coordsEx = new float[3];
- /** Adds a {@link Vertex} object to the Region
- * This vertex will be bound to OGL objects
- * on the next call to {@code update}
- * @param vert a vertex objects
- *
- * @see update(GL2ES2)
- */
- public void addVertex(Vertex vert) {
- vertices.add(vert);
+ private void pushNewVertexImpl(final Vertex vertIn, final AffineTransform transform) {
+ if( null != transform ) {
+ final float[] coordsIn = vertIn.getCoord();
+ transform.transform(coordsIn, coordsEx);
+ coordsEx[2] = coordsIn[2];
+ box.resize(coordsEx[0], coordsEx[1], coordsEx[2]);
+ pushVertex(coordsEx, vertIn.getTexCoord());
+ } else {
+ box.resize(vertIn.getX(), vertIn.getY(), vertIn.getZ());
+ pushVertex(vertIn.getCoord(), vertIn.getTexCoord());
+ }
numVertices++;
- setDirty(true);
}
- /** Adds a list of {@link Vertex} objects to the Region
- * These vertices are to be binded to OGL objects
- * on the next call to {@code update}
- * @param verts an arraylist of vertex objects
- *
- * @see update(GL2ES2)
- */
- public void addVertices(ArrayList<Vertex> verts) {
- vertices.addAll(verts);
- numVertices = vertices.size();
+ private void pushNewVertexIdxImpl(final Vertex vertIn, final AffineTransform transform) {
+ pushIndex(numVertices);
+ pushNewVertexImpl(vertIn, transform);
+ }
+
+ public final void addOutlineShape(final OutlineShape shape, final AffineTransform transform) {
+ final List<Triangle> trisIn = shape.getTriangles(OutlineShape.VerticesState.QUADRATIC_NURBS);
+ final ArrayList<Vertex> vertsIn = shape.getVertices();
+ if(DEBUG_INSTANCE) {
+ System.err.println("Region.addOutlineShape().0: tris: "+trisIn.size()+", verts "+vertsIn.size()+", transform "+transform);
+ }
+ final int idxOffset = numVertices;
+ int vertsVNewIdxCount = 0, vertsTMovIdxCount = 0, vertsTNewIdxCount = 0, tris = 0;
+ int vertsDupCountV = 0, vertsDupCountT = 0, vertsKnownMovedT = 0;
+ if( vertsIn.size() >= 3 ) {
+ if(DEBUG_INSTANCE) {
+ System.err.println("Region.addOutlineShape(): Processing Vertices");
+ }
+ for(int i=0; i<vertsIn.size(); i++) {
+ pushNewVertexImpl(vertsIn.get(i), transform);
+ vertsVNewIdxCount++;
+ }
+ if(DEBUG_INSTANCE) {
+ System.err.println("Region.addOutlineShape(): Processing Triangles");
+ }
+ for(int i=0; i<trisIn.size(); i++) {
+ final Triangle triIn = trisIn.get(i);
+ if(Region.DEBUG_INSTANCE) {
+ System.err.println("T["+i+"]: "+triIn);
+ }
+ // triEx.addVertexIndicesOffset(idxOffset);
+ // triangles.add( triEx );
+ final Vertex[] triInVertices = triIn.getVertices();
+ final int tv0Idx = triInVertices[0].getId();
+ if( Integer.MAX_VALUE-idxOffset > tv0Idx ) { // Integer.MAX_VALUE != i0 // FIXME: renderer uses SHORT!
+ // valid 'known' idx - move by offset
+ if(Region.DEBUG_INSTANCE) {
+ System.err.println("T["+i+"]: Moved "+tv0Idx+" + "+idxOffset+" -> "+(tv0Idx+idxOffset));
+ }
+ pushIndex(tv0Idx+idxOffset);
+ pushIndex(triInVertices[1].getId()+idxOffset);
+ pushIndex(triInVertices[2].getId()+idxOffset);
+ vertsTMovIdxCount+=3;
+ } else {
+ // invalid idx - generate new one
+ if(Region.DEBUG_INSTANCE) {
+ System.err.println("T["+i+"]: New Idx "+numVertices);
+ }
+ pushNewVertexIdxImpl(triInVertices[0], transform);
+ pushNewVertexIdxImpl(triInVertices[1], transform);
+ pushNewVertexIdxImpl(triInVertices[2], transform);
+ vertsTNewIdxCount+=3;
+ }
+ tris++;
+ }
+ }
+ if(DEBUG_INSTANCE) {
+ System.err.println("Region.addOutlineShape().X: idxOffset "+idxOffset+", tris: "+tris+", verts [idx "+vertsTNewIdxCount+", add "+vertsTNewIdxCount+" = "+(vertsVNewIdxCount+vertsTNewIdxCount)+"]");
+ System.err.println("Region.addOutlineShape().X: verts: idx[v-new "+vertsVNewIdxCount+", t-new "+vertsTNewIdxCount+" = "+(vertsVNewIdxCount+vertsTNewIdxCount)+"]");
+ System.err.println("Region.addOutlineShape().X: verts: idx t-moved "+vertsTMovIdxCount+", numVertices "+numVertices);
+ System.err.println("Region.addOutlineShape().X: verts: v-dups "+vertsDupCountV+", t-dups "+vertsDupCountT+", t-known "+vertsKnownMovedT);
+ // int vertsDupCountV = 0, vertsDupCountT = 0;
+ System.err.println("Region.addOutlineShape().X: box "+box);
+ }
setDirty(true);
}
- /**
- * @return the AxisAligned bounding box of
- * current region
- */
- public final AABBox getBounds(){
+ public final void addOutlineShapes(final List<OutlineShape> shapes, final AffineTransform transform) {
+ for (int i = 0; i < shapes.size(); i++) {
+ addOutlineShape(shapes.get(i), transform);
+ }
+ }
+
+ /** @return the AxisAligned bounding box of current region */
+ public final AABBox getBounds() {
return box;
}
- /** Check if this region is dirty. A region is marked dirty
- * when new Vertices, Triangles, and or Lines are added after a
- * call to update()
+ /** Check if this region is dirty. A region is marked dirty when new
+ * Vertices, Triangles, and or Lines are added after a call to update()
+ *
* @return true if region is Dirty, false otherwise
*
- * @see update(GL2ES2)
- */
+ * @see update(GL2ES2) */
public final boolean isDirty() {
return dirty;
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
index dfb7a95b3..defb7722a 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
@@ -27,17 +27,11 @@
*/
package com.jogamp.graph.curve.opengl;
-
-import java.util.ArrayList;
-
+import javax.media.opengl.GL;
import javax.media.opengl.GL2ES2;
-import com.jogamp.opengl.util.PMVMatrix;
-import com.jogamp.graph.curve.OutlineShape;
+import com.jogamp.opengl.util.PMVMatrix;
import com.jogamp.graph.curve.Region;
-import com.jogamp.graph.geom.Triangle;
-import com.jogamp.graph.geom.Vertex;
-import jogamp.graph.curve.opengl.RegionFactory;
/** A GLRegion is the OGL binding of one or more OutlineShapes
* Defined by its vertices and generated triangles. The Region
@@ -51,79 +45,87 @@ import jogamp.graph.curve.opengl.RegionFactory;
*/
public abstract class GLRegion extends Region {
- /** Create an ogl {@link GLRegion} defining the list of {@link OutlineShape}.
- * Combining the Shapes into single buffers.
- * @return the resulting Region inclusive the generated region
+ /**
+ * Create a GLRegion using the passed render mode
+ *
+ * <p> In case {@link Region#VBAA_RENDERING_BIT} is being requested the default texture unit
+ * {@link Region#TWO_PASS_DEFAULT_TEXTURE_UNIT} is being used.</p>
+ *
+ * @param rs the RenderState to be used
+ * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#VBAA_RENDERING_BIT}
*/
- public static GLRegion create(OutlineShape[] outlineShapes, int renderModes) {
- final GLRegion region = RegionFactory.create(renderModes);
-
- int numVertices = region.getNumVertices();
-
- for(int index=0; index<outlineShapes.length; index++) {
- OutlineShape outlineShape = outlineShapes[index];
- outlineShape.transformOutlines(OutlineShape.VerticesState.QUADRATIC_NURBS);
-
- ArrayList<Triangle> triangles = outlineShape.triangulate();
- region.addTriangles(triangles);
-
- ArrayList<Vertex> vertices = outlineShape.getVertices();
- for(int pos=0; pos < vertices.size(); pos++){
- Vertex vert = vertices.get(pos);
- vert.setId(numVertices++);
- }
- region.addVertices(vertices);
- }
+ public static GLRegion create(int renderModes) {
+ return Region.create(renderModes);
+ }
- return region;
+ protected GLRegion(int renderModes) {
+ super(renderModes);
}
/**
- * Create an ogl {@link GLRegion} defining this {@link OutlineShape}
- * @return the resulting Region.
+ * Updates a graph region by updating the ogl related
+ * objects for use in rendering if {@link #isDirty()}.
+ * <p>Allocates the ogl related data and initializes it the 1st time.<p>
+ * <p>Called by {@link #draw(GL2ES2, RenderState, int, int, int)}.</p>
*/
- public static GLRegion create(OutlineShape outlineShape, int renderModes) {
- final GLRegion region = RegionFactory.create(renderModes);
+ protected abstract void update(GL2ES2 gl, RegionRenderer renderer);
- outlineShape.transformOutlines(OutlineShape.VerticesState.QUADRATIC_NURBS);
- ArrayList<Triangle> triangles = (ArrayList<Triangle>) outlineShape.triangulate();
- ArrayList<Vertex> vertices = (ArrayList<Vertex>) outlineShape.getVertices();
- region.addVertices(vertices);
- region.addTriangles(triangles);
- return region;
- }
+ protected abstract void destroyImpl(GL2ES2 gl, RegionRenderer renderer);
- protected GLRegion(int renderModes) {
- super(renderModes);
- }
+ protected abstract void clearImpl(final GL2ES2 gl, final RegionRenderer renderer);
- /** Updates a graph region by updating the ogl related
- * objects for use in rendering if {@link #isDirty()}.
- * <p>Allocates the ogl related data and initializes it the 1st time.<p>
- * <p>Called by {@link #draw(GL2ES2, RenderState, int, int, int)}.</p>
- * @param rs TODO
+ /**
+ * Clears all data, i.e. triangles, vertices etc.
*/
- protected abstract void update(GL2ES2 gl, RenderState rs);
+ public void clear(final GL2ES2 gl, final RegionRenderer renderer) {
+ clearImpl(gl, renderer);
+ clearImpl();
+ }
- /** Delete and clean the associated OGL
- * objects
+ /**
+ * Delete and clear the associated OGL objects.
*/
- public abstract void destroy(GL2ES2 gl, RenderState rs);
+ public final void destroy(GL2ES2 gl, RegionRenderer renderer) {
+ clear(gl, renderer);
+ destroyImpl(gl, renderer);
+ }
- /** Renders the associated OGL objects specifying
+ /**
+ * Renders the associated OGL objects specifying
* current width/hight of window for multi pass rendering
* of the region.
+ * <p>
+ * User shall consider {@link RegionRenderer#enable(GL2ES2, boolean) enabling}
+ * the renderer beforehand and {@link RegionRenderer#enable(GL2ES2, boolean) disabling}
+ * it afterwards when used in conjunction with other renderer.
+ * </p>
+ * <p>
+ * Users shall also consider setting the {@link GL#glClearColor(float, float, float, float) Clear Color}
+ * appropriately:
+ * <ul>
+ * <li>If {@link GL#GL_BLEND blending} is enabled, <i>RGB</i> shall be set to text color, otherwise
+ * blending will reduce the alpha seam's contrast and the font will appear thinner.</li>
+ * <li>If {@link GL#GL_BLEND blending} is disabled, <i>RGB</i> shall be set to the actual desired background.</li>
+ * </ul>
+ * The <i>alpha</i> component shall be set to zero.
+ * Note: If {@link GL#GL_BLEND blending} is enabled, the
+ * {@link RegionRenderer} might need to be
+ * {@link RegionRenderer#create(RenderState, int, com.jogamp.graph.curve.opengl.RegionRenderer.GLCallback, com.jogamp.graph.curve.opengl.RegionRenderer.GLCallback) created}
+ * with the appropriate {@link {@link RegionRenderer.GLCallback callbacks}.
+ * </p>
* @param matrix current {@link PMVMatrix}.
- * @param rs the RenderState to be used
- * @param vp_width current screen width
- * @param vp_height current screen height
- * @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.
+ * @param renderer the {@link RegionRenderer} to be used
+ * @param sampleCount desired multisampling sample count for msaa-rendering.
+ * The actual used scample-count is written back when msaa-rendering is enabled, otherwise the store is untouched.
+ * @see RegionRenderer#enable(GL2ES2, boolean)
*/
- public final void draw(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int[/*1*/] texWidth) {
- update(gl, rs);
- drawImpl(gl, rs, vp_width, vp_height, texWidth);
+ public final void draw(GL2ES2 gl, RegionRenderer renderer, int[/*1*/] sampleCount) {
+ if(isDirty()) {
+ update(gl, renderer);
+ setDirty(false);
+ }
+ drawImpl(gl, renderer, sampleCount);
}
- protected abstract void drawImpl(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int[/*1*/] texWidth);
+ protected abstract void drawImpl(GL2ES2 gl, RegionRenderer renderer, int[/*1*/] sampleCount);
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
index f7d4bfd2f..1f6e532d3 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
@@ -27,58 +27,373 @@
*/
package com.jogamp.graph.curve.opengl;
+import java.nio.FloatBuffer;
+
+import javax.media.opengl.GL;
import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLException;
+import javax.media.opengl.fixedfunc.GLMatrixFunc;
-import com.jogamp.graph.curve.OutlineShape;
+import com.jogamp.opengl.util.glsl.ShaderCode;
+import com.jogamp.opengl.util.glsl.ShaderState;
+import com.jogamp.opengl.util.PMVMatrix;
import com.jogamp.graph.curve.Region;
-public abstract class RegionRenderer extends Renderer {
+/**
+ * OpenGL {@link Region} renderer
+ * <p>
+ * All OpenGL related operations regarding {@link Region}s
+ * are passed through an instance of this class.
+ * </p>
+ */
+public abstract class RegionRenderer {
+ protected static final boolean DEBUG = Region.DEBUG;
+ protected static final boolean DEBUG_INSTANCE = Region.DEBUG_INSTANCE;
+
+ public interface GLCallback {
+ /**
+ * @param gl a current GL object
+ * @param renderer {@link RegionRenderer} calling this method.
+ */
+ void run(GL gl, RegionRenderer renderer);
+ }
+
+ /**
+ * Default {@link GL#GL_BLEND} <i>enable</i> {@link GLCallback},
+ * turning on the {@link GL#GL_BLEND} state and setting up
+ * {@link GL#glBlendFunc(int, int) glBlendFunc}({@link GL#GL_SRC_ALPHA}, {@link GL#GL_ONE_MINUS_SRC_ALPHA}).
+ * @see #setEnableCallback(GLCallback, GLCallback)
+ * @see #enable(GL2ES2, boolean)
+ */
+ public static final GLCallback defaultBlendEnable = new GLCallback() {
+ @Override
+ public void run(final GL gl, final RegionRenderer args) {
+ gl.glEnable(GL.GL_BLEND);
+ gl.glBlendEquation(GL.GL_FUNC_ADD); // default
+ gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
+ }
+ };
+
+ /**
+ * Default {@link GL#GL_BLEND} <i>disable</i> {@link GLCallback},
+ * simply turning off the {@link GL#GL_BLEND} state.
+ * @see #setEnableCallback(GLCallback, GLCallback)
+ * @see #enable(GL2ES2, boolean)
+ */
+ public static final GLCallback defaultBlendDisable = new GLCallback() {
+ @Override
+ public void run(final GL gl, final RegionRenderer args) {
+ gl.glDisable(GL.GL_BLEND);
+ }
+ };
+
+ public static boolean isWeightValid(float v) {
+ return 0.0f <= v && v <= 1.9f ;
+ }
/**
* Create a Hardware accelerated Region Renderer.
+ * <p>
+ * The optional {@link GLCallback}s <code>enableCallback</code> and <code>disableCallback</code>
+ * maybe used to issue certain tasks at {@link #enable(GL2ES2, boolean)}.<br/>
+ * For example, instances {@link #defaultBlendEnable} and {@link #defaultBlendDisable}
+ * can be utilized to enable and disable {@link GL#GL_BLEND}.
+ * </p>
* @param rs the used {@link RenderState}
* @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#VBAA_RENDERING_BIT}
+ * @param enableCallback optional {@link GLCallback}, if not <code>null</code> will be issued at
+ * {@link #init(GL2ES2) init(gl)} and {@link #enable(GL2ES2, boolean) enable(gl, true)}.
+ * @param disableCallback optional {@link GLCallback}, if not <code>null</code> will be issued at
+ * {@link #enable(GL2ES2, boolean) enable(gl, false)}.
* @return an instance of Region Renderer
+ * @see #enable(GL2ES2, boolean)
*/
- public static RegionRenderer create(RenderState rs, int renderModes) {
- return new jogamp.graph.curve.opengl.RegionRendererImpl01(rs, renderModes);
+ public static RegionRenderer create(final RenderState rs, final int renderModes,
+ final GLCallback enableCallback, final GLCallback disableCallback) {
+ return new jogamp.graph.curve.opengl.RegionRendererImpl01(rs, renderModes, enableCallback, disableCallback);
}
- protected RegionRenderer(RenderState rs, int renderModes) {
- super(rs, renderModes);
+ protected final int renderModes;
+ protected final RenderState rs;
+
+ protected final GLCallback enableCallback;
+ protected final GLCallback disableCallback;
+
+ protected int vp_width;
+ protected int vp_height;
+ protected boolean initialized;
+ private boolean vboSupported = false;
+
+ public final boolean isInitialized() { return initialized; }
+
+ public final int getWidth() { return vp_width; }
+ public final int getHeight() { return vp_height; }
+
+ public final float getWeight() { return rs.getWeight().floatValue(); }
+ public final float getAlpha() { return rs.getAlpha().floatValue(); }
+ public final PMVMatrix getMatrix() { return rs.pmvMatrix(); }
+
+ /**
+ * Implementation shall load, compile and link the shader program and leave it active.
+ * @param gl referencing the current GLContext to which the ShaderState is bound to
+ * @return
+ */
+ protected abstract boolean initImpl(GL2ES2 gl);
+
+ /** Delete and clean the associated OGL objects */
+ protected abstract void destroyImpl(GL2ES2 gl);
+
+ //////////////////////////////////////
+
+ /**
+ * @param rs the used {@link RenderState}
+ * @param renderModes bit-field of modes
+ */
+ protected RegionRenderer(final RenderState rs, final int renderModes, final GLCallback enableCallback, final GLCallback disableCallback) {
+ this.rs = rs;
+ this.renderModes = renderModes;
+ this.enableCallback = enableCallback;
+ this.disableCallback = disableCallback;
+ }
+
+ public final int getRenderModes() {
+ return renderModes;
}
+ public final boolean usesVariableCurveWeight() { return Region.isNonUniformWeight(renderModes); }
- /** Render an {@link OutlineShape} in 3D space at the position provided
- * the triangles of the shapes will be generated, if not yet generated
- * @param region the OutlineShape to Render.
- * @param position the initial translation of the outlineShape.
- * @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 HwRegionRenderer not initialized
+ /**
+ * @return true if Region's renderModes contains all bits as this Renderer's renderModes
+ * except {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, otherwise false.
+ */
+ public final boolean areRenderModesCompatible(final Region region) {
+ final int cleanRenderModes = getRenderModes() & ( Region.VARIABLE_CURVE_WEIGHT_BIT );
+ return cleanRenderModes == ( region.getRenderModes() & cleanRenderModes );
+ }
+
+ public final boolean isVBOSupported() { return vboSupported; }
+
+ /**
+ * Initialize shader and bindings for GPU based rendering bound to the given GL object's GLContext
+ * if not initialized yet.
+ * <p>Leaves the renderer enabled, ie ShaderState.</p>
+ * <p>Shall be called by a {@code draw()} method, e.g. {@link RegionRenderer#draw(GL2ES2, Region, int)}</p>
+ *
+ * @param gl referencing the current GLContext to which the ShaderState is bound to
+ * @throws GLException if initialization failed
*/
- public final void draw(GL2ES2 gl, Region region, float[] position, int[/*1*/] texWidth) {
- if(!isInitialized()) {
- throw new GLException("RegionRenderer: not initialized!");
+ public final void init(GL2ES2 gl) throws GLException {
+ if(initialized){
+ return;
}
- if( !areRenderModesCompatible(region) ) {
- throw new GLException("Incompatible render modes, : region modes "+region.getRenderModes()+
- " doesn't contain renderer modes "+this.getRenderModes());
+ vboSupported = gl.isFunctionAvailable("glGenBuffers") &&
+ gl.isFunctionAvailable("glBindBuffer") &&
+ gl.isFunctionAvailable("glBufferData") &&
+ gl.isFunctionAvailable("glDrawElements") &&
+ gl.isFunctionAvailable("glVertexAttribPointer") &&
+ gl.isFunctionAvailable("glDeleteBuffers");
+
+ if(DEBUG) {
+ System.err.println("TextRendererImpl01: VBO Supported = " + isVBOSupported());
+ }
+
+ if(!vboSupported){
+ throw new GLException("VBO not supported");
+ }
+
+ rs.attachTo(gl);
+
+ if( null != enableCallback ) {
+ enableCallback.run(gl, this);
+ }
+
+ initialized = initImpl(gl);
+ if(!initialized) {
+ throw new GLException("Shader initialization failed");
+ }
+
+ if(!rs.getShaderState().uniform(gl, rs.getPMVMatrix())) {
+ throw new GLException("Error setting PMVMatrix in shader: "+rs.getShaderState());
+ }
+
+ if( Region.isNonUniformWeight( getRenderModes() ) ) {
+ if(!rs.getShaderState().uniform(gl, rs.getWeight())) {
+ throw new GLException("Error setting weight in shader: "+rs.getShaderState());
+ }
}
- drawImpl(gl, region, position, texWidth);
+
+ if(!rs.getShaderState().uniform(gl, rs.getAlpha())) {
+ throw new GLException("Error setting global alpha in shader: "+rs.getShaderState());
+ }
+
+ if(!rs.getShaderState().uniform(gl, rs.getColorStatic())) {
+ throw new GLException("Error setting global color in shader: "+rs.getShaderState());
+ }
+ }
+
+ public final void destroy(GL2ES2 gl) {
+ if(!initialized){
+ if(DEBUG_INSTANCE) {
+ System.err.println("TextRenderer: Not initialized!");
+ }
+ return;
+ }
+ rs.getShaderState().useProgram(gl, false);
+ destroyImpl(gl);
+ rs.destroy(gl);
+ initialized = false;
}
+ public final RenderState getRenderState() { return rs; }
+ public final ShaderState getShaderState() { return rs.getShaderState(); }
+
/**
- * Usually just dispatched the draw call to the Region's draw implementation,
- * e.g. {@link com.jogamp.graph.curve.opengl.GLRegion#draw(GL2ES2, RenderState, int, int, int[]) GLRegion#draw(GL2ES2, RenderState, int, int, int[])}.
+ * Enabling or disabling the {@link RenderState#getShaderState() RenderState}'s
+ * {@link ShaderState#useProgram(GL2ES2, boolean) ShaderState program}.
+ * <p>
+ * In case enable and disable {@link GLCallback}s are setup via {@link #create(RenderState, int, GLCallback, GLCallback)},
+ * they will be called before toggling the shader program.
+ * </p>
+ * @see #create(RenderState, int, GLCallback, GLCallback)
*/
- protected abstract void drawImpl(GL2ES2 gl, Region region, float[] position, int[] texWidth);
+ public final void enable(GL2ES2 gl, boolean enable) {
+ if( enable ) {
+ if( null != enableCallback ) {
+ enableCallback.run(gl, this);
+ }
+ } else {
+ if( null != disableCallback ) {
+ disableCallback.run(gl, this);
+ }
+ }
+ rs.getShaderState().useProgram(gl, enable);
+ }
+
+ public final void setWeight(GL2ES2 gl, float v) {
+ if( !isWeightValid(v) ) {
+ throw new IllegalArgumentException("Weight out of range");
+ }
+ rs.getWeight().setData(v);
+ if(null != gl && rs.getShaderState().inUse() && Region.isNonUniformWeight( getRenderModes() ) ) {
+ rs.getShaderState().uniform(gl, rs.getWeight());
+ }
+ }
+
+ public final void setAlpha(GL2ES2 gl, float alpha_t) {
+ rs.getAlpha().setData(alpha_t);
+ if(null != gl && rs.getShaderState().inUse()) {
+ rs.getShaderState().uniform(gl, rs.getAlpha());
+ }
+
+ }
+
+ public final void getColorStatic(GL2ES2 gl, float[] rgb) {
+ FloatBuffer fb = (FloatBuffer) rs.getColorStatic().getBuffer();
+ rgb[0] = fb.get(0);
+ rgb[1] = fb.get(1);
+ rgb[2] = fb.get(2);
+ }
+
+ public final void setColorStatic(GL2ES2 gl, float r, float g, float b){
+ FloatBuffer fb = (FloatBuffer) rs.getColorStatic().getBuffer();
+ fb.put(0, r);
+ fb.put(1, g);
+ fb.put(2, b);
+ if(null != gl && rs.getShaderState().inUse()) {
+ rs.getShaderState().uniform(gl, rs.getColorStatic());
+ }
+ }
+
+ public final void rotate(GL2ES2 gl, float angle, float x, float y, float z) {
+ rs.pmvMatrix().glRotatef(angle, x, y, z);
+ updateMatrix(gl);
+ }
+
+ public final void translate(GL2ES2 gl, float x, float y, float z) {
+ rs.pmvMatrix().glTranslatef(x, y, z);
+ updateMatrix(gl);
+ }
+
+ public final void scale(GL2ES2 gl, float x, float y, float z) {
+ rs.pmvMatrix().glScalef(x, y, z);
+ updateMatrix(gl);
+ }
+
+ public final void resetModelview(GL2ES2 gl) {
+ rs.pmvMatrix().glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
+ rs.pmvMatrix().glLoadIdentity();
+ updateMatrix(gl);
+ }
+
+ public final void updateMatrix(GL2ES2 gl) {
+ if(initialized && null != gl && rs.getShaderState().inUse()) {
+ rs.getShaderState().uniform(gl, rs.getPMVMatrix());
+ }
+ }
+
+ /** No PMVMatrix operation is performed here. PMVMatrix will be updated if gl is not null. */
+ public final boolean reshapeNotify(GL2ES2 gl, int width, int height) {
+ this.vp_width = width;
+ this.vp_height = height;
+ updateMatrix(gl);
+ return true;
+ }
- @Override
- protected void destroyImpl(GL2ES2 gl) {
- // nop
+ public final boolean reshapePerspective(GL2ES2 gl, float angle, int width, int height, float near, float far) {
+ this.vp_width = width;
+ this.vp_height = height;
+ final float ratio = (float)width/(float)height;
+ final PMVMatrix p = rs.pmvMatrix();
+ p.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
+ p.glLoadIdentity();
+ p.gluPerspective(angle, ratio, near, far);
+ updateMatrix(gl);
+ return true;
}
+ public final boolean reshapeOrtho(GL2ES2 gl, int width, int height, float near, float far) {
+ this.vp_width = width;
+ this.vp_height = height;
+ final PMVMatrix p = rs.pmvMatrix();
+ p.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
+ p.glLoadIdentity();
+ p.glOrthof(0, width, 0, height, near, far);
+ updateMatrix(gl);
+ return true;
+ }
+
+ protected String getVertexShaderName() {
+ return "curverenderer" + getImplVersion();
+ }
+
+ protected String getFragmentShaderName() {
+ final String version = getImplVersion();
+ final String pass;
+ if( Region.isVBAA(renderModes) ) {
+ pass = "-2pass_vbaa";
+ } else if( Region.isMSAA(renderModes) ) {
+ pass = "-2pass_msaa";
+ } else {
+ pass = "-1pass_norm" ;
+ }
+ final String weight = Region.isNonUniformWeight(renderModes) ? "-weight" : "" ;
+ return "curverenderer" + version + pass + weight;
+ }
-}
+ // FIXME: Really required to have sampler2D def. precision ? If not, we can drop getFragmentShaderPrecision(..) and use default ShaderCode ..
+ public static final String es2_precision_fp = "\nprecision mediump float;\nprecision mediump int;\nprecision mediump sampler2D;\n";
+
+ protected String getFragmentShaderPrecision(GL2ES2 gl) {
+ if( gl.isGLES() ) {
+ return es2_precision_fp;
+ }
+ if( ShaderCode.requiresGL3DefaultPrecision(gl) ) {
+ return ShaderCode.gl3_default_precision_fp;
+ }
+ return null;
+ }
+
+ protected String getImplVersion() {
+ return "01";
+ }
+} \ No newline at end of file
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java
deleted file mode 100644
index 029286601..000000000
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java
+++ /dev/null
@@ -1,302 +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.nio.FloatBuffer;
-
-import javax.media.opengl.GL2ES2;
-import javax.media.opengl.GLException;
-import javax.media.opengl.fixedfunc.GLMatrixFunc;
-
-import com.jogamp.opengl.util.glsl.ShaderCode;
-import com.jogamp.opengl.util.glsl.ShaderState;
-import com.jogamp.opengl.util.PMVMatrix;
-
-import com.jogamp.graph.curve.Region;
-
-public abstract class Renderer {
- protected static final boolean DEBUG = Region.DEBUG;
- protected static final boolean DEBUG_INSTANCE = Region.DEBUG_INSTANCE;
-
- public static boolean isWeightValid(float v) {
- return 0.0f <= v && v <= 1.9f ;
- }
-
- protected final int renderModes;
- protected int vp_width;
- protected int vp_height;
- protected boolean initialized;
- protected final RenderState rs;
- private boolean vboSupported = false;
-
- public final boolean isInitialized() { return initialized; }
-
- public final int getWidth() { return vp_width; }
- public final int getHeight() { return vp_height; }
-
- public float getWeight() { return rs.getWeight().floatValue(); }
- public float getAlpha() { return rs.getAlpha().floatValue(); }
- public final PMVMatrix getMatrix() { return rs.pmvMatrix(); }
-
- /**
- * Implementation shall load, compile and link the shader program and leave it active.
- * @param gl referencing the current GLContext to which the ShaderState is bound to
- * @return
- */
- protected abstract boolean initShaderProgram(GL2ES2 gl);
-
- protected abstract void destroyImpl(GL2ES2 gl);
-
- /**
- * @param rs the used {@link RenderState}
- * @param renderModes bit-field of modes
- */
- protected Renderer(RenderState rs, int renderModes) {
- this.rs = rs;
- this.renderModes = renderModes;
- }
-
- public final int getRenderModes() {
- return renderModes;
- }
-
- public boolean usesVariableCurveWeight() { return Region.isNonUniformWeight(renderModes); }
-
- /**
- * @return true if Region's renderModes contains all bits as this Renderer's renderModes
- * except {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, otherwise false.
- */
- public final boolean areRenderModesCompatible(Region region) {
- final int cleanRenderModes = getRenderModes() & ( Region.VARIABLE_CURVE_WEIGHT_BIT );
- return cleanRenderModes == ( region.getRenderModes() & cleanRenderModes );
- }
-
- public final boolean isVBOSupported() { return vboSupported; }
-
- /**
- * Initialize shader and bindings for GPU based rendering bound to the given GL object's GLContext
- * if not initialized yet.
- * <p>Leaves the renderer enabled, ie ShaderState.</p>
- * <p>Shall be called by a {@code draw()} method, e.g. {@link RegionRenderer#draw(GL2ES2, Region, float[], int)}</p>
- *
- * @param gl referencing the current GLContext to which the ShaderState is bound to
- * @throws GLException if initialization failed
- */
- public final void init(GL2ES2 gl) throws GLException {
- if(initialized){
- return;
- }
- vboSupported = gl.isFunctionAvailable("glGenBuffers") &&
- gl.isFunctionAvailable("glBindBuffer") &&
- gl.isFunctionAvailable("glBufferData") &&
- gl.isFunctionAvailable("glDrawElements") &&
- gl.isFunctionAvailable("glVertexAttribPointer") &&
- gl.isFunctionAvailable("glDeleteBuffers");
-
- if(DEBUG) {
- System.err.println("TextRendererImpl01: VBO Supported = " + isVBOSupported());
- }
-
- if(!vboSupported){
- throw new GLException("VBO not supported");
- }
-
- rs.attachTo(gl);
-
- gl.glEnable(GL2ES2.GL_BLEND);
- gl.glBlendFunc(GL2ES2.GL_SRC_ALPHA, GL2ES2.GL_ONE_MINUS_SRC_ALPHA); // FIXME: alpha blending stage ?
-
- initialized = initShaderProgram(gl);
- if(!initialized) {
- throw new GLException("Shader initialization failed");
- }
-
- if(!rs.getShaderState().uniform(gl, rs.getPMVMatrix())) {
- throw new GLException("Error setting PMVMatrix in shader: "+rs.getShaderState());
- }
-
- if( Region.isNonUniformWeight( getRenderModes() ) ) {
- if(!rs.getShaderState().uniform(gl, rs.getWeight())) {
- throw new GLException("Error setting weight in shader: "+rs.getShaderState());
- }
- }
-
- if(!rs.getShaderState().uniform(gl, rs.getAlpha())) {
- throw new GLException("Error setting global alpha in shader: "+rs.getShaderState());
- }
-
- if(!rs.getShaderState().uniform(gl, rs.getColorStatic())) {
- throw new GLException("Error setting global color in shader: "+rs.getShaderState());
- }
- }
-
- public final void flushCache(GL2ES2 gl) {
- // FIXME: REMOVE !
- }
-
- public void destroy(GL2ES2 gl) {
- if(!initialized){
- if(DEBUG_INSTANCE) {
- System.err.println("TextRenderer: Not initialized!");
- }
- return;
- }
- rs.getShaderState().useProgram(gl, false);
- destroyImpl(gl);
- rs.destroy(gl);
- initialized = false;
- }
-
- public final RenderState getRenderState() { return rs; }
- public final ShaderState getShaderState() { return rs.getShaderState(); }
-
- public final void enable(GL2ES2 gl, boolean enable) {
- rs.getShaderState().useProgram(gl, enable);
- }
-
- public void setWeight(GL2ES2 gl, float v) {
- if( !isWeightValid(v) ) {
- throw new IllegalArgumentException("Weight out of range");
- }
- rs.getWeight().setData(v);
- if(null != gl && rs.getShaderState().inUse() && Region.isNonUniformWeight( getRenderModes() ) ) {
- rs.getShaderState().uniform(gl, rs.getWeight());
- }
- }
-
- public void setAlpha(GL2ES2 gl, float alpha_t) {
- rs.getAlpha().setData(alpha_t);
- if(null != gl && rs.getShaderState().inUse()) {
- rs.getShaderState().uniform(gl, rs.getAlpha());
- }
-
- }
-
- public void getColorStatic(GL2ES2 gl, float[] rgb) {
- FloatBuffer fb = (FloatBuffer) rs.getColorStatic().getBuffer();
- rgb[0] = fb.get(0);
- rgb[1] = fb.get(1);
- rgb[2] = fb.get(2);
- }
-
- public void setColorStatic(GL2ES2 gl, float r, float g, float b){
- FloatBuffer fb = (FloatBuffer) rs.getColorStatic().getBuffer();
- fb.put(0, r);
- fb.put(1, g);
- fb.put(2, b);
- if(null != gl && rs.getShaderState().inUse()) {
- rs.getShaderState().uniform(gl, rs.getColorStatic());
- }
- }
-
- public void rotate(GL2ES2 gl, float angle, float x, float y, float z) {
- rs.pmvMatrix().glRotatef(angle, x, y, z);
- updateMatrix(gl);
- }
-
- public void translate(GL2ES2 gl, float x, float y, float z) {
- rs.pmvMatrix().glTranslatef(x, y, z);
- updateMatrix(gl);
- }
-
- public void scale(GL2ES2 gl, float x, float y, float z) {
- rs.pmvMatrix().glScalef(x, y, z);
- updateMatrix(gl);
- }
-
- public void resetModelview(GL2ES2 gl) {
- rs.pmvMatrix().glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
- rs.pmvMatrix().glLoadIdentity();
- updateMatrix(gl);
- }
-
- public void updateMatrix(GL2ES2 gl) {
- if(initialized && null != gl && rs.getShaderState().inUse()) {
- rs.getShaderState().uniform(gl, rs.getPMVMatrix());
- }
- }
-
- /** No PMVMatrix operation is performed here. PMVMatrix will be updated if gl is not null. */
- public boolean reshapeNotify(GL2ES2 gl, int width, int height) {
- this.vp_width = width;
- this.vp_height = height;
- updateMatrix(gl);
- return true;
- }
-
- public boolean reshapePerspective(GL2ES2 gl, float angle, int width, int height, float near, float far) {
- this.vp_width = width;
- this.vp_height = height;
- final float ratio = (float)width/(float)height;
- final PMVMatrix p = rs.pmvMatrix();
- p.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- p.glLoadIdentity();
- p.gluPerspective(angle, ratio, near, far);
- updateMatrix(gl);
- return true;
- }
-
- public boolean reshapeOrtho(GL2ES2 gl, int width, int height, float near, float far) {
- this.vp_width = width;
- this.vp_height = height;
- final PMVMatrix p = rs.pmvMatrix();
- p.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- p.glLoadIdentity();
- p.glOrthof(0, width, 0, height, near, far);
- updateMatrix(gl);
- return true;
- }
-
- protected String getVertexShaderName() {
- return "curverenderer" + getImplVersion();
- }
-
- protected String getFragmentShaderName() {
- final String version = getImplVersion();
- final String pass = Region.isVBAA(renderModes) ? "-2pass" : "-1pass" ;
- final String weight = Region.isNonUniformWeight(renderModes) ? "-weight" : "" ;
- return "curverenderer" + version + pass + weight;
- }
-
- // FIXME: Really required to have sampler2D def. precision ? If not, we can drop getFragmentShaderPrecision(..) and use default ShaderCode ..
- public static final String es2_precision_fp = "\nprecision mediump float;\nprecision mediump int;\nprecision mediump sampler2D;\n";
-
- protected String getFragmentShaderPrecision(GL2ES2 gl) {
- if( gl.isGLES() ) {
- return es2_precision_fp;
- }
- if( ShaderCode.requiresGL3DefaultPrecision(gl) ) {
- return ShaderCode.gl3_default_precision_fp;
- }
- return null;
- }
-
- protected String getImplVersion() {
- return "01";
- }
-} \ No newline at end of file
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java
new file mode 100644
index 000000000..0721c4726
--- /dev/null
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java
@@ -0,0 +1,316 @@
+/**
+ * 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 javax.media.opengl.GL2ES2;
+import javax.media.opengl.GLException;
+
+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.Vertex;
+import com.jogamp.graph.geom.Vertex.Factory;
+
+/**
+ * Text {@link GLRegion} Utility Class
+ */
+public class TextRegionUtil {
+
+ public final RegionRenderer renderer;
+
+ public TextRegionUtil(final RegionRenderer renderer) {
+ this.renderer = renderer;
+ }
+
+ public static interface ShapeVisitor {
+ /**
+ * Visiting the given {@link OutlineShape} with it's corresponding {@link AffineTransform}.
+ * @param shape may be used as is, otherwise a copy shall be made if intended to be modified.
+ * @param t may be used immediately as is, otherwise a copy shall be made if stored.
+ */
+ public void visit(final OutlineShape shape, final AffineTransform t);
+ }
+
+ /**
+ * Visit each {@link Font.Glyph}'s {@link OutlineShape} with the given {@link ShapeVisitor}
+ * additionally passing the progressed {@link AffineTransform}.
+ * The latter reflects the given font metric, pixelSize and hence character position.
+ * @param visitor
+ * @param transform
+ * @param font the target {@link Font}
+ * @param pixelSize Use {@link Font#getPixelSize(float, float)} for resolution correct pixel-size.
+ * @param str string text
+ */
+ public static void processString(final ShapeVisitor visitor, final AffineTransform transform,
+ final Font font, final float pixelSize, final CharSequence str) {
+ final int charCount = str.length();
+
+ // region.setFlipped(true);
+ final Font.Metrics metrics = font.getMetrics();
+ final float lineHeight = font.getLineHeight(pixelSize);
+
+ final float scale = metrics.getScale(pixelSize);
+ final AffineTransform t = new AffineTransform(transform);
+
+ float y = 0;
+ float advanceTotal = 0;
+
+ for(int i=0; i< charCount; i++) {
+ final char character = str.charAt(i);
+ if( '\n' == character ) {
+ y -= lineHeight;
+ 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 ) {
+ continue;
+ }
+ visitor.visit(glyphShape, t);
+
+ advanceTotal += glyph.getAdvance(pixelSize, true);
+ }
+ }
+ }
+
+ /**
+ * Add the string in 3D space w.r.t. the font and pixelSize at the end of the {@link GLRegion}.
+ * @param region the {@link GLRegion} sink
+ * @param vertexFactory vertex impl factory {@link Factory}
+ * @param font the target {@link Font}
+ * @param pixelSize Use {@link Font#getPixelSize(float, float)} for resolution correct pixel-size.
+ * @param str string text
+ */
+ public static void addStringToRegion(final GLRegion region, final Factory<? extends Vertex> vertexFactory,
+ final Font font, final float pixelSize, final CharSequence str) {
+ final ShapeVisitor visitor = new ShapeVisitor() {
+ public final void visit(final OutlineShape shape, final AffineTransform t) {
+ region.addOutlineShape(shape, t);
+ } };
+ processString(visitor, new AffineTransform(vertexFactory), font, pixelSize, str);
+ }
+
+ /**
+ * Render the string in 3D space w.r.t. the font and pixelSize
+ * using a cached {@link GLRegion} for reuse.
+ * <p>
+ * Cached {@link GLRegion}s will be destroyed w/ {@link #clear(GL2ES2)} or to free memory.
+ * </p>
+ * @param gl the current GL state
+ * @param font {@link Font} to be used
+ * @param pixelSize Use {@link Font#getPixelSize(float, float)} for resolution correct pixel-size.
+ * @param str text to be rendered
+ * @param sampleCount desired multisampling sample count for msaa-rendering.
+ * The actual used scample-count is written back when msaa-rendering is enabled, otherwise the store is untouched.
+ * @throws Exception if TextRenderer not initialized
+ */
+ public void drawString3D(final GL2ES2 gl,
+ final Font font, final float pixelSize, final CharSequence str,
+ final int[/*1*/] sampleCount) {
+ if( !renderer.isInitialized() ) {
+ throw new GLException("TextRendererImpl01: not initialized!");
+ }
+ final int special = 0;
+ GLRegion region = getCachedRegion(font, str, pixelSize, special);
+ if(null == region) {
+ region = GLRegion.create(renderer.getRenderModes());
+ addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str);
+ addCachedRegion(gl, font, str, pixelSize, special, region);
+ }
+ region.draw(gl, renderer, sampleCount);
+ }
+
+ /**
+ * Render the string in 3D space w.r.t. the font and pixelSize
+ * using a temporary {@link GLRegion}, which will be destroyed afterwards.
+ * <p>
+ * In case of a multisampling region renderer, i.e. {@link Region#VBAA_RENDERING_BIT}, recreating the {@link GLRegion}
+ * is a huge performance impact.
+ * In such case better use {@link #drawString3D(GLRegion, RegionRenderer, GL2ES2, Font, float, CharSequence, int[])}
+ * instead.
+ * </p>
+ * @param gl the current GL state
+ * @param font {@link Font} to be used
+ * @param pixelSize Use {@link Font#getPixelSize(float, float)} for resolution correct pixel-size.
+ * @param str text to be rendered
+ * @param sampleCount desired multisampling sample count for msaa-rendering.
+ * The actual used scample-count is written back when msaa-rendering is enabled, otherwise the store is untouched.
+ * @throws Exception if TextRenderer not initialized
+ */
+ public static void drawString3D(final RegionRenderer renderer, final GL2ES2 gl,
+ final Font font, final float pixelSize, final CharSequence str,
+ final int[/*1*/] sampleCount) {
+ if(!renderer.isInitialized()){
+ throw new GLException("TextRendererImpl01: not initialized!");
+ }
+ final GLRegion region = GLRegion.create(renderer.getRenderModes());
+ addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str);
+ region.draw(gl, renderer, sampleCount);
+ region.destroy(gl, renderer);
+ }
+
+ /**
+ * Render the string in 3D space w.r.t. the font and pixelSize
+ * using the given {@link GLRegion}, which will {@link GLRegion#clear(GL2ES2, RegionRenderer) cleared} beforehand.
+ * @param gl the current GL state
+ * @param font {@link Font} to be used
+ * @param pixelSize Use {@link Font#getPixelSize(float, float)} for resolution correct pixel-size.
+ * @param str text to be rendered
+ * @param sampleCount desired multisampling sample count for msaa-rendering.
+ * The actual used scample-count is written back when msaa-rendering is enabled, otherwise the store is untouched.
+ * @throws Exception if TextRenderer not initialized
+ */
+ public static void drawString3D(final GLRegion region, final RegionRenderer renderer, final GL2ES2 gl,
+ final Font font, final float pixelSize, final CharSequence str,
+ final int[/*1*/] sampleCount) {
+ if(!renderer.isInitialized()){
+ throw new GLException("TextRendererImpl01: not initialized!");
+ }
+ region.clear(gl, renderer);
+ addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str);
+ region.draw(gl, renderer, sampleCount);
+ }
+
+ /**
+ * Clear all cached {@link GLRegions}.
+ */
+ public void clear(GL2ES2 gl) {
+ // fluchCache(gl) already called
+ final Iterator<GLRegion> iterator = stringCacheMap.values().iterator();
+ while(iterator.hasNext()){
+ final GLRegion region = iterator.next();
+ region.destroy(gl, renderer);
+ }
+ stringCacheMap.clear();
+ stringCacheArray.clear();
+ }
+
+ /**
+ * <p>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 </p>
+ *
+ * <p>The cache will be validate when the next string rendering happens.</p>
+ *
+ * @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, float pixelSize, int special) {
+ return stringCacheMap.get(getKey(font, str, pixelSize, special));
+ }
+
+ protected final void addCachedRegion(GL2ES2 gl, Font font, CharSequence str, float pixelSize, int special, GLRegion glyphString) {
+ if ( 0 != getCacheLimit() ) {
+ final String key = getKey(font, str, pixelSize, special);
+ 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 pixelSize, int special) {
+ final String key = getKey(font, str, pixelSize, special);
+ final GLRegion region = stringCacheMap.remove(key);
+ if(null != region) {
+ region.destroy(gl, renderer);
+ }
+ stringCacheArray.remove(key);
+ }
+
+ protected final void removeCachedRegion(GL2ES2 gl, int idx) {
+ final String key = stringCacheArray.remove(idx);
+ if( null != key ) {
+ final GLRegion region = stringCacheMap.remove(key);
+ if(null != region) {
+ region.destroy(gl, renderer);
+ }
+ }
+ }
+
+ protected final String getKey(Font font, CharSequence str, float pixelSize, int special) {
+ final StringBuilder sb = new StringBuilder();
+ return font.getName(sb, Font.NAME_UNIQUNAME)
+ .append(".").append(str.hashCode()).append(".").append(Float.floatToIntBits(pixelSize)).append(special).toString();
+ }
+
+ /** Default cache limit, see {@link #setCacheLimit(int)} */
+ public static final int DEFAULT_CACHE_LIMIT = 256;
+
+ private final HashMap<String, GLRegion> stringCacheMap = new HashMap<String, GLRegion>(DEFAULT_CACHE_LIMIT);
+ private final ArrayList<String> stringCacheArray = new ArrayList<String>(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 f6ce852d8..000000000
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java
+++ /dev/null
@@ -1,193 +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.font.Font;
-
-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 position the lower left corner of the string
- * @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, float[] position, 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<GlyphString> 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<GlyphString> iterator = stringCacheMap.values().iterator();
- while(iterator.hasNext()){
- GlyphString glyphString = iterator.next();
- glyphString.destroy(gl, rs);
- }
- stringCacheMap.clear();
- stringCacheArray.clear();
- }
-
- /**
- * <p>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 </p>
- *
- * <p>The cache will be validate when the next string rendering happens.</p>
- *
- * @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 HashMap<String, GlyphString> stringCacheMap = new HashMap<String, GlyphString>(DEFAULT_CACHE_LIMIT);
- private ArrayList<String> stringCacheArray = new ArrayList<String>(DEFAULT_CACHE_LIMIT);
- private int stringCacheLimit = DEFAULT_CACHE_LIMIT;
-} \ No newline at end of file
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..96ff4bbb8 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,20 @@ 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}
+ * @param sharpness TODO
*/
- public void addCurve(Outline outline);
+ public void addCurve(List<Triangle> sink, Outline outline, float sharpness);
/** 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<Triangle> generate();
+ public void generate(List<Triangle> 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 a4a8fd53d..ac7a904e7 100644
--- a/src/jogl/classes/com/jogamp/graph/font/Font.java
+++ b/src/jogl/classes/com/jogamp/graph/font/Font.java
@@ -27,16 +27,33 @@
*/
package com.jogamp.graph.font;
+import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.opengl.math.geom.AABBox;
/**
* Interface wrapper for font implementation.
- *
+ * <p>
* TrueType Font Specification:
- * http://developer.apple.com/fonts/ttrefman/rm06/Chap6.html
- *
+ * <ul>
+ * <li>http://www.freetype.org/freetype2/documentation.html</li>
+ * <li>http://developer.apple.com/fonts/ttrefman/rm06/Chap6.html</li>
+ * <li>http://www.microsoft.com/typography/SpecificationsOverview.mspx</li>
+ * <li>http://www.microsoft.com/typography/otspec/</li>
+ * </ul>
+ * </p>
+ * <p>
* TrueType Font Table Introduction:
- * http://scripts.sil.org/cms/scripts/page.php?item_id=IWS-Chapter08
+ * <ul>
+ * <li>http://scripts.sil.org/cms/scripts/page.php?item_id=IWS-Chapter08</li>
+ * </ul>
+ * </p>
+ * <p>
+ * Misc.:
+ * <ul>
+ * <li>Treatis on Font <code>Rasterization https://freddie.witherden.org/pages/font-rasterisation/</code></li>
+ * <li>Glyph Hell <code>http://walon.org/pub/ttf/ttf_glyphs.htm</code></li>
+ * </ul>
+ * </p>
*/
public interface Font {
@@ -67,11 +84,20 @@ public interface Font {
float getLineGap(float pixelSize);
float getMaxExtend(float pixelSize);
float getScale(float pixelSize);
- AABBox getBBox(float pixelSize);
+ /**
+ * @param pixelSize
+ * @param tmpV3 caller provided temporary 3-component vector
+ * @return
+ */
+ AABBox getBBox(float pixelSize, float[] tmpV3);
}
/**
* Glyph for font
+ *
+ * http://developer.apple.com/textfonts/TTRefMan/RM06/Chap6cmap.html
+ * http://developer.apple.com/textfonts/TTRefMan/RM06/Chap6glyf.html
+ * http://www.microsoft.com/typography/otspec/glyf.htm
*/
public interface Glyph {
// reserved special glyph IDs
@@ -82,8 +108,18 @@ public interface Font {
public Font getFont();
public char getSymbol();
- public AABBox getBBox(float pixelSize);
+ public short getID();
+ public AABBox getBBox();
+ public float getScale(float pixelSize);
+ /**
+ * @param pixelSize
+ * @param tmpV3 caller provided temporary 3-component vector
+ * @return
+ */
+ public AABBox getBBox(float pixelSize, float[] tmpV3);
public float getAdvance(float pixelSize, boolean useFrationalMetrics);
+ public OutlineShape getShape();
+ public int hashCode();
}
@@ -97,11 +133,28 @@ public interface Font {
public StringBuilder getAllNames(StringBuilder string, String separator);
- public float getAdvanceWidth(int i, float pixelSize);
+ /**
+ * <pre>
+ Font Scale Formula:
+ inch: 25.4 mm
+ pointSize: [point] = [1/72 inch]
+
+ [1] Scale := pointSize * resolution / ( 72 points per inch * units_per_em )
+ [2] PixelSize := pointSize * resolution / ( 72 points per inch )
+ [3] Scale := PixelSize / units_per_em
+ * </pre>
+ * @param fontSize in point-per-inch
+ * @param resolution display resolution in dots-per-inch
+ * @return pixel-per-inch, pixelSize scale factor for font operations.
+ */
+ public float getPixelSize(float fontSize /* points per inch */, float resolution);
+
+ public float getAdvanceWidth(int glyphID, float pixelSize);
public Metrics getMetrics();
public Glyph getGlyph(char symbol);
public int getNumGlyphs();
+ public float getLineHeight(float pixelSize);
public float getStringWidth(CharSequence string, float pixelSize);
public float getStringHeight(CharSequence string, float pixelSize);
public AABBox getStringBounds(CharSequence string, float pixelSize);
@@ -111,4 +164,4 @@ public interface Font {
/** Shall return {@link #getFullFamilyName()} */
@Override
public String toString();
-} \ No newline at end of file
+}
diff --git a/src/jogl/classes/com/jogamp/graph/font/FontFactory.java b/src/jogl/classes/com/jogamp/graph/font/FontFactory.java
index 884662e6e..948600a4a 100644
--- a/src/jogl/classes/com/jogamp/graph/font/FontFactory.java
+++ b/src/jogl/classes/com/jogamp/graph/font/FontFactory.java
@@ -29,10 +29,13 @@ package com.jogamp.graph.font;
import java.io.File;
import java.io.IOException;
+import java.net.URI;
import java.net.URLConnection;
+import com.jogamp.common.util.IOUtil;
import com.jogamp.common.util.PropertyAccess;
import com.jogamp.common.util.ReflectionUtil;
+import com.jogamp.common.util.cache.TempJarCache;
import jogamp.graph.font.FontConstructor;
import jogamp.graph.font.JavaFontLoader;
@@ -50,10 +53,10 @@ public class FontFactory {
private static final String FontConstructorPropKey = "jogamp.graph.font.ctor";
private static final String DefaultFontConstructor = "jogamp.graph.font.typecast.TypecastFontConstructor";
- /** Ubuntu is the default font family */
+ /** Ubuntu is the default font family, {@value} */
public static final int UBUNTU = 0;
- /** Java fonts are optional */
+ /** Java fonts are optional, {@value} */
public static final int JAVA = 1;
private static final FontConstructor fontConstr;
@@ -92,6 +95,24 @@ public class FontFactory {
return fontConstr.create(conn);
}
+ public static final Font get(final Class<?> context, final String fname, final boolean useTempJarCache) throws IOException {
+ URLConnection conn = null;
+ if( useTempJarCache ) {
+ try {
+ final URI uri = TempJarCache.getResource(fname);
+ conn = null != uri ? uri.toURL().openConnection() : null;
+ } catch (Exception e) {
+ throw new IOException(e);
+ }
+ } else {
+ conn = IOUtil.getResource(context, fname);
+ }
+ if(null != conn) {
+ return FontFactory.get ( conn ) ;
+ }
+ return null;
+ }
+
public static boolean isPrintableChar( char c ) {
if( Character.isWhitespace(c) ) {
return true;
diff --git a/src/jogl/classes/com/jogamp/graph/font/FontSet.java b/src/jogl/classes/com/jogamp/graph/font/FontSet.java
index 17b8b2136..60a16b241 100644
--- a/src/jogl/classes/com/jogamp/graph/font/FontSet.java
+++ b/src/jogl/classes/com/jogamp/graph/font/FontSet.java
@@ -32,30 +32,38 @@ import java.io.IOException;
public interface FontSet {
- /** Font family REGULAR **/
+ /** Font family REGULAR, {@value} **/
public static final int FAMILY_REGULAR = 0;
- /** Font family LIGHT **/
+ /** Font family LIGHT, {@value} **/
public static final int FAMILY_LIGHT = 1;
- /** Font family MEDIUM **/
+ /** Font family MEDIUM, {@value} **/
public static final int FAMILY_MEDIUM = 2;
- /** Font family CONDENSED **/
+ /** Font family CONDENSED, {@value} **/
public static final int FAMILY_CONDENSED = 3;
- /** Font family MONO **/
+ /** Font family MONO, {@value} **/
public static final int FAMILY_MONOSPACED = 4;
- /** SERIF style/family bit flag. Fallback to Sans Serif. */
+ /** Zero style, {@value} */
+ public static final int STYLE_NONE = 0;
+
+ /** SERIF style/family bit flag. Fallback to Sans Serif, {@value} */
public static final int STYLE_SERIF = 1 << 1;
- /** BOLD style bit flag */
+ /** BOLD style bit flag, {@value} */
public static final int STYLE_BOLD = 1 << 2;
- /** ITALIC style bit flag */
+ /** ITALIC style bit flag, {@value} */
public static final int STYLE_ITALIC = 1 << 3;
+ /**
+ * Returns the family {@link #FAMILY_REGULAR} with {@link #STYLE_NONE}
+ * as retrieved with {@link #get(int, int)}.
+ * @throws IOException
+ */
Font getDefault() throws IOException ;
Font get(int family, int stylebits) throws IOException ;
diff --git a/src/jogl/classes/com/jogamp/graph/geom/Outline.java b/src/jogl/classes/com/jogamp/graph/geom/Outline.java
index 77a318078..2d9d74966 100644
--- a/src/jogl/classes/com/jogamp/graph/geom/Outline.java
+++ b/src/jogl/classes/com/jogamp/graph/geom/Outline.java
@@ -62,7 +62,8 @@ public class Outline implements Cloneable, Comparable<Outline> {
return vertices.size();
}
- /** Appends a vertex to the outline loop/strip.
+ /**
+ * Appends a vertex to the outline loop/strip.
* @param vertex Vertex to be added
* @throws NullPointerException if the {@link Vertex} element is null
*/
@@ -70,7 +71,8 @@ public class Outline implements Cloneable, Comparable<Outline> {
addVertex(vertices.size(), vertex);
}
- /** Insert the {@link Vertex} element at the given {@code position} to the outline loop/strip.
+ /**
+ * Insert the {@link Vertex} element at the given {@code position} to the outline loop/strip.
* @param position of the added Vertex
* @param vertex Vertex object to be added
* @throws NullPointerException if the {@link Vertex} element is null
@@ -151,22 +153,32 @@ public class Outline implements Cloneable, Comparable<Outline> {
return closed;
}
- /** define if this outline is closed or not.
- * if set to closed, checks if the last vertex is
- * equal to the first vertex. If not Equal adds a
- * vertex at the end to the list.
- * @param closed
+ /**
+ * Ensure this outline is closed.
+ * <p>
+ * Checks whether the last vertex equals to the first.
+ * If not equal, it either appends a clone of the first vertex
+ * or prepends a clone of the last vertex, depending on <code>closeTail</code>.
+ * </p>
+ * @param closeTail if true, a clone of the first vertex will be appended,
+ * otherwise a clone of the last vertex will be prepended.
+ * @return true if closing performed, otherwise false for NOP
*/
- public final void setClosed(boolean closed) {
- this.closed = closed;
- if( closed && !isEmpty() ) {
- Vertex first = vertices.get(0);
- Vertex last = getLastVertex();
- if(!VectorUtil.checkEquality(first.getCoord(), last.getCoord())){
- Vertex v = first.clone();
- vertices.add(v);
+ public final boolean setClosed(boolean closeTail) {
+ this.closed = true;
+ if( !isEmpty() ) {
+ final Vertex first = vertices.get(0);
+ final Vertex last = getLastVertex();
+ if( !VectorUtil.checkEquality( first.getCoord(), last.getCoord() ) ) {
+ if( closeTail ) {
+ vertices.add(first.clone());
+ } else {
+ vertices.add(0, last.clone());
+ }
+ 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..e353dd061 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;
+ }
- public Triangle(Vertex ... v123){
- vertices = v123;
+ 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);
+ } */
+ }
+
+ /**
+ * 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,7 @@ public class Triangle {
this.id = id;
}
+ /** Returns array of 3 vertices, denominating the triangle. */
public Vertex[] getVertices() {
return vertices;
}
@@ -57,10 +96,6 @@ public class Triangle {
return boundaryVertices[0] || boundaryVertices[1] || boundaryVertices[2];
}
- public void setEdgesBoundary(boolean[] boundary) {
- this.boundaryEdges = boundary;
- }
-
public boolean[] getEdgeBoundary() {
return boundaryEdges;
}
@@ -75,6 +110,6 @@ public class Triangle {
@Override
public String toString() {
- return "Tri ID: " + id + "\n" + vertices[0] + "\n" + vertices[1] + "\n" + vertices[2];
+ return "Tri ID: " + id + "\n\t" + vertices[0] + "\n\t" + vertices[1] + "\n\t" + vertices[2];
}
}
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);
diff --git a/src/jogl/classes/com/jogamp/opengl/FBObject.java b/src/jogl/classes/com/jogamp/opengl/FBObject.java
index 90a8dc073..33751eab9 100644
--- a/src/jogl/classes/com/jogamp/opengl/FBObject.java
+++ b/src/jogl/classes/com/jogamp/opengl/FBObject.java
@@ -2316,8 +2316,8 @@ public class FBObject {
return "FBO[name r/w "+fbName+"/"+getReadFramebuffer()+", init "+initialized+", bound "+bound+", size "+width+"x"+height+
", samples "+samples+"/"+maxSamples+", depth "+depth+", stencil "+stencil+
", color attachments: "+colorAttachmentCount+"/"+maxColorAttachments+
- ": "+caps+", msaa-sink "+samplingSinkTexture+", hasSamplesSink "+(null != samplingSink)+
- ", state "+getStatusString()+", obj "+toHexString(objectHashCode())+"]";
+ ": "+caps+", msaa["+samplingSinkTexture+", hasSink "+(null != samplingSink)+
+ ", dirty "+samplingSinkDirty+"], state "+getStatusString()+", obj "+toHexString(objectHashCode())+"]";
}
private final void updateStatus(GL gl) {
diff --git a/src/jogl/classes/com/jogamp/opengl/math/FloatUtil.java b/src/jogl/classes/com/jogamp/opengl/math/FloatUtil.java
index 191a83241..d2976357d 100644
--- a/src/jogl/classes/com/jogamp/opengl/math/FloatUtil.java
+++ b/src/jogl/classes/com/jogamp/opengl/math/FloatUtil.java
@@ -29,23 +29,39 @@ package com.jogamp.opengl.math;
import java.nio.FloatBuffer;
+import jogamp.opengl.Debug;
+
import com.jogamp.common.os.Platform;
/**
* Basic Float math utility functions.
* <p>
* Implementation assumes linear matrix layout in column-major order
- * matching OpenGL's implementation.
+ * matching OpenGL's implementation, translation matrix example:
+ * <pre>
+ Row-Major Order:
+ 1 0 0 x
+ 0 1 0 y
+ 0 0 1 z
+ 0 0 0 1
+ * </pre>
+ * <pre>
+ Column-Major Order:
+ 1 0 0 0
+ 0 1 0 0
+ 0 0 1 0
+ x y z 1
+ * </pre>
* </p>
* <p>
* Derived from ProjectFloat.java - Created 11-jan-2004
* </p>
*
- * @author Erik Duijs
- * @author Kenneth Russell
- * @author Sven Gothel
+ * @author Erik Duijs, Kenneth Russell, et al.
*/
public class FloatUtil {
+ public static final boolean DEBUG = Debug.debug("Math");
+
private static final float[] IDENTITY_MATRIX =
new float[] {
1.0f, 0.0f, 0.0f, 0.0f,
@@ -558,7 +574,7 @@ public class FloatUtil {
public static final float PI = 3.14159265358979323846f;
- public static float abs(float a) { return (float) java.lang.Math.abs(a); }
+ public static float abs(float a) { return java.lang.Math.abs(a); }
public static float pow(float a, float b) { return (float) java.lang.Math.pow(a, b); }
diff --git a/src/jogl/classes/com/jogamp/opengl/math/Quaternion.java b/src/jogl/classes/com/jogamp/opengl/math/Quaternion.java
index 52a59c599..3c3510b7f 100644
--- a/src/jogl/classes/com/jogamp/opengl/math/Quaternion.java
+++ b/src/jogl/classes/com/jogamp/opengl/math/Quaternion.java
@@ -56,7 +56,8 @@ public class Quaternion {
*/
public Quaternion(float[] vector1, float[] vector2) {
final float theta = FloatUtil.acos(VectorUtil.dot(vector1, vector2));
- final float[] cross = VectorUtil.cross(vector1, vector2);
+ final float[] cross = new float[3];
+ VectorUtil.cross(cross, vector1, vector2);
fromAxis(cross, theta);
}
@@ -79,7 +80,7 @@ public class Quaternion {
public void fromAxis(float[] vector, float angle) {
final float halfangle = angle * 0.5f;
final float sin = FloatUtil.sin(halfangle);
- final float[] nv = VectorUtil.normalize(vector);
+ final float[] nv = VectorUtil.normalize(vector, vector);
x = (nv[0] * sin);
y = (nv[1] * sin);
z = (nv[2] * sin);
@@ -220,7 +221,7 @@ public class Quaternion {
* Normalize a quaternion required if to be used as a rotational quaternion
*/
public void normalize() {
- final float norme = (float) FloatUtil.sqrt(w * w + x * x + y * y + z * z);
+ final float norme = FloatUtil.sqrt(w * w + x * x + y * y + z * z);
if (norme == 0.0f) {
setIdentity();
} else {
@@ -355,7 +356,7 @@ public class Quaternion {
public void setFromMatrix(float[] m) {
final float T = m[0] + m[4] + m[8] + 1;
if (T > 0) {
- final float S = 0.5f / (float) FloatUtil.sqrt(T);
+ final float S = 0.5f / FloatUtil.sqrt(T);
w = 0.25f / S;
x = (m[5] - m[7]) * S;
y = (m[6] - m[2]) * S;
diff --git a/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java b/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java
index e1e797088..734b7459b 100644
--- a/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java
+++ b/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java
@@ -52,41 +52,26 @@ public class VectorUtil {
{
return (vec1[0]*vec2[0] + vec1[1]*vec2[1] + vec1[2]*vec2[2]);
}
- /** Normalize a vector
+
+ /**
+ * Normalize a vector
* @param vector input vector
* @return normalized vector
*/
- public static float[] normalize(float[] vector)
+ public static float[] normalize(final float[] result, float[] vector)
{
- final float[] newVector = new float[3];
-
final float d = FloatUtil.sqrt(vector[0]*vector[0] + vector[1]*vector[1] + vector[2]*vector[2]);
if(d> 0.0f)
{
- newVector[0] = vector[0]/d;
- newVector[1] = vector[1]/d;
- newVector[2] = vector[2]/d;
+ result[0] = vector[0]/d;
+ result[1] = vector[1]/d;
+ result[2] = vector[2]/d;
}
- return newVector;
- }
-
- /** Scales a vector by param creating a new float[] for the result!
- * @param vector input vector
- * @param scale constant to scale by
- * @return new scaled vector
- * @deprecated Use {@link #scale(float[], float[], float)}
- */
- public static float[] scale(float[] vector, float scale)
- {
- final float[] newVector = new float[3];
-
- newVector[0] = vector[0] * scale;
- newVector[1] = vector[1] * scale;
- newVector[2] = vector[2] * scale;
- return newVector;
+ return result;
}
- /** Scales a vector by param using given result float[]
+ /**
+ * Scales a vector by param using given result float[]
* @param result vector for the result
* @param vector input vector
* @param scale single scale constant for all vector components
@@ -113,67 +98,61 @@ public class VectorUtil {
return result;
}
- /** Adds to vectors
+ /**
+ * Adds to vectors
* @param v1 vector 1
* @param v2 vector 2
* @return v1 + v2
*/
- public static float[] vectorAdd(float[] v1, float[] v2)
+ public static float[] vectorAdd(float[] result, float[] v1, float[] v2)
{
- final float[] newVector = new float[3];
-
- newVector[0] = v1[0] + v2[0];
- newVector[1] = v1[1] + v2[1];
- newVector[2] = v1[2] + v2[2];
- return newVector;
+ result[0] = v1[0] + v2[0];
+ result[1] = v1[1] + v2[1];
+ result[2] = v1[2] + v2[2];
+ return result;
}
- /** cross product vec1 x vec2
+ /**
+ * cross product vec1 x vec2
* @param vec1 vector 1
* @param vec2 vecttor 2
* @return the resulting vector
*/
- public static float[] cross(float[] vec1, float[] vec2)
+ public static float[] cross(final float[] result, float[] vec1, float[] vec2)
{
- final float[] out = new float[3];
-
- out[0] = vec2[2]*vec1[1] - vec2[1]*vec1[2];
- out[1] = vec2[0]*vec1[2] - vec2[2]*vec1[0];
- out[2] = vec2[1]*vec1[0] - vec2[0]*vec1[1];
+ result[0] = vec2[2]*vec1[1] - vec2[1]*vec1[2];
+ result[1] = vec2[0]*vec1[2] - vec2[2]*vec1[0];
+ result[2] = vec2[1]*vec1[0] - vec2[0]*vec1[1];
- return out;
+ return result;
}
/** Column Matrix Vector multiplication
* @param colMatrix column matrix (4x4)
* @param vec vector(x,y,z)
- * @return result new float[3]
+ * @return result
*/
- public static float[] colMatrixVectorMult(float[] colMatrix, float[] vec)
+ public static float[] colMatrixVectorMult(final float[] result, float[] colMatrix, float[] vec)
{
- final float[] out = new float[3];
-
- out[0] = vec[0]*colMatrix[0] + vec[1]*colMatrix[4] + vec[2]*colMatrix[8] + colMatrix[12];
- out[1] = vec[0]*colMatrix[1] + vec[1]*colMatrix[5] + vec[2]*colMatrix[9] + colMatrix[13];
- out[2] = vec[0]*colMatrix[2] + vec[1]*colMatrix[6] + vec[2]*colMatrix[10] + colMatrix[14];
+ result[0] = vec[0]*colMatrix[0] + vec[1]*colMatrix[4] + vec[2]*colMatrix[8] + colMatrix[12];
+ result[1] = vec[0]*colMatrix[1] + vec[1]*colMatrix[5] + vec[2]*colMatrix[9] + colMatrix[13];
+ result[2] = vec[0]*colMatrix[2] + vec[1]*colMatrix[6] + vec[2]*colMatrix[10] + colMatrix[14];
- return out;
+ return result;
}
/** Matrix Vector multiplication
* @param rawMatrix column matrix (4x4)
* @param vec vector(x,y,z)
- * @return result new float[3]
+ * @return result
*/
- public static float[] rowMatrixVectorMult(float[] rawMatrix, float[] vec)
+ public static float[] rowMatrixVectorMult(final float[] result, float[] rawMatrix, float[] vec)
{
- final float[] out = new float[3];
-
- out[0] = vec[0]*rawMatrix[0] + vec[1]*rawMatrix[1] + vec[2]*rawMatrix[2] + rawMatrix[3];
- out[1] = vec[0]*rawMatrix[4] + vec[1]*rawMatrix[5] + vec[2]*rawMatrix[6] + rawMatrix[7];
- out[2] = vec[0]*rawMatrix[8] + vec[1]*rawMatrix[9] + vec[2]*rawMatrix[10] + rawMatrix[11];
+ result[0] = vec[0]*rawMatrix[0] + vec[1]*rawMatrix[1] + vec[2]*rawMatrix[2] + rawMatrix[3];
+ result[1] = vec[0]*rawMatrix[4] + vec[1]*rawMatrix[5] + vec[2]*rawMatrix[6] + rawMatrix[7];
+ result[2] = vec[0]*rawMatrix[8] + vec[1]*rawMatrix[9] + vec[2]*rawMatrix[10] + rawMatrix[11];
- return out;
+ return result;
}
/** Calculate the midpoint of two values
@@ -186,19 +165,19 @@ public class VectorUtil {
return (p1+p2)/2.0f;
}
- /** Calculate the midpoint of two points
+ /**
+ * Calculate the midpoint of two points
* @param p1 first point
* @param p2 second point
* @return midpoint
*/
- public static float[] mid(float[] p1, float[] p2)
+ public static float[] mid(final float[] result, float[] p1, float[] p2)
{
- final float[] midPoint = new float[3];
- midPoint[0] = (p1[0] + p2[0])*0.5f;
- midPoint[1] = (p1[1] + p2[1])*0.5f;
- midPoint[2] = (p1[2] + p2[2])*0.5f;
+ result[0] = (p1[0] + p2[0])*0.5f;
+ result[1] = (p1[1] + p2[1])*0.5f;
+ result[2] = (p1[2] + p2[2])*0.5f;
- return midPoint;
+ return result;
}
/** Compute the norm of a vector
@@ -271,17 +250,14 @@ public class VectorUtil {
}
/** Compute Vector
+ * @param vector storage for resulting Vector V1V2
* @param v1 vertex 1
* @param v2 vertex2 2
- * @return Vector V1V2
*/
- public static float[] computeVector(float[] v1, float[] v2)
- {
- final float[] vector = new float[3];
+ public static void computeVector(float[] vector, float[] v1, float[] v2) {
vector[0] = v2[0] - v1[0];
vector[1] = v2[1] - v1[1];
vector[2] = v2[2] - v1[2];
- return vector;
}
/** Check if vertices in triangle circumcircle
@@ -292,11 +268,15 @@ public class VectorUtil {
* @return true if the vertex d is inside the circle defined by the
* vertices a, b, c. from paper by Guibas and Stolfi (1985).
*/
- public static boolean inCircle(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d){
- return (a.getX() * a.getX() + a.getY() * a.getY()) * triArea(b, c, d) -
- (b.getX() * b.getX() + b.getY() * b.getY()) * triArea(a, c, d) +
- (c.getX() * c.getX() + c.getY() * c.getY()) * triArea(a, b, d) -
- (d.getX() * d.getX() + d.getY() * d.getY()) * triArea(a, b, c) > 0;
+ public static boolean inCircle(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d) {
+ final float[] A = a.getCoord();
+ final float[] B = b.getCoord();
+ final float[] C = c.getCoord();
+ final float[] D = d.getCoord();
+ return (A[0] * A[0] + A[1] * A[1]) * triArea(B, C, D) -
+ (B[0] * B[0] + B[1] * B[1]) * triArea(A, C, D) +
+ (C[0] * C[0] + C[1] * C[1]) * triArea(A, B, D) -
+ (D[0] * D[0] + D[1] * D[1]) * triArea(A, B, C) > 0;
}
/** Computes oriented area of a triangle
@@ -306,8 +286,22 @@ public class VectorUtil {
* @return compute twice the area of the oriented triangle (a,b,c), the area
* is positive if the triangle is oriented counterclockwise.
*/
- public static float triArea(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c) {
- return (b.getX() - a.getX()) * (c.getY() - a.getY()) - (b.getY() - a.getY())*(c.getX() - a.getX());
+ public static float triArea(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c){
+ final float[] A = a.getCoord();
+ final float[] B = b.getCoord();
+ final float[] C = c.getCoord();
+ return (B[0] - A[0]) * (C[1] - A[1]) - (B[1] - A[1]) * (C[0] - A[0]);
+ }
+
+ /** Computes oriented area of a triangle
+ * @param A first vertex
+ * @param B second vertex
+ * @param C third vertex
+ * @return compute twice the area of the oriented triangle (a,b,c), the area
+ * is positive if the triangle is oriented counterclockwise.
+ */
+ public static float triArea(float[] A, float[] B, float[] C){
+ return (B[0] - A[0]) * (C[1] - A[1]) - (B[1] - A[1])*(C[0] - A[0]);
}
/** Check if a vertex is in triangle using
@@ -318,11 +312,13 @@ public class VectorUtil {
* @param p the vertex in question
* @return true if p is in triangle (a, b, c), false otherwise.
*/
- public static boolean vertexInTriangle(float[] a, float[] b, float[] c, float[] p){
+ public static boolean vertexInTriangle(float[] a, float[] b, float[] c,
+ float[] p,
+ float[] ac, float[] ab, float[] ap){
// Compute vectors
- final float[] ac = computeVector(a, c); //v0
- final float[] ab = computeVector(a, b); //v1
- final float[] ap = computeVector(a, p); //v2
+ computeVector(ac, a, c); //v0
+ computeVector(ab, a, b); //v1
+ computeVector(ap, a, p); //v2
// Compute dot products
final float dot00 = dot(ac, ac);
@@ -340,6 +336,76 @@ public class VectorUtil {
return (u >= 0) && (v >= 0) && (u + v < 1);
}
+ /**
+ * Check if one of three vertices are in triangle using
+ * barycentric coordinates computation.
+ * @param a first triangle vertex
+ * @param b second triangle vertex
+ * @param c third triangle vertex
+ * @param p1 the vertex in question
+ * @param p2 the vertex in question
+ * @param p3 the vertex in question
+ * @param tmpAC
+ * @param tmpAB
+ * @param tmpAP
+ * @return true if p1 or p2 or p3 is in triangle (a, b, c), false otherwise.
+ */
+ public static boolean vertexInTriangle3(float[] a, float[] b, float[] c,
+ float[] p1, float[] p2, float[] p3,
+ float[] tmpAC, float[] tmpAB, float[] tmpAP){
+ // Compute vectors
+ computeVector(tmpAC, a, c); //v0
+ computeVector(tmpAB, a, b); //v1
+
+ // Compute dot products
+ final float dotAC_AC = dot(tmpAC, tmpAC);
+ final float dotAC_AB = dot(tmpAC, tmpAB);
+ final float dotAB_AB = dot(tmpAB, tmpAB);
+
+ // Compute barycentric coordinates
+ final float invDenom = 1 / (dotAC_AC * dotAB_AB - dotAC_AB * dotAC_AB);
+ {
+ computeVector(tmpAP, a, p1); //v2
+ final float dotAC_AP1 = dot(tmpAC, tmpAP);
+ final float dotAB_AP1 = dot(tmpAB, tmpAP);
+ final float u1 = (dotAB_AB * dotAC_AP1 - dotAC_AB * dotAB_AP1) * invDenom;
+ final float v1 = (dotAC_AC * dotAB_AP1 - dotAC_AB * dotAC_AP1) * invDenom;
+
+ // Check if point is in triangle
+ if ( (u1 >= 0) && (v1 >= 0) && (u1 + v1 < 1) ) {
+ return true;
+ }
+ }
+
+ {
+ computeVector(tmpAP, a, p2); //v2
+ final float dotAC_AP2 = dot(tmpAC, tmpAP);
+ final float dotAB_AP2 = dot(tmpAB, tmpAP);
+ final float u = (dotAB_AB * dotAC_AP2 - dotAC_AB * dotAB_AP2) * invDenom;
+ final float v = (dotAC_AC * dotAB_AP2 - dotAC_AB * dotAC_AP2) * invDenom;
+
+ // Check if point is in triangle
+ if ( (u >= 0) && (v >= 0) && (u + v < 1) ) {
+ return true;
+ }
+ }
+
+ {
+ computeVector(tmpAP, a, p3); //v2
+ final float dotAC_AP3 = dot(tmpAC, tmpAP);
+ final float dotAB_AP3 = dot(tmpAB, tmpAP);
+ final float u = (dotAB_AB * dotAC_AP3 - dotAC_AB * dotAB_AP3) * invDenom;
+ final float v = (dotAC_AC * dotAB_AP3 - dotAC_AB * dotAC_AP3) * invDenom;
+
+ // Check if point is in triangle
+ if ( (u >= 0) && (v >= 0) && (u + v < 1) ) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
/** Check if points are in ccw order
* @param a first vertex
* @param b second vertex
@@ -390,10 +456,9 @@ public class VectorUtil {
* @param b vertex 2 of first segment
* @param c vertex 1 of second segment
* @param d vertex 2 of second segment
- * @return the intersection coordinates if the segments intersect, otherwise
- * returns null
+ * @return the intersection coordinates if the segments intersect, otherwise returns null
*/
- public static float[] seg2SegIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d) {
+ public static float[] seg2SegIntersection(final float[] result, Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d) {
final float determinant = (a.getX()-b.getX())*(c.getY()-d.getY()) - (a.getY()-b.getY())*(c.getX()-d.getX());
if (determinant == 0)
@@ -409,7 +474,42 @@ public class VectorUtil {
if(gamma <= 0 || gamma >= 1) return null;
if(gamma1 <= 0 || gamma1 >= 1) return null;
- return new float[]{xi,yi,0};
+ result[0] = xi;
+ result[1] = yi;
+ result[2] = 0;
+ return result;
+ }
+
+ /** Compute intersection between two segments
+ * @param a vertex 1 of first segment
+ * @param b vertex 2 of first segment
+ * @param c vertex 1 of second segment
+ * @param d vertex 2 of second segment
+ * @return true if the segments intersect, otherwise returns false
+ */
+ public static boolean testSeg2SegIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d) {
+ final float[] A = a.getCoord();
+ final float[] B = b.getCoord();
+ final float[] C = c.getCoord();
+ final float[] D = d.getCoord();
+
+ final float determinant = (A[0]-B[0])*(C[1]-D[1]) - (A[1]-B[1])*(C[0]-D[0]);
+
+ if (determinant == 0) {
+ return false;
+ }
+
+ final float alpha = (A[0]*B[1]-A[1]*B[0]);
+ final float beta = (C[0]*D[1]-C[1]*D[1]);
+ final float xi = ((C[0]-D[0])*alpha-(A[0]-B[0])*beta)/determinant;
+
+ final float gamma = (xi - A[0])/(B[0] - A[0]);
+ final float gamma1 = (xi - C[0])/(D[0] - C[0]);
+ if(gamma <= 0 || gamma >= 1 || gamma1 <= 0 || gamma1 >= 1) {
+ return false;
+ }
+
+ return true;
}
/** Compute intersection between two lines
@@ -420,7 +520,7 @@ public class VectorUtil {
* @return the intersection coordinates if the lines intersect, otherwise
* returns null
*/
- public static float[] line2lineIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d) {
+ public static float[] line2lineIntersection(final float[] result, Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d) {
final float determinant = (a.getX()-b.getX())*(c.getY()-d.getY()) - (a.getY()-b.getY())*(c.getX()-d.getX());
if (determinant == 0)
@@ -431,7 +531,10 @@ public class VectorUtil {
final float xi = ((c.getX()-d.getX())*alpha-(a.getX()-b.getX())*beta)/determinant;
final float yi = ((c.getY()-d.getY())*alpha-(a.getY()-b.getY())*beta)/determinant;
- return new float[]{xi,yi,0};
+ result[0] = xi;
+ result[1] = yi;
+ result[2] = 0;
+ return result;
}
/** Check if a segment intersects with a triangle
@@ -442,14 +545,9 @@ public class VectorUtil {
* @param e vertex 2 of first segment
* @return true if the segment intersects at least one segment of the triangle, false otherwise
*/
- public static boolean tri2SegIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d, Vert2fImmutable e){
- if(seg2SegIntersection(a, b, d, e) != null)
- return true;
- if(seg2SegIntersection(b, c, d, e) != null)
- return true;
- if(seg2SegIntersection(a, c, d, e) != null)
- return true;
-
- return false;
+ public static boolean testTri2SegIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d, Vert2fImmutable e){
+ return testSeg2SegIntersection(a, b, d, e) ||
+ testSeg2SegIntersection(b, c, d, e) ||
+ testSeg2SegIntersection(a, c, d, e) ;
}
}
diff --git a/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java b/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java
index d48677da5..c28b36f82 100644
--- a/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java
+++ b/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java
@@ -27,7 +27,9 @@
*/
package com.jogamp.opengl.math.geom;
+import com.jogamp.opengl.math.FloatUtil;
import com.jogamp.opengl.math.VectorUtil;
+import com.jogamp.opengl.util.PMVMatrix;
/**
@@ -37,9 +39,10 @@ import com.jogamp.opengl.math.VectorUtil;
*
*/
public class AABBox implements Cloneable {
- private float[] low = new float[3];
- private float[] high = new float[3];
- private float[] center = new float[3];
+ private static final boolean DEBUG = FloatUtil.DEBUG;
+ private final float[] low = new float[3];
+ private final float[] high = new float[3];
+ private final float[] center = new float[3];
/** Create a Axis Aligned bounding box (AABBox)
* where the low and and high MAX float Values.
@@ -167,20 +170,26 @@ public class AABBox implements Cloneable {
*/
public final void resize(float x, float y, float z) {
/** test low */
- if (x < low[0])
+ if (x < low[0]) {
low[0] = x;
- if (y < low[1])
+ }
+ if (y < low[1]) {
low[1] = y;
- if (z < low[2])
+ }
+ if (z < low[2]) {
low[2] = z;
+ }
/** test high */
- if (x > high[0])
+ if (x > high[0]) {
high[0] = x;
- if (y > high[1])
+ }
+ if (y > high[1]) {
high[1] = y;
- if (z > high[2])
+ }
+ if (z > high[2]) {
high[2] = z;
+ }
computeCenter();
}
@@ -275,26 +284,25 @@ public class AABBox implements Cloneable {
return center;
}
- /** Scale the AABBox by a constant
+ /**
+ * Scale the AABBox by a constant
* @param size a constant float value
+ * @param tmpV3 caller provided temporary 3-component vector
*/
- public final void scale(float size) {
- float[] diffH = new float[3];
- diffH[0] = high[0] - center[0];
- diffH[1] = high[1] - center[1];
- diffH[2] = high[2] - center[2];
+ public final void scale(float size, float[] tmpV3) {
+ tmpV3[0] = high[0] - center[0];
+ tmpV3[1] = high[1] - center[1];
+ tmpV3[2] = high[2] - center[2];
- diffH = VectorUtil.scale(diffH, size);
+ VectorUtil.scale(tmpV3, tmpV3, size); // in-place scale
+ VectorUtil.vectorAdd(high, center, tmpV3);
- float[] diffL = new float[3];
- diffL[0] = low[0] - center[0];
- diffL[1] = low[1] - center[1];
- diffL[2] = low[2] - center[2];
+ tmpV3[0] = low[0] - center[0];
+ tmpV3[1] = low[1] - center[1];
+ tmpV3[2] = low[2] - center[2];
- diffL = VectorUtil.scale(diffL, size);
-
- high = VectorUtil.vectorAdd(center, diffH);
- low = VectorUtil.vectorAdd(center, diffL);
+ VectorUtil.scale(tmpV3, tmpV3, size); // in-place scale
+ VectorUtil.vectorAdd(low, center, tmpV3);
}
public final float getMinX() {
@@ -351,9 +359,66 @@ public class AABBox implements Cloneable {
VectorUtil.checkEquality(high, other.high) ;
}
+ /**
+ * Assume this bounding box as being in object space and
+ * compute the window bounding box.
+ * <p>
+ * If <code>useCenterZ</code> is <code>true</code>,
+ * only 4 {@link PMVMatrix#gluProject(float, float, float, int[], int, float[], int) gluProject}
+ * operations are made on points [1..4] using {@link #getCenter()}'s z-value.
+ * Otherwise 8 {@link PMVMatrix#gluProject(float, float, float, int[], int, float[], int) gluProject}
+ * operation on all 8 points are performed.
+ * </p>
+ * <pre>
+ * [2] ------ [4]
+ * | |
+ * | |
+ * [1] ------ [3]
+ * </pre>
+ * @param pmv
+ * @param view
+ * @param useCenterZ
+ * @param tmpV3 TODO
+ * @return
+ */
+ public AABBox mapToWindow(final AABBox result, final PMVMatrix pmv, final int[] view, final boolean useCenterZ, float[] tmpV3) {
+ // System.err.printf("AABBox.mapToWindow.0: view[%d, %d, %d, %d], this %s%n", view[0], view[1], view[2], view[3], toString());
+ float objZ = useCenterZ ? center[2] : getMinZ();
+ pmv.gluProject(getMinX(), getMinY(), objZ, view, 0, tmpV3, 0);
+ // System.err.printf("AABBox.mapToWindow.p1: %f, %f, %f -> %f, %f, %f%n", getMinX(), getMinY(), objZ, tmpV3[0], tmpV3[1], tmpV3[2]);
+ // System.err.printf("AABBox.mapToWindow.p1: %s%n", pmv.toString());
+ result.reset();
+ result.resize(tmpV3, 0);
+ pmv.gluProject(getMinX(), getMaxY(), objZ, view, 0, tmpV3, 0);
+ // System.err.printf("AABBox.mapToWindow.p2: %f, %f, %f -> %f, %f, %f%n", getMinX(), getMaxY(), objZ, tmpV3[0], tmpV3[1], tmpV3[2]);
+ result.resize(tmpV3, 0);
+ pmv.gluProject(getMaxX(), getMinY(), objZ, view, 0, tmpV3, 0);
+ // System.err.printf("AABBox.mapToWindow.p3: %f, %f, %f -> %f, %f, %f%n", getMaxX(), getMinY(), objZ, tmpV3[0], tmpV3[1], tmpV3[2]);
+ result.resize(tmpV3, 0);
+ pmv.gluProject(getMaxX(), getMaxY(), objZ, view, 0, tmpV3, 0);
+ // System.err.printf("AABBox.mapToWindow.p4: %f, %f, %f -> %f, %f, %f%n", getMaxX(), getMaxY(), objZ, tmpV3[0], tmpV3[1], tmpV3[2]);
+ result.resize(tmpV3, 0);
+ if( !useCenterZ ) {
+ objZ = getMaxZ();
+ pmv.gluProject(getMinX(), getMinY(), objZ, view, 0, tmpV3, 0);
+ result.resize(tmpV3, 0);
+ pmv.gluProject(getMinX(), getMaxY(), objZ, view, 0, tmpV3, 0);
+ result.resize(tmpV3, 0);
+ pmv.gluProject(getMaxX(), getMinY(), objZ, view, 0, tmpV3, 0);
+ result.resize(tmpV3, 0);
+ pmv.gluProject(getMaxX(), getMaxY(), objZ, view, 0, tmpV3, 0);
+ result.resize(tmpV3, 0);
+ }
+ if( DEBUG ) {
+ System.err.printf("AABBox.mapToWindow: view[%d, %d], this %s -> %s%n", view[0], view[1], toString(), result.toString());
+ }
+ return result;
+ }
+
@Override
public final String toString() {
- return "[ "+low[0]+"/"+low[1]+"/"+low[1]+" .. "+high[0]+"/"+high[0]+"/"+high[0]+", ctr "+
- center[0]+"/"+center[1]+"/"+center[1]+" ]";
+ return "[ dim "+getWidth()+" x "+getHeight()+" x "+getDepth()+
+ ", box "+low[0]+" / "+low[1]+" / "+low[2]+" .. "+high[0]+" / "+high[1]+" / "+high[2]+
+ ", ctr "+center[0]+" / "+center[1]+" / "+center[2]+" ]";
}
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java b/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java
index 218897ffe..270bf34f6 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java
@@ -65,6 +65,7 @@ import com.jogamp.opengl.math.geom.Frustum;
* <p>
* All matrices are provided in column-major order,
* as specified in the OpenGL fixed function pipeline, i.e. compatibility profile.
+ * See {@link FloatUtil}.
* </p>
* <p>
* PMVMatrix can supplement {@link GL2ES2} applications w/ the
@@ -486,7 +487,7 @@ public class PMVMatrix implements GLMatrixFunc {
public final void glGetFloatv(int matrixGetName, FloatBuffer params) {
int pos = params.position();
if(matrixGetName==GL_MATRIX_MODE) {
- params.put((float)matrixMode);
+ params.put(matrixMode);
} else {
final FloatBuffer matrix = glGetMatrixf(matrixGetName);
params.put(matrix); // matrix -> params
@@ -498,7 +499,7 @@ public class PMVMatrix implements GLMatrixFunc {
@Override
public final void glGetFloatv(int matrixGetName, float[] params, int params_offset) {
if(matrixGetName==GL_MATRIX_MODE) {
- params[params_offset]=(float)matrixMode;
+ params[params_offset]=matrixMode;
} else {
final FloatBuffer matrix = glGetMatrixf(matrixGetName);
matrix.get(params, params_offset, 16); // matrix -> params
diff --git a/src/jogl/classes/com/jogamp/opengl/util/av/AudioSink.java b/src/jogl/classes/com/jogamp/opengl/util/av/AudioSink.java
index b964245ad..f4ea29084 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/av/AudioSink.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/av/AudioSink.java
@@ -133,7 +133,7 @@ public interface AudioSink {
* @param sampleCount sample count per frame and channel
*/
public final float getSamplesDuration(int sampleCount) {
- return ( 1000f * (float) sampleCount ) / (float)sampleRate;
+ return ( 1000f * sampleCount ) / sampleRate;
}
/**
@@ -152,7 +152,7 @@ public interface AudioSink {
* @param frameDuration duration per frame in milliseconds.
*/
public final int getFrameCount(int millisecs, float frameDuration) {
- return Math.max(1, (int) ( (float)millisecs / frameDuration + 0.5f ));
+ return Math.max(1, (int) ( millisecs / frameDuration + 0.5f ));
}
/**
@@ -187,7 +187,7 @@ public interface AudioSink {
* <p>
* Byte Count -> Sample Count
* </p>
- * @param sampleCount sample count
+ * @param byteCount number of bytes
*/
public final int getBytesSampleCount(int byteCount) {
return ( byteCount << 3 ) / sampleSize;
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/RegionFactory.java b/src/jogl/classes/jogamp/graph/curve/opengl/RegionFactory.java
deleted file mode 100644
index 515583b14..000000000
--- a/src/jogl/classes/jogamp/graph/curve/opengl/RegionFactory.java
+++ /dev/null
@@ -1,74 +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 com.jogamp.graph.curve.Region;
-import com.jogamp.graph.curve.opengl.GLRegion;
-
-/** RegionFactory to create a Context specific Region implementation.
- *
- * @see GLRegion
- */
-public class RegionFactory {
-
- /**
- * Create a Region using the passed render mode
- *
- * <p> In case {@link Region#VBAA_RENDERING_BIT} is being requested the default texture unit
- * {@link Region#TWO_PASS_DEFAULT_TEXTURE_UNIT} is being used.</p>
- *
- * @param rs the RenderState to be used
- * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#VBAA_RENDERING_BIT}
- */
- public static GLRegion create(int renderModes) {
- if( 0 != ( Region.VBAA_RENDERING_BIT & renderModes ) ){
- return new VBORegion2PES2(renderModes, Region.TWO_PASS_DEFAULT_TEXTURE_UNIT);
- }
- else{
- return new VBORegionSPES2(renderModes);
- }
- }
-
- /** Create a Single Pass Region using the passed render mode
- * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT},
- * {@link Region#VBAA_RENDERING_BIT}
- * @return
- */
- public static GLRegion createSinglePass(int renderModes) {
- return new VBORegionSPES2(renderModes);
- }
-
- /** Create a Two Pass (VBAA) Region using the passed render mode
- * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT},
- * {@link Region#VBAA_RENDERING_BIT}
- * @return
- */
- public static GLRegion createTwoPass(int renderModes, int textureUnit) {
- return new VBORegion2PES2(renderModes, textureUnit);
- }
-}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java b/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java
index 31ad974d0..e50caa663 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java
@@ -32,23 +32,21 @@ import javax.media.opengl.GLException;
import jogamp.graph.curve.opengl.shader.AttributeNames;
-import com.jogamp.graph.curve.Region;
-import com.jogamp.graph.curve.opengl.GLRegion;
-import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.curve.opengl.RenderState;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
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 RegionRendererImpl01 extends RegionRenderer {
- public RegionRendererImpl01(RenderState rs, int renderModes) {
- super(rs, renderModes);
+ public RegionRendererImpl01(final RenderState rs, final int renderModes, final GLCallback enableCallback, final GLCallback disableCallback) {
+ super(rs, renderModes, enableCallback, disableCallback);
}
@Override
- protected boolean initShaderProgram(GL2ES2 gl) {
+ protected final boolean initImpl(GL2ES2 gl) {
final ShaderState st = rs.getShaderState();
final ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, RegionRendererImpl01.class, "shader",
@@ -89,12 +87,7 @@ public class RegionRendererImpl01 extends RegionRenderer {
}
@Override
- protected void destroyImpl(GL2ES2 gl) {
- super.destroyImpl(gl);
- }
-
- @Override
- protected void drawImpl(GL2ES2 gl, Region region, float[] position, int[] texSize) {
- ((GLRegion)region).draw(gl, rs, vp_width, vp_height, texSize);
+ protected final void destroyImpl(GL2ES2 gl) {
+ // NOP .. all will be destroyed via RenderState
}
}
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 4ec4d1d98..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, float[] position, 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/VBORegion2PES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java
deleted file mode 100644
index 77c862ed4..000000000
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java
+++ /dev/null
@@ -1,343 +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 java.nio.FloatBuffer;
-
-import javax.media.opengl.GL2ES2;
-// FIXME: Subsume GL2GL3.GL_DRAW_FRAMEBUFFER -> GL2ES2.GL_DRAW_FRAMEBUFFER !
-import javax.media.opengl.GL;
-import javax.media.opengl.GLUniformData;
-import javax.media.opengl.fixedfunc.GLMatrixFunc;
-
-import jogamp.graph.curve.opengl.shader.AttributeNames;
-import jogamp.graph.curve.opengl.shader.UniformNames;
-
-import com.jogamp.common.nio.Buffers;
-import com.jogamp.graph.geom.Triangle;
-import com.jogamp.graph.geom.Vertex;
-
-import com.jogamp.graph.curve.opengl.GLRegion;
-import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.opengl.FBObject;
-import com.jogamp.opengl.FBObject.Attachment;
-import com.jogamp.opengl.FBObject.TextureAttachment;
-import com.jogamp.opengl.util.GLArrayDataServer;
-import com.jogamp.opengl.util.PMVMatrix;
-import com.jogamp.opengl.util.glsl.ShaderState;
-
-public class VBORegion2PES2 extends GLRegion {
- private GLArrayDataServer verticeTxtAttr;
- private GLArrayDataServer texCoordTxtAttr;
- private GLArrayDataServer indicesTxt;
- private GLArrayDataServer verticeFboAttr;
- private GLArrayDataServer texCoordFboAttr;
- private GLArrayDataServer indicesFbo;
-
-
- private FBObject fbo;
- private TextureAttachment texA;
- private PMVMatrix fboPMVMatrix;
- GLUniformData mgl_fboPMVMatrix;
-
- private int tex_width_c = 0;
- private int tex_height_c = 0;
- GLUniformData mgl_ActiveTexture;
- GLUniformData mgl_TextureSize; // if GLSL < 1.30
-
- public VBORegion2PES2(int renderModes, int textureEngine) {
- super(renderModes);
- fboPMVMatrix = new PMVMatrix();
- mgl_fboPMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, fboPMVMatrix.glGetPMvMatrixf());
- mgl_ActiveTexture = new GLUniformData(UniformNames.gcu_TextureUnit, textureEngine);
- }
-
- @Override
- public void update(GL2ES2 gl, RenderState rs) {
- if(!isDirty()) {
- return;
- }
-
- if(null == indicesFbo) {
- final int initialElementCount = 256;
- final ShaderState st = rs.getShaderState();
-
- indicesFbo = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
- indicesFbo.puts((short) 0); indicesFbo.puts((short) 1); indicesFbo.puts((short) 3);
- indicesFbo.puts((short) 1); indicesFbo.puts((short) 2); indicesFbo.puts((short) 3);
- indicesFbo.seal(true);
-
- texCoordFboAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT,
- false, initialElementCount, GL.GL_STATIC_DRAW);
- st.ownAttribute(texCoordFboAttr, true);
- texCoordFboAttr.putf(5); texCoordFboAttr.putf(5);
- texCoordFboAttr.putf(5); texCoordFboAttr.putf(6);
- texCoordFboAttr.putf(6); texCoordFboAttr.putf(6);
- texCoordFboAttr.putf(6); texCoordFboAttr.putf(5);
- texCoordFboAttr.seal(true);
-
- verticeFboAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT,
- false, initialElementCount, GL.GL_STATIC_DRAW);
- st.ownAttribute(verticeFboAttr, true);
-
-
- indicesTxt = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
-
- verticeTxtAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT,
- false, initialElementCount, GL.GL_STATIC_DRAW);
- st.ownAttribute(verticeTxtAttr, true);
-
- texCoordTxtAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT,
- false, initialElementCount, GL.GL_STATIC_DRAW);
- st.ownAttribute(texCoordTxtAttr, true);
-
- if(DEBUG_INSTANCE) {
- System.err.println("VBORegion2PES2 Create: " + this);
- }
- }
- // process triangles
- indicesTxt.seal(gl, false);
- indicesTxt.rewind();
- for(int i=0; i<triangles.size(); i++) {
- final Triangle t = triangles.get(i);
- final Vertex[] t_vertices = t.getVertices();
-
- if(t_vertices[0].getId() == Integer.MAX_VALUE){
- t_vertices[0].setId(numVertices++);
- t_vertices[1].setId(numVertices++);
- t_vertices[2].setId(numVertices++);
-
- vertices.add(t_vertices[0]);
- vertices.add(t_vertices[1]);
- vertices.add(t_vertices[2]);
-
- indicesTxt.puts((short) t_vertices[0].getId());
- indicesTxt.puts((short) t_vertices[1].getId());
- indicesTxt.puts((short) t_vertices[2].getId());
- } else {
- indicesTxt.puts((short) t_vertices[0].getId());
- indicesTxt.puts((short) t_vertices[1].getId());
- indicesTxt.puts((short) t_vertices[2].getId());
- }
- }
- indicesTxt.seal(gl, true);
- indicesTxt.enableBuffer(gl, false);
-
- // process vertices and update bbox
- box.reset();
- verticeTxtAttr.seal(gl, false);
- verticeTxtAttr.rewind();
- texCoordTxtAttr.seal(gl, false);
- texCoordTxtAttr.rewind();
- for(int i=0; i<vertices.size(); i++) {
- final Vertex v = vertices.get(i);
- verticeTxtAttr.putf(v.getX());
- verticeTxtAttr.putf(v.getY());
- verticeTxtAttr.putf(v.getZ());
- box.resize(v.getX(), v.getY(), v.getZ());
-
- final float[] tex = v.getTexCoord();
- texCoordTxtAttr.putf(tex[0]);
- texCoordTxtAttr.putf(tex[1]);
- }
- texCoordTxtAttr.seal(gl, true);
- texCoordTxtAttr.enableBuffer(gl, false);
- verticeTxtAttr.seal(gl, true);
- verticeTxtAttr.enableBuffer(gl, false);
-
- // update all bbox related data
- verticeFboAttr.seal(gl, false);
- verticeFboAttr.rewind();
- verticeFboAttr.putf(box.getLow()[0]); verticeFboAttr.putf(box.getLow()[1]); verticeFboAttr.putf(box.getLow()[2]);
- verticeFboAttr.putf(box.getLow()[0]); verticeFboAttr.putf(box.getHigh()[1]); verticeFboAttr.putf(box.getLow()[2]);
- verticeFboAttr.putf(box.getHigh()[0]); verticeFboAttr.putf(box.getHigh()[1]); verticeFboAttr.putf(box.getLow()[2]);
- verticeFboAttr.putf(box.getHigh()[0]); verticeFboAttr.putf(box.getLow()[1]); verticeFboAttr.putf(box.getLow()[2]);
- verticeFboAttr.seal(gl, true);
- verticeFboAttr.enableBuffer(gl, false);
-
- fboPMVMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- fboPMVMatrix.glLoadIdentity();
- fboPMVMatrix.glOrthof(box.getLow()[0], box.getHigh()[0], box.getLow()[1], box.getHigh()[1], -1, 1);
-
- // push data 2 GPU ..
- indicesFbo.seal(gl, true);
- indicesFbo.enableBuffer(gl, false);
-
- setDirty(false);
-
- // the buffers were disabled, since due to real/fbo switching and other vbo usage
- }
-
- int[] maxTexSize = new int[] { -1 } ;
-
- @Override
- protected void drawImpl(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int[/*1*/] texWidth) {
- if(vp_width <=0 || vp_height <= 0 || null==texWidth || texWidth[0] <= 0){
- renderRegion(gl);
- } else {
- if(0 > maxTexSize[0]) {
- gl.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, maxTexSize, 0);
- }
- if(texWidth[0] != tex_width_c) {
- if(texWidth[0] > maxTexSize[0]) {
- texWidth[0] = maxTexSize[0]; // clip to max - write-back user value!
- }
- renderRegion2FBO(gl, rs, texWidth);
- }
- // System.out.println("Scale: " + matrix.glGetMatrixf().get(1+4*3) +" " + matrix.glGetMatrixf().get(2+4*3));
- renderFBO(gl, rs, vp_width, vp_height);
- }
- }
-
- private void renderFBO(GL2ES2 gl, RenderState rs, int width, int hight) {
- final ShaderState st = rs.getShaderState();
-
- gl.glViewport(0, 0, width, hight);
- st.uniform(gl, mgl_ActiveTexture);
- gl.glActiveTexture(GL.GL_TEXTURE0 + mgl_ActiveTexture.intValue());
- fbo.use(gl, texA);
- verticeFboAttr.enableBuffer(gl, true);
- texCoordFboAttr.enableBuffer(gl, true);
- indicesFbo.bindBuffer(gl, true); // keeps VBO binding
-
- gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesFbo.getElementCount() * indicesFbo.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0);
-
- indicesFbo.bindBuffer(gl, false);
- texCoordFboAttr.enableBuffer(gl, false);
- verticeFboAttr.enableBuffer(gl, false);
- fbo.unuse(gl);
-
- // setback: gl.glActiveTexture(currentActiveTextureEngine[0]);
- }
-
- private void renderRegion2FBO(GL2ES2 gl, RenderState rs, int[/*1*/] texWidth) {
- final ShaderState st = rs.getShaderState();
-
- if(0>=texWidth[0]) {
- throw new IllegalArgumentException("texWidth must be greater than 0: "+texWidth[0]);
- }
-
- tex_width_c = texWidth[0];
- tex_height_c = (int) ( ( ( tex_width_c * box.getHeight() ) / box.getWidth() ) + 0.5f );
-
- // System.out.println("FBO Size: "+texWidth[0]+" -> "+tex_width_c+"x"+tex_height_c);
- // System.out.println("FBO Scale: " + m.glGetMatrixf().get(0) +" " + m.glGetMatrixf().get(5));
-
- if(null != fbo && fbo.getWidth() != tex_width_c && fbo.getHeight() != tex_height_c ) {
- fbo.reset(gl, tex_width_c, tex_height_c);
- }
-
- if(null == fbo) {
- fbo = new FBObject();
- fbo.reset(gl, tex_width_c, tex_height_c);
- // FIXME: shall not use bilinear, due to own AA ? However, w/o bilinear result is not smooth
- texA = fbo.attachTexture2D(gl, 0, true, GL2ES2.GL_LINEAR, GL2ES2.GL_LINEAR, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE);
- // texA = fbo.attachTexture2D(gl, 0, GL2ES2.GL_NEAREST, GL2ES2.GL_NEAREST, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE);
- fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24);
- } else {
- fbo.bind(gl);
- }
-
- //render texture
- gl.glViewport(0, 0, tex_width_c, tex_height_c);
- st.uniform(gl, mgl_fboPMVMatrix); // use orthogonal matrix
-
- gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
- gl.glClear(GL2ES2.GL_COLOR_BUFFER_BIT | GL2ES2.GL_DEPTH_BUFFER_BIT);
- renderRegion(gl);
- fbo.unbind(gl);
-
- st.uniform(gl, rs.getPMVMatrix()); // switch back to real PMV matrix
-
- // if( !gl.isGL3() ) {
- // GLSL < 1.30
- if(null == mgl_TextureSize) {
- mgl_TextureSize = new GLUniformData(UniformNames.gcu_TextureSize, 2, Buffers.newDirectFloatBuffer(2));
- }
- final FloatBuffer texSize = (FloatBuffer) mgl_TextureSize.getBuffer();
- texSize.put(0, (float)fbo.getWidth());
- texSize.put(1, (float)fbo.getHeight());
- st.uniform(gl, mgl_TextureSize);
- //}
- }
-
- private void renderRegion(GL2ES2 gl) {
- verticeTxtAttr.enableBuffer(gl, true);
- texCoordTxtAttr.enableBuffer(gl, true);
- indicesTxt.bindBuffer(gl, true); // keeps VBO binding
-
- gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesTxt.getElementCount() * indicesTxt.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0);
-
- indicesTxt.bindBuffer(gl, false);
- texCoordTxtAttr.enableBuffer(gl, false);
- verticeTxtAttr.enableBuffer(gl, false);
- }
-
- @Override
- public void destroy(GL2ES2 gl, RenderState rs) {
- if(DEBUG_INSTANCE) {
- System.err.println("VBORegion2PES2 Destroy: " + this);
- }
- final ShaderState st = rs.getShaderState();
- if(null != fbo) {
- fbo.destroy(gl);
- fbo = null;
- texA = null;
- }
- if(null != verticeTxtAttr) {
- st.ownAttribute(verticeTxtAttr, false);
- verticeTxtAttr.destroy(gl);
- verticeTxtAttr = null;
- }
- if(null != texCoordTxtAttr) {
- st.ownAttribute(texCoordTxtAttr, false);
- texCoordTxtAttr.destroy(gl);
- texCoordTxtAttr = null;
- }
- if(null != indicesTxt) {
- indicesTxt.destroy(gl);
- indicesTxt = null;
- }
- if(null != verticeFboAttr) {
- st.ownAttribute(verticeFboAttr, false);
- verticeFboAttr.destroy(gl);
- verticeFboAttr = null;
- }
- if(null != texCoordFboAttr) {
- st.ownAttribute(texCoordFboAttr, false);
- texCoordFboAttr.destroy(gl);
- texCoordFboAttr = null;
- }
- if(null != indicesFbo) {
- indicesFbo.destroy(gl);
- indicesFbo = null;
- }
- triangles.clear();
- vertices.clear();
- }
-}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java
new file mode 100644
index 000000000..176b39c25
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java
@@ -0,0 +1,411 @@
+/**
+ * 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 java.nio.FloatBuffer;
+
+import javax.media.opengl.GL2ES2;
+// FIXME: Subsume GL2GL3.GL_DRAW_FRAMEBUFFER -> GL2ES2.GL_DRAW_FRAMEBUFFER !
+import javax.media.opengl.GL;
+import javax.media.opengl.GLUniformData;
+import javax.media.opengl.fixedfunc.GLMatrixFunc;
+
+import jogamp.graph.curve.opengl.shader.AttributeNames;
+import jogamp.graph.curve.opengl.shader.UniformNames;
+
+import com.jogamp.common.nio.Buffers;
+import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.GLRegion;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
+import com.jogamp.graph.curve.opengl.RenderState;
+import com.jogamp.opengl.FBObject;
+import com.jogamp.opengl.FBObject.Attachment;
+import com.jogamp.opengl.math.geom.AABBox;
+import com.jogamp.opengl.util.GLArrayDataServer;
+import com.jogamp.opengl.util.PMVMatrix;
+import com.jogamp.opengl.util.glsl.ShaderState;
+
+public class VBORegion2PMSAAES2 extends GLRegion {
+ private static final boolean DEBUG_FBO_1 = false;
+ private static final boolean DEBUG_FBO_2 = false;
+ private GLArrayDataServer verticeTxtAttr;
+ private GLArrayDataServer texCoordTxtAttr;
+ private GLArrayDataServer indicesTxtBuffer;
+ private GLArrayDataServer verticeFboAttr;
+ private GLArrayDataServer texCoordFboAttr;
+ private GLArrayDataServer indicesFbo;
+
+ private FBObject fbo;
+ private final PMVMatrix fboPMVMatrix;
+ GLUniformData mgl_fboPMVMatrix;
+
+ private int fboWidth = 0;
+ private int fboHeight = 0;
+ GLUniformData mgl_ActiveTexture;
+ GLUniformData mgl_TextureSize;
+
+ final int[] maxTexSize = new int[] { -1 } ;
+
+ public VBORegion2PMSAAES2(final int renderModes, final int textureUnit) {
+ super(renderModes);
+ final int initialElementCount = 256;
+ fboPMVMatrix = new PMVMatrix();
+ mgl_fboPMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, fboPMVMatrix.glGetPMvMatrixf());
+ mgl_ActiveTexture = new GLUniformData(UniformNames.gcu_TextureUnit, textureUnit);
+
+ indicesTxtBuffer = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ verticeTxtAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT,
+ false, initialElementCount, GL.GL_STATIC_DRAW);
+ texCoordTxtAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT,
+ false, initialElementCount, GL.GL_STATIC_DRAW);
+ }
+
+ @Override
+ protected final void clearImpl(final GL2ES2 gl, final RegionRenderer renderer) {
+ indicesTxtBuffer.seal(gl, false);
+ indicesTxtBuffer.rewind();
+ verticeTxtAttr.seal(gl, false);
+ verticeTxtAttr.rewind();
+ texCoordTxtAttr.seal(gl, false);
+ texCoordTxtAttr.rewind();
+ }
+
+ @Override
+ protected final void pushVertex(float[] coords, float[] texParams) {
+ verticeTxtAttr.putf(coords[0]);
+ verticeTxtAttr.putf(coords[1]);
+ verticeTxtAttr.putf(coords[2]);
+
+ texCoordTxtAttr.putf(texParams[0]);
+ texCoordTxtAttr.putf(texParams[1]);
+ }
+
+ @Override
+ protected final void pushIndex(int idx) {
+ indicesTxtBuffer.puts((short)idx);
+ }
+
+ @Override
+ protected void update(final GL2ES2 gl, final RegionRenderer renderer) {
+ if(null == indicesFbo) {
+ final ShaderState st = renderer.getShaderState();
+
+ indicesFbo = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, 2, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ indicesFbo.puts((short) 0); indicesFbo.puts((short) 1); indicesFbo.puts((short) 3);
+ indicesFbo.puts((short) 1); indicesFbo.puts((short) 2); indicesFbo.puts((short) 3);
+ indicesFbo.seal(true);
+
+ texCoordFboAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT,
+ false, 4, GL.GL_STATIC_DRAW);
+ st.ownAttribute(texCoordFboAttr, true);
+ texCoordFboAttr.putf(0); texCoordFboAttr.putf(0);
+ texCoordFboAttr.putf(0); texCoordFboAttr.putf(1);
+ texCoordFboAttr.putf(1); texCoordFboAttr.putf(1);
+ texCoordFboAttr.putf(1); texCoordFboAttr.putf(0);
+ texCoordFboAttr.seal(true);
+
+ verticeFboAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT,
+ false, 4, GL.GL_STATIC_DRAW);
+ st.ownAttribute(verticeFboAttr, true);
+
+ st.ownAttribute(verticeTxtAttr, true);
+ st.ownAttribute(texCoordTxtAttr, true);
+
+ if(Region.DEBUG_INSTANCE) {
+ System.err.println("VBORegion2PES2 Create: " + this);
+ }
+ }
+ // seal buffers
+ indicesTxtBuffer.seal(gl, true);
+ indicesTxtBuffer.enableBuffer(gl, false);
+ texCoordTxtAttr.seal(gl, true);
+ texCoordTxtAttr.enableBuffer(gl, false);
+ verticeTxtAttr.seal(gl, true);
+ verticeTxtAttr.enableBuffer(gl, false);
+
+ // update all bbox related data
+ verticeFboAttr.seal(gl, false);
+ verticeFboAttr.rewind();
+ verticeFboAttr.putf(box.getMinX()); verticeFboAttr.putf(box.getMinY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMinX()); verticeFboAttr.putf(box.getMaxY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMaxX()); verticeFboAttr.putf(box.getMaxY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMaxX()); verticeFboAttr.putf(box.getMinY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.seal(gl, true);
+ verticeFboAttr.enableBuffer(gl, false);
+
+ fboPMVMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
+ fboPMVMatrix.glLoadIdentity();
+ fboPMVMatrix.glOrthof(box.getMinX(), box.getMaxX(), box.getMinY(), box.getMaxY(), -1, 1);
+
+ // push data 2 GPU ..
+ indicesFbo.seal(gl, true);
+ indicesFbo.enableBuffer(gl, false);
+
+ // trigger renderRegion2FBO !
+ fboHeight = 0;
+ fboWidth = 0;
+ // the buffers were disabled, since due to real/fbo switching and other vbo usage
+ }
+
+ private final AABBox drawWinBox = new AABBox();
+ private final int[] drawView = new int[] { 0, 0, 0, 0 };
+ private final float[] drawTmpV3 = new float[3];
+
+ @Override
+ protected void drawImpl(final GL2ES2 gl, final RegionRenderer renderer, final int[/*1*/] sampleCount) {
+ final int width = renderer.getWidth();
+ final int height = renderer.getHeight();
+ if(width <=0 || height <= 0 || null==sampleCount || sampleCount[0] <= 0){
+ renderRegion(gl);
+ } else {
+ if(0 > maxTexSize[0]) {
+ gl.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, maxTexSize, 0);
+ }
+ final RenderState rs = renderer.getRenderState();
+ float renderFboWidth, renderFboHeight;
+ int targetFboWidth, targetFboHeight;
+ float diffWidth, diffHeight;
+ {
+ // Calculate perspective pixel width/height for FBO,
+ // considering the sampleCount.
+ drawView[2] = width;
+ drawView[3] = height;
+ box.mapToWindow(drawWinBox, renderer.getMatrix(), drawView, true /* useCenterZ */, drawTmpV3);
+ renderFboWidth = drawWinBox.getWidth();
+ renderFboHeight = drawWinBox.getHeight();
+ targetFboWidth = (int)Math.ceil(renderFboWidth);
+ targetFboHeight = (int)Math.ceil(renderFboHeight);
+ diffWidth = targetFboWidth-renderFboWidth;
+ diffHeight = targetFboHeight-renderFboHeight;
+ if( DEBUG_FBO_2 ) {
+ System.err.printf("XXX.MinMax view[%d, %d]: FBO f[%.3f, %.3f], i[%d x %d], d[%.3f, %.3f], msaa %d%n",
+ drawView[2], drawView[3],
+ renderFboWidth, renderFboHeight, targetFboWidth, targetFboHeight,
+ diffWidth, diffHeight, sampleCount[0]);
+ }
+ }
+ final int deltaFboWidth = Math.abs(targetFboWidth-fboWidth);
+ final int deltaFboHeight = Math.abs(targetFboHeight-fboHeight);
+ final int maxDeltaFbo, maxLengthFbo;
+ if( deltaFboWidth >= deltaFboHeight ) {
+ maxDeltaFbo = deltaFboWidth;
+ maxLengthFbo = fboWidth > 0 ? fboWidth : 1;
+ } else {
+ maxDeltaFbo = deltaFboHeight;
+ maxLengthFbo = fboHeight > 0 ? fboHeight : 1;
+ }
+ final float pctFboDelta = (float)maxDeltaFbo / (float)maxLengthFbo;
+ if( DEBUG_FBO_2 ) {
+ System.err.printf("XXX.maxDelta: %d / %d = %.3f%n", maxDeltaFbo, maxLengthFbo, pctFboDelta);
+ }
+ if( pctFboDelta > 0.1f || ( fbo != null && fbo.getNumSamples() != sampleCount[0] ) ) { // more than 10% !
+ if( DEBUG_FBO_1 ) {
+ System.err.printf("XXX.maxDelta: %d / %d = %.3f%n", maxDeltaFbo, maxLengthFbo, pctFboDelta);
+ System.err.printf("XXX.MSAA %d, %d x %d%n",
+ sampleCount[0], targetFboWidth, targetFboHeight);
+ }
+ // FIXME: maxTexSize test not correct
+ boolean rescale = false;
+ if( targetFboWidth > maxTexSize[0] ) {
+ targetFboWidth = maxTexSize[0];
+ renderFboWidth = targetFboWidth;
+ rescale = true;
+ }
+ if( targetFboHeight > maxTexSize[0] ) {
+ targetFboHeight = maxTexSize[0];
+ renderFboHeight = targetFboHeight;
+ rescale = true;
+ }
+ if(rescale) {
+ diffWidth = targetFboWidth-renderFboWidth;
+ diffHeight = targetFboHeight-renderFboHeight;
+ if( DEBUG_FBO_1 ) {
+ System.err.printf("XXX.Rescale (MAX): FBO f[%.3f, %.3f], i[%d x %d], d[%.3f, %.3f], msaa %d%n",
+ renderFboWidth, renderFboHeight, targetFboWidth, targetFboHeight,
+ diffWidth, diffHeight, sampleCount[0]);
+ }
+ }
+ verticeFboAttr.seal(false);
+ verticeFboAttr.rewind();
+ verticeFboAttr.putf(box.getMinX()); verticeFboAttr.putf(box.getMinY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMinX()); verticeFboAttr.putf(box.getMaxY()+diffHeight); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMaxX()+diffWidth); verticeFboAttr.putf(box.getMaxY()+diffHeight); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMaxX()+diffWidth); verticeFboAttr.putf(box.getMinY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.seal(true);
+ fboPMVMatrix.glLoadIdentity();
+ fboPMVMatrix.glOrthof(box.getMinX(), box.getMaxX()+diffWidth,
+ box.getMinY(), box.getMaxY()+diffHeight, -1, 1);
+ renderRegion2FBO(gl, rs, targetFboWidth, targetFboHeight, sampleCount);
+ } else {
+ texCoordFboAttr.setVBOWritten(false);
+ }
+ // System.out.println("Scale: " + matrix.glGetMatrixf().get(1+4*3) +" " + matrix.glGetMatrixf().get(2+4*3));
+ renderFBO(gl, rs, width, height);
+ }
+ }
+ private void setTexSize(final GL2ES2 gl, final ShaderState st, boolean firstPass) {
+ if(null == mgl_TextureSize) {
+ mgl_TextureSize = new GLUniformData(UniformNames.gcu_TextureSize, 3, Buffers.newDirectFloatBuffer(3));
+ }
+ final FloatBuffer texSize = (FloatBuffer) mgl_TextureSize.getBuffer();
+ if( firstPass ) {
+ texSize.put(2, 0f);
+ } else {
+ texSize.put(0, fboWidth);
+ texSize.put(1, fboHeight);
+ texSize.put(2, 1f);
+ }
+ st.uniform(gl, mgl_TextureSize);
+ }
+
+ private void renderFBO(final GL2ES2 gl, final RenderState rs, final int width, final int height) {
+ final ShaderState st = rs.getShaderState();
+
+ gl.glViewport(0, 0, width, height);
+ st.uniform(gl, mgl_ActiveTexture);
+ gl.glActiveTexture(GL.GL_TEXTURE0 + mgl_ActiveTexture.intValue());
+ setTexSize(gl, st, false);
+
+ fbo.use(gl, fbo.getSamplingSink());
+ verticeFboAttr.enableBuffer(gl, true);
+ texCoordFboAttr.enableBuffer(gl, true);
+ indicesFbo.bindBuffer(gl, true); // keeps VBO binding
+
+ gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesFbo.getElementCount() * indicesFbo.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0);
+
+ indicesFbo.bindBuffer(gl, false);
+ texCoordFboAttr.enableBuffer(gl, false);
+ verticeFboAttr.enableBuffer(gl, false);
+ fbo.unuse(gl);
+
+ // setback: gl.glActiveTexture(currentActiveTextureEngine[0]);
+ }
+
+ private void renderRegion2FBO(final GL2ES2 gl, final RenderState rs, final int targetFboWidth, final int targetFboHeight, int[] sampleCount) {
+ final ShaderState st = rs.getShaderState();
+
+ if( 0 >= targetFboWidth || 0 >= targetFboHeight ) {
+ throw new IllegalArgumentException("fboSize must be greater than 0: "+targetFboWidth+"x"+targetFboHeight);
+ }
+
+ if(null == fbo) {
+ fboWidth = targetFboWidth;
+ fboHeight = targetFboHeight;
+ fbo = new FBObject();
+ fbo.reset(gl, fboWidth, fboHeight, sampleCount[0], false);
+ sampleCount[0] = fbo.getNumSamples();
+ fbo.attachColorbuffer(gl, 0, true);
+ fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24);
+ final FBObject ssink = new FBObject();
+ {
+ ssink.reset(gl, fboWidth, fboHeight);
+ // FIXME: shall not use bilinear (GL_LINEAR), due to MSAA ???
+ // ssink.attachTexture2D(gl, 0, true, GL2ES2.GL_LINEAR, GL2ES2.GL_LINEAR, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE);
+ ssink.attachTexture2D(gl, 0, true, GL2ES2.GL_NEAREST, GL2ES2.GL_NEAREST, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE);
+ ssink.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24);
+ }
+ fbo.setSamplingSink(ssink);
+ fbo.resetSamplingSink(gl); // validate
+ if( DEBUG_FBO_1 ) {
+ System.err.printf("XXX.createFBO: %dx%d%n%s%n", fboWidth, fboHeight, fbo.toString());
+ }
+ } else if( targetFboWidth != fboWidth || targetFboHeight != fboHeight || fbo.getNumSamples() != sampleCount[0] ) {
+ fbo.reset(gl, targetFboWidth, targetFboHeight, sampleCount[0], true /* resetSamplingSink */);
+ sampleCount[0] = fbo.getNumSamples();
+ if( DEBUG_FBO_1 ) {
+ System.err.printf("XXX.resetFBO: %dx%d -> %dx%d%n%s%n", fboWidth, fboHeight, targetFboWidth, targetFboHeight, fbo );
+ }
+ fboWidth = targetFboWidth;
+ fboHeight = targetFboHeight;
+ }
+ fbo.bind(gl);
+ setTexSize(gl, st, true);
+
+ //render texture
+ gl.glViewport(0, 0, fboWidth, fboHeight);
+ st.uniform(gl, mgl_fboPMVMatrix); // use orthogonal matrix
+
+ gl.glClear(GL2ES2.GL_COLOR_BUFFER_BIT | GL2ES2.GL_DEPTH_BUFFER_BIT);
+ renderRegion(gl);
+ fbo.unbind(gl);
+
+ st.uniform(gl, rs.getPMVMatrix()); // switch back to real PMV matrix
+ }
+
+ private void renderRegion(final GL2ES2 gl) {
+ verticeTxtAttr.enableBuffer(gl, true);
+ texCoordTxtAttr.enableBuffer(gl, true);
+ indicesTxtBuffer.bindBuffer(gl, true); // keeps VBO binding
+
+ gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesTxtBuffer.getElementCount() * indicesTxtBuffer.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0);
+
+ indicesTxtBuffer.bindBuffer(gl, false);
+ texCoordTxtAttr.enableBuffer(gl, false);
+ verticeTxtAttr.enableBuffer(gl, false);
+ }
+
+ @Override
+ protected void destroyImpl(final GL2ES2 gl, final RegionRenderer renderer) {
+ if(DEBUG_INSTANCE) {
+ System.err.println("VBORegion2PES2 Destroy: " + this);
+ }
+ final ShaderState st = renderer.getShaderState();
+ if(null != fbo) {
+ fbo.destroy(gl);
+ fbo = null;
+ }
+ if(null != verticeTxtAttr) {
+ st.ownAttribute(verticeTxtAttr, false);
+ verticeTxtAttr.destroy(gl);
+ verticeTxtAttr = null;
+ }
+ if(null != texCoordTxtAttr) {
+ st.ownAttribute(texCoordTxtAttr, false);
+ texCoordTxtAttr.destroy(gl);
+ texCoordTxtAttr = null;
+ }
+ if(null != indicesTxtBuffer) {
+ indicesTxtBuffer.destroy(gl);
+ indicesTxtBuffer = null;
+ }
+ if(null != verticeFboAttr) {
+ st.ownAttribute(verticeFboAttr, false);
+ verticeFboAttr.destroy(gl);
+ verticeFboAttr = null;
+ }
+ if(null != texCoordFboAttr) {
+ st.ownAttribute(texCoordFboAttr, false);
+ texCoordFboAttr.destroy(gl);
+ texCoordFboAttr = null;
+ }
+ if(null != indicesFbo) {
+ indicesFbo.destroy(gl);
+ indicesFbo = null;
+ }
+ }
+}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java
new file mode 100644
index 000000000..3f3709d6e
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java
@@ -0,0 +1,408 @@
+/**
+ * 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 java.nio.FloatBuffer;
+
+import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GL;
+import javax.media.opengl.GLUniformData;
+import javax.media.opengl.fixedfunc.GLMatrixFunc;
+
+import jogamp.graph.curve.opengl.shader.AttributeNames;
+import jogamp.graph.curve.opengl.shader.UniformNames;
+
+import com.jogamp.common.nio.Buffers;
+import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.GLRegion;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
+import com.jogamp.graph.curve.opengl.RenderState;
+import com.jogamp.opengl.FBObject;
+import com.jogamp.opengl.FBObject.Attachment;
+import com.jogamp.opengl.FBObject.TextureAttachment;
+import com.jogamp.opengl.math.geom.AABBox;
+import com.jogamp.opengl.util.GLArrayDataServer;
+import com.jogamp.opengl.util.PMVMatrix;
+import com.jogamp.opengl.util.glsl.ShaderState;
+
+public class VBORegion2PVBAAES2 extends GLRegion {
+ private static final boolean DEBUG_FBO_1 = false;
+ private static final boolean DEBUG_FBO_2 = false;
+ private GLArrayDataServer verticeTxtAttr;
+ private GLArrayDataServer texCoordTxtAttr;
+ private GLArrayDataServer indicesTxtBuffer;
+ private GLArrayDataServer verticeFboAttr;
+ private GLArrayDataServer texCoordFboAttr;
+ private GLArrayDataServer indicesFbo;
+
+ private FBObject fbo;
+ private TextureAttachment texA;
+ private final PMVMatrix fboPMVMatrix;
+ GLUniformData mgl_fboPMVMatrix;
+
+ private int fboWidth = 0;
+ private int fboHeight = 0;
+ GLUniformData mgl_ActiveTexture;
+ GLUniformData mgl_TextureSize;
+
+ final int[] maxTexSize = new int[] { -1 } ;
+
+ public VBORegion2PVBAAES2(final int renderModes, final int textureUnit) {
+ super(renderModes);
+ final int initialElementCount = 256;
+ fboPMVMatrix = new PMVMatrix();
+ mgl_fboPMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, fboPMVMatrix.glGetPMvMatrixf());
+ mgl_ActiveTexture = new GLUniformData(UniformNames.gcu_TextureUnit, textureUnit);
+
+ indicesTxtBuffer = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ verticeTxtAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT,
+ false, initialElementCount, GL.GL_STATIC_DRAW);
+ texCoordTxtAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT,
+ false, initialElementCount, GL.GL_STATIC_DRAW);
+ }
+
+ @Override
+ protected final void clearImpl(final GL2ES2 gl, final RegionRenderer renderer) {
+ indicesTxtBuffer.seal(gl, false);
+ indicesTxtBuffer.rewind();
+ verticeTxtAttr.seal(gl, false);
+ verticeTxtAttr.rewind();
+ texCoordTxtAttr.seal(gl, false);
+ texCoordTxtAttr.rewind();
+ }
+
+ @Override
+ protected final void pushVertex(float[] coords, float[] texParams) {
+ verticeTxtAttr.putf(coords[0]);
+ verticeTxtAttr.putf(coords[1]);
+ verticeTxtAttr.putf(coords[2]);
+
+ texCoordTxtAttr.putf(texParams[0]);
+ texCoordTxtAttr.putf(texParams[1]);
+ }
+
+ @Override
+ protected final void pushIndex(int idx) {
+ indicesTxtBuffer.puts((short)idx);
+ }
+
+ @Override
+ protected void update(final GL2ES2 gl, final RegionRenderer renderer) {
+ if(null == indicesFbo) {
+ final ShaderState st = renderer.getShaderState();
+
+ indicesFbo = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, 2, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ indicesFbo.puts((short) 0); indicesFbo.puts((short) 1); indicesFbo.puts((short) 3);
+ indicesFbo.puts((short) 1); indicesFbo.puts((short) 2); indicesFbo.puts((short) 3);
+ indicesFbo.seal(true);
+
+ texCoordFboAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT,
+ false, 4, GL.GL_STATIC_DRAW);
+ st.ownAttribute(texCoordFboAttr, true);
+ texCoordFboAttr.putf(0); texCoordFboAttr.putf(0);
+ texCoordFboAttr.putf(0); texCoordFboAttr.putf(1);
+ texCoordFboAttr.putf(1); texCoordFboAttr.putf(1);
+ texCoordFboAttr.putf(1); texCoordFboAttr.putf(0);
+ texCoordFboAttr.seal(true);
+
+ verticeFboAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT,
+ false, 4, GL.GL_STATIC_DRAW);
+ st.ownAttribute(verticeFboAttr, true);
+
+ st.ownAttribute(verticeTxtAttr, true);
+ st.ownAttribute(texCoordTxtAttr, true);
+
+ if(Region.DEBUG_INSTANCE) {
+ System.err.println("VBORegion2PES2 Create: " + this);
+ }
+ }
+ // seal buffers
+ indicesTxtBuffer.seal(gl, true);
+ indicesTxtBuffer.enableBuffer(gl, false);
+ texCoordTxtAttr.seal(gl, true);
+ texCoordTxtAttr.enableBuffer(gl, false);
+ verticeTxtAttr.seal(gl, true);
+ verticeTxtAttr.enableBuffer(gl, false);
+
+ // update all bbox related data
+ verticeFboAttr.seal(gl, false);
+ verticeFboAttr.rewind();
+ verticeFboAttr.putf(box.getMinX()); verticeFboAttr.putf(box.getMinY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMinX()); verticeFboAttr.putf(box.getMaxY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMaxX()); verticeFboAttr.putf(box.getMaxY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMaxX()); verticeFboAttr.putf(box.getMinY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.seal(gl, true);
+ verticeFboAttr.enableBuffer(gl, false);
+
+ fboPMVMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
+ fboPMVMatrix.glLoadIdentity();
+ fboPMVMatrix.glOrthof(box.getMinX(), box.getMaxX(), box.getMinY(), box.getMaxY(), -1, 1);
+
+ // push data 2 GPU ..
+ indicesFbo.seal(gl, true);
+ indicesFbo.enableBuffer(gl, false);
+
+ // trigger renderRegion2FBO !
+ fboHeight = 0;
+ fboWidth = 0;
+ // the buffers were disabled, since due to real/fbo switching and other vbo usage
+ }
+
+ private final AABBox drawWinBox = new AABBox();
+ private final int[] drawView = new int[] { 0, 0, 0, 0 };
+ private final float[] drawTmpV3 = new float[3];
+
+ @Override
+ protected void drawImpl(final GL2ES2 gl, final RegionRenderer renderer, final int[/*1*/] sampleCount) {
+ final int width = renderer.getWidth();
+ final int height = renderer.getHeight();
+ if(width <=0 || height <= 0 || null==sampleCount || sampleCount[0] <= 0){
+ renderRegion(gl);
+ } else {
+ if(0 > maxTexSize[0]) {
+ gl.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, maxTexSize, 0);
+ }
+ final RenderState rs = renderer.getRenderState();
+ final float winWidth, winHeight;
+ int targetFboWidth, targetFboHeight;
+ float renderFboWidth, renderFboHeight;
+ float diffWidth, diffHeight;
+ {
+ // Calculate perspective pixel width/height for FBO,
+ // considering the sampleCount.
+ drawView[2] = width;
+ drawView[3] = height;
+ box.mapToWindow(drawWinBox, renderer.getMatrix(), drawView, true /* useCenterZ */, drawTmpV3);
+ winWidth = drawWinBox.getWidth();
+ winHeight = drawWinBox.getHeight();
+ diffWidth = (float)Math.ceil(winWidth)-winWidth;
+ diffHeight = (float)Math.ceil(winHeight)-winHeight;
+ renderFboWidth = winWidth*sampleCount[0];
+ renderFboHeight = winHeight*sampleCount[0];
+ targetFboWidth = (int)Math.ceil(renderFboWidth);
+ targetFboHeight = (int)Math.ceil(renderFboHeight);
+ if( DEBUG_FBO_2 ) {
+ System.err.printf("XXX.MinMax1 view[%d, %d] -> win[%.3f, %.3f]: FBO f[%.3f, %.3f], i[%d x %d], d[%.3f, %.3f], msaa %d%n",
+ drawView[2], drawView[3],
+ winWidth, winHeight,
+ renderFboWidth, renderFboHeight, targetFboWidth, targetFboHeight,
+ diffWidth, diffHeight, sampleCount[0]);
+ }
+ }
+ final int deltaFboWidth = Math.abs(targetFboWidth-fboWidth);
+ final int deltaFboHeight = Math.abs(targetFboHeight-fboHeight);
+ final int maxDeltaFbo, maxLengthFbo;
+ if( deltaFboWidth >= deltaFboHeight ) {
+ maxDeltaFbo = deltaFboWidth;
+ maxLengthFbo = fboWidth > 0 ? fboWidth : 1;
+ } else {
+ maxDeltaFbo = deltaFboHeight;
+ maxLengthFbo = fboHeight > 0 ? fboHeight : 1;
+ }
+ final float pctFboDelta = (float)maxDeltaFbo / (float)maxLengthFbo;
+ if( DEBUG_FBO_2 ) {
+ System.err.printf("XXX.maxDelta: %d / %d = %.3f%n", maxDeltaFbo, maxLengthFbo, pctFboDelta);
+ }
+ if( pctFboDelta > 0.1f ) { // more than 10% !
+ if( DEBUG_FBO_1 ) {
+ System.err.printf("XXX.maxDelta: %d / %d = %.3f%n", maxDeltaFbo, maxLengthFbo, pctFboDelta);
+ System.err.printf("XXX.Scale %d * [%f x %f]: %d x %d%n",
+ sampleCount[0], winWidth, winHeight, targetFboWidth, targetFboHeight);
+ }
+ final int maxLength = Math.max(targetFboWidth, targetFboHeight);
+ if( maxLength > maxTexSize[0] ) {
+ if( targetFboWidth > targetFboHeight ) {
+ sampleCount[0] = (int)Math.floor(maxTexSize[0] / winWidth);
+ } else {
+ sampleCount[0] = (int)Math.floor(maxTexSize[0] / winHeight);
+ }
+ renderFboWidth = winWidth*sampleCount[0];
+ renderFboHeight = winHeight*sampleCount[0];
+ targetFboWidth = (int)Math.ceil(renderFboWidth);
+ targetFboHeight = (int)Math.ceil(renderFboHeight);
+ if( DEBUG_FBO_1 ) {
+ System.err.printf("XXX.Rescale (MAX): win[%.3f, %.3f]: FBO f[%.3f, %.3f], i[%d x %d], msaa %d%n",
+ winWidth, winHeight,
+ renderFboWidth, renderFboHeight, targetFboWidth, targetFboHeight, sampleCount[0]);
+ }
+ if( sampleCount[0] <= 0 ) {
+ // Last way out!
+ renderRegion(gl);
+ return;
+ }
+ }
+ verticeFboAttr.seal(false);
+ verticeFboAttr.rewind();
+ verticeFboAttr.putf(box.getMinX()); verticeFboAttr.putf(box.getMinY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMinX()); verticeFboAttr.putf(box.getMaxY()+diffHeight); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMaxX()+diffWidth); verticeFboAttr.putf(box.getMaxY()+diffHeight); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.putf(box.getMaxX()+diffWidth); verticeFboAttr.putf(box.getMinY()); verticeFboAttr.putf(box.getMinZ());
+ verticeFboAttr.seal(true);
+ fboPMVMatrix.glLoadIdentity();
+ fboPMVMatrix.glOrthof(box.getMinX(), box.getMaxX()+diffWidth,
+ box.getMinY(), box.getMaxY()+diffHeight, -1, 1);
+ renderRegion2FBO(gl, rs, targetFboWidth, targetFboHeight, sampleCount[0]);
+ }
+ // System.out.println("Scale: " + matrix.glGetMatrixf().get(1+4*3) +" " + matrix.glGetMatrixf().get(2+4*3));
+ renderFBO(gl, rs, width, height, sampleCount[0]);
+ }
+ }
+ private void setTexSize(final GL2ES2 gl, final ShaderState st, boolean firstPass, int sampleCount) {
+ if(null == mgl_TextureSize) {
+ mgl_TextureSize = new GLUniformData(UniformNames.gcu_TextureSize, 3, Buffers.newDirectFloatBuffer(3));
+ }
+ final FloatBuffer texSize = (FloatBuffer) mgl_TextureSize.getBuffer();
+ if( firstPass ) {
+ texSize.put(2, 0f);
+ } else {
+ texSize.put(0, fboWidth);
+ texSize.put(1, fboHeight);
+ texSize.put(2, sampleCount);
+ }
+ st.uniform(gl, mgl_TextureSize);
+ }
+
+ private void renderFBO(final GL2ES2 gl, final RenderState rs, final int width, final int height, int sampleCount) {
+ final ShaderState st = rs.getShaderState();
+
+ gl.glViewport(0, 0, width, height);
+ st.uniform(gl, mgl_ActiveTexture);
+ gl.glActiveTexture(GL.GL_TEXTURE0 + mgl_ActiveTexture.intValue());
+ setTexSize(gl, st, false, sampleCount);
+
+ fbo.use(gl, texA);
+ verticeFboAttr.enableBuffer(gl, true);
+ texCoordFboAttr.enableBuffer(gl, true);
+ indicesFbo.bindBuffer(gl, true); // keeps VBO binding
+
+ gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesFbo.getElementCount() * indicesFbo.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0);
+
+ indicesFbo.bindBuffer(gl, false);
+ texCoordFboAttr.enableBuffer(gl, false);
+ verticeFboAttr.enableBuffer(gl, false);
+ fbo.unuse(gl);
+
+ // setback: gl.glActiveTexture(currentActiveTextureEngine[0]);
+ }
+
+ private void renderRegion2FBO(final GL2ES2 gl, final RenderState rs, final int targetFboWidth, final int targetFboHeight, int sampleCount) {
+ final ShaderState st = rs.getShaderState();
+
+ if( 0 >= targetFboWidth || 0 >= targetFboHeight ) {
+ throw new IllegalArgumentException("fboSize must be greater than 0: "+targetFboWidth+"x"+targetFboHeight);
+ }
+
+ if(null == fbo) {
+ fboWidth = targetFboWidth;
+ fboHeight = targetFboHeight;
+ fbo = new FBObject();
+ fbo.reset(gl, fboWidth, fboHeight);
+ // Shall not use bilinear (GL_LINEAR), due to own VBAA. Result is smooth w/o it now!
+ // texA = fbo.attachTexture2D(gl, 0, true, GL2ES2.GL_LINEAR, GL2ES2.GL_LINEAR, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE);
+ texA = fbo.attachTexture2D(gl, 0, true, GL2ES2.GL_NEAREST, GL2ES2.GL_NEAREST, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE);
+ fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24);
+ if( DEBUG_FBO_1 ) {
+ System.err.printf("XXX.createFBO: %dx%d%n%s%n", fboWidth, fboHeight, fbo.toString());
+ }
+ } else if( targetFboWidth != fboWidth || targetFboHeight != fboHeight ) {
+ fbo.reset(gl, targetFboWidth, targetFboHeight);
+ fbo.bind(gl);
+ if( DEBUG_FBO_1 ) {
+ System.err.printf("XXX.resetFBO: %dx%d -> %dx%d%n%s%n", fboWidth, fboHeight, targetFboWidth, targetFboHeight, fbo );
+ }
+ fboWidth = targetFboWidth;
+ fboHeight = targetFboHeight;
+ } else {
+ fbo.bind(gl);
+ }
+ setTexSize(gl, st, true, sampleCount);
+
+ //render texture
+ gl.glViewport(0, 0, fboWidth, fboHeight);
+ st.uniform(gl, mgl_fboPMVMatrix); // use orthogonal matrix
+
+ gl.glClear(GL2ES2.GL_COLOR_BUFFER_BIT | GL2ES2.GL_DEPTH_BUFFER_BIT);
+ renderRegion(gl);
+ fbo.unbind(gl);
+
+ st.uniform(gl, rs.getPMVMatrix()); // switch back to real PMV matrix
+ }
+
+ private void renderRegion(final GL2ES2 gl) {
+ verticeTxtAttr.enableBuffer(gl, true);
+ texCoordTxtAttr.enableBuffer(gl, true);
+ indicesTxtBuffer.bindBuffer(gl, true); // keeps VBO binding
+
+ gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesTxtBuffer.getElementCount() * indicesTxtBuffer.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0);
+
+ indicesTxtBuffer.bindBuffer(gl, false);
+ texCoordTxtAttr.enableBuffer(gl, false);
+ verticeTxtAttr.enableBuffer(gl, false);
+ }
+
+ @Override
+ protected void destroyImpl(final GL2ES2 gl, final RegionRenderer renderer) {
+ if(DEBUG_INSTANCE) {
+ System.err.println("VBORegion2PES2 Destroy: " + this);
+ }
+ final ShaderState st = renderer.getShaderState();
+ if(null != fbo) {
+ fbo.destroy(gl);
+ fbo = null;
+ texA = null;
+ }
+ if(null != verticeTxtAttr) {
+ st.ownAttribute(verticeTxtAttr, false);
+ verticeTxtAttr.destroy(gl);
+ verticeTxtAttr = null;
+ }
+ if(null != texCoordTxtAttr) {
+ st.ownAttribute(texCoordTxtAttr, false);
+ texCoordTxtAttr.destroy(gl);
+ texCoordTxtAttr = null;
+ }
+ if(null != indicesTxtBuffer) {
+ indicesTxtBuffer.destroy(gl);
+ indicesTxtBuffer = null;
+ }
+ if(null != verticeFboAttr) {
+ st.ownAttribute(verticeFboAttr, false);
+ verticeFboAttr.destroy(gl);
+ verticeFboAttr = null;
+ }
+ if(null != texCoordFboAttr) {
+ st.ownAttribute(texCoordFboAttr, false);
+ texCoordFboAttr.destroy(gl);
+ texCoordFboAttr = null;
+ }
+ if(null != indicesFbo) {
+ indicesFbo.destroy(gl);
+ indicesFbo = null;
+ }
+ }
+}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
index 9feb18a12..bdf824b6a 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
@@ -33,118 +33,94 @@ import javax.media.opengl.GL2ES2;
import jogamp.graph.curve.opengl.shader.AttributeNames;
import com.jogamp.graph.curve.opengl.GLRegion;
-import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.geom.Vertex;
-import com.jogamp.graph.geom.Triangle;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.opengl.util.GLArrayDataServer;
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;
+ private boolean buffersAttached = false;
- protected VBORegionSPES2(int renderModes) {
+ public VBORegionSPES2(final int renderModes) {
super(renderModes);
+ final int initialElementCount = 256;
+ 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);
+
+ texCoordAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT,
+ false, initialElementCount, GL.GL_STATIC_DRAW);
}
@Override
- protected void update(GL2ES2 gl, RenderState rs) {
- if(!isDirty()) {
- return;
- }
+ protected final void clearImpl(final GL2ES2 gl, final RegionRenderer renderer) {
+ indicesBuffer.seal(gl, false);
+ indicesBuffer.rewind();
+ verticeAttr.seal(gl, false);
+ verticeAttr.rewind();
+ texCoordAttr.seal(gl, false);
+ texCoordAttr.rewind();
+ }
- if(null == indices) {
- final int initialElementCount = 256;
- final ShaderState st = rs.getShaderState();
+ @Override
+ protected final void pushVertex(float[] coords, float[] texParams) {
+ verticeAttr.putf(coords[0]);
+ verticeAttr.putf(coords[1]);
+ verticeAttr.putf(coords[2]);
- indices = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ texCoordAttr.putf(texParams[0]);
+ texCoordAttr.putf(texParams[1]);
+ }
- verticeAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT,
- false, initialElementCount, GL.GL_STATIC_DRAW);
- st.ownAttribute(verticeAttr, true);
+ @Override
+ protected final void pushIndex(int idx) {
+ indicesBuffer.puts((short)idx);
+ }
- texCoordAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT,
- false, initialElementCount, GL.GL_STATIC_DRAW);
+ @Override
+ protected void update(final GL2ES2 gl, final RegionRenderer renderer) {
+ if( !buffersAttached ) {
+ final ShaderState st = renderer.getShaderState();
+ st.ownAttribute(verticeAttr, true);
st.ownAttribute(texCoordAttr, true);
-
- if(DEBUG_INSTANCE) {
- System.err.println("VBORegionSPES2 Create: " + this);
- }
- }
-
- // process triangles
- indices.seal(gl, false);
- indices.rewind();
- for(int i=0; i<triangles.size(); i++) {
- final Triangle t = triangles.get(i);
- final Vertex[] t_vertices = t.getVertices();
-
- if(t_vertices[0].getId() == Integer.MAX_VALUE){
- t_vertices[0].setId(numVertices++);
- t_vertices[1].setId(numVertices++);
- t_vertices[2].setId(numVertices++);
-
- vertices.add(t_vertices[0]);
- vertices.add(t_vertices[1]);
- vertices.add(t_vertices[2]);
-
- indices.puts((short) t_vertices[0].getId());
- indices.puts((short) t_vertices[1].getId());
- indices.puts((short) t_vertices[2].getId());
- } else {
- indices.puts((short) t_vertices[0].getId());
- indices.puts((short) t_vertices[1].getId());
- indices.puts((short) t_vertices[2].getId());
- }
- }
- indices.seal(gl, true);
- indices.enableBuffer(gl, false);
-
- // process vertices and update bbox
- box.reset();
- verticeAttr.seal(gl, false);
- verticeAttr.rewind();
- texCoordAttr.seal(gl, false);
- texCoordAttr.rewind();
- for(int i=0; i<vertices.size(); i++) {
- final Vertex v = vertices.get(i);
- verticeAttr.putf(v.getX());
- verticeAttr.putf(v.getY());
- verticeAttr.putf(v.getZ());
- box.resize(v.getX(), v.getY(), v.getZ());
-
- final float[] tex = v.getTexCoord();
- texCoordAttr.putf(tex[0]);
- texCoordAttr.putf(tex[1]);
+ buffersAttached = true;
}
+ // seal buffers
+ indicesBuffer.seal(gl, true);
+ indicesBuffer.enableBuffer(gl, false);
verticeAttr.seal(gl, true);
verticeAttr.enableBuffer(gl, false);
texCoordAttr.seal(gl, true);
texCoordAttr.enableBuffer(gl, false);
-
- setDirty(false);
+ if(DEBUG_INSTANCE) {
+ System.err.println("VBORegionSPES2 idx "+indicesBuffer);
+ System.err.println("VBORegionSPES2 ver "+verticeAttr);
+ System.err.println("VBORegionSPES2 tex "+texCoordAttr);
+ }
}
@Override
- protected void drawImpl(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int[/*1*/] texWidth) {
+ protected void drawImpl(final GL2ES2 gl, final RegionRenderer renderer, final int[/*1*/] sampleCount) {
verticeAttr.enableBuffer(gl, true);
texCoordAttr.enableBuffer(gl, true);
- indices.bindBuffer(gl, true); // keeps VBO binding
+ indicesBuffer.bindBuffer(gl, true); // keeps VBO binding
- gl.glDrawElements(GL2ES2.GL_TRIANGLES, indices.getElementCount() * indices.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0);
+ gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0);
- indices.bindBuffer(gl, false);
+ indicesBuffer.bindBuffer(gl, false);
texCoordAttr.enableBuffer(gl, false);
verticeAttr.enableBuffer(gl, false);
}
@Override
- public final void destroy(GL2ES2 gl, RenderState rs) {
+ protected void destroyImpl(final GL2ES2 gl, final RegionRenderer renderer) {
if(DEBUG_INSTANCE) {
System.err.println("VBORegionSPES2 Destroy: " + this);
}
- final ShaderState st = rs.getShaderState();
+ final ShaderState st = renderer.getShaderState();
if(null != verticeAttr) {
st.ownAttribute(verticeAttr, false);
verticeAttr.destroy(gl);
@@ -155,9 +131,9 @@ public class VBORegionSPES2 extends GLRegion {
texCoordAttr.destroy(gl);
texCoordAttr = null;
}
- if(null != indices) {
- indices.destroy(gl);
- indices = null;
+ if(null != indicesBuffer) {
+ indicesBuffer.destroy(gl);
+ indicesBuffer = null;
}
}
}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass-weight.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass_norm-weight.fp
index 7643dab7b..940e95071 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass-weight.fp
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass_norm-weight.fp
@@ -14,21 +14,26 @@
#include uniforms.glsl
#include varyings.glsl
+const vec3 zero3 = vec3(0);
+
void main (void)
{
+ vec3 c;
+ float alpha;
+
vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y));
- vec3 c = gcu_ColorStatic.rgb;
-
- float alpha = 0.0;
-
- if((gcv_TexCoord.x == 0.0) && (gcv_TexCoord.y == 0.0)) {
+
+ if( gcv_TexCoord.x == 0.0 && gcv_TexCoord.y == 0.0 ) {
+ // pass-1: Lines
+ c = gcu_ColorStatic.rgb;
alpha = gcu_Alpha;
- }
- else if ((gcv_TexCoord.x > 0.0) && (rtex.y > 0.0 || rtex.x == 1.0)) {
+ } else if ( gcv_TexCoord.x > 0.0 && ( rtex.y > 0.0 || rtex.x == 1.0 ) ) {
+ // pass-1: curves
rtex.y -= 0.1;
if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) {
// discard; // freezes NV tegra2 compiler
+ c = zero3;
alpha = 0.0;
} else {
rtex.y = max(rtex.y, 0.0);
@@ -45,10 +50,12 @@ void main (void)
float gd = (aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0)*(aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0);
vec2 f = vec2((dtx.y - (w*dtx.x*(1.0 - 2.0*rtex.x))/gd), (dty.y - (w*dty.x*(1.0 - 2.0*rtex.x))/gd));
- // FIXME: will we ever set gcu_Alpha != 1.0 ? If not, a==alpha!
- float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
- alpha = gcu_Alpha * a;
+ c = gcu_ColorStatic.rgb;
+ alpha = gcu_Alpha * clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
}
+ } else {
+ c = zero3;
+ alpha = 0.0;
}
mgl_FragColor = vec4(c, alpha);
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass_norm.fp
index e12eef4b1..2175c1a31 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass.fp
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-1pass_norm.fp
@@ -14,21 +14,35 @@
#include uniforms.glsl
#include varyings.glsl
+const vec3 zero3 = vec3(0);
+
void main (void)
{
+ vec3 c;
+ float alpha;
+
+ /**
+ * CDTriangulator2D.extractBoundaryTriangles(..):
+ * 0 > gcv_TexCoord.y : hole or holeLike
+ * 0 < gcv_TexCoord.y : !hole (outer)
+ *
+ * 0 == gcv_TexCoord.x : vertex-0 of triangle
+ * 0.5 == gcv_TexCoord.x : vertex-1 of triangle
+ * 1 == gcv_TexCoord.x : vertex-2 of triangle
+ */
vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y));
- vec3 c = gcu_ColorStatic.rgb;
-
- float alpha = 0.0;
- if((gcv_TexCoord.x == 0.0) && (gcv_TexCoord.y == 0.0)) {
+ if( gcv_TexCoord.x == 0.0 && gcv_TexCoord.y == 0.0 ) {
+ // pass-1: Lines
+ c = gcu_ColorStatic.rgb;
alpha = gcu_Alpha;
- }
- else if ((gcv_TexCoord.x > 0.0) && (rtex.y > 0.0 || rtex.x == 1.0)) {
+ } else if ( gcv_TexCoord.x > 0.0 && ( rtex.y > 0.0 || rtex.x == 1.0 ) ) {
+ // pass-1: curves
rtex.y -= 0.1;
if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) {
// discard; // freezes NV tegra2 compiler
+ c = zero3;
alpha = 0.0;
} else {
rtex.y = max(rtex.y, 0.0);
@@ -39,11 +53,12 @@ void main (void)
vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x));
float position = rtex.y - (rtex.x * (1.0 - rtex.x));
- // FIXME: will we ever set gcu_Alpha != 1.0 ? If not, a==alpha!
- float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
- alpha = gcu_Alpha * a;
+ c = gcu_ColorStatic.rgb;
+ alpha = gcu_Alpha * clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
}
+ } else {
+ c = zero3;
+ alpha = 0.0;
}
-
mgl_FragColor = vec4(c, alpha);
}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass-weight.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass-weight.fp
deleted file mode 100644
index fb71abd14..000000000
--- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass-weight.fp
+++ /dev/null
@@ -1,97 +0,0 @@
-//Copyright 2010 JogAmp Community. All rights reserved.
-
-//
-// 2-pass shader w/ weight
-//
-
-#if __VERSION__ >= 130
- #define varying in
- out vec4 mgl_FragColor;
- #define texture2D texture
-#else
- #define mgl_FragColor gl_FragColor
-#endif
-
-#include uniforms.glsl
-#include varyings.glsl
-
-const vec4 tex_weights = vec4(0.075, 0.06, 0.045, 0.025);
-
-void main (void)
-{
- vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y));
- vec3 c = gcu_ColorStatic.rgb;
-
- float alpha = 0.0;
-
- if((gcv_TexCoord.x == 0.0) && (gcv_TexCoord.y == 0.0)) {
- alpha = gcu_Alpha;
- }
- else if((gcv_TexCoord.x >= 5.0)) {
- vec2 dfx = dFdx(gcv_TexCoord);
- vec2 dfy = dFdy(gcv_TexCoord);
-
- vec2 size = 1.0/gcu_TextureSize;
-
- rtex -= 5.0;
- vec4 t = texture2D(gcu_TextureUnit, rtex)* 0.18;
-
- t += texture2D(gcu_TextureUnit, rtex + size*(vec2(1, 0)))*tex_weights.x;
- t += texture2D(gcu_TextureUnit, rtex - size*(vec2(1, 0)))*tex_weights.x;
- t += texture2D(gcu_TextureUnit, rtex + size*(vec2(0, 1)))*tex_weights.x;
- t += texture2D(gcu_TextureUnit, rtex - size*(vec2(0, 1)))*tex_weights.x;
-
- t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(1, 0)))*tex_weights.y;
- t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(1, 0)))*tex_weights.y;
- t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(0, 1)))*tex_weights.y;
- t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(0, 1)))*tex_weights.y;
-
- t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(1, 0)))*tex_weights.z;
- t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(1, 0)))*tex_weights.z;
- t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(0, 1)))*tex_weights.z;
- t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(0, 1)))*tex_weights.z;
-
- t += texture2D(gcu_TextureUnit, rtex + 4.0*size*(vec2(1, 0)))*tex_weights.w;
- t += texture2D(gcu_TextureUnit, rtex - 4.0*size*(vec2(1, 0)))*tex_weights.w;
- t += texture2D(gcu_TextureUnit, rtex + 4.0*size*(vec2(0, 1)))*tex_weights.w;
- t += texture2D(gcu_TextureUnit, rtex - 4.0*size*(vec2(0, 1)))*tex_weights.w;
-
- #if 0
- if(t.w == 0.0) {
- discard; // discard freezes NV tegra2 compiler
- }
- #endif
-
- c = t.xyz;
- alpha = gcu_Alpha * t.w;
- }
- ///////////////////////////////////////////////////////////
- else if ((gcv_TexCoord.x > 0.0) && (rtex.y > 0.0 || rtex.x == 1.0)) {
- rtex.y -= 0.1;
-
- if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) {
- // discard; // freezes NV tegra2 compiler
- alpha = 0.0;
- } else {
- rtex.y = max(rtex.y, 0.0);
-
- vec2 dtx = dFdx(rtex);
- vec2 dty = dFdy(rtex);
-
- float w = gcu_Weight;
- float pd = ((2.0 - (2.0*w))*rtex.x*rtex.x) + 2.0*(w-1.0)*rtex.x + 1.0;
- float position = rtex.y - ((w*rtex.x*(1.0 - rtex.x))/pd);
-
- float aph = 2.0 - 2.0*w;
-
- float gd = (aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0)*(aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0);
- vec2 f = vec2((dtx.y - (w*dtx.x*(1.0 - 2.0*rtex.x))/gd), (dty.y - (w*dty.x*(1.0 - 2.0*rtex.x))/gd));
-
- // FIXME: will we ever set gcu_Alpha != 1.0 ? If not, a==alpha!
- float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
- alpha = gcu_Alpha * a;
- }
- }
-
- mgl_FragColor = vec4(c, alpha);
-}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass.fp
deleted file mode 100644
index 8e5600dd9..000000000
--- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass.fp
+++ /dev/null
@@ -1,91 +0,0 @@
-//Copyright 2010 JogAmp Community. All rights reserved.
-
-//
-// 2-pass shader w/o weight
-//
-
-#if __VERSION__ >= 130
- #define varying in
- out vec4 mgl_FragColor;
- #define texture2D texture
-#else
- #define mgl_FragColor gl_FragColor
-#endif
-
-#include uniforms.glsl
-#include varyings.glsl
-
-const vec4 tex_weights = vec4(0.075, 0.06, 0.045, 0.025);
-
-void main (void)
-{
- vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y));
- vec3 c = gcu_ColorStatic.rgb;
-
- float alpha = 0.0;
- float enable = 1.0;
-
- if((gcv_TexCoord.x == 0.0) && (gcv_TexCoord.y == 0.0)) {
- alpha = gcu_Alpha;
- }
- else if((gcv_TexCoord.x >= 5.0)) {
- vec2 dfx = dFdx(gcv_TexCoord);
- vec2 dfy = dFdy(gcv_TexCoord);
-
- vec2 size = 1.0/gcu_TextureSize;
-
- rtex -= 5.0;
- vec4 t = texture2D(gcu_TextureUnit, rtex)* 0.18;
-
- t += texture2D(gcu_TextureUnit, rtex + size*(vec2(1, 0)))*tex_weights.x;
- t += texture2D(gcu_TextureUnit, rtex - size*(vec2(1, 0)))*tex_weights.x;
- t += texture2D(gcu_TextureUnit, rtex + size*(vec2(0, 1)))*tex_weights.x;
- t += texture2D(gcu_TextureUnit, rtex - size*(vec2(0, 1)))*tex_weights.x;
-
- t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(1, 0)))*tex_weights.y;
- t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(1, 0)))*tex_weights.y;
- t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(0, 1)))*tex_weights.y;
- t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(0, 1)))*tex_weights.y;
-
- t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(1, 0)))*tex_weights.z;
- t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(1, 0)))*tex_weights.z;
- t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(0, 1)))*tex_weights.z;
- t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(0, 1)))*tex_weights.z;
-
- t += texture2D(gcu_TextureUnit, rtex + 4.0*size*(vec2(1, 0)))*tex_weights.w;
- t += texture2D(gcu_TextureUnit, rtex - 4.0*size*(vec2(1, 0)))*tex_weights.w;
- t += texture2D(gcu_TextureUnit, rtex + 4.0*size*(vec2(0, 1)))*tex_weights.w;
- t += texture2D(gcu_TextureUnit, rtex - 4.0*size*(vec2(0, 1)))*tex_weights.w;
-
- #if 0
- if(t.w == 0.0){
- discard; // discard freezes NV tegra2 compiler
- }
- #endif
-
- c = t.xyz;
- alpha = gcu_Alpha * t.w;
- }
- else if ((gcv_TexCoord.x > 0.0) && (rtex.y > 0.0 || rtex.x == 1.0)) {
- rtex.y -= 0.1;
-
- if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) {
- // discard; // freezes NV tegra2 compiler
- alpha = 0.0;
- } else {
- rtex.y = max(rtex.y, 0.0);
-
- vec2 dtx = dFdx(rtex);
- vec2 dty = dFdy(rtex);
-
- vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x));
- float position = rtex.y - (rtex.x * (1.0 - rtex.x));
-
- // FIXME: will we ever set gcu_Alpha != 1.0 ? If not, a==alpha!
- float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
- alpha = gcu_Alpha * a;
- }
- }
-
- mgl_FragColor = vec4(c, alpha);
-}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa-weight.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa-weight.fp
new file mode 100644
index 000000000..733669e64
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa-weight.fp
@@ -0,0 +1,76 @@
+//Copyright 2010 JogAmp Community. All rights reserved.
+
+//
+// 2-pass shader w/ weight
+//
+
+#if __VERSION__ >= 130
+ #define varying in
+ out vec4 mgl_FragColor;
+ #define texture2D texture
+#else
+ #define mgl_FragColor gl_FragColor
+#endif
+
+#include uniforms.glsl
+#include varyings.glsl
+
+const vec3 zero3 = vec3(0);
+
+void main (void)
+{
+ vec3 c;
+ float alpha;
+
+ if( 0 < gcu_TextureSize.z ) {
+ // Pass-2: Dump Texture
+ vec4 t = texture2D(gcu_TextureUnit, gcv_TexCoord);
+ #if 0
+ if( 0.0 == t.a ) {
+ discard; // discard freezes NV tegra2 compiler
+ }
+ #endif
+
+ c = t.rgb;
+ alpha = gcu_Alpha * t.a;
+ } else {
+ // Pass-1
+ vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y));
+
+ if( gcv_TexCoord.x == 0.0 && gcv_TexCoord.y == 0.0 ) {
+ // pass-1: Lines
+ c = gcu_ColorStatic.rgb;
+ alpha = 1.0;
+ } else if ( gcv_TexCoord.x > 0.0 && (rtex.y > 0.0 || rtex.x == 1.0) ) {
+ // pass-1: curves
+ rtex.y -= 0.1;
+
+ if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) {
+ // discard; // freezes NV tegra2 compiler
+ c = zero3;
+ alpha = 0.0;
+ } else {
+ rtex.y = max(rtex.y, 0.0);
+
+ vec2 dtx = dFdx(rtex);
+ vec2 dty = dFdy(rtex);
+
+ float w = gcu_Weight;
+ float pd = ((2.0 - (2.0*w))*rtex.x*rtex.x) + 2.0*(w-1.0)*rtex.x + 1.0;
+ float position = rtex.y - ((w*rtex.x*(1.0 - rtex.x))/pd);
+
+ float aph = 2.0 - 2.0*w;
+
+ float gd = (aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0)*(aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0);
+ vec2 f = vec2((dtx.y - (w*dtx.x*(1.0 - 2.0*rtex.x))/gd), (dty.y - (w*dty.x*(1.0 - 2.0*rtex.x))/gd));
+
+ c = gcu_ColorStatic.rgb;
+ alpha = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
+ }
+ } else {
+ c = zero3;
+ alpha = 0.0;
+ }
+ }
+ mgl_FragColor = vec4(c, alpha);
+}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa.fp
new file mode 100644
index 000000000..2536e251b
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_msaa.fp
@@ -0,0 +1,88 @@
+//Copyright 2010 JogAmp Community. All rights reserved.
+
+//
+// 2-pass shader w/o weight
+//
+
+#if __VERSION__ >= 130
+ #define varying in
+ out vec4 mgl_FragColor;
+ #define texture2D texture
+#else
+ #define mgl_FragColor gl_FragColor
+#endif
+
+#include uniforms.glsl
+#include varyings.glsl
+
+// #define PREALPHA 1
+
+const vec3 zero3 = vec3(0);
+
+void main (void)
+{
+ vec3 c;
+ float alpha;
+
+ if( 0 < gcu_TextureSize.z ) {
+ // Pass-2: Dump Texture
+ vec4 t = texture2D(gcu_TextureUnit, gcv_TexCoord);
+ #if 0
+ if( 0.0 == t.a ) {
+ discard; // discard freezes NV tegra2 compiler
+ }
+ #endif
+
+ c = t.rgb;
+ #ifdef PREALPHA
+ // alpha = mix(0.0, gcu_Alpha, t.a); // t.a one of [ 0.0, 1.0 ]
+ // ^^ for = 0.0 == t.a ? 0.0 : gcu_Alpha;
+ // mix(x, y, a) := x * ( 1 - a ) + y * a
+ alpha = gcu_Alpha;
+ #else
+ alpha = gcu_Alpha * t.a;
+ #endif
+ } else {
+ // Pass-1
+ vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y));
+
+ if( gcv_TexCoord.x == 0.0 && gcv_TexCoord.y == 0.0 ) {
+ // pass-1: Lines
+ c = gcu_ColorStatic.rgb;
+ alpha = 1.0;
+ } else if ( gcv_TexCoord.x > 0.0 && (rtex.y > 0.0 || rtex.x == 1.0) ) {
+ // pass-1: curves
+ rtex.y -= 0.1;
+
+ if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) {
+ // discard; // freezes NV tegra2 compiler
+ c = zero3;
+ alpha = 0.0;
+ } else {
+ rtex.y = max(rtex.y, 0.0);
+
+ vec2 dtx = dFdx(rtex);
+ vec2 dty = dFdy(rtex);
+
+ vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x));
+ float position = rtex.y - (rtex.x * (1.0 - rtex.x));
+
+ #ifdef PREALPHA
+ float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
+ c = gcu_ColorStatic.rgb * a;
+ alpha = mix(1.0, 0.0, step(a, 0.0));
+ // ^^ = 0.0 < a ? 1.0 : 0.0;
+ // step(e, x) := e > x ? 0.0 : 1.0
+ // mix(x, y, a) := x * ( 1 - a ) + y * a
+ #else
+ c = gcu_ColorStatic.rgb;
+ alpha = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
+ #endif
+ }
+ } else {
+ c = zero3;
+ alpha = 0.0;
+ }
+ }
+ mgl_FragColor = vec4(c, alpha);
+}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa-weight.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa-weight.fp
new file mode 100644
index 000000000..3b1b55c87
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa-weight.fp
@@ -0,0 +1,109 @@
+//Copyright 2010 JogAmp Community. All rights reserved.
+
+//
+// 2-pass shader w/ weight
+//
+
+#if __VERSION__ >= 130
+ #define varying in
+ out vec4 mgl_FragColor;
+ #define texture2D texture
+#else
+ #define mgl_FragColor gl_FragColor
+#endif
+
+#include uniforms.glsl
+#include varyings.glsl
+
+const vec3 zero3 = vec3(0);
+
+void main (void)
+{
+ vec3 c;
+ float alpha;
+
+ if( 0 < gcu_TextureSize.z ) {
+ // Pass-2: AA on Texture
+ // Note: gcv_TexCoord is in center of sample pixels.
+
+ float sampleCount = gcu_TextureSize.z;
+ vec2 psize = 1.0 / gcu_TextureSize.xy; // pixel size
+
+ float sample_weight = 1 / ( 2 * sampleCount );
+ // float sample_weight = 1 / ( 2 * sampleCount + 1 );
+
+ vec4 t = vec4(0);
+ // vec4 t = texture2D(gcu_TextureUnit, gcv_TexCoord)* sample_weight; // center: +1
+
+ // SampleCount 2
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-0.5, -0.5)))*sample_weight; // NW
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-0.5, 0.5)))*sample_weight; // SW
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 0.5, 0.5)))*sample_weight; // SE
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 0.5, -0.5)))*sample_weight; // NE
+ if( sampleCount > 2 ) {
+ // SampleCount 4
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-1.5, -1.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-1.5, 1.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 1.5, 1.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 1.5, -1.5)))*sample_weight;
+ if( sampleCount > 4 ) {
+ // SampleCount 8
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-2.5, -2.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-2.5, 2.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 2.5, 2.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 2.5, -2.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-3.5, -3.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-3.5, 3.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 3.5, 3.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 3.5, -3.5)))*sample_weight;
+ }
+ }
+ #if 0
+ if(t.w == 0.0){
+ discard; // discard freezes NV tegra2 compiler
+ }
+ #endif
+
+ c = t.rgb;
+ alpha = gcu_Alpha * t.a;
+ } else {
+ // pass-1
+ vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y));
+
+ if((gcv_TexCoord.x == 0.0) && (gcv_TexCoord.y == 0.0)) {
+ // pass-1: Lines
+ c = gcu_ColorStatic.rgb;
+ alpha = 1.0;
+ } else if ( gcv_TexCoord.x > 0.0 && (rtex.y > 0.0 || rtex.x == 1.0) ) {
+ // pass-1: curves
+ rtex.y -= 0.1;
+
+ if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) {
+ // discard; // freezes NV tegra2 compiler
+ c = zero3;
+ alpha = 0.0;
+ } else {
+ rtex.y = max(rtex.y, 0.0);
+
+ vec2 dtx = dFdx(rtex);
+ vec2 dty = dFdy(rtex);
+
+ float w = gcu_Weight;
+ float pd = ((2.0 - (2.0*w))*rtex.x*rtex.x) + 2.0*(w-1.0)*rtex.x + 1.0;
+ float position = rtex.y - ((w*rtex.x*(1.0 - rtex.x))/pd);
+
+ float aph = 2.0 - 2.0*w;
+
+ float gd = (aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0)*(aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0);
+ vec2 f = vec2((dtx.y - (w*dtx.x*(1.0 - 2.0*rtex.x))/gd), (dty.y - (w*dty.x*(1.0 - 2.0*rtex.x))/gd));
+
+ c = gcu_ColorStatic.rgb;
+ alpha = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
+ }
+ } else {
+ c = zero3;
+ alpha = 0.0;
+ }
+ }
+ mgl_FragColor = vec4(c, alpha);
+}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa.fp
new file mode 100644
index 000000000..8237fa55b
--- /dev/null
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-2pass_vbaa.fp
@@ -0,0 +1,103 @@
+//Copyright 2010 JogAmp Community. All rights reserved.
+
+//
+// 2-pass shader w/o weight
+//
+
+#if __VERSION__ >= 130
+ #define varying in
+ out vec4 mgl_FragColor;
+ #define texture2D texture
+#else
+ #define mgl_FragColor gl_FragColor
+#endif
+
+#include uniforms.glsl
+#include varyings.glsl
+
+const vec3 zero3 = vec3(0);
+
+void main (void)
+{
+ vec3 c;
+ float alpha;
+
+ if( 0 < gcu_TextureSize.z ) {
+ // Pass-2: AA on Texture
+ // Note: gcv_TexCoord is in center of sample pixels.
+
+ float sampleCount = gcu_TextureSize.z;
+ vec2 psize = 1.0 / gcu_TextureSize.xy; // pixel size
+
+ float sample_weight = 1 / ( 2 * sampleCount );
+ // float sample_weight = 1 / ( 2 * sampleCount + 1 );
+
+ vec4 t = vec4(0);
+ // vec4 t = texture2D(gcu_TextureUnit, gcv_TexCoord)* sample_weight; // center: +1
+
+ // SampleCount 2
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-0.5, -0.5)))*sample_weight; // NW
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-0.5, 0.5)))*sample_weight; // SW
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 0.5, 0.5)))*sample_weight; // SE
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 0.5, -0.5)))*sample_weight; // NE
+ if( sampleCount > 2 ) {
+ // SampleCount 4
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-1.5, -1.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-1.5, 1.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 1.5, 1.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 1.5, -1.5)))*sample_weight;
+ if( sampleCount > 4 ) {
+ // SampleCount 8
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-2.5, -2.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-2.5, 2.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 2.5, 2.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 2.5, -2.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-3.5, -3.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2(-3.5, 3.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 3.5, 3.5)))*sample_weight;
+ t += texture2D(gcu_TextureUnit, gcv_TexCoord + psize*(vec2( 3.5, -3.5)))*sample_weight;
+ }
+ }
+ #if 0
+ if(t.w == 0.0){
+ discard; // discard freezes NV tegra2 compiler
+ }
+ #endif
+
+ c = t.rgb;
+ alpha = gcu_Alpha * t.a;
+ } else {
+ // pass-1
+ vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y));
+
+ if( gcv_TexCoord.x == 0.0 && gcv_TexCoord.y == 0.0 ) {
+ // pass-1: Lines
+ c = gcu_ColorStatic.rgb;
+ alpha = 1.0;
+ } else if ( gcv_TexCoord.x > 0.0 && (rtex.y > 0.0 || rtex.x == 1.0) ) {
+ // pass-1: curves
+ rtex.y -= 0.1;
+
+ if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) {
+ // discard; // freezes NV tegra2 compiler
+ c = zero3;
+ alpha = 0.0;
+ } else {
+ rtex.y = max(rtex.y, 0.0);
+
+ vec2 dtx = dFdx(rtex);
+ vec2 dty = dFdy(rtex);
+
+ vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x));
+ float position = rtex.y - (rtex.x * (1.0 - rtex.x));
+
+ c = gcu_ColorStatic.rgb;
+ alpha = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
+ }
+ } else {
+ c = zero3;
+ alpha = 0.0;
+ }
+ }
+ mgl_FragColor = vec4(c, alpha);
+}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl
index 5bbd5de14..92e78d5de 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl
@@ -6,11 +6,10 @@ uniform mat4 gcu_PMVMatrix[3]; // P, Mv, and Mvi
uniform vec3 gcu_ColorStatic;
uniform float gcu_Alpha;
uniform float gcu_Weight;
-uniform sampler2D gcu_TextureUnit;
+uniform sampler2D gcu_TextureUnit;
-// #if __VERSION__ < 130
-uniform vec2 gcu_TextureSize;
-// #endif
+/** 3rd component: 0: pass-1, >0: pass-2, sampleCount */
+uniform vec3 gcu_TextureSize;
// const int MAX_TEXTURE_UNITS = 8; // <= gl_MaxTextureImageUnits
// const int MAX_LIGHTS = 8;
diff --git a/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java b/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java
index a60f91b87..35263407d 100644
--- a/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java
+++ b/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java
@@ -29,7 +29,7 @@
package jogamp.graph.curve.tess;
import java.util.ArrayList;
-
+import java.util.List;
import com.jogamp.graph.curve.tess.Triangulator;
import com.jogamp.graph.geom.Outline;
@@ -44,15 +44,12 @@ import jogamp.opengl.Debug;
* Closed Regions with optional n holes.
*
*/
-public class CDTriangulator2D implements Triangulator{
+public class CDTriangulator2D implements Triangulator {
protected static final boolean DEBUG = Debug.debug("Triangulation");
- private float sharpness = 0.5f;
- private ArrayList<Loop> loops;
- private ArrayList<Vertex> vertices;
+ private final ArrayList<Loop> loops = new ArrayList<Loop>();
- private ArrayList<Triangle> triangles;
private int maxTriID = 0;
@@ -62,19 +59,14 @@ public class CDTriangulator2D implements Triangulator{
reset();
}
- /** Reset the triangulation to initial state
- * Clearing cached data
- */
@Override
- public void reset() {
+ public final void reset() {
maxTriID = 0;
- vertices = new ArrayList<Vertex>();
- triangles = new ArrayList<Triangle>(3);
- loops = new ArrayList<Loop>();
+ loops.clear();
}
@Override
- public void addCurve(Outline polyline) {
+ public final void addCurve(final List<Triangle> sink, final Outline polyline, final float sharpness) {
Loop loop = null;
if(!loops.isEmpty()) {
@@ -82,27 +74,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, sharpness);
+ // 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, sharpness);
+ // vertices.addAll(innerPoly.getVertices());
loop.addConstraintCurve(innerPoly);
}
}
@Override
- public ArrayList<Triangle> generate() {
+ public final void generate(List<Triangle> sink) {
for(int i=0;i<loops.size();i++) {
- Loop loop = loops.get(i);
+ final Loop loop = loops.get(i);
int numTries = 0;
int size = loop.computeLoopSize();
while(!loop.isSimplex()){
- Triangle tri = null;
+ final Triangle tri;
if(numTries > size){
tri = loop.cut(false);
}
@@ -115,7 +107,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,27 +119,27 @@ public class CDTriangulator2D implements Triangulator{
break;
}
}
- Triangle tri = loop.cut(true);
- if(tri != null)
- triangles.add(tri);
+ final Triangle tri = loop.cut(true);
+ if(tri != null) {
+ sink.add(tri);
+ }
}
- return triangles;
}
- private GraphOutline extractBoundaryTriangles(GraphOutline outline, boolean hole) {
- GraphOutline innerOutline = new GraphOutline();
- ArrayList<GraphVertex> outVertices = outline.getGraphPoint();
- int size = outVertices.size();
+ private GraphOutline extractBoundaryTriangles(final List<Triangle> sink, final GraphOutline outline, final boolean hole, final float sharpness) {
+ final GraphOutline innerOutline = new GraphOutline();
+ final ArrayList<GraphVertex> outVertices = outline.getGraphPoint();
+ final int size = outVertices.size();
for(int i=0; i < size; i++) {
- GraphVertex currentVertex = outVertices.get(i);
- GraphVertex gv0 = outVertices.get((i+size-1)%size);
- GraphVertex gv2 = outVertices.get((i+1)%size);
- GraphVertex gv1 = currentVertex;
+ final GraphVertex currentVertex = outVertices.get(i);
+ final GraphVertex gv0 = outVertices.get((i+size-1)%size);
+ final GraphVertex gv2 = outVertices.get((i+1)%size);
+ final GraphVertex gv1 = currentVertex;
- if(!currentVertex.getPoint().isOnCurve()) {
- Vertex v0 = gv0.getPoint().clone();
- Vertex v2 = gv2.getPoint().clone();
- Vertex v1 = gv1.getPoint().clone();
+ if( !currentVertex.getPoint().isOnCurve() ) {
+ final Vertex v0 = gv0.getPoint().clone();
+ final Vertex v2 = gv2.getPoint().clone();
+ final Vertex v1 = gv1.getPoint().clone();
gv0.setBoundaryContained(true);
gv1.setBoundaryContained(true);
@@ -163,23 +155,22 @@ 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);
}
if( hole || holeLike ) {
v0.setTexCoord(0, -0.1f);
v2.setTexCoord(1, -0.1f);
- v1.setTexCoord(0.5f, -1*sharpness -0.1f);
+ v1.setTexCoord(0.5f, -1*sharpness-0.1f);
innerOutline.addVertex(currentVertex);
} else {
v0.setTexCoord(0, 0.1f);
v2.setTexCoord(1, 0.1f);
v1.setTexCoord(0.5f, sharpness+0.1f);
}
- }
- else {
- if(!gv2.getPoint().isOnCurve() || !gv0.getPoint().isOnCurve()){
+ } else {
+ if( !gv2.getPoint().isOnCurve() || !gv0.getPoint().isOnCurve() ) {
currentVertex.setBoundaryContained(true);
}
innerOutline.addVertex(currentVertex);
@@ -189,16 +180,13 @@ public class CDTriangulator2D implements Triangulator{
}
private Loop getContainerLoop(Outline polyline) {
- ArrayList<Vertex> vertices = polyline.getVertices();
+ final ArrayList<Vertex> vertices = polyline.getVertices();
for(int i=0; i < loops.size(); i++) {
- Loop loop = loops.get(i);
- boolean inside = false;
+ final Loop loop = loops.get(i);
for(int j=0; j < vertices.size(); j++) {
- Vertex v = vertices.get(j);
- inside |= loop.checkInside(v);
- }
- if(inside) {
- return loop;
+ if( loop.checkInside( vertices.get(j) ) ) {
+ return loop;
+ }
}
}
return null;
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 ff46c3338..000000000
--- a/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java
+++ /dev/null
@@ -1,99 +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.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 OutlineShape shape = null;
-
- /** Create a new Glyph shape
- * based on Parametric curve control polyline
- */
- public GlyphShape(Vertex.Factory<? extends Vertex> factory){
- shape = new OutlineShape(factory);
- }
-
- /** 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, OutlineShape shape){
- this(factory);
- this.shape = shape;
- this.shape.transformOutlines(OutlineShape.VerticesState.QUADRATIC_NURBS);
- }
-
- public final Vertex.Factory<? extends Vertex> vertexFactory() { return shape.vertexFactory(); }
-
- public OutlineShape getShape() {
- return shape;
- }
-
- public int getNumVertices() {
- return shape.getVertices().size();
- }
-
- /** Get the rotational Quaternion attached to this Shape
- * @return the Quaternion Object
- */
- public Quaternion getQuat() {
- return quat;
- }
-
- /** Set the Quaternion that shall defien the rotation
- * of this shape.
- * @param quat
- */
- public void setQuat(Quaternion quat) {
- this.quat = quat;
- }
-
- /** Triangluate the glyph shape
- * @return ArrayList of triangles which define this shape
- */
- public ArrayList<Triangle> triangulate(){
- return shape.triangulate();
- }
-
- /** Get the list of Vertices of this Object
- * @return arrayList of Vertices
- */
- public ArrayList<Vertex> 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 2284ab669..000000000
--- a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java
+++ /dev/null
@@ -1,213 +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;
-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.font.FontInt;
-
-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;
-
-public class GlyphString {
- /** Static font size for all default font OutlineShape generations via {@link #createString(OutlineShape, Factory, Font, String)}.
- * <p>The actual font size shall be accomplished by the GL PMV matrix.</p>
- */
- public static final int STATIC_FONT_SIZE = 10;
-
- private ArrayList<GlyphShape> glyphs = new ArrayList<GlyphShape>();
- private CharSequence str;
- private String fontname;
- private GLRegion region;
-
- private SVertex origin = new SVertex();
-
- /**
- * <p>Uses {@link #STATIC_FONT_SIZE}.</p>
- * <p>No caching is performed.</p>
- *
- * @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);
- }
-
- /**
- * <p>No caching is performed.</p>
- *
- * @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, String str) {
- ArrayList<OutlineShape> shapes = ((FontInt)font).getOutlineShapes(str, fontSize, vertexFactory);
-
- GlyphString glyphString = new GlyphString(font.getName(Font.NAME_UNIQUNAME), str);
- glyphString.createfromOutlineShapes(vertexFactory, shapes);
- if(null != shape) {
- for(int i=0; i<glyphString.glyphs.size(); i++) {
- shape.addOutlineShape(glyphString.glyphs.get(i).getShape());
- }
- }
- return glyphString;
- }
-
- /** Create a new GlyphString object
- * @param fontname the name of the font that this String is
- * associated with
- * @param str the string object
- */
- public GlyphString(String fontname, CharSequence str){
- this.fontname = fontname;
- this.str = str;
- }
-
- public void addGlyphShape(GlyphShape glyph){
- glyphs.add(glyph);
- }
-
- public CharSequence getString(){
- return str;
- }
-
- /**Creates the Curve based Glyphs from a list of {@link OutlineShape}
- * @param vertexFactory vertex impl factory {@link Factory}
- * @param shapes list of {@link OutlineShape}
- */
- public void createfromOutlineShapes(Factory<? extends Vertex> vertexFactory, ArrayList<OutlineShape> shapes) {
- final int numGlyps = shapes.size();
- for (int index=0;index<numGlyps;index++){
- if(shapes.get(index) == null){
- continue;
- }
- GlyphShape glyphShape = new GlyphShape(vertexFactory, shapes.get(index));
-
- if(glyphShape.getNumVertices() < 3) {
- continue;
- }
- addGlyphShape(glyphShape);
- }
- }
-
-
- /** Generate a OGL Region to represent this Object.
- * @param gl the current gl object
- * @param rs the current attached RenderState
- * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#VBAA_RENDERING_BIT}
- */
- public GLRegion createRegion(GL2ES2 gl, int renderModes){
- region = RegionFactory.create(renderModes);
- // region.setFlipped(true);
-
- int numVertices = region.getNumVertices();
-
- for(int i=0; i< glyphs.size(); i++) {
- final GlyphShape glyph = glyphs.get(i);
- ArrayList<Triangle> gtris = glyph.triangulate();
- region.addTriangles(gtris);
-
- final ArrayList<Vertex> gVertices = glyph.getVertices();
- for(int j=0; j<gVertices.size(); j++) {
- final Vertex gVert = gVertices.get(j);
- gVert.setId(numVertices++);
- region.addVertex(gVert);
- }
- }
- return region;
- }
-
- /** Generate a Hashcode for this object
- * @return a string defining the hashcode
- */
- public String getTextHashCode(){
- return "" + fontname.hashCode() + str.hashCode();
- }
-
- /** Render the Object based using the associated Region
- * previously generated.
- */
- public void renderString3D(GL2ES2 gl) {
- region.draw(gl, null, 0, 0, null);
- }
- /** Render the Object based using the associated Region
- * previously generated.
- * @param matrix current {@link PMVMatrix}.
- * @param rs the RenderState to be used
- * @param vp_width current screen width
- * @param vp_height current screen height
- * @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.
- */
- public void renderString3D(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int[/*1*/] texWidth) {
- region.draw(gl, rs, vp_width, vp_height, texWidth);
- }
-
- /** Get the Origin of this GlyphString
- * @return
- */
- public Vertex getOrigin() {
- return origin;
- }
-
- /** Destroy the associated OGL objects
- * @param rs the current attached RenderState
- */
- public void destroy(GL2ES2 gl, RenderState rs) {
- if(null != gl && null != rs) {
- region.destroy(gl, rs);
- region = null;
- } else if(null != region) {
- throw new InternalError("destroy called w/o GL context, but has a region");
- }
- glyphs.clear();
- }
-
- public AABBox getBounds(){
- return region.getBounds();
- }
-}
diff --git a/src/jogl/classes/jogamp/graph/font/FontInt.java b/src/jogl/classes/jogamp/graph/font/FontInt.java
deleted file mode 100644
index 4366724ad..000000000
--- a/src/jogl/classes/jogamp/graph/font/FontInt.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * Copyright 2011 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.font;
-
-import java.util.ArrayList;
-
-import jogamp.graph.geom.plane.Path2D;
-
-import com.jogamp.graph.curve.OutlineShape;
-import com.jogamp.graph.font.Font;
-import com.jogamp.graph.geom.Vertex;
-import com.jogamp.graph.geom.Vertex.Factory;
-
-public interface FontInt extends Font {
-
- public interface GlyphInt extends Font.Glyph {
- public Path2D getPath(); // unscaled path
- public Path2D getPath(float pixelSize);
- }
-
- public ArrayList<OutlineShape> getOutlineShapes(CharSequence string, float pixelSize, Factory<? extends Vertex> vertexFactory);
-}
diff --git a/src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java b/src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java
index e1e44c92c..c7efe143b 100644
--- a/src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java
+++ b/src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java
@@ -38,9 +38,7 @@ import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontSet;
import com.jogamp.graph.font.FontFactory;
-import java.net.MalformedURLException;
import java.net.URI;
-import java.net.URISyntaxException;
import java.net.URLConnection;
import java.security.AccessController;
import java.security.PrivilegedAction;
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
index 67ae6c387..3cd9ab7c1 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
@@ -27,9 +27,6 @@
*/
package jogamp.graph.font.typecast;
-import java.util.ArrayList;
-
-import jogamp.graph.font.FontInt;
import jogamp.graph.font.typecast.ot.OTFont;
import jogamp.graph.font.typecast.ot.OTFontCollection;
import jogamp.graph.font.typecast.ot.table.CmapFormat;
@@ -37,32 +34,30 @@ import jogamp.graph.font.typecast.ot.table.CmapIndexEntry;
import jogamp.graph.font.typecast.ot.table.CmapTable;
import jogamp.graph.font.typecast.ot.table.HdmxTable;
import jogamp.graph.font.typecast.ot.table.ID;
-import jogamp.graph.geom.plane.AffineTransform;
-import jogamp.graph.geom.plane.Path2D;
import com.jogamp.common.util.IntObjectHashMap;
import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontFactory;
-import com.jogamp.graph.font.Font.Glyph;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.graph.geom.Vertex;
-import com.jogamp.graph.geom.Vertex.Factory;
import com.jogamp.opengl.math.geom.AABBox;
-class TypecastFont implements FontInt {
+class TypecastFont implements Font {
static final boolean DEBUG = false;
+ private static final Vertex.Factory<SVertex> vertexFactory = SVertex.factory();
- final OTFontCollection fontset;
- final OTFont font;
- TypecastHMetrics metrics;
- final CmapFormat cmapFormat;
- int cmapentries;
-
+ // private final OTFontCollection fontset;
+ /* pp */ final OTFont font;
+ private final CmapFormat cmapFormat;
+ private final int cmapentries;
+ private final IntObjectHashMap char2Glyph;
+ private final TypecastHMetrics metrics;
+ private final float[] tmpV3 = new float[3];
// FIXME: Add cache size to limit memory usage ??
- IntObjectHashMap char2Glyph;
- public TypecastFont(OTFontCollection fontset) {
- this.fontset = fontset;
+ public TypecastFont(final OTFontCollection fontset) {
+ // this.fontset = fontset;
this.font = fontset.getFont(0);
// FIXME: Generic attempt to find the best CmapTable,
@@ -124,10 +119,13 @@ class TypecastFont implements FontInt {
}
}
- cmapentries = 0;
- for (int i = 0; i < cmapFormat.getRangeCount(); ++i) {
- CmapFormat.Range range = cmapFormat.getRange(i);
- cmapentries += range.getEndCode() - range.getStartCode() + 1; // end included
+ {
+ int _cmapentries = 0;
+ for (int i = 0; i < cmapFormat.getRangeCount(); ++i) {
+ CmapFormat.Range range = cmapFormat.getRange(i);
+ _cmapentries += range.getEndCode() - range.getStartCode() + 1; // end included
+ }
+ cmapentries = _cmapentries;
}
if(DEBUG) {
System.err.println("font direction hint: "+font.getHeadTable().getFontDirectionHint());
@@ -140,12 +138,13 @@ class TypecastFont implements FontInt {
for (int j = range.getStartCode(); j <= range.getEndCode(); ++j) {
final int code = cmapFormat.mapCharCode(j);
if(code < 15) {
- System.err.println(" char: " + (int)j + " ( " + (char)j +" ) -> " + code);
+ System.err.println(" char: " + j + " ( " + (char)j +" ) -> " + code);
}
}
}
}
char2Glyph = new IntObjectHashMap(cmapentries + cmapentries/4);
+ metrics = new TypecastHMetrics(this);
}
@Override
@@ -168,15 +167,12 @@ class TypecastFont implements FontInt {
}
@Override
- public float getAdvanceWidth(int i, float pixelSize) {
- return font.getHmtxTable().getAdvanceWidth(i) * metrics.getScale(pixelSize);
+ public float getAdvanceWidth(int glyphID, float pixelSize) {
+ return font.getHmtxTable().getAdvanceWidth(glyphID) * metrics.getScale(pixelSize);
}
@Override
- public Metrics getMetrics() {
- if (metrics == null) {
- metrics = new TypecastHMetrics(this);
- }
+ public final Metrics getMetrics() {
return metrics;
}
@@ -202,10 +198,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(symbol, glyph, vertexFactory);
+ result = new TypecastGlyph(this, symbol, code, glyph.getBBox(), glyph.getAdvanceWidth(), shape);
if(DEBUG) {
- System.err.println("New glyph: " + (int)symbol + " ( " + (char)symbol +" ) -> " + code + ", contours " + glyph.getPointCount() + ": " + path);
+ System.err.println("New glyph: " + (int)symbol + " ( " + symbol +" ) -> " + code + ", contours " + glyph.getPointCount() + ": " + shape);
}
final HdmxTable hdmx = font.getHdmxTable();
if (null!= result && null != hdmx) {
@@ -227,18 +223,26 @@ class TypecastFont implements FontInt {
}
@Override
- public ArrayList<OutlineShape> getOutlineShapes(CharSequence string, float pixelSize, Factory<? extends Vertex> vertexFactory) {
- AffineTransform transform = new AffineTransform(vertexFactory);
- return TypecastRenderer.getOutlineShapes(this, string, pixelSize, transform, vertexFactory);
+ public final float getPixelSize(float fontSize /* points per inch */, float resolution) {
+ return fontSize * resolution / ( 72 /* points per inch */ );
+ }
+
+ @Override
+ public float getLineHeight(float pixelSize) {
+ final Metrics metrics = getMetrics();
+ final float lineGap = metrics.getLineGap(pixelSize) ; // negative value!
+ final float ascent = metrics.getAscent(pixelSize) ; // negative value!
+ final float descent = metrics.getDescent(pixelSize) ; // positive value!
+ final float advanceY = lineGap - descent + ascent; // negative value!
+ return -advanceY;
}
@Override
public float getStringWidth(CharSequence string, float pixelSize) {
float width = 0;
final int len = string.length();
- for (int i=0; i< len; i++)
- {
- char character = string.charAt(i);
+ for (int i=0; i< len; i++) {
+ final char character = string.charAt(i);
if (character == '\n') {
width = 0;
} else {
@@ -246,7 +250,6 @@ class TypecastFont implements FontInt {
width += glyph.getAdvance(pixelSize, false);
}
}
-
return (int)(width + 0.5f);
}
@@ -254,13 +257,11 @@ class TypecastFont implements FontInt {
public float getStringHeight(CharSequence string, float pixelSize) {
int height = 0;
- for (int i=0; i<string.length(); i++)
- {
- char character = string.charAt(i);
- if (character != ' ')
- {
- Glyph glyph = getGlyph(character);
- AABBox bbox = glyph.getBBox(pixelSize);
+ for (int i=0; i<string.length(); i++) {
+ final char character = string.charAt(i);
+ if (character != ' ') {
+ final Glyph glyph = getGlyph(character);
+ AABBox bbox = glyph.getBBox(pixelSize, tmpV3);
height = (int)Math.ceil(Math.max(bbox.getHeight(), height));
}
}
@@ -272,11 +273,8 @@ class TypecastFont implements FontInt {
if (string == null) {
return new AABBox();
}
- final Metrics metrics = 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 lineHeight = getLineHeight(pixelSize);
+
float totalHeight = 0;
float totalWidth = 0;
float curLineWidth = 0;
@@ -285,14 +283,14 @@ class TypecastFont implements FontInt {
if (character == '\n') {
totalWidth = Math.max(curLineWidth, totalWidth);
curLineWidth = 0;
- totalHeight -= advanceY;
+ totalHeight += lineHeight;
continue;
}
Glyph glyph = getGlyph(character);
curLineWidth += glyph.getAdvance(pixelSize, true);
}
if (curLineWidth > 0) {
- totalHeight -= advanceY;
+ totalHeight += lineHeight;
totalWidth = Math.max(curLineWidth, totalWidth);
}
return new AABBox(0, 0, 0, totalWidth, totalHeight,0);
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java
index 574aeb86d..b0e283278 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java
@@ -29,18 +29,15 @@ package jogamp.graph.font.typecast;
import java.util.HashMap;
-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;
-public class TypecastGlyph implements FontInt.GlyphInt {
+public class TypecastGlyph implements Font.Glyph {
public class Advance
{
- final Font font;
- final float advance;
+ private final Font font;
+ private final float advance;
HashMap<Float, Float> size2advance = new HashMap<Float, Float>();
public Advance(Font font, float advance)
@@ -65,7 +62,7 @@ public class TypecastGlyph implements FontInt.GlyphInt {
public float get(float size, boolean useFrationalMetrics)
{
- Float fo = size2advance.get(size);
+ final Float fo = size2advance.get(size);
if(null == fo) {
float value = (this.advance * getScale(size));
if (useFrationalMetrics == false) {
@@ -90,8 +87,8 @@ public class TypecastGlyph implements FontInt.GlyphInt {
public class Metrics
{
- AABBox bbox;
- Advance advance;
+ private final AABBox bbox;
+ private final Advance advance;
public Metrics(Font font, AABBox bbox, float advance)
{
@@ -136,105 +133,86 @@ public class TypecastGlyph implements FontInt.GlyphInt {
public static final short MAX_ID = (short)((1 << 16) - 2);
private final Font font;
+ private final char symbol;
+ private final OutlineShape shape; // in EM units
+ private final short id;
+ private final int advance;
+ private final Metrics metrics;
- char symbol;
- short id;
- int advance;
- Metrics metrics;
-
- protected Path2D path; // in EM units
- protected Path2D pathSized;
- protected float numberSized;
-
- protected TypecastGlyph(Font font, char symbol) {
- this.font = font;
- this.symbol = symbol;
- }
-
- protected TypecastGlyph(Font font,
- char symbol, short id, AABBox bbox, int advance, Path2D path) {
+ protected TypecastGlyph(Font font, char symbol, short id, AABBox bbox, int advance, OutlineShape shape) {
this.font = font;
this.symbol = symbol;
- this.advance = advance;
-
- init(id, bbox, advance);
-
- this.path = path;
- this.pathSized = null;
- this.numberSized = 0.0f;
- }
-
- void init(short id, AABBox bbox, int advance) {
+ this.shape = shape;
this.id = id;
this.advance = advance;
this.metrics = new Metrics(this.font, bbox, this.advance);
}
+ /**
public void reset(Path2D path) {
this.path = path;
this.metrics.reset();
- }
+ } */
@Override
- public Font getFont() {
+ public final Font getFont() {
return this.font;
}
@Override
- public char getSymbol() {
+ public final char getSymbol() {
return this.symbol;
}
- AABBox getBBoxUnsized() {
+ final AABBox getBBoxUnsized() {
return this.metrics.getBBox();
}
- public AABBox getBBox() {
+ @Override
+ public final AABBox getBBox() {
return this.metrics.getBBox();
}
- public Metrics getMetrics() {
+ public final Metrics getMetrics() {
return this.metrics;
}
- public short getID() {
+ @Override
+ public final short getID() {
return this.id;
}
- public float getScale(float pixelSize) {
+ @Override
+ public final float getScale(float pixelSize) {
return this.metrics.getScale(pixelSize);
}
@Override
- public AABBox getBBox(float pixelSize) {
+ public final AABBox getBBox(float pixelSize, float[] tmpV3) {
final float size = getScale(pixelSize);
AABBox newBox = getBBox().clone();
- newBox.scale(size);
+ newBox.scale(size, tmpV3);
return newBox;
}
- protected void addAdvance(float advance, float size) {
+ protected final void addAdvance(float advance, float size) {
this.metrics.addAdvance(advance, size);
}
@Override
- public float getAdvance(float pixelSize, boolean useFrationalMetrics) {
+ public final float getAdvance(float pixelSize, boolean useFrationalMetrics) {
return this.metrics.getAdvance(pixelSize, useFrationalMetrics);
}
@Override
- public Path2D getPath() {
- return this.path;
+ public final OutlineShape getShape() {
+ return this.shape;
}
@Override
- public Path2D getPath(float pixelSize) {
- final float size = getScale(pixelSize);
-
- if (this.numberSized != size) {
- this.numberSized = size;
- this.pathSized = AffineTransform.getScaleInstance(null, size, size).createTransformedShape(getPath());
- }
- return this.pathSized;
+ public final int hashCode() {
+ // 31 * x == (x << 5) - x
+ int hash = 31 + font.getName(Font.NAME_UNIQUNAME).hashCode();
+ return ((hash << 5) - hash) + id;
}
}
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java
index ecc41e438..4064e6463 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java
@@ -50,7 +50,7 @@ class TypecastHMetrics implements Metrics {
headTable = this.fontImpl.font.getHeadTable();
hheaTable = this.fontImpl.font.getHheaTable();
// vheaTable = this.fontImpl.font.getVheaTable();
- unitsPerEM_Inv = 1.0f / ( (float) headTable.getUnitsPerEm() );
+ unitsPerEM_Inv = 1.0f / ( headTable.getUnitsPerEm() );
int maxWidth = headTable.getXMax() - headTable.getXMin();
int maxHeight = headTable.getYMax() - headTable.getYMin();
@@ -82,9 +82,9 @@ class TypecastHMetrics implements Metrics {
return pixelSize * unitsPerEM_Inv;
}
@Override
- public final AABBox getBBox(float pixelSize) {
+ public final AABBox getBBox(float pixelSize, float[] tmpV3) {
AABBox res = new AABBox(bbox.getLow(), bbox.getHigh());
- res.scale(getScale(pixelSize));
+ res.scale(getScale(pixelSize), tmpV3);
return res;
}
} \ No newline at end of file
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java
index 127e260ca..6768b18c3 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java
@@ -27,196 +27,192 @@
*/
package jogamp.graph.font.typecast;
-import java.util.ArrayList;
-
-import jogamp.graph.font.FontInt.GlyphInt;
import jogamp.graph.font.typecast.ot.OTGlyph;
import jogamp.graph.font.typecast.ot.Point;
-import jogamp.graph.geom.plane.AffineTransform;
-import jogamp.graph.geom.plane.Path2D;
-import jogamp.graph.geom.plane.PathIterator;
import com.jogamp.graph.curve.OutlineShape;
-import com.jogamp.graph.font.Font;
-import com.jogamp.graph.font.Font.Glyph;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.geom.Vertex.Factory;
/**
- * Factory to build a {@link com.jogamp.graph.geom.Path2D Path2D} from
+ * Factory to build an {@link OutlineShape} from
* {@link jogamp.graph.font.typecast.ot.OTGlyph Glyph}s.
+ *
+ * http://www.freetype.org/freetype2/docs/glyphs/glyphs-3.html
+ * http://walon.org/pub/ttf/ttf_glyphs.htm
*/
public class TypecastRenderer {
+ private static final boolean DEBUG = false;
- private static void getPaths(TypecastFont font,
- CharSequence string, float pixelSize, AffineTransform transform, Path2D[] p)
- {
- 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) ;
- if (transform == null) {
- transform = new AffineTransform();
- }
- AffineTransform t = new AffineTransform();
-
- float advanceY = lineGap - descent + ascent;
- float y = 0;
- for (int i=0; i<string.length(); i++)
- {
- p[i] = new Path2D();
- p[i].reset();
- t.setTransform(transform);
- char character = string.charAt(i);
- if (character == '\n') {
- y += advanceY;
- advanceTotal = 0;
- continue;
- } else if (character == ' ') {
- advanceTotal += font.getAdvanceWidth(Glyph.ID_SPACE, pixelSize);
- continue;
- }
- Glyph glyph = font.getGlyph(character);
- Path2D gp = ((GlyphInt)glyph).getPath();
- float scale = metrics.getScale(pixelSize);
- t.translate(advanceTotal, y);
- t.scale(scale, scale);
- p[i].append(gp.iterator(t), false);
- advanceTotal += glyph.getAdvance(pixelSize, true);
- }
+ private static void addShapeMoveTo(final OutlineShape shape, Factory<? extends Vertex> vertexFactory, Point p1) {
+ shape.closeLastOutline(false);
+ shape.addEmptyOutline();
+ shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, p1.onCurve));
}
-
- public static ArrayList<OutlineShape> getOutlineShapes(TypecastFont font, CharSequence string, float pixelSize, AffineTransform transform, Factory<? extends Vertex> vertexFactory) {
- Path2D[] paths = new Path2D[string.length()];
- getPaths(font, string, pixelSize, transform, paths);
-
- ArrayList<OutlineShape> shapes = new ArrayList<OutlineShape>();
- final int numGlyps = paths.length;
- for (int index=0;index<numGlyps;index++) {
- if(paths[index] == null){
- continue;
- }
- OutlineShape shape = new OutlineShape(vertexFactory);
- shapes.add(shape);
- PathIterator iterator = paths[index].iterator(transform);
- if(null != iterator){
- while(!iterator.isDone()){
- float[] coords = new float[6];
- int segmentType = iterator.currentSegment(coords);
- addPathVertexToOutline(shape, vertexFactory, coords, segmentType);
- iterator.next();
- }
- }
- }
- return shapes;
+ private static void addShapeLineTo(final OutlineShape shape, Factory<? extends Vertex> vertexFactory, Point p1) {
+ shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, p1.onCurve));
}
- private static void addPathVertexToOutline(OutlineShape shape, Factory<? extends Vertex> vertexFactory, float[] coords, int segmentType){
- switch(segmentType) {
- case PathIterator.SEG_MOVETO:
- shape.closeLastOutline();
- shape.addEmptyOutline();
- shape.addVertex(0, vertexFactory.create(coords, 0, 2, true));
- break;
- case PathIterator.SEG_LINETO:
- shape.addVertex(0, vertexFactory.create(coords, 0, 2, true));
- break;
- case PathIterator.SEG_QUADTO:
- shape.addVertex(0, vertexFactory.create(coords, 0, 2, false));
- shape.addVertex(0, vertexFactory.create(coords, 2, 2, true));
- break;
- case PathIterator.SEG_CUBICTO:
- 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));
- break;
- case PathIterator.SEG_CLOSE:
- shape.closeLastOutline();
- break;
- default:
- throw new IllegalArgumentException("Unhandled Segment Type: "+segmentType);
- }
+ 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, p1.onCurve));
+ shape.addVertex(0, vertexFactory.create(p2.x, p2.y, 0, p2.onCurve));
+ }
+ private static void addShapeQuadTo(final OutlineShape shape, Factory<? extends Vertex> vertexFactory, Point p1,
+ float p2x, float p2y, boolean p2OnCurve) {
+ shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, p1.onCurve));
+ shape.addVertex(0, vertexFactory.create(p2x, p2y, 0, p2OnCurve));
}
-
/**
- * Build a {@link com.jogamp.graph.geom.Path2D Path2D} from a
- * {@link jogamp.graph.font.typecast.ot.OTGlyph Glyph}. This glyph path can then
- * be transformed and rendered.
- */
- public static Path2D buildPath(OTGlyph glyph) {
+ 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, p1.onCurve));
+ shape.addVertex(0, vertexFactory.create(p2.x, p2.y, 0, p2.onCurve));
+ shape.addVertex(0, vertexFactory.create(p3.x, p3.y, 0, p3.onCurve));
+ } */
+
+ public static OutlineShape buildShape(char symbol, OTGlyph glyph, Factory<? extends Vertex> vertexFactory) {
+ //
+ // See Typecast: GlyphPathFactory.addContourToPath(..)
+ //
if (glyph == null) {
return null;
}
- Path2D glyphPath = new Path2D();
+ final OutlineShape shape = new OutlineShape(vertexFactory);
+ buildShapeImpl(shape, symbol, glyph, vertexFactory);
+ shape.closeLastOutline(false);
+ return shape;
+ }
+ /**
+ private static void buildShapeImpl02(final OutlineShape shape, char symbol, OTGlyph glyph, Factory<? extends Vertex> 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 firstIndex = 0;
+ int startIndex = 0;
int count = 0;
for (int i = 0; i < glyph.getPointCount(); i++) {
count++;
- if (glyph.getPoint(i).endOfContour) {
- addContourToPath(glyphPath, glyph, firstIndex, count);
- firstIndex = i + 1;
+ if ( glyph.getPoint(i).endOfContour ) {
+ for(int j=0; j<count; j++) {
+ final Point p = glyph.getPoint(startIndex + j);
+ shape.addVertex(0, vertexFactory.create(p.x, p.y, 0, p.onCurve));
+ }
+ shape.closeLastOutline(false);
+ startIndex = i + 1;
count = 0;
}
}
- return glyphPath;
- }
+ } */
- private static void addContourToPath(Path2D gp, OTGlyph glyph, int startIndex, int count) {
- int offset = 0;
- while (offset < count) {
- Point point = glyph.getPoint(startIndex + offset%count);
- Point point_plus1 = glyph.getPoint(startIndex + (offset+1)%count);
- Point point_plus2 = glyph.getPoint(startIndex + (offset+2)%count);
- if(offset == 0)
- {
- gp.moveTo(point.x, point.y);
- }
+ private static void buildShapeImpl(final OutlineShape shape, char symbol, OTGlyph glyph, Factory<? extends Vertex> 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;
+ final int totalPoints = glyph.getPointCount();
+ for (int i = 0; i < totalPoints; i++) {
+ count++;
+ if ( glyph.getPoint(i).endOfContour ) {
+ int offset = 0;
+ while ( offset < count - 1 ) { // require at least +1 point (last one is end-of-contour)
+ final Point p0 = glyph.getPoint(startIndex + offset%count);
+ final Point p1 = glyph.getPoint(startIndex + (offset+1)%count);
+ final Point p2 = glyph.getPoint(startIndex + (offset+2)%count);
+ final Point p3 = offset+3 < count ? glyph.getPoint(startIndex + offset+3) : null;
+ if( DEBUG ) {
+ System.err.println("GlyphShape<"+symbol+">: offset "+offset+" of "+count+"/"+totalPoints+" points");
+ final int pMIdx= (offset==0) ? startIndex+count-1 : startIndex+(offset-1)%count;
+ final Point pM = glyph.getPoint(pMIdx);
+ final int p0Idx = startIndex + offset%count;
+ final int p1Idx = startIndex + (offset+1)%count;
+ final int p2Idx = startIndex + (offset+2)%count;
+ final int p3Idx = startIndex + (offset+3)%count;
+ System.err.println("\t pM["+pMIdx+"] "+pM);
+ System.err.println("\t p0["+p0Idx+"] "+p0);
+ System.err.println("\t p1["+p1Idx+"] "+p1);
+ System.err.println("\t p2["+p2Idx+"] "+p2);
+ System.err.println("\t p3["+p3Idx+"] "+p3);
+ }
+ if(offset == 0) {
+ addShapeMoveTo(shape, vertexFactory, p0);
+ // 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);
- 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);
- gp.quadTo(point_plus1.x, point_plus1.y, point_plus2.x, point_plus2.y);
- offset+=2;
+ if( p0.endOfContour ) {
+ // Branch-0: EOC ** SHALL NEVER HAPPEN **
+ if( DEBUG ) { System.err.println("B0 .. end-of-contour **** EOC"); }
+ shape.closeLastOutline(false);
+ break;
+ } else if (p0.onCurve) {
+ if (p1.onCurve) {
+ // Branch-1: point.onCurve && p1.onCurve
+ if( DEBUG ) { System.err.println("B1 .. line-to p0-p1"); }
+
+ // s = new Line2D.Float(point.x, point.y, p1.x, p1.y);
+ // gp.lineTo( p1.x, p1.y );
+ addShapeLineTo(shape, vertexFactory, p1);
+ offset++;
+ } else {
+ if (p2.onCurve) {
+ // Branch-2: point.onCurve && !p1.onCurve && p2.onCurve
+ if( DEBUG ) { System.err.println("B2 .. quad-to p0-p1-p2"); }
+
+ // s = new QuadCurve2D.Float( point.x, point.y, p1.x, p1.y, p2.x, p2.y);
+ // gp.quadTo(p1.x, p1.y, p2.x, p2.y);
+ addShapeQuadTo(shape, vertexFactory, p1, p2);
+ offset+=2;
+ } else {
+ if (null != p3 && p3.onCurve) {
+ // Branch-3: point.onCurve && !p1.onCurve && !p2.onCurve && p3.onCurve
+ if( DEBUG ) { System.err.println("B3 .. 2-quad p0-p1-p1_2, p1_2-p2-p3 **** 2QUAD"); }
+ // addShapeCubicTo(shape, vertexFactory, p1, p2, p3);
+ addShapeQuadTo(shape, vertexFactory, p1,
+ midValue(p1.x, p2.x),
+ midValue(p1.y, p2.y), true);
+ addShapeQuadTo(shape, vertexFactory, p2, p3);
+ offset+=3;
+ } else {
+ // Branch-4: point.onCurve && !p1.onCurve && !p2.onCurve && !p3.onCurve
+ if( DEBUG ) { System.err.println("B4 .. quad-to p0-p1-p2h **** MID"); }
+
+ // s = new QuadCurve2D.Float(point.x,point.y,p1.x,p1.y,
+ // midValue(p1.x, p2.x), midValue(p1.y, p2.y));
+ // gp.quadTo(p1.x, p1.y, midValue(p1.x, p2.x), midValue(p1.y, p2.y));
+ addShapeQuadTo(shape, vertexFactory, p1,
+ midValue(p1.x, p2.x),
+ midValue(p1.y, p2.y), true);
+ offset+=2; // Skip p2 as done in Typecast
+ }
+ }
+ }
} 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));
- gp.quadTo(point_plus1.x, point_plus1.y, midValue(point_plus1.x, point_plus2.x), midValue(point_plus1.y, point_plus2.y));
- offset+=2;
+ if (!p1.onCurve) {
+ // Branch-5: !point.onCurve && !p1.onCurve
+ if( DEBUG ) { System.err.println("B5 .. quad-to pMh-p0-p1h ***** MID"); }
+ // s = new QuadCurve2D.Float(midValue(pM.x, point.x), midValue(pM.y, point.y),
+ // point.x, point.y,
+ // midValue(point.x, p1.x), midValue(point.y, p1.y));
+ addShapeQuadTo(shape, vertexFactory, p0,
+ midValue(p0.x, p1.x), midValue(p0.y, p1.y), true);
+ offset++;
+ } else {
+ // Branch-6: !point.onCurve && p1.onCurve
+ if( DEBUG ) { System.err.println("B6 .. quad-to pMh-p0-p1"); }
+ // s = new QuadCurve2D.Float(midValue(pM.x, point.x), midValue(pM.y, point.y),
+ // point.x, point.y, p1.x, p1.y);
+ // gp.quadTo(point.x, point.y, p1.x, p1.y);
+ addShapeQuadTo(shape, vertexFactory, p0, p1);
+ offset++;
+ }
}
}
- } 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);
- 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);
- gp.quadTo(point.x, point.y, midValue(point.x, point_plus1.x), midValue(point.y, point_plus1.y));
- offset++;
- }
+ shape.closeLastOutline(false);
+ startIndex = i + 1;
+ count = 0;
}
}
}
- private static int midValue(int a, int b) {
- return a + (b - a)/2;
+ private static float midValue(float a, float b) {
+ return a + (b - a)/2f;
}
}
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/Point.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/Point.java
index f1a090d68..0cac8ab44 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/ot/Point.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/Point.java
@@ -18,7 +18,6 @@ public class Point {
public int y = 0;
public boolean onCurve = true;
public boolean endOfContour = false;
- public boolean touched = false;
public Point(int x, int y, boolean onCurve, boolean endOfContour) {
this.x = x;
@@ -26,4 +25,8 @@ public class Point {
this.onCurve = onCurve;
this.endOfContour = endOfContour;
}
+
+ public String toString() {
+ return "P["+x+"/"+y+", on "+onCurve+", end "+endOfContour+"]";
+ }
}
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfCompositeDescript.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfCompositeDescript.java
index 50e0fa339..fabc71a77 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfCompositeDescript.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfCompositeDescript.java
@@ -65,7 +65,7 @@ import java.util.ArrayList;
*/
public class GlyfCompositeDescript extends GlyfDescript {
- private ArrayList<GlyfCompositeComp> _components =
+ private final ArrayList<GlyfCompositeComp> _components =
new ArrayList<GlyfCompositeComp>();
public GlyfCompositeDescript(
@@ -167,8 +167,9 @@ public class GlyfCompositeDescript extends GlyfDescript {
@Override
public int getContourCount() {
- GlyfCompositeComp c = _components.get(_components.size()-1);
- return c.getFirstContour() + _parentTable.getDescription(c.getGlyphIndex()).getContourCount();
+ final GlyfCompositeComp c = _components.get(_components.size()-1);
+ final GlyfDescript d = _parentTable.getDescription(c.getGlyphIndex());
+ return c.getFirstContour() + ( null != d ? d.getContourCount() : 0 );
}
public int getComponentIndex(int i) {
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/t2/T2Interpreter.java b/src/jogl/classes/jogamp/graph/font/typecast/t2/T2Interpreter.java
index 181ec7e10..73f26b27c 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/t2/T2Interpreter.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/t2/T2Interpreter.java
@@ -39,11 +39,11 @@ public class T2Interpreter {
private static final int SUBR_STACK_LIMIT = 10;
private static final int TRANSIENT_ARRAY_ELEMENT_COUNT = 32;
- private Number[] _argStack = new Number[ARGUMENT_STACK_LIMIT];
+ private final Number[] _argStack = new Number[ARGUMENT_STACK_LIMIT];
private int _argStackIndex = 0;
- private int[] _subrStack = new int[SUBR_STACK_LIMIT];
+ private final int[] _subrStack = new int[SUBR_STACK_LIMIT];
private int _subrStackIndex = 0;
- private Number[] _transientArray = new Number[TRANSIENT_ARRAY_ELEMENT_COUNT];
+ private final Number[] _transientArray = new Number[TRANSIENT_ARRAY_ELEMENT_COUNT];
private ArrayList<Point> _points;
diff --git a/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java b/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java
index 32e2b6a39..621802c36 100644
--- a/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java
+++ b/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java
@@ -19,18 +19,13 @@
*/
package jogamp.graph.geom.plane;
-import java.io.IOException;
-import java.io.Serializable;
-
// import jogamp.opengl.util.HashCode;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.geom.Vertex.Factory;
import com.jogamp.opengl.math.FloatUtil;
-public class AffineTransform implements Cloneable, Serializable {
-
- private static final long serialVersionUID = 1330973210523860834L;
+public class AffineTransform implements Cloneable {
static final String determinantIsZero = "Determinant is zero";
@@ -74,16 +69,12 @@ public class AffineTransform implements Cloneable, Serializable {
public AffineTransform() {
pointFactory = null;
- type = TYPE_IDENTITY;
- m00 = m11 = 1.0f;
- m10 = m01 = m02 = m12 = 0.0f;
+ setToIdentity();
}
public AffineTransform(Factory<? extends Vertex> factory) {
pointFactory = factory;
- type = TYPE_IDENTITY;
- m00 = m11 = 1.0f;
- m10 = m01 = m02 = m12 = 0.0f;
+ setToIdentity();
}
public AffineTransform(AffineTransform t) {
@@ -121,6 +112,8 @@ public class AffineTransform implements Cloneable, Serializable {
}
}
+ public final Vertex.Factory<? extends Vertex> getFactory() { return pointFactory; }
+
/*
* Method returns type of affine transformation.
*
@@ -185,35 +178,35 @@ public class AffineTransform implements Cloneable, Serializable {
return type;
}
- public float getScaleX() {
+ public final float getScaleX() {
return m00;
}
- public float getScaleY() {
+ public final float getScaleY() {
return m11;
}
- public float getShearX() {
+ public final float getShearX() {
return m01;
}
- public float getShearY() {
+ public final float getShearY() {
return m10;
}
- public float getTranslateX() {
+ public final float getTranslateX() {
return m02;
}
- public float getTranslateY() {
+ public final float getTranslateY() {
return m12;
}
- public boolean isIdentity() {
+ public final boolean isIdentity() {
return getType() == TYPE_IDENTITY;
}
- public void getMatrix(float[] matrix) {
+ public final void getMatrix(float[] matrix) {
matrix[0] = m00;
matrix[1] = m10;
matrix[2] = m01;
@@ -224,11 +217,11 @@ public class AffineTransform implements Cloneable, Serializable {
}
}
- public float getDeterminant() {
+ public final float getDeterminant() {
return m00 * m11 - m01 * m10;
}
- public void setTransform(float m00, float m10, float m01, float m11, float m02, float m12) {
+ public final void setTransform(float m00, float m10, float m01, float m11, float m02, float m12) {
this.type = TYPE_UNKNOWN;
this.m00 = m00;
this.m10 = m10;
@@ -238,18 +231,18 @@ public class AffineTransform implements Cloneable, Serializable {
this.m12 = m12;
}
- public void setTransform(AffineTransform t) {
+ public final void setTransform(AffineTransform t) {
type = t.type;
setTransform(t.m00, t.m10, t.m01, t.m11, t.m02, t.m12);
}
- public void setToIdentity() {
+ public final void setToIdentity() {
type = TYPE_IDENTITY;
m00 = m11 = 1.0f;
m10 = m01 = m02 = m12 = 0.0f;
}
- public void setToTranslation(float mx, float my) {
+ public final void setToTranslation(float mx, float my) {
m00 = m11 = 1.0f;
m01 = m10 = 0.0f;
m02 = mx;
@@ -261,7 +254,7 @@ public class AffineTransform implements Cloneable, Serializable {
}
}
- public void setToScale(float scx, float scy) {
+ public final void setToScale(float scx, float scy) {
m00 = scx;
m11 = scy;
m10 = m01 = m02 = m12 = 0.0f;
@@ -272,7 +265,7 @@ public class AffineTransform implements Cloneable, Serializable {
}
}
- public void setToShear(float shx, float shy) {
+ public final void setToShear(float shx, float shy) {
m00 = m11 = 1.0f;
m02 = m12 = 0.0f;
m01 = shx;
@@ -284,7 +277,7 @@ public class AffineTransform implements Cloneable, Serializable {
}
}
- public void setToRotation(float angle) {
+ public final void setToRotation(float angle) {
float sin = FloatUtil.sin(angle);
float cos = FloatUtil.cos(angle);
if (FloatUtil.abs(cos) < ZERO) {
@@ -302,7 +295,7 @@ public class AffineTransform implements Cloneable, Serializable {
type = TYPE_UNKNOWN;
}
- public void setToRotation(float angle, float px, float py) {
+ public final void setToRotation(float angle, float px, float py) {
setToRotation(angle);
m02 = px * (1.0f - m00) + py * m10;
m12 = py * (1.0f - m00) - px * m10;
@@ -339,23 +332,23 @@ public class AffineTransform implements Cloneable, Serializable {
return t;
}
- public void translate(float mx, float my) {
+ public final void translate(float mx, float my) {
concatenate(AffineTransform.getTranslateInstance(pointFactory, mx, my));
}
- public void scale(float scx, float scy) {
+ public final void scale(float scx, float scy) {
concatenate(AffineTransform.getScaleInstance(pointFactory, scx, scy));
}
- public void shear(float shx, float shy) {
+ public final void shear(float shx, float shy) {
concatenate(AffineTransform.getShearInstance(pointFactory, shx, shy));
}
- public void rotate(float angle) {
+ public final void rotate(float angle) {
concatenate(AffineTransform.getRotateInstance(pointFactory, angle));
}
- public void rotate(float angle, float px, float py) {
+ public final void rotate(float angle, float px, float py) {
concatenate(AffineTransform.getRotateInstance(pointFactory, angle, px, py));
}
@@ -377,15 +370,15 @@ public class AffineTransform implements Cloneable, Serializable {
t1.m02 * t2.m10 + t1.m12 * t2.m11 + t2.m12);// m12
}
- public void concatenate(AffineTransform t) {
+ public final void concatenate(AffineTransform t) {
setTransform(multiply(t, this));
}
- public void preConcatenate(AffineTransform t) {
+ public final void preConcatenate(AffineTransform t) {
setTransform(multiply(this, t));
}
- public AffineTransform createInverse() throws NoninvertibleTransformException {
+ public final AffineTransform createInverse() throws NoninvertibleTransformException {
float det = getDeterminant();
if (FloatUtil.abs(det) < ZERO) {
throw new NoninvertibleTransformException(determinantIsZero);
@@ -401,33 +394,45 @@ public class AffineTransform implements Cloneable, Serializable {
);
}
- public Vertex transform(Vertex src, Vertex dst) {
+ public final Vertex transform(final 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();
-
- dst.setCoord(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12, 0f);
+ final float x = src.getX();
+ final float y = src.getY();
+ dst.setCoord(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12, src.getZ());
return dst;
}
- public void transform(Vertex[] src, int srcOff, Vertex[] dst, int dstOff, int length) {
+ public final 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");
}
- dstPoint.setCoord(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12, 0f);
+ final float x = srcPoint.getX();
+ final float y = srcPoint.getY();
+ dstPoint.setCoord(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12, srcPoint.getZ());
dst[dstOff++] = dstPoint;
}
}
- public void transform(float[] src, int srcOff, float[] dst, int dstOff, int length) {
+ public final void transform(final float[] src, final float[] dst) {
+ final float x = src[0];
+ final float y = src[1];
+ dst[0] = x * m00 + y * m01 + m02;
+ dst[1] = x * m10 + y * m11 + m12;
+ }
+
+ public final void transform(final float[] src, final int srcOff, final float[] dst, final int dstOff) {
+ final float x = src[srcOff + 0];
+ final float y = src[srcOff + 1];
+ dst[dstOff + 0] = x * m00 + y * m01 + m02;
+ dst[dstOff + 1] = x * m10 + y * m11 + m12;
+ }
+
+ public final void transform(final float[] src, int srcOff, final float[] dst, int dstOff, int length) {
int step = 2;
if (src == dst && srcOff < dstOff && dstOff < srcOff + length * 2) {
srcOff = srcOff + length * 2 - 2;
@@ -435,8 +440,8 @@ public class AffineTransform implements Cloneable, Serializable {
step = -2;
}
while (--length >= 0) {
- float x = src[srcOff + 0];
- float y = src[srcOff + 1];
+ final float x = src[srcOff + 0];
+ final float y = src[srcOff + 1];
dst[dstOff + 0] = x * m00 + y * m01 + m02;
dst[dstOff + 1] = x * m10 + y * m11 + m12;
srcOff += step;
@@ -444,19 +449,17 @@ public class AffineTransform implements Cloneable, Serializable {
}
}
- public Vertex deltaTransform(Vertex src, Vertex dst) {
+ public final 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();
-
- dst.setCoord(x * m00 + y * m01, x * m10 + y * m11, 0f);
+ final float x = src.getX();
+ final float y = src.getY();
+ dst.setCoord(x * m00 + y * m01, x * m10 + y * m11, src.getZ());
return dst;
}
- public void deltaTransform(float[] src, int srcOff, float[] dst, int dstOff, int length) {
+ public final void deltaTransform(float[] src, int srcOff, float[] dst, int dstOff, int length) {
while (--length >= 0) {
float x = src[srcOff++];
float y = src[srcOff++];
@@ -465,23 +468,21 @@ public class AffineTransform implements Cloneable, Serializable {
}
}
- public Vertex inverseTransform(Vertex src, Vertex dst) throws NoninvertibleTransformException {
+ public final Vertex inverseTransform(Vertex src, Vertex dst) throws NoninvertibleTransformException {
float det = getDeterminant();
if (FloatUtil.abs(det) < ZERO) {
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;
-
- dst.setCoord((x * m11 - y * m01) / det, (y * m00 - x * m10) / det, 0f);
+ final float x = src.getX() - m02;
+ final float y = src.getY() - m12;
+ dst.setCoord((x * m11 - y * m01) / det, (y * m00 - x * m10) / det, src.getZ());
return dst;
}
- public void inverseTransform(float[] src, int srcOff, float[] dst, int dstOff, int length)
+ public final void inverseTransform(float[] src, int srcOff, float[] dst, int dstOff, int length)
throws NoninvertibleTransformException
{
float det = getDeterminant();
@@ -497,12 +498,12 @@ public class AffineTransform implements Cloneable, Serializable {
}
}
- public Path2D createTransformedShape(Path2D src) {
+ public final Path2D createTransformedShape(Path2D src) {
if (src == null) {
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());
@@ -511,7 +512,7 @@ public class AffineTransform implements Cloneable, Serializable {
}
@Override
- public String toString() {
+ public final String toString() {
return
getClass().getName() +
"[[" + m00 + ", " + m01 + ", " + m02 + "], [" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
@@ -519,7 +520,7 @@ public class AffineTransform implements Cloneable, Serializable {
}
@Override
- public AffineTransform clone() {
+ public final AffineTransform clone() {
try {
return (AffineTransform) super.clone();
} catch (CloneNotSupportedException e) {
@@ -540,7 +541,7 @@ public class AffineTransform implements Cloneable, Serializable {
} */
@Override
- public boolean equals(Object obj) {
+ public final boolean equals(Object obj) {
if (obj == this) {
return true;
}
@@ -553,28 +554,5 @@ public class AffineTransform implements Cloneable, Serializable {
}
return false;
}
-
-
- /**
- * Write AffineTrasform object to the output steam.
- * @param stream - the output stream
- * @throws IOException - if there are I/O errors while writing to the output strem
- */
- private void writeObject(java.io.ObjectOutputStream stream) throws IOException {
- stream.defaultWriteObject();
- }
-
-
- /**
- * Read AffineTransform object from the input stream
- * @param stream - the input steam
- * @throws IOException - if there are I/O errors while reading from the input strem
- * @throws ClassNotFoundException - if class could not be found
- */
- private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException {
- stream.defaultReadObject();
- type = TYPE_UNKNOWN;
- }
-
}
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;
diff --git a/src/newt/classes/com/jogamp/newt/MonitorDevice.java b/src/newt/classes/com/jogamp/newt/MonitorDevice.java
index 28d9f53a1..2d1d912c7 100644
--- a/src/newt/classes/com/jogamp/newt/MonitorDevice.java
+++ b/src/newt/classes/com/jogamp/newt/MonitorDevice.java
@@ -33,7 +33,7 @@ import java.util.List;
import javax.media.nativewindow.util.DimensionImmutable;
import javax.media.nativewindow.util.Rectangle;
import javax.media.nativewindow.util.RectangleImmutable;
-
+import javax.media.nativewindow.util.SurfaceSize;
import com.jogamp.common.util.ArrayHashSet;
/**
@@ -119,6 +119,32 @@ public abstract class MonitorDevice {
}
/**
+ * Stores the <i>pixels per millimeter</i> value according to <i>current</i> {@link MonitorMode}
+ * {@link SurfaceSize#getResolution() SurfaceSize's resolution} in the given storage <code>ppmmStore</code>.
+ * <p>
+ * To convert the result to <i>dpi</i>, i.e. dots-per-inch, multiply both components with <code>25.4f</code>.
+ * </p>
+ */
+ public final void getPixelsPerMM(final float[] ppmmStore) {
+ final MonitorMode mode = getCurrentMode();
+ getPixelsPerMM(mode, ppmmStore);
+ }
+
+ /**
+ * Stores the <i>pixels per millimeter</i> value according to the given {@link MonitorMode}
+ * {@link SurfaceSize#getResolution() SurfaceSize's resolution} in the given storage <code>ppmmStore</code>.
+ * <p>
+ * To convert the result to <i>dpi</i>, i.e. dots-per-inch, multiply both components with <code>25.4f</code>.
+ * </p>
+ */
+ public final void getPixelsPerMM(final MonitorMode mode, final float[] ppmmStore) {
+ final DimensionImmutable sdim = getSizeMM();
+ final DimensionImmutable spix = mode.getSurfaceSize().getResolution();
+ ppmmStore[0] = (float)spix.getWidth() / (float)sdim.getWidth();
+ ppmmStore[1] = (float)spix.getHeight() / (float)sdim.getHeight();
+ }
+
+ /**
* Returns the immutable original {@link com.jogamp.newt.MonitorMode}, as used at NEWT initialization.
* <p>
* The returned {@link MonitorMode} is element of the lists {@link #getSupportedModes()} and {@link Screen#getMonitorModes()}.
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java b/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java
index e9609ca9c..de5fe8eb2 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java
@@ -44,7 +44,7 @@ import org.junit.runners.MethodSorters;
import com.jogamp.common.os.Platform;
import com.jogamp.graph.curve.Region;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.test.junit.graph.demos.GPURegionGLListener01;
import com.jogamp.opengl.test.junit.graph.demos.GPURegionGLListener02;
@@ -59,8 +59,8 @@ public class TestRegionRendererNEWT01 extends UITestCase {
public static void main(String args[]) throws IOException {
String tstname = TestRegionRendererNEWT01.class.getName();
org.junit.runner.JUnitCore.main(tstname);
- }
-
+ }
+
static void destroyWindow(GLWindow window) {
if(null!=window) {
window.destroy();
@@ -80,46 +80,75 @@ public class TestRegionRendererNEWT01 extends UITestCase {
return window;
}
- @Test
- public void testRegionRendererR2T01() throws InterruptedException {
+ // @Test
+ public void test00RegionRendererNONE01() throws InterruptedException {
+ GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
+ GLCapabilities caps = new GLCapabilities(glp);
+ // caps.setOnscreen(false);
+ caps.setAlphaBits(4);
+
+ GLWindow window = createWindow("shape-vbaa0-msaa0", caps, 800, 400);
+ RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
+
+ GPURegionGLListener01 demo01Listener = new GPURegionGLListener01 (rs, 0, 0, false, false);
+ demo01Listener.attachInputListenerTo(window);
+ window.addGLEventListener(demo01Listener);
+
+ RegionGLListener listener = new RegionGLListener(demo01Listener, window.getTitle(), "GPURegion01");
+ window.addGLEventListener(listener);
+
+ listener.setTech(-20, 0, -300, 0f, 2);
+ window.display();
+
+ listener.setTech(-20, 0, -150, 0f, 3);
+ window.display();
+
+ listener.setTech(-20, 0, -50, 0f, 4);
+ window.display();
+
+ destroyWindow(window);
+ }
+
+ // @Test
+ public void test01RegionRendererNONE02() throws InterruptedException {
if(Platform.CPUFamily.X86 != Platform.CPU_ARCH.family) { // FIXME
- // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise).
+ // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise).
+ // FIXME: Also the GLSL code for VARIABLE_CURVE is not fit for mobile yet!
System.err.println("disabled on non desktop (x86) arch for now ..");
return;
}
- GLProfile glp = GLProfile.getGL2ES2();
-
+ GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
GLCapabilities caps = new GLCapabilities(glp);
- //caps.setOnscreen(false);
- caps.setAlphaBits(4);
+ caps.setAlphaBits(4);
- GLWindow window = createWindow("shape-vbaa1-msaa0", caps, 800,400);
+ GLWindow window = createWindow("shape-vbaa0-msaa0", caps, 800, 400);
RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
- GPURegionGLListener02 demo02Listener = new GPURegionGLListener02 (rs, Region.VBAA_RENDERING_BIT, 1140, false, false);
- demo02Listener.attachInputListenerTo(window);
- window.addGLEventListener(demo02Listener);
-
- RegionGLListener listener = new RegionGLListener(demo02Listener, window.getTitle(), "GPURegionNewtDemo02");
+
+ GPURegionGLListener01 demo01Listener = new GPURegionGLListener01 (rs, Region.VARIABLE_CURVE_WEIGHT_BIT, 0, false, false);
+ demo01Listener.attachInputListenerTo(window);
+ window.addGLEventListener(demo01Listener);
+
+ RegionGLListener listener = new RegionGLListener(demo01Listener, window.getTitle(), "GPURegion02");
window.addGLEventListener(listener);
-
- listener.setTech(-20, 00, 0f, -300, 400);
+
+ listener.setTech(-20, 0, -300, 0f, 2);
window.display();
-
- listener.setTech(-20, 00, 0f, -150, 800);
+
+ listener.setTech(-20, 0, -150, 0f, 3);
window.display();
-
- listener.setTech(-20, 00, 0f, -50, 1000);
+
+ listener.setTech(-20, 0, -50, 0f, 4);
window.display();
- destroyWindow(window);
+ destroyWindow(window);
}
-
+
@Test
- public void testRegionRendererMSAA01() throws InterruptedException {
+ public void test10RegionRendererMSAA01() throws InterruptedException {
GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
GLCapabilities caps = new GLCapabilities(glp);
// caps.setOnscreen(false);
- caps.setAlphaBits(4);
+ caps.setAlphaBits(4);
caps.setSampleBuffers(true);
caps.setNumSamples(4);
@@ -127,26 +156,26 @@ public class TestRegionRendererNEWT01 extends UITestCase {
RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
GPURegionGLListener01 demo01Listener = new GPURegionGLListener01 (rs, 0, 0, false, false);
- demo01Listener.attachInputListenerTo(window);
+ demo01Listener.attachInputListenerTo(window);
window.addGLEventListener(demo01Listener);
-
+
RegionGLListener listener = new RegionGLListener(demo01Listener, window.getTitle(), "GPURegion01");
window.addGLEventListener(listener);
-
- listener.setTech(-20, 00, 0f, -300, 400);
+
+ listener.setTech(-20, 00, -300, 0f, 2);
window.display();
-
- listener.setTech(-20, 00, 0f, -150, 800);
+
+ listener.setTech(-20, 00, -150, 0f, 3);
window.display();
-
- listener.setTech(-20, 00, 0f, -50, 1000);
+
+ listener.setTech(-20, 00, -50, 0f, 4);
window.display();
-
- destroyWindow(window);
+
+ destroyWindow(window);
}
-
- @Test
- public void testRegionRendererMSAA02() throws InterruptedException {
+
+ // @Test
+ public void test11RegionRendererMSAA02() throws InterruptedException {
if(Platform.CPUFamily.X86 != Platform.CPU_ARCH.family) { // FIXME
// FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise).
// FIXME: Also the GLSL code for VARIABLE_CURVE is not fit for mobile yet!
@@ -155,7 +184,7 @@ public class TestRegionRendererNEWT01 extends UITestCase {
}
GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
GLCapabilities caps = new GLCapabilities(glp);
- caps.setAlphaBits(4);
+ caps.setAlphaBits(4);
caps.setSampleBuffers(true);
caps.setNumSamples(4);
@@ -163,43 +192,77 @@ public class TestRegionRendererNEWT01 extends UITestCase {
RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
GPURegionGLListener01 demo01Listener = new GPURegionGLListener01 (rs, Region.VARIABLE_CURVE_WEIGHT_BIT, 0, false, false);
- demo01Listener.attachInputListenerTo(window);
+ demo01Listener.attachInputListenerTo(window);
window.addGLEventListener(demo01Listener);
-
+
RegionGLListener listener = new RegionGLListener(demo01Listener, window.getTitle(), "GPURegion02");
window.addGLEventListener(listener);
-
- listener.setTech(-20, 00, 0f, -300, 400);
+
+ listener.setTech(-20, 00, -300, 0f, 2);
window.display();
-
- listener.setTech(-20, 00, 0f, -150, 800);
+
+ listener.setTech(-20, 00, -150, 0f, 3);
window.display();
-
- listener.setTech(-20, 00, 0f, -50, 1000);
+
+ listener.setTech(-20, 00, -50, 0f, 4);
window.display();
-
- destroyWindow(window);
+
+ destroyWindow(window);
}
-
+
+ @Test
+ public void test20RegionRendererR2T01() throws InterruptedException {
+ if(Platform.CPUFamily.X86 != Platform.CPU_ARCH.family) { // FIXME
+ // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise).
+ System.err.println("disabled on non desktop (x86) arch for now ..");
+ return;
+ }
+ GLProfile glp = GLProfile.getGL2ES2();
+
+ GLCapabilities caps = new GLCapabilities(glp);
+ //caps.setOnscreen(false);
+ caps.setAlphaBits(4);
+
+ GLWindow window = createWindow("shape-vbaa1-msaa0", caps, 800,400);
+ RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
+ GPURegionGLListener02 demo02Listener = new GPURegionGLListener02 (rs, Region.VBAA_RENDERING_BIT, 4, false, false);
+ demo02Listener.attachInputListenerTo(window);
+ window.addGLEventListener(demo02Listener);
+
+ RegionGLListener listener = new RegionGLListener(demo02Listener, window.getTitle(), "GPURegionNewtDemo02");
+ window.addGLEventListener(listener);
+
+ listener.setTech(-20, 00, -300, 0f, 2);
+ window.display();
+
+ listener.setTech(-20, 00, -150, 0f, 3);
+ window.display();
+
+ listener.setTech(-20, 00, -50, 0f, 4);
+ window.display();
+
+ destroyWindow(window);
+ }
+
private class RegionGLListener implements GLEventListener {
String winTitle;
String name;
GPURegionRendererListenerBase01 impl;
-
+
public RegionGLListener(GPURegionRendererListenerBase01 impl, String title, String name) {
this.impl = impl;
this.winTitle = title;
this.name = name;
}
-
- public void setTech(float xt, float yt, float angle, int zoom, int fboSize){
- impl.setMatrix(xt, yt, angle, zoom, fboSize);
+
+ public void setTech(float xt, float yt, int zt, float angle, int sampleCount){
+ impl.setMatrix(xt, yt, zt, angle, sampleCount);
}
public void init(GLAutoDrawable drawable) {
impl.init(drawable);
}
-
+
public void display(GLAutoDrawable drawable) {
impl.display(drawable);
@@ -214,12 +277,12 @@ public class TestRegionRendererNEWT01 extends UITestCase {
public void dispose(GLAutoDrawable drawable) {
impl.dispose(drawable);
-
+
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
impl.reshape(drawable, x, y, width, height);
-
+
}
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java
index f675e42cd..905483e7f 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java
@@ -29,33 +29,36 @@ package com.jogamp.opengl.test.junit.graph;
import java.io.File;
import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
import javax.media.opengl.GL;
import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GLAnimatorControl;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLCapabilitiesImmutable;
-import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLException;
import javax.media.opengl.GLProfile;
import javax.media.opengl.GLRunnable;
import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
import org.junit.FixMethodOrder;
+import org.junit.Test;
import org.junit.runners.MethodSorters;
+import com.jogamp.common.os.Platform;
+import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.GLRegion;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.curve.opengl.TextRenderer;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontFactory;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
+import com.jogamp.newt.MonitorDevice;
+import com.jogamp.newt.Window;
import com.jogamp.newt.opengl.GLWindow;
-import com.jogamp.opengl.math.geom.AABBox;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.util.Animator;
import com.jogamp.opengl.util.GLReadBufferUtil;
import com.jogamp.opengl.util.glsl.ShaderState;
@@ -64,42 +67,86 @@ import com.jogamp.opengl.util.glsl.ShaderState;
public class TestTextRendererNEWT00 extends UITestCase {
static final boolean DEBUG = false;
static final boolean TRACE = false;
- static long duration = 100; // ms
-
- static final float[] textPosition = new float[] {0,0,0};
- static final int[] texSize = new int[] { 0 };
- static final int fontSize = 24;
- static Font font;
-
- @BeforeClass
- public static void setup() throws IOException {
- font = FontFactory.get(FontFactory.UBUNTU).getDefault();
- }
-
+ static long Duration = 2000; // ms
+ static boolean WaitStartEnd = false;
+ static boolean TextAnim = false;
+ static int SceneMSAASamples = 4;
+ static int GraphVBAASamples = 4;
+ static int GraphMSAASamples = 4;
+ static int SwapInterval = 0;
+
+ static String fontFileName = null;
+ static int fontSet = 0;
+ static int fontFamily = 0;
+ static int fontStylebits = 0;
+ static float fontSizeFixed = 14f;
+
static int atoi(String a) {
try {
return Integer.parseInt(a);
} catch (Exception ex) { throw new RuntimeException(ex); }
}
-
+
public static void main(String args[]) throws IOException {
for(int i=0; i<args.length; i++) {
if(args[i].equals("-time")) {
i++;
- duration = atoi(args[i]);
+ Duration = atoi(args[i]);
+ } else if(args[i].equals("-fontFile")) {
+ i++;
+ fontFileName = args[i];
+ } else if(args[i].equals("-fontSet")) {
+ i++;
+ fontSet = atoi(args[i]);
+ } else if(args[i].equals("-fontFamily")) {
+ i++;
+ fontFamily = atoi(args[i]);
+ } else if(args[i].equals("-fontStyle")) {
+ i++;
+ fontStylebits = atoi(args[i]);
+ } else if(args[i].equals("-fontSize")) {
+ i++;
+ fontSizeFixed = atoi(args[i]);
+ } else if(args[i].equals("-smsaa")) {
+ i++;
+ SceneMSAASamples = atoi(args[i]);
+ GraphMSAASamples = 0;
+ GraphVBAASamples = 0;
+ } else if(args[i].equals("-gmsaa")) {
+ i++;
+ SceneMSAASamples = 0;
+ GraphMSAASamples = atoi(args[i]);
+ GraphVBAASamples = 0;
+ } else if(args[i].equals("-gvbaa")) {
+ i++;
+ SceneMSAASamples = 0;
+ GraphMSAASamples = 0;
+ GraphVBAASamples = atoi(args[i]);
+ } else if(args[i].equals("-textAnim")) {
+ TextAnim = true;
+ } else if(args[i].equals("-vsync")) {
+ i++;
+ SwapInterval = MiscUtils.atoi(args[i], SwapInterval);
+ } else if(args[i].equals("-wait")) {
+ WaitStartEnd = true;
}
}
+ System.err.println("Font [set "+fontSet+", family "+fontFamily+", style "+fontStylebits+", size "+fontSizeFixed+"], fontFileName "+fontFileName);
+ System.err.println("Scene MSAA Samples "+SceneMSAASamples);
+ System.err.println("Graph MSAA Samples "+GraphMSAASamples);
+ System.err.println("Graph VBAA Samples "+GraphVBAASamples);
+ System.err.println("swapInterval "+SwapInterval);
String tstname = TestTextRendererNEWT00.class.getName();
org.junit.runner.JUnitCore.main(tstname);
- }
-
+ }
+
static void sleep() {
try {
- System.err.println("** new frame ** (sleep: "+duration+"ms)");
- Thread.sleep(duration);
+ System.err.println("** new frame ** (sleep: "+Duration+"ms)");
+ Thread.sleep(Duration);
} catch (InterruptedException ie) {}
}
-
+
static void destroyWindow(GLWindow window) {
if(null!=window) {
window.destroy();
@@ -118,122 +165,232 @@ public class TestTextRendererNEWT00 extends UITestCase {
return window;
}
-
+
@Test
- public void testTextRendererMSAA01() throws InterruptedException {
+ public void test01SceneMSAA01() throws InterruptedException {
+ if( SceneMSAASamples > 0 ) {
+ testImpl(SceneMSAASamples, 0, 0);
+ }
+ }
+ @Test
+ public void test02GraphMSAA01() throws InterruptedException {
+ if( GraphMSAASamples > 0 ) {
+ testImpl(0, GraphMSAASamples, 0);
+ }
+ }
+ @Test
+ public void test03GraphVBAA01() throws InterruptedException {
+ if( GraphVBAASamples > 0 ) {
+ testImpl(0, 0, GraphVBAASamples);
+ }
+ }
+
+ public void testImpl(final int sceneMSAASamples, final int graphMSAASamples, final int graphVBAASamples) throws InterruptedException {
GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
GLCapabilities caps = new GLCapabilities(glp);
- caps.setAlphaBits(4);
- caps.setSampleBuffers(true);
- caps.setNumSamples(4);
- System.err.println("Requested: "+caps);
+ caps.setAlphaBits(4);
+ if( 0 < sceneMSAASamples ) {
+ caps.setSampleBuffers(true);
+ caps.setNumSamples(sceneMSAASamples);
+ }
+ System.err.println("Requested: "+caps+", graph[msaaSamples "+graphMSAASamples+", vbaaSamples "+graphVBAASamples+"]");
- GLWindow window = createWindow("text-vbaa0-msaa1", caps, 800, 400);
+ GLWindow window = createWindow("text-gvbaa"+graphVBAASamples+"-gmsaa"+graphMSAASamples+"-smsaa"+sceneMSAASamples, caps, 1024, 640);
window.display();
System.err.println("Chosen: "+window.getChosenGLCapabilities());
-
+ if( WaitStartEnd ) {
+ UITestCase.waitForKey("Start");
+ }
+
final RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
- final TextRendererListener textGLListener = new TextRendererListener(rs);
- final TextRenderer renderer = textGLListener.getRenderer();
+ final int rendererMode, sampleCount;
+ if( graphVBAASamples > 0 ) {
+ rendererMode = Region.VBAA_RENDERING_BIT;
+ sampleCount = graphVBAASamples;
+ } else if ( graphMSAASamples > 0 ) {
+ rendererMode = Region.MSAA_RENDERING_BIT;
+ sampleCount = graphMSAASamples;
+ } else {
+ rendererMode = 0;
+ sampleCount = 0;
+ }
+ final TextRendererGLEL textGLListener = new TextRendererGLEL(rs, rendererMode, sampleCount);
+ System.err.println(textGLListener.getFontInfo());
+
window.addGLEventListener(textGLListener);
+ Animator anim = new Animator();
+ anim.add(window);
+ anim.start();
+ anim.setUpdateFPSFrames(60, null);
+ sleep();
window.invoke(true, new GLRunnable() {
@Override
public boolean run(GLAutoDrawable drawable) {
- int c=0;
- renderString(drawable, renderer, "GlueGen", c++, -1, -1000);
- renderString(drawable, renderer, "JOAL", c++, -1, -1000);
- renderString(drawable, renderer, "JOGL", c++, -1, -1000);
- renderString(drawable, renderer, "JOCL", c++, -1, -1000);
try {
textGLListener.printScreen(drawable, "./", "TestTextRendererNEWT00-snap"+screenshot_num, false);
+ screenshot_num++;
} catch (Exception e) {
e.printStackTrace();
}
return true;
- }
+ }
});
- sleep();
-
- destroyWindow(window);
- }
- int screenshot_num = 0;
-
- int lastRow = -1;
-
- void renderString(GLAutoDrawable drawable, TextRenderer renderer, String text, int column, int row, int z0) {
- final GL2ES2 gl = drawable.getGL().getGL2ES2();
- final int height = drawable.getHeight();
-
- int dx = 0;
- int dy = height;
- if(0>row) {
- row = lastRow + 1;
+ anim.stop();
+ if( WaitStartEnd ) {
+ UITestCase.waitForKey("Stop");
}
- AABBox textBox = font.getStringBounds(text, fontSize);
- dx += font.getAdvanceWidth('X', fontSize) * column;
- dy -= (int)textBox.getHeight() * ( row + 1 );
- renderer.resetModelview(null);
- renderer.translate(gl, dx, dy, z0);
- renderer.drawString3D(gl, font, text, textPosition, fontSize, texSize);
-
- lastRow = row;
+ destroyWindow(window);
}
-
- public class TextRendererListener implements GLEventListener {
- private GLReadBufferUtil screenshot;
- private TextRenderer renderer;
-
- public TextRendererListener(RenderState rs) {
+ int screenshot_num = 0;
+
+ static final String textX2 =
+ "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec sapien tellus. \n"+
+ "Ut purus odio, rhoncus sit amet commodo eget, ullamcorper vel urna. Mauris ultricies \n"+
+ "quam iaculis urna cursus ornare. Nullam ut felis a ante ultrices ultricies nec a elit. \n"+
+ "In hac habitasse platea dictumst. Vivamus et mi a quam lacinia pharetra at venenatis est.\n"+
+ "Morbi quis bibendum nibh. Donec lectus orci, sagittis in consequat nec, volutpat nec nisi.\n"+
+ "Donec ut dolor et nulla tristique varius. In nulla magna, fermentum id tempus quis, semper \n"+
+ "in lorem. Maecenas in ipsum ac justo scelerisque sollicitudin. Quisque sit amet neque lorem,\n" +
+ "-------Press H to change text---------\n";
+
+ private final class TextRendererGLEL extends TextRendererGLELBase {
+ private final GLReadBufferUtil screenshot;
+ private final GLRegion regionFPS, regionFPSAnim;
+ final Font font;
+ final float fontSizeMin, fontSizeMax;
+ private long t0;
+ float fontSizeAnim, fontSizeDelta;
+ float dpiH;
+
+ TextRendererGLEL(final RenderState rs, final int renderModes, final int sampleCount) {
+ super(renderModes, new int[] { sampleCount });
+ setRendererCallbacks(RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
+ setRenderState(rs);
+
+ regionFPS = GLRegion.create(renderModes);
+ regionFPSAnim = GLRegion.create(renderModes);
+ if( null != fontFileName ) {
+ Font _font = null;
+ try {
+ _font = FontFactory.get(getClass(), fontFileName, false);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ font = _font;
+ } else {
+ font = getFont(fontSet, fontFamily, fontStylebits);
+ }
+
+ staticRGBAColor[0] = 0.0f;
+ staticRGBAColor[1] = 0.0f;
+ staticRGBAColor[2] = 0.0f;
+ staticRGBAColor[3] = 1.0f;
+
this.screenshot = new GLReadBufferUtil(false, false);
- this.renderer = TextRenderer.create(rs, 0);
+ // fontSizeMin = Math.max(8, fontSizeFixed-5);
+ fontSizeMin = fontSizeFixed;
+ fontSizeMax = fontSizeFixed+8;
+ fontSizeAnim = fontSizeFixed;
+ fontSizeDelta = 0.01f;
+ }
+
+ @Override
+ public void init(GLAutoDrawable drawable) {
+ super.init(drawable);
+ drawable.getGL().setSwapInterval(SwapInterval);
+ t0 = Platform.currentTimeMillis();
+
+ final Window win = (Window)drawable.getUpstreamWidget();
+ final MonitorDevice monitor = win.getMainMonitor();
+ final float[] pixelsPerMM = new float[2];
+ monitor.getPixelsPerMM(pixelsPerMM);
+ final float[] dotsPerInch = new float[] { pixelsPerMM[0]*25.4f, pixelsPerMM[1]*25.4f };
+ dpiH = dotsPerInch[1];
+ System.err.println(getFontInfo());
+ System.err.println("fontSize "+fontSizeFixed+", dotsPerMM "+pixelsPerMM[0]+"x"+pixelsPerMM[1]+", dpi "+dotsPerInch[0]+"x"+dotsPerInch[1]+", pixelSize "+font.getPixelSize(fontSizeFixed, dotsPerInch[1] /* dpi display */));
}
-
- public final TextRenderer getRenderer() { return renderer; }
-
+
+ @Override
+ public void dispose(GLAutoDrawable drawable) {
+ final GL2ES2 gl = drawable.getGL().getGL2ES2();
+ screenshot.dispose(gl);
+ regionFPS.destroy(gl, renderer);
+ regionFPSAnim.destroy(gl, renderer);
+ super.dispose(drawable);
+ }
+
public void printScreen(GLAutoDrawable drawable, String dir, String objName, boolean exportAlpha) throws GLException, IOException {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- pw.printf("%s-%03dx%03d-T%04d", objName, drawable.getWidth(), drawable.getHeight(), texSize[0]);
-
- final String filename = dir + sw +".png";
+ final String modeS = Region.getRenderModeString(renderer.getRenderModes());
+ final String bname = String.format("%s-msaa%02d-fontsz%02.1f-%03dx%03d-%s%04d", objName,
+ drawable.getChosenGLCapabilities().getNumSamples(),
+ TestTextRendererNEWT00.fontSizeFixed, drawable.getWidth(), drawable.getHeight(), modeS, vbaaSampleCount[0]);
+ final String filename = dir + bname +".png";
if(screenshot.readPixels(drawable.getGL(), false)) {
screenshot.write(new File(filename));
}
}
-
- public void init(GLAutoDrawable drawable) {
- final GL2ES2 gl = drawable.getGL().getGL2ES2();
- gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
- renderer.init(gl);
- renderer.setAlpha(gl, 1.0f);
- renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
- }
-
- public void reshape(GLAutoDrawable drawable, int xstart, int ystart, int width, int height) {
- final GL2ES2 gl = drawable.getGL().getGL2ES2();
-
- gl.glViewport(xstart, ystart, width, height);
- // renderer.reshapePerspective(gl, 45.0f, width, height, 0.1f, 1000.0f);
- renderer.reshapeOrtho(gl, width, height, 0.1f, 1000.0f);
+
+ String getFontInfo() {
+ final float unitsPerEM_Inv = font.getMetrics().getScale(1f);
+ final float unitsPerEM = 1f / unitsPerEM_Inv;
+ return String.format("Font %s%n %s%nunitsPerEM %f (upem)",
+ font.getFullFamilyName(null).toString(),
+ font.getName(Font.NAME_UNIQUNAME),
+ unitsPerEM);
}
-
+
+ @Override
public void display(GLAutoDrawable drawable) {
- final GL2ES2 gl = drawable.getGL().getGL2ES2();
+ final GL2ES2 gl = drawable.getGL().getGL2ES2();
+
+ gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
-
- renderString(drawable, renderer, "012345678901234567890123456789", 0, 0, -1000);
- renderString(drawable, renderer, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, -1, -1000);
- renderString(drawable, renderer, "Hello World", 0, -1, -1000);
- renderString(drawable, renderer, "4567890123456", 4, -1, -1000);
- renderString(drawable, renderer, "I like JogAmp", 4, -1, -1000);
- }
-
- public void dispose(GLAutoDrawable drawable) {
- final GL2ES2 gl = drawable.getGL().getGL2ES2();
- screenshot.dispose(gl);
- renderer.destroy(gl);
- }
- }
+
+ final GLAnimatorControl anim = drawable.getAnimator();
+ final float lfps = null != anim ? anim.getLastFPS() : 0f;
+ final float tfps = null != anim ? anim.getTotalFPS() : 0f;
+
+ // Note: MODELVIEW is from [ 0 .. height ]
+
+ final long t1 = Platform.currentTimeMillis();
+
+ // final float fontSize = TestTextRendererNEWT00.fontSize;
+
+ fontSizeAnim += fontSizeDelta;
+ if( fontSizeMin >= fontSizeAnim || fontSizeAnim >= fontSizeMax ) {
+ fontSizeDelta *= -1f;
+ }
+
+ final float pixelSize = font.getPixelSize(fontSizeFixed, dpiH);
+ final float pixelSizeAnim = font.getPixelSize(fontSizeAnim, dpiH);
+
+ final String modeS = Region.getRenderModeString(renderer.getRenderModes());
+ final String text1 = String.format("%03.1f/%03.1f fps, vsync %d, elapsed %4.1f s, fontSize %2.2f, msaa %d, %s-samples %d",
+ lfps, tfps, gl.getSwapInterval(), (t1-t0)/1000.0, fontSizeFixed,
+ drawable.getChosenGLCapabilities().getNumSamples(), modeS, vbaaSampleCount[0]);
+ final String text1A = String.format("%03.1f/%03.1f fps, vsync %d, elapsed %4.1f s, fontSize %2.2f, msaa %d, %s-samples %d",
+ lfps, tfps, gl.getSwapInterval(), (t1-t0)/1000.0, fontSizeAnim,
+ drawable.getChosenGLCapabilities().getNumSamples(), modeS, vbaaSampleCount[0]);
+
+ if( false ) {
+ // renderString(drawable, font, pixelSize, getFontInfo(), 0, 0, 0, 0, -1000f, true);
+ renderString(drawable, font, pixelSize, textX2, 0, 0, 0, 0, -1000f, true);
+ // renderString(drawable, font, pixelSize, text1, 0, 0, 0, -1000f, regionFPS); // no-cache
+ } else {
+ renderString(drawable, font, pixelSize, getFontInfo(), 0, 0, 0, 0, -1000, true);
+ renderString(drawable, font, pixelSize, "012345678901234567890123456789", 0, 0, 0, -1000, true);
+ renderString(drawable, font, pixelSize, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, 0, 0, -1000, true);
+ renderString(drawable, font, pixelSize, "Hello World", 0, 0, 0, -1000, true);
+ renderString(drawable, font, pixelSize, "4567890123456", 4, 0, 0, -1000, true);
+ renderString(drawable, font, pixelSize, "I like JogAmp", 4, 0, 0, -1000, true);
+ renderString(drawable, font, pixelSize, "Hello World", 0, 0, 0, -1000, true);
+ renderString(drawable, font, pixelSize, textX2, 0, 0, 0, -1000, true);
+ renderString(drawable, font, pixelSize, text1, 0, 0, 0, -1000, regionFPS); // no-cache
+ if( TextAnim ) {
+ renderString(drawable, font, pixelSizeAnim, text1A, 0, 0, 0, -1000, regionFPSAnim); // no-cache
+ }
+ }
+ } };
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java
index 75a672a5b..a8044463d 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java
@@ -45,9 +45,9 @@ import org.junit.runners.MethodSorters;
import com.jogamp.common.os.Platform;
import com.jogamp.graph.curve.Region;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.curve.opengl.TextRenderer;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.font.FontFactory;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.test.junit.graph.demos.GPUTextRendererListenerBase01;
import com.jogamp.opengl.test.junit.util.UITestCase;
@@ -65,7 +65,7 @@ public class TestTextRendererNEWT01 extends UITestCase {
return Integer.parseInt(a);
} catch (Exception ex) { throw new RuntimeException(ex); }
}
-
+
public static void main(String args[]) throws IOException {
for(int i=0; i<args.length; i++) {
if(args[i].equals("-time")) {
@@ -75,15 +75,15 @@ public class TestTextRendererNEWT01 extends UITestCase {
}
String tstname = TestTextRendererNEWT01.class.getName();
org.junit.runner.JUnitCore.main(tstname);
- }
-
+ }
+
static void sleep() {
try {
System.err.println("** new frame ** (sleep: "+duration+"ms)");
Thread.sleep(duration);
} catch (InterruptedException ie) {}
}
-
+
static void destroyWindow(GLWindow window) {
if(null!=window) {
window.destroy();
@@ -111,56 +111,56 @@ public class TestTextRendererNEWT01 extends UITestCase {
return;
}
GLProfile glp = GLProfile.getGL2ES2();
-
+
GLCapabilities caps = new GLCapabilities(glp);
- caps.setAlphaBits(4);
+ caps.setAlphaBits(4);
System.err.println("Requested: "+caps);
GLWindow window = createWindow("text-vbaa1-msaa0", caps, 800,400);
window.display();
System.err.println("Chosen: "+window.getChosenGLCapabilities());
-
+
RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
TextGLListener textGLListener = new TextGLListener(rs, Region.VBAA_RENDERING_BIT, DEBUG, TRACE);
textGLListener.attachInputListenerTo(window);
window.addGLEventListener(textGLListener);
-
+
if(textGLListener.setFontSet(FontFactory.UBUNTU, 0, 0)) {
- textGLListener.setTech(-400, -30, 0f, -1000, window.getWidth()*2);
+ textGLListener.setTech(-400, -30, 0f, -1000, 2);
window.display();
sleep();
-
- textGLListener.setTech(-400, -30, 0, -380, window.getWidth()*3);
+
+ textGLListener.setTech(-400, -30, 0f, -380, 3);
window.display();
sleep();
-
- textGLListener.setTech(-400, -20, 0, -80, window.getWidth()*4);
+
+ textGLListener.setTech(-400, -20, 0f, -80, 4);
window.display();
sleep();
}
if(textGLListener.setFontSet(FontFactory.JAVA, 0, 0)) {
- textGLListener.setTech(-400, -30, 0f, -1000, window.getWidth()*2);
+ textGLListener.setTech(-400, -30, 0f, -1000, 2);
window.display();
sleep();
-
- textGLListener.setTech(-400, -30, 0, -380, window.getWidth()*3);
+
+ textGLListener.setTech(-400, -30, 0f, -380, 3);
window.display();
sleep();
-
- textGLListener.setTech(-400, -20, 0, -80, window.getWidth()*4);
+
+ textGLListener.setTech(-400, -20, 0f, -80, 4);
window.display();
sleep();
}
-
- destroyWindow(window);
+
+ destroyWindow(window);
}
-
+
@Test
public void testTextRendererMSAA01() throws InterruptedException {
GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
GLCapabilities caps = new GLCapabilities(glp);
- caps.setAlphaBits(4);
+ caps.setAlphaBits(4);
caps.setSampleBuffers(true);
caps.setNumSamples(4);
System.err.println("Requested: "+caps);
@@ -168,22 +168,22 @@ public class TestTextRendererNEWT01 extends UITestCase {
GLWindow window = createWindow("text-vbaa0-msaa1", caps, 800, 400);
window.display();
System.err.println("Chosen: "+window.getChosenGLCapabilities());
-
+
RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
TextGLListener textGLListener = new TextGLListener(rs, 0, DEBUG, TRACE);
textGLListener.attachInputListenerTo(window);
window.addGLEventListener(textGLListener);
-
+
if(textGLListener.setFontSet(FontFactory.UBUNTU, 0, 0)) {
textGLListener.setTech(-400, -30, 0f, -1000, 0);
window.display();
sleep();
-
- textGLListener.setTech(-400, -30, 0, -380, 0);
+
+ textGLListener.setTech(-400, -30, 0, -380, 0);
window.display();
sleep();
-
- textGLListener.setTech(-400, -20, 0, -80, 0);
+
+ textGLListener.setTech(-400, -20, 0, -80, 0);
window.display();
sleep();
}
@@ -192,47 +192,47 @@ public class TestTextRendererNEWT01 extends UITestCase {
textGLListener.setTech(-400, -30, 0f, -1000, 0);
window.display();
sleep();
-
- textGLListener.setTech(-400, -30, 0, -380, 0);
+
+ textGLListener.setTech(-400, -30, 0, -380, 0);
window.display();
sleep();
-
- textGLListener.setTech(-400, -20, 0, -80, 0);
+
+ textGLListener.setTech(-400, -20, 0, -80, 0);
window.display();
sleep();
}
-
- destroyWindow(window);
+
+ destroyWindow(window);
}
-
+
private class TextGLListener extends GPUTextRendererListenerBase01 {
String winTitle;
-
+
public TextGLListener(RenderState rs, int type, boolean debug, boolean trace) {
- super(rs, type, debug, trace);
+ super(rs, type, 4, true, debug, trace);
}
-
+
public void attachInputListenerTo(GLWindow window) {
super.attachInputListenerTo(window);
winTitle = window.getTitle();
}
- public void setTech(float xt, float yt, float angle, int zoom, int fboSize){
- setMatrix(xt, yt, angle, zoom, fboSize);
+ public void setTech(float xt, float yt, float angle, int zoom, int sampleCount){
+ setMatrix(xt, yt, zoom, angle, sampleCount);
}
public void init(GLAutoDrawable drawable) {
super.init(drawable);
-
+
GL2ES2 gl = drawable.getGL().getGL2ES2();
gl.setSwapInterval(1);
gl.glEnable(GL.GL_DEPTH_TEST);
-
- final TextRenderer textRenderer = (TextRenderer) getRenderer();
-
- textRenderer.setAlpha(gl, 1.0f);
- textRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
+
+ final RegionRenderer renderer = getRenderer();
+
+ renderer.setAlpha(gl, 1.0f);
+ renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
}
-
+
public void display(GLAutoDrawable drawable) {
super.display(drawable);
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java
index bfa942cc1..d109ba1cc 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java
@@ -42,10 +42,11 @@ import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.curve.opengl.TextRenderer;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
+import com.jogamp.graph.curve.opengl.TextRegionUtil;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontFactory;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.opengl.math.geom.AABBox;
import com.jogamp.opengl.test.junit.util.NEWTGLContext;
import com.jogamp.opengl.test.junit.util.UITestCase;
@@ -60,9 +61,9 @@ public class TestTextRendererNEWT10 extends UITestCase {
static boolean forceES2 = false;
static boolean forceGL3 = false;
static boolean mainRun = false;
-
- static final float[] textPosition = new float[] {0,0,0};
- static final int[] texSize = new int[] { 0 };
+ static boolean useMSAA = true;
+
+ static final int[] texSize = new int[] { 0 };
static final int fontSize = 24;
static Font font;
@@ -70,19 +71,21 @@ public class TestTextRendererNEWT10 extends UITestCase {
public static void setup() throws IOException {
font = FontFactory.get(FontFactory.UBUNTU).getDefault();
}
-
+
static int atoi(String a) {
try {
return Integer.parseInt(a);
} catch (Exception ex) { throw new RuntimeException(ex); }
}
-
+
public static void main(String args[]) throws IOException {
mainRun = true;
for(int i=0; i<args.length; i++) {
if(args[i].equals("-time")) {
i++;
duration = atoi(args[i]);
+ } else if(args[i].equals("-noMSAA")) {
+ useMSAA = false;
} else if(args[i].equals("-es2")) {
forceES2 = true;
} else if(args[i].equals("-gl3")) {
@@ -91,17 +94,26 @@ public class TestTextRendererNEWT10 extends UITestCase {
}
String tstname = TestTextRendererNEWT10.class.getName();
org.junit.runner.JUnitCore.main(tstname);
- }
-
+ }
+
static void sleep() {
try {
System.err.println("** new frame ** (sleep: "+duration+"ms)");
Thread.sleep(duration);
} catch (InterruptedException ie) {}
}
-
+
+ // @Test
+ public void test00TextRendererNONE01() throws InterruptedException {
+ testTextRendererImpl(0);
+ }
+
@Test
public void testTextRendererMSAA01() throws InterruptedException {
+ testTextRendererImpl(4);
+ }
+
+ void testTextRendererImpl(int sampleCount) throws InterruptedException {
final GLProfile glp;
if(forceGL3) {
glp = GLProfile.get(GLProfile.GL3);
@@ -111,76 +123,77 @@ public class TestTextRendererNEWT10 extends UITestCase {
glp = GLProfile.getGL2ES2();
}
final GLCapabilities caps = new GLCapabilities( glp );
- caps.setAlphaBits(4);
- caps.setSampleBuffers(true);
- caps.setNumSamples(4);
+ caps.setAlphaBits(4);
+ if( 0 < sampleCount ) {
+ caps.setSampleBuffers(true);
+ caps.setNumSamples(sampleCount);
+ }
System.err.println("Requested: "+caps);
final NEWTGLContext.WindowContext winctx = NEWTGLContext.createOnscreenWindow(caps, 800, 400, true);
final GLDrawable drawable = winctx.context.getGLDrawable();
final GL2ES2 gl = winctx.context.getGL().getGL2ES2();
- System.err.println(winctx.context);
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
System.err.println("Chosen: "+winctx.window.getChosenCapabilities());
-
+
final RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
- final TextRenderer renderer = TextRenderer.create(rs, 0);
+ final RegionRenderer renderer = RegionRenderer.create(rs, 0, RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
+ final TextRegionUtil textRenderUtil = new TextRegionUtil(renderer);
// init
gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
renderer.init(gl);
renderer.setAlpha(gl, 1.0f);
- renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
+ renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
// reshape
- gl.glViewport(0, 0, drawable.getWidth(), drawable.getHeight());
+ gl.glViewport(0, 0, drawable.getWidth(), drawable.getHeight());
// renderer.reshapePerspective(gl, 45.0f, drawable.getWidth(), drawable.getHeight(), 0.1f, 1000.0f);
renderer.reshapeOrtho(gl, drawable.getWidth(), drawable.getHeight(), 0.1f, 1000.0f);
// display
- gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
- renderString(drawable, gl, renderer, "012345678901234567890123456789", 0, 0, -1000);
- renderString(drawable, gl, renderer, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, -1, -1000);
- renderString(drawable, gl, renderer, "Hello World", 0, -1, -1000);
- renderString(drawable, gl, renderer, "4567890123456", 4, -1, -1000);
- renderString(drawable, gl, renderer, "I like JogAmp", 4, -1, -1000);
-
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+ renderString(drawable, gl, textRenderUtil, "012345678901234567890123456789", 0, 0, -1000);
+ renderString(drawable, gl, textRenderUtil, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, -1, -1000);
+ renderString(drawable, gl, textRenderUtil, "Hello World", 0, -1, -1000);
+ renderString(drawable, gl, textRenderUtil, "4567890123456", 4, -1, -1000);
+ renderString(drawable, gl, textRenderUtil, "I like JogAmp", 4, -1, -1000);
+
int c = 0;
- renderString(drawable, gl, renderer, "GlueGen", c++, -1, -1000);
- renderString(drawable, gl, renderer, "JOAL", c++, -1, -1000);
- renderString(drawable, gl, renderer, "JOGL", c++, -1, -1000);
- renderString(drawable, gl, renderer, "JOCL", c++, -1, -1000);
-
+ renderString(drawable, gl, textRenderUtil, "GlueGen", c++, -1, -1000);
+ renderString(drawable, gl, textRenderUtil, "JOAL", c++, -1, -1000);
+ renderString(drawable, gl, textRenderUtil, "JOGL", c++, -1, -1000);
+ renderString(drawable, gl, textRenderUtil, "JOCL", c++, -1, -1000);
+
drawable.swapBuffers();
- sleep();
+ sleep();
// dispose
renderer.destroy(gl);
-
+
NEWTGLContext.destroyWindow(winctx);
- }
- int screenshot_num = 0;
-
+ }
+
int lastRow = -1;
-
- void renderString(GLDrawable drawable, GL2ES2 gl, TextRenderer renderer, String text, int column, int row, int z0) {
+
+ void renderString(GLDrawable drawable, GL2ES2 gl, TextRegionUtil textRenderUtil, String text, int column, int row, int z0) {
final int height = drawable.getHeight();
-
+
int dx = 0;
- int dy = height;
+ int dy = height;
if(0>row) {
row = lastRow + 1;
}
AABBox textBox = font.getStringBounds(text, fontSize);
dx += font.getAdvanceWidth('X', fontSize) * column;
dy -= (int)textBox.getHeight() * ( row + 1 );
- renderer.resetModelview(null);
- renderer.translate(gl, dx, dy, z0);
- renderer.drawString3D(gl, font, text, textPosition, fontSize, texSize);
-
+ textRenderUtil.renderer.resetModelview(null);
+ textRenderUtil.renderer.translate(gl, dx, dy, z0);
+ textRenderUtil.drawString3D(gl, font, fontSize, text, texSize);
+
lastRow = row;
- }
+ }
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java b/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java
index 1282d5d97..4b89a85fb 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java
@@ -34,22 +34,71 @@ import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.fixedfunc.GLMatrixFunc;
+import com.jogamp.graph.curve.opengl.GLRegion;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.curve.opengl.TextRenderer;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
+import com.jogamp.graph.curve.opengl.TextRegionUtil;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontFactory;
-import com.jogamp.graph.geom.opengl.SVertex;
-import com.jogamp.opengl.math.geom.AABBox;
+import com.jogamp.graph.font.FontSet;
+import com.jogamp.graph.geom.SVertex;
+import com.jogamp.newt.Window;
import com.jogamp.opengl.util.PMVMatrix;
import com.jogamp.opengl.util.glsl.ShaderState;
public abstract class TextRendererGLELBase implements GLEventListener {
- protected final float[] textPosition = new float[] {0,0,0};
- protected final int[] texSize = new int[] { 0 };
+ public final int usrRenderModes;
+
+ protected final int[] vbaaSampleCount;
protected final float[] staticRGBAColor = new float[] { 1f, 1f, 1f, 1f };
- protected final Font font;
- protected final int usrRenderModes;
+ private boolean exclusivePMVMatrix = true;
+ private PMVMatrix sharedPMVMatrix = null;
+ private RenderState rs = null;
+ private RegionRenderer.GLCallback enableCallback=null, disableCallback=null;
+ protected RegionRenderer renderer = null;
+ protected TextRegionUtil textRenderUtil = null;
+
+ /** scale pixel, default is 1f */
+ protected float pixelScale = 1.0f;
+
+ /** dpi display resolution, queried at {@link #init(GLAutoDrawable)} if NEWT, otherwise 96. */
+ protected float dpiH = 96;
+
+ boolean flipVerticalInGLOrientation = false;
+
+ /**
+ * @param fontSet e.g. default is {@link FontFactory#UBUNTU}
+ * @param fontFamily e.g. default is {@link FontSet#FAMILY_REGULAR}
+ * @param fontStylebits e.g. default is {@link FontSet#STYLE_NONE}
+ * @return the resulting font.
+ */
+ public static Font getFont(final int fontSet, final int fontFamily, final int fontStylebits) {
+ try {
+ return FontFactory.get(fontSet).get(fontFamily, fontStylebits);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * @param renderModes
+ * @param sampleCount desired multisampling sample count for msaa-rendering.
+ * @see #setRendererCallbacks(com.jogamp.graph.curve.opengl.RegionRenderer.GLCallback, com.jogamp.graph.curve.opengl.RegionRenderer.GLCallback)
+ */
+ public TextRendererGLELBase(final int renderModes, int[] sampleCount) {
+ this.usrRenderModes = renderModes;
+ this.vbaaSampleCount = sampleCount;
+ }
+
+ /**
+ * <p>
+ * Must be called before {@link #init(GLAutoDrawable)}.
+ * </p>
+ * @param rs
+ */
+ public void setRenderState(RenderState rs) { this.rs = rs; }
/**
* In exclusive mode, impl. uses a pixelScale of 1f and orthogonal PMV on window dimensions
@@ -58,54 +107,49 @@ public abstract class TextRendererGLELBase implements GLEventListener {
* In non-exclusive mode, i.e. shared w/ custom PMV (within another 3d scene),
* it uses the custom pixelScale and renderString uses normalized 'height', i.e. '1'.
* </p>
+ * <p>
+ * Must be called before {@link #init(GLAutoDrawable)}.
+ * </p>
*/
- protected boolean exclusivePMVMatrix = true;
- protected PMVMatrix usrPMVMatrix = null;
- protected RenderState rs = null;
- protected TextRenderer renderer = null;
-
- /** font size in pixels, default is 24 */
- protected int fontSize = 24;
- /** scale pixel, default is 1f */
- protected float pixelScale = 1.0f;
- protected int texSizeScale = 2;
-
- boolean flipVerticalInGLOrientation = false;
+ public void setSharedPMVMatrix(PMVMatrix pmv) {
+ this.sharedPMVMatrix = pmv;
+ }
- public TextRendererGLELBase(final int renderModes) {
- usrRenderModes = renderModes;
- {
- Font _font = null;
- try {
- _font = FontFactory.get(FontFactory.UBUNTU).getDefault();
- } catch (IOException e) {
- e.printStackTrace();
- }
- this.font = _font;
- }
+ /**
+ * See {@link RegionRenderer#create(RenderState, int, com.jogamp.graph.curve.opengl.RegionRenderer.GLCallback, com.jogamp.graph.curve.opengl.RegionRenderer.GLCallback)}.
+ * <p>
+ * Must be called before {@link #init(GLAutoDrawable)}.
+ * </p>
+ */
+ public void setRendererCallbacks(RegionRenderer.GLCallback enable, RegionRenderer.GLCallback disable) {
+ this.enableCallback = enable;
+ this.disableCallback = disable;
}
public void setFlipVerticalInGLOrientation(boolean v) { flipVerticalInGLOrientation=v; }
- public final TextRenderer getRenderer() { return renderer; }
+ public final RegionRenderer getRenderer() { return renderer; }
+ public final TextRegionUtil getTextRenderUtil() { return textRenderUtil; }
@Override
public void init(GLAutoDrawable drawable) {
- if( null != font ) {
- exclusivePMVMatrix = null == usrPMVMatrix;
- this.rs = RenderState.createRenderState(new ShaderState(), SVertex.factory(), usrPMVMatrix);
- this.renderer = TextRenderer.create(rs, usrRenderModes);
- if( 0 == usrRenderModes ) {
- texSizeScale = 0;
- }
- final GL2ES2 gl = drawable.getGL().getGL2ES2();
- renderer.init(gl);
- renderer.setAlpha(gl, staticRGBAColor[3]);
- renderer.setColorStatic(gl, staticRGBAColor[0], staticRGBAColor[1], staticRGBAColor[2]);
- final ShaderState st = rs.getShaderState();
- st.useProgram(gl, false);
- } else {
- this.rs = null;
- this.renderer = null;
+ if( null == this.rs ) {
+ exclusivePMVMatrix = null == sharedPMVMatrix;
+ this.rs = RenderState.createRenderState(new ShaderState(), SVertex.factory(), sharedPMVMatrix);
+ }
+ this.renderer = RegionRenderer.create(rs, usrRenderModes, enableCallback, disableCallback);
+ this.textRenderUtil = new TextRegionUtil(renderer);
+ final GL2ES2 gl = drawable.getGL().getGL2ES2();
+ renderer.init(gl);
+ renderer.setAlpha(gl, staticRGBAColor[3]);
+ renderer.setColorStatic(gl, staticRGBAColor[0], staticRGBAColor[1], staticRGBAColor[2]);
+ final ShaderState st = rs.getShaderState();
+ st.useProgram(gl, false);
+
+ final Object upObj = drawable.getUpstreamWidget();
+ if( upObj instanceof Window ) {
+ final float[] pixelsPerMM = new float[2];
+ ((Window)upObj).getMainMonitor().getPixelsPerMM(pixelsPerMM);
+ dpiH = pixelsPerMM[1]*25.4f;
}
}
@@ -123,7 +167,6 @@ public abstract class TextRendererGLELBase implements GLEventListener {
renderer.reshapeNotify(gl, width, height);
}
st.useProgram(gl, false);
- texSize[0] = width * texSizeScale;
}
}
@@ -140,13 +183,63 @@ public abstract class TextRendererGLELBase implements GLEventListener {
int lastRow = -1;
- public void renderString(GLAutoDrawable drawable, String text, int column, float tx, float ty, float tz) {
+ /**
+ *
+ * @param drawable
+ * @param font
+ * @param pixelSize Use {@link Font#getPixelSize(float, float)} for resolution correct pixel-size.
+ * @param text
+ * @param column
+ * @param tx
+ * @param ty
+ * @param tz
+ * @param cacheRegion
+ */
+ public void renderString(GLAutoDrawable drawable,
+ Font font, float pixelSize, String text,
+ int column, float tx, float ty, float tz, boolean cacheRegion) {
final int row = lastRow + 1;
- renderString(drawable, text, column, row, tx, ty, tz);
- lastRow = row;
+ renderStringImpl(drawable, font, pixelSize, text, column, row, tx, ty, tz, cacheRegion, null);
}
- public void renderString(GLAutoDrawable drawable, String text, int column, int row, float tx, float ty, float tz) {
+ public void renderString(GLAutoDrawable drawable,
+ Font font, float pixelSize, String text,
+ int column, float tx, float ty, float tz, GLRegion region) {
+ final int row = lastRow + 1;
+ renderStringImpl(drawable, font, pixelSize, text, column, row, tx, ty, tz, false, region);
+ }
+
+ /**
+ *
+ * @param drawable
+ * @param font
+ * @param pixelSize Use {@link Font#getPixelSize(float, float)} for resolution correct pixel-size.
+ * @param text
+ * @param column
+ * @param row
+ * @param tx
+ * @param ty
+ * @param tz
+ * @param cacheRegion
+ */
+ public void renderString(GLAutoDrawable drawable,
+ Font font, float pixelSize, String text,
+ int column, int row,
+ float tx, float ty, float tz, boolean cacheRegion) {
+ renderStringImpl(drawable, font, pixelSize, text, column, row, tx, ty, tz, cacheRegion, null);
+ }
+
+ public void renderString(GLAutoDrawable drawable,
+ Font font, float pixelSize, String text,
+ int column, int row,
+ float tx, float ty, float tz, GLRegion region) {
+ renderStringImpl(drawable, font, pixelSize, text, column, row, tx, ty, tz, false, region);
+ }
+
+ private void renderStringImpl(GLAutoDrawable drawable,
+ Font font, float pixelSize, String text,
+ int column, int row,
+ float tx, float ty, float tz, boolean cacheRegion, GLRegion region) {
if( null != renderer ) {
final GL2ES2 gl = drawable.getGL().getGL2ES2();
@@ -159,12 +252,11 @@ public abstract class TextRendererGLELBase implements GLEventListener {
final int height = drawable.getHeight();
dy = height-ty;
}
+ final int newLineCount = text.length() - text.replace("\n", "").length();
+ final float lineHeight = font.getLineHeight(pixelSize);
+ dx += pixelScale * font.getAdvanceWidth('X', pixelSize) * column;
+ dy -= pixelScale * lineHeight * ( row + 1 );
- final AABBox textBox = font.getStringBounds(text, fontSize);
- dx += pixelScale * font.getAdvanceWidth('X', fontSize) * column;
- dy -= pixelScale * (int)textBox.getHeight() * ( row + 1 );
-
- final ShaderState st = rs.getShaderState();
final PMVMatrix pmvMatrix = rs.pmvMatrix();
pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
if( !exclusivePMVMatrix ) {
@@ -172,24 +264,27 @@ public abstract class TextRendererGLELBase implements GLEventListener {
} else {
pmvMatrix.glLoadIdentity();
}
-
- st.useProgram(gl, true);
- gl.glEnable(GL2ES2.GL_BLEND);
pmvMatrix.glTranslatef(dx, dy, tz);
if( flipVerticalInGLOrientation && drawable.isGLOriented() ) {
pmvMatrix.glScalef(pixelScale, -1f*pixelScale, 1f);
} else if( 1f != pixelScale ) {
pmvMatrix.glScalef(pixelScale, pixelScale, 1f);
}
+ renderer.enable(gl, true);
renderer.updateMatrix(gl);
- renderer.drawString3D(gl, font, text, textPosition, fontSize, texSize);
- st.useProgram(gl, false);
- gl.glDisable(GL2ES2.GL_BLEND);
+ if( cacheRegion ) {
+ textRenderUtil.drawString3D(gl, font, pixelSize, text, vbaaSampleCount);
+ } else if( null != region ) {
+ TextRegionUtil.drawString3D(region, renderer, gl, font, pixelSize, text, vbaaSampleCount);
+ } else {
+ TextRegionUtil.drawString3D(renderer, gl, font, pixelSize, text, vbaaSampleCount);
+ }
+ renderer.enable(gl, false);
if( !exclusivePMVMatrix ) {
pmvMatrix.glPopMatrix();
}
- lastRow = -1;
+ lastRow = row + newLineCount;
}
}
-} \ No newline at end of file
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener01.java
index 46557e8c8..6dd86e10c 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener01.java
@@ -31,26 +31,27 @@ package com.jogamp.opengl.test.junit.graph.demos;
import javax.media.opengl.GL;
import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLAutoDrawable;
+
import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.graph.curve.opengl.GLRegion;
-import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.curve.opengl.RenderState;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
/** Demonstrate the rendering of multiple outlines into one region/OutlineShape
* These Outlines are not necessary connected or contained.
* The output of this demo shows two identical shapes but the left one
- * has some vertices with off-curve flag set to true, and the right allt he vertices
- * are on the curve. Demos the Res. Independent Nurbs based Curve rendering
+ * has some vertices with off-curve flag set to true, and the right allt he vertices
+ * are on the curve. Demos the Res. Independent Nurbs based Curve rendering
*
*/
public class GPURegionGLListener01 extends GPURegionRendererListenerBase01 {
OutlineShape outlineShape = null;
-
- public GPURegionGLListener01 (RenderState rs, int renderModes, int fbosize, boolean debug, boolean trace) {
+
+ public GPURegionGLListener01 (RenderState rs, int renderModes, int sampleCount, boolean debug, boolean trace) {
super(rs, renderModes, debug, trace);
- setMatrix(-20, 00, 0f, -50, fbosize);
+ setMatrix(-20, 00, -50, 0f, sampleCount);
}
-
+
private void createTestOutline(){
float offset = 0;
outlineShape = new OutlineShape(getRenderer().getRenderState().getVertexFactory());
@@ -61,14 +62,14 @@ public class GPURegionGLListener01 extends GPURegionRendererListenerBase01 {
outlineShape.addVertex(6.0f,15.0f, false);
outlineShape.addVertex(5.0f,8.0f, false);
outlineShape.addVertex(0.0f,10.0f,true);
- outlineShape.closeLastOutline();
+ outlineShape.closeLastOutline(true);
outlineShape.addEmptyOutline();
outlineShape.addVertex(5.0f,-5.0f,true);
outlineShape.addVertex(10.0f,-5.0f, false);
outlineShape.addVertex(10.0f,0.0f, true);
outlineShape.addVertex(5.0f,0.0f, false);
- outlineShape.closeLastOutline();
-
+ outlineShape.closeLastOutline(true);
+
/** Same shape as above but without any off-curve vertices */
offset = 30;
outlineShape.addEmptyOutline();
@@ -79,30 +80,31 @@ public class GPURegionGLListener01 extends GPURegionRendererListenerBase01 {
outlineShape.addVertex(offset+7.0f,15.0f, true);
outlineShape.addVertex(offset+6.0f,8.0f, true);
outlineShape.addVertex(offset+0.0f,10.0f, true);
- outlineShape.closeLastOutline();
+ outlineShape.closeLastOutline(true);
outlineShape.addEmptyOutline();
outlineShape.addVertex(offset+5.0f,0.0f, true);
outlineShape.addVertex(offset+5.0f,-5.0f, true);
outlineShape.addVertex(offset+10.0f,-5.0f, true);
outlineShape.addVertex(offset+10.0f,0.0f, true);
- outlineShape.closeLastOutline();
-
- region = GLRegion.create(outlineShape, getRenderModes());
+ outlineShape.closeLastOutline(true);
+
+ region = GLRegion.create(getRenderModes());
+ region.addOutlineShape(outlineShape, null);
}
public void init(GLAutoDrawable drawable) {
super.init(drawable);
-
+
GL2ES2 gl = drawable.getGL().getGL2ES2();
- final RegionRenderer regionRenderer = (RegionRenderer) getRenderer();
+ final RegionRenderer regionRenderer = getRenderer();
gl.setSwapInterval(1);
gl.glEnable(GL2ES2.GL_DEPTH_TEST);
gl.glEnable(GL2ES2.GL_BLEND);
regionRenderer.setAlpha(gl, 1.0f);
regionRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
-
+
createTestOutline();
}
@@ -112,14 +114,14 @@ public class GPURegionGLListener01 extends GPURegionRendererListenerBase01 {
gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
- final RegionRenderer regionRenderer = (RegionRenderer) getRenderer();
-
+ final RegionRenderer regionRenderer = getRenderer();
+
regionRenderer.resetModelview(null);
- regionRenderer.translate(null, getXTran(), getYTran(), getZoom());
+ regionRenderer.translate(null, getXTran(), getYTran(), getZTran());
regionRenderer.rotate(gl, getAngle(), 0, 1, 0);
if( weight != regionRenderer.getWeight()) {
regionRenderer.setWeight(gl, weight);
}
- regionRenderer.draw(gl, region, getPosition(), getTexSize());
- }
+ region.draw(gl, regionRenderer, getSampleCount());
+ }
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java
index 525c5e648..d0afc8ad0 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java
@@ -28,79 +28,85 @@
package com.jogamp.opengl.test.junit.graph.demos;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.media.opengl.GL;
import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLAutoDrawable;
import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.graph.curve.opengl.GLRegion;
-import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.curve.opengl.RenderState;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
/** Demonstrate the rendering of multiple OutlineShapes
* into one region
*
*/
public class GPURegionGLListener02 extends GPURegionRendererListenerBase01 {
- OutlineShape[] outlineShapes = new OutlineShape[2];
+ List<OutlineShape> outlineShapes = new ArrayList<OutlineShape>();
- public GPURegionGLListener02 (RenderState rs, int renderModes, int fbosize, boolean debug, boolean trace) {
+ public GPURegionGLListener02 (RenderState rs, int renderModes, int sampleCount, boolean debug, boolean trace) {
super(rs, renderModes, debug, trace);
- setMatrix(-20, 00, 0f, -50, fbosize);
+ setMatrix(-20, 00, -50, 0f, sampleCount);
}
-
+
private void createTestOutline(){
float offset = 0;
- outlineShapes[0] = new OutlineShape(getRenderer().getRenderState().getVertexFactory());
- outlineShapes[0].addVertex(0.0f,-10.0f,true);
- outlineShapes[0].addVertex(15.0f,-10.0f, true);
- outlineShapes[0].addVertex(10.0f,5.0f, false);
- outlineShapes[0].addVertex(15.0f,10.0f, true);
- outlineShapes[0].addVertex(6.0f,15.0f, false);
- outlineShapes[0].addVertex(5.0f,8.0f, false);
- outlineShapes[0].addVertex(0.0f,10.0f,true);
- outlineShapes[0].closeLastOutline();
- outlineShapes[0].addEmptyOutline();
- outlineShapes[0].addVertex(5.0f,-5.0f,true);
- outlineShapes[0].addVertex(10.0f,-5.0f, false);
- outlineShapes[0].addVertex(10.0f,0.0f, true);
- outlineShapes[0].addVertex(5.0f,0.0f, false);
- outlineShapes[0].closeLastOutline();
-
+ OutlineShape shape = new OutlineShape(getRenderer().getRenderState().getVertexFactory());
+ outlineShapes.add(shape);
+ shape.addVertex(0.0f,-10.0f,true);
+ shape.addVertex(15.0f,-10.0f, true);
+ shape.addVertex(10.0f,5.0f, false);
+ shape.addVertex(15.0f,10.0f, true);
+ shape.addVertex(6.0f,15.0f, false);
+ shape.addVertex(5.0f,8.0f, false);
+ shape.addVertex(0.0f,10.0f,true);
+ shape.closeLastOutline(true);
+ shape.addEmptyOutline();
+ shape.addVertex(5.0f,-5.0f,true);
+ shape.addVertex(10.0f,-5.0f, false);
+ shape.addVertex(10.0f,0.0f, true);
+ shape.addVertex(5.0f,0.0f, false);
+ shape.closeLastOutline(true);
+
/** Same shape as above but without any off-curve vertices */
- outlineShapes[1] = new OutlineShape(getRenderer().getRenderState().getVertexFactory());
+ shape = new OutlineShape(getRenderer().getRenderState().getVertexFactory());
+ outlineShapes.add(shape);
offset = 30;
- outlineShapes[1].addVertex(offset+0.0f,-10.0f, true);
- outlineShapes[1].addVertex(offset+17.0f,-10.0f, true);
- outlineShapes[1].addVertex(offset+11.0f,5.0f, true);
- outlineShapes[1].addVertex(offset+16.0f,10.0f, true);
- outlineShapes[1].addVertex(offset+7.0f,15.0f, true);
- outlineShapes[1].addVertex(offset+6.0f,8.0f, true);
- outlineShapes[1].addVertex(offset+0.0f,10.0f, true);
- outlineShapes[1].closeLastOutline();
- outlineShapes[1].addEmptyOutline();
- outlineShapes[1].addVertex(offset+5.0f,0.0f, true);
- outlineShapes[1].addVertex(offset+5.0f,-5.0f, true);
- outlineShapes[1].addVertex(offset+10.0f,-5.0f, true);
- outlineShapes[1].addVertex(offset+10.0f,0.0f, true);
- outlineShapes[1].closeLastOutline();
-
- region = GLRegion.create(outlineShapes, getRenderModes());
+ shape.addVertex(offset+0.0f,-10.0f, true);
+ shape.addVertex(offset+17.0f,-10.0f, true);
+ shape.addVertex(offset+11.0f,5.0f, true);
+ shape.addVertex(offset+16.0f,10.0f, true);
+ shape.addVertex(offset+7.0f,15.0f, true);
+ shape.addVertex(offset+6.0f,8.0f, true);
+ shape.addVertex(offset+0.0f,10.0f, true);
+ shape.closeLastOutline(true);
+ shape.addEmptyOutline();
+ shape.addVertex(offset+5.0f,0.0f, true);
+ shape.addVertex(offset+5.0f,-5.0f, true);
+ shape.addVertex(offset+10.0f,-5.0f, true);
+ shape.addVertex(offset+10.0f,0.0f, true);
+ shape.closeLastOutline(true);
+
+ region = GLRegion.create(getRenderModes());
+ region.addOutlineShapes(outlineShapes, null);
}
public void init(GLAutoDrawable drawable) {
super.init(drawable);
-
+
GL2ES2 gl = drawable.getGL().getGL2ES2();
- final RegionRenderer regionRenderer = (RegionRenderer) getRenderer();
+ final RegionRenderer regionRenderer = getRenderer();
gl.setSwapInterval(1);
gl.glEnable(GL2ES2.GL_DEPTH_TEST);
gl.glEnable(GL2ES2.GL_BLEND);
regionRenderer.setAlpha(gl, 1.0f);
regionRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
-
+
createTestOutline();
}
@@ -110,15 +116,15 @@ public class GPURegionGLListener02 extends GPURegionRendererListenerBase01 {
gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
- final RegionRenderer regionRenderer = (RegionRenderer) getRenderer();
-
+ final RegionRenderer regionRenderer = getRenderer();
+
regionRenderer.resetModelview(null);
- regionRenderer.translate(null, getXTran(), getYTran(), getZoom());
+ regionRenderer.translate(null, getXTran(), getYTran(), getZTran());
regionRenderer.rotate(gl, getAngle(), 0, 1, 0);
if( weight != regionRenderer.getWeight()) {
regionRenderer.setWeight(gl, weight);
}
- regionRenderer.draw(gl, region, getPosition(), getTexSize());
-
- }
+ region.draw(gl, regionRenderer, getSampleCount());
+
+ }
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java
index 160dc0ffe..c6c4b62ce 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java
@@ -28,13 +28,12 @@
package com.jogamp.opengl.test.junit.graph.demos;
-import javax.media.opengl.FPSCounter;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import com.jogamp.graph.curve.Region;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.newt.event.KeyAdapter;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.WindowAdapter;
@@ -46,14 +45,14 @@ import com.jogamp.opengl.util.glsl.ShaderState;
/** Demonstrate the rendering of multiple outlines into one region/OutlineShape
* These Outlines are not necessary connected or contained.
* The output of this demo shows two identical shapes but the left one
- * has some vertices with off-curve flag set to true, and the right allt he vertices
- * are on the curve. Demos the Res. Independent Nurbs based Curve rendering
+ * has some vertices with off-curve flag set to true, and the right allt he vertices
+ * are on the curve. Demos the Res. Independent Nurbs based Curve rendering
*
*/
public class GPURegionNewtDemo01 {
static final boolean DEBUG = false;
static final boolean TRACE = false;
-
+
public static void main(String[] args) {
GLProfile glp = GLProfile.getGL2ES2();
GLCapabilities caps = new GLCapabilities(glp);
@@ -61,25 +60,23 @@ public class GPURegionNewtDemo01 {
caps.setSampleBuffers(true);
caps.setNumSamples(4); // 2 samples is not enough ..
System.out.println("Requested: " + caps);
-
+
final GLWindow window = GLWindow.create(caps);
window.setPosition(10, 10);
window.setSize(800, 400);
window.setTitle("GPU Curve Region Newt Demo 01 - vbaa0 msaa1");
-
+
RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
GPURegionGLListener01 regionGLListener = new GPURegionGLListener01 (rs, Region.VARIABLE_CURVE_WEIGHT_BIT, 0, DEBUG, TRACE);
- regionGLListener.attachInputListenerTo(window);
+ regionGLListener.attachInputListenerTo(window);
window.addGLEventListener(regionGLListener);
-
- window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err);
window.setVisible(true);
//FPSAnimator animator = new FPSAnimator(60);
final Animator animator = new Animator();
- animator.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err);
+ animator.setUpdateFPSFrames(60, System.err);
animator.add(window);
-
+
window.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent arg0) {
if(arg0.getKeyCode() == KeyEvent.VK_F4) {
@@ -92,7 +89,7 @@ public class GPURegionNewtDemo01 {
animator.stop();
}
});
-
+
animator.start();
- }
+ }
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java
index e7b5c73c5..e7bd59aeb 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java
@@ -28,13 +28,12 @@
package com.jogamp.opengl.test.junit.graph.demos;
-import javax.media.opengl.FPSCounter;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import com.jogamp.graph.curve.Region;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.newt.event.KeyAdapter;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.WindowAdapter;
@@ -50,31 +49,29 @@ import com.jogamp.opengl.util.glsl.ShaderState;
public class GPURegionNewtDemo02 {
static final boolean DEBUG = false;
static final boolean TRACE = false;
-
+
public static void main(String[] args) {
GLProfile glp = GLProfile.getGL2ES2();
GLCapabilities caps = new GLCapabilities(glp);
- caps.setAlphaBits(4);
+ caps.setAlphaBits(4);
System.out.println("Requested: " + caps);
-
+
final GLWindow window = GLWindow.create(caps);
window.setPosition(10, 10);
window.setSize(800, 400);
window.setTitle("GPU Curve Region Newt Demo 02 - vbaa1 msaa0");
-
+
RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
- GPURegionGLListener02 regionGLListener = new GPURegionGLListener02 (rs, Region.VBAA_RENDERING_BIT|Region.VARIABLE_CURVE_WEIGHT_BIT, 1140, DEBUG, TRACE);
- regionGLListener.attachInputListenerTo(window);
+ GPURegionGLListener02 regionGLListener = new GPURegionGLListener02 (rs, Region.VBAA_RENDERING_BIT|Region.VARIABLE_CURVE_WEIGHT_BIT, 4, DEBUG, TRACE);
+ regionGLListener.attachInputListenerTo(window);
window.addGLEventListener(regionGLListener);
-
- window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err);
window.setVisible(true);
//FPSAnimator animator = new FPSAnimator(60);
final Animator animator = new Animator();
- animator.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err);
+ animator.setUpdateFPSFrames(60, System.err);
animator.add(window);
-
+
window.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent arg0) {
if(arg0.getKeyCode() == KeyEvent.VK_F4) {
@@ -87,7 +84,7 @@ public class GPURegionNewtDemo02 {
animator.stop();
}
});
-
+
animator.start();
- }
+ }
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionRendererListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionRendererListenerBase01.java
index 8439d1fff..9ececa082 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionRendererListenerBase01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionRendererListenerBase01.java
@@ -37,7 +37,7 @@ import com.jogamp.graph.curve.opengl.RenderState;
* - 1/2: zoom in/out
* - 3/4: font +/-
* - 6/7: 2nd pass texture size
- * - 0/9: rotate
+ * - 0/9: rotate
* - s: toogle draw 'font set'
* - f: toggle draw fps
* - v: toggle v-sync
@@ -47,6 +47,6 @@ public abstract class GPURegionRendererListenerBase01 extends GPURendererListene
OutlineShape outlineShape = null;
public GPURegionRendererListenerBase01(RenderState rs, int renderModes, boolean debug, boolean trace) {
- super(RegionRenderer.create(rs, renderModes), renderModes, debug, trace);
- }
-} \ No newline at end of file
+ super(RegionRenderer.create(rs, renderModes, RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable), renderModes, debug, trace);
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java
index 4ebb937a0..d5247eb51 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java
@@ -42,10 +42,9 @@ import javax.media.opengl.GLException;
import javax.media.opengl.GLPipelineFactory;
import javax.media.opengl.GLRunnable;
-
import com.jogamp.graph.curve.Region;
import com.jogamp.graph.curve.opengl.GLRegion;
-import com.jogamp.graph.curve.opengl.Renderer;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.KeyListener;
import com.jogamp.newt.opengl.GLWindow;
@@ -56,60 +55,64 @@ import com.jogamp.opengl.util.GLReadBufferUtil;
* Action Keys:
* - 1/2: zoom in/out
* - 6/7: 2nd pass texture size
- * - 0/9: rotate
+ * - 0/9: rotate
* - Q/W: change weight
* - v: toggle v-sync
* - s: screenshot
*/
public abstract class GPURendererListenerBase01 implements GLEventListener {
- private GLReadBufferUtil screenshot;
- private Renderer renderer;
- private int renderModes;
- private boolean debug;
- private boolean trace;
-
+ private final RegionRenderer renderer;
+ private final int renderModes;
+ private final boolean debug;
+ private final boolean trace;
+
protected GLRegion region;
+ private final GLReadBufferUtil screenshot;
+
private KeyAction keyAction;
-
+
private volatile GLAutoDrawable autoDrawable = null;
-
+
private final float[] position = new float[] {0,0,0};
+
+ protected final float zNear = 0.1f, zFar = 7000f;
private float xTran = -10;
- private float yTran = 10;
+ private float yTran = 10;
private float ang = 0f;
- private float zoom = -70f;
- private int[] texSize = new int[] { 400 };
+ private float zTran = -70f;
+ private final int[] sampleCount = new int[] { 4 };
protected volatile float weight = 1.0f;
boolean ignoreInput = false;
- public GPURendererListenerBase01(Renderer renderer, int renderModes, boolean debug, boolean trace) {
+ public GPURendererListenerBase01(RegionRenderer renderer, int renderModes, boolean debug, boolean trace) {
this.renderer = renderer;
this.renderModes = renderModes;
this.debug = debug;
this.trace = trace;
this.screenshot = new GLReadBufferUtil(false, false);
}
-
- public final Renderer getRenderer() { return renderer; }
+
+ public final RegionRenderer getRenderer() { return renderer; }
public final int getRenderModes() { return renderModes; }
- public final float getZoom() { return zoom; }
+ public final float getZTran() { return zTran; }
public final float getXTran() { return xTran; }
public final float getYTran() { return yTran; }
public final float getAngle() { return ang; }
- public final int[] getTexSize() { return texSize; }
+ public final int[] getSampleCount() { return sampleCount; }
public final float[] getPosition() { return position; }
- public void setMatrix(float xtrans, float ytrans, float angle, int zoom, int fbosize) {
+ public void setMatrix(float xtrans, float ytrans, int zTran, float angle, int sampleCount) {
this.xTran = xtrans;
- this.yTran = ytrans;
- this.ang = angle;
- this.zoom = zoom;
- this.texSize[0] = fbosize;
+ this.yTran = ytrans;
+ this.zTran = zTran;
+ this.ang = angle;
+ this.sampleCount[0] = sampleCount;
}
-
+
+ @Override
public void init(GLAutoDrawable drawable) {
autoDrawable = drawable;
GL2ES2 gl = drawable.getGL().getGL2ES2();
@@ -125,32 +128,34 @@ public abstract class GPURendererListenerBase01 implements GLEventListener {
gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
getRenderer().init(gl);
}
-
+
+ @Override
public void reshape(GLAutoDrawable drawable, int xstart, int ystart, int width, int height) {
GL2ES2 gl = drawable.getGL().getGL2ES2();
-
- gl.glViewport(xstart, ystart, width, height);
- renderer.reshapePerspective(gl, 45.0f, width, height, 0.1f, 7000.0f);
-
+
+ gl.glViewport(xstart, ystart, width, height);
+ renderer.reshapePerspective(gl, 45.0f, width, height, zNear, zFar);
+
dumpMatrix();
- System.err.println("Reshape: "+renderer.getRenderState());
+ // System.err.println("Reshape: "+renderer.getRenderState());
}
-
+
+ @Override
public void dispose(GLAutoDrawable drawable) {
autoDrawable = null;
GL2ES2 gl = drawable.getGL().getGL2ES2();
if(null != region) {
- region.destroy(gl, renderer.getRenderState());
+ region.destroy(gl, renderer);
}
screenshot.dispose(gl);
renderer.destroy(gl);
- }
-
+ }
+
public void zoom(int v){
- zoom += v;
+ zTran += v;
dumpMatrix();
}
-
+
public void move(float x, float y){
xTran += x;
yTran += y;
@@ -162,43 +167,43 @@ public abstract class GPURendererListenerBase01 implements GLEventListener {
dumpMatrix();
}
public void editGlobalWeight(float delta) {
- if( !Renderer.isWeightValid(weight+delta) ) {
+ if( !RegionRenderer.isWeightValid(weight+delta) ) {
return;
}
weight += delta;
System.err.println("Global Weight: "+ weight);
}
-
+
void dumpMatrix() {
- System.err.println("Matrix: " + xTran + "/" + yTran + " x"+zoom + " @"+ang);
+ System.err.println("Matrix: " + xTran + " / " + yTran + " / "+zTran + " @ "+ang);
}
-
- /** Attach the input listener to the window */
+
+ /** Attach the input listener to the window */
public void attachInputListenerTo(GLWindow window) {
if ( null == keyAction ) {
keyAction = new KeyAction();
- window.addKeyListener(keyAction);
+ window.addKeyListener(keyAction);
}
}
-
+
public void detachInputListenerFrom(GLWindow window) {
if ( null == keyAction ) {
return;
}
window.removeKeyListener(keyAction);
}
-
+
public void printScreen(GLAutoDrawable drawable, String dir, String tech, String objName, boolean exportAlpha) throws GLException, IOException {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
- pw.printf("-%03dx%03d-Z%04d-T%04d-%s", drawable.getWidth(), drawable.getHeight(), (int)Math.abs(zoom), texSize[0], objName);
-
+ pw.printf("-%03dx%03d-Z%04d-S%02d-%s", drawable.getWidth(), drawable.getHeight(), (int)Math.abs(zTran), sampleCount[0], objName);
+
final String filename = dir + tech + sw +".png";
if(screenshot.readPixels(drawable.getGL(), false)) {
screenshot.write(new File(filename));
}
}
-
+
int screenshot_num = 0;
public void setIgnoreInput(boolean v) {
@@ -207,13 +212,14 @@ public abstract class GPURendererListenerBase01 implements GLEventListener {
public boolean getIgnoreInput() {
return ignoreInput;
}
-
+
public class KeyAction implements KeyListener {
+ @Override
public void keyPressed(KeyEvent arg0) {
if(ignoreInput) {
return;
}
-
+
if(arg0.getKeyCode() == KeyEvent.VK_1){
zoom(10);
}
@@ -227,25 +233,25 @@ public abstract class GPURendererListenerBase01 implements GLEventListener {
move(0, 1);
}
else if(arg0.getKeyCode() == KeyEvent.VK_LEFT){
- move(1, 0);
+ move(-1, 0);
}
else if(arg0.getKeyCode() == KeyEvent.VK_RIGHT){
- move(-1, 0);
+ move(1, 0);
}
else if(arg0.getKeyCode() == KeyEvent.VK_6){
- texSize[0] -= 10;
- System.err.println("Tex Size: " + texSize[0]);
+ sampleCount[0] -= 1;
+ System.err.println("Sample Count: " + sampleCount[0]);
}
else if(arg0.getKeyCode() == KeyEvent.VK_7){
- texSize[0] += 10;
- System.err.println("Tex Size: " + texSize[0]);
- }
+ sampleCount[0] += 1;
+ System.err.println("Sample Count: " + sampleCount[0]);
+ }
else if(arg0.getKeyCode() == KeyEvent.VK_0){
rotate(1);
}
else if(arg0.getKeyCode() == KeyEvent.VK_9){
rotate(-1);
- }
+ }
else if(arg0.getKeyCode() == KeyEvent.VK_Q){
editGlobalWeight(-0.1f);
}
@@ -255,9 +261,10 @@ public abstract class GPURendererListenerBase01 implements GLEventListener {
else if(arg0.getKeyCode() == KeyEvent.VK_V) {
if(null != autoDrawable) {
autoDrawable.invoke(false, new GLRunnable() {
+ @Override
public boolean run(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
- int i = gl.getSwapInterval();
+ int i = gl.getSwapInterval();
i = i==0 ? 1 : 0;
gl.setSwapInterval(i);
final GLAnimatorControl a = drawable.getAnimator();
@@ -271,28 +278,31 @@ public abstract class GPURendererListenerBase01 implements GLEventListener {
return true;
}
});
- }
+ }
}
else if(arg0.getKeyCode() == KeyEvent.VK_S){
rotate(-1);
if(null != autoDrawable) {
autoDrawable.invoke(false, new GLRunnable() {
+ @Override
public boolean run(GLAutoDrawable drawable) {
try {
- final String type = Region.isVBAA(renderModes) ? "vbaa0-msaa1" : "vbaa1-msaa0" + ( Region.isNonUniformWeight(renderModes) ? "-vc" : "-uc" ) ;
+ final String modeS = Region.getRenderModeString(renderer.getRenderModes());
+ final String type = modeS + ( Region.isNonUniformWeight(renderModes) ? "-vc" : "-uc" ) ;
printScreen(drawable, "./", "demo-"+type, "snap"+screenshot_num, false);
screenshot_num++;
} catch (GLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
- }
+ }
return true;
}
});
- }
- }
+ }
+ }
}
+ @Override
public void keyReleased(KeyEvent arg0) {}
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextGLListener0A.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextGLListener0A.java
index 5c7d15ad1..29b897d0e 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextGLListener0A.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextGLListener0A.java
@@ -32,40 +32,33 @@ import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLAutoDrawable;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.curve.opengl.TextRenderer;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.newt.opengl.GLWindow;
-import com.jogamp.opengl.util.glsl.ShaderState;
public class GPUTextGLListener0A extends GPUTextRendererListenerBase01 {
-
- public GPUTextGLListener0A() {
- this( RenderState.createRenderState(new ShaderState(), SVertex.factory()), 0, 0, false, false ) ;
- }
-
- public GPUTextGLListener0A(RenderState rs, int numpass, int fbosize, boolean debug, boolean trace) {
- super(rs, numpass, debug, trace);
- setMatrix(-400, -30, 0f, -500, fbosize);
+
+ public GPUTextGLListener0A(RenderState rs, int renderModes, int sampleCount, boolean blending, boolean debug, boolean trace) {
+ super(rs, renderModes, sampleCount, blending, debug, trace);
}
-
+
public void init(GLAutoDrawable drawable) {
if(drawable instanceof GLWindow) {
final GLWindow glw = (GLWindow) drawable;
attachInputListenerTo(glw);
- }
+ }
super.init(drawable);
-
+
GL2ES2 gl = drawable.getGL().getGL2ES2();
-
- final TextRenderer textRenderer = (TextRenderer) getRenderer();
-
+
+ final RegionRenderer renderer = getRenderer();
+
gl.setSwapInterval(1);
gl.glEnable(GL2ES2.GL_DEPTH_TEST);
gl.glEnable(GL2ES2.GL_BLEND);
- textRenderer.setAlpha(gl, 1.0f);
- textRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
+ renderer.setAlpha(gl, 1.0f);
+ renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
}
-
+
public void dispose(GLAutoDrawable drawable) {
if(drawable instanceof GLWindow) {
final GLWindow glw = (GLWindow) drawable;
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java
index d257f78fc..de06310d7 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java
@@ -28,14 +28,11 @@
package com.jogamp.opengl.test.junit.graph.demos;
-import javax.media.opengl.FPSCounter;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
-
-import com.jogamp.graph.curve.opengl.GLRegion;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.newt.event.KeyAdapter;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.WindowAdapter;
@@ -47,7 +44,7 @@ import com.jogamp.opengl.util.glsl.ShaderState;
public class GPUTextNewtDemo01 {
static final boolean DEBUG = false;
static final boolean TRACE = false;
-
+
public static void main(String[] args) {
GLProfile glp = GLProfile.getGL2ES2();
GLCapabilities caps = new GLCapabilities(glp);
@@ -55,21 +52,20 @@ public class GPUTextNewtDemo01 {
caps.setSampleBuffers(true);
caps.setNumSamples(4); // 2 samples is not enough ..
System.out.println("Requested: "+caps);
-
- final GLWindow window = GLWindow.create(caps);
+
+ final GLWindow window = GLWindow.create(caps);
window.setPosition(10, 10);
window.setSize(800, 400);
- window.setTitle("GPU Text Newt Demo 01 - vbaa0 msaa1");
-
+ window.setTitle("GPU Text Newt Demo 01 - smsaa1");
+
final RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
- GPUTextGLListener0A textGLListener = new GPUTextGLListener0A(rs, 0, 0, DEBUG, TRACE);
+ GPUTextGLListener0A textGLListener = new GPUTextGLListener0A(rs, 0, 0, true, DEBUG, TRACE);
window.addGLEventListener(textGLListener);
- window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err);
-
+
final Animator animator = new Animator();
- animator.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err);
+ animator.setUpdateFPSFrames(60, System.err);
animator.add(window);
-
+
window.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent arg0) {
if(arg0.getKeyCode() == KeyEvent.VK_F4) {
@@ -82,9 +78,9 @@ public class GPUTextNewtDemo01 {
animator.stop();
}
});
-
+
window.setVisible(true);
// FPSAnimator animator = new FPSAnimator(10);
animator.start();
- }
+ }
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java
index 1b71cd781..3dc03788b 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java
@@ -27,13 +27,12 @@
*/
package com.jogamp.opengl.test.junit.graph.demos;
-import javax.media.opengl.FPSCounter;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import com.jogamp.graph.curve.Region;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.newt.event.KeyAdapter;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.WindowAdapter;
@@ -45,42 +44,50 @@ import com.jogamp.opengl.util.glsl.ShaderState;
public class GPUTextNewtDemo02 {
/**
* FIXME:
- *
+ *
* If DEBUG is enabled:
- *
- * Caused by: javax.media.opengl.GLException: Thread[main-Display-X11_:0.0-1-EDT-1,5,main] glGetError() returned the following error codes after a call to glFramebufferRenderbuffer(<int> 0x8D40, <int> 0x1902, <int> 0x8D41, <int> 0x1): GL_INVALID_ENUM ( 1280 0x500),
+ *
+ * Caused by: javax.media.opengl.GLException: Thread[main-Display-X11_:0.0-1-EDT-1,5,main] glGetError() returned the following error codes after a call to glFramebufferRenderbuffer(<int> 0x8D40, <int> 0x1902, <int> 0x8D41, <int> 0x1): GL_INVALID_ENUM ( 1280 0x500),
* at javax.media.opengl.DebugGL4bc.checkGLGetError(DebugGL4bc.java:33961)
* at javax.media.opengl.DebugGL4bc.glFramebufferRenderbuffer(DebugGL4bc.java:33077)
* at jogamp.graph.curve.opengl.VBORegion2PGL3.initFBOTexture(VBORegion2PGL3.java:295)
*/
static final boolean DEBUG = false;
static final boolean TRACE = false;
-
+
public static void main(String[] args) {
- GLProfile glp = GLProfile.getGL2ES2();
-
+ boolean alpha = true;
+ boolean blending = true;
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-noblend")) {
+ blending = false;
+ } else if(args[i].equals("-noalpha")) {
+ alpha = false;
+ }
+ }
+
+ final GLProfile glp = GLProfile.getGL2ES2();
+
GLCapabilities caps = new GLCapabilities(glp);
- caps.setAlphaBits(4);
+ caps.setAlphaBits( alpha ? 4 : 0 );
System.out.println("Requested: "+caps);
-
+
final GLWindow window = GLWindow.create(caps);
-
+
window.setPosition(10, 10);
- window.setSize(800, 400);
- window.setTitle("GPU Text Newt Demo 02 - vbaa1 msaa0");
-
+ window.setSize(800, 400);
+ window.setTitle("GPU Text Newt Demo 02 - gvbaa4 gmsaa0");
+
RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
- GPUTextGLListener0A textGLListener = new GPUTextGLListener0A(rs, Region.VBAA_RENDERING_BIT, window.getWidth()*3, DEBUG, TRACE);
+ GPUTextGLListener0A textGLListener = new GPUTextGLListener0A(rs, Region.VBAA_RENDERING_BIT, 4, blending, DEBUG, TRACE);
// ((TextRenderer)textGLListener.getRenderer()).setCacheLimit(32);
window.addGLEventListener(textGLListener);
-
- window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err);
window.setVisible(true);
// FPSAnimator animator = new FPSAnimator(60);
final Animator animator = new Animator();
- animator.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err);
+ animator.setUpdateFPSFrames(60, System.err);
animator.add(window);
-
+
window.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent arg0) {
if(arg0.getKeyCode() == KeyEvent.VK_F4) {
@@ -93,7 +100,7 @@ public class GPUTextNewtDemo02 {
animator.stop();
}
});
-
+
animator.start();
- }
+ }
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo03.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo03.java
new file mode 100644
index 000000000..9174d69af
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo03.java
@@ -0,0 +1,96 @@
+/**
+ * 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.opengl.test.junit.graph.demos;
+
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+
+import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.RenderState;
+import com.jogamp.graph.geom.SVertex;
+import com.jogamp.newt.event.KeyAdapter;
+import com.jogamp.newt.event.KeyEvent;
+import com.jogamp.newt.event.WindowAdapter;
+import com.jogamp.newt.event.WindowEvent;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.glsl.ShaderState;
+
+public class GPUTextNewtDemo03 {
+ /**
+ * FIXME:
+ *
+ * If DEBUG is enabled:
+ *
+ * Caused by: javax.media.opengl.GLException: Thread[main-Display-X11_:0.0-1-EDT-1,5,main] glGetError() returned the following error codes after a call to glFramebufferRenderbuffer(<int> 0x8D40, <int> 0x1902, <int> 0x8D41, <int> 0x1): GL_INVALID_ENUM ( 1280 0x500),
+ * at javax.media.opengl.DebugGL4bc.checkGLGetError(DebugGL4bc.java:33961)
+ * at javax.media.opengl.DebugGL4bc.glFramebufferRenderbuffer(DebugGL4bc.java:33077)
+ * at jogamp.graph.curve.opengl.VBORegion2PGL3.initFBOTexture(VBORegion2PGL3.java:295)
+ */
+ static final boolean DEBUG = false;
+ static final boolean TRACE = false;
+
+ public static void main(String[] args) {
+ GLProfile glp = GLProfile.getGL2ES2();
+
+ GLCapabilities caps = new GLCapabilities(glp);
+ caps.setAlphaBits(4);
+ System.out.println("Requested: "+caps);
+
+ final GLWindow window = GLWindow.create(caps);
+
+ window.setPosition(10, 10);
+ window.setSize(800, 400);
+ window.setTitle("GPU Text Newt Demo 03 - gvbaa0 gmsaa4");
+
+ RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
+ GPUTextGLListener0A textGLListener = new GPUTextGLListener0A(rs, Region.MSAA_RENDERING_BIT, 4, true, DEBUG, TRACE);
+ // ((TextRenderer)textGLListener.getRenderer()).setCacheLimit(32);
+ window.addGLEventListener(textGLListener);
+ window.setVisible(true);
+ // FPSAnimator animator = new FPSAnimator(60);
+ final Animator animator = new Animator();
+ animator.setUpdateFPSFrames(60, System.err);
+ animator.add(window);
+
+ window.addKeyListener(new KeyAdapter() {
+ public void keyPressed(KeyEvent arg0) {
+ if(arg0.getKeyCode() == KeyEvent.VK_F4) {
+ window.destroy();
+ }
+ }
+ });
+ window.addWindowListener(new WindowAdapter() {
+ public void windowDestroyed(WindowEvent e) {
+ animator.stop();
+ }
+ });
+
+ animator.start();
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java
index 1dc104cbb..d77b0032d 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java
@@ -35,14 +35,19 @@ import javax.media.opengl.GLAnimatorControl;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLException;
+import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.GLRegion;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.curve.opengl.TextRenderer;
+import com.jogamp.graph.curve.opengl.TextRegionUtil;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontFactory;
+import com.jogamp.newt.Window;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.KeyListener;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.math.geom.AABBox;
+import com.jogamp.opengl.util.PMVMatrix;
/**
*
@@ -52,7 +57,7 @@ import com.jogamp.opengl.math.geom.AABBox;
* - 0/9: rotate
* - v: toggle v-sync
* - s: screenshot
- *
+ *
* Additional Keys:
* - 3/4: font +/-
* - h: toogle draw 'font set'
@@ -61,145 +66,248 @@ import com.jogamp.opengl.math.geom.AABBox;
* - i: live input text input (CR ends it, backspace supported)
*/
public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerBase01 {
+ public final TextRegionUtil textRegionUtil;
+ private final GLRegion regionFPS;
+ private final boolean useBlending;
int fontSet = FontFactory.UBUNTU;
Font font;
-
+
int headType = 0;
- boolean drawFPS = false;
- final int fontSizeFixed = 6;
- int fontSize = 40;
+ boolean drawFPS = true;
+ final float fontSizeFName = 8f;
+ final float fontSizeFPS = 10f;
+ final int[] sampleCountFPS = new int[] { 8 };
+ float fontSizeHead = 12f;
+ float fontSizeBottom = 16f;
+ float dpiH = 96;
final int fontSizeModulo = 100;
String fontName;
AABBox fontNameBox;
String headtext;
AABBox headbox;
-
+
static final String text1 = "abcdefghijklmnopqrstuvwxyz\nABCDEFGHIJKLMNOPQRSTUVWXYZ\n0123456789.:,;(*!?/\\\")$%^&-+@~#<>{}[]";
static final String text2 = "The quick brown fox jumps over the lazy dog";
- static final String textX =
+ static final String textX =
"JOGAMP graph demo using Resolution Independent NURBS\n"+
"JOGAMP JOGL - OpenGL ES2 profile\n"+
"Press 1/2 to zoom in/out the below text\n"+
+ "Press 3/4 to incr/decs font size (alt: head, w/o bottom)\n"+
"Press 6/7 to edit texture size if using VBAA\n"+
"Press 0/9 to rotate the below string\n"+
"Press v to toggle vsync\n"+
"Press i for live input text input (CR ends it, backspace supported)\n"+
- "Press f to toggle fps. H for different text, space for font type\n";
-
- static final String textX2 =
+ "Press f to toggle fps. H for different text, space for font type\n";
+
+ static final String textX2 =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec sapien tellus. \n"+
"Ut purus odio, rhoncus sit amet commodo eget, ullamcorper vel urna. Mauris ultricies \n"+
"quam iaculis urna cursus ornare. Nullam ut felis a ante ultrices ultricies nec a elit. \n"+
- "In hac habitasse platea dictumst. Vivamus et mi a quam lacinia pharetra at venenatis est.\n"+
+ "In hac habitasse platea dictumst. Vivamus et mi a quam lacinia pharetra at venenatis est.\n"+
"Morbi quis bibendum nibh. Donec lectus orci, sagittis in consequat nec, volutpat nec nisi.\n"+
"Donec ut dolor et nulla tristique varius. In nulla magna, fermentum id tempus quis, semper \n"+
"in lorem. Maecenas in ipsum ac justo scelerisque sollicitudin. Quisque sit amet neque lorem,\n" +
- "-------Press H to change text---------\n";
-
+ "-------Press H to change text---------";
+
StringBuilder userString = new StringBuilder();
boolean userInput = false;
-
- public GPUTextRendererListenerBase01(RenderState rs, int modes, boolean debug, boolean trace) {
- super(TextRenderer.create(rs, modes), modes, debug, trace);
+ public GPUTextRendererListenerBase01(RenderState rs, int renderModes, int sampleCount, boolean blending, boolean debug, boolean trace) {
+ // NOTE_ALPHA_BLENDING: We use alpha-blending
+ super(RegionRenderer.create(rs, renderModes,
+ blending ? RegionRenderer.defaultBlendEnable : null,
+ blending ? RegionRenderer.defaultBlendDisable : null),
+ renderModes, debug, trace);
+ this.useBlending = blending;
+ this.textRegionUtil = new TextRegionUtil(this.getRenderer());
+ this.regionFPS = GLRegion.create(renderModes);
try {
this.font = FontFactory.get(fontSet).getDefault();
dumpFontNames();
-
+
this.fontName = font.toString();
- this.fontNameBox = font.getStringBounds(fontName, fontSizeFixed*2);
- switchHeadBox();
} catch (IOException ioe) {
System.err.println("Catched: "+ioe.getMessage());
ioe.printStackTrace();
}
+ setMatrix(0, 0, 0, 0f, sampleCount);
}
void dumpFontNames() {
System.err.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.err.println(font.getAllNames(null, "\n"));
- System.err.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
+ System.err.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
}
-
+
void switchHeadBox() {
- headType = ( headType + 1 ) % 4 ;
+ headType = ( headType + 1 ) % 4 ;
switch(headType) {
case 0:
headtext = null;
break;
-
+
case 1:
headtext= textX2;
break;
case 2:
headtext= textX;
break;
-
+
default:
- headtext = text1;
+ headtext = text1;
}
if(null != headtext) {
- headbox = font.getStringBounds(headtext, fontSizeFixed*3);
+ headbox = font.getStringBounds(headtext, font.getPixelSize(fontSizeHead, dpiH));
+ }
+ }
+
+ @Override
+ public void init(GLAutoDrawable drawable) {
+ super.init(drawable);
+ final Object upObj = drawable.getUpstreamWidget();
+ if( upObj instanceof Window ) {
+ final float[] pixelsPerMM = new float[2];
+ ((Window)upObj).getMainMonitor().getPixelsPerMM(pixelsPerMM);
+ dpiH = pixelsPerMM[1]*25.4f;
}
+ fontNameBox = font.getStringBounds(fontName, font.getPixelSize(fontSizeFName, dpiH));
+ switchHeadBox();
+
}
+ @Override
+ public void dispose(GLAutoDrawable drawable) {
+ regionFPS.destroy(drawable.getGL().getGL2ES2(), getRenderer());
+ super.dispose(drawable);
+ }
+
+ public static void mapWin2ObjectCoords(final PMVMatrix pmv, final int[] view,
+ final float zNear, final float zFar,
+ float orthoX, float orthoY, float orthoDist,
+ final float[] winZ, final float[] objPos) {
+ winZ[0] = (1f/zNear-1f/orthoDist)/(1f/zNear-1f/zFar);
+ pmv.gluUnProject(orthoX, orthoY, winZ[0], view, 0, objPos, 0);
+ }
+ public static void translateOrtho(final String msg,
+ final PMVMatrix pmv, final int[] view,
+ final float zNear, final float zFar,
+ float orthoX, float orthoY, float orthoDist,
+ final float[] winZ, final float[] objPos) {
+ mapWin2ObjectCoords(pmv, view, zNear, zFar, orthoX, orthoY, orthoDist, winZ, objPos);
+ pmv.glTranslatef(objPos[0], objPos[1], objPos[2]);
+ /**
+ System.err.printf("XXX %7s: [%5.1f, %5.1f, [%5.1f -> %5.1f]] --> [%8.3f, %8.3f, %8.3f]%n",
+ msg, orthoX, orthoY, orthoDist, winZ[0], objPos[0], objPos[1], objPos[2]); */
+ }
+
+ @Override
public void display(GLAutoDrawable drawable) {
final int width = drawable.getWidth();
final int height = drawable.getHeight();
GL2ES2 gl = drawable.getGL().getGL2ES2();
-
- gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Demo02 needs to have this set here as well .. hmm ?
+
+ gl.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
- final TextRenderer textRenderer = (TextRenderer) getRenderer();
- textRenderer.reshapeOrtho(null, width, height, 0.1f, 7000.0f);
- textRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
- final GLAnimatorControl animator = drawable.getAnimator();
- final boolean _drawFPS = drawFPS && null != animator && animator.getTotalFPSFrames()>10;
-
- if(_drawFPS) {
- final float fps = animator.getTotalFPS();
- final String fpsS = String.valueOf(fps);
- final int fpsSp = fpsS.indexOf('.');
- textRenderer.resetModelview(null);
- textRenderer.translate(gl, fontSizeFixed, fontSizeFixed, -6000);
- textRenderer.drawString3D(gl, font, fpsS.substring(0, fpsSp+2)+" fps", getPosition(), fontSizeFixed*3, getTexSize());
+ final float zDistance0 = 500f;
+ final float zDistance1 = 400f;
+ final float[] objPos = new float[3];
+ final float[] winZ = new float[1];
+ final int[] view = new int[] { 0, 0, drawable.getWidth(), drawable.getHeight() };
+
+ final RegionRenderer renderer = getRenderer();
+ final PMVMatrix pmv = renderer.getMatrix();
+ renderer.resetModelview(null);
+ renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
+ if( useBlending ) {
+ // NOTE_ALPHA_BLENDING:
+ // Due to alpha blending and VBAA, we need a background in text color
+ // otherwise blending will amplify 'white'!
+ gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ }
+
+ final float pixelSizeFName = font.getPixelSize(fontSizeFName, dpiH);
+ final float pixelSizeHead = font.getPixelSize(fontSizeHead, dpiH);
+ final float pixelSizeBottom = font.getPixelSize(fontSizeBottom, dpiH);
+
+ if( drawFPS ) {
+ final float pixelSizeFPS = font.getPixelSize(fontSizeFPS, dpiH);
+ final float lfps, tfps, td;
+ final GLAnimatorControl animator = drawable.getAnimator();
+ if( null != animator ) {
+ lfps = animator.getLastFPS();
+ tfps = animator.getTotalFPS();
+ td = animator.getTotalFPSDuration()/1000f;
+ } else {
+ lfps = 0f;
+ tfps = 0f;
+ td = 0f;
+ }
+ final String modeS = Region.getRenderModeString(renderer.getRenderModes());
+ final String text = String.format("%03.1f/%03.1f fps, v-sync %d, fontSize [head %.1f, bottom %.1f], %s-samples [%d, this %d], td %4.1f, blend %b, alpha-bits %d",
+ lfps, tfps, gl.getSwapInterval(), fontSizeHead, fontSizeBottom, modeS, getSampleCount()[0], sampleCountFPS[0], td,
+ useBlending, drawable.getChosenGLCapabilities().getAlphaBits());
+
+ // bottom, half line up
+ renderer.resetModelview(null);
+ translateOrtho("fpstxt", pmv, view, zNear, zFar, 0, pixelSizeFPS/2, zDistance0, winZ, objPos);
+ renderer.updateMatrix(gl);
+
+ // No cache, keep region alive!
+ TextRegionUtil.drawString3D(regionFPS, renderer, gl, font, pixelSizeFPS, text, sampleCountFPS);
+ }
+
+ float dx = width-fontNameBox.getWidth()-2f;
+ float dy = height - 10f;
+
+ renderer.resetModelview(null);
+ translateOrtho("fontxt", pmv, view, zNear, zFar, dx, dy, zDistance0, winZ, objPos);
+ renderer.updateMatrix(gl);
+ textRegionUtil.drawString3D(gl, font, pixelSizeFName, fontName, getSampleCount());
+
+ dx = 10f;
+ dy += -fontNameBox.getHeight() - 10f;
+
+ if(null != headtext) {
+ renderer.resetModelview(null);
+ translateOrtho("headtx", pmv, view, zNear, zFar, dx, dy, zDistance0, winZ, objPos);
+ renderer.updateMatrix(gl);
+ textRegionUtil.drawString3D(gl, font, pixelSizeHead, headtext, getSampleCount());
}
-
- int dx = width-(int)fontNameBox.getWidth()-2 ;
- int dy = height - 10;
-
- textRenderer.resetModelview(null);
- textRenderer.translate(gl, dx, dy, -6000);
- textRenderer.drawString3D(gl, font, fontName, getPosition(), fontSizeFixed*2, getTexSize());
-
- dx = 10;
- dy += -(int)fontNameBox.getHeight() - 10;
-
- if(null != headtext) {
- textRenderer.resetModelview(null);
- textRenderer.translate(gl, dx, dy, -6000);
- textRenderer.drawString3D(gl, font, headtext, getPosition(), fontSizeFixed*3, getTexSize());
+
+ dy += -headbox.getHeight() - font.getLineHeight(pixelSizeBottom);
+
+ renderer.resetModelview(null);
+ translateOrtho("Bottom", pmv, view, zNear, zFar, dx, dy, zDistance1, winZ, objPos);
+ renderer.translate(null, getXTran(), getYTran(), getZTran());
+ renderer.rotate(gl, getAngle(), 0, 1, 0);
+ renderer.setColorStatic(gl, 1.0f, 0.0f, 0.0f);
+ if( useBlending ) {
+ // NOTE_ALPHA_BLENDING:
+ // Due to alpha blending and VBAA, we need a background in text color
+ // otherwise blending will amplify 'white'!
+ gl.glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
}
-
- textRenderer.reshapePerspective(null, 45.0f, width, height, 0.1f, 7000.0f);
- textRenderer.resetModelview(null);
- textRenderer.translate(null, getXTran(), getYTran(), getZoom());
- textRenderer.rotate(gl, getAngle(), 0, 1, 0);
- textRenderer.setColorStatic(gl, 1.0f, 0.0f, 0.0f);
if(!userInput) {
- textRenderer.drawString3D(gl, font, text2, getPosition(), fontSize, getTexSize());
+ textRegionUtil.drawString3D(gl, font, pixelSizeBottom, text2, getSampleCount());
} else {
- textRenderer.drawString3D(gl, font, userString.toString(), getPosition(), fontSize, getTexSize());
+ textRegionUtil.drawString3D(gl, font, pixelSizeBottom, userString.toString(), getSampleCount());
}
- }
-
- public void fontIncr(int v) {
- fontSize = Math.abs((fontSize + v) % fontSizeModulo) ;
+ }
+
+ public void fontBottomIncr(int v) {
+ fontSizeBottom = Math.abs((fontSizeBottom + v) % fontSizeModulo) ;
dumpMatrix(true);
}
- public boolean nextFontSet() {
+ public void fontHeadIncr(int v) {
+ fontSizeHead = Math.abs((fontSizeHead + v) % fontSizeModulo) ;
+ if(null != headtext) {
+ headbox = font.getStringBounds(headtext, font.getPixelSize(fontSizeHead, dpiH));
+ }
+ }
+
+ public boolean nextFontSet() {
try {
int set = ( fontSet == FontFactory.UBUNTU ) ? FontFactory.JAVA : FontFactory.UBUNTU ;
Font _font = FontFactory.get(set).getDefault();
@@ -207,7 +315,7 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
fontSet = set;
font = _font;
fontName = font.getFullFamilyName(null).toString();
- fontNameBox = font.getStringBounds(fontName, fontSizeFixed*3);
+ fontNameBox = font.getStringBounds(fontName, font.getPixelSize(fontSizeFName, dpiH));
dumpFontNames();
return true;
}
@@ -216,7 +324,7 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
}
return false;
}
-
+
public boolean setFontSet(int set, int family, int stylebits) {
try {
Font _font = FontFactory.get(set).get(family, stylebits);
@@ -224,7 +332,7 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
fontSet = set;
font = _font;
fontName = font.getFullFamilyName(null).toString();
- fontNameBox = font.getStringBounds(fontName, fontSizeFixed*3);
+ fontNameBox = font.getStringBounds(fontName, font.getPixelSize(fontSizeFName, dpiH));
dumpFontNames();
return true;
}
@@ -233,25 +341,25 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
}
return false;
}
-
+
public boolean isUserInputMode() { return userInput; }
-
+
void dumpMatrix(boolean bbox) {
- System.err.println("Matrix: " + getXTran() + "/" + getYTran() + " x"+getZoom() + " @"+getAngle() +" fontSize "+fontSize);
+ System.err.println("Matrix: " + getXTran() + "/" + getYTran() + " x"+getZTran() + " @"+getAngle() +" fontSize "+fontSizeBottom);
if(bbox) {
- System.err.println("bbox: "+font.getStringBounds(text2, fontSize));
+ System.err.println("bbox: "+font.getStringBounds(text2, font.getPixelSize(fontSizeBottom, dpiH)));
}
}
-
+
KeyAction keyAction = null;
-
+
@Override
public void attachInputListenerTo(GLWindow window) {
if ( null == keyAction ) {
keyAction = new KeyAction();
window.addKeyListener(keyAction);
- super.attachInputListenerTo(window);
- }
+ super.attachInputListenerTo(window);
+ }
}
@Override
@@ -262,31 +370,42 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
}
window.removeKeyListener(keyAction);
}
-
+
public void printScreen(GLAutoDrawable drawable, String dir, String tech, boolean exportAlpha) throws GLException, IOException {
- final String fn = font.getFullFamilyName(null).toString();
+ final String fn = font.getFullFamilyName(null).toString();
printScreen(drawable, dir, tech, fn.replace(' ', '_'), exportAlpha);
}
-
+
+ float fontHeadScale = 1f;
+
public class KeyAction implements KeyListener {
+ @Override
public void keyPressed(KeyEvent e) {
if(userInput) {
return;
}
- final short s = e.getKeySymbol();
+ final short s = e.getKeySymbol();
if(s == KeyEvent.VK_3) {
- fontIncr(10);
+ if( e.isAltDown() ) {
+ fontHeadIncr(1);
+ } else {
+ fontBottomIncr(1);
+ }
}
else if(s == KeyEvent.VK_4) {
- fontIncr(-10);
+ if( e.isAltDown() ) {
+ fontHeadIncr(-1);
+ } else {
+ fontBottomIncr(-1);
+ }
}
else if(s == KeyEvent.VK_H) {
switchHeadBox();
- }
+ }
else if(s == KeyEvent.VK_F) {
- drawFPS = !drawFPS;
- }
- else if(s == KeyEvent.VK_SPACE) {
+ drawFPS = !drawFPS;
+ }
+ else if(s == KeyEvent.VK_SPACE) {
nextFontSet();
}
else if(s == KeyEvent.VK_I) {
@@ -294,12 +413,13 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
setIgnoreInput(true);
}
}
-
+
+ @Override
public void keyReleased(KeyEvent e) {
if( !e.isPrintableKey() || e.isAutoRepeat() ) {
return;
- }
- if(userInput) {
+ }
+ if(userInput) {
final short k = e.getKeySymbol();
if( KeyEvent.VK_ENTER == k ) {
userInput = false;
@@ -308,7 +428,7 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
userString.deleteCharAt(userString.length()-1);
} else {
final char c = e.getKeyChar();
- if( font.isPrintableChar( c ) ) {
+ if( font.isPrintableChar( c ) ) {
userString.append(c);
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java
index 59ce28408..aef3ab4bd 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java
@@ -11,76 +11,76 @@ import javax.media.opengl.GLPipelineFactory;
import javax.media.opengl.GLRunnable;
import com.jogamp.graph.curve.Region;
-import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.curve.opengl.RenderState;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontFactory;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
+import com.jogamp.newt.Window;
import com.jogamp.newt.event.MouseAdapter;
import com.jogamp.newt.event.MouseEvent;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.test.junit.graph.demos.ui.Label;
import com.jogamp.opengl.test.junit.graph.demos.ui.RIButton;
import com.jogamp.opengl.test.junit.graph.demos.ui.SceneUIController;
-import com.jogamp.opengl.test.junit.graph.demos.ui.opengl.UIRegion;
import com.jogamp.opengl.util.glsl.ShaderState;
public class GPUUISceneGLListener0A implements GLEventListener {
private boolean debug = false;
- private boolean trace = false;
-
+ private boolean trace = false;
+
private final int renderModes;
- private final int[] texSize = new int[1];
- private final int renderModes2;
- private final int[] texSize2 = new int[1];
- private RegionRenderer regionRenderer;
- private RenderState rs;
-
+ private final int[] sampleCount = new int[1];
+ private final int[] texSize2 = new int[1];
+ private final RenderState rs;
+ private final boolean useBlending;
+ private final SceneUIController sceneUIController;
+ protected final float zNear = 0.1f, zFar = 7000f;
+
+ private RegionRenderer renderer;
+
int fontSet = FontFactory.UBUNTU;
Font font;
- final int fontSizeFixed = 6;
-
+ final float fontSizeFixed = 6;
+ float dpiH = 96;
+
private float xTran = 0;
- private float yTran = 0;
+ private float yTran = 0;
private float ang = 0f;
private float zoom = -200f;
- private float zoomText = 1f;
+ private final float zoomText = 1f;
private int currentText = 0;
-
+
private Label[] labels = null;
private String[] strings = null;
- private UIRegion[] labelRegions;
- private UIRegion fpsRegion = null;
- private UIRegion jogampRegion = null;
private RIButton[] buttons = null;
-
- private int numSelectable = 6;
-
- private SceneUIController sceneUIController = null;
+ private Label jogampLabel = null;
+ private Label fpsLabel = null;
+ private final int numSelectable = 6;
+
private MultiTouchListener multiTouchListener = null;
private boolean showFPS = false;
private GLAutoDrawable cDrawable;
- private float fps = 0;
-
- private String jogamp = "JogAmp - Jogl Graph Module Demo";
- private float angText = 0;
-
+
+ private final String jogamp = "JogAmp - Jogl Graph Module Demo";
+ private final float angText = 0;
+
public GPUUISceneGLListener0A() {
this(0);
}
-
+
public GPUUISceneGLListener0A(int renderModes) {
this(RenderState.createRenderState(new ShaderState(), SVertex.factory()), renderModes, false, false);
}
-
+
public GPUUISceneGLListener0A(RenderState rs, int renderModes, boolean debug, boolean trace) {
this.rs = rs;
this.renderModes = renderModes;
- this.texSize[0] = Region.isVBAA(renderModes) ? 400 : 0;
- this.renderModes2 = 0;
+ this.sampleCount[0] = 4;
this.texSize2[0] = 0;
-
+ this.useBlending = true;
+
this.debug = debug;
this.trace = trace;
try {
@@ -89,19 +89,18 @@ public class GPUUISceneGLListener0A implements GLEventListener {
System.err.println("Catched: "+ioe.getMessage());
ioe.printStackTrace();
}
- labelRegions = new UIRegion[3];
sceneUIController = new SceneUIController();
}
-
+
private void initButtons(int width, int height) {
buttons = new RIButton[numSelectable];
int xaxis = -110;
float xSize = 40f;
float ySize = 16f;
-
+
int start = 50;
int diff = (int)ySize + 5;
-
+
buttons[0] = new RIButton(SVertex.factory(), font, "Next Text", xSize, ySize){
public void onClick() {
currentText = (currentText+1)%3;
@@ -109,9 +108,9 @@ public class GPUUISceneGLListener0A implements GLEventListener {
public void onPressed() { }
public void onRelease() { }
};
-
- buttons[0].setPosition(xaxis,start,0);
-
+
+ buttons[0].translate(xaxis,start);
+
buttons[1] = new RIButton(SVertex.factory(), font, "Show FPS", xSize, ySize){
public void onClick() {
final GLAnimatorControl a = cDrawable.getAnimator();
@@ -120,12 +119,10 @@ public class GPUUISceneGLListener0A implements GLEventListener {
}
showFPS = !showFPS;
}
- public void onPressed() { }
- public void onRelease() { }
};
- buttons[1].setPosition(xaxis,start - diff,0);
+ buttons[1].translate(xaxis,start - diff);
buttons[1].setToggleable(true);
-
+
buttons[2] = new RIButton(SVertex.factory(), font, "v-sync", xSize, ySize){
public void onClick() {
cDrawable.invoke(false, new GLRunnable() {
@@ -140,72 +137,68 @@ public class GPUUISceneGLListener0A implements GLEventListener {
}
});
}
- public void onPressed() { }
- public void onRelease() { }
};
- buttons[2].setPosition(xaxis,start-diff*2,0);
+ buttons[2].translate(xaxis,start-diff*2);
buttons[2].setToggleable(true);
-
+
buttons[3] = new RIButton(SVertex.factory(), font, "Tilt +Y", xSize, ySize) {
- public void onClick() {
+ public void onClick() {
ang+=10;
}
- public void onPressed() {
-
- }
- public void onRelease() { }
};
- buttons[3].setPosition(xaxis,start-diff*3,0);
-
+ buttons[3].translate(xaxis,start-diff*3);
+
buttons[4] = new RIButton(SVertex.factory(), font, "Tilt -Y", xSize, ySize){
public void onClick() {
ang-=10;
}
- public void onPressed() { }
- public void onRelease() { }
};
- buttons[4].setPosition(xaxis,start-diff*4,0);
-
+ buttons[4].translate(xaxis,start-diff*4);
+
buttons[5] = new RIButton(SVertex.factory(), font, "Quit", xSize, ySize){
public void onClick() {
cDrawable.destroy();
}
- public void onPressed() { }
- public void onRelease() { }
};
- buttons[5].setPosition(xaxis,start-diff*5,0);
- buttons[5].setButtonColor(0.8f, 0.0f, 0.0f);
+ buttons[5].translate(xaxis,start-diff*5);
+ buttons[5].setColor(0.8f, 0.0f, 0.0f);
buttons[5].setLabelColor(1.0f, 1.0f, 1.0f);
-
- buttons[5].setButtonSelectedColor(0.8f, 0.8f, 0.8f);
+
+ buttons[5].setSelectedColor(0.8f, 0.8f, 0.8f);
buttons[5].setLabelSelectedColor(0.8f, 0.0f, 0.0f);
}
-
+
private void initTexts() {
strings = new String[3];
-
+
strings[0] = "abcdefghijklmn\nopqrstuvwxyz\nABCDEFGHIJKL\nMNOPQRSTUVWXYZ\n0123456789.:,;(*!?/\\\")$%^&-+@~#<>{}[]";
strings[1] = "The quick brown fox\njumps over the lazy\ndog";
-
- strings[2] =
+
+ strings[2] =
"Lorem ipsum dolor sit amet, consectetur\n"+
"Ut purus odio, rhoncus sit amet com\n"+
"quam iaculis urna cursus ornare. Nullam\n"+
- "In hac habitasse platea dictumst. Vivam\n"+
+ "In hac habitasse platea dictumst. Vivam\n"+
"Morbi quis bibendum nibh. Donec lectus\n"+
"Donec ut dolor et nulla tristique variu\n"+
"in lorem. Maecenas in ipsum ac justo sc\n";
-
+
labels = new Label[3];
}
public void init(GLAutoDrawable drawable) {
+ final Object upObj = drawable.getUpstreamWidget();
+ if( upObj instanceof Window ) {
+ final float[] pixelsPerMM = new float[2];
+ ((Window)upObj).getMainMonitor().getPixelsPerMM(pixelsPerMM);
+ dpiH = pixelsPerMM[1]*25.4f;
+ }
if(drawable instanceof GLWindow) {
System.err.println("GPUUISceneGLListener0A: init (1)");
final GLWindow glw = (GLWindow) drawable;
attachInputListenerTo(glw);
} else {
- System.err.println("GPUUISceneGLListener0A: init (0)");
+ System.err.println("GPUUISceneGLListener0A: init (0)");
}
final int width = drawable.getWidth();
final int height = drawable.getHeight();
@@ -217,46 +210,42 @@ public class GPUUISceneGLListener0A implements GLEventListener {
if(trace) {
gl = gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", null, gl, new Object[] { System.err } ) ).getGL2ES2();
}
-
+
try {
font = FontFactory.get(fontSet).getDefault();
} catch (IOException ioe) {
System.err.println("Catched: "+ioe.getMessage());
ioe.printStackTrace();
}
-
- regionRenderer = RegionRenderer.create(rs, renderModes);
-
+
+ renderer = RegionRenderer.create(rs, renderModes, RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
+
gl.glEnable(GL2ES2.GL_DEPTH_TEST);
gl.glEnable(GL2ES2.GL_BLEND);
-
- regionRenderer.init(gl);
- regionRenderer.setAlpha(gl, 1.0f);
- regionRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
-
+
+ renderer.init(gl);
+ renderer.setAlpha(gl, 1.0f);
+ renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
+
initTexts();
initButtons(width, height);
-
- sceneUIController.setRenderer(regionRenderer, rs, renderModes, texSize);
+
+ sceneUIController.setRenderer(renderer, renderModes, sampleCount);
sceneUIController.addShape(buttons[0]);
sceneUIController.addShape(buttons[1]);
sceneUIController.addShape(buttons[2]);
sceneUIController.addShape(buttons[3]);
sceneUIController.addShape(buttons[4]);
sceneUIController.addShape(buttons[5]);
- drawable.addGLEventListener(sceneUIController);
-
- Label jlabel = new Label(SVertex.factory(), font, fontSizeFixed, jogamp){
- public void onClick() { }
- public void onPressed() { }
- public void onRelease() { }
- };
-
- jogampRegion = new UIRegion(jlabel);
+ sceneUIController.init(drawable);
+
+ final float pixelSizeFixed = font.getPixelSize(fontSizeFixed, dpiH);
+ jogampLabel = new Label(SVertex.factory(), font, pixelSizeFixed, jogamp);
+
final GLAnimatorControl a = drawable.getAnimator();
if( null != a ) {
a.resetFPSCounter();
- }
+ }
}
public void dispose(GLAutoDrawable drawable) {
@@ -265,95 +254,87 @@ public class GPUUISceneGLListener0A implements GLEventListener {
final GLWindow glw = (GLWindow) drawable;
detachInputListenerFrom(glw);
} else {
- System.err.println("GPUUISceneGLListener0A: dispose (0)");
+ System.err.println("GPUUISceneGLListener0A: dispose (0)");
}
- // sceneUIController will remove itself from the drawable!
-
+ sceneUIController.dispose(drawable);
+
GL2ES2 gl = drawable.getGL().getGL2ES2();
- regionRenderer.destroy(gl);
+ renderer.destroy(gl);
}
public void display(GLAutoDrawable drawable) {
// System.err.println("GPUUISceneGLListener0A: display");
- final int width = drawable.getWidth();
- final int height = drawable.getHeight();
GL2ES2 gl = drawable.getGL().getGL2ES2();
-
+
gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
-
- regionRenderer.reshapePerspective(null, 45.0f, width, height, 0.1f, 7000.0f);
+
+ renderer.resetModelview(null);
sceneUIController.setTranslate(xTran, yTran, zoom);
sceneUIController.setRotation(0, ang, 0);
-
- renderScene(drawable);
- }
-
- private void renderScene(GLAutoDrawable drawable) {
- GL2ES2 gl = drawable.getGL().getGL2ES2();
-
- regionRenderer.resetModelview(null);
- regionRenderer.translate(null, xTran-50, yTran+43, zoom);
- regionRenderer.translate(gl, 0, 30, 0);
- regionRenderer.scale(null, zoomText, zoomText, 1);
- regionRenderer.scale(gl, 1.5f, 1.5f, 1.0f);
- regionRenderer.rotate(gl, angText , 0, 1, 0);
- regionRenderer.setColorStatic(gl, 0.0f, 1.0f, 0.0f);
- regionRenderer.draw(gl, jogampRegion.getRegion(gl, rs, 0), new float[]{0,0,0}, null);
-
- if(null == labelRegions[currentText]) {
- if( null == labels[currentText]) {
- labels[currentText] = new Label(SVertex.factory(), font, fontSizeFixed, strings[currentText]){
- public void onClick() { }
- public void onPressed() { }
- public void onRelease() { }
- };
- }
- labelRegions[currentText] = new UIRegion(labels[currentText]);
+ sceneUIController.display(drawable);
+
+ final float pixelSizeFixed = font.getPixelSize(fontSizeFixed, dpiH);
+
+ renderer.resetModelview(null);
+ renderer.translate(null, xTran-50, yTran+43, zoom);
+ renderer.translate(gl, 0, 30, 0);
+ renderer.scale(null, zoomText, zoomText, 1);
+ renderer.scale(gl, 1.5f, 1.5f, 1.0f);
+ renderer.rotate(gl, angText , 0, 1, 0);
+ renderer.setColorStatic(gl, 0.0f, 1.0f, 0.0f);
+ jogampLabel.drawShape(gl, renderer, sampleCount, false);
+ if(null == labels[currentText]) {
+ labels[currentText] = new Label(SVertex.factory(), font, pixelSizeFixed, strings[currentText]);
}
-
- regionRenderer.resetModelview(null);
- regionRenderer.translate(null, xTran-50, yTran, zoom);
- regionRenderer.translate(gl, 0, 30, 0);
- regionRenderer.scale(null, zoomText, zoomText, 1);
- regionRenderer.scale(gl, 1.5f, 1.5f, 1.0f);
- regionRenderer.rotate(gl, zoomText, 0, 1, 0);
-
- regionRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
- regionRenderer.draw(gl, labelRegions[currentText].getRegion(gl, rs, renderModes2), new float[]{0,0,0}, texSize2);
-
- final GLAnimatorControl animator = drawable.getAnimator();
- final boolean _drawFPS = showFPS && null != animator;
-
- if(_drawFPS && fps != animator.getTotalFPS()) {
- if(null != fpsRegion) {
- fpsRegion.destroy(gl, rs);
+
+ renderer.resetModelview(null);
+ renderer.translate(null, xTran-50, yTran, zoom);
+ renderer.translate(gl, 0, 30, 0);
+ renderer.scale(null, zoomText, zoomText, 1);
+ renderer.scale(gl, 1.5f, 1.5f, 1.0f);
+ renderer.rotate(gl, zoomText, 0, 1, 0);
+
+ renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
+ labels[currentText].drawShape(gl, renderer, sampleCount, false);
+
+ if( showFPS ) {
+ final float lfps, tfps, td;
+ final GLAnimatorControl animator = drawable.getAnimator();
+ if( null != animator ) {
+ lfps = animator.getLastFPS();
+ tfps = animator.getTotalFPS();
+ td = animator.getTotalFPSDuration()/1000f;
+ } else {
+ lfps = 0f;
+ tfps = 0f;
+ td = 0f;
+ }
+ final String modeS = Region.getRenderModeString(renderer.getRenderModes());
+ final String text = String.format("%03.1f/%03.1f fps, v-sync %d, fontSize %.1f, %s-samples %d, td %4.1f, blend %b, alpha-bits %d",
+ lfps, tfps, gl.getSwapInterval(), fontSizeFixed, modeS, sampleCount[0], td,
+ useBlending, drawable.getChosenGLCapabilities().getAlphaBits());
+ if(null != fpsLabel) {
+ fpsLabel.clear(gl, renderer);
+ fpsLabel.setText(text);
+ fpsLabel.setPixelSize(pixelSizeFixed);
+ } else {
+ fpsLabel = new Label(renderer.getRenderState().getVertexFactory(), font, pixelSizeFixed, text);
}
- fps = animator.getTotalFPS();
- final String fpsS = String.valueOf(fps);
- final int fpsSp = fpsS.indexOf('.');
-
- Label fpsLabel = new Label(SVertex.factory(), font, fontSizeFixed, fpsS.substring(0, fpsSp+2)+" fps"){
- public void onClick() { }
- public void onPressed() { }
- public void onRelease() { }
- };
- fpsRegion = new UIRegion(fpsLabel);
- }
- if(showFPS && null != fpsRegion) {
- regionRenderer.translate(gl, 0, -60, 0);
- regionRenderer.scale(null, zoomText, zoomText, 1);
- regionRenderer.draw(gl, fpsRegion.getRegion(gl, rs, 0), new float[]{0,0,0}, null);
+ renderer.translate(gl, 0, -60, 0);
+ renderer.scale(null, zoomText, zoomText, 1);
+ fpsLabel.drawShape(gl, renderer, sampleCount, false);
}
}
-
+
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
System.err.println("GPUUISceneGLListener0A: reshape");
GL2ES2 gl = drawable.getGL().getGL2ES2();
-
- gl.glViewport(x, y, width, height);
- regionRenderer.reshapePerspective(gl, 45.0f, width, height, 5f, 70.0f);
+
+ gl.glViewport(x, y, width, height);
+ renderer.reshapePerspective(gl, 45.0f, width, height, zNear, zFar);
+ sceneUIController.reshape(drawable, x, y, width, height);
}
public void attachInputListenerTo(GLWindow window) {
@@ -363,23 +344,23 @@ public class GPUUISceneGLListener0A implements GLEventListener {
sceneUIController.attachInputListenerTo(window);
}
}
-
+
public void detachInputListenerFrom(GLWindow window) {
if ( null != multiTouchListener ) {
window.removeMouseListener(multiTouchListener);
sceneUIController.detachInputListenerFrom(window);
}
}
-
+
private class MultiTouchListener extends MouseAdapter {
int lx = 0;
int ly = 0;
-
+
boolean first = false;
-
+
@Override
public void mousePressed(MouseEvent e) {
- first = true;
+ first = true;
}
@Override
@@ -399,9 +380,9 @@ public class GPUUISceneGLListener0A implements GLEventListener {
}
int nv = Math.abs(e.getY(0)-e.getY(1));
int dy = nv - lx;
-
+
zoom += 2 * Math.signum(dy);
-
+
lx = nv;
} else {
// 1 pointer drag
@@ -413,7 +394,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
}
int nx = e.getX();
int ny = e.getY();
- int dx = nx - lx;
+ int dx = nx - lx;
int dy = ny - ly;
if(Math.abs(dx) > Math.abs(dy)){
xTran += Math.signum(dx);
@@ -425,7 +406,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
ly = ny;
}
}
-
+
@Override
public void mouseWheelMoved(MouseEvent e) {
if( !e.isShiftDown() ) {
@@ -433,4 +414,4 @@ public class GPUUISceneGLListener0A implements GLEventListener {
}
}
}
-} \ No newline at end of file
+} \ No newline at end of file
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java
index 0563ab2cf..17b9642d9 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java
@@ -4,7 +4,7 @@ import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.newt.event.WindowAdapter;
import com.jogamp.newt.event.WindowEvent;
import com.jogamp.newt.opengl.GLWindow;
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo02.java
index 4c8da139e..a4673f0c5 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo02.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo02.java
@@ -5,7 +5,7 @@ import javax.media.opengl.GLProfile;
import com.jogamp.graph.curve.Region;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.newt.event.WindowAdapter;
import com.jogamp.newt.event.WindowEvent;
import com.jogamp.newt.opengl.GLWindow;
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/MSAATool.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/MSAATool.java
index 4cddb1340..ea593ec7d 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/MSAATool.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/MSAATool.java
@@ -45,27 +45,27 @@ public class MSAATool {
} catch (Exception e) {
System.err.println("Catched Exception: "+e.getMessage());
// e.printStackTrace();
- }
+ }
return isEnabled;
}
public static void dump(GLAutoDrawable drawable) {
float[] vf = new float[] { 0f };
byte[] vb = new byte[] { 0 };
int[] vi = new int[] { 0, 0 };
-
+
System.out.println("GL MSAA SETUP:");
GL2ES2 gl = drawable.getGL().getGL2ES2();
GLCapabilitiesImmutable caps = drawable.getChosenGLCapabilities();
- System.out.println(" Caps realised "+caps);
+ System.out.println(" Caps realised "+caps);
System.out.println(" Caps sample buffers "+caps.getSampleBuffers()+", samples "+caps.getNumSamples());
-
+
System.out.println(" GL MULTISAMPLE "+glIsEnabled(gl, GL2ES2.GL_MULTISAMPLE));
- // sample buffers min 0, same as GLX_SAMPLE_BUFFERS_ARB or WGL_SAMPLE_BUFFERS_ARB
+ // sample buffers min 0, same as GLX_SAMPLE_BUFFERS_ARB or WGL_SAMPLE_BUFFERS_ARB
gl.glGetIntegerv(GL2GL3.GL_SAMPLE_BUFFERS, vi, 0);
// samples min 0
gl.glGetIntegerv(GL2GL3.GL_SAMPLES, vi, 1);
System.out.println(" GL SAMPLE_BUFFERS "+vi[0]+", SAMPLES "+vi[1]);
-
+
System.out.println("GL CSAA SETUP:");
// default FALSE
System.out.println(" GL SAMPLE COVERAGE "+glIsEnabled(gl, GL2GL3.GL_SAMPLE_COVERAGE));
@@ -76,8 +76,21 @@ public class MSAATool {
// default FALSE, value 1, invert false
gl.glGetFloatv(GL2GL3.GL_SAMPLE_COVERAGE_VALUE, vf, 0);
gl.glGetBooleanv(GL2GL3.GL_SAMPLE_COVERAGE_INVERT, vb, 0);
- System.out.println(" GL SAMPLE_COVERAGE "+glIsEnabled(gl, GL2GL3.GL_SAMPLE_COVERAGE) +
+ System.out.println(" GL SAMPLE_COVERAGE "+glIsEnabled(gl, GL2GL3.GL_SAMPLE_COVERAGE) +
": SAMPLE_COVERAGE_VALUE "+vf[0]+
- ", SAMPLE_COVERAGE_INVERT "+vb[0]);
+ ", SAMPLE_COVERAGE_INVERT "+vb[0]);
+ dumpBlend(gl);
+ }
+ public static void dumpBlend(GL gl) {
+ int[] vi = new int[] { 0, 0, 0, 0 };
+ gl.glGetIntegerv(GL.GL_BLEND, vi, 0);
+ gl.glGetIntegerv(GL.GL_BLEND_SRC_ALPHA, vi, 1);
+ gl.glGetIntegerv(GL.GL_BLEND_SRC_RGB, vi, 2);
+ gl.glGetIntegerv(GL.GL_BLEND_DST_RGB, vi, 3);
+ final boolean blendEnabled = vi[0] == GL.GL_TRUE;
+ System.out.println("GL_BLEND "+blendEnabled+"/"+glIsEnabled(gl, GL.GL_BLEND) +
+ " GL_SRC_ALPHA 0x"+Integer.toHexString(vi[1])+
+ " GL_SRC_RGB 0x"+Integer.toHexString(vi[2])+
+ " GL_DST_RGB 0x"+Integer.toHexString(vi[3]));
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java
index 4fef2d8c2..6275f25d2 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java
@@ -29,77 +29,83 @@ package com.jogamp.opengl.test.junit.graph.demos.ui;
import javax.media.opengl.GL2ES2;
-import jogamp.graph.curve.text.GlyphString;
+import jogamp.graph.geom.plane.AffineTransform;
+import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.graph.curve.opengl.RegionRenderer;
-import com.jogamp.graph.curve.opengl.RenderState;
+import com.jogamp.graph.curve.opengl.TextRegionUtil;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.geom.Vertex.Factory;
+import com.jogamp.opengl.math.geom.AABBox;
-public abstract class Label extends UIShape implements UITextShape {
+public class Label extends UIShape {
protected Font font;
- protected int size;
+ protected float pixelSize;
protected String text;
- protected GlyphString glyphString;
-
- public Label(Factory<? extends Vertex> factory, Font font, int size, String text) {
+
+ public Label(Factory<? extends Vertex> factory, Font font, float pixelSize, String text) {
super(factory);
this.font = font;
- this.size = size;
+ this.pixelSize = pixelSize;
this.text = text;
}
-
- public GlyphString getGlyphString() {
- return glyphString;
- }
-
+
public String getText() {
return text;
}
-
+
public void setText(String text) {
this.text = text;
- dirty |= DIRTY_SHAPE;
+ dirty |= DIRTY_SHAPE | DIRTY_REGION;
}
-
+
public Font getFont() {
return font;
}
public void setFont(Font font) {
this.font = font;
- dirty |= DIRTY_SHAPE;
+ dirty |= DIRTY_SHAPE | DIRTY_REGION;
}
- public int getSize() {
- return size;
+ public float getPixelSize() {
+ return pixelSize;
}
- public void setSize(int size) {
- this.size = size;
- dirty |= DIRTY_SHAPE;
+ public void setPixelSize(float pixelSize) {
+ this.pixelSize = pixelSize;
+ dirty |= DIRTY_SHAPE | DIRTY_REGION;
}
- public String toString(){
- return "Label [" + font.toString() + ", size " + size + ", " + getText() + "]";
+ @Override
+ protected void clearImpl(GL2ES2 gl, RegionRenderer renderer) {
}
@Override
- protected void clearImpl() {
- if(null != glyphString) {
- glyphString.destroy(null, null);
- }
+ protected void destroyImpl(GL2ES2 gl, RegionRenderer renderer) {
}
-
+
+ private final TextRegionUtil.ShapeVisitor shapeVisitor = new TextRegionUtil.ShapeVisitor() {
+ final float[] tmp = new float[3];
+ @Override
+ public void visit(OutlineShape shape, AffineTransform t) {
+ shapes.add(new TransformedShape(shape, new AffineTransform(t)));
+ final AABBox sbox = shape.getBounds();
+ t.transform(sbox.getLow(), tmp);
+ box.resize(tmp, 0);
+ t.transform(sbox.getHigh(), tmp);
+ box.resize(tmp, 0);
+ }
+ };
+
@Override
- protected void createShape() {
- clearImpl();
- glyphString = GlyphString.createString(shape, getVertexFactory(), font, size, text);
+ protected void createShape(GL2ES2 gl, RegionRenderer renderer) {
+ TextRegionUtil.processString(shapeVisitor, new AffineTransform(renderer.getRenderState().getVertexFactory()), font, pixelSize, text);
}
@Override
- public void render(GL2ES2 gl, RenderState rs, RegionRenderer renderer,
- int renderModes, int[/*1*/] texSize, boolean selection) {
+ public String toString(){
+ return "Label [" + font.toString() + ", size " + pixelSize + ", " + getText() + "]";
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java
index 12c90f87d..df0e504c6 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java
@@ -29,40 +29,35 @@ package com.jogamp.opengl.test.junit.graph.demos.ui;
import javax.media.opengl.GL2ES2;
+import jogamp.graph.geom.plane.AffineTransform;
+
+import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.graph.curve.opengl.RegionRenderer;
-import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.geom.Vertex.Factory;
import com.jogamp.opengl.math.geom.AABBox;
-import com.jogamp.opengl.test.junit.graph.demos.ui.opengl.UIRegion;
-/** GPU based resolution independent Button impl
+/**
+ * GPU based resolution independent Button impl
*/
public abstract class RIButton extends UIShape {
private float width, height;
- private Label label;
+ private final Label label;
private float spacing = 4.0f;
private float corner = 1.0f;
private float labelZOffset = -0.05f;
-
- private float[] buttonColor = {0.6f, 0.6f, 0.6f};
- private float[] buttonSelectedColor = {0.8f,0.8f,0.8f};
- private float[] labelColor = {1.0f, 1.0f, 1.0f};
- private float[] labelSelectedColor = {0.1f, 0.1f, 0.1f};
-
-
+
public RIButton(Factory<? extends Vertex> factory, Font labelFont, String labelText, float width, float height) {
super(factory);
-
+
// FIXME: Determine font size - PMV Matrix relation ?
// this.label = new Label(factory, labelFont, (int)(height - 2f * spacing), labelText);
- this.label = new Label(factory, labelFont, 10, labelText){
- public void onClick() { }
- public void onPressed() { }
- public void onRelease() { }
- };
-
+ this.label = new Label(factory, labelFont, 10, labelText);
+ this.label.setSelectedColor(this.color[0], this.color[1], this.color[2]);
+ this.label.setColor(0.9f, 0.9f, 0.9f);
+ this.label.setSelectedColor(1f, 1f, 1f);
+
this.width = width;
this.height = height;
}
@@ -75,63 +70,77 @@ public abstract class RIButton extends UIShape {
public void setDimension(int width, int height) {
this.width = width;
this.height = height;
- dirty |= DIRTY_SHAPE;
+ dirty |= DIRTY_SHAPE | DIRTY_REGION;
+ }
+
+ @Override
+ protected void clearImpl(GL2ES2 gl, RegionRenderer renderer) {
+ label.clear(gl, renderer);
}
-
+
@Override
- protected void clearImpl() {
- label.clear();
+ protected void destroyImpl(GL2ES2 gl, RegionRenderer renderer) {
+ label.destroy(gl, renderer);
}
-
+
@Override
- protected void createShape() {
- // FIXME: Only possible if all data (color) is
- // is incl. in Outline Shape.
- // Until then - draw each separately!
- //shape.addOutlinShape( label.getShape() );
- label.updateShape();
-
- final AABBox lbox = label.getBounds();
+ public void drawShape(GL2ES2 gl, RegionRenderer renderer, int[] sampleCount, boolean select) {
+ gl.glEnable(GL2ES2.GL_POLYGON_OFFSET_FILL);
+ gl.glPolygonOffset(0.0f, 1f);
+ super.drawShape(gl, renderer, sampleCount, select);
+ gl.glDisable(GL2ES2.GL_POLYGON_OFFSET_FILL);
+
+ label.drawShape(gl, renderer, sampleCount, select);
+ }
+
+ @Override
+ protected void createShape(GL2ES2 gl, RegionRenderer renderer) {
+ label.createShape(gl, renderer);
+ box.resize(label.getBounds());
+
+ final float sx = getWidth() / ( 2f*spacing + box.getWidth() );
+ final float sy = getHeight() / ( 2f*spacing + box.getHeight() );
+ scale(sx, sy, 1);
+
+ final OutlineShape shape = new OutlineShape(renderer.getRenderState().getVertexFactory());
if(corner == 0.0f) {
- createSharpOutline(lbox);
+ createSharpOutline(shape, box);
} else {
- createCurvedOutline(lbox);
+ createCurvedOutline(shape, box);
}
- float sx = getWidth() / ( 2f*spacing + lbox.getWidth() );
- float sy = getHeight() / ( 2f*spacing + lbox.getHeight() );
-
- setScale(sx, sy, 1);
+ box.resize(shape.getBounds());
+ shapes.add(new TransformedShape(shape, new AffineTransform(renderer.getRenderState().getVertexFactory())));
+ System.err.println("XXX.UIShape.RIButton: Added Shape: "+shape+", "+box);
}
-
-
- private void createSharpOutline(AABBox lbox) {
+ private void createSharpOutline(OutlineShape shape, AABBox lbox) {
float th = (2f*spacing) + lbox.getHeight();
float tw = (2f*spacing) + lbox.getWidth();
-
+
float minX = lbox.getMinX()-spacing;
float minY = lbox.getMinY()-spacing;
float minZ = labelZOffset;
-
+
shape.addVertex(minX, minY, minZ, true);
shape.addVertex(minX+tw, minY, minZ, true);
shape.addVertex(minX+tw, minY + th, minZ, true);
shape.addVertex(minX, minY + th, minZ, true);
- shape.closeLastOutline();
+ shape.closeLastOutline(true);
}
-
- private void createCurvedOutline(AABBox lbox){
- float th = 2.0f*spacing + lbox.getHeight();
- float tw = 2.0f*spacing + lbox.getWidth();
-
- float cw = 0.5f*corner*Math.min(tw, th);
- float ch = 0.5f*corner*Math.min(tw, th);
-
+ private void createCurvedOutline(OutlineShape shape, AABBox lbox){
+ final float th = 2.0f*spacing + lbox.getHeight();
+ final float tw = 2.0f*spacing + lbox.getWidth();
+ final float cw = 0.5f*corner*Math.min(tw, th);
+ final float ch = 0.5f*corner*Math.min(tw, th);
+
float minX = lbox.getMinX()-spacing;
float minY = lbox.getMinY()-spacing;
float minZ = labelZOffset;
+
shape.addVertex(minX, minY + ch, minZ, true);
shape.addVertex(minX, minY, minZ, false);
+
shape.addVertex(minX + cw, minY, minZ, true);
+
shape.addVertex(minX + tw - cw, minY, minZ, true);
shape.addVertex(minX + tw, minY, minZ, false);
shape.addVertex(minX + tw, minY + ch, minZ, true);
@@ -141,9 +150,9 @@ public abstract class RIButton extends UIShape {
shape.addVertex(minX + cw, minY + th, minZ, true);
shape.addVertex(minX, minY + th, minZ, false);
shape.addVertex(minX, minY + th - ch, minZ, true);
- shape.closeLastOutline();
+ shape.closeLastOutline(true);
}
-
+
public void setCorner(float corner) {
if(corner > 1.0f){
this.corner = 1.0f;
@@ -154,16 +163,16 @@ public abstract class RIButton extends UIShape {
else{
this.corner = corner;
}
- dirty |= DIRTY_SHAPE;
+ dirty |= DIRTY_SHAPE | DIRTY_REGION;
}
-
+
public float getLabelZOffset() {
return labelZOffset;
}
public void setLabelZOffset(float labelZOffset) {
this.labelZOffset = -labelZOffset;
- dirty |= DIRTY_SHAPE;
+ dirty |= DIRTY_SHAPE | DIRTY_REGION;
}
public float getSpacing() {
return spacing;
@@ -176,91 +185,19 @@ public abstract class RIButton extends UIShape {
else{
this.spacing = spacing;
}
- dirty |= DIRTY_SHAPE;
- }
-
- public float[] getButtonColor() {
- return buttonColor;
- }
-
- public void setButtonColor(float r, float g, float b) {
- this.buttonColor = new float[3];
- this.buttonColor[0] = r;
- this.buttonColor[1] = g;
- this.buttonColor[2] = b;
+ dirty |= DIRTY_SHAPE | DIRTY_REGION;
}
public float[] getLabelColor() {
- return labelColor;
+ return label.getColor();
}
-
- private UIRegion buttonRegion = null;
- private UIRegion labelRegion = null;
- private boolean toggle =false;
- private boolean toggleable = false;
- public void render(GL2ES2 gl, RenderState rs, RegionRenderer renderer, int renderModes, int[/*1*/] texSize, boolean selection) {
- if(null == buttonRegion) {
- buttonRegion = new UIRegion(this);
- labelRegion = new UIRegion(getLabel());
- }
-
- gl.glEnable(GL2ES2.GL_POLYGON_OFFSET_FILL);
- gl.glPolygonOffset(0.0f, 1f);
-
- float[] bColor = buttonColor;
- if(isPressed() || toggle){
- bColor = buttonSelectedColor;
- }
- if(!selection){
- renderer.setColorStatic(gl, bColor[0], bColor[1], bColor[2]);
- }
- renderer.draw(gl, buttonRegion.getRegion(gl, rs, renderModes), getPosition(), texSize);
- gl.glDisable(GL2ES2.GL_POLYGON_OFFSET_FILL);
-
- float[] lColor = labelColor;
- if(isPressed() || toggle ){
- lColor = labelSelectedColor;
- }
- if(!selection){
- renderer.setColorStatic(gl, lColor[0], lColor[1], lColor[2]);
- }
- renderer.draw(gl, labelRegion.getRegion(gl, rs, renderModes), getPosition(), texSize);
- }
- public void setPressed(boolean b) {
- super.setPressed(b);
- if(isToggleable() && b) {
- toggle = !toggle;
- }
- }
-
public void setLabelColor(float r, float g, float b) {
- this.labelColor = new float[3];
- this.labelColor[0] = r;
- this.labelColor[1] = g;
- this.labelColor[2] = b;
- }
-
- public void setButtonSelectedColor(float r, float g, float b){
- this.buttonSelectedColor = new float[3];
- this.buttonSelectedColor[0] = r;
- this.buttonSelectedColor[1] = g;
- this.buttonSelectedColor[2] = b;
- }
-
- public void setLabelSelectedColor(float r, float g, float b){
- this.labelSelectedColor = new float[3];
- this.labelSelectedColor[0] = r;
- this.labelSelectedColor[1] = g;
- this.labelSelectedColor[2] = b;
+ label.setColor(r, g, b);
}
- public boolean isToggleable() {
- return toggleable;
- }
-
- public void setToggleable(boolean toggleable) {
- this.toggleable = toggleable;
+ public void setLabelSelectedColor(float r, float g, float b){
+ label.setSelectedColor(r, g, b);
}
public String toString() {
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java
index 616dd9b98..77195646d 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java
@@ -10,52 +10,56 @@ import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLRunnable;
+import javax.media.opengl.fixedfunc.GLMatrixFunc;
+
+import jogamp.graph.geom.plane.AffineTransform;
import com.jogamp.common.nio.Buffers;
import com.jogamp.graph.curve.opengl.RegionRenderer;
-import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.newt.event.MouseEvent;
import com.jogamp.newt.event.MouseListener;
import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.util.PMVMatrix;
public class SceneUIController implements GLEventListener{
- private ArrayList<UIShape> shapes = new ArrayList<UIShape>();
+ private final ArrayList<UIShape> shapes = new ArrayList<UIShape>();
private int count = 0;
- private int renderModes;
- private int[] texSize;
- private RegionRenderer renderer = null;
- private RenderState rs = null;
+ private int renderModes;
+ private int[] sampleCount;
+ private RegionRenderer renderer;
+
+ private final float[] translate = new float[3];
+ private final float[] scale = new float[3];
+ private final float[] rotation = new float[3];
- private float[] translate = new float[3];
- private float[] scale = new float[3];
- private float[] rotation = new float[3];
+ private final float[] sceneClearColor = new float[]{0,0,0,0};
- private float[] sceneClearColor = new float[]{0,0,0,1};
-
private int activeId = -1;
-
+
private SBCMouseListener sbcMouseListener = null;
-
+
private GLAutoDrawable cDrawable = null;
public SceneUIController() {
+ this(null, 0, null);
}
-
- public void setRenderer(RegionRenderer renderer, RenderState rs, int renderModes, int[] texSize) {
+
+ public SceneUIController(RegionRenderer renderer, int renderModes, int[] sampleCount) {
this.renderer = renderer;
- this.rs = rs;
this.renderModes = renderModes;
- this.texSize = texSize;
+ this.sampleCount = sampleCount;
+ setScale(1f, 1f, 1f);
+ setTranslate(0f, 0f, 0f);
+ setRotation(0f, 0f, 0f);
}
-
- public SceneUIController(RegionRenderer renderer, RenderState rs, int renderModes, int[] texSize) {
+
+ public void setRenderer(RegionRenderer renderer, int renderModes, int[] sampleCount) {
this.renderer = renderer;
- this.rs = rs;
this.renderModes = renderModes;
- this.texSize = texSize;
+ this.sampleCount = sampleCount;
}
-
+
public void attachInputListenerTo(GLWindow window) {
if(null == sbcMouseListener) {
sbcMouseListener = new SBCMouseListener();
@@ -68,7 +72,7 @@ public class SceneUIController implements GLEventListener{
window.removeMouseListener(sbcMouseListener);
}
}
-
+
public ArrayList<UIShape> getShapes() {
return shapes;
}
@@ -83,7 +87,7 @@ public class SceneUIController implements GLEventListener{
count--;
}
}
-
+
public void init(GLAutoDrawable drawable) {
System.err.println("SceneUIController: init");
cDrawable = drawable;
@@ -94,20 +98,15 @@ public class SceneUIController implements GLEventListener{
final int height = drawable.getHeight();
GL2ES2 gl = drawable.getGL().getGL2ES2();
- render(gl, width, height, renderModes, texSize, false);
+ render(gl, width, height, renderModes, sampleCount, false);
}
-
+
public void dispose(GLAutoDrawable drawable) {
System.err.println("SceneUIController: dispose");
cDrawable = null;
- drawable.removeGLEventListener(this);
}
- public void reshape(GLAutoDrawable drawable, int x, int y, int width,
- int height) {
- System.err.println("SceneUIController: reshape");
- GL2ES2 gl = drawable.getGL().getGL2ES2();
- renderer.reshapePerspective(gl, 45.0f, width, height, 5f, 70.0f);
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
}
public UIShape getShape(GLAutoDrawable drawable,int x, int y) {
@@ -120,13 +119,13 @@ public class SceneUIController implements GLEventListener{
return null;
return shapes.get(index);
}
-
+
public UIShape getActiveUI() {
if(activeId == -1)
return null;
return shapes.get(activeId);
}
-
+
public void release() {
activeId = -1;
}
@@ -152,27 +151,30 @@ public class SceneUIController implements GLEventListener{
return index;
}
- private void render(GL2ES2 gl, int width, int height, int renderModes, int[/*1*/] texSize, boolean select) {
- renderer.reshapePerspective(null, 45.0f, width, height, 0.1f, 7000.0f);
-
+ private void render(GL2ES2 gl, int width, int height, int renderModes, int[/*1*/] sampleCount, boolean select) {
for(int index=0; index < count;index++){
if(select) {
float color= index+1;
renderer.setColorStatic(gl, color/(count+2), color/(count+2), color/(count+2));
}
- float[] s = shapes.get(index).getScale();
- float[] p = shapes.get(index).getPosition();
- renderer.resetModelview(null);
- renderer.translate(null, translate[0]+p[0], translate[1]+p[1], translate[2]+p[2]);
- renderer.scale(gl, s[0], s[1], s[2]);
- renderer.rotate(gl, rotation[0], 1, 0, 0);
- renderer.rotate(gl, rotation[1], 0, 1, 0);
- renderer.rotate(gl, rotation[2], 0, 0, 1);
-
- shapes.get(index).render(gl, rs, renderer, renderModes, texSize, select);
- renderer.rotate(gl, -rotation[0], 1, 0, 0);
- renderer.rotate(gl, -rotation[1], 0, 1, 0);
- renderer.rotate(gl, -rotation[2], 0, 0, 1);
+ final UIShape uiShape = shapes.get(index);
+ uiShape.validate(gl, renderer);
+ final AffineTransform t = uiShape.getTransform();
+
+ final PMVMatrix pmv = renderer.getMatrix();
+ pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
+ pmv.glPushMatrix();
+ pmv.glLoadIdentity();
+ System.err.printf("SceneUICtrl.render.1.0: translate.0: %f, %f, %f%n", translate[0], translate[1], translate[2]);
+ System.err.printf("SceneUICtrl.render.1.0: translate.1: %f, %f%n", t.getTranslateX(), t.getTranslateY());
+ pmv.glTranslatef(translate[0]+t.getTranslateX(), translate[1]+t.getTranslateY(), translate[2]);
+ pmv.glScalef(scale[0]*t.getScaleX(), scale[1]*t.getScaleY(), scale[2]);
+ pmv.glRotatef(rotation[0], 1, 0, 0);
+ pmv.glRotatef(rotation[1], 0, 1, 0);
+ pmv.glRotatef(rotation[2], 0, 0, 1);
+ renderer.updateMatrix(gl);
+ uiShape.drawShape(gl, renderer, sampleCount, select);
+ pmv.glPopMatrix();
}
}
@@ -203,11 +205,11 @@ public class SceneUIController implements GLEventListener{
this.sceneClearColor[2] = b;
this.sceneClearColor[3] = a;
}
-
+
private class SBCMouseListener implements MouseListener {
int mouseX = -1;
int mouseY = -1;
-
+
public void mouseClicked(MouseEvent e) {
UIShape uiShape = getActiveUI();
if(uiShape != null){
@@ -221,7 +223,7 @@ public class SceneUIController implements GLEventListener{
}
mouseX = e.getX();
mouseY = e.getY();
-
+
GLRunnable runnable = new GLRunnable() {
public boolean run(GLAutoDrawable drawable) {
UIShape s = getShape(drawable, mouseX, mouseY);
@@ -235,16 +237,16 @@ public class SceneUIController implements GLEventListener{
}
};
cDrawable.invoke(true, runnable);
-
+
UIShape uiShape = getActiveUI();
-
+
if(uiShape != null) {
uiShape.setPressed(true);
uiShape.onPressed();
}
}
- public void mouseReleased(MouseEvent e) {
+ public void mouseReleased(MouseEvent e) {
UIShape uiShape = getActiveUI();
if(uiShape != null){
uiShape.setPressed(false);
@@ -257,6 +259,6 @@ public class SceneUIController implements GLEventListener{
public void mouseExited(MouseEvent e) { }
public void mouseDragged(MouseEvent e) { }
public void mouseWheelMoved(MouseEvent e) { }
-
+
}
} \ No newline at end of file
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java
index da94f6a7c..587b9b3dc 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java
@@ -34,18 +34,19 @@ import javax.media.opengl.GL;
import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLAutoDrawable;
-import com.jogamp.graph.curve.opengl.RegionRenderer;
+import jogamp.graph.geom.plane.AffineTransform;
+
import com.jogamp.graph.curve.opengl.RenderState;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontFactory;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.opengl.test.junit.graph.demos.MSAATool;
-import com.jogamp.opengl.test.junit.graph.demos.ui.opengl.UIRegion;
public class UIGLListener01 extends UIListenerBase01 {
-
+
public UIGLListener01 (RenderState rs, boolean debug, boolean trace) {
- super(RegionRenderer.create(rs, 0), debug, trace);
+ super(RegionRenderer.create(rs, 0, RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable), debug, trace);
setMatrix(-20, 00, 0f, -50);
try {
final Font font = FontFactory.get(FontFactory.UBUNTU).getDefault();
@@ -56,9 +57,9 @@ public class UIGLListener01 extends UIListenerBase01 {
}
public void onRelease() {
}
-
+
};
- button.setPosition(2,1,0);
+ button.translate(2,1);
/** Button defaults !
button.setLabelColor(1.0f,1.0f,1.0f);
button.setButtonColor(0.6f,0.6f,0.6f);
@@ -69,24 +70,21 @@ public class UIGLListener01 extends UIListenerBase01 {
} catch (IOException ex) {
System.err.println("Catched: "+ex.getMessage());
ex.printStackTrace();
- }
+ }
}
-
+
public void init(GLAutoDrawable drawable) {
super.init(drawable);
-
+
GL2ES2 gl = drawable.getGL().getGL2ES2();
gl.setSwapInterval(1);
gl.glEnable(GL2ES2.GL_DEPTH_TEST);
gl.glEnable(GL2ES2.GL_POLYGON_OFFSET_FILL);
-
+
MSAATool.dump(drawable);
}
- UIRegion regionButton;
- UIRegion regionLabel;
-
public void display(GLAutoDrawable drawable) {
GL2ES2 gl = drawable.getGL().getGL2ES2();
@@ -94,37 +92,21 @@ public class UIGLListener01 extends UIListenerBase01 {
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
final RegionRenderer regionRenderer = getRegionRenderer();
- final RenderState rs = regionRenderer.getRenderState();
-
+
regionRenderer.resetModelview(null);
-
+
regionRenderer.translate(null, getXTran(), getYTran(), getZoom());
regionRenderer.rotate(gl, getAngle(), 0, 1, 0);
-
- final float[] bColor = button.getButtonColor();
- final float[] lColor = button.getLabelColor();
- if(null == regionButton) {
- regionButton = new UIRegion(button);
- regionLabel = new UIRegion(button.getLabel());
- }
-
- regionRenderer.setColorStatic(gl, bColor[0], bColor[1], bColor[2]);
- regionRenderer.draw(gl, regionButton.getRegion(gl, rs, 0), getPosition(), null);
-// regionRenderer.translate(gl, button.getPosition()[0], button.getPosition()[1], button.getPosition()[2]);
- regionRenderer.setColorStatic(gl, lColor[0], lColor[1], lColor[2]);
- regionRenderer.draw(gl, regionLabel.getRegion(gl, rs, 0), getPosition(), null);
- }
-
+
+ final int[] sampleCount = { 4 };
+ final AffineTransform t = button.getTransform();
+ regionRenderer.translate(gl, t.getTranslateX(), t.getTranslateY(), 0);
+ button.drawShape(gl, regionRenderer, sampleCount, false);
+ }
+
public void dispose(GLAutoDrawable drawable) {
GL2ES2 gl = drawable.getGL().getGL2ES2();
- if(null != regionButton) {
- regionButton.destroy(gl, getRegionRenderer().getRenderState());
- regionButton = null;
- }
- if(null != regionLabel) {
- regionLabel.destroy(gl, getRegionRenderer().getRenderState());
- regionButton = null;
- }
+ button.destroy(gl, getRegionRenderer());
super.dispose(drawable);
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java
index 0577c5ff0..031d43e79 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java
@@ -28,12 +28,11 @@
package com.jogamp.opengl.test.junit.graph.demos.ui;
-import javax.media.opengl.FPSCounter;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.newt.event.KeyAdapter;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.WindowAdapter;
@@ -45,14 +44,14 @@ import com.jogamp.opengl.util.glsl.ShaderState;
/** Demonstrate the rendering of multiple outlines into one region/OutlineShape
* These Outlines are not necessary connected or contained.
* The output of this demo shows two identical shapes but the left one
- * has some vertices with off-curve flag set to true, and the right allt he vertices
- * are on the curve. Demos the Res. Independent Nurbs based Curve rendering
+ * has some vertices with off-curve flag set to true, and the right allt he vertices
+ * are on the curve. Demos the Res. Independent Nurbs based Curve rendering
*
*/
public class UINewtDemo01 {
static final boolean DEBUG = false;
static final boolean TRACE = false;
-
+
public static void main(String[] args) {
GLProfile glp = GLProfile.getGL2ES2();
GLCapabilities caps = new GLCapabilities(glp);
@@ -60,23 +59,21 @@ public class UINewtDemo01 {
caps.setSampleBuffers(true);
caps.setNumSamples(4);
System.out.println("Requested: " + caps);
-
+
final GLWindow window = GLWindow.create(caps);
window.setPosition(10, 10);
window.setSize(800, 400);
window.setTitle("GPU UI Newt Demo 01");
RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
UIGLListener01 uiGLListener = new UIGLListener01 (rs, DEBUG, TRACE);
- uiGLListener.attachInputListenerTo(window);
+ uiGLListener.attachInputListenerTo(window);
window.addGLEventListener(uiGLListener);
-
- window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err);
window.setVisible(true);
final Animator animator = new Animator();
- animator.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err);
+ animator.setUpdateFPSFrames(60, System.err);
animator.add(window);
-
+
window.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent arg0) {
if(arg0.getKeyCode() == KeyEvent.VK_F4) {
@@ -89,7 +86,7 @@ public class UINewtDemo01 {
animator.stop();
}
});
-
+
animator.start();
- }
+ }
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java
index c38f8f75c..5a7b147d5 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java
@@ -27,104 +27,253 @@
*/
package com.jogamp.opengl.test.junit.graph.demos.ui;
+import java.util.ArrayList;
+
import javax.media.opengl.GL2ES2;
+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.RegionRenderer;
-import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.geom.Vertex.Factory;
import com.jogamp.opengl.math.geom.AABBox;
public abstract class UIShape {
private final Factory<? extends Vertex> vertexFactory;
- protected OutlineShape shape;
-
- protected static final int DIRTY_SHAPE = 1 << 0 ;
- protected int dirty = DIRTY_SHAPE;
-
+
+ public class TransformedShape {
+ public final OutlineShape shape;
+ public final AffineTransform t;
+
+ public TransformedShape(final OutlineShape shape, final AffineTransform t) {
+ this.shape = shape;
+ this.t = t;
+ }
+ }
+ protected final ArrayList<TransformedShape> shapes;
+
+ protected static final int DIRTY_SHAPE = 1 << 0 ;
+ protected static final int DIRTY_POSITION = 1 << 1 ;
+ protected static final int DIRTY_REGION = 1 << 2 ;
+ protected int dirty = DIRTY_SHAPE | DIRTY_POSITION | DIRTY_REGION;
+
+ protected final AABBox box;
+ protected final AffineTransform transform;
+ private GLRegion region = null;
+
+ protected final float[] color = {0.6f, 0.6f, 0.6f};
+ protected final float[] selectedColor = {0.8f, 0.8f, 0.8f};
+
private boolean down = false;
+ private boolean toggle =false;
+ private boolean toggleable = false;
public UIShape(Factory<? extends Vertex> factory) {
this.vertexFactory = factory;
- this.shape = new OutlineShape(factory);
- }
-
- public void clear() {
- clearImpl();
- shape.clear();
- }
-
- public abstract void render(GL2ES2 gl, RenderState rs, RegionRenderer renderer, int renderModes, int[/*1*/] texSize, boolean selection);
-
- protected boolean positionDirty = false;
-
- private float[] position = new float[]{0,0,0};
- private float[] scale = new float[]{1.0f,1.0f,1.0f};
- public void setScale(float x, float y, float z){
- scale[0] = x;
- scale[1] = y;
- scale[2] = z;
- }
-
- public void setPosition(float x, float y, float z) {
- this.position[0] = x;
- this.position[1] = y;
- this.position[2] = z;
- positionDirty = true;
- }
-
- private void updatePosition () {
- float minX = shape.getBounds().getLow()[0];
- float minY = shape.getBounds().getLow()[1];
- float minZ = shape.getBounds().getLow()[2];
- System.out.println("Position was: " + (position[0]) + " " + (position[1]) + " " + (position[2]));
- System.out.println("Position became: " + (position[0] - minX) + " " + (position[1] - minY) + " " + (position[2] - minZ));
- setPosition(position[0] - minX, position[1] - minY, position[2] - minZ);
- positionDirty = false;
- }
-
- public float[] getScale() { return scale; }
- public float[] getPosition() { return position; }
-
- protected abstract void clearImpl();
-
- protected abstract void createShape();
-
- public boolean updateShape() {
- if( isShapeDirty() ) {
- shape.clear();
- createShape();
- if(positionDirty){
- updatePosition();
+ this.shapes = new ArrayList<TransformedShape>();
+ this.box = new AABBox();
+ this.transform = new AffineTransform(factory);
+ }
+
+ public final Vertex.Factory<? extends Vertex> getVertexFactory() { return vertexFactory; }
+
+ /**
+ * Clears all data and reset all states as if this instance was newly created
+ * @param gl TODO
+ * @param renderer TODO\
+ */
+ public void clear(GL2ES2 gl, RegionRenderer renderer) {
+ clearImpl(gl, renderer);
+ shapes.clear();
+ transform.setToIdentity();
+ box.reset();
+ dirty = DIRTY_SHAPE | DIRTY_POSITION | DIRTY_REGION;
+ }
+
+ /**
+ * Destroys all data
+ * @param gl
+ * @param renderer
+ */
+ public void destroy(GL2ES2 gl, RegionRenderer renderer) {
+ destroyImpl(gl, renderer);
+ shapes.clear();
+ transform.setToIdentity();
+ box.reset();
+ dirty = DIRTY_SHAPE | DIRTY_POSITION | DIRTY_REGION;
+ }
+
+ public final void translate(float tx, float ty) {
+ transform.translate(tx, ty);
+ dirty |= DIRTY_POSITION;
+ }
+
+ public final void scale(float sx, float sy, float sz) {
+ transform.scale(sx, sy);
+ }
+
+ public final AffineTransform getTransform() {
+ if( !isShapeDirty() ) {
+ validatePosition();
+ }
+ return transform;
+ }
+
+ public final boolean isShapeDirty() {
+ return 0 != ( dirty & DIRTY_SHAPE ) ;
+ }
+
+ public final boolean isPositionDirty() {
+ return 0 != ( dirty & DIRTY_POSITION ) ;
+ }
+
+ public final boolean isRegionDirty() {
+ return 0 != ( dirty & DIRTY_REGION ) ;
+ }
+
+ public ArrayList<TransformedShape> getShapes() { return shapes; }
+
+ public final AABBox getBounds() { return box; }
+
+ public GLRegion getRegion(GL2ES2 gl, RegionRenderer renderer) {
+ validate(gl, renderer);
+ if( isRegionDirty() ) {
+ if( null == region ) {
+ region = GLRegion.create(renderer.getRenderModes());
+ } else {
+ region.clear(gl, renderer);
}
+ addToRegion(region);
+ dirty &= ~DIRTY_REGION;
+ System.err.println("XXX.UIShape: updated: "+region);
+ }
+ return region;
+ }
+
+ /**
+ * Renders {@link OutlineShape} using local {@link GLRegion} which might be cached or updated.
+ * <p>
+ * No matrix operations (translate, scale, ..) are performed.
+ * </p>
+ * @param gl
+ * @param renderer
+ * @param sampleCount
+ * @param select
+ */
+ public void drawShape(GL2ES2 gl, RegionRenderer renderer, int[] sampleCount, boolean select) {
+ float[] _color = color;
+ if( isPressed() || toggle ){
+ _color = selectedColor;
+ }
+ if(!select){
+ /**
+ if( useBlending ) {
+ // NOTE_ALPHA_BLENDING:
+ // Due to alpha blending and VBAA, we need a background in text color
+ // otherwise blending will amplify 'white'!
+ gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ } */
+ renderer.setColorStatic(gl, _color[0], _color[1], _color[2]);
+ }
+ getRegion(gl, renderer).draw(gl, renderer, sampleCount);
+ }
+
+ public final boolean validate(GL2ES2 gl, RegionRenderer renderer) {
+ if( !validateShape(gl, renderer) ) {
+ return validatePosition();
+ }
+ return true;
+ }
+ private final boolean validateShape(GL2ES2 gl, RegionRenderer renderer) {
+ if( isShapeDirty() ) {
+ shapes.clear();
+ box.reset();
+ createShape(gl, renderer);
dirty &= ~DIRTY_SHAPE;
+ dirty |= DIRTY_REGION;
+ validatePosition();
return true;
}
return false;
}
-
- public final Vertex.Factory<? extends Vertex> getVertexFactory() { return vertexFactory; }
- public AABBox getBounds() { return shape.getBounds(); }
-
- public OutlineShape getShape() {
- updateShape();
- return shape;
+ private final boolean validatePosition () {
+ if( isPositionDirty() && !isShapeDirty() ) {
+ // Subtract the bbox minx/miny from position, i.e. the shape's offset.
+ final AABBox box = getBounds();
+ final float minX = box.getMinX();
+ final float minY = box.getMinY();
+ System.err.println("XXX.UIShape: Position pre: " + transform.getTranslateX() + " " + transform.getTranslateY() + ", sbox "+box);
+ translate(-minX, -minY);
+ System.err.println("XXX.UIShape: Position post: " + transform.getTranslateX() + " " + transform.getTranslateY() + ", sbox "+box);
+ dirty &= ~DIRTY_POSITION;
+ return true;
+ }
+ return false;
}
-
- public boolean isShapeDirty() {
- return 0 != ( dirty & DIRTY_SHAPE ) ;
- }
-
+
+ private final void addToRegion(Region region) {
+ final int shapeCount = shapes.size();
+ for(int i=0; i<shapeCount; i++) {
+ final TransformedShape tshape = shapes.get(i);
+ region.addOutlineShape(tshape.shape, tshape.t);
+ }
+ }
+
+ public float[] getColor() {
+ return color;
+ }
+
+ public void setColor(float r, float g, float b) {
+ this.color[0] = r;
+ this.color[1] = g;
+ this.color[2] = b;
+ }
+ public void setSelectedColor(float r, float g, float b){
+ this.selectedColor[0] = r;
+ this.selectedColor[1] = g;
+ this.selectedColor[2] = b;
+ }
+
+ //
+ // Input
+ //
+
public void setPressed(boolean b) {
this.down = b;
+ if(isToggleable() && b) {
+ toggle = !toggle;
+ }
}
-
+
public boolean isPressed() {
return this.down;
}
-
- public abstract void onClick();
- public abstract void onPressed();
- public abstract void onRelease();
+
+ public boolean isToggleable() {
+ return toggleable;
+ }
+
+ public void setToggleable(boolean toggleable) {
+ this.toggleable = toggleable;
+ }
+
+ public void onClick() { }
+ public void onPressed() { }
+ public void onRelease() { }
+
+ //
+ //
+ //
+
+ protected abstract void clearImpl(GL2ES2 gl, RegionRenderer renderer);
+ protected abstract void destroyImpl(GL2ES2 gl, RegionRenderer renderer);
+ protected abstract void createShape(GL2ES2 gl, RegionRenderer renderer);
+
+ //
+ //
+ //
+
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UITextShape.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UITextShape.java
deleted file mode 100644
index ee79d9a0b..000000000
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UITextShape.java
+++ /dev/null
@@ -1,37 +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.opengl.test.junit.graph.demos.ui;
-
-import jogamp.graph.curve.text.GlyphString;
-
-/**
- * Marker interface to mark a UIShape implementation for text usage
- */
-public interface UITextShape {
- GlyphString getGlyphString();
-}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/opengl/UIRegion.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/opengl/UIRegion.java
deleted file mode 100644
index 88271095c..000000000
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/opengl/UIRegion.java
+++ /dev/null
@@ -1,77 +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.opengl.test.junit.graph.demos.ui.opengl;
-
-import javax.media.opengl.GL2ES2;
-
-import com.jogamp.graph.curve.opengl.GLRegion;
-import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.opengl.test.junit.graph.demos.ui.UIShape;
-import com.jogamp.opengl.test.junit.graph.demos.ui.UITextShape;
-
-public class UIRegion {
- protected static final int DIRTY_REGION = 1 << 0 ;
- protected int dirty = DIRTY_REGION;
-
- private UIShape uiShape;
- private GLRegion region;
-
- public UIRegion(UIShape uis) {
- this.uiShape = uis;
- }
-
- public boolean updateRegion(GL2ES2 gl, RenderState rs, int renderModes) {
- if( uiShape.updateShape() || isRegionDirty() ) {
- destroy(gl, rs);
- if(uiShape instanceof UITextShape) {
- region = ((UITextShape)uiShape).getGlyphString().createRegion(gl, renderModes);
- } else {
- region = GLRegion.create(uiShape.getShape(), renderModes);
- }
- dirty &= ~DIRTY_REGION;
- return true;
- }
- return false;
- }
-
- public GLRegion getRegion(GL2ES2 gl, RenderState rs, int renderModes) {
- updateRegion(gl, rs, renderModes);
- return region;
- }
-
- public boolean isRegionDirty() {
- return 0 != ( dirty & DIRTY_REGION ) ;
- }
-
- public void destroy(GL2ES2 gl, RenderState rs) {
- if(null != region) {
- region.destroy(gl, rs);
- region = null;
- }
- }
-}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/GLReadBuffer00Base.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/GLReadBuffer00Base.java
index 43f8b89bd..d556f2963 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/GLReadBuffer00Base.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/GLReadBuffer00Base.java
@@ -41,6 +41,9 @@ import org.junit.Test;
import org.junit.runners.MethodSorters;
import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.GLRegion;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
+import com.jogamp.graph.font.Font;
import com.jogamp.opengl.test.junit.graph.TextRendererGLELBase;
import com.jogamp.opengl.test.junit.util.UITestCase;
@@ -51,15 +54,16 @@ import com.jogamp.opengl.test.junit.util.UITestCase;
public abstract class GLReadBuffer00Base extends UITestCase {
public static class TextRendererGLEL extends TextRendererGLELBase {
+ final Font font = getFont(0, 0, 0);
public int frameNo = 0;
public int userCounter = 0;
+ private final GLRegion regionFPS;
public TextRendererGLEL() {
// FIXME: Graph TextRenderer does not AA well w/o MSAA and FBO
- super(Region.VBAA_RENDERING_BIT);
- texSizeScale = 2;
-
- fontSize = 24;
+ super(Region.VBAA_RENDERING_BIT, new int[] { 4 });
+ this.setRendererCallbacks(RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
+ regionFPS = GLRegion.create(usrRenderModes);
staticRGBAColor[0] = 1.0f;
staticRGBAColor[1] = 1.0f;
@@ -68,11 +72,19 @@ public abstract class GLReadBuffer00Base extends UITestCase {
}
@Override
+ public void dispose(GLAutoDrawable drawable) {
+ regionFPS.destroy(drawable.getGL().getGL2ES2(), renderer);
+ super.dispose(drawable);
+ }
+
+ @Override
public void display(GLAutoDrawable drawable) {
final String text = String.format("Frame %04d (%03d): %04dx%04d", frameNo, userCounter, drawable.getWidth(), drawable.getHeight());
System.err.println("TextRendererGLEL.display: "+text);
if( null != renderer ) {
- renderString(drawable, text, 0 /* col */, 0 /* row */, 0, 0, -1);
+ final float pixelSize = font.getPixelSize(14f, dpiH);
+ drawable.getGL().glClearColor(1f, 1f, 1f, 0f);
+ renderString(drawable, font, pixelSize, text, 0 /* col */, 0 /* row */, 0, 0, -1, regionFPS);
} else {
System.err.println(text);
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java
index b02238c2b..79e0655e3 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java
@@ -305,14 +305,6 @@ public class TextureSequenceCubeES2 implements GLEventListener {
gl.glViewport(0, 0, width, height);
- if(innerCube) {
- // Clear background to white
- gl.glClearColor(1.0f, 1.0f, 1.0f, 0.4f);
- } else {
- // Clear background to blue
- gl.glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
- }
-
if(!innerCube) {
// lights on
} else {
@@ -370,6 +362,13 @@ public class TextureSequenceCubeES2 implements GLEventListener {
public void display(GLAutoDrawable drawable) {
GL2ES2 gl = drawable.getGL().getGL2ES2();
+ if(innerCube) {
+ // Clear background to white
+ gl.glClearColor(1.0f, 1.0f, 1.0f, 0.4f);
+ } else {
+ // Clear background to blue
+ gl.glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
+ }
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
if( null == st ) {
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java
index b148ebabd..3aa400232 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java
@@ -43,6 +43,7 @@ import javax.media.opengl.GLProfile;
import com.jogamp.common.util.IOUtil;
import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.GLRegion;
import com.jogamp.graph.font.Font;
import com.jogamp.newt.Window;
import com.jogamp.newt.event.KeyAdapter;
@@ -156,24 +157,22 @@ public class MovieCube implements GLEventListener {
resetGLState = true;
}
+ final int[] textSampleCount = { 4 };
+
private final class InfoTextRendererGLELBase extends TextRendererGLELBase {
- static final float z_diff = 0.001f;
- final float underlineSize;
+ private static final float z_diff = 0.001f;
+ private final Font font = getFont(0, 0, 0);
+ private final float fontSize = 12;
+ private final GLRegion regionFPS;
+ private float pixelSize, underlineSize;
InfoTextRendererGLELBase() {
// FIXME: Graph TextRenderer does not AA well w/o MSAA and FBO
- super(Region.VBAA_RENDERING_BIT);
- texSizeScale = 2;
-
- fontSize = 1;
- pixelScale = 1.0f / ( fontSize * 20f );
-
- // underlineSize: 'underline' amount of pixel below 0/0 (Note: lineGap is negative)
- final Font.Metrics metrics = font.getMetrics();
- final float lineGap = metrics.getLineGap(fontSize);
- final float descent = metrics.getDescent(fontSize);
- underlineSize = descent - lineGap;
- // System.err.println("XXX: fLG "+lineGap+", fDesc "+descent+", underlineSize "+underlineSize);
+ super(Region.VBAA_RENDERING_BIT, MovieCube.this.textSampleCount);
+ // NOTE_ALPHA_BLENDING: We go w/o alpha and blending!
+ // this.setRendererCallbacks(RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
+ regionFPS = GLRegion.create(usrRenderModes);
+ System.err.println("RegionFPS "+Region.getRenderModeString(usrRenderModes)+", sampleCount "+textSampleCount[0]+", class "+regionFPS.getClass().getName());
staticRGBAColor[0] = 0.0f;
staticRGBAColor[1] = 0.0f;
@@ -184,8 +183,23 @@ public class MovieCube implements GLEventListener {
@Override
public void init(GLAutoDrawable drawable) {
// non-exclusive mode!
- this.usrPMVMatrix = cube.pmvMatrix;
+ this.setSharedPMVMatrix(cube.pmvMatrix);
super.init(drawable);
+
+ pixelSize = font.getPixelSize(fontSize, dpiH);
+ pixelScale = 1.0f / ( pixelSize * 20f );
+ // underlineSize: 'underline' amount of pixel below 0/0 (Note: lineGap is negative)
+ final Font.Metrics metrics = font.getMetrics();
+ final float lineGap = metrics.getLineGap(pixelSize);
+ final float descent = metrics.getDescent(pixelSize);
+ underlineSize = descent - lineGap;
+ System.err.println("XXX: dpiH "+dpiH+", fontSize "+fontSize+", pixelSize "+pixelSize+", pixelScale "+pixelScale+", fLG "+lineGap+", fDesc "+descent+", underlineSize "+underlineSize);
+ }
+
+ @Override
+ public void dispose(GLAutoDrawable drawable) {
+ regionFPS.destroy(drawable.getGL().getGL2ES2(), renderer);
+ super.dispose(drawable);
}
@Override
@@ -215,9 +229,7 @@ public class MovieCube implements GLEventListener {
"; underlineSize "+underlineSize+" "+(pixelScale*underlineSize)+
"; yoff "+yoff1+", yoff2 "+yoff2); */
- // FIXME: Graph TextRenderer does not scale well, i.e. text update per 1/10s cause too much recompute of regions!
- // final String text1 = String.format("%03.1f/%03.1f s, %s (%01.2fx, vol %01.2f), a %01.2f, fps %02.1f -> %02.1f / %02.1f, v-sync %d",
- final String text1 = String.format("%03.0f/%03.0f s, %s (%01.2fx, vol %01.2f), a %01.2f, fps %02.1f -> %02.1f / %02.1f, v-sync %d",
+ final String text1 = String.format("%03.1f/%03.1f s, %s (%01.2fx, vol %01.2f), a %01.2f, fps %02.1f -> %02.1f / %02.1f, v-sync %d",
pts, mPlayer.getDuration() / 1000f,
mPlayer.getState().toString().toLowerCase(), mPlayer.getPlaySpeed(), mPlayer.getAudioVolume(),
aspect, mPlayer.getFramerate(), lfps, tfps, swapIntervalSet);
@@ -227,10 +239,11 @@ public class MovieCube implements GLEventListener {
mPlayer.getVID(), mPlayer.getVideoBitrate()/1000, mPlayer.getVideoCodec());
final String text4 = mPlayer.getURI().getRawPath();
if( displayOSD && null != renderer ) {
- renderString(drawable, text1, 1 /* col */, -1 /* row */, -1+z_diff, yoff1, 1f+z_diff);
- renderString(drawable, text2, 1 /* col */, 0 /* row */, -1+z_diff, yoff2, 1f+z_diff);
- renderString(drawable, text3, 1 /* col */, 1 /* row */, -1+z_diff, yoff2, 1f+z_diff);
- renderString(drawable, text4, 1 /* col */, 2 /* row */, -1+z_diff, yoff2, 1f+z_diff);
+ drawable.getGL().glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
+ renderString(drawable, font, pixelSize, text1, 1 /* col */, -1 /* row */, -1+z_diff, yoff1, 1f+z_diff, regionFPS); // no-cache
+ renderString(drawable, font, pixelSize, text2, 1 /* col */, 0 /* row */, -1+z_diff, yoff2, 1f+z_diff, true);
+ renderString(drawable, font, pixelSize, text3, 1 /* col */, 1 /* row */, -1+z_diff, yoff2, 1f+z_diff, true);
+ renderString(drawable, font, pixelSize, text4, 1 /* col */, 2 /* row */, -1+z_diff, yoff2, 1f+z_diff, true);
}
} };
private final InfoTextRendererGLELBase textRendererGLEL = new InfoTextRendererGLELBase();
@@ -510,7 +523,9 @@ public class MovieCube implements GLEventListener {
glp = GLProfile.getGL2ES2();
}
System.err.println("GLProfile: "+glp);
- final GLWindow window = GLWindow.create(new GLCapabilities(glp));
+ final GLCapabilities caps = new GLCapabilities(glp);
+ // caps.setAlphaBits(4); // NOTE_ALPHA_BLENDING: We go w/o alpha and blending!
+ final GLWindow window = GLWindow.create(caps);
final Animator anim = new Animator(window);
window.addWindowListener(new WindowAdapter() {
public void windowDestroyed(WindowEvent e) {
@@ -519,6 +534,7 @@ public class MovieCube implements GLEventListener {
});
window.setSize(width, height);
window.setVisible(true);
+ System.err.println("Chosen: "+window.getChosenGLCapabilities());
anim.start();
mc.mPlayer.addEventListener(new GLMediaEventListener() {
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java
index 787dbab78..6cee4066b 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java
@@ -49,6 +49,8 @@ import javax.media.opengl.fixedfunc.GLMatrixFunc;
import com.jogamp.common.os.Platform;
import com.jogamp.common.util.IOUtil;
import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.GLRegion;
+import com.jogamp.graph.font.Font;
import com.jogamp.newt.Window;
import com.jogamp.newt.event.KeyAdapter;
import com.jogamp.newt.event.KeyEvent;
@@ -130,13 +132,20 @@ public class MovieSimple implements GLEventListener {
defURI = _defURI;
}
+ final int[] textSampleCount = { 4 };
+
private final class InfoTextRendererGLELBase extends TextRendererGLELBase {
+ private final Font font = getFont(0, 0, 0);
+ private final float fontSize = 10f;
+ private final GLRegion regionFPS;
+
InfoTextRendererGLELBase() {
// FIXME: Graph TextRenderer does not AA well w/o MSAA and FBO
- super(Region.VBAA_RENDERING_BIT);
- texSizeScale = 2;
-
- fontSize = 18;
+ super(Region.VBAA_RENDERING_BIT, textSampleCount);
+ // NOTE_ALPHA_BLENDING: We go w/o alpha and blending!
+ // this.setRendererCallbacks(RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
+ regionFPS = GLRegion.create(usrRenderModes);
+ System.err.println("RegionFPS "+Region.getRenderModeString(usrRenderModes)+", sampleCount "+textSampleCount[0]+", class "+regionFPS.getClass().getName());
staticRGBAColor[0] = 1.0f;
staticRGBAColor[1] = 1.0f;
@@ -145,6 +154,17 @@ public class MovieSimple implements GLEventListener {
}
@Override
+ public void init(GLAutoDrawable drawable) {
+ super.init(drawable);
+ }
+
+ @Override
+ public void dispose(GLAutoDrawable drawable) {
+ regionFPS.destroy(drawable.getGL().getGL2ES2(), renderer);
+ super.dispose(drawable);
+ }
+
+ @Override
public void display(GLAutoDrawable drawable) {
final GLAnimatorControl anim = drawable.getAnimator();
final float lfps = null != anim ? anim.getLastFPS() : 0f;
@@ -158,9 +178,7 @@ public class MovieSimple implements GLEventListener {
final float aspect = (float)mPlayer.getWidth() / (float)mPlayer.getHeight();
- // FIXME: Graph TextRenderer does not scale well, i.e. text update per 1/10s cause too much recompute of regions!
- // final String text1 = String.format("%03.1f/%03.1f s, %s (%01.2fx, vol %01.2f), a %01.2f, fps %02.1f -> %02.1f / %02.1f, v-sync %d",
- final String text1 = String.format("%03.0f/%03.0f s, %s (%01.2fx, vol %01.2f), a %01.2f, fps %02.1f -> %02.1f / %02.1f, v-sync %d",
+ final String text1 = String.format("%03.1f/%03.1f s, %s (%01.2fx, vol %01.2f), a %01.2f, fps %02.1f -> %02.1f / %02.1f, v-sync %d",
pts, mPlayer.getDuration() / 1000f,
mPlayer.getState().toString().toLowerCase(), mPlayer.getPlaySpeed(), mPlayer.getAudioVolume(),
aspect, mPlayer.getFramerate(), lfps, tfps, swapIntervalSet);
@@ -170,10 +188,12 @@ public class MovieSimple implements GLEventListener {
mPlayer.getVID(), mPlayer.getVideoBitrate()/1000, mPlayer.getVideoCodec());
final String text4 = mPlayer.getURI().getRawPath();
if( displayOSD && null != renderer ) {
- renderString(drawable, text1, 1 /* col */, 1 /* row */, 0, 0, -1);
- renderString(drawable, text2, 1 /* col */, -4 /* row */, 0, height, -1);
- renderString(drawable, text3, 1 /* col */, -3 /* row */, 0, height, -1);
- renderString(drawable, text4, 1 /* col */, -2 /* row */, 0, height, -1);
+ // We share ClearColor w/ MovieSimple's init !
+ final float pixelSize = font.getPixelSize(fontSize, dpiH);
+ renderString(drawable, font, pixelSize, text1, 1 /* col */, 1 /* row */, 0, 0, -1, regionFPS); // no-cache
+ renderString(drawable, font, pixelSize, text2, 1 /* col */, -4 /* row */, 0, height, -1, true);
+ renderString(drawable, font, pixelSize, text3, 1 /* col */, -3 /* row */, 0, height, -1, true);
+ renderString(drawable, font, pixelSize, text4, 1 /* col */, -2 /* row */, 0, height, -1, true);
}
} };
private final InfoTextRendererGLELBase textRendererGLEL = new InfoTextRendererGLELBase();
@@ -993,7 +1013,8 @@ public class MovieSimple implements GLEventListener {
glp = GLProfile.getGL2ES2();
}
System.err.println("GLProfile: "+glp);
- GLCapabilities caps = new GLCapabilities(glp);
+ final GLCapabilities caps = new GLCapabilities(glp);
+ // caps.setAlphaBits(4); // NOTE_ALPHA_BLENDING: We go w/o alpha and blending!
final MovieSimple[] mss = new MovieSimple[windowCount];
final GLWindow[] windows = new GLWindow[windowCount];
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java
index 360f4e8d7..32bea649f 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java
@@ -29,7 +29,6 @@ package com.jogamp.opengl.test.junit.jogl.glsl;
import com.jogamp.common.nio.Buffers;
import com.jogamp.newt.MonitorDevice;
-import com.jogamp.newt.MonitorMode;
import com.jogamp.opengl.util.GLArrayDataServer;
import com.jogamp.opengl.util.PMVMatrix;
import com.jogamp.opengl.util.glsl.ShaderCode;
@@ -43,7 +42,6 @@ import com.jogamp.opengl.test.junit.util.UITestCase;
import java.io.IOException;
import java.nio.FloatBuffer;
-import javax.media.nativewindow.util.DimensionImmutable;
import javax.media.opengl.GL;
import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLCapabilities;
@@ -73,9 +71,9 @@ public class TestRulerNEWT01 extends UITestCase {
System.err.println(winctx.context);
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
- // test code ..
+ // test code ..
final ShaderState st = new ShaderState();
-
+
final ShaderCode vp0 = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, RedSquareES2.class, "shader",
"shader/bin", "default", true);
final ShaderCode fp0 = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, RedSquareES2.class, "shader",
@@ -85,50 +83,47 @@ public class TestRulerNEWT01 extends UITestCase {
final ShaderProgram sp0 = new ShaderProgram();
sp0.add(gl, vp0, System.err);
- sp0.add(gl, fp0, System.err);
- Assert.assertTrue(0 != sp0.program());
+ sp0.add(gl, fp0, System.err);
+ Assert.assertTrue(0 != sp0.program());
Assert.assertTrue(!sp0.inUse());
Assert.assertTrue(!sp0.linked());
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
-
+
st.attachShaderProgram(gl, sp0, true);
-
+
final PMVMatrix pmvMatrix = new PMVMatrix();
final GLUniformData pmvMatrixUniform = new GLUniformData("gcu_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf());
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
- st.ownUniform(pmvMatrixUniform);
+ st.ownUniform(pmvMatrixUniform);
st.uniform(gl, pmvMatrixUniform);
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
-
+
final GLUniformData rulerColor= new GLUniformData("gcu_RulerColor", 3, Buffers.newDirectFloatBuffer(3));
final FloatBuffer rulerColorV = (FloatBuffer) rulerColor.getBuffer();
rulerColorV.put(0, 0.5f);
rulerColorV.put(1, 0.5f);
rulerColorV.put(2, 0.5f);
- st.ownUniform(rulerColor);
- st.uniform(gl, rulerColor);
+ st.ownUniform(rulerColor);
+ st.uniform(gl, rulerColor);
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
-
+
Assert.assertNotNull(winctx);
Assert.assertNotNull(winctx.window);
Assert.assertNotNull(winctx.window.getScreen());
- final MonitorDevice monitor = winctx.window.getMainMonitor();
- Assert.assertNotNull(monitor);
- System.err.println(monitor);
- final MonitorMode mmode = monitor.getCurrentMode();
- Assert.assertNotNull(mmode);
- System.err.println(mmode);
- final DimensionImmutable sdim = monitor.getSizeMM();
- final DimensionImmutable spix = mmode.getSurfaceSize().getResolution();
+ final float[] ppmmStore = { 0f, 0f };
+ {
+ final MonitorDevice monitor = winctx.window.getMainMonitor();
+ Assert.assertNotNull(monitor);
+ System.err.println(monitor);
+ monitor.getPixelsPerMM(ppmmStore);
+ }
final GLUniformData rulerPixFreq = new GLUniformData("gcu_RulerPixFreq", 2, Buffers.newDirectFloatBuffer(2));
final FloatBuffer rulerPixFreqV = (FloatBuffer) rulerPixFreq.getBuffer();
- rulerPixFreqV.put(0, (float)spix.getWidth() / (float)sdim.getWidth() * 10.0f);
- rulerPixFreqV.put(1, (float)spix.getHeight() / (float)sdim.getHeight() * 10.0f);
+ rulerPixFreqV.put(0, ppmmStore[0] * 10.0f);
+ rulerPixFreqV.put(1, ppmmStore[1] * 10.0f);
st.ownUniform(rulerPixFreq);
- st.uniform(gl, rulerPixFreq);
+ st.uniform(gl, rulerPixFreq);
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
- System.err.println("Screen dim "+sdim);
- System.err.println("Screen siz "+spix);
System.err.println("Screen pixel/cm "+rulerPixFreqV.get(0)+", "+rulerPixFreqV.get(1));
final GLArrayDataServer vertices0 = GLArrayDataServer.createGLSL("gca_Vertices", 3, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW);
@@ -138,7 +133,7 @@ public class TestRulerNEWT01 extends UITestCase {
vertices0.putf(1); vertices0.putf(0); vertices0.putf(0);
vertices0.seal(gl, true);
st.ownAttribute(vertices0, true);
-
+
// misc GL setup
gl.glClearColor(1, 1, 1, 1);
gl.glEnable(GL2ES2.GL_DEPTH_TEST);
@@ -154,29 +149,29 @@ public class TestRulerNEWT01 extends UITestCase {
// pmvMatrix.glTranslatef(0, 0, -6);
// pmvMatrix.glRotatef(45f, 1f, 0f, 0f);
st.uniform(gl, pmvMatrixUniform);
- gl.glViewport(0, 0, drawable.getWidth(), drawable.getHeight());
+ gl.glViewport(0, 0, drawable.getWidth(), drawable.getHeight());
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
-
+
for(int i=0; i<10; i++) {
vertices0.enableBuffer(gl, true);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
- gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4);
+ gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4);
vertices0.enableBuffer(gl, false);
drawable.swapBuffers();
Thread.sleep(durationPerTest/10);
}
-
+
long t2 = System.nanoTime();
-
+
NEWTGLContext.destroyWindow(winctx);
-
+
long t3 = System.nanoTime();
-
- System.err.println("t1-t0: "+ (t1-t0)/1e6 +"ms");
- System.err.println("t3-t0: "+ (t3-t0)/1e6 +"ms");
- System.err.println("t3-t2: "+ (t3-t2)/1e6 +"ms");
+
+ System.err.println("t1-t0: "+ (t1-t0)/1e6 +"ms");
+ System.err.println("t3-t0: "+ (t3-t0)/1e6 +"ms");
+ System.err.println("t3-t2: "+ (t3-t2)/1e6 +"ms");
}
-
+
public static void main(String args[]) throws IOException {
System.err.println("main - start");
for(int i=0; i<args.length; i++) {
@@ -187,6 +182,6 @@ public class TestRulerNEWT01 extends UITestCase {
String tstname = TestRulerNEWT01.class.getName();
org.junit.runner.JUnitCore.main(tstname);
System.err.println("main - end");
- }
+ }
}