Back to API Reference
Class

UniTextMeshGenerator

Converts positioned glyphs into Unity mesh data for text rendering.

Remarks

This is the final stage of the text processing pipeline. It takes PositionedGlyph data from TextProcessor and generates vertex, UV, color, and triangle data suitable for Unity's mesh system. Key features: Groups glyphs by rendering target to minimize draw calls: one segment per font (Texture2DArray atlas) Uses pooled buffers from ArrayPool<T> for zero allocations Provides callbacks for text modifiers to inject custom processing Typical usage: generator.SetRectOffset(rect); generator.GenerateMeshDataOnly(positionedGlyphs); var renderData = generator.CollectRenderData(); // Use renderData to render each segment generator.ReturnInstanceBuffers();
public OrderedEvent onMainPassComplete{ get }

Runs after primary text glyph emission and before main-pass finalization.

public OrderedEvent onMainPassFinalize{ get }

Runs after onMainPassComplete and before color-quad emission.

public OrderedEvent onGlyph{ get }

Runs for each glyph during mesh generation.

public OrderedEvent onRebuildEnd{ get }

Runs after all mesh generation is complete.

public OrderedEvent onRebuildStart{ get }

Runs before mesh generation starts.

public OrderedEvent<SubMeshCollectionContext> onCollectSubMeshes{ get }

Collects custom render-data segments before the base segments are appended.

public float FontSize{ get; set }

Gets or sets the font size in points for mesh generation.

public UniTextRenderMode RenderMode{ get; set }

Gets or sets the atlas mode (SDF or MSDF) for glyph lookup and material selection.

public bool HasGeneratedData{ get }

Gets a value indicating whether mesh data has been generated and is available.

public Vector3[] Vertices{ get }

Gets the vertex position buffer (X, Y, Z coordinates).

public Vector4[] Uvs0{ get }

Gets the primary UV buffer (texture coordinates and scale in W component).

public Color32[] Colors{ get }

Gets the vertex color buffer.

public int[] Triangles{ get }

Gets the triangle index buffer.

public Vector4[] Uvs1{ get }

Gets the UV1 buffer: x = aspect (glyphW/glyphH), y = faceDilate, z = per-glyph cluster index (monotonic per-line, transform-invariant), w = intra-glyph X fraction (0 on the left edge, 1 on the right — interpolated by GPU).

public Vector4[] Uvs2{ get }

Gets the UV2 buffer — the COVERAGE contract (TEXCOORD2).

public Vector4[] Uvs3{ get }

Gets the UV3 buffer — the PAINT contract (TEXCOORD3).

public bool TrackGlyphKey()

Tracks a glyph key for atlas ref counting. Deduplicates automatically. Use for modifier glyphs that don't need cached entry data.

[ctor]public UniTextMeshGenerator(UniTextFontProvider fontProvider, UniTextBuffers uniTextBuffers)

Initializes a new instance of the UniTextMeshGenerator class.

public static void ScaleGlyphQuad(float pivotX)

Scales a glyph quad (4 vertices) around the cursor position and baseline. Used by SizeModifier, SmallCapsModifier, ScriptPositionModifier.

public void ScaleFace()

Scales the current face quad and records the factor into currentGlyphScale. Every per-glyph size change (size tag, small-caps, sub/superscript, ruby, font metric overrides) must pass through here rather than ScaleGlyphQuad directly — a scale the generator does not see leaves paint-layer offset and quad growth stuck at the base size.

public void XScaleFace()

Scales a face quad horizontally around the pen position — the fit / justification glyph-compression channel. Deliberately not folded into currentGlyphScale: paint-layer growth stays isotropic while the rendered glyph narrows.

public void EnsureUvBuffer(int channel)

Allocates and zero-clears a UV effect buffer (channel 2 or 3) if not already allocated.

public float GlyphScale()

Per-glyph scale for the face quad starting at baseIdx (1 when the glyph was never scaled). Read by paint layers at emit time.

public void ReturnInstanceBuffers()

Returns all instance buffers to the pool and clears the generated data flag.

public void Dispose()

Releases all pooled resources. Call when the generator is no longer needed.

public void EnsureCapacity(int additionalVertices, int additionalTriangles)

Ensures the vertex and triangle buffers have capacity for additional data.

public void ResetPerGlyphState()

Resets the per-glyph state that onGlyph modifiers read and write — the claim race (fillClaimedThisGlyph/baseFaceClaimed), the claimed claimedFillSequence/claimedFillBlend, and the tier-upgrade currentMaxGlyphExtent. Every emitter of a glyph quad (face, kashida, decoration line) calls this before firing onGlyph.

public void AddSdfQuad()

Records a quad (4 vertices at baseVertexIdx) of the current segment (SDF or color) to be drawn at layer sequence with blend. Triangles are written in sequence order by MaterializeQuadTriangles, so painter order follows the layer stack; glyph-major ranges (paintOrders) group a glyph's quads together first, ordering layers within each glyph. The quad's owning cluster is read from its UV1 z channel (see Uvs1), which duplicate reservation copies from the source face.

public void RequestTierUpgradeIfNeeded()

Raises the current glyph's atlas pad tier when a modifier asked for more outward rim than the tier reserves — the glyph is re-rasterized smaller in its shared tile so the extra distance field (outline / shadow / bold) has room, plus TierSeamMarginNorm of AA-ramp headroom so the effect's outer edge samples inside computed field, not at the tile seam. Only the request is recorded here; the sweep re-rasterizes the tile and re-meshes every consumer of it at the new tier in the same frame (see UniTextBase_Parallel). Grow-only.

public void RequestTileSizeUpgradeIfNeeded()

Records a grow-only atlas tile-size upgrade for the current glyph when a resolution modifier asked for more detail / a larger tile than the font default. The sweep relocates the shared tile to the larger class and re-meshes its consumers the same frame (see UniTextBase_Parallel). The glyph's atlas key ignores tile size, so all consumers share one tile at the max requested resolution. Call immediately after onGlyph.

public void ExpandQuad()

Expands a 4-vertex quad outward along its current local axes: UV0 by delta (atlas-space, normalized by glyph height), positions by the matching distance in the quad's own UV0→pixel scale, so the SDF sample stays attached to the geometry whatever size the quad was built or scaled to.

public void SetRectOffset(Rect rect)

Sets the layout rectangle for text positioning.

public void SetVisibleBand()

Bounds quad emission to a local-space vertical band (viewport culling). Geometry queries, selection and hit-testing are untouched — positioned glyphs exist for every paragraph; only mesh emission skips bands outside the window. Reset to infinite for no culling.

public bool IsLocalBandVisible()

True when a local-space vertical span intersects the visible band — the one culling test every emission site shares (glyph paragraphs, virtual glyphs, decoration lines).

public void GenerateMeshDataOnly()

Generates mesh data (vertices, UVs, colors, triangles) from positioned glyphs. Groups by rendering target: SDF fonts in one segment (Texture2DArray), color separately.

public List<UniTextRenderData> CollectRenderData()

Collects raw render data (vertex/UV/triangle array slices + material/order metadata) for every segment produced by the latest mesh generation. Does not build Unity Mesh objects — consumers (canvas UpdateSubMeshes, world batcher) decide what to do with the raw data.

public static const float DefaultSdfPadding

Base UV-space padding (normalized by glyph height) allocated around every face quad. Face and effect modifiers that expand the quad must subtract this baseline from their requested extent when computing the expansion delta.

public static const int GlyphGeometryConsumerOrder

Order for callbacks that consume the completed glyph quad to derive additional geometry.

public int currentCluster

The cluster index of the glyph currently being processed.

public int currentGlyphId

Font glyph id of the glyph currently being processed — identifies which glyph a quad renders when the cluster alone is ambiguous (virtual glyphs).

public float height

Height of the current glyph including padding.

public float baselineY

Y coordinate of the text baseline for the current glyph.

public float cursorX

X coordinate of the cursor position (pen position) for the current glyph.

public float scale

Design-units → pixels for the current glyph's font.

public float fontMetricFactor

FontSize * FontScale — converts normalized glyph metrics to UI-space units. Constant per font.

public Color32 defaultColor

Default vertex color applied to all glyphs.

public Core font

Current font being processed.

public float offsetX

X offset from the rect origin.

public float offsetY

Y offset from the rect origin.

public int vertexCount

Current number of vertices in the mesh buffers.

public int triangleCount

Current number of triangle indices in the mesh buffers.

public int faceBaseIdx

Index of the first vertex of the face quad of the glyph currently being processed. Stable across all onGlyph invocations for a single glyph, even when modifiers append additional geometry that grows vertexCount.

public static const int DefaultFillSequence

Sequence assigned to a glyph face when no explicit fill claimed it — below every layer (default fill = bottom of the stack).

public int claimedFillSequence

Set during onGlyph by the fill that claims the current glyph's base quad, to its LayerSequence; left at DefaultFillSequence when none does. The face quad is ordered at this sequence, so an explicit fill stacks the glyph at its layer position.

public LayerBlend claimedFillBlend

Blend mode paired with claimedFillSequence for the current glyph face.

public int sequenceBias

Added to every layer sequence a modifier captures while it is set, lifting a whole stack — face, stroke, shadow, glow — into a higher band together instead of leaving each layer at its own style-stack position. Zero for shaped text; a virtual-glyph emitter raises it around its own emission and restores it afterwards. A layer folds it in where it captures the sequence, during onGlyph — never where it flushes, by which time the emitter has restored it.

public float currentMaxGlyphExtent

Maximum UV-space padding requested for the current glyph by any modifier. Reset to 0 before each onGlyph invocation. Subscribers accumulate via max. Read after onGlyph to decide atlas tier upgrades.

public int currentTileSizeBoost

Largest resolution boost (0–2 tile-size classes above the glyph's default) a resolution modifier requested for the current glyph. Reset to 0 before each onGlyph; accumulated via max, read after to request a grow-only atlas tile-size upgrade. See RequestTileSizeUpgradeIfNeeded.

public float currentGlyphScale

Product of every per-glyph scale applied to the current face quad (size, small-caps, sub/superscript, ruby, font metric overrides) via ScaleFace. Reset to 1 before each onGlyph; GlyphScale reads it back per quad once the glyph completes. Em → pixels for an emitted quad is fontMetricFactor times this: em geometry multiplies by it and absolute (px) geometry divides by it, so a px value keeps a constant on-screen size while the glyph scales.

public bool fillClaimedThisGlyph

Reset to before each onGlyph; a fill layer sets it when it claims (recolours) the glyph's base quad, so later fills on the same glyph stack as duplicates instead of fighting over the base.

public bool baseFaceClaimed

Set when a layer takes over rendering the current glyph's base face in its own sub-mesh — a texture fill, or a MaterialModifier in Replace mode. The base-mesh face quad must then not be recorded (it would sit at the claimed sequence as a transparent placeholder and stop the base mesh from slicing there, breaking layer order). Reset before each onGlyph.

public bool suppressInheritedFill

Set by a virtual-glyph emitter (decoration line with its own paint) around its onGlyph so the inherited text fill stands down entirely — neither claiming the base nor stacking a duplicate over it. Unlike fillClaimedThisGlyph (which only loses the base race and still overlays), this fully suppresses base fills, letting the line's own paint replace the inherited one (CSS text-decoration-color). Non-base layers (shadow, glow, stroke) are unaffected and still decorate the line.

public bool isVirtualGlyph

True when the currently processed glyph is virtual (injected by a modifier — list marker, ellipsis dot — and has no ShapedGlyph behind it).

public int currentPositionedIndex

Index into the positioned-glyph array of the glyph the current quad renders, or -1 when no positioned glyph stands behind it.

See Also