// Copyright (c) Wojciech Figat. All rights reserved.
#pragma once
#include "Textures/GPUTexture.h"
///
/// Utility for pooling render target resources with reusing and sharing resources during rendering.
///
API_CLASS(Static) class FLAXENGINE_API RenderTargetPool
{
DECLARE_SCRIPTING_TYPE_NO_SPAWN(RenderTargetPool);
public:
///
/// Flushes the temporary render targets.
///
/// True if release unused render targets by force, otherwise will use a few frames of delay.
/// Amount of previous frames that should persist in the pool after flush. Resources used more than given value wil be freed. Use value of -1 to auto pick default duration.
static void Flush(bool force = false, int32 framesOffset = -1);
///
/// Gets a temporary render target.
///
/// The texture description.
/// The allocated render target or reused one.
API_FUNCTION() static GPUTexture* Get(API_PARAM(Ref) const GPUTextureDescription& desc);
///
/// Releases a temporary render target.
///
/// The reference to temporary target to release.
API_FUNCTION() static void Release(GPUTexture* rt);
};
// Utility to set name to the pooled render target (compiled-put in Release builds)
#if GPU_ENABLE_RESOURCE_NAMING
#define RENDER_TARGET_POOL_SET_NAME(rt, name) rt->SetName(TEXT(name));
#else
#define RENDER_TARGET_POOL_SET_NAME(rt, name)
#endif