Classes
- BackgroundSystem
- BindGroup
- BlendModePipe
- Buffer
- BufferResource
- GlProgram
- GlUniformGroupSystem
- GpuProgram
- Shader
- UniformGroup
Interface Definitions
-
Options for rendering.autoDetectRenderer.
Properties:
Name Type Description manageImportsboolean Whether to manage the dynamic imports of the renderer code. It is true by default, this means PixiJS will load all the default pixi systems and extensions. If you set this to false, then you as the dev will need to manually import the systems and extensions you need.
preference"webgl" | "webgpu" The preferred renderer type. WebGPU is recommended as its generally faster than WebGL.
webglPartial<WebGLOptions> Optional WebGLOptions to pass only to the WebGL renderer
webgpuPartial<WebGPUOptions> Optional WebGPUOptions to pass only to WebGPU renderer.
-
Options for the background system.
Properties:
Name Type Default Description backgroundColorSource Alias for backgroundColor
backgroundAlphanumber 1 Transparency of the background color, value from
0(fully transparent) to1(fully opaque).backgroundColorColorSource 'black' The background color used to clear the canvas. See ColorSource for accepted color values.
clearBeforeRenderboolean true Whether to clear the canvas before new render passes.
-
an interface that allows a resource to be bound to the gpu in a bind group
-
The options for the gl program
Properties:
Name Type Description fragmentstring The fragment glsl shader source.
namestring the name of the program, defaults to 'pixi-program'
preferredFragmentPrecisionstring the preferred fragment precision for the shader, this may not be used if the device does not support it
preferredVertexPrecisionstring the preferred vertex precision for the shader, this may not be used if the device does not support it
vertexstring The vertex glsl shader source.
-
The options for the gpu program
Properties:
Name Type Description fragmentrendering.ProgramSource The fragment glsl shader source.
gpuLayoutrendering.ProgramPipelineLayoutDescription The gpu layout of the program. If not provided, it will be generated from the shader sources.
layoutrendering.ProgramLayout The layout of the program. If not provided, it will be generated from the shader sources.
namestring 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!
vertexrendering.ProgramSource The vertex glsl shader source.
-
the program source
Properties:
Name Type Description entryPointstring The main function to run in this shader
sourcestring The wgsl source code of the shader.
-
A descriptor for a shader
Properties:
Name Type Description compatibleRenderersnumber A number that uses two bits on whether the shader is compatible with the WebGL renderer and/or the WebGPU renderer. 0b00 - not compatible with either 0b01 - compatible with WebGL 0b10 - compatible with WebGPU This is automatically set based on if a GlProgram or {@link GpuProgram} is provided.
glProgramrendering.GlProgram The WebGL program used by the WebGL renderer.
gpuProgramrendering.GpuProgram The WebGPU program used by the WebGPU renderer.
-
A descriptor for a shader with groups.
Properties:
Name Type Description groupMapRecord<string, Record<string, any>> an optional map of how to bind the groups. This is automatically generated by reading the WebGPU program
groupsrendering.ShaderGroups A record of BindGroup's used by the shader.
-
A descriptor for a shader with resources. This is an easier way to work with uniforms. especially when you are not working with bind groups
Properties:
Name Type Description resourcesRecord<string, any> A key value of uniform resources used by the shader. Under the hood pixi will look at the provided shaders and figure out where the resources are mapped. Its up to you to make sure the resource key matches the uniform name in the webGPU program. WebGL is a little more forgiving!
Enums
rendering.BufferUsage
Buffer usage flags. they can be combined using the bitwise OR operator eg : BufferUsage.VERTEX | BufferUsage.INDEX
Properties:
| Name | Description |
|---|---|
COPY_DST |
The buffer can be used as the destination of a copy or write operation. (Examples: as the destination argument of a copyBufferToBuffer() or copyTextureToBuffer() call, or as the target of a writeBuffer() call.) |
COPY_SRC |
The buffer can be used as the source of a copy operation. (Examples: as the source argument of a copyBufferToBuffer() or copyBufferToTexture() call.) |
INDEX |
The buffer can be used as an index buffer. (Example: passed to setIndexBuffer().) |
INDIRECT |
The buffer can be used as to store indirect command arguments. (Examples: as the indirectBuffer argument of a drawIndirect() or dispatchWorkgroupsIndirect() call.) |
MAP_READ |
The buffer can be mapped for reading. (Example: calling mapAsync() with GPUMapMode.READ) May only be combined with COPY_DST. |
MAP_WRITE |
The buffer can be mapped for writing. (Example: calling mapAsync() with GPUMapMode.WRITE) May only be combined with COPY_SRC. |
QUERY_RESOLVE |
The buffer can be used to capture query results. (Example: as the destination argument of a resolveQuerySet() call.) |
STATIC |
the buffer will not be updated frequently |
STORAGE |
The buffer can be used as a storage buffer. (Example: as a bind group entry for a GPUBufferBindingLayout with a buffer.type of "storage" or "read-only-storage".) |
UNIFORM |
The buffer can be used as a uniform buffer. (Example: as a bind group entry for a GPUBufferBindingLayout with a buffer.type of "uniform".) |
VERTEX |
The buffer can be used as a vertex buffer. (Example: passed to setVertexBuffer().) |
Type Definitions
a map the maps names of uniforms to group indexes
a WebGPU descriptions of how the program is layed out
A record of BindGroup's used by the shader.
Record<number, BindGroup>
Uniform group options
Properties:
| Name | Type | Description |
|---|---|---|
isStatic |
boolean |
if true, then you are responsible for when the data is uploaded to the GPU by calling |
ubo |
boolean |
if true the UniformGroup is handled as an Uniform buffer object. This is the only way WebGPU can work with uniforms. WebGL2 can also use this. So don't set to true if you want to use WebGPU :D |
Methods
autoDetectRenderer (options) Promise<Renderer>
Automatically determines the most appropriate renderer for the current environment.
The function will prioritize the WebGPU renderer, falling back to WebGL2 if WebGPU is not supported. The selected renderer's code is then dynamically imported to optimize performance and minimize the initial bundle size.
To maximize the benefits of dynamic imports, it's recommended to use a modern bundler that supports code splitting. This will place the renderer code in a separate chunk, which is loaded only when needed.
| Name | Type | Description |
|---|---|---|
options |
Partial<rendering.AutoDetectOptions> |
A partial configuration object based on the |
Returns:
| Type | Description |
|---|---|
| Promise<Renderer> | A Promise that resolves to an instance of the selected renderer. |
Example
// create a renderer
const renderer = await autoDetectRenderer({
width: 800,
height: 600,
antialias: true,
});
// custom for each renderer
const renderer = await autoDetectRenderer({
width: 800,
height: 600,
webgpu:{
antialias: true,
backgroundColor: 'red'
},
webgl:{
antialias: true,
backgroundColor: 'green'
}
});