aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-03-13 06:02:33 +0100
committerSven Gothel <[email protected]>2023-03-13 06:02:33 +0100
commite9a0f5cdc2bca9ca97175d2fa3c1b722a574b267 (patch)
treef492f20550cbac29b2072930b576e4e668c6e143
parent913b00f8b876e29af91677ef61b3eb35d6853e6e (diff)
Graph: Add GLRegion creation w/ pre-calculating its buffer sizes; TextRegionUtil: Use pre-calc'ing buffer sizes for GLRegion;
TextRendererGLELBase: Fix temp AffineTransform usage
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java39
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java23
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/PerfTextRendererNEWT00.java20
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java4
4 files changed, 64 insertions, 22 deletions
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 e02752f73..57f9a69d8 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
@@ -41,6 +41,7 @@ import jogamp.graph.curve.opengl.VBORegionSPES2;
import com.jogamp.opengl.util.PMVMatrix;
import com.jogamp.opengl.util.texture.TextureSequence;
import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.font.Font;
import java.io.PrintStream;
@@ -120,6 +121,44 @@ public abstract class GLRegion extends Region {
return GLRegion.create(glp, renderModes, colorTexSeq, defaultVerticesCount, defaultIndicesCount);
}
+ /**
+ * Create a GLRegion using the passed render mode and pre-calculating its buffer sizes
+ * using given font's {@link Font#processString(com.jogamp.graph.curve.OutlineShape.Visitor2, CharSequence)}
+ * to {@link #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 font Font used to {@link Font#processString(com.jogamp.graph.curve.OutlineShape.Visitor2, CharSequence)} to {@link #countOutlineShape(OutlineShape, int[]) to count initial number of vertices and indices}
+ * @param str the string used to to {@link #countOutlineShape(OutlineShape, int[]) to count initial number of vertices and indices}
+ */
+ public static GLRegion create(final GLProfile glp, int renderModes, final TextureSequence colorTexSeq, final Font font, final CharSequence str) {
+ if( null != colorTexSeq ) {
+ renderModes |= Region.COLORTEXTURE_RENDERING_BIT;
+ } else if( Region.hasColorTexture(renderModes) ) {
+ throw new IllegalArgumentException("COLORTEXTURE_RENDERING_BIT set but null TextureSequence");
+ }
+ GLRegion region;
+ if( isVBAA(renderModes) ) {
+ region = new VBORegion2PVBAAES2(glp, renderModes, colorTexSeq, Region.DEFAULT_TWO_PASS_TEXTURE_UNIT, 0, 0);
+ } else if( isMSAA(renderModes) ) {
+ region = new VBORegion2PMSAAES2(glp, renderModes, colorTexSeq, Region.DEFAULT_TWO_PASS_TEXTURE_UNIT, 0, 0);
+ } else {
+ region = new VBORegionSPES2(glp, renderModes, colorTexSeq, 0, 0);
+ }
+ final int[] vertIndexCount = { 0, 0 };
+ final OutlineShape.Visitor2 visitor = new OutlineShape.Visitor2() {
+ @Override
+ public final void visit(final OutlineShape shape) {
+ region.countOutlineShape(shape, vertIndexCount);
+ } };
+ font.processString(visitor, str);
+ region.setBufferCapacity(vertIndexCount[0], vertIndexCount[1]);
+ return region;
+ }
+
private final int gl_idx_type;
protected final TextureSequence colorTexSeq;
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 8d55c6136..de9ff5636 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java
@@ -125,6 +125,7 @@ public class TextRegionUtil {
* @param vertIndexCount the int[2] storage where the counted vertices and indices are added, vertices at [0] and indices at [1]
* @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 Region region, final Font font, final CharSequence str, final int[/*2*/] vertIndexCount) {
final OutlineShape.Visitor2 visitor = new OutlineShape.Visitor2() {
@@ -146,6 +147,9 @@ public class TextRegionUtil {
* <p>
* Cached {@link GLRegion}s will be destroyed w/ {@link #clear(GL2ES2)} or to free memory.
* </p>
+ * <p>
+ * The region's buffer size is pre-calculated via {@link GLRegion#create(com.jogamp.opengl.GLProfile, int, com.jogamp.opengl.util.texture.TextureSequence, Font, CharSequence)}
+ * </p>
* @param gl the current GL state
* @param renderer TODO
* @param font {@link Font} to be used
@@ -165,7 +169,7 @@ public class TextRegionUtil {
GLRegion region = getCachedRegion(font, str);
AABBox res;
if(null == region) {
- region = GLRegion.create(gl.getGLProfile(), renderModes, null);
+ region = GLRegion.create(gl.getGLProfile(), renderModes, null, font, str);
res = addStringToRegion(region, font, null, str, rgbaColor, tempT1, tempT2);
addCachedRegion(gl, font, str, region);
} else {
@@ -178,6 +182,9 @@ public class TextRegionUtil {
/**
* Try using {@link #drawString3D(GL2ES2, int, RegionRenderer, Font, CharSequence, float[], int[], AffineTransform, AffineTransform)} to reuse {@link AffineTransform} instances.
+ * <p>
+ * The region's buffer size is pre-calculated via {@link GLRegion#create(com.jogamp.opengl.GLProfile, int, com.jogamp.opengl.util.texture.TextureSequence, Font, CharSequence)}
+ * </p>
*/
public static AABBox drawString3D(final GL2ES2 gl, final int renderModes,
final RegionRenderer renderer, final Font font, final CharSequence str,
@@ -194,6 +201,9 @@ public class TextRegionUtil {
* Origin of rendered text is 0/0 at bottom left.
* </p>
* <p>
+ * The region's buffer size is pre-calculated via {@link GLRegion#create(com.jogamp.opengl.GLProfile, int, com.jogamp.opengl.util.texture.TextureSequence, Font, CharSequence)}
+ * </p>
+ * <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(GL2ES2, GLRegion, RegionRenderer, Font, CharSequence, float[], int[], AffineTransform, AffineTransform)}
@@ -217,7 +227,7 @@ public class TextRegionUtil {
if(!renderer.isInitialized()){
throw new GLException("TextRendererImpl01: not initialized!");
}
- final GLRegion region = GLRegion.create(gl.getGLProfile(), renderModes, null);
+ final GLRegion region = GLRegion.create(gl.getGLProfile(), renderModes, null, font, str);
final AABBox res = addStringToRegion(region, font, null, str, rgbaColor, tmp1, tmp2);
region.draw(gl, renderer, sampleCount);
region.destroy(gl);
@@ -226,6 +236,9 @@ public class TextRegionUtil {
/**
* Try using {@link #drawString3D(GL2ES2, GLRegion, RegionRenderer, Font, CharSequence, float[], int[], AffineTransform, AffineTransform)} to reuse {@link AffineTransform} instances.
+ * <p>
+ * The region's buffer size is pre-calculated via {@link #countStringRegion(Region, Font, CharSequence, int[])}.
+ * </p>
*/
public static AABBox drawString3D(final GL2ES2 gl, final GLRegion region, final RegionRenderer renderer,
final Font font, final CharSequence str, final float[] rgbaColor, final int[/*1*/] sampleCount) {
@@ -243,6 +256,9 @@ public class TextRegionUtil {
* <p>
* Origin of rendered text is 0/0 at bottom left.
* </p>
+ * <p>
+ * The region's buffer size is pre-calculated via {@link #countStringRegion(Region, Font, CharSequence, int[])}.
+ * </p>
* @param gl the current GL state
* @param region
* @param renderer
@@ -262,6 +278,9 @@ public class TextRegionUtil {
if(!renderer.isInitialized()){
throw new GLException("TextRendererImpl01: not initialized!");
}
+ final int[] vertIndCount = { 0, 0 };
+ TextRegionUtil.countStringRegion(region, font, str, vertIndCount);
+ region.growBuffer(vertIndCount[0], vertIndCount[1]);
final AABBox res = addStringToRegion(region, font, null, str, rgbaColor, tmp1, tmp2);
region.draw(gl, renderer, sampleCount);
return res;
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/PerfTextRendererNEWT00.java b/src/test/com/jogamp/opengl/test/junit/graph/PerfTextRendererNEWT00.java
index e31ed7ae3..1b6109af7 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/PerfTextRendererNEWT00.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/PerfTextRendererNEWT00.java
@@ -245,24 +245,8 @@ public class PerfTextRendererNEWT00 {
final RegionRenderer renderer = RegionRenderer.create(rs, RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
rs.setHintMask(RenderState.BITHINT_GLOBAL_DEPTH_TEST_ENABLED);
- // Since we know about the size ...
- // final GLRegion region = GLRegion.create(gl.getGLProfile(), renderModes, null);
- // region.growBufferSize(123000, 62000); // hack-me
- // FreeSans ~ vertices 68/char, indices 36/char
- // Ubuntu Light ~ vertices 100/char, indices 50/char
- // FreeSerif ~ vertices 115/char, indices 61/char
- // final int vertices_per_char = 68; // 100;
- // final int indices_per_char = 36; // 50;
- // final GLRegion region = GLRegion.create(gl.getGLProfile(), renderModes, null, text.length()*vertices_per_char, text.length()*indices_per_char);
- final GLRegion region = GLRegion.create(gl.getGLProfile(), renderModes, null);
- System.err.println("Region post ctor w/ default initial buffer size");
- region.printBufferStats(System.err);
-
- final int[] verticesIndicesCount = new int[] { 0, 0 };
- TextRegionUtil.countStringRegion(region, font, text, verticesIndicesCount);
- System.err.println("Region count: text "+text.length()+" chars -> vertices "+verticesIndicesCount[0]+", indices "+verticesIndicesCount[1]);
- region.setBufferCapacity(verticesIndicesCount[0], verticesIndicesCount[1]);
- System.err.println("Region post set-buffer-size w/ matching vertices "+verticesIndicesCount[0]+", indices "+verticesIndicesCount[1]);
+ final GLRegion region = GLRegion.create(gl.getGLProfile(), renderModes, null, font, text);
+ System.err.println("Region post ctor w/ pre-calculated buffer size");
region.printBufferStats(System.err);
final Perf perf = new Perf();
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 7a83501c6..b867c054e 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java
@@ -276,9 +276,9 @@ public abstract class TextRendererGLELBase implements GLEventListener {
if( cacheRegion ) {
textRenderUtil.drawString3D(gl, renderer, font, text, null, vbaaSampleCount);
} else if( null != region ) {
- TextRegionUtil.drawString3D(gl, region, renderer, font, text, null, vbaaSampleCount, tempT1, tempT1);
+ TextRegionUtil.drawString3D(gl, region, renderer, font, text, null, vbaaSampleCount, tempT1, tempT2);
} else {
- TextRegionUtil.drawString3D(gl, renderModes, renderer, font, text, null, vbaaSampleCount, tempT1, tempT1);
+ TextRegionUtil.drawString3D(gl, renderModes, renderer, font, text, null, vbaaSampleCount, tempT1, tempT2);
}
renderer.enable(gl, false);