Overview
Unreal textures in the UI
Prysm allows you to render textures managed by Unreal directly in the UI. This enables you to achieve some pretty amazing effects e.g. using the Material Editor to change how a texture looks on screen. Both static and dynamic textures are supported.
Here you can find more details on all the types of textures that are supported:
- PreloadedTextures - This feature allows you to preload textures before the UI is rendered, which decreases its loading time
- LiveViews - Allows the embedding of dynamic textures, rendered by Unreal, inside your UI
- TextureAtlasing - Allows you to pack multiple Unreal textures, used in your UI, in one larger texture
- StreamingTextures - Read more about how we handle streaming texture resource requests
Texture lifetime management
Unreal textures that will be rendered by Prysm need to have their lifetime properly managed, as the engine has many mechanisms (like garbage collection, mip level streaming and more) that can invalidate a given texture before it reaches the Prysm rendering plugin for processing.
For this reason, Prysm will always keep an extra reference to the UTexture
’s FTexture2DRHIRef
, in order to keep it from being destroyed while it is in use by the UI.
Generally, this is how this is handled:
- Prysm receives a resource request for a texture and won’t reply to it until it has successfully cached the
UTexture
’sFTexture2DRHIRef
- After that, the
FTexture2DRHIRef
, along with the actualUTexture
, will be stored in ourFCohTexture
and picked up by aFCohTextureCollector
for preservation, until it is internally processed and forwarded to the Prysm rendering backend classFCohRenoirBackend
(which will happen on the render thread)- If during this time a UI element changes its texture or the UI element gets removed, such that the texture is no longer needed, a special
OnUserImageDropped
event will be fired, which will signal theFCohTextureCollector
to remove the specificFCohTexture
so that the memory is released
- If during this time a UI element changes its texture or the UI element gets removed, such that the texture is no longer needed, a special
- At some point, the
FCohRenoirBackend
will receive aWrapUserTexture
command, where ownership of theFCohTexture
will be transferred from theFCohTextureCollector
to the backend’s internal texture collection - At a later point, the
FCohRenoirBackend
will receive a command for binding all textures in its collection - Textures in the
FCohRenoirBackend
collections get removed in these cases:- Receiving a
DestroyTexture
command- Can happen if a UI element changes its texture or the element itself gets removed
- Destroying a
View
- Uninitializing the Prysm
System
- Receiving a
Events
The Prysm Unreal Engine plugin provides two single non-dynamic delegates that allow for custom logic to be implemented for textures that will be used in the UI:
- Upon the
FCohTextureCollector
collecting a texture, right before a Prysm resource request will be signaled as “successful”FCohTextureCollector::OnCohTextureCollected
(executed on the Game or async thread)
- Upon reaching the
FCohRenoirBackend
after aWrapUserTexture
commandIRenderingBackend::OnWrapUserTexture
(executed on the render thread)