mirror of
https://github.com/visgl/luma.gl.git
synced 2025-12-08 17:36:19 +00:00
2.0 KiB
2.0 KiB
Shader
:::caution The luma.gl v9 API is currently in public review and may be subject to change. :::
The Shader class holds a compiled shader.
- It takes shader source code and compiles it during construction.
- Shaders are used as inputs when creating
RenderPipelineandComputePipelineobjects. - A
Shaderis immutable and the same compiled shader can safely be referenced by many pipelines.
Usage
Create a pair of shaders
const vs = device.createShader({stage: 'vertex', source});
const fs = device.createShader({stage: 'fragment', source});
Types
ShaderProps
Properties for a Shader
| Field | Type | Description |
|---|---|---|
id |
string |
name/identifier (for debugging) |
stage |
'vertex' | 'fragment' | 'compute' | Required by WebGL and GLSL transpiler |
source |
string |
Shader source code |
sourceMap? |
string |
WebGPU only |
language? |
'glsl' | 'wgsl' | wgsl in WebGPU only |
entryPoint? |
string |
WGLSL only, name of main function |
Members
device:Device- holds a reference to thehandle:unknown- holds the underlying WebGL or WebGPU shader objectprops:ShaderProps- holds a copy of theShaderPropsused to create thisShader.
Methods
constructor(props: ShaderProps)
Shader is an abstract class and cannot be instantiated directly. Create with device.createShader(...).
destroy(): void
Free up any GPU resources associated with this shader immediately (instead of waiting for garbage collection).
getInfoLog(): Promise<CompilerMessage[]>
Remarks
- Shader compilation is fairly fast, in particular compared to Pipeline linking.