Classes
- AbstractRenderer
- BackgroundSystem
- Batch
- BatchTextureArray
- BindGroup
- BindGroupSystem
- BlendModePipe
- Bounds
- Buffer
- BufferResource
- CanvasPool
- CanvasTextSystem
- CustomRenderPipe
- ExtractSystem
- FilterSystem
- GenerateTextureSystem
- Geometry
- GlBackBufferSystem
- GlBufferSystem
- GlColorMaskSystem
- GlContextSystem
- GlEncoderSystem
- GlGeometrySystem
- GlobalUniformSystem
- GlProgram
- GlRenderTargetSystem
- GlShaderSystem
- GlStateSystem
- GlStencilSystem
- GlTextureSystem
- GlUboSystem
- GlUniformGroupSystem
- GpuBufferSystem
- GpuColorMaskSystem
- GpuDeviceSystem
- GpuEncoderSystem
- GpuProgram
- GpuRenderTargetSystem
- GpuShaderSystem
- GpuStateSystem
- GpuStencilSystem
- GpuTextureSystem
- GpuUboSystem
- GraphicsContextSystem
- HelloSystem
- HTMLTextSystem
- InstructionSet
- PipelineSystem
- PrepareBase
- PrepareQueue
- PrepareSystem
- PrepareUpload
- RenderGroup
- RenderGroupSystem
- RenderTarget
- RenderTargetSystem
- RenderTexture
- Shader
- State
- SystemRunner
- Texture
- TextureGCSystem
- TextureMatrix
- TexturePool
- TextureSource
- TextureStyle
- UboSystem
- UniformGroup
- VideoSource
- ViewSystem
- WebGLRenderer
- WebGPURenderer
- TextureUvs
Interface Definitions
-
The attribute data for a geometries attributes
Properties:
Name Type Description bufferBuffer the buffer that this attributes data belongs to
formatVertexFormat the format of the attribute
instanceboolean is this an instanced buffer? (defaults to false)
locationnumber set where the shader location is for this attribute
offsetnumber the offset of the attribute from the buffer, defaults to 0
sizenumber The number of elements to be rendered. If not specified, all vertices after the starting vertex will be drawn.
startnumber The starting vertex in the geometry to start drawing from. If not specified, drawing will start from the first vertex.
stridenumber the stride of the data in the buffer
typenumber the type of attribute
-
Options for 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 1Transparency 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 trueWhether to clear the canvas before new render passes.
-
Options for extracting content from a renderer.
Properties:
Name Type Description antialiasboolean Whether to enable anti-aliasing. This may affect performance.
clearColorColorSource The color used to clear the extracted content.
frameRectangle The region of the target to extract.
resolutionnumber The resolution of the extracted content.
targetContainer | Texture The target to extract.
-
an interface that allows a resource to be bound to the gpu in a bind group
-
Simple bounds implementation instead of more ambiguous [number, number, number, number]
-
The options for clearing the render target.
Properties:
Name Type Description clearCLEAR_OR_BOOL The clear mode to use.
clearColorColorSource The color to clear with.
targetRenderSurface The render target to render.
-
An effect that can be applied to a container. This is used to create effects such as filters/masks etc.
-
the interface that describes the structure of the geometry
Properties:
Name Type Description attributesRecord<string, AttributesOption> the attributes that make up the geometry
indexBufferBuffer | TypedArray | number[] optional index buffer for this geometry
labelstring an optional label to easily identify the geometry
topologyTopology the topology of the geometry, defaults to 'triangle-list'
-
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.
-
Options for the WebGPU context.
Properties:
Name Type Description forceFallbackAdapterboolean Force the use of the fallback adapter
powerPreferenceGpuPowerPreference An optional hint indicating what configuration of GPU is suitable for the WebGPU context, can be
'high-performance'or'low-power'. Setting to'high-performance'will prioritize rendering performance over power consumption, while setting to'low-power'will prioritize power saving over rendering performance. -
The options for the gpu program
Properties:
Name Type Description fragmentProgramSource The fragment glsl shader source.
gpuLayoutProgramPipelineLayoutDescription The gpu layout of the program. If not provided, it will be generated from the shader sources.
layoutProgramLayout 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!
vertexProgramSource The vertex glsl shader source.
-
Options for the GraphicsContextSystem.
Properties:
Name Type Description bezierSmoothnessnumber A value from 0 to 1 that controls the smoothness of bezier curves (the higher the smoother)
-
Options for creating an image from a renderer.
Properties:
Name Type Description formatFormats The format of the image.
qualitynumber The quality of the image.
-
An instruction that can be executed by the renderer
Properties:
Name Type Description actionstring the name of the instruction
canBundleboolean true if this instruction can be compiled into a WebGPU bundle
renderPipeIdstring a the id of the render pipe that can run this instruction
-
An interface for a pipe that can be used to build instructions for the renderer. InstructionPipes are specifically used to manage the state of the renderer. For example, the BlendModePipe is used to set the blend mode of the renderer.
Properties:
Name Type Description execute(instruction: INSTRUCTION) => void this is where the actual instruction is executed - eg make the draw call activate a filter. Any instructions that have the same renderPipeId have their execute method called
pop(effect: Effect, targetContainer: Container, instructionSet: InstructionSet) => void Used by effect pipes to pop effects from the renderer.
push(effect: Effect, targetContainer: Container, instructionSet: InstructionSet) => void Used by the effect pipes push and pop effects to the renderer. A push effect allows the renderer to change its state to support the effect. A pop effect allows the renderer to return to its previous state. An example of this would be the filter effect.
renderEnd() => void Called just after the render ends giving the RenderPipes a chance to do any cleanup
renderStart() => void Called just before the render starts giving the RenderPipes a chance to do any setup
upload(instructionSet: InstructionSet) => void called just before we execute the draw calls , this is where the pipes have an opportunity to upload data to the GPU. This is only called if data changes.
-
the program source
Properties:
Name Type Description entryPointstring The main function to run in this shader
sourcestring The wgsl source code of the shader.
-
The options for rendering a view.
-
An interface for a pipe that can be used to build instructions for the renderer. RenderPipes are specifically used to render Renderables like a Mesh.
Properties:
Name Type Description addRenderable(renderable: RENDERABLE, instructionSet: InstructionSet) => void This is where the renderable is added to the instruction set. This is called once per renderable. For instance, a MeshRenderPipe could be used to enqueue a 'draw mesh' command to the rendering instruction set, catering to the rendering of mesh geometry. In more complex scenarios, such as the SpritePipe, this seamlessly coordinates with a batchPipe to efficiently batch and add batch instructions to the instructions set
Add is called when the instructions set is being built.
destroyRenderable(renderable: RENDERABLE) => void Called whenever a renderable is destroyed, often the pipes keep a webGL / webGPU specific representation of the renderable that needs to be tidied up when the renderable is destroyed.
updateRenderable(renderable: RENDERABLE, instructionSet: InstructionSet) => void Called whenever a renderable has been been updated, eg its position has changed. This is only called in the render loop if the instructions set is being reused from the last frame. Otherwise addRenderable is called.
validateRenderable(renderable: RENDERABLE) => boolean This function is called when the renderer is determining if it can use the same instruction set again to improve performance. If this function returns false, the renderer will rebuild the whole instruction set for the scene. This is only called if the scene has not its changed its structure .
-
Options for creating a render target.
Properties:
Name Type Description antialiasboolean should this render target be antialiased?
colorTexturesBindableTexture[] | number an array of textures, or a number indicating how many color textures there should be
depthboolean should this render target have a depth buffer?
depthStencilTextureBindableTexture | boolean a depth stencil texture that the depth and stencil outputs will be written to
heightnumber the height of the RenderTarget
isRootboolean is this a root element, true if this is gl context owners render target
resolutionnumber the resolution of the RenderTarget
stencilboolean should this render target have a stencil buffer?
widthnumber the width of the RenderTarget
-
Stores the width of the non-scalable borders, for example when used with NineSlicePlane texture.
Properties:
Name Type Description bottomnumber bottom border in pixels
leftnumber left border in pixels
rightnumber right border in pixels
topnumber top border in pixels
-
Options for the TextureGCSystem.
Properties:
Name Type Default Description textureGCActiveboolean trueIf set to true, this will enable the garbage collector on the GPU.
textureGCAMaxIdlenumber 60 * 60The maximum idle frames before a texture is destroyed by garbage collection.
textureGCCheckCountMaxnumber 600Frames between two garbage collections.
-
The options that can be passed to a new Texture
Properties:
Name Type Description defaultAnchor{
x: number,
y: number
}Default anchor point used for sprite placement / rotation
defaultBordersTextureBorders Default borders used for 9-slice scaling NineSlicePlane
frameRectangle The rectangle frame of the texture to show
labelstring optional label, for debugging
origRectangle The area of original texture
rotatenumber indicates how the texture was rotated by texture packer. See groupD8
sourceTextureSource the underlying texture data that this texture will use
trimRectangle Trimmed rectangle of original texture
-
options for creating a new TextureSource
Properties:
Name Type Description alphaModeALPHA_MODES the alpha mode of the texture
antialiasboolean Only really affects RenderTextures. Should we use antialiasing for this texture. It will look better, but may impact performance as a Blit operation will be required to resolve the texture.
autoGarbageCollectboolean If true, the Garbage Collector will unload this texture if it is not used after a period of time
autoGenerateMipmapsboolean Should we auto generate mipmaps for this texture? This will automatically generate mipmaps for this texture when uploading to the GPU. Mipmapped textures take up more memory, but can look better when scaled down.
For performance reasons, it is recommended to NOT use this with RenderTextures, as they are often updated every frame. If you do, make sure to call
updateMipmapsafter you update the texture.dimensionsTEXTURE_DIMENSIONS how many dimensions does this texture have? currently v8 only supports 2d
formatTEXTURE_FORMATS the format that the texture data has
heightnumber the pixel height of this texture source. This is the REAL pure number, not accounting resolution
labelstring optional label, can be used for debugging
mipLevelCountnumber The number of mip levels to generate for this texture. this is overridden if autoGenerateMipmaps is true
resolutionnumber the resolution of the texture.
resourceT the resource that will be upladed to the GPU. This is where we get our pixels from eg an ImageBimt / Canvas / Video etc
widthnumber the pixel width of this texture source. This is the REAL pure number, not accounting resolution
-
Options for video sources.
Properties:
Name Type Description alphaModeALPHA_MODES The alpha mode of the video.
autoLoadboolean If true, the video will start loading immediately.
autoPlayboolean If true, the video will start playing as soon as it is loaded.
crossoriginboolean | string If true, the video will be loaded with the
crossoriginattribute.loopboolean If true, the video will loop when it ends.
mutedboolean If true, the video will be muted.
playsinlineboolean If true, the video will play inline.
preloadboolean If true, the video will be preloaded.
preloadTimeoutMsnumber The time in milliseconds to wait for the video to preload before timing out.
updateFPSnumber The number of times a second to update the texture from the video. Leave at 0 to update at every render.
-
Options passed to the ViewSystem
Properties:
Name Type Description antialiasboolean Whether to enable anti-aliasing. This may affect performance.
autoDensityboolean Resizes renderer view in CSS pixels to allow for resolutions other than 1.
canvasICanvas The canvas to use as a view, optional.
depthboolean Whether to ensure the main view has can make use of the depth buffer. Always true for WebGL renderer.
heightnumber The height of the screen.
multiViewboolean TODO: multiView
resolutionnumber The resolution / device pixel ratio of the renderer.
viewICanvas widthnumber The width of the screen.
-
Options for WebGLRenderer.
-
The default WebGL renderer, uses WebGL2 contexts.
Properties:
Name Type Default Description accessibilityrendering.AccessibilitySystem AccessibilitySystem instance. Requires
import 'pixi.js/accessibility'.backgroundBackgroundSystem The background system manages the background color and alpha of the main view.
canvasICanvas The canvas element that everything is drawn to.
eventsrendering.EventSystem EventSystem instance.
extractExtractSystem ExtractSystem instance. Requires
import 'pixi.js/extract'.filterFilterSystem FilterSystem instance.
globalUniformsGlobalUniformSystem GlobalUniformSystem instance.
heightnumber 600Same as view.height, actual number of pixels in the canvas by vertical.
helloHelloSystem HelloSystem instance.
lastObjectRenderedContainer the last object rendered by the renderer. Useful for other plugins like interaction managers
namestring The name of the renderer.
preparePrepareSystem PrepareSystem instance. Requires
import 'pixi.js/prepare'.renderGroupRenderGroupSystem RenderGroupSystem instance.
renderingToScreenboolean trueFlag if we are rendering to the screen vs renderTexture
resolutionnumber The resolution / device pixel ratio of the renderer.
roundPixelsboolean Whether the renderer will round coordinates to whole pixels when rendering. Can be overridden on a per scene item basis.
screenRectangle Measurements of the screen. (0, 0, screenWidth, screenHeight).
Its safe to use as filterArea or hitArea for the whole stage.
texturerendering.TextureSystem TextureSystem instance.
textureGCTextureGCSystem TextureGCSystem instance.
textureGeneratorGenerateTextureSystem System that manages the generation of textures from the renderer
viewViewSystem The view system manages the main canvas that is attached to the DOM
widthnumber 800Same as view.width, actual number of pixels in the canvas by horizontal.
Members
The map of blend modes supported by Pixi
Enums
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().) |
STENCIL_MODES
The stencil operation to perform when using the stencil buffer
Type Definitions
The attribute options used by the constructor for adding geometries attributes extends Attribute but allows for the buffer to be a typed or number array
The culling mode to use. It can be either none, front or back.
Options for extracting and downloading content from a renderer.
Properties:
| Name | Type | Description |
|---|---|---|
filename |
string |
The filename to use when downloading the content. |
Options for extracting an HTMLImage from the renderer.
Options for extracting content from a renderer.
Options for generating a texture from a container.
Properties:
| Name | Type | Description |
|---|---|---|
antialias |
boolean |
Whether to enable anti-aliasing. This may affect performance. |
clearColor |
ColorSource |
The color used to clear the texture. |
frame |
Rectangle |
The region of the container, that shall be rendered, if no region is specified, defaults to the local bounds of the container. |
resolution |
number |
The resolution of the texture being generated. |
target |
Container |
The container to generate the texture from |
textureSourceOptions |
GenerateTextureSourceOptions |
The options passed to the texture source. |
a map the maps names of uniforms to group indexes
a WebGPU descriptions of how the program is layed out
A render surface is a texture, canvas, or render target
- See:
A record of BindGroup's used by the shader.
Record<number, BindGroup>
A descriptor for a shader
A descriptor for a shader with groups.
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
The different topology types supported by the renderer used to describe how the geometry should be renderer
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 |
The UVs data structure for a texture.
The different types of vertex formats supported by the renderer
Methods
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<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'
}
});
Takes a vertices array and a matrix and transforms the vertices based on the matrix. this out put is written to the uvs array
| Name | Type | Default | Description |
|---|---|---|---|
vertices |
number[] |
the vertices to calculate uvs from |
|
verticesStride |
number |
the stride of the vertice |
|
verticesOffset |
number |
the offset of the vertices |
|
uvs |
number[] |
the uvs to fill |
|
uvsOffset |
number |
the offset of the uvs |
|
uvsStride |
number |
the stride of the uvs |
|
size |
number |
the size of the vertices |
|
matrix |
Matrix | undefined |
the matrix to apply to the uvs |
Converts something into a buffer. If it is already a buffer it will pass it through if it is a number array it will convert it to a float32 array before being passed into a buffer the buffer will be created with the correct usage flags for geometry attributes
| Name | Type | Description |
|---|---|---|
buffer |
Buffer | TypedArray | number[] |
number array |
index |
boolean |
is this an index buffer? |
Returns:
| Type | Description |
|---|---|
| Buffer | a buffer |
Transforms the vertices in an array with the given matrix.
| Name | Type | Attributes | Description |
|---|---|---|---|
vertices |
number[] |
the vertices to transform |
|
m |
Matrix |
the matrix to apply to the vertices |
|
offset |
number |
<optional> |
the offset of the vertices (defaults to 0) |
stride |
number |
<optional> |
the stride of the vertices (defaults to 2) |
size |
number |
<optional> |
the size of the vertices (defaults to vertices.length / stride - offset) |