genRenderPipeline

View sourcegenRenderPipeline<T>(type: Constructor<T>, vertexSource: string, fragmentSource: string): SystemFunc

Creates a system that lazily compiles and caches one material’s WebGL render pipeline.

The factory captures type, vertexSource, and fragmentSource, computes typeid(type), and returns a SystemFunc; it does not compile shaders or register the system itself. Each run reads the world’s AttributeMap, UBOCache, WebglProgramCache, and Windows resources, and queries the first [[EntityHandle](</api/ecs/others/class/EntityHandle>), [Window](</api/window/component/Window>), [MainWindow](</api/window/component/MainWindow>)] tuple with Query#single.

If WebglProgramCache already has the material type ID, the system returns immediately without checking the window or touching WebGL. Without a main window it warns Please define the main window for rendering.; a missing canvas returns silently; and a canvas without a webgl2 context warns WebGL 2.0 context is not created or is lost.. These guard paths leave the pipeline cache unchanged.

Otherwise, the system uses Windows#getWindow to find the canvas, then compiles the captured sources with createShader for ShaderStage.Vertex and ShaderStage.Fragment, reports their status with validateShader, creates a linked program with createProgram using the AttributeMap, and wraps it in a WebglRenderPipeline. It then reports link and validation status with validateProgram, calls UBOCache#create to create a 16-byte UBO named by the material type ID, initializes the pipeline with WebglRenderPipeline#init, and stores it in the cache. Shader and program validation only logs diagnostics; their return values are ignored, so pipeline initialization continues after a reported validation failure. Allocation, reflection, or UBO-size errors from the called APIs propagate. A successful run returns undefined.

Examples

const initPipeline = genRenderPipeline(MyMaterial, vertexSource, fragmentSource)
app.registerSystem({
  schedule: AppSchedule.Update,
  systemGroup: CoreSystems.PostMain,
  system: initPipeline
})
// Later runs do nothing once WebglProgramCache contains this material ID.

Type Parameters

T

Parameters

NameDescriptionDefault
type

Material constructor whose type ID keys the pipeline and material UBO.

—
vertexSource

Vertex-shader source passed to createShader.

—
fragmentSource

Fragment-shader source passed to createShader.

—

Returns

System that initializes and caches the material pipeline when the WebGL setup is available.