tecs.gfx
The public scene-rendering values a game spawns.
Renderable3D selects indexed meshes with Transform3D, Mesh, Bounds3D and MeshMaterial. Models load shared glTF geometry and independent animation poses. Particles keep individual particle state on the GPU; entities author their emitters. View selects ordered 2D and 3D cameras.
Tint, Sprite, and Renderable2D accompany tecs.ecs.Transform2D on a drawable entity, and Camera2D with ActiveCamera selects the view every frame is projected through.
PreviousTransform2D opts an entity into fixed-step presentation interpolation. The extractor blends position and the shortest rotation arc using the world's residual fixed time. Lights and shadow geometry use the same presented pose. Scale, depth and layer use current values, and entities without history render directly from their current transform. Physics seeds history automatically; an authored history should initially match the entity's creation pose.
const image = tecs.gfx.images.upload({name = "tiles/grass", width = 2, height = 2, pixels = grassRgba8})
world:spawn(tecs.gfx.Camera2D(320, 180, 1, 0), tecs.gfx.ActiveCamera)
world:spawn(
tecs.ecs.Transform2D(320, 180, 0, 1, 0, 64, 64),
tecs.gfx.Tint(1, 1, 1, 1),
tecs.gfx.Sprite(image),
tecs.gfx.Renderable2D
)tecs.gfx.lighting owns the deferred lighting resolve, the two shadow mechanisms, and optional bloom, and it is where PointLight2D, Occluder2D, and DropShadow2D are documented. tecs.gfx.layers decides the order and placement of those entities, tecs.gfx.images owns image identity and residency, tecs.gfx.clips owns the target-pixel regions Clip selects, tecs.gfx.sheet and tecs.gfx.animation cut an image into frames and play them, tecs.gfx.fonts owns font identity and the glyph atlas, tecs.gfx.text lays a string out into glyph entities that draw through the same textured path a sprite does, tecs.gpu.materials numbers the materials a Material selects, and tecs.gpu.passes declares the render passes and render targets a frame is drawn through.
Submodules
| Module | Description |
|---|---|
tecs.gfx.animation | Fixed-step sprite-sheet playback. |
tecs.gfx.camera3d | A perspective camera maps a right-handed 3D world to one viewport. |
tecs.gfx.clips | Target-pixel clip regions and the component that selects one. |
tecs.gfx.flycamera3d | A free-fly controller turns mouse and keyboard input into a 3D camera pose. |
tecs.gfx.fonts | Font identity, glyph metrics, and the atlas that carries glyphs to the backend. |
tecs.gfx.frametable | Shared sprite animation tables. |
tecs.gfx.images | Image identity, residency, and the commands that carry pixels to the backend. |
tecs.gfx.layers | Depth bands, sorting, coordinate spaces, parallax, and lighting. |
tecs.gfx.lighting | Deferred two-dimensional lighting, the shadows it casts, and optional bloom. |
tecs.gfx.meshes | Per-view 3D lighting, shadows, ambient probes and environments. |
tecs.gfx.models | Resident glTF models and allocation-stable node animation. |
tecs.gfx.particles | GPU particle effects, emitter playback, pool sizing, and rendering limits. |
tecs.gfx.screenshot | Capture the next presented frame, including UI and post-processing. |
tecs.gfx.sheet | A sprite sheet divides one image into frames, tags, and slices. |
tecs.gfx.text | Shaped text as entities in the rendered world. |
tecs.gfx.truetype | TrueType outlines, metrics, coverage rasterization, and signed distance fields. |
Module contents
Constructors
| Constructor | Description |
|---|---|
newCamera2D | Creates a camera value for a View or coordinate conversion outside an entity. |
newCamera3D | Creates a right-handed perspective camera looking along negative Z. |
newText | Builds a text value that belongs to no entity, for measurement. |
newTTF | Loads a TrueType font and reads its metrics. |
Types
| Type | Kind | Description |
|---|---|---|
Animation | struct | Sprite-sheet playback state stored on an entity. |
Bounds3D | type | Stores the Bounds3D data for one 3D primitive. |
Camera2D | struct | A view onto the world, in world units and target pixels. |
Camera3D | type | A perspective camera with quaternion orientation. |
Clip | struct | A clip region selected by a renderable entity. |
DropShadow2D | struct | A stretched ground shadow, stored on a renderable entity. |
Font | record | A loaded font and the atlas its glyphs live in. |
Material | struct | A material selection stored on a renderable entity. |
Mesh | type | Stores the Mesh data for one 3D primitive. |
MeshMaterial | type | Stores the MeshMaterial data for one 3D primitive. |
MeshMorph | type | Stores the MeshMorph data for one 3D primitive. |
MeshSkin | type | Stores the MeshSkin data for one 3D primitive. |
Occluder2D | struct | A silhouette that blocks light, stored on a renderable entity. |
PointLight2D | struct | A light the deferred resolve accumulates. |
PointLight3D | type | Omnidirectional mesh light positioned by Transform3D. |
SpotLight3D | type | Conical mesh light aimed along Transform3D local negative Z. |
Sprite | struct | An image region stored on a renderable entity. |
Text | record | A string laid out into glyph entities. |
TileChunk | type | A native 16 by 16 grid of static atlas tiles. |
Tint | struct | A four-channel color stored on a renderable entity. |
View | type | Describes an ordered viewport with its own camera. |
Values
| Value | Kind | Description |
|---|---|---|
ActiveCamera | variable | Selects the camera entity extraction projects the scene through. |
Animation | variable | Constructs playback state directly. |
AnimationEvents | variable | Requests tecs.gfx.animation.Completed and tecs.gfx.animation.Looped for one entity. |
Bounds3D | variable | Constructs the Bounds3D component for a 3D primitive. |
Camera2D | variable | Constructs a camera centered on the world origin at zoom one. |
Clip | variable | Constructs a clip selecting a region set with tecs.gfx.clips.setRegion. |
DirtyTileChunk | variable | Requests synchronization after a nested tile-array edit. |
DropShadow2D | variable | Constructs a drop-shadow caster at full height. |
LIGHT_CASTS_SHADOWS | variable | Requests a slot in the local-light shadow atlas. |
Material | variable | Constructs a material selection, defaulting to textured at parameter one quarter. |
Mesh | variable | Constructs the Mesh component for a 3D primitive. |
MeshMaterial | variable | Constructs the MeshMaterial component for a 3D primitive. |
MeshMorph | variable | Constructs the MeshMorph component for a 3D primitive. |
MeshSkin | variable | Constructs the MeshSkin component for a 3D primitive. |
Occluder2D | variable | Constructs an occluder at full height. |
Pivot | variable | Anchors a sprite at normalized X/Y coordinates or an authored sheet slice. |
PointLight2D | variable | Constructs a light at height sixty-four, reaching two hundred and fifty-six world units, in white at full strength. |
PointLight3D | variable | Constructs a point light with radius, linear RGB, intensity and LIGHT flags. |
Renderable2D | variable | Marks an entity as contributing geometry to the two-dimensional scene. |
Renderable3D | variable | Marks geometry for the 3D renderer. |
SpotLight3D | variable | Constructs a spot light with radius, inner and outer half-angles in radians, linear RGB, intensity and LIGHT flags. |
Sprite | variable | Constructs a sprite whose omitted UV rectangle covers the whole image. |
Text | variable | Constructs a text whose omitted fields default to an empty left-aligned string at em size sixteen with no wrapping. |
TextGlyph | variable | Marks an entity as one glyph tecs.gfx.text placed for a Text. |
TILE_CHUNK_SIZE | variable | The number of cells along a tile chunk edge. |
TileChunk | variable | Constructs a tile chunk positioned by its top-left Transform2D. |
Tint | variable | Constructs a tint whose omitted channels default to one. |
View | variable | Constructs a viewport from a camera and optional rectangle, order and enabled fields. |
Constructors#
newCamera2Dconstructor#
function newCamera2D(options: {
x: number?,
y: number?,
zoom: number?,
rotation: number?
}?): Camera2DCreates a camera value for a View or coordinate conversion outside an entity.
Arguments
| Name | Type | Description |
|---|---|---|
options | {
x: number?,
y: number?,
zoom: number?,
rotation: number?
}? | The caller supplies world position, positive zoom and radians of rotation. |
Returns
| Type | Description |
|---|---|
Camera2D | The camera value, centered at zero with zoom one by default. |
Raises
When zoom is not positive or a value is not finite.
newCamera3Dconstructor#
function newCamera3D(options: Options?): Camera3DCreates a right-handed perspective camera looking along negative Z.
Arguments
| Name | Type | Description |
|---|---|---|
options | Options? |
Returns
| Type | Description |
|---|---|
Camera3D |
newTextconstructor#
function newText(value: string?, font: fonts.Font?, size: number?, align: Align?, wrapWidth: number?): TextBuilds a text value that belongs to no entity, for measurement.
Arguments
| Name | Type | Description |
|---|---|---|
value | string? | the string to lay out, defaulting to empty |
font | fonts.Font? | the font supplying the glyphs, or nil to draw nothing |
size | number? | the em size in world units, defaulting to sixteen |
align | Align? | the alignment, defaulting to |
wrapWidth | number? | the maximum line width in world units, defaulting to zero, which disables wrapping |
Returns
| Type | Description |
|---|---|
Text | the text value, which the caller owns |
Raises
when the alignment is not one of its declared values, or when the wrap width is negative
newTTFconstructor#
function newTTF(options: TTFOptions): Font?, string?Loads a TrueType font and reads its metrics.
Arguments
| Name | Type | Description |
|---|---|---|
options | TTFOptions | the source path or |
Returns
| Type | Description |
|---|---|
Font? | the font, or nil when the file could not be read or parsed |
string? | why the font could not be loaded, when unsuccessful |
Raises
when neither
sourcenorbytesis given, when the size is not greater than zero, or when the raster is not one of its declared values
Types#
Animationstruct#
struct Animation
sheet: integer
tag: integer
speed: number
time: number
frame: integer
loop: boolean
playing: boolean
crossed: integer
endSprite-sheet playback state stored on an entity.
Fields
sheet#
sheet: integerCaller-writable. Selects a sheet by its registration index. Zero plays nothing.
tag#
tag: integerCaller-writable. Selects a tag by its Sheet.tagId index. Zero plays the whole sheet in order.
speed#
speed: numberCaller-writable. Multiplies the timing the sheet carries. One is the timing as authored and two is twice as fast. Zero or less holds the current frame and stops time advancing, which is a pause that leaves playing alone.
How long each frame is held is the sheet's answer rather than an entity's, because that is where an artist sets it: a hold frame is a frame with a long duration, which no single rate can express.
time#
time: numberCaller-writable. Supplies the phase used when frame is zero. To seek, write time and reset frame to zero. Read live phase with timeOf.
frame#
frame: integerEngine-owned. Holds -1 for encoded GPU playback, or zero to request re-encoding from time. Ordinary game code should call frameOf, which answers for an entity carrying no Animation too. Writing zero asks playback to rewrite the Sprite, which is what play, restart, of, and a restored snapshot do.
crossed#
crossed: integerEngine-owned. Retains the serialized component layout; GPU playback leaves this legacy event scratch field at zero. Ordinary game code should observe Completed and Looped instead. The reporting system clears it, and a snapshot drops it.
Bounds3Dtype#
type Bounds3D = Bounds3D2Stores the Bounds3D data for one 3D primitive.
Camera2Dstruct#
struct Camera2D
x: number
y: number
zoom: number
rotation: number
function matrix(borrows self: Camera2D, width: number, height: number): {number} end
function viewBounds(borrows self: Camera2D, width: number, height: number): number, number, number, number end
function toWorld(
borrows self: Camera2D,
screenX: number,
screenY: number,
width: number,
height: number
): number, number end
function toScreen(
borrows self: Camera2D,
worldX: number,
worldY: number,
width: number,
height: number
): number, number end
endA view onto the world, in world units and target pixels.
Methods
matrix#
matrix: function matrix(borrows self: Camera2D, width: number, height: number): {number}Returns the world-to-clip matrix for a viewport of width by height.
Column major, because that is how a shader reads a four-by-four uniform: the first four numbers are the first column, not the first row. Transposing them renders something plausible rather than nothing, which is how the mistake survives review.
The matrix owns the only y flip in the camera. toScreen and toWorld each spell out the same negated scale rather than sharing one helper, so a mismatch between the three stays visible.
Arguments
| Name | Type | Description |
|---|---|---|
borrows self | Camera2D | the camera to project through |
width | number | the viewport width in target pixels |
height | number | the viewport height in target pixels |
Returns
| Type | Description |
|---|---|
{number} | a fresh sixteen-number table the caller owns, indexed from one |
viewBounds#
viewBounds: function viewBounds(borrows self: Camera2D, width: number, height: number): number, number, number, numberReturns the world rectangle this camera can see.
A rotated camera reports the axis-aligned box enclosing the view's corners, so culling keeps a little more than it must. Keeping too much costs a few instances; keeping too little drops geometry that should have drawn, which is why the error goes this way.
Arguments
| Name | Type | Description |
|---|---|---|
borrows self | Camera2D | the camera to bound |
width | number | the viewport width in target pixels |
height | number | the viewport height in target pixels |
Returns
| Type | Description |
|---|---|
number | the smallest x, then the smallest y, then the largest x, then the largest y |
number | |
number | |
number |
toWorld#
toWorld: function toWorld(borrows self: Camera2D, screenX: number, screenY: number, width: number, height: number): number, numberConverts a target point to world space.
Arguments
| Name | Type | Description |
|---|---|---|
borrows self | Camera2D | the camera to project through |
screenX | number | the pixels from the left of the viewport |
screenY | number | the pixels from the top of the viewport, running down |
width | number | the viewport width in target pixels, the same one the matrix was built with |
height | number | the viewport height in target pixels, the same one the matrix was built with |
Returns
| Type | Description |
|---|---|
number | the world x, then the world y; a point outside the viewport converts too and lands outside the view rectangle |
number |
toScreen#
toScreen: function toScreen(borrows self: Camera2D, worldX: number, worldY: number, width: number, height: number): number, numberConverts a world point to target space.
Exactly the inverse of toWorld at the same width and height, and the same mapping matrix applies, so a point round-trips.
Arguments
| Name | Type | Description |
|---|---|---|
borrows self | Camera2D | the camera to project through |
worldX | number | the world x |
worldY | number | the world y, running down |
width | number | the viewport width in target pixels, the same one the matrix was built with |
height | number | the viewport height in target pixels, the same one the matrix was built with |
Returns
| Type | Description |
|---|---|
number | the pixels from the left, then the pixels from the top; neither is clamped to the viewport |
number |
Fields
y#
y: numberCaller-writable. Sets the vertical center of the view in world units. Increasing y moves the view towards the bottom of the world.
zoom#
zoom: numberCaller-writable. Sets the zoom. Values above one magnify about the center without moving the point under the middle of the target.
rotation#
rotation: numberCaller-writable. Sets the rotation in radians. Positive values turn the scene counter-clockwise on screen.
Camera3Dtype#
type Camera3D = Camera3D2A perspective camera with quaternion orientation.
Clipstruct#
struct Clip
index: integer
endA clip region selected by a renderable entity.
Fields
index#
index: integerCaller-writable. Selects a region set with setRegion, from one to MAX - 1. Zero, the default, means no clipping.
DropShadow2Dstruct#
struct DropShadow2D
height: number
endA stretched ground shadow, stored on a renderable entity.
Fields
height#
height: numberCaller-writable. Sets how far lights throw the shadow, from zero to one of the world's configured shadow height.
Fontrecord#
record Font
name: string
source: string
size: number
raster: Raster
ascent: number
descent: number
lineGap: number
lineHeight: number
endA loaded font and the atlas its glyphs live in.
Fields
source#
source: stringRead-only. Reports the path the bytes were read from, or the empty string for a font handed over as bytes.
size#
size: numberRead-only. Reports the point size glyphs are rasterized at. It is not the size text is drawn at.
raster#
raster: RasterRead-only. Reports whether the atlas holds a distance field or direct coverage.
ascent#
ascent: numberRead-only. Reports the distance from the baseline to the top of the typographic ascent, in em units.
descent#
descent: numberRead-only. Reports the distance from the baseline to the bottom of the typographic descent, in em units. It is negative in every ordinary font.
lineHeight#
lineHeight: numberRead-only. Reports the baseline-to-baseline distance in em units, which is the ascent less the descent plus the leading.
Materialstruct#
A material selection stored on a renderable entity.
Fields
id#
id: integerCaller-writable. Selects a material by an id id returned. Zero draws through textured.
param#
param: numberCaller-writable. Passes a value from zero to one to the material. What it means is the material's business.
Meshtype#
type Mesh = Mesh2Stores the Mesh data for one 3D primitive.
MeshMaterialtype#
type MeshMaterial = MeshMaterial2Stores the MeshMaterial data for one 3D primitive.
MeshMorphtype#
type MeshMorph = MeshMorph2Stores the MeshMorph data for one 3D primitive.
MeshSkintype#
type MeshSkin = MeshSkin2Stores the MeshSkin data for one 3D primitive.
Occluder2Dstruct#
struct Occluder2D
height: number
endA silhouette that blocks light, stored on a renderable entity.
Fields
height#
height: numberCaller-writable. Sets the occluder height from zero to one of the world's configured shadow height.
PointLight2Dstruct#
struct PointLight2D
height: number
radius: number
r: number
g: number
b: number
intensity: number
endA light the deferred resolve accumulates.
Fields
height#
height: numberCaller-writable. Sets the height above the surface plane in world units. At zero the Lambert term vanishes and the light contributes nothing.
radius#
radius: numberCaller-writable. Sets the light's reach in world units. Falloff is smooth and reaches exactly zero at the radius.
intensity#
intensity: numberCaller-writable. Scales the light's contribution. Values above one are meaningful, because the resolve writes a wider-than-eight-bit target.
PointLight3Dtype#
type PointLight3D = PointLight3D2Omnidirectional mesh light positioned by Transform3D.
SpotLight3Dtype#
type SpotLight3D = SpotLight3D2Conical mesh light aimed along Transform3D local negative Z.
Spritestruct#
An image region stored on a renderable entity.
Fields
image#
image: integerCaller-writable. Selects an image by its tecs.gfx.images id. Zero selects no image.
Textrecord#
record Text
text: string
font: fonts.Font?
size: number
align: Align
wrapWidth: number
width: number
height: number
endA string laid out into glyph entities.
Fields
text#
text: stringCaller-writable. Sets the laid-out string. A newline starts a line and wrapWidth may introduce further breaks.
font#
font: fonts.Font?Caller-writable. Selects the font that supplies the glyphs. Without one, the text draws nothing.
wrapWidth#
wrapWidth: numberCaller-writable. Sets the maximum line width in world units. Zero disables wrapping.
width#
width: numberEngine-owned. Reports the width of the last layout in world units, before the Transform2D scale. Assigning it has no effect.
height#
height: numberEngine-owned. Reports the height of the last layout in world units, on the same terms. Assigning it has no effect.
TileChunktype#
type TileChunk = TileChunk2A native 16 by 16 grid of static atlas tiles.
Tintstruct#
A four-channel color stored on a renderable entity.
Fields
Viewtype#
type View = View2Describes an ordered viewport with its own camera. Explicit views replace the synthesized full-frame camera; coordinates are fractions of the frame.
Values#
ActiveCameravariable#
const ActiveCamera: components.ComponentSelects the camera entity extraction projects the scene through.
Extraction reads the lowest live entity carrying both Camera2D and this tag. A world with no such entity draws through a camera centered on the render target at zoom one, which places world unit and target pixel on top of each other with the origin at the top left corner.
Animationvariable#
const Animation: ecs.ComponentDefinition<Animation>Constructs playback state directly. Prefer tecs.gfx.animation.of, which resolves a sheet and a tag name for you.
AnimationEventsvariable#
const AnimationEvents: ecs.ComponentRequests tecs.gfx.animation.Completed and tecs.gfx.animation.Looped for one entity.
Bounds3Dvariable#
Constructs the Bounds3D component for a 3D primitive.
Camera2Dvariable#
Constructs a camera centered on the world origin at zoom one.
Clipvariable#
const Clip: ecs.ComponentDefinition<Clip>Constructs a clip selecting a region set with tecs.gfx.clips.setRegion.
DirtyTileChunkvariable#
const DirtyTileChunkRequests synchronization after a nested tile-array edit.
DropShadow2Dvariable#
const DropShadow2D: components.FFIComponent<DropShadow2D>Constructs a drop-shadow caster at full height.
LIGHT_CASTS_SHADOWSvariable#
const LIGHT_CASTS_SHADOWS: integerRequests a slot in the local-light shadow atlas.
Materialvariable#
Constructs a material selection, defaulting to textured at parameter one quarter.
Meshvariable#
Constructs the Mesh component for a 3D primitive.
MeshMaterialvariable#
const MeshMaterial: components.FFIComponent<MeshMaterial>Constructs the MeshMaterial component for a 3D primitive.
MeshMorphvariable#
Constructs the MeshMorph component for a 3D primitive.
MeshSkinvariable#
Constructs the MeshSkin component for a 3D primitive.
Occluder2Dvariable#
const Occluder2D: components.FFIComponent<Occluder2D>Constructs an occluder at full height.
Pivotvariable#
const PivotAnchors a sprite at normalized X/Y coordinates or an authored sheet slice. Use Sheet:pivot to keep animated slice anchors synchronized with the GPU frames.
PointLight2Dvariable#
const PointLight2D: components.FFIComponent<PointLight2D>Constructs a light at height sixty-four, reaching two hundred and fifty-six world units, in white at full strength.
PointLight3Dvariable#
const PointLight3D: components.FFIComponent<PointLight3D>Constructs a point light with radius, linear RGB, intensity and LIGHT_* flags.
Renderable2Dvariable#
const Renderable2D: components.ComponentMarks an entity as contributing geometry to the two-dimensional scene.
Renderable3Dvariable#
const Renderable3DMarks geometry for the 3D renderer.
SpotLight3Dvariable#
const SpotLight3D: components.FFIComponent<SpotLight3D>Constructs a spot light with radius, inner and outer half-angles in radians, linear RGB, intensity and LIGHT_* flags.
Spritevariable#
Constructs a sprite whose omitted UV rectangle covers the whole image.
Textvariable#
const Text: ecs.ComponentDefinition<Text>Constructs a text whose omitted fields default to an empty left-aligned string at em size sixteen with no wrapping.
TextGlyphvariable#
Marks an entity as one glyph tecs.gfx.text placed for a Text.
TILE_CHUNK_SIZEvariable#
const TILE_CHUNK_SIZE: integerThe number of cells along a tile chunk edge.
TileChunkvariable#
Constructs a tile chunk positioned by its top-left Transform2D.
Tintvariable#
Constructs a tint whose omitted channels default to one.
Viewvariable#
Constructs a viewport from a camera and optional rectangle, order and enabled fields.