Class TextRegionUtil
- java.lang.Object
-
- com.jogamp.graph.curve.opengl.TextRegionUtil
-
public class TextRegionUtil extends Object
Text Type Rendering Utility Class adding theFont.Glyph
sOutlineShape
to aGLRegion
.OutlineShape
s are all produced in font em-size [0..1].
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_CACHE_LIMIT
Default cache limit, seesetCacheLimit(int)
int
renderModes
AffineTransform
tempT1
AffineTransform
tempT2
-
Constructor Summary
Constructors Constructor Description TextRegionUtil(int renderModes)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static AABBox
addStringToRegion(boolean preGrowRegion, Region region, Font font, AffineTransform transform, CharSequence str, Vec4f rgbaColor, AffineTransform temp1, AffineTransform temp2)
Add the string in 3D space w.r.t.static AABBox
addStringToRegion(Region region, Font font, AffineTransform transform, CharSequence str, Vec4f rgbaColor)
Add the string in 3D space w.r.t.static AABBox
addStringToRegion(Region region, Font font, AffineTransform transform, CharSequence str, Vec4f rgbaColor, AffineTransform temp1, AffineTransform temp2)
Add the string in 3D space w.r.t.void
clear(GL2ES2 gl)
Clear all cachedGLRegions
and mapped values.static int[]
countStringRegion(Font font, CharSequence str, int[] vertIndexCount)
Count required number of vertices and indices adding to given int[2] `vertIndexCount` array.static AABBox
drawString3D(GL2ES2 gl, int renderModes, RegionRenderer renderer, Font font, CharSequence str, Vec4f rgbaColor, int[] sampleCount)
Try usingdrawString3D(GL2ES2, int, RegionRenderer, Font, CharSequence, Vec4f, int[], AffineTransform, AffineTransform)
to reuseAffineTransform
instances.static AABBox
drawString3D(GL2ES2 gl, int renderModes, RegionRenderer renderer, Font font, CharSequence str, Vec4f rgbaColor, int[] sampleCount, AffineTransform tmp1, AffineTransform tmp2)
Render the string in 3D space w.r.t.static AABBox
drawString3D(GL2ES2 gl, GLRegion region, RegionRenderer renderer, Font font, CharSequence str, Vec4f rgbaColor, int[] sampleCount)
static AABBox
drawString3D(GL2ES2 gl, GLRegion region, RegionRenderer renderer, Font font, CharSequence str, Vec4f rgbaColor, int[] sampleCount, AffineTransform tmp1, AffineTransform tmp2)
Render the string in 3D space w.r.t.AABBox
drawString3D(GL2ES2 gl, RegionRenderer renderer, Font font, CharSequence str, Vec4f rgbaColor, int[] sampleCount)
Render the string in 3D space w.r.t.int
getCacheLimit()
int
getCacheSize()
static int
getCharCount(String s, char c)
void
setCacheLimit(int newLimit)
Sets the cache limit for reusing GlyphString's and their Region.void
setCacheLimit(GL2ES2 gl, int newLimit)
Sets the cache limit, seesetCacheLimit(int)
and validates the cache.
-
-
-
Field Detail
-
renderModes
public final int renderModes
-
DEFAULT_CACHE_LIMIT
public static final int DEFAULT_CACHE_LIMIT
Default cache limit, seesetCacheLimit(int)
- See Also:
- Constant Field Values
-
tempT1
public final AffineTransform tempT1
-
tempT2
public final AffineTransform tempT2
-
-
Method Detail
-
getCharCount
public static int getCharCount(String s, char c)
-
addStringToRegion
public static AABBox addStringToRegion(Region region, Font font, AffineTransform transform, CharSequence str, Vec4f rgbaColor)
Add the string in 3D space w.r.t. the font in font em-size [0..1] at the end of theGLRegion
while passing the progressedAffineTransform
.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.
Origin of rendered text is 0/0 at bottom left.
The region buffer's size is grown by pre-calculating required size via
countStringRegion(Font, CharSequence, int[])
.- Parameters:
region
- theGLRegion
sinkfont
- the targetFont
transform
- optional given transformstr
- string textrgbaColor
- ifRegion.hasColorChannel()
RGBA color must be passed, otherwise value is ignored.- Returns:
- the bounding box of the given string by taking each glyph's font em-sized [0..1] OutlineShape into account.
-
addStringToRegion
public static AABBox addStringToRegion(Region region, Font font, AffineTransform transform, CharSequence str, Vec4f rgbaColor, AffineTransform temp1, AffineTransform temp2)
Add the string in 3D space w.r.t. the font in font em-size [0..1] at the end of theGLRegion
while passing the progressedAffineTransform
.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.
Origin of rendered text is 0/0 at bottom left.
The region buffer's size is grown by pre-calculating required size via
countStringRegion(Font, CharSequence, int[])
.- Parameters:
region
- theGLRegion
sinkfont
- the targetFont
transform
- optional given transformstr
- string textrgbaColor
- ifRegion.hasColorChannel()
RGBA color must be passed, otherwise value is ignored.temp1
- temporary AffineTransform storage, mandatorytemp2
- temporary AffineTransform storage, mandatory- Returns:
- the bounding box of the given string by taking each glyph's font em-sized [0..1] OutlineShape into account.
-
addStringToRegion
public static AABBox addStringToRegion(boolean preGrowRegion, Region region, Font font, AffineTransform transform, CharSequence str, Vec4f rgbaColor, AffineTransform temp1, AffineTransform temp2)
Add the string in 3D space w.r.t. the font in font em-size [0..1] at the end of theGLRegion
while passing the progressedAffineTransform
.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.
Origin of rendered text is 0/0 at bottom left.
Depending on `preGrowRegion`, the region buffer's size is grown by pre-calculating required size via
countStringRegion(Font, CharSequence, int[])
.- Parameters:
preGrowRegion
- if true, utilizescountStringRegion(Font, CharSequence, int[])
to pre-calc required buffer size, otherwise not.region
- theGLRegion
sinkfont
- the targetFont
transform
- optional given transformstr
- string textrgbaColor
- ifRegion.hasColorChannel()
RGBA color must be passed, otherwise value is ignored.temp1
- temporary AffineTransform storage, mandatorytemp2
- temporary AffineTransform storage, mandatory- Returns:
- the bounding box of the given string by taking each glyph's font em-sized [0..1] OutlineShape into account.
-
countStringRegion
public static int[] countStringRegion(Font font, CharSequence str, int[] vertIndexCount)
Count required number of vertices and indices adding to given int[2] `vertIndexCount` array.The region's buffer can be either set using
Region.setBufferCapacity(int, int)
or grown usingRegion.growBuffer(int, int)
.- Parameters:
font
- the targetFont
str
- string textvertIndexCount
- the int[2] storage where the counted vertices and indices are added, vertices at [0] and indices at [1]- Returns:
- the given int[2] storage for chaining
- See Also:
Region.setBufferCapacity(int, int)
,Region.growBuffer(int, int)
,drawString3D(GL2ES2, GLRegion, RegionRenderer, Font, CharSequence, Vec4f, int[], AffineTransform, AffineTransform)
-
drawString3D
public AABBox drawString3D(GL2ES2 gl, RegionRenderer renderer, Font font, CharSequence str, Vec4f rgbaColor, int[] sampleCount)
Render the string in 3D space w.r.t. the font int font em-size [0..1] at the end of an internally cachedGLRegion
.The shapes added to the GLRegion are in font em-size [0..1].
Origin of rendered text is 0/0 at bottom left.
Cached
GLRegion
s will be destroyed w/clear(GL2ES2)
or to free memory.The region's buffer size is pre-calculated via
GLRegion.create(com.jogamp.opengl.GLProfile, int, com.jogamp.opengl.util.texture.TextureSequence, Font, CharSequence)
- Parameters:
gl
- the current GL staterenderer
- TODOfont
-Font
to be usedstr
- text to be renderedrgbaColor
- used to fill theregion's color-channel
if used and setrenderer's static-color
to white. Otherwise used to set therenderer's static-color
only, if notnull
.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.- Returns:
- the bounding box of the given string from the produced and rendered GLRegion
- Throws:
Exception
- if TextRenderer not initialized
-
drawString3D
public static AABBox drawString3D(GL2ES2 gl, int renderModes, RegionRenderer renderer, Font font, CharSequence str, Vec4f rgbaColor, int[] sampleCount)
Try usingdrawString3D(GL2ES2, int, RegionRenderer, Font, CharSequence, Vec4f, int[], AffineTransform, AffineTransform)
to reuseAffineTransform
instances.The region's buffer size is pre-calculated via
GLRegion.create(com.jogamp.opengl.GLProfile, int, com.jogamp.opengl.util.texture.TextureSequence, Font, CharSequence)
-
drawString3D
public static AABBox drawString3D(GL2ES2 gl, int renderModes, RegionRenderer renderer, Font font, CharSequence str, Vec4f rgbaColor, int[] sampleCount, AffineTransform tmp1, AffineTransform tmp2)
Render the string in 3D space w.r.t. the font in font em-size [0..1] at the end of an internally temporaryGLRegion
.The shapes added to the GLRegion are in font em-size [0..1].
Origin of rendered text is 0/0 at bottom left.
The region's buffer size is pre-calculated via
GLRegion.create(com.jogamp.opengl.GLProfile, int, com.jogamp.opengl.util.texture.TextureSequence, Font, CharSequence)
In case of a multisampling region renderer, i.e.
Region.VBAA_RENDERING_BIT
, recreating theGLRegion
is a huge performance impact. In such case better usedrawString3D(GL2ES2, GLRegion, RegionRenderer, Font, CharSequence, Vec4f, int[], AffineTransform, AffineTransform)
instead.- Parameters:
gl
- the current GL staterenderModes
- TODOfont
-Font
to be usedstr
- text to be renderedrgbaColor
- used to fill theregion's color-channel
if used and setrenderer's static-color
to white. Otherwise used to set therenderer's static-color
only, if notnull
.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.tmp1
- tempAffineTransform
to be reusedtmp2
- tempAffineTransform
to be reused- Returns:
- the bounding box of the given string from the produced and rendered GLRegion
- Throws:
Exception
- if TextRenderer not initialized
-
drawString3D
public static AABBox drawString3D(GL2ES2 gl, GLRegion region, RegionRenderer renderer, Font font, CharSequence str, Vec4f rgbaColor, int[] sampleCount)
Try usingdrawString3D(GL2ES2, GLRegion, RegionRenderer, Font, CharSequence, Vec4f, int[], AffineTransform, AffineTransform)
to reuseAffineTransform
instances.The region buffer's size is grown by pre-calculating required size via
countStringRegion(Font, CharSequence, int[])
.
-
drawString3D
public static AABBox drawString3D(GL2ES2 gl, GLRegion region, RegionRenderer renderer, Font font, CharSequence str, Vec4f rgbaColor, int[] sampleCount, AffineTransform tmp1, AffineTransform tmp2)
Render the string in 3D space w.r.t. the font in font em-size [0..1] at the end of the givenGLRegion
.User might want to
GLRegion.clear(GL2ES2)
the region before calling this method.The shapes added to the GLRegion are in font em-size [0..1].
Origin of rendered text is 0/0 at bottom left.
The region buffer's size is grown by pre-calculating required size via
countStringRegion(Font, CharSequence, int[])
.- Parameters:
gl
- the current GL stateregion
-renderer
-font
-Font
to be usedstr
- text to be renderedrgbaColor
- used to fill theregion's color-channel
if used and setrenderer's static-color
to white. Otherwise used to set therenderer's static-color
only, if notnull
.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.tmp1
- tempAffineTransform
to be reusedtmp2
- tempAffineTransform
to be reused- Returns:
- the bounding box of the given string from the produced and rendered GLRegion
- Throws:
Exception
- if TextRenderer not initialized
-
clear
public void clear(GL2ES2 gl)
Clear all cachedGLRegions
and mapped values.
-
setCacheLimit
public final void setCacheLimit(int newLimit)
Sets the cache limit for reusing GlyphString's and their Region. Default is
DEFAULT_CACHE_LIMIT
, -1 unlimited, 0 turns cache off, >0 limitedThe cache will be validate when the next string rendering happens.
- Parameters:
newLimit
- new cache size- See Also:
DEFAULT_CACHE_LIMIT
-
setCacheLimit
public final void setCacheLimit(GL2ES2 gl, int newLimit)
Sets the cache limit, seesetCacheLimit(int)
and validates the cache.- Parameters:
gl
- current GL used to remove cached objects if requirednewLimit
- new cache size- See Also:
setCacheLimit(int)
-
getCacheLimit
public final int getCacheLimit()
- Returns:
- the current cache limit
-
getCacheSize
public final int getCacheSize()
- Returns:
- the current utilized cache size, <=
getCacheLimit()
-
-