Namespace: rendering

rendering

The rendering namespace contains all the classes used for core rendering in PixiJS this includes all the lower level resources such as Textures, Shaders, State, Buffers, Geometry and the systems required to use them. This covers WebGL and WEbGPU and their shared classes.

Classes

BackgroundSystem
BindGroup
BlendModePipe
Buffer
BufferResource
GlProgram
GlUniformGroupSystem
GpuProgram
Shader
UniformGroup

Interface Definitions

AutoDetectOptions

Properties:
Name Type Description
manageImports boolean

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.

webgl Partial<WebGLOptions>

Optional WebGLOptions to pass only to the WebGL renderer

webgpu Partial<WebGPUOptions>

Optional WebGPUOptions to pass only to WebGPU renderer.

BackgroundSystemOptions

Options for the background system.

Properties:
Name Type Default Description
background ColorSource

Alias for backgroundColor

backgroundAlpha number 1

Transparency of the background color, value from 0 (fully transparent) to 1 (fully opaque).

backgroundColor ColorSource 'black'

The background color used to clear the canvas. See ColorSource for accepted color values.

clearBeforeRender boolean true

Whether to clear the canvas before new render passes.

BindResource

an interface that allows a resource to be bound to the gpu in a bind group

GlProgramOptions

The options for the gl program

Properties:
Name Type Description
fragment string

The fragment glsl shader source.

name string

the name of the program, defaults to 'pixi-program'

preferredFragmentPrecision string

the preferred fragment precision for the shader, this may not be used if the device does not support it

preferredVertexPrecision string

the preferred vertex precision for the shader, this may not be used if the device does not support it

vertex string

The vertex glsl shader source.

GpuProgramOptions

The options for the gpu program

Properties:
Name Type Description
fragment rendering.ProgramSource

The fragment glsl shader source.

gpuLayout rendering.ProgramPipelineLayoutDescription

The gpu layout of the program. If not provided, it will be generated from the shader sources.

layout rendering.ProgramLayout

The layout of the program. If not provided, it will be generated from the shader sources.

name string

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!

vertex rendering.ProgramSource

The vertex glsl shader source.

ProgramSource

the program source

Properties:
Name Type Description
entryPoint string

The main function to run in this shader

source string

The wgsl source code of the shader.

ShaderWith

A descriptor for a shader

Properties:
Name Type Description
compatibleRenderers number

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.

glProgram rendering.GlProgram

The WebGL program used by the WebGL renderer.

gpuProgram rendering.GpuProgram

The WebGPU program used by the WebGPU renderer.

ShaderWithGroupsDescriptor

A descriptor for a shader with groups.

Properties:
Name Type Description
groupMap Record<string, Record<string, any>>

an optional map of how to bind the groups. This is automatically generated by reading the WebGPU program

groups rendering.ShaderGroups

A record of BindGroup's used by the shader.

ShaderWithResourcesDescriptor

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
resources Record<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

ProgramLayout

a map the maps names of uniforms to group indexes

ProgramPipelineLayoutDescription

a WebGPU descriptions of how the program is layed out

See:

ShaderGroups

A record of BindGroup's used by the shader.

Record<number, BindGroup>

UniformGroupOptions

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 update()

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 AutoDetectOptions type.

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'
   }
  });