genRender

View sourcegenRender<T extends Material & UniformBind>(type: Constructor<T>): SystemFunc

Creates a system that renders one material type’s 3D opaque pass with WebGL.

The factory captures type, computes the material type ID, and computes the typed Assets IDs for Mesh and that material. It returns a SystemFunc; it does not register the system or create any resources. Each run reads Assets<Mesh>, Assets<T>, MeshCache, WebglProgramCache, UBOCache, Windows, and ClearColor. It also queries cameras with [[GlobalTransform3D](</api/transform/component/GlobalTransform3D>), [RenderLists3D](</api/render-core/component/RenderLists3D>), [Camera](</api/render-core/component/Camera>)] and the first window with [[EntityHandle](</api/ecs/others/class/EntityHandle>), [Window](</api/window/component/Window>), [MainWindow](</api/window/component/MainWindow>)].

No main window logs Please define the main window for rendering. and returns. A missing canvas returns silently, while a missing webgl2 context logs WebGL 2.0 context is not created or is lost. and returns. On success, the system clears the color buffer using the channels in ClearColor before visiting cameras. A camera is skipped when the WebglProgramCache has no pipeline for this material type or when its RenderLists3D has no opaque pass for that type.

For each opaque item, the system looks up its mesh and material assets and cached vertex array, converts its transform with Affine3.toMatrix4, uploads the material’s UniformBind#asUniformBind data to the material UBO, binds the pipeline and vertex array, and draws indexed triangles when Mesh#getIndices returns a value. Otherwise it reads the position3d attribute and draws positions.data.length / 3 vertices. The camera UBO is updated with the inverse global transform followed by the camera projection matrix before that camera’s items are drawn.

The camera UBO and material UBO are required: missing entries trigger the corresponding assert failure. Missing mesh or material assets are not guarded here and fail when their methods are used; a missing GPU cache entry is passed to gl.bindVertexArray as-is. If a mesh has no position3d attribute, the current camera callback returns and its remaining items are skipped. A successful run returns undefined; WebGL state and uploaded buffer contents remain available to subsequent system invocations.

Examples

const renderMaterial = genRender(MyMaterial)
app.registerSystem({
  schedule: AppSchedule.Update,
  systemGroup: CoreSystems.PostMain,
  system: renderMaterial
})
// WebglMaterialPlugin performs this registration for its material type.

Type Parameters

T extends Material & UniformBind

Parameters

NameDescriptionDefault
type

Material asset constructor whose opaque pass and typed asset pool are rendered.

—

Returns

System that clears the active WebGL canvas and renders the material’s available 3D opaque items.