Class TextRegionUtil

    • Constructor Detail

      • TextRegionUtil

        public TextRegionUtil​(int renderModes)
    • 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 the GLRegion while passing the progressed AffineTransform.

        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 - the GLRegion sink
        font - the target Font
        transform - optional given transform
        str - string text
        rgbaColor - if Region.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 the GLRegion while passing the progressed AffineTransform.

        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 - the GLRegion sink
        font - the target Font
        transform - optional given transform
        str - string text
        rgbaColor - if Region.hasColorChannel() RGBA color must be passed, otherwise value is ignored.
        temp1 - temporary AffineTransform storage, mandatory
        temp2 - 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 the GLRegion while passing the progressed AffineTransform.

        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, utilizes countStringRegion(Font, CharSequence, int[]) to pre-calc required buffer size, otherwise not.
        region - the GLRegion sink
        font - the target Font
        transform - optional given transform
        str - string text
        rgbaColor - if Region.hasColorChannel() RGBA color must be passed, otherwise value is ignored.
        temp1 - temporary AffineTransform storage, mandatory
        temp2 - 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 using Region.growBuffer(int, int).

        Parameters:
        font - the target Font
        str - string text
        vertIndexCount - 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, float[], int[], AffineTransform, AffineTransform)
      • 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 given GLRegion.

        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 state
        region -
        renderer -
        font - Font to be used
        str - text to be rendered
        rgbaColor - if Region.hasColorChannel() RGBA color must be passed, otherwise value is ignored.
        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 - temp AffineTransform to be reused
        tmp2 - temp AffineTransform 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 cached GLRegions 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 limited

        The 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, see setCacheLimit(int) and validates the cache.
        Parameters:
        gl - current GL used to remove cached objects if required
        newLimit - 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()