Class: BaseRenderTexture

PIXI.BaseRenderTexture

A BaseRenderTexture is a special texture that allows any PixiJS display object to be rendered to it.

Hint: All DisplayObjects (i.e. Sprites) that render to a BaseRenderTexture should be preloaded otherwise black rectangles will be drawn instead.

A BaseRenderTexture takes a snapshot of any Display Object given to its render method. The position and rotation of the given Display Objects is ignored. For example:

new PIXI.BaseRenderTexture (options) overrides

Name Type Attributes Default Description
options IBaseTextureOptions
options.width number <optional>
100

The width of the base render texture.

options.height number <optional>
100

The height of the base render texture.

options.scaleMode PIXI.SCALE_MODES <optional>
PIXI.BaseTexture.defaultOptions.scaleMode

See PIXI.SCALE_MODES for possible values.

options.resolution number <optional>
PIXI.settings.RESOLUTION

The resolution / device pixel ratio of the texture being generated.

options.multisample PIXI.MSAA_QUALITY <optional>
PIXI.MSAA_QUALITY.NONE

The number of samples of the frame buffer.

Example

 import { autoDetectRenderer, BaseRenderTexture, RenderTexture, Sprite } from 'pixi.js';

 const renderer = autoDetectRenderer();
 const baseRenderTexture = new BaseRenderTexture({ width: 800, height: 600 });
 const renderTexture = new RenderTexture(baseRenderTexture);
 const sprite = Sprite.from('spinObj_01.png');

 sprite.position.x = 800 / 2;
 sprite.position.y = 600 / 2;
 sprite.anchor.x = 0.5;
 sprite.anchor.y = 0.5;

 renderer.render(sprite, { renderTexture });

 // The Sprite in this case will be rendered using its local transform.
 // To render this sprite at 0,0 you can clear the transform
 sprite.setTransform();

 const baseRenderTexture = new BaseRenderTexture({ width: 100, height: 100 });
 const renderTexture = new RenderTexture(baseRenderTexture);

 renderer.render(sprite, { renderTexture }); // Renders to center of RenderTexture

Extends

Members

clear PIXI.Color readonly

Color object when clearning the texture.

Since:
  • 7.2.0

clearColor PIXI.ColorSource

Color when clearning the texture.

filterStack Array<any>

The data structure for the filters.

framebuffer PIXI.Framebuffer readonly

The framebuffer of this base texture.

maskStack Array<PIXI.MaskData>

The data structure for the stencil masks.

multisample PIXI.MSAA_QUALITY

Shortcut to this.framebuffer.multisample.

Default Value:
  • PIXI.MSAA_QUALITY.NONE

_canvasRenderTarget PIXI.utils.CanvasRenderTarget protected

A reference to the canvas render target (we only need one as this can be shared across renderers)

Default Value:
  • undefined

Methods

Destroys this texture.

Frees the texture and framebuffer from WebGL memory without destroying this texture object. This means you can still use the texture later which will upload it to GPU memory again.

Fires:

resize (desiredWidth, desiredHeight) void

Resizes the BaseRenderTexture.

Name Type Description
desiredWidth number

The desired width to resize to.

desiredHeight number

The desired height to resize to.

Inherited Properties

From class PIXI.BaseTexture

_batchEnabled number inherited

Number of the texture batch, used by multi-texture renderers

_batchLocation number inherited

Location inside texture batch, used by multi-texture renderers

How to treat premultiplied alpha, see PIXI.ALPHA_MODES.

Default Value:
  • PIXI.ALPHA_MODES.UNPACK

anisotropicLevel number inherited

Anisotropic filtering level of texture

Default Value:
  • 0

cacheId string inherited

Currently default cache ID.

destroyed boolean readonly inherited

Flag if BaseTexture has been destroyed.

dirtyId number readonly inherited

Used by TextureSystem to only update texture to the GPU when needed. Please call update() to increment it.

The pixel format of the texture

Default Value:
  • PIXI.FORMATS.RGBA

height number readonly inherited

The height of the base texture set when the image has loaded

isPowerOfTwo boolean readonly inherited

Whether or not the texture is a power of two, try to use power of two textures as much as you can

Default Value:
  • false

Mipmap mode of the texture, affects downscaled images

Default Value:
  • PIXI.MIPMAP_MODES.POW2

parentTextureArray PIXI.BaseTexture inherited

Whether its a part of another texture, handled by ArrayResource or CubeResource

realHeight number readonly inherited

Pixel height of the source of this texture

realWidth number readonly inherited

Pixel width of the source of this texture

resolution number readonly inherited

The resolution / device pixel ratio of the texture

Default Value:
  • PIXI.settings.RESOLUTION

resource PIXI.Resource readonly inherited

The resource used by this BaseTexture, there can only be one resource per BaseTexture, but textures can share resources.

The scale mode to apply when scaling this texture

Default Value:
  • PIXI.SCALE_MODES.LINEAR

The target type

Default Value:
  • PIXI.TARGETS.TEXTURE_2D

textureCacheIds Array<string> readonly inherited

The collection of alternative cache ids, since some BaseTextures can have more than one ID, short name and longer full URL

The type of resource data

Default Value:
  • PIXI.TYPES.UNSIGNED_BYTE

valid boolean readonly inherited

Generally speaking means when resource is loaded.

width number readonly inherited

The width of the base texture set when the image has loaded

How the texture wraps

Default Value:
  • PIXI.WRAP_MODES.CLAMP

dirtyStyleId number protected inherited

Used by TextureSystem to only update texture style when needed.

touched number protected inherited

Used by automatic texture Garbage Collection, stores last GC tick when it was bound

uid number protectedreadonly inherited

Global unique identifier for this BaseTexture

Inherited Methods

From class PIXI.BaseTexture

Utility function for BaseTexture|Texture cast.

Returns:
Type Description
PIXI.BaseTexture

Get the drawable source, such as HTMLCanvasElement or HTMLImageElement suitable for rendering with CanvasRenderer. Provided by @pixi/canvas-renderer package.

Returns:
Type Description
PIXI.ICanvasImageSource Source to render with CanvasRenderer

setRealSize (realWidth, realHeight, resolution) this inherited

Sets real size of baseTexture, preserves current resolution.

Name Type Attributes Description
realWidth number

Full rendered width

realHeight number

Full rendered height

resolution number <optional>

Optionally set resolution

Returns:
Type Description
this
  • this

setResolution (resolution) this inherited

Changes resolution

Name Type Description
resolution number

res

Returns:
Type Description
this
  • this

setResource (resource) this inherited

Sets the resource if it wasn't set. Throws error if resource already present

Name Type Description
resource R

that is managing this BaseTexture

Returns:
Type Description
this
  • this

setSize (desiredWidth, desiredHeight, resolution) this inherited

Changes w/h/resolution. Texture becomes valid if width and height are greater than zero.

Name Type Attributes Description
desiredWidth number

Desired visual width

desiredHeight number

Desired visual height

resolution number <optional>

Optionally set resolution

Returns:
Type Description
this
  • this

setStyle (scaleMode, mipmap) this inherited

Changes style options of BaseTexture

Name Type Attributes Description
scaleMode PIXI.SCALE_MODES <optional>

Pixi scalemode

mipmap PIXI.MIPMAP_MODES <optional>

enable mipmaps

Returns:
Type Description
this
  • this

update () void inherited

Invalidates the object. Texture becomes valid if width and height are greater than zero.

Inherited Events

From class PIXI.BaseTexture

Fired when a not-immediately-available source fails to load.

Name Type Description
baseTexture PIXI.BaseTexture

Resource errored.

event ErrorEvent

Load error event.

Fired when a not-immediately-available source finishes loading.

Name Type Description
baseTexture PIXI.BaseTexture

Resource loaded.

Fired when BaseTexture is updated.

Name Type Description
baseTexture PIXI.BaseTexture

Instance of texture being updated.