Shader

Shader(uniforms) :: # (opaque)

Host-owned GPU shaders and their typed application uniform records.

Shader construction belongs here because a shader is a resource independent of a particular presentation frame. Applying one remains a Draw.Frame operation (frame.with_shader!).

from_source! : LoadShaderSource, uniforms => Try(Shader(uniforms), [ShaderLoadFailed, ResourceLimit, UniformNotFound(Str), UniformReflectionUnavailable, UniformTypeMismatch({ name : Str, expected : ShaderUniformType, actual : ShaderUniformType }), UnsupportedUniformType(Str)])
    where [
        uniforms.encoder_for : UniformFormat -> (uniforms, UniformState -> Try(UniformState, UniformEncodeError)),
    ]

Compile shader stages from source strings and validate the complete application-uniform schema. Legal in init!, update!, and tasks; refused in render!.

from_store! : Store, LoadShader, uniforms => Try(Shader(uniforms), [PathInvalid, NotFound, ReadFailed, ShaderLoadFailed, ResourceLimit, UniformNotFound(Str), UniformReflectionUnavailable, UniformTypeMismatch({ name : Str, expected : ShaderUniformType, actual : ShaderUniformType }), UnsupportedUniformType(Str)])
    where [
        uniforms.encoder_for : UniformFormat -> (uniforms, UniformState -> Try(UniformState, UniformEncodeError)),
    ]

Compile shader stage files resolved through an explicit asset store. Legal in init!, where it blocks startup, and in tasks, where it parks the task; refused in update! and render!.

with_uniforms : Shader(uniforms), uniforms -> Shader(uniforms)
    where [
        uniforms.encoder_for : UniformFormat -> (uniforms, UniformState -> Try(UniformState, UniformEncodeError)),
    ]

Return a shader sharing its compiled program and binding layout with a replaced, type-checked uniform record. This is pure.

stub : uniforms -> Shader(uniforms)
    where [
        uniforms.encoder_for : UniformFormat -> (uniforms, UniformState -> Try(UniformState, UniformEncodeError)),
    ]

Resource-free shader value for pure tests.

for_frame : Shader(uniforms) -> { resource : Shader, values : List(ShaderUniformValue) }

Private frame payload assembled from the retained uniform record.