28package com.jogamp.graph.curve.opengl;
30import java.util.ArrayList;
31import java.util.HashMap;
32import java.util.Iterator;
34import com.jogamp.opengl.GL2ES2;
35import com.jogamp.opengl.GLException;
36import com.jogamp.graph.curve.OutlineShape;
37import com.jogamp.graph.curve.Region;
38import com.jogamp.graph.font.Font;
39import com.jogamp.graph.font.Font.Glyph;
40import com.jogamp.math.Vec4f;
41import com.jogamp.math.geom.AABBox;
42import com.jogamp.math.geom.plane.AffineTransform;
78 final CharSequence str,
final Vec4f rgbaColor) {
104 final CharSequence str,
final Vec4f rgbaColor,
106 return addStringToRegion(
true , region, font, transform, str, rgbaColor, temp1, temp2);
132 final CharSequence str,
final Vec4f rgbaColor,
142 if( preGrowRegion ) {
144 region.
growBuffer(vertIndCount[0], vertIndCount[1]);
146 return font.
processString(visitor, transform, str, temp1, temp2);
165 public final void visit(
final Font.
Glyph glyph) {
166 if( !glyph.isNonContour() ) {
171 return vertIndexCount;
199 final Font font,
final CharSequence str,
final Vec4f rgbaColor) {
201 throw new GLException(
"TextRendererImpl01: not initialized!");
203 GLRegion region = getCachedRegion(font, str);
208 addCachedRegion(gl, font, str, region);
214 if(
null != rgbaColor ) {
220 region.
draw(gl, renderer);
231 final Font font,
final CharSequence str,
final Vec4f rgbaColor) {
265 final Font font,
final CharSequence str,
final Vec4f rgbaColor,
268 throw new GLException(
"TextRendererImpl01: not initialized!");
273 if(
null != rgbaColor ) {
279 region.
draw(gl, renderer);
291 final Font font,
final CharSequence str,
final Vec4f rgbaColor) {
323 final Font font,
final CharSequence str,
final Vec4f rgbaColor,
326 throw new GLException(
"TextRendererImpl01: not initialized!");
330 if(
null != rgbaColor ) {
336 region.
draw(gl, renderer);
345 final Iterator<GLRegion> iterator = stringCacheMap.values().iterator();
346 while(iterator.hasNext()){
347 final GLRegion region = iterator.next();
350 stringCacheMap.clear();
351 stringCacheArray.clear();
364 public final void setCacheLimit(
final int newLimit ) { stringCacheLimit = newLimit; }
374 public final void setCacheLimit(
final GL2ES2 gl,
final int newLimit ) { stringCacheLimit = newLimit; validateCache(gl, 0); }
386 private final void validateCache(
final GL2ES2 gl,
final int space) {
389 removeCachedRegion(gl, 0);
394 private final GLRegion getCachedRegion(
final Font font,
final CharSequence str) {
395 return stringCacheMap.get(
new Key(font, str));
398 private final void addCachedRegion(
final GL2ES2 gl,
final Font font,
final CharSequence str,
final GLRegion glyphString) {
400 final Key key =
new Key(font, str);
401 final GLRegion oldRegion = stringCacheMap.put(key, glyphString);
402 if (
null == oldRegion ) {
404 validateCache(gl, 1);
405 stringCacheArray.add(stringCacheArray.size(), key);
410 private final void removeCachedRegion(
final GL2ES2 gl,
final Font font,
final CharSequence str) {
411 final Key key =
new Key(font, str);
412 final GLRegion region = stringCacheMap.remove(key);
416 stringCacheArray.remove(key);
419 private final void removeCachedRegion(
final GL2ES2 gl,
final int idx) {
420 final Key key = stringCacheArray.remove(idx);
422 final GLRegion region = stringCacheMap.remove(key);
430 private final String fontName;
431 private final CharSequence text;
432 public final int hash;
434 public Key(
final Font font,
final CharSequence text) {
435 this.fontName = font.getName(Font.NAME_UNIQUNAME);
439 final int lhash = 31 + fontName.hashCode();
440 this.hash = ((lhash << 5) - lhash) + text.hashCode();
444 public final int hashCode() {
return hash; }
447 public final boolean equals(
final Object o) {
448 if(
this == o ) {
return true; }
449 if( o instanceof Key ) {
450 final Key ok = (Key)o;
451 return ok.fontName.equals(fontName) && ok.text.equals(text);
462 private final HashMap<Key, GLRegion> stringCacheMap =
new HashMap<Key, GLRegion>(
DEFAULT_CACHE_LIMIT);
Abstract Outline shape representation define the method an OutlineShape(s) is bound and rendered.
final void addOutlineShape(final OutlineShape shape, final AffineTransform t, final Vec4f rgbaColor)
Add the given OutlineShape to this region with the given optional AffineTransform.
static final int[] countOutlineShape(final OutlineShape shape, final int[] vertIndexCount)
Count required number of vertices and indices adding to given int[2] vertIndexCount array.
static boolean hasColorChannel(final int renderModes)
Returns true if render mode has a color channel, i.e.
abstract boolean growBuffer(int verticesCount, int indicesCount)
Increase the renderer buffers if necessary to add given counts of vertices- and index elements.
A GLRegion is the OGL binding of one or more OutlineShapes Defined by its vertices and generated tria...
final void destroy(final GL2ES2 gl)
Delete and clear the associated OGL objects.
final void draw(final GL2ES2 gl, final RegionRenderer renderer)
Renders the associated OGL objects specifying current width/hight of window for optional multi pass r...
static GLRegion create(final GLProfile glp, int renderModes, final TextureSequence colorTexSeq, final int pass2TexUnit, final int initialVerticesCount, final int initialIndicesCount)
Create a GLRegion using the passed render mode.
final boolean isInitialized()
final void setColorStatic(final Vec4f rgbaColor)
Text Type Rendering Utility Class adding the Font.Glyphs OutlineShape to a GLRegion.
AABBox drawString3D(final GL2ES2 gl, final RegionRenderer renderer, final Font font, final CharSequence str, final Vec4f rgbaColor)
Render the string in 3D space w.r.t.
static AABBox drawString3D(final GL2ES2 gl, final GLRegion region, final RegionRenderer renderer, final Font font, final CharSequence str, final Vec4f rgbaColor)
Try using drawString3D(GL2ES2, GLRegion, RegionRenderer, Font, CharSequence, Vec4f,...
static AABBox drawString3D(final GL2ES2 gl, final GLRegion region, final RegionRenderer renderer, final Font font, final CharSequence str, final Vec4f rgbaColor, final AffineTransform tmp1, final AffineTransform tmp2)
Render the string in 3D space w.r.t.
final void setCacheLimit(final GL2ES2 gl, final int newLimit)
Sets the cache limit, see setCacheLimit(int) and validates the cache.
static int[] countStringRegion(final Font font, final CharSequence str, final int[] vertIndexCount)
Count required number of vertices and indices adding to given int[2] vertIndexCount array.
TextRegionUtil(final int renderModes)
final AffineTransform tempT1
static final int DEFAULT_CACHE_LIMIT
Default cache limit, see setCacheLimit(int).
static AABBox drawString3D(final GL2ES2 gl, final int renderModes, final RegionRenderer renderer, final Font font, final CharSequence str, final Vec4f rgbaColor, final AffineTransform tmp1, final AffineTransform tmp2)
Render the string in 3D space w.r.t.
final AffineTransform tempT2
static AABBox addStringToRegion(final Region region, final Font font, final AffineTransform transform, final CharSequence str, final Vec4f rgbaColor)
Add the string in 3D space w.r.t.
final void setCacheLimit(final int newLimit)
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.
void clear(final GL2ES2 gl)
Clear all cached GLRegions and mapped values.
static AABBox addStringToRegion(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.
final int getCacheLimit()
static AABBox drawString3D(final GL2ES2 gl, final int renderModes, final RegionRenderer renderer, final Font font, final CharSequence str, final Vec4f rgbaColor)
Try using drawString3D(GL2ES2, int, RegionRenderer, Font, CharSequence, Vec4f, AffineTransform,...
4D Vector based upon four float components.
Axis Aligned Bounding Box.
final AABBox copy(final AABBox src)
Copy given AABBox 'src' values to this AABBox.
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
General purpose Font.Glyph visitor w/o AffineTransform.
General purpose Font.Glyph visitor.
boolean isNonContour()
Returns true if isWhitespace() or isUndefined().
Interface wrapper for font implementation.
AABBox processString(final Font.GlyphVisitor visitor, final AffineTransform transform, final CharSequence string)
Try using processString(GlyphVisitor, AffineTransform, CharSequence, AffineTransform,...
GLProfile getGLProfile()
Returns the GLProfile associated with this GL object.