genrender

View sourcegenrender<T extends Material>(type: Constructor<T>, renderMaterial: Canvas2DFunction<T>): SystemFunc

Creates a Canvas 2D render system for one material constructor.

The returned system expects typed Assets resources for Mesh and the generic T material, a TextureCache for image textures, a Windows resource, and a main-window entity with EntityHandle, Window, and MainWindow. It visits cameras that have GlobalTransform2D, RenderLists2D, and Camera.

For each camera, the system applies its orthographic projection and view transform, then resolves or creates the camera’s opaque pass for type. It calls renderMaterial for entries whose mesh and material handles resolve, passing the drawing context, material, mesh, and shared texture cache. Missing asset values are skipped, and the existing render list is not cleared or rebuilt by this system.

If no main-window entity is found, the system warns and stops. It also stops when the window has no registered canvas. A canvas without a 2D context produces a warning. A camera using a non-orthographic projection throws because this renderer supports OrthographicProjection only. Missing required resources cause the returned system’s resource lookup to fail.

Examples

const renderSystem = genrender(BasicMaterial, (ctx, material, mesh, textures) => {
  // Draw `mesh` with `material`, using `textures` when needed.
})

app.registerSystem({
  schedule: AppSchedule.Update,
  system: renderSystem
})

Type Parameters

T extends Material

Parameters

NameDescriptionDefault
type

Material constructor whose opaque pass is rendered.

—
renderMaterial

Callback that draws one material and mesh.

—

Returns

System that renders the material’s 2D opaque pass.