MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Get

Method Get

Source/Engine/Graphics/RenderTargetPool.cpp:48–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48GPUTexture* RenderTargetPool::Get(const GPUTextureDescription& desc)
49{
50 PROFILE_CPU();
51
52 // Initialize render targets with pink color in debug builds to prevent incorrect data usage (GPU doesn't clear texture upon creation)
53#if BUILD_DEBUG && PLATFORM_DESKTOP
54 #define RENDER_TARGET_POOL_CLEAR() if (desc.Dimensions == TextureDimensions::Texture && EnumHasAllFlags(desc.Flags, GPUTextureFlags::RenderTarget) && GPUDevice::Instance->IsRendering() && IsInMainThread()) GPUDevice::Instance->GetMainContext()->Clear(e.RT->View(), Color::Pink);
55#else
56 #define RENDER_TARGET_POOL_CLEAR()
57#endif
58
59 // Find free render target with the same properties
60 const uint32 descHash = GetHash(desc);
61 for (int32 i = 0; i < TemporaryRTs.Count(); i++)
62 {
63 auto& e = TemporaryRTs[i];
64 if (!e.IsOccupied && e.DescriptionHash == descHash)
65 {
66 // Mark as used
67 e.IsOccupied = true;
68 RENDER_TARGET_POOL_CLEAR();
69 return e.RT;
70 }
71 }
72#if !BUILD_RELEASE
73 if (TemporaryRTs.Count() > 2000)
74 {
75 LOG(Fatal, "Too many textures allocated in RenderTargetPool. Know your limits, sir!");
76 return nullptr;
77 }
78#endif
79
80 // Create new rt
81 const String name = TEXT("TemporaryRT_") + StringUtils::ToString(TemporaryRTs.Count());
82 GPUTexture* rt = GPUDevice::Instance->CreateTexture(name);
83 if (rt->Init(desc))
84 {
85 Delete(rt);
86 LOG(Error, "Cannot create temporary render target. Description: {0}", desc.ToString());
87 return nullptr;
88 }
89
90 // Create temporary rt entry
91 Entry e;
92 e.IsOccupied = true;
93 e.LastFrameReleased = 0;
94 e.RT = rt;
95 e.DescriptionHash = descHash;
96 TemporaryRTs.Add(e);
97 RENDER_TARGET_POOL_CLEAR();
98
99#undef RENDER_TARGET_POOL_CLEAR
100 return rt;
101}
102
103void RenderTargetPool::Release(GPUTexture* rt)
104{

Callers 10

WriteReserveFunction · 0.45
SetNameMethod · 0.45
DrawAllMethod · 0.45
OnCollectDrawCallsMethod · 0.45
FlushMethod · 0.45
RunMethod · 0.45
BlendWithMethod · 0.45
HasContentLoadedMethod · 0.45
RenderTask.hFile · 0.45

Calls 8

DeleteFunction · 0.85
GetHashFunction · 0.70
ToStringFunction · 0.70
CountMethod · 0.45
CreateTextureMethod · 0.45
InitMethod · 0.45
ToStringMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected