Create a new GpuProgram
Name | Type | Description |
---|---|---|
options |
GpuProgramOptions |
The options for the gpu program |
Example
// Create a new program
const program = new GpuProgram({
vertex: {
source: '...',
entryPoint: 'main',
},
fragment:{
source: '...',
entryPoint: 'main',
},
});
Members
if true, the program will automatically assign global uniforms to group[0]
if true, the program will automatically assign local uniforms to group[1]
fragment ProgramSource readonly
The fragment glsl shader source.
gpuLayout ProgramPipelineLayoutDescription readonly
Configuration for the WebGPU bind group layouts, detailing resource organization for the shader. Generated from shader sources if not explicitly provided.
Example
// Assuming a shader program that requires two bind groups:
[
// First bind group layout entries
[{ binding: 0, visibility: GPUShaderStage.VERTEX, type: "uniform-buffer" }],
// Second bind group layout entries
[{ binding: 1, visibility: GPUShaderStage.FRAGMENT, type: "sampler" },
{ binding: 2, visibility: GPUShaderStage.FRAGMENT, type: "sampled-texture" }]
]
layout ProgramLayout readonly
Mapping of uniform names to group indexes for organizing shader program uniforms. Automatically generated from shader sources if not provided.
Example
// Assuming a shader with two uniforms, `u_time` and `u_resolution`, grouped respectively:
[
{ "u_time": 0 },
{ "u_resolution": 1 }
]
the name of the program, this is added to the label of the GPU Program created under the hood. Makes it much easier to debug!
the structs and groups extracted from the shader sources
vertex ProgramSource readonly
The vertex glsl shader source
Methods
from (options) GpuProgram static
Helper function that creates a program for a given source. It will check the program cache if the program has already been created. If it has that one will be returned, if not a new one will be created and cached.
Name | Type | Description |
---|---|---|
options |
GpuProgramOptions |
The options for the program. |
Returns:
Type | Description |
---|---|
GpuProgram | A program using the same source |
destroys the program