UWAL / MSDFText
Classes
MSDFText
Utility class to write some text into a storage GPUBuffer. When combined with the MSDFText shader, the buffer content can be outputted to a screen or into a GPUTexture. Note: This class will probably be deprecated once HTML in Canvas gets widely adopted.
See
MSDF Text and Curtains for reference.
Constructors
Constructor
new MSDFText(label?): MSDFText;Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
label? | string | "MSDFText" | Text label. |
Returns
Methods
CreateRenderPipeline()
CreateRenderPipeline(Renderer, descriptor?): Promise<PipelineInstance>;Create an internal render pipeline to output the text.
Parameters
| Parameter | Type | Description |
|---|---|---|
Renderer | RenderStage | Renderer instance to create the pipeline. |
descriptor? | PipelineDescriptor & RenderPipelineState & Record<"renderBundleDescriptor", RenderBundleDescriptor | undefined> & Record<"colorTargets", GPUColorTargetState | GPUColorTargetState[] | undefined> | Optional pipeline descriptor. |
Returns
Promise<PipelineInstance>
LoadFont()
LoadFont(
source,
generated?,
requestOptions?
): Promise<void>;Load and use an MSDFFont.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
source | string | undefined | Font source path. |
generated? | boolean | false | Whether the font was generated here. |
requestOptions? | RequestInit | undefined | fetch request options. |
Returns
Promise<void>
See
https://github.com/UstymUkhman/uwal/issues/9
Throws
ERROR.PIPELINE_NOT_FOUND if called before CreateRenderPipeline.
Write()
Write(
text,
color?,
scale?,
centered?
): GPUBuffer;Write a text string into a storage GPUBuffer.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
text | string | undefined | Text to write. |
color? | ColorValue | 0x000000 | Text color. |
scale? | number | 0.01 | Text scale. |
centered? | boolean | false | Whether the text should be centered. |
Returns
GPUBuffer
Throws
ERROR.PIPELINE_NOT_FOUND if called before CreateRenderPipeline, ERROR.FONT_NOT_FOUND if called before LoadFont, and ERROR.CAMERA_BUFFER_NOT_FOUND if a PerspectiveCamera buffer hasn't been set yet with CameraMatrixBuffer.
SetTranslation()
SetTranslation(translation, buffer): void;Set the text translation.
Parameters
| Parameter | Type | Description |
|---|---|---|
translation | Float32Array<ArrayBufferLike> | Translation matrix. |
buffer | GPUBuffer | Text buffer to update. |
Returns
void
SetColor()
SetColor(color, buffer): void;Set the text color.
Parameters
| Parameter | Type | Description |
|---|---|---|
color | ColorValue | Color value. |
buffer | GPUBuffer | Text buffer to update. |
Returns
void
SetScale()
SetScale(scale, buffer): void;Set the text scale.
Parameters
| Parameter | Type | Description |
|---|---|---|
scale | number | Scale value. |
buffer | GPUBuffer | Text buffer to update. |
Returns
void
Clear()
Clear(buffer?): void;Destroy the text buffer and reset its color and scale values. Remove pipeline's bind groups and reset its render bundles.
Parameters
| Parameter | Type | Description |
|---|---|---|
buffer? | GPUBuffer | Text buffer to remove. |
Returns
void
Destroy()
Destroy(): void;Destroy and remove the rendering pipeline, destroy the font, and reset the internal state.
Returns
void
Accessors
CameraMatrixBuffer
Set Signature
set CameraMatrixBuffer(buffer): void;Set a PerspectiveCamera buffer to render the text.
See
https://github.com/UstymUkhman/uwal/issues/9
Parameters
| Parameter | Type | Description |
|---|---|---|
buffer | GPUBuffer | Camera buffer. |
Returns
void
Pipeline
Get Signature
get Pipeline(): RenderPipelineInstance | undefined;Returns
RenderPipelineInstance | undefined
Internal pipeline used to render the text.