mirror of
https://github.com/sinbad/StevesUEHelpers.git
synced 2025-02-23 17:45:23 +00:00
Implement ReserveTexture
This commit is contained in:
parent
642c8d2781
commit
6b947b6906
@ -18,8 +18,28 @@ void FStevesTextureRenderTargetPool::ReleaseTextureReservation(UTextureRenderTar
|
|||||||
FStevesTextureRenderTargetReservationPtr FStevesTextureRenderTargetPool::ReserveTexture(FIntPoint Size,
|
FStevesTextureRenderTargetReservationPtr FStevesTextureRenderTargetPool::ReserveTexture(FIntPoint Size,
|
||||||
ETextureRenderTargetFormat Format, const UObject* Owner)
|
ETextureRenderTargetFormat Format, const UObject* Owner)
|
||||||
{
|
{
|
||||||
// TODO
|
const FTextureKey Key {Size, Format};
|
||||||
return MakeShared<FStevesTextureRenderTargetReservation>(nullptr, this->AsShared());
|
UTextureRenderTarget2D* Tex = nullptr;
|
||||||
|
if (auto Pooled = UnreservedTextures.Find(Key))
|
||||||
|
{
|
||||||
|
Tex = *Pooled;
|
||||||
|
UnreservedTextures.RemoveSingle(Key, Tex);
|
||||||
|
}
|
||||||
|
else if (Size.X > 0 && Size.Y > 0)
|
||||||
|
{
|
||||||
|
// No existing texture, so create
|
||||||
|
// Texture owner should be a valid UObject that will determine lifespan
|
||||||
|
UObject* TextureOwner = PoolOwner.IsValid() ? PoolOwner.Get() : GetTransientPackage();
|
||||||
|
Tex = NewObject<UTextureRenderTarget2D>(TextureOwner);
|
||||||
|
Tex->RenderTargetFormat = Format;
|
||||||
|
Tex->InitAutoFormat(Size.X, Size.Y);
|
||||||
|
Tex->UpdateResourceImmediate(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Record reservation
|
||||||
|
Reservations.Add(FReservationInfo(Key, Owner, Tex));
|
||||||
|
|
||||||
|
return MakeShared<FStevesTextureRenderTargetReservation>(Tex, this->AsShared(), Owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FStevesTextureRenderTargetPool::RevokeReservations(const UObject* ForOwner)
|
void FStevesTextureRenderTargetPool::RevokeReservations(const UObject* ForOwner)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user