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.
Implements
Inherited Members
Namespace: PopcorningGuineaPig.Engine.Services
Assembly: PopcorningGuineaPig.Engine.dll
Syntax
public sealed class RenderTexturePool : IDisposable
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
| Edit this page View SourceRenderTexturePool()
Constructs a pool with the default per-key retention bound and the production Raylib load/unload paths.
Declaration
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.
Declaration
public RenderTexturePool(int maxPerKey)
Parameters
| Type | Name | Description |
|---|---|---|
| int | maxPerKey | Maximum retained render textures per (w, h, format) key. Must be at least 1. |
Fields
| Edit this page View SourceDefaultMaxPerKey
Default maximum retained render textures per (width, height, format) key.
Declaration
public const int DefaultMaxPerKey = 4
Field Value
| Type | Description |
|---|---|
| int |
Properties
| Edit this page View SourceRetainedBytes
Approximate retained bytes across all idle render textures. Reset to 0 after Dispose().
Declaration
public long RetainedBytes { get; }
Property Value
| Type | Description |
|---|---|
| long |
RetainedCount
Number of idle render textures currently parked in the pool.
Declaration
public int RetainedCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
TotalAcquires
Cumulative Acquire(int, int) calls since construction.
Declaration
public int TotalAcquires { get; }
Property Value
| Type | Description |
|---|---|
| int |
TotalEvictions
Cumulative Release(RenderTexture2D) calls that unloaded the returned texture because the pool was at its retention bound.
Declaration
public int TotalEvictions { get; }
Property Value
| Type | Description |
|---|---|
| int |
TotalReuses
Cumulative Acquire(int, int) calls that returned a pooled instance instead of allocating.
Declaration
public int TotalReuses { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
| Edit this page View SourceAcquire(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).
Declaration
public RenderTexture2D Acquire(int width, int height)
Parameters
| Type | Name | Description |
|---|---|---|
| int | width | Pixel width. Must be positive. |
| int | height | Pixel height. Must be positive. |
Returns
| Type | Description |
|---|---|
| RenderTexture2D | An RT whose internal |
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.
Declaration
public void Clear()
Dispose()
Disposes the pool and unloads every retained render texture. Releases after dispose unload immediately without re-entering the dispose path.
Declaration
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.
Declaration
public void Release(RenderTexture2D renderTexture)
Parameters
| Type | Name | Description |
|---|---|---|
| RenderTexture2D | renderTexture | The render texture to return. Must have a non-zero |