the desired width of the canvas
the desired height of the canvas
The attributes to create both the canvas and context
OptionalantiAlias?: booleanWhether to enable anti-aliasing, use false (default) for a pixelated effect.
Optionalcontext?: stringthe context type to be created ("2d", "webgl" — a "webgl" request creates a WebGL 2 context — or "webgpu")
OptionaloffscreenCanvas?: booleanwill create an offscreenCanvas if true instead of a standard canvas
Optionaltransparent?: booleanspecify if the canvas contains an alpha channel
OptionalwillReadFrequently?: booleanIndicates whether or not a lot of read-back operations are planned
The WebGL version of the created context.
The height of this canvas texture in pixels
The height of this render target in pixels.
The width of this canvas texture in pixels
The width of this render target in pixels.
Bind this render target as the active draw destination. All subsequent draw calls will render into this target until unbind is called. No-op by default: only the GPU renderers' own targets override it.
Clears the content of the canvas texture
Release this render target: its canvas, and the copy of it the renderer uploaded to the GPU. It must not be used afterwards.
Optionalrenderer: Renderer
the renderer it was drawn with, so the copy uploaded to the GPU is freed too
Returns an ImageData object representing the underlying pixel data for a specified portion of this canvas texture.
(Note: when using getImageData(), it is highly recommended to use the willReadFrequently attribute when creating the corresponding canvas texture)
The x-axis coordinate of the top-left corner of the rectangle from which the ImageData will be extracted
The y-axis coordinate of the top-left corner of the rectangle from which the ImageData will be extracted
The width of the rectangle from which the ImageData will be extracted. Positive values are to the right, and negative to the left
The height of the rectangle from which the ImageData will be extracted. Positive values are down, and negative are up
The ImageData extracted from this CanvasRenderTarget.
invalidate the current CanvasRenderTarget, and force a reupload of the corresponding texture (call this if you modify the canvas content between two draw calls)
the renderer to which this canvas texture is attached
Resizes the canvas texture to the given width and height.
the desired width
the desired height
enable/disable image smoothing (scaling interpolation)
Optionalenable: boolean = false
whether to enable or not image smoothing (scaling interpolation)
Creates a Blob directly from the canvas (avoids the getImageData round-trip).
Optionaltype: string = "image/png"
A string indicating the image format
Optionalquality: number
A number between 0 and 1 for lossy formats (image/jpeg, image/webp)
A Promise resolving to a Blob
Returns a data URL directly from the canvas (avoids the getImageData/Blob round-trip). Note: not supported by OffscreenCanvas — falls back to the base implementation.
Optionaltype: string = "image/png"
A string indicating the image format
Optionalquality: number
A number between 0 and 1 for lossy formats (image/jpeg, image/webp)
A Promise resolving to a data URL string
Creates an ImageBitmap directly from the canvas (avoids the getImageData round-trip).
A Promise resolving to an ImageBitmap
Read back pixel data from this render target.
The canvas backend can read back synchronously, so this resolves immediately; it exists so code that must work on every backend has one method to call. See RenderTarget#toImageData.
Optionalx: number
x coordinate of the top-left corner
Optionaly: number
y coordinate of the top-left corner
Optionalwidth: number
width of the area to read
Optionalheight: number
height of the area to read
the pixel data
Unbind this render target, restoring the default (screen) output. No-op by default: only the GPU renderers' own targets override it.
A 2D canvas render target: draw into it once and reuse it, as a texture, a baked background or a fog map. Make one and keep it rather than making a new one each time. The engine uses it too, for text, gradients, particle textures and tinted images. Drawn with the WebGL or WebGPU renderer, its canvas is uploaded to the GPU, and uploaded again after CanvasRenderTarget#invalidate.