Class RenderTexturePool
Bounded pool of Raylib_cs.RenderTexture2D instances keyed by
(width, height, format). Returning a render texture parks it in the pool
(up to the per-key retention bound) so the next Acquire(int, int) with the
same key reuses the GPU handle instead of paying the
Raylib.LoadRenderTexture + Raylib.UnloadRenderTexture churn.
public sealed class RenderTexturePool : IDisposable
- Inheritance
-
RenderTexturePool
- Implements
- Inherited Members
Remarks
Designed for the editor's transient render-target paths — hover previews,
thumbnail rendering, on-demand effect passes. Long-lived viewport render
targets (SceneViewportTile, AnimatedModelPreviewTile) keep
owning their own RTs and use resize-on-demand because they're sized to the
viewport and rarely freed during a session.
Thread contract: single-threaded — Raylib's resource APIs are not safe to call concurrently. Acquire/Release/Dispose must execute on the main thread between frames, like every other Raylib resource holder in this codebase.
Constructors
RenderTexturePool()
Constructs a pool with the default per-key retention bound and the production Raylib load/unload paths.
public RenderTexturePool()
RenderTexturePool(int)
Constructs a pool with a custom retention bound. Use a small bound for the editor's hover/thumbnail paths (default 4) and larger for synthetic stress tests.
public RenderTexturePool(int maxPerKey)
Parameters
maxPerKeyintMaximum retained render textures per (w, h, format) key. Must be at least 1.
Fields
DefaultMaxPerKey
Default maximum retained render textures per (width, height, format) key.
public const int DefaultMaxPerKey = 4
Field Value
Properties
RetainedBytes
Approximate retained bytes across all idle render textures. Reset to 0 after Dispose().
public long RetainedBytes { get; }
Property Value
RetainedCount
Number of idle render textures currently parked in the pool.
public int RetainedCount { get; }
Property Value
TotalAcquires
Cumulative Acquire(int, int) calls since construction.
public int TotalAcquires { get; }
Property Value
TotalEvictions
Cumulative Release(RenderTexture2D) calls that unloaded the returned texture because the pool was at its retention bound.
public int TotalEvictions { get; }
Property Value
TotalReuses
Cumulative Acquire(int, int) calls that returned a pooled instance instead of allocating.
public int TotalReuses { get; }
Property Value
Methods
Acquire(int, int)
Returns a render texture matching the requested dimensions. Reuses a pooled
instance when one is available; otherwise allocates a fresh one via
Raylib.LoadRenderTexture. Always pair with Release(RenderTexture2D).
public RenderTexture2D Acquire(int width, int height)
Parameters
Returns
- RenderTexture2D
An RT whose internal
Texture.Width/Texture.Heightmatch the requested dimensions.
Clear()
Drops every idle render texture, unloading each. Useful when a project closes or the editor wants to release retained GPU memory without disposing the pool.
public void Clear()
Dispose()
Disposes the pool and unloads every retained render texture. Releases after dispose unload immediately without re-entering the dispose path.
public void Dispose()
Release(RenderTexture2D)
Returns a previously-acquired render texture to the pool. Parks it for reuse up to the configured per-key bound; further releases past the bound unload the texture immediately.
public void Release(RenderTexture2D renderTexture)
Parameters
renderTextureRenderTexture2DThe render texture to return. Must have a non-zero
Id.