Render
Back to the reference

Render

What the renderer is told and what it answers: backends, capabilities and draw items.

6 symbols

useRenderStylefunctionhooknacatamalon

useRenderStyle(style: TRenderStyle | null) => TRenderStyleHandle

Draws this scene in a style: how its models' materials are drawn when they do not say (at every pixel, swimming, shivering) and the full-screen effects it is seen through, in place of the game's style (createGame({ style })). Leaving the scene takes it away and the game's comes back, its effects included, so one level can be a 1997 console and the next a glossy studio.

The view's, like useFog: a picture with a world of its own has its own, and asking for one inside it does not change the room the picture is in. A picture is drawn with no full-screen effects, so there a style changes its materials only: its post is for the screen. With none of its own, a picture takes its scene's.

Its resolution and filtering, when it has them, are the game's from the moment it is asked for, so the rest of the scene is built at the size it is drawn at; behind a transition's cover, from the swap, and behind the splash, from when it lets the game go. A material that says otherwise keeps what it says. The first time a scene draws a material at every pixel it has not drawn that way before, its shader is made; until it is ready the model is drawn at its corners, for a frame or two.

Parameters

styleTRenderStyle | null

One of RENDER.STYLES (cgi, ps1), one of the game's own, or null for the game's.

Example

const Museum = () => {
    const keys = useKeyboard();
    const style = useRenderStyle(RENDER.STYLES.cgi);
    useStudio();
    // ...
    useUpdate(() => {
        if (keys.justPressed('p')) style.set(RENDER.STYLES.ps1);
    });
    return createScene();
};
View source · hooks/style/use_render_style.ts:46

TCaptureResulttypenacatamalon

Pixels brought back from the graphics card, as RGBA8, row by row from the top-left corner.

Top-left because that is where every other picture in this engine starts. WebGL2 reads from the bottom, so its backend turns the rows around before handing them over: a picture that comes back upside down depending on which backend ran is exactly the kind of difference the interface exists to hide.

Properties

widthnumber
heightnumber
dataUint8Array

width * height * 4 bytes.

View source · render/interface/t_capture_result.ts:13

TRendererTypetypenacatamalon

TRendererType: 'AUTO' | TRendererBackend

What a caller may ask createRenderer for.

  • 'AUTO': tries WebGPU, and on any failure falls back to WebGL2.
  • 'WEBGPU' / 'WEBGL2': that backend or nothing. A named backend never falls back: asking for one explicitly and silently getting the other hides the thing you were testing.
View source · render/interface/t_renderer_capabilities.ts:21

TRenderStyletypenacatamalon

A way of drawing a whole scene: how its models' materials are drawn when they do not say, the full-screen effects it is seen through, and the resolution and filtering of the screen it is drawn on. RENDER.STYLES has the engine's own (from nes to cgi); a game makes its own the same way, as plain data, or one of them changed: { ...RENDER.STYLES.n64, width: 640, height: 480 }.

Given to the game (createGame({ style })) it is every scene's, and what the game's own options say wins over it: createGame({ style: RENDER.STYLES.n64, width: 640, height: 480 }) is the N64 at 640 x 480. Given to a scene (useRenderStyle) it is that scene's, in place of the game's, and its resolution and filtering are laid over the game's while it is on, whatever the game said: a 1280 x 720 game whose level asks for RENDER.STYLES.cgi draws that level at 640 x 480. To keep the game's, give the style without them: { ...RENDER.STYLES.cgi, width: undefined, height: undefined }. Leaving the scene puts the game's back. A material that says otherwise keeps what it says: perPixel: false on one is drawn at its corners in a scene that draws the rest at every pixel.

Properties

perPixeloptionalboolean

The light worked out at every pixel, for each material that does not say (see the material's perPixel).

affineoptionalboolean

The picture stretched across the screen without correcting for depth, for each material that does not say (see the material's affine).

vertexSnapoptionalboolean | number

The corners put on a coarse grid of the screen, for each material that does not say (see the material's vertexSnap).

postoptionalTPostChain

The full-screen effects the scene is seen through while the style is on, after its own and the game's: entries as createGame({ post }) takes them, { builtin: 'bloom', uniforms: { ... } }.

widthoptionalnumber

The resolution the game is drawn at while the style is on, as createGame({ width }), with height: the two are one decision, and one without the other is no resolution. Left out, the game's. A scene that asks for its style with useRenderStyle is built at it already, so its HUD placed by useGame().getWidth() is where it should be; one built behind a transition's cover or behind the splash is built at the size before, and gets its own at the swap or once the splash lets the game go, so its HUD is placed again on onResized as well. With scaling 'none', the default, the canvas is shown at the new size.

heightoptionalnumber

The resolution's height, as createGame({ height }). Left out, the game's.

smoothoptionalboolean

Pictures read smoothly between their pixels, as createGame({ smooth }): the textures of every material that does not say, and the screen as it is scaled up unless smoothScaling says. Left out, the game's.

smoothScalingoptionalboolean

The screen scaled up to the page smoothly, as createGame({ smoothScaling }), apart from the pictures: RENDER.STYLES.n64 reads its textures smoothly and keeps its screen's pixels square. Left out, it goes with smooth.

pixelAspectoptionalnumber

The shape of the screen's pixels, as createGame({ pixelAspect }): 8 / 7 for the NES and the SNES, a little wider than tall. Left out, the game's.

View source · style/t_render_style.ts:23