# `tecs.gfx.layers`
## Overview
::: api-overview
**functions**
- [`bandOf`](#tecs.gfx.layers.bandOf)
- [`configure`](#tecs.gfx.layers.configure)
- [`depthIn`](#tecs.gfx.layers.depthIn)
- [`depthOf`](#tecs.gfx.layers.depthOf)
- [`entryOf`](#tecs.gfx.layers.entryOf)
- [`extents`](#tecs.gfx.layers.extents)
- [`isOverlay`](#tecs.gfx.layers.isOverlay)
- [`isScreenSpace`](#tecs.gfx.layers.isScreenSpace)
- [`parallaxOf`](#tecs.gfx.layers.parallaxOf)
- [`place`](#tecs.gfx.layers.place)
- [`resolution`](#tecs.gfx.layers.resolution)
- [`revision`](#tecs.gfx.layers.revision)
- [`setExtents`](#tecs.gfx.layers.setExtents)
- [`setVirtualSize`](#tecs.gfx.layers.setVirtualSize)
- [`sortOf`](#tecs.gfx.layers.sortOf)
- [`viewCulled`](#tecs.gfx.layers.viewCulled)
- [`virtualSize`](#tecs.gfx.layers.virtualSize)
**types**
- [`Config`](#tecs.gfx.layers.Config)
- [`Sort`](#tecs.gfx.layers.Sort)
**values**
- [`MAX`](#tecs.gfx.layers.MAX)
- [`MODE_CAMERA`](#tecs.gfx.layers.MODE_CAMERA)
- [`MODE_SCREEN`](#tecs.gfx.layers.MODE_SCREEN)
- [`MODE_VIRTUAL`](#tecs.gfx.layers.MODE_VIRTUAL)
- [`SORT_ISOMETRIC`](#tecs.gfx.layers.SORT_ISOMETRIC)
- [`SORT_TOPDOWN`](#tecs.gfx.layers.SORT_TOPDOWN)
- [`SORT_Z`](#tecs.gfx.layers.SORT_Z)
:::
::: api-group
## Functions
::: api-item tecs.gfx.layers.bandOf
### `bandOf` _function_
```nupp
function(layer: integer): (number, integer)
```
Returns the two terms `depthIn` takes, resolved once for one layer.
A caller writing many depths on one layer resolves the band once here
rather than once a row.
#### Arguments
`layer` - `integer`
: the band to resolve; outside one to `MAX` this resolves the nearest layer whole, so the sort answered is the clamped layer's
#### Returns
`number`
: the band's near edge, then the sort identifier
`integer`
:
:::
::: api-item tecs.gfx.layers.configure
### `configure` _function_
```nupp
function(layer: integer, config: Config)
```
Sets what one layer does with its contents.
Replaces the layer's configuration rather than amending it, so every
omitted field takes its default instead of keeping its previous value.
#### Arguments
`layer` - `integer`
: the band to configure, from one to `MAX`
`config` - [`Config`](../../../../modules/tecs/gfx/layers/index.html#tecs.gfx.layers.Config)
: the complete replacement configuration
#### Raises
| Type | Condition |
| --- | --- |
| `string` | when the layer is outside the band range, when the sort is unknown, or when one layer asks for screen pixels and virtual coordinates at once |
:::
::: api-item tecs.gfx.layers.depthIn
### `depthIn` _function_
```nupp
function(base: number, sort: integer, z: number, x: number, y: number): number
```
Returns one entity's depth on a band `bandOf` already resolved.
#### Arguments
`base` - `number`
: the band's near edge, from `bandOf`
`sort` - `integer`
: the sort identifier, from `bandOf`
`z` - `number`
: the height in the sort, normalized against the height extent
`x` - `number`
: the world x, read only by the isometric sort
`y` - `number`
: the world y, read by the topdown and isometric sorts, larger being nearer
#### Returns
`number`
: a depth inside the band, held between 0.001 and 0.999
:::
::: api-item tecs.gfx.layers.depthOf
### `depthOf` _function_
```nupp
function(layer: integer, z: number, x: number, y: number): number
```
Returns one entity's depth from zero to one, with zero nearest.
Exact ties carry no tie-breaker of their own. Extraction writes instances in
sorted order and the backend draws them in that order, so two entities at
one depth resolve the same way every frame: the later one wins.
#### Arguments
`layer` - `integer`
: the band, from one to `MAX`; outside that range this takes the nearest layer whole, because a band is the only thing a depth can name
`z` - `number`
: the height in the sort, normalized against the height extent
`x` - `number`
: the world x, read only by the isometric sort
`y` - `number`
: the world y, read by the topdown and isometric sorts, larger being nearer
#### Returns
`number`
: the depth inside the layer's own band
:::
::: api-item tecs.gfx.layers.entryOf
### `entryOf` _function_
```nupp
function(layer: integer): (number, number, number, number)
```
Returns the four numbers that position and light one layer.
A consumer packs these together when `revision` changes rather than reading
them per frame, which is why they come back together.
#### Arguments
`layer` - `integer`
: the band to read; outside one to `MAX` this answers the defaults an unconfigured layer carries rather than raising
#### Returns
`number`
: the positioning mode, then the camera position's multiplier, then one when the layer ignores zoom, then one when the layer is lit
`number`
:
`number`
:
`number`
:
:::
::: api-item tecs.gfx.layers.extents
### `extents` _function_
```nupp
function(): (number, number)
```
Returns the authored extents every sort normalizes against.
#### Returns
`number`
: the highest height a scene expects to use, then half the expected world extent
`number`
:
:::
::: api-item tecs.gfx.layers.isOverlay
### `isOverlay` _function_
```nupp
function(layer: integer): boolean
```
Returns whether a layer always takes the sorted forward lane.
#### Arguments
`layer` - `integer`
: the band to read; outside one to `MAX` this answers false, as an unconfigured layer does
#### Returns
`boolean`
: whether `configure` selected `overlay` for the layer
:::
::: api-item tecs.gfx.layers.isScreenSpace
### `isScreenSpace` _function_
```nupp
function(layer: integer): boolean
```
Returns whether a layer measures positions in target pixels.
#### Arguments
`layer` - `integer`
: the band to read; outside one to `MAX` this answers false, as an unconfigured layer does
#### Returns
`boolean`
: whether `configure` selected `screenSpace` for the layer
:::
::: api-item tecs.gfx.layers.parallaxOf
### `parallaxOf` _function_
```nupp
function(layer: integer): number
```
Returns how much of the camera's movement a layer's contents take.
#### Arguments
`layer` - `integer`
: the band to read; outside one to `MAX` this answers one, as an unconfigured layer does
#### Returns
`number`
: the parallax factor, one moving contents with the world and a half drifting them at half speed
:::
::: api-item tecs.gfx.layers.place
### `place` _function_
```nupp
function(
layer: integer,
x: number,
y: number,
cameraX: number,
cameraY: number,
zoom: number,
rotation: number,
width: number,
height: number
): (number, number)
```
Returns where one authored position lands on the render target.
The one place the four positioning modes are resolved, so a caller placing
geometry and a caller hit-testing it cannot disagree. A camera layer turns
and scales the position about the view center, taking parallax before the
turn and dropping the zoom afterwards when the layer ignores it. A
screen-space layer answers the position unchanged, and a virtual layer
scales the authored resolution onto the target.
#### Arguments
`layer` - `integer`
: the band whose mode decides what the position means; outside one to `MAX` this places through the camera, as an unconfigured layer does
`x` - `number`
: the authored horizontal position, in world units, target pixels, or virtual units according to the layer's mode
`y` - `number`
: the authored vertical position, running down in every mode
`cameraX` - `number`
: the view center's world x, read only by a camera layer
`cameraY` - `number`
: the view center's world y, read only by a camera layer
`zoom` - `number`
: the camera's zoom, read only by a camera layer that does not ignore it
`rotation` - `number`
: the camera's rotation in radians, read only by a camera layer
`width` - `number`
: the render target width in pixels
`height` - `number`
: the render target height in pixels
#### Returns
`number`
: the pixels from the target's left edge, then the pixels from its top edge; neither is clamped to the target
`number`
:
:::
::: api-item tecs.gfx.layers.resolution
### `resolution` _function_
```nupp
function(): number
```
Returns the smallest depth difference `depthOf` produces between two
entities one world unit apart, taken over every sort mode.
A depth target must preserve this difference. A format with a larger step
keeps the bands, so layer order stays safe, and loses the sort inside them.
#### Returns
`number`
: the depth difference, in the input that moves depth least
:::
::: api-item tecs.gfx.layers.revision
### `revision` _function_
```nupp
function(): integer
```
Returns the configuration revision.
#### Returns
`integer`
: a count starting at zero that only rises, so a consumer holding a packed copy can tell whether its copy is still the answer
:::
::: api-item tecs.gfx.layers.setExtents
### `setExtents` _function_
```nupp
function(highestZ: number, halfExtent: number)
```
Replaces the authored extents every sort normalizes against.
Raising an extent lowers the depth difference one world unit is worth,
which is what `resolution` reports.
#### Arguments
`highestZ` - `number`
: the highest height a scene expects to use
`halfExtent` - `number`
: half the expected world extent, used by the position terms
#### Raises
| Type | Condition |
| --- | --- |
| `string` | when either extent is not greater than zero |
:::
::: api-item tecs.gfx.layers.setVirtualSize
### `setVirtualSize` _function_
```nupp
function(width: number, height: number)
```
Replaces the authored resolution every virtual-coordinate layer is measured
in.
One resolution serves every such layer, because a game has one authored
layout size. `place` scales it to fill the target, so the layout keeps its
internal proportions at any window size and stretches with the window's
aspect. It neither letterboxes nor preserves square pixels.
#### Arguments
`width` - `number`
: the authored width in virtual units
`height` - `number`
: the authored height in virtual units
#### Raises
| Type | Condition |
| --- | --- |
| `string` | when either dimension is not greater than zero |
:::
::: api-item tecs.gfx.layers.sortOf
### `sortOf` _function_
```nupp
function(layer: integer): integer
```
Returns a layer's sort as the identifier `depthIn` accepts.
#### Arguments
`layer` - `integer`
: the band to read, from one to `MAX`
#### Returns
`integer`
: the sort identifier, which is an internal number rather than a `Sort` string
:::
::: api-item tecs.gfx.layers.viewCulled
### `viewCulled` _function_
```nupp
function(layer: integer): boolean
```
Returns whether the camera's view rectangle decides if a layer draws.
False on a layer the camera does not place where its world bound says.
Screen-space and virtual-coordinate contents have no world position for the
view to test, and parallax and zoom independence draw them somewhere the
bound does not describe. Extraction gives those contents a bound every view
contains, so they draw whatever the camera is looking at, and a layer using
none of these modes keeps exact culling.
#### Arguments
`layer` - `integer`
: the band to read; outside one to `MAX` this answers true, as an unconfigured layer does
#### Returns
`boolean`
: whether extraction should write this layer's real world bound
:::
::: api-item tecs.gfx.layers.virtualSize
### `virtualSize` _function_
```nupp
function(): (number, number)
```
Returns the authored resolution every virtual-coordinate layer is measured
in.
#### Returns
`number`
: the authored width, then the authored height, both in virtual units
`number`
:
:::
:::
::: api-group
## Types
::: api-item tecs.gfx.layers.Config
### `Config` _type_
```nupp
type Config = {
sort: Sort,
screenSpace: boolean?,
ignoreZoom: boolean?,
virtualCoords: boolean?,
unlit: boolean?,
overlay: boolean?,
parallax: number?
}
```
Defines everything a layer decides about its contents.
A field left out takes its default, so this says what a layer is rather
than amending what it was. `sort` is the one field a caller must set;
`screenSpace`, `ignoreZoom`, `virtualCoords`, `unlit`, and `overlay`
default to false, and `parallax` defaults to one.
#### Members
::: api-overview
**fields**
- [`ignoreZoom`](#tecs.gfx.layers.Config.ignoreZoom)
- [`overlay`](#tecs.gfx.layers.Config.overlay)
- [`parallax`](#tecs.gfx.layers.Config.parallax)
- [`screenSpace`](#tecs.gfx.layers.Config.screenSpace)
- [`sort`](#tecs.gfx.layers.Config.sort)
- [`unlit`](#tecs.gfx.layers.Config.unlit)
- [`virtualCoords`](#tecs.gfx.layers.Config.virtualCoords)
:::
::: api-item tecs.gfx.layers.Config.sort
#### `sort` _field_
`sort:` [`Sort`](../../../../modules/tecs/gfx/layers/index.html#tecs.gfx.layers.Sort)
:::
::: api-item tecs.gfx.layers.Config.screenSpace
#### `screenSpace` _field_
```nupp
screenSpace: boolean?
```
:::
::: api-item tecs.gfx.layers.Config.ignoreZoom
#### `ignoreZoom` _field_
```nupp
ignoreZoom: boolean?
```
:::
::: api-item tecs.gfx.layers.Config.virtualCoords
#### `virtualCoords` _field_
```nupp
virtualCoords: boolean?
```
:::
::: api-item tecs.gfx.layers.Config.unlit
#### `unlit` _field_
```nupp
unlit: boolean?
```
:::
::: api-item tecs.gfx.layers.Config.overlay
#### `overlay` _field_
```nupp
overlay: boolean?
```
:::
::: api-item tecs.gfx.layers.Config.parallax
#### `parallax` _field_
```nupp
parallax: number?
```
:::
:::
::: api-item tecs.gfx.layers.Sort
### `Sort` _type_
```nupp
type Sort = "topdown" | "z" | "isometric"
```
Selects how a layer orders its own contents.
These identifiers reach configuration a developer writes and are a
compatibility surface.
:::
:::
::: api-group
## Values
::: api-item tecs.gfx.layers.MAX
### `MAX` _variable_
```nupp
const MAX: integer
```
The number of bands that divide the depth range.
Load-bearing at sixteen. The band formula divides the range by it and a
consumer recovers a layer by multiplying a depth by it, so raising it
changes every depth a scene has ever recorded.
:::
::: api-item tecs.gfx.layers.MODE_CAMERA
### `MODE_CAMERA` _variable_
```nupp
const MODE_CAMERA: number
```
Positions contents in world units, through the camera.
This value is the first component of what `entryOf` reports, which a
renderer packs into a uniform the vertex stage compares against, so it is a
compatibility surface rather than an identifier this tree renumbers.
:::
::: api-item tecs.gfx.layers.MODE_SCREEN
### `MODE_SCREEN` _variable_
```nupp
const MODE_SCREEN: number
```
Positions contents in target pixels, ignoring the camera.
:::
::: api-item tecs.gfx.layers.MODE_VIRTUAL
### `MODE_VIRTUAL` _variable_
```nupp
const MODE_VIRTUAL: number
```
Positions contents in the authored virtual resolution, stretched to the
target.
:::
::: api-item tecs.gfx.layers.SORT_ISOMETRIC
### `SORT_ISOMETRIC` _variable_
```nupp
const SORT_ISOMETRIC: integer
```
Sorts by x plus y plus height for a diamond grid.
:::
::: api-item tecs.gfx.layers.SORT_TOPDOWN
### `SORT_TOPDOWN` _variable_
```nupp
const SORT_TOPDOWN: integer
```
Sorts lower screen positions in front and breaks ties with height.
:::
::: api-item tecs.gfx.layers.SORT_Z
### `SORT_Z` _variable_
```nupp
const SORT_Z: integer
```
Sorts only by height and ignores world position.
:::
:::