Skip to content

Class RenderTargetPool

Definition

Namespace: StardewUI.Graphics
Assembly: StardewUI.dll

Pools RenderTarget2D instances so they can be reused across multiple frames.

public class RenderTargetPool : System.IDisposable

Inheritance
Object ⇦ RenderTargetPool

Implements
IDisposable

Remarks

Targets are pooled by their size, since render targets have a fixed size and changing the size requires recreating the target. The pooled targets are considered to be managed by the pool, and are disposed along with the pool itself; typically a pool is associated with some long-lived UI object such as a menu, and then assigned to a transient instance like PropagatedSpriteBatch.

Pools can be configured with a slack in order to increase long-term reuse at the expense of higher transient memory and/or VRAM usage due to the extra targets; these may be several megabytes if the areas to be captured are large. Slack can help accommodate dynamic views, e.g. different tabs with different scroll sizes, but should be used conservatively to avoid keeping long-dead targets.

The pool is effectively unbounded in the number of instances it can create, but once slack is exceeded, it will dispose an old instance before creating a new one, starting with the instance having the largest pixel size (i.e. taking up the most memory).

Members

Constructors

Name Description
RenderTargetPool(GraphicsDevice, Int32) Pools RenderTarget2D instances so they can be reused across multiple frames.

Methods

Name Description
Acquire(Int32, Int32, RenderTarget2D) Obtains a pooled target with the specified dimensions, or creates a new target if there is no usable pooled instance.
Dispose()

Details

Constructors

RenderTargetPool(GraphicsDevice, int)

Pools RenderTarget2D instances so they can be reused across multiple frames.

public RenderTargetPool(Microsoft.Xna.Framework.Graphics.GraphicsDevice graphicsDevice, int slack);
Parameters

graphicsDevice   GraphicsDevice
The graphics device used for rendering.

slack   Int32
Specifies the maximum number of unused pooled render targets to keep, when requesting a new target whose size is not in the pool, before disposing an older target.

Remarks

Targets are pooled by their size, since render targets have a fixed size and changing the size requires recreating the target. The pooled targets are considered to be managed by the pool, and are disposed along with the pool itself; typically a pool is associated with some long-lived UI object such as a menu, and then assigned to a transient instance like PropagatedSpriteBatch.

Pools can be configured with a slack in order to increase long-term reuse at the expense of higher transient memory and/or VRAM usage due to the extra targets; these may be several megabytes if the areas to be captured are large. Slack can help accommodate dynamic views, e.g. different tabs with different scroll sizes, but should be used conservatively to avoid keeping long-dead targets.

The pool is effectively unbounded in the number of instances it can create, but once slack is exceeded, it will dispose an old instance before creating a new one, starting with the instance having the largest pixel size (i.e. taking up the most memory).


Methods

Acquire(int, int, RenderTarget2D)

Obtains a pooled target with the specified dimensions, or creates a new target if there is no usable pooled instance.

public System.IDisposable Acquire(int width, int height, out Microsoft.Xna.Framework.Graphics.RenderTarget2D target);
Parameters

width   Int32
The target's pixel width.

height   Int32
The target's pixel height.

target   RenderTarget2D
Receives the pooled or created RenderTarget2D which has the specified width and height.

Returns

IDisposable

An IDisposable instance which, when disposed, will release the target back to the pool, without disposing the target itself.


Dispose()

public void Dispose();