Table Of Contents

Previous topic

20.1. The TextureEncode Object

Next topic

20.3. The ParticleBuilder Object

This Page

20.2. The SharedRenderContext Object

Added SDK 0.28.0

The SharedRenderContext object provides a utility for handling the sharing of particle state textures, and mapping table textures between many particle systems.

The context can be used to allocate new regions of the double-buffered renderable textures required by a ParticleSystem and a ParticleView which is z-sorted.

This object does not expose any way of releasing previously allocated regions, as the underlying allocation algorithm (OnlineTexturePacker) does not support this. The intention is that these shared textures are used where systems are either permanent, or short-lived and recycled.


This is a low-level particle system API.

20.2.1. Methods create


Create a new SharedRenderContext object.


var sharedRenderContext = SharedRenderContext.create({
    graphicsDevice: graphicsDevice
}); allocate


Allocate a new region of the shared textures. May return null in the case that an attempt is made to allocate a texture region larger than is supported by the GraphicsDevice.


function setCallbackFn(newRegion)
    // The shared render context was resized by some later allocations
    // and the uvRectangle and renderTargets have been changed.
    // .. handle changes here.
var region = sharedRenderContext.allocate({
    width: 64,
    height: 64,
    set: setCallbackFn
var renderTargets = region.renderTargets;
var uvRectangle = region.uvRectangle;
The width of the region required.
The height of the region required.
A function to be called when resizing the shared textures from which the region was allocated, and the uv-rectangle of the region has changed.

The region object returned has the following fields:

The pair of RenderTargets representing the double buffer texture store region is allocated from.
A Vector4 object representing the texture coordinate rectangle of the region in the shared textures. This is of the form [x0, y0, x1, y1] in normalize coordinates. release


Release an allocated region for re-use.


The intention is that these shared textures are used where systems are either permanent, or short-lived and recycled. The underlying algorithm responsible for allocating regions does not perform any defragmentation or merging of free regions, and as such releasing an allocated region should be done with care.


The region returned by allocate, or passed to the set callback. destroy


Destroy all render targets and textures owned by this shared context. The shared context, nor any of its previously allocated regions can be used following this call.