summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-04-20 21:48:15 +0200
committerSven Gothel <[email protected]>2023-04-20 21:48:15 +0200
commitc21082a5d7caf0ae6e29144358b4b4a1eafec019 (patch)
treeb302c82c1c14896f5c55d7ce54b72b8a0ec6046b /src
parenta251f5734cc1f5c907f239c3ca3a4f1d4c262058 (diff)
Graph GLRegion/TextRegionUtil: Enhance pre-determination of buffer-size, increase default initial 16->64 (unsued)
- Region.countOutlineShape(..) now returns unpatched 3*triangle value for indices, avoiding grow - TextRegionUtil.addStringToRegion() uses countStringRegion(..) per default - Added GLRegion.create(.., OutlineShape) for convenience, using Region.countOutlineShape(..) - Refined API doc -
Diffstat (limited to 'src')
-rw-r--r--src/demos/com/jogamp/opengl/demos/av/MovieCube.java2
-rw-r--r--src/demos/com/jogamp/opengl/demos/av/MovieSBSStereo.java13
-rw-r--r--src/demos/com/jogamp/opengl/demos/av/MovieSimple.java2
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/GPURegionGLListener00.java2
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/GPURegionGLListener01.java2
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/GPURegionGLListener10.java5
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/GPUTextRendererListenerBase01.java6
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/Region.java34
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java49
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java43
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/GPURegionGLListener01.java2
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/GPURegionGLListener10.java5
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/GPUTextRendererListenerBase01.java6
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java4
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/GLReadBuffer00Base.java2
15 files changed, 119 insertions, 58 deletions
diff --git a/src/demos/com/jogamp/opengl/demos/av/MovieCube.java b/src/demos/com/jogamp/opengl/demos/av/MovieCube.java
index e7e393e18..0be2c35ba 100644
--- a/src/demos/com/jogamp/opengl/demos/av/MovieCube.java
+++ b/src/demos/com/jogamp/opengl/demos/av/MovieCube.java
@@ -171,7 +171,7 @@ public class MovieCube implements GLEventListener {
// FIXME: Graph TextRenderer does not AA well w/o MSAA and FBO
super(rmode, MovieCube.this.textSampleCount);
this.setRendererCallbacks(RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
- regionFPS = GLRegion.create(glp, renderModes, null);
+ regionFPS = GLRegion.create(glp, renderModes, null, 0, 0);
System.err.println("RegionFPS "+Region.getRenderModeString(renderModes)+", sampleCount "+textSampleCount[0]+", class "+regionFPS.getClass().getName());
staticRGBAColor[0] = 0.1f;
staticRGBAColor[1] = 0.1f;
diff --git a/src/demos/com/jogamp/opengl/demos/av/MovieSBSStereo.java b/src/demos/com/jogamp/opengl/demos/av/MovieSBSStereo.java
index 5fd70f97c..3c3350061 100644
--- a/src/demos/com/jogamp/opengl/demos/av/MovieSBSStereo.java
+++ b/src/demos/com/jogamp/opengl/demos/av/MovieSBSStereo.java
@@ -141,16 +141,12 @@ public class MovieSBSStereo implements StereoGLEventListener {
private final float fontSize = 1f; // 0.01f;
private final GLRegion regionFPS;
- InfoTextRendererGLELBase(final GLProfile glp, final int rmode, final boolean lowPerfDevice) {
+ InfoTextRendererGLELBase(final GLProfile glp, final int rmode) {
// FIXME: Graph TextRenderer does not AA well w/o MSAA and FBO
super(rmode, textSampleCount);
this.setRendererCallbacks(RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
- if( lowPerfDevice ) {
- regionFPS = null;
- } else {
- regionFPS = GLRegion.create(glp, renderModes, null);
- System.err.println("RegionFPS "+Region.getRenderModeString(renderModes)+", sampleCount "+textSampleCount[0]+", class "+regionFPS.getClass().getName());
- }
+ regionFPS = GLRegion.create(glp, renderModes, null, 0, 0);
+ System.err.println("RegionFPS "+Region.getRenderModeString(renderModes)+", sampleCount "+textSampleCount[0]+", class "+regionFPS.getClass().getName());
staticRGBAColor[0] = 0.9f;
staticRGBAColor[1] = 0.9f;
staticRGBAColor[2] = 0.9f;
@@ -545,9 +541,8 @@ public class MovieSBSStereo implements StereoGLEventListener {
surfHeight = window.getSurfaceHeight();
}
final int rmode = drawable.getChosenGLCapabilities().getSampleBuffers() ? 0 : Region.VBAA_RENDERING_BIT;
- final boolean lowPerfDevice = gl.isGLES();
if( enableTextRendererGLEL ) {
- textRendererGLEL = new InfoTextRendererGLELBase(gl.getGLProfile(), rmode, lowPerfDevice);
+ textRendererGLEL = new InfoTextRendererGLELBase(gl.getGLProfile(), rmode);
textRendererGLEL.init(drawable);
} else {
textRendererGLEL = null;
diff --git a/src/demos/com/jogamp/opengl/demos/av/MovieSimple.java b/src/demos/com/jogamp/opengl/demos/av/MovieSimple.java
index 6a5e932b9..deed019d1 100644
--- a/src/demos/com/jogamp/opengl/demos/av/MovieSimple.java
+++ b/src/demos/com/jogamp/opengl/demos/av/MovieSimple.java
@@ -126,7 +126,7 @@ public class MovieSimple implements GLEventListener {
// FIXME: Graph TextRenderer does not AA well w/o MSAA and FBO
super(rmode, textSampleCount);
this.setRendererCallbacks(RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
- regionFPS = GLRegion.create(glp, renderModes, null);
+ regionFPS = GLRegion.create(glp, renderModes, null, 0, 0);
System.err.println("RegionFPS "+Region.getRenderModeString(renderModes)+", sampleCount "+textSampleCount[0]+", class "+regionFPS.getClass().getName());
staticRGBAColor[0] = 0.9f;
staticRGBAColor[1] = 0.9f;
diff --git a/src/demos/com/jogamp/opengl/demos/graph/GPURegionGLListener00.java b/src/demos/com/jogamp/opengl/demos/graph/GPURegionGLListener00.java
index 6cb19101c..1ec894d15 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/GPURegionGLListener00.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/GPURegionGLListener00.java
@@ -91,7 +91,7 @@ public class GPURegionGLListener00 extends GPURendererListenerBase01 {
outlineShape.addVertex(offset+10.0f,0.0f, true);
outlineShape.closeLastOutline(true);
- region = GLRegion.create(glp, getRenderModes(), null);
+ region = GLRegion.create(glp, getRenderModes(), null, outlineShape);
region.addOutlineShape(outlineShape, null, region.hasColorChannel() ? getRenderer().getRenderState().getColorStatic(new Vec4f()) : null);
}
diff --git a/src/demos/com/jogamp/opengl/demos/graph/GPURegionGLListener01.java b/src/demos/com/jogamp/opengl/demos/graph/GPURegionGLListener01.java
index 404e502cf..fd1ba4df3 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/GPURegionGLListener01.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/GPURegionGLListener01.java
@@ -272,7 +272,7 @@ public class GPURegionGLListener01 extends GPURendererListenerBase01 {
createTestOutline01();
break;
}
- region = GLRegion.create(gl.getGLProfile(), getRenderModes(), null);
+ region = GLRegion.create(gl.getGLProfile(), getRenderModes(), null, outlineShape);
region.addOutlineShape(outlineShape, null, region.hasColorChannel() ? getRenderer().getRenderState().getColorStatic(new Vec4f()) : null);
}
diff --git a/src/demos/com/jogamp/opengl/demos/graph/GPURegionGLListener10.java b/src/demos/com/jogamp/opengl/demos/graph/GPURegionGLListener10.java
index 6024b1410..f23d15b24 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/GPURegionGLListener10.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/GPURegionGLListener10.java
@@ -38,6 +38,7 @@ import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
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.graph.curve.opengl.RegionRenderer;
@@ -73,6 +74,7 @@ public class GPURegionGLListener10 extends GPURendererListenerBase01 {
shape.addVertex(10.0f,0.0f, true);
shape.addVertex(5.0f,0.0f, false);
shape.closeLastOutline(true);
+ final int[/*2*/] vertIndexCount = Region.countOutlineShape(shape, new int[2]);
/** Same shape as above but without any off-curve vertices */
shape = new OutlineShape();
@@ -92,8 +94,9 @@ public class GPURegionGLListener10 extends GPURendererListenerBase01 {
shape.addVertex(offset+10.0f,-5.0f, true);
shape.addVertex(offset+10.0f,0.0f, true);
shape.closeLastOutline(true);
+ Region.countOutlineShape(shape, vertIndexCount);
- region = GLRegion.create(glp, getRenderModes(), null);
+ region = GLRegion.create(glp, getRenderModes(), null, vertIndexCount[0], vertIndexCount[1]);
region.addOutlineShapes(outlineShapes, null, null);
}
diff --git a/src/demos/com/jogamp/opengl/demos/graph/GPUTextRendererListenerBase01.java b/src/demos/com/jogamp/opengl/demos/graph/GPUTextRendererListenerBase01.java
index 9685f2cf9..26feafa5a 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/GPUTextRendererListenerBase01.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/GPUTextRendererListenerBase01.java
@@ -156,9 +156,9 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
renderModes, debug, trace);
this.getRenderer().getRenderState().setHintMask(RenderState.BITHINT_GLOBAL_DEPTH_TEST_ENABLED);
this.textRegionUtil = new TextRegionUtil(renderModes);
- this.regionFPS = GLRegion.create(glp, renderModes, null);
- this.regionHead = GLRegion.create(glp, renderModes, null);
- this.regionBottom = GLRegion.create(glp, renderModes, null);
+ this.regionFPS = GLRegion.create(glp, renderModes, null, 0, 0);
+ this.regionHead = GLRegion.create(glp, renderModes, null, 0, 0);
+ this.regionBottom = GLRegion.create(glp, renderModes, null, 0, 0);
setFontSet(fontSet, FontSet.FAMILY_LIGHT, FontSet.STYLE_NONE);
setMatrix(0, 0, 0, 0f, sampleCount);
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java
index 820911bbf..28ac1a134 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/Region.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java
@@ -236,27 +236,32 @@ public abstract class Region {
public final boolean usesI32Idx() { return this.use_int32_idx; }
/**
- * Allow the renderer buffers to pre-emptively grow for given vertices- and index counts.
- * @param verticesCount number of vertices to hold
- * @param indicesCount number of indices to hold
+ * Increase the renderer buffers if necessary to add given counts of vertices- and index elements.
+ * <p>
+ * Buffers will not change if remaining free slots, capacity less position, satisfy count elements.
+ * </p>
+ * @param verticesCount number of vertex elements to add if necessary
+ * @param indicesCount number of index elements to add if necessary
+ * @return true if buffer size has changed, i.e. grown. Otherwise false.
* @see #setBufferCapacity(int, int)
* @see #countOutlineShape(OutlineShape, int[])
* @see #countOutlineShapes(List, int[])
*/
- public abstract void growBuffer(int verticesCount, int indicesCount);
+ public abstract boolean growBuffer(int verticesCount, int indicesCount);
/**
* Set the renderer buffers pre-emptively for given vertices- and index counts.
* <p>
- * If the buffers already exceeds given numbers, the buffers are unchanged.
+ * Buffers will not change if given count elements is lower or equal current capacity.
* </p>
* @param verticesCount number of vertices to hold
* @param indicesCount number of indices to hold
+ * @return true if buffer size has changed, i.e. grown. Otherwise false.
* @see #growBuffer(int, int)
* @see #countOutlineShape(OutlineShape, int[])
* @see #countOutlineShapes(List, int[])
*/
- public abstract void setBufferCapacity(int verticesCount, int indicesCount);
+ public abstract boolean setBufferCapacity(int verticesCount, int indicesCount);
protected abstract void pushVertex(final Vec3f coords, final Vec3f texParams, Vec4f rgba);
protected abstract void pushVertices(final Vec3f coords1, final Vec3f coords2, final Vec3f coords3,
@@ -487,18 +492,21 @@ public abstract class Region {
* </p>
* @param shape the {@link OutlineShape} to count
* @param vertIndexCount the int[2] storage where the counted vertices and indices are added, vertices at [0] and indices at [1]
+ * @return the given int[2] storage for chaining
* @see #setBufferCapacity(int, int)
* @see #growBuffer(int, int)
*/
- public static final void countOutlineShape(final OutlineShape shape, final int[/*2*/] vertIndexCount) {
+ public static final int[] countOutlineShape(final OutlineShape shape, final int[/*2*/] vertIndexCount) {
+ if( null == shape ) {
+ return vertIndexCount;
+ }
final List<Triangle> trisIn = shape.getTriangles(OutlineShape.VerticesState.QUADRATIC_NURBS);
final ArrayList<Vertex> vertsIn = shape.getVertices();
{
- final int verticeCount = vertsIn.size() + shape.getAddedVerticeCount();
- final int indexCount = trisIn.size() * 3;
- vertIndexCount[0] += verticeCount;
- vertIndexCount[1] += Math.min( Math.ceil(verticeCount * 0.9), indexCount );
+ vertIndexCount[0] += vertsIn.size() + shape.getAddedVerticeCount(); // verticesCount
+ vertIndexCount[1] += trisIn.size() * 3; // indicesCount
}
+ return vertIndexCount;
}
/**
@@ -510,13 +518,15 @@ public abstract class Region {
* </p>
* @param shapes list of {@link OutlineShape} to count
* @param vertIndexCount the int[2] storage where the counted vertices and indices are added, vertices at [0] and indices at [1]
+ * @return the given int[2] storage for chaining
* @see #setBufferCapacity(int, int)
* @see #growBuffer(int, int)
*/
- public static final void countOutlineShapes(final List<OutlineShape> shapes, final int[/*2*/] vertIndexCount) {
+ public static final int[] countOutlineShapes(final List<OutlineShape> shapes, final int[/*2*/] vertIndexCount) {
for (int i = 0; i < shapes.size(); i++) {
countOutlineShape(shapes.get(i), vertIndexCount);
}
+ return vertIndexCount;
}
/**
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 db3a935cf..9117d1aee 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
@@ -84,12 +84,12 @@ public abstract class GLRegion extends Region {
/**
* Default initial vertices count {@value}, assuming small sized shapes.
*/
- public static final int defaultVerticesCount = 16;
+ public static final int defaultVerticesCount = 64;
/**
* Default initial indices count {@value}, assuming small sized shapes.
*/
- public static final int defaultIndicesCount = 16;
+ public static final int defaultIndicesCount = 64;
// private static final float growthFactor = 1.2f; // avg +5% size but 15% more overhead (34% total)
protected static final float growthFactor = GLArrayDataClient.DEFAULT_GROWTH_FACTOR; // avg +20% size, but 15% less CPU overhead compared to 1.2 (19% total)
@@ -121,7 +121,7 @@ public abstract class GLRegion extends Region {
}
/**
- * Create a GLRegion using the passed render mode
+ * Create a GLRegion using the passed render mode and default initial buffer sizes {@link #defaultVerticesCount} and {@link #defaultIndicesCount}.
*
* <p> In case {@link Region#VBAA_RENDERING_BIT} is being requested the default texture unit
* {@link Region#DEFAULT_TWO_PASS_TEXTURE_UNIT} is being used.</p>
@@ -135,6 +135,22 @@ public abstract class GLRegion extends Region {
/**
* Create a GLRegion using the passed render mode and pre-calculating its buffer sizes
+ * using {@link Region#countOutlineShape(OutlineShape, int[])}.
+ *
+ * <p> In case {@link Region#VBAA_RENDERING_BIT} is being requested the default texture unit
+ * {@link Region#DEFAULT_TWO_PASS_TEXTURE_UNIT} is being used.</p>
+ * @param glp intended GLProfile to use. Instance may use higher OpenGL features if indicated by GLProfile.
+ * @param renderModes bit-field of modes, e.g. {@link Region#VARWEIGHT_RENDERING_BIT}, {@link Region#VBAA_RENDERING_BIT}
+ * @param colorTexSeq optional {@link TextureSequence} for {@link Region#COLORTEXTURE_RENDERING_BIT} rendering mode.
+ * @param shape the {@link OutlineShape} used to determine {@link GLRegion}'s buffer sizes via {@link Region#countOutlineShape(OutlineShape, int[])}
+ */
+ public static GLRegion create(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq, final OutlineShape shape) {
+ final int[/*2*/] vertIndexCount = Region.countOutlineShape(shape, new int[2]);
+ return GLRegion.create(glp, renderModes, colorTexSeq, vertIndexCount[0], vertIndexCount[1]);
+ }
+
+ /**
+ * Create a GLRegion using the passed render mode and pre-calculating its buffer sizes
* using given font's {@link Font#processString(com.jogamp.graph.font.Font.GlyphVisitor2, CharSequence)}
* to {@link #countOutlineShape(OutlineShape, int[])}.
*
@@ -213,39 +229,47 @@ public abstract class GLRegion extends Region {
}
@Override
- public final void growBuffer(final int verticesCount, final int indicesCount) {
+ public final boolean growBuffer(final int verticesCount, final int indicesCount) {
boolean grown = false;
if( curIndicesCap < indicesBuffer.elemPosition() + indicesCount ) {
- // System.err.printf("XXX Buffer grow - Indices: %d < ( %d = %d + %d ); Status: %s%n",
- // curIndicesCap, indicesBuffer.elemPosition() + indicesCount, indicesBuffer.elemPosition(), indicesCount, indicesBuffer.elemStatsToString());
+ System.err.printf("XXX Buffer grow - Indices: %d < ( %d = %d + %d ); Status: %s%n",
+ curIndicesCap, indicesBuffer.elemPosition() + indicesCount, indicesBuffer.elemPosition(), indicesCount, indicesBuffer.elemStatsToString());
indicesBuffer.growIfNeeded(indicesCount * indicesBuffer.getCompsPerElem());
- // System.err.println("grew.indices 0x"+Integer.toHexString(hashCode())+": "+curIndicesCap+" -> "+indicesBuffer.getElemCapacity()+", "+indicesBuffer.elemStatsToString());
+ System.err.println("grew.indices 0x"+Integer.toHexString(hashCode())+": "+curIndicesCap+" -> "+indicesBuffer.getElemCapacity()+", "+indicesBuffer.elemStatsToString());
+ Thread.dumpStack();
curIndicesCap = indicesBuffer.getElemCapacity();
grown = true;
}
if( curVerticesCap < vpc_ileave.elemPosition() + verticesCount ) {
- // System.err.printf("XXX Buffer grow - Verices: %d < ( %d = %d + %d ); Status: %s%n",
- // curVerticesCap, gca_VerticesAttr.elemPosition() + verticesCount, gca_VerticesAttr.elemPosition(), verticesCount, gca_VerticesAttr.elemStatsToString());
+ System.err.printf("XXX Buffer grow - Verices: %d < ( %d = %d + %d ); Status: %s%n",
+ curVerticesCap, gca_VerticesAttr.elemPosition() + verticesCount, gca_VerticesAttr.elemPosition(), verticesCount, gca_VerticesAttr.elemStatsToString());
vpc_ileave.growIfNeeded(verticesCount * vpc_ileave.getCompsPerElem());
- // System.err.println("grew.vertices 0x"+Integer.toHexString(hashCode())+": "+curVerticesCap+" -> "+gca_VerticesAttr.getElemCapacity()+", "+gca_VerticesAttr.elemStatsToString());
+ System.err.println("grew.vertices 0x"+Integer.toHexString(hashCode())+": "+curVerticesCap+" -> "+gca_VerticesAttr.getElemCapacity()+", "+gca_VerticesAttr.elemStatsToString());
curVerticesCap = vpc_ileave.getElemCapacity();
grown = true;
}
if( grown ) {
++growCount;
+ return true;
+ } else {
+ return false;
}
}
@Override
- public final void setBufferCapacity(final int verticesCount, final int indicesCount) {
+ public final boolean setBufferCapacity(final int verticesCount, final int indicesCount) {
+ boolean grown = false;
if( curIndicesCap < indicesCount ) {
indicesBuffer.reserve(indicesCount);
curIndicesCap = indicesBuffer.getElemCapacity();
+ grown = true;
}
if( curVerticesCap < verticesCount ) {
vpc_ileave.reserve(verticesCount);
curVerticesCap = vpc_ileave.getElemCapacity();
+ grown = true;
}
+ return grown;
}
@Override
@@ -409,6 +433,9 @@ public abstract class GLRegion extends Region {
indicesBuffer.destroy(gl);
indicesBuffer = null;
}
+ curVerticesCap = 0;
+ curIndicesCap = 0;
+ growCount = 0;
destroyImpl(gl);
}
protected abstract void destroyImpl(final GL2ES2 gl);
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java
index 8e41ddaa4..428bb350d 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java
@@ -76,7 +76,7 @@ public class TextRegionUtil {
* Origin of rendered text is 0/0 at bottom left.
* </p>
* <p>
- * The region buffer's size is grown by pre-calculating required string size via {@link #countStringRegion(Font, CharSequence, int[])}.
+ * The region buffer's size is grown by pre-calculating required size via {@link #countStringRegion(Font, CharSequence, int[])}.
* </p>
* @param region the {@link GLRegion} sink
* @param font the target {@link Font}
@@ -100,7 +100,7 @@ public class TextRegionUtil {
* Origin of rendered text is 0/0 at bottom left.
* </p>
* <p>
- * The region buffer's size is grown by pre-calculating required string size via {@link #countStringRegion(Font, CharSequence, int[])}.
+ * The region buffer's size is grown by pre-calculating required size via {@link #countStringRegion(Font, CharSequence, int[])}.
* </p>
* @param region the {@link GLRegion} sink
* @param font the target {@link Font}
@@ -117,9 +117,31 @@ public class TextRegionUtil {
return addStringToRegion(true /* preGrowRegion */, region, font, transform, str, rgbaColor, temp1, temp2);
}
- private static AABBox addStringToRegion(final boolean preGrowRegion, final Region region, final Font font, final AffineTransform transform,
- final CharSequence str, final Vec4f rgbaColor,
- final AffineTransform temp1, final AffineTransform temp2) {
+ /**
+ * Add the string in 3D space w.r.t. the font in font em-size [0..1] at the end of the {@link GLRegion}
+ * while passing the progressed {@link AffineTransform}.
+ * <p>
+ * The shapes added to the GLRegion are in font em-size [0..1], but can be adjusted with the given transform, progressed and passed to the visitor.
+ * </p>
+ * <p>
+ * Origin of rendered text is 0/0 at bottom left.
+ * </p>
+ * <p>
+ * Depending on `preGrowRegion`, the region buffer's size is grown by pre-calculating required size via {@link #countStringRegion(Font, CharSequence, int[])}.
+ * </p>
+ * @param preGrowRegion if true, utilizes {@link #countStringRegion(Font, CharSequence, int[])} to pre-calc required buffer size, otherwise not.
+ * @param region the {@link GLRegion} sink
+ * @param font the target {@link Font}
+ * @param transform optional given transform
+ * @param str string text
+ * @param rgbaColor if {@link Region#hasColorChannel()} RGBA color must be passed, otherwise value is ignored.
+ * @param temp1 temporary AffineTransform storage, mandatory
+ * @param temp2 temporary AffineTransform storage, mandatory
+ * @return the bounding box of the given string by taking each glyph's font em-sized [0..1] OutlineShape into account.
+ */
+ public static AABBox addStringToRegion(final boolean preGrowRegion, final Region region, final Font font, final AffineTransform transform,
+ final CharSequence str, final Vec4f rgbaColor,
+ final AffineTransform temp1, final AffineTransform temp2) {
final Font.GlyphVisitor visitor = new Font.GlyphVisitor() {
@Override
public void visit(final char symbol, final Glyph glyph, final AffineTransform t) {
@@ -130,8 +152,7 @@ public class TextRegionUtil {
}
};
if( preGrowRegion ) {
- final int[] vertIndCount = { 0, 0 };
- countStringRegion(font, str, vertIndCount);
+ final int[] vertIndCount = countStringRegion(font, str, new int[2]);
region.growBuffer(vertIndCount[0], vertIndCount[1]);
}
return font.processString(visitor, transform, str, temp1, temp2);
@@ -145,17 +166,19 @@ public class TextRegionUtil {
* @param font the target {@link Font}
* @param str string text
* @param vertIndexCount the int[2] storage where the counted vertices and indices are added, vertices at [0] and indices at [1]
+ * @return the given int[2] storage for chaining
* @see Region#setBufferCapacity(int, int)
* @see Region#growBuffer(int, int)
* @see #drawString3D(GL2ES2, GLRegion, RegionRenderer, Font, CharSequence, float[], int[], AffineTransform, AffineTransform)
*/
- public static void countStringRegion(final Font font, final CharSequence str, final int[/*2*/] vertIndexCount) {
+ public static int[] countStringRegion(final Font font, final CharSequence str, final int[/*2*/] vertIndexCount) {
final Font.GlyphVisitor2 visitor = new Font.GlyphVisitor2() {
@Override
public final void visit(final char symbol, final Font.Glyph glyph) {
Region.countOutlineShape(glyph.getShape(), vertIndexCount);
} };
font.processString(visitor, str);
+ return vertIndexCount;
}
/**
@@ -259,7 +282,7 @@ public class TextRegionUtil {
/**
* Try using {@link #drawString3D(GL2ES2, GLRegion, RegionRenderer, Font, CharSequence, float[], int[], AffineTransform, AffineTransform)} to reuse {@link AffineTransform} instances.
* <p>
- * The region buffer's size is grown by pre-calculating required string size via {@link #countStringRegion(Font, CharSequence, int[])}.
+ * The region buffer's size is grown by pre-calculating required size via {@link #countStringRegion(Font, CharSequence, int[])}.
* </p>
*/
public static AABBox drawString3D(final GL2ES2 gl, final GLRegion region, final RegionRenderer renderer,
@@ -279,7 +302,7 @@ public class TextRegionUtil {
* Origin of rendered text is 0/0 at bottom left.
* </p>
* <p>
- * The region buffer's size is grown by pre-calculating required string size via {@link #countStringRegion(Font, CharSequence, int[])}.
+ * The region buffer's size is grown by pre-calculating required size via {@link #countStringRegion(Font, CharSequence, int[])}.
* </p>
* @param gl the current GL state
* @param region
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/GPURegionGLListener01.java b/src/test/com/jogamp/opengl/test/junit/graph/GPURegionGLListener01.java
index fd4ec47b1..0b25b3d3a 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/GPURegionGLListener01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/GPURegionGLListener01.java
@@ -272,7 +272,7 @@ public class GPURegionGLListener01 extends GPURendererListenerBase01 {
createTestOutline01();
break;
}
- region = GLRegion.create(gl.getGLProfile(), getRenderModes(), null);
+ region = GLRegion.create(gl.getGLProfile(), getRenderModes(), null, outlineShape);
region.addOutlineShape(outlineShape, null, region.hasColorChannel() ? getRenderer().getRenderState().getColorStatic(new Vec4f()) : null);
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/GPURegionGLListener10.java b/src/test/com/jogamp/opengl/test/junit/graph/GPURegionGLListener10.java
index 80beafd60..10cabb213 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/GPURegionGLListener10.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/GPURegionGLListener10.java
@@ -38,6 +38,7 @@ import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
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.graph.curve.opengl.RegionRenderer;
@@ -73,6 +74,7 @@ public class GPURegionGLListener10 extends GPURendererListenerBase01 {
shape.addVertex(10.0f,0.0f, true);
shape.addVertex(5.0f,0.0f, false);
shape.closeLastOutline(true);
+ final int[/*2*/] vertIndexCount = Region.countOutlineShape(shape, new int[2]);
/** Same shape as above but without any off-curve vertices */
shape = new OutlineShape();
@@ -92,8 +94,9 @@ public class GPURegionGLListener10 extends GPURendererListenerBase01 {
shape.addVertex(offset+10.0f,-5.0f, true);
shape.addVertex(offset+10.0f,0.0f, true);
shape.closeLastOutline(true);
+ Region.countOutlineShape(shape, vertIndexCount);
- region = GLRegion.create(glp, getRenderModes(), null);
+ region = GLRegion.create(glp, getRenderModes(), null, vertIndexCount[0], vertIndexCount[1]);
region.addOutlineShapes(outlineShapes, null, null);
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/GPUTextRendererListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/GPUTextRendererListenerBase01.java
index 8a7cd0e1b..f4283bf41 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/GPUTextRendererListenerBase01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/GPUTextRendererListenerBase01.java
@@ -155,9 +155,9 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
renderModes, debug, trace);
this.getRenderer().getRenderState().setHintMask(RenderState.BITHINT_GLOBAL_DEPTH_TEST_ENABLED);
this.textRegionUtil = new TextRegionUtil(renderModes);
- this.regionFPS = GLRegion.create(glp, renderModes, null);
- this.regionHead = GLRegion.create(glp, renderModes, null);
- this.regionBottom = GLRegion.create(glp, renderModes, null);
+ this.regionFPS = GLRegion.create(glp, renderModes, null, 0, 0);
+ this.regionHead = GLRegion.create(glp, renderModes, null, 0, 0);
+ this.regionBottom = GLRegion.create(glp, renderModes, null, 0, 0);
setFontSet(fontSet, FontSet.FAMILY_LIGHT, FontSet.STYLE_NONE);
setMatrix(0, 0, 0, 0f, sampleCount);
}
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 6a666cf21..23da67b3c 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java
@@ -295,8 +295,8 @@ public class TestTextRendererNEWT10 extends UITestCase {
super(renderModes, new int[] { sampleCount });
setRendererCallbacks(RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
- regionFPS = GLRegion.create(glp, renderModes, null);
- regionFPSAnim = GLRegion.create(glp, renderModes, null);
+ regionFPS = GLRegion.create(glp, renderModes, null, 0, 0);
+ regionFPSAnim = GLRegion.create(glp, renderModes, null, 0, 0);
if( null != fontURL ) {
Font _font = null;
try {
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 c8ce8b1c2..935a02dd2 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
@@ -76,7 +76,7 @@ public abstract class GLReadBuffer00Base extends UITestCase {
// FIXME: Graph TextRenderer does not AA well w/o MSAA and FBO
super(Region.VBAA_RENDERING_BIT, new int[] { 4 });
this.setRendererCallbacks(RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
- regionFPS = GLRegion.create(glp, renderModes, null);
+ regionFPS = GLRegion.create(glp, renderModes, null, 0, 0);
staticRGBAColor[0] = 0.9f;
staticRGBAColor[1] = 0.9f;