diff options
Diffstat (limited to 'src/jogl/classes/com/jogamp')
3 files changed, 40 insertions, 33 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java index 799b8b7bd..e897acba1 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/Region.java +++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java @@ -477,14 +477,20 @@ public abstract class Region { /** * Count required number of vertices and indices adding to given int[2] `vertIndexCount` array. * <p> - * The region's buffer can be either set using {@link Region#setBufferCapacity(int, int)} or grown using {@link Region#growBuffer(int, int)}. + * The region's buffer can be either set using {@link Region#setBufferCapacity(int, int)}, + * {@link GLRegion#create(GLProfile, int, TextureSequence, int, int) GLRegion ctor w/ initial capacities} + * or grown using {@link Region#growBuffer(int, int)}. + * </p> + * <p> + * Method is utilized in {@link GLRegion#create(GLProfile, int, TextureSequence, com.jogamp.graph.font.Font, CharSequence) GLRegion ctor w/ font + text}, + * computing the initial capacity. * </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] * @see #setBufferCapacity(int, int) * @see #growBuffer(int, int) */ - public final void countOutlineShape(final OutlineShape shape, final int[/*2*/] vertIndexCount) { + public static final void countOutlineShape(final OutlineShape shape, final int[/*2*/] vertIndexCount) { final List<Triangle> trisIn = shape.getTriangles(OutlineShape.VerticesState.QUADRATIC_NURBS); final ArrayList<Vertex> vertsIn = shape.getVertices(); { @@ -498,14 +504,16 @@ public abstract class Region { /** * Count required number of vertices and indices adding to given int[2] `vertIndexCount` array. * <p> - * The region's buffer can be either set using {@link Region#setBufferCapacity(int, int)} or grown using {@link Region#growBuffer(int, int)}. + * The region's buffer can be either set using {@link Region#setBufferCapacity(int, int)}, + * {@link GLRegion#create(GLProfile, int, TextureSequence, int, int) GLRegion ctor w/ initial capacities} + * or grown using {@link Region#growBuffer(int, int)}. * </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] * @see #setBufferCapacity(int, int) * @see #growBuffer(int, int) */ - public final void countOutlineShapes(final List<OutlineShape> shapes, final int[/*2*/] vertIndexCount) { + public static final void countOutlineShapes(final List<OutlineShape> shapes, final int[/*2*/] vertIndexCount) { for (int i = 0; i < shapes.size(); i++) { countOutlineShape(shapes.get(i), 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 402a238c9..d02ff28d0 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java @@ -136,29 +136,15 @@ public abstract class GLRegion extends Region { * @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);
- }
+ public static GLRegion create(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq, final Font font, final CharSequence str) {
final int[] vertIndexCount = { 0, 0 };
final Font.GlyphVisitor2 visitor = new Font.GlyphVisitor2() {
@Override
public final void visit(final char symbol, final Font.Glyph glyph) {
- region.countOutlineShape(glyph.getShape(), vertIndexCount);
+ Region.countOutlineShape(glyph.getShape(), vertIndexCount);
} };
font.processString(visitor, str);
- region.setBufferCapacity(vertIndexCount[0], vertIndexCount[1]);
- return region;
+ return GLRegion.create(glp, renderModes, colorTexSeq, vertIndexCount[0], vertIndexCount[1]);
}
private final int gl_idx_type;
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 6beb11be1..8e41ddaa4 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java @@ -75,6 +75,9 @@ public class TextRegionUtil { * <p> * 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[])}. + * </p> * @param region the {@link GLRegion} sink * @param font the target {@link Font} * @param transform optional given transform @@ -84,7 +87,7 @@ public class TextRegionUtil { */ public static AABBox addStringToRegion(final Region region, final Font font, final AffineTransform transform, final CharSequence str, final Vec4f rgbaColor) { - return addStringToRegion(region, font, transform, str, rgbaColor, new AffineTransform(), new AffineTransform()); + return addStringToRegion(true /* preGrowRegion */, region, font, transform, str, rgbaColor, new AffineTransform(), new AffineTransform()); } /** @@ -96,6 +99,9 @@ public class TextRegionUtil { * <p> * 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[])}. + * </p> * @param region the {@link GLRegion} sink * @param font the target {@link Font} * @param transform optional given transform @@ -108,6 +114,12 @@ public class TextRegionUtil { public static AABBox addStringToRegion(final Region region, final Font font, final AffineTransform transform, final CharSequence str, final Vec4f rgbaColor, final AffineTransform temp1, final AffineTransform temp2) { + 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) { final Font.GlyphVisitor visitor = new Font.GlyphVisitor() { @Override public void visit(final char symbol, final Glyph glyph, final AffineTransform t) { @@ -117,6 +129,11 @@ public class TextRegionUtil { region.addOutlineShape(glyph.getShape(), t, rgbaColor); } }; + if( preGrowRegion ) { + final int[] vertIndCount = { 0, 0 }; + countStringRegion(font, str, vertIndCount); + region.growBuffer(vertIndCount[0], vertIndCount[1]); + } return font.processString(visitor, transform, str, temp1, temp2); } @@ -125,7 +142,6 @@ public class TextRegionUtil { * <p> * The region's buffer can be either set using {@link Region#setBufferCapacity(int, int)} or grown using {@link Region#growBuffer(int, int)}. * </p> - * @param region the {@link GLRegion} sink * @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] @@ -133,11 +149,11 @@ public class TextRegionUtil { * @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) { + public static void 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); + Region.countOutlineShape(glyph.getShape(), vertIndexCount); } }; font.processString(visitor, str); } @@ -176,7 +192,7 @@ public class TextRegionUtil { AABBox res; if(null == region) { region = GLRegion.create(gl.getGLProfile(), renderModes, null, font, str); - res = addStringToRegion(region, font, null, str, rgbaColor, tempT1, tempT2); + res = addStringToRegion(false /* preGrowRegion */, region, font, null, str, rgbaColor, tempT1, tempT2); addCachedRegion(gl, font, str, region); } else { res = new AABBox(); @@ -234,7 +250,7 @@ public class TextRegionUtil { throw new GLException("TextRendererImpl01: not initialized!"); } final GLRegion region = GLRegion.create(gl.getGLProfile(), renderModes, null, font, str); - final AABBox res = addStringToRegion(region, font, null, str, rgbaColor, tmp1, tmp2); + final AABBox res = addStringToRegion(false /* preGrowRegion */, region, font, null, str, rgbaColor, tmp1, tmp2); region.draw(gl, renderer, sampleCount); region.destroy(gl); return res; @@ -243,7 +259,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's buffer size is pre-calculated via {@link #countStringRegion(Region, Font, CharSequence, int[])}. + * The region buffer's size is grown by pre-calculating required string size via {@link #countStringRegion(Font, CharSequence, int[])}. * </p> */ public static AABBox drawString3D(final GL2ES2 gl, final GLRegion region, final RegionRenderer renderer, @@ -263,7 +279,7 @@ 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 #countStringRegion(Region, Font, CharSequence, int[])}. + * The region buffer's size is grown by pre-calculating required string size via {@link #countStringRegion(Font, CharSequence, int[])}. * </p> * @param gl the current GL state * @param region @@ -284,10 +300,7 @@ 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); + final AABBox res = addStringToRegion(true /* preGrowRegion */, region, font, null, str, rgbaColor, tmp1, tmp2); region.draw(gl, renderer, sampleCount); return res; } |