Skip to main content

RenderTargetProvider

Class

Controls a camera texture resource.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

Controls a camera texture resource. Can be accessed through Texture.control on a Camera texture. For more information, see the Camera and Layers guide.

Index

Extends

Properties

antialiasingMode

antialiasingMode: AntialiasingMode

The anti-aliasing technique applied on the render target.

Since

Lens Scripting Version 305

Default Value

RenderTargetProvider.AntialiasingMode.Disabled

antialiasingQuality

antialiasingQuality: AntialiasingQuality

The quality of the anti-aliasing technique applied on the render target.

Since

Lens Scripting Version 305

Default Value

RenderTargetProvider.AntialiasingQuality.X4

clearColor

clearColor: vec4

When clearColorEnabled is true and inputTexture is null, this color is used to clear this RenderTarget the first time it is drawn to each frame.

Default Value

(0, 0, 0, 1)

clearColorOption

clearColorOption: ClearColorOption

Sets the clear color option.

Since

Lens Scripting Version 141

Default Value

ClearColorOption.Background

clearDepthEnabled

clearDepthEnabled: boolean

If true, the depth buffer will be cleared on this RenderTarget the first time it is drawn to each frame.

Default Value

true

depthBufferUsage

depthBufferUsage: DepthBufferUsage

Controls the depth buffer usage strategy for this render target.

Since

Lens Scripting Version 336

Default Value

RenderTargetProvider.DepthBufferUsage.Auto

format

format: TextureFormat

The pixel format of the render target.

Assigning a different format reallocates the render target's texture, discarding its contents. Not every format is renderable on every device — assigning one that isn't throws an error, so check it first with DeviceInfoSystem#isFormatSupported.

Since

Lens Scripting Version 375

Default Value

TextureFormat.RGBA8Unorm

Example

var target = global.scene.createRenderTargetTexture();
var format = TextureFormat.RGBA16Float;
// A render target is normally sampled too, so require Filter alongside Render.
if (global.deviceInfoSystem.isFormatSupported(format, TextureUsage.Render | TextureUsage.Filter)) {
target.control.format = format;
}

inputTexture

inputTexture: Texture

When clearColorEnabled is true, this texture is used to clear this RenderTarget the first time it is drawn to each frame. If this texture is null, clearColor will be used instead.

Default Value

null

mipmapsEnabled

mipmapsEnabled: boolean

If true, mipmaps will be generated for this render target.

Default Value

false

msaaStrategy

msaaStrategy: MSAAStrategy

How MSAA should be applied on the render target.

Since

Lens Scripting Version 305

Default Value

RenderTargetProvider.MSAAStrategy.OnlyWhenRequired

outputResolution

outputResolution: OutputResolution

Controls the resolution source for this render target.

Since

Lens Scripting Version 336

Default Value

RenderTargetProvider.OutputResolution.Custom

resolution

resolution: vec2

When useScreenResolution is false, controls the horizontal and vertical resolution of the Render Target.

Default Value

(0, 0)

resolutionScale

resolutionScale: number

When Use Screen Resolution is enabled, this scales the render target resolution relative to the device resolution.

Since

Lens Scripting Version 190

Default Value

1

sliceCount

sliceCount: number

sliceCount refers to the number of slices in a texture array or 3D texture.

Since

Lens Scripting Version 336


textureType

textureType: TextureType

The texture type of the render target.

Default Value

RenderTargetProvider.TextureType.Texture2D

useScreenResolution

useScreenResolution: boolean

If true, the Render Target's resolution will match the device's screen resolution.

Default Value

false

Methods

ensureLoaded()

ensureLoaded(): Promise<void>

Returns a Promise that resolves once this Provider has finished loading its resource.

Returns

Promise<void>

Remarks

If the Provider is already loaded when ensureLoaded() is called, the returned Promise resolves immediately. Otherwise it resolves once loading completes.

Completion is determined by the Provider's load status (see Provider.getLoadStatus). Some Providers only become loaded once supporting runtime data is available — for example, a Provider whose resource depends on tracking will not report loaded until the relevant tracking data has arrived — so the returned Promise stays pending until that data is produced.

This method is useful when Lens script needs to await a Provider before reading its data — for example, waiting for a remote-asset Provider to finish downloading before sampling it.

Since

Lens Scripting Version 370

Example

Fetch a Texture at runtime via RemoteMediaModule and wait for its Provider to finish loading before using it:

const internetModule = require("LensStudio:InternetModule");
const remoteMediaModule = require("LensStudio:RemoteMediaModule");

function loadImageTexture(url) {
const resource = internetModule.makeResourceFromUrl(url);
return new Promise((resolve, reject) => {
remoteMediaModule.loadResourceAsImageTexture(resource, resolve, reject);
});
}

const texture = await loadImageTexture("https://example.com/image.png");

// Wait until the fetched Texture's Provider has finished loading before using it.
await texture.control.ensureLoaded();
print("Texture ready, loadStatus: " + texture.control.getLoadStatus());

Inherited from

TextureProvider.ensureLoaded


getAspect()

getAspect(): number

Returns the texture's aspect ratio, which is calculated as width / height.

Returns

number

Inherited from

TextureProvider.getAspect


getHeight()

getHeight(): number

Returns the height of the texture in pixels.

Returns

number

Inherited from

TextureProvider.getHeight


getLoadStatus()

getLoadStatus(): LoadStatus

Returns

LoadStatus

Inherited from

TextureProvider.getLoadStatus


getTypeName()

static getTypeName(): TypeName<RenderTargetProvider>

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<RenderTargetProvider>

Overrides

TextureProvider.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

TextureProvider.getTypeName


getWidth()

getWidth(): number

Returns the width of the texture in pixels.

Returns

number

Inherited from

TextureProvider.getWidth


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

TextureProvider.isOfType


isSame()

isSame(other): boolean

Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

TextureProvider.isSame

Nested types

Enumerations

EnumerationDescription
AntialiasingModeThe anti-aliasing technique to use on a render target.
AntialiasingQualityThe fidelity of the anti-aliasing technique to apply.
DepthBufferUsageControls depth buffer usage strategy for the render target.
MSAAStrategyHow MSAA should be applied to the render target.
OutputResolutionControls the resolution source for the render target.
TextureTypeSpecifies what kind of render target it is. Some texture types, for example TextureCubemap, need additional properties set on the rendering camera to work correctly.