Create SRV From MediaTexture

I am using a custom compute shader which reads from a SRV.
Currently I load a still image via UTexture2D and get the FTexture2DRHIRef via

static_cast<FTexture2DResource*>(InputRgbaTexture->Resource)->GetTexture2DRHI();

from which I create a SRV using RHICreateShaderResourceView(…).

Now I want to do the same with a Media Texture, but there doesn’t seem to be a simple way to do so, if the textures sink mode is Buffered.

Using AcquireTextureSinkBuffer() to get the raw data and copying it to another Texture seems weird.

Is there a simpler way?

Perhaps you could try something like this:

FRHITexture2D* RHITexture2D = MyTexture->Resource->TextureRHI->GetTexture2D();

Each one of the dereferenced fields may be nullptr, so you have to check accordingly.

Your downcast of the resource to FTexture2DResource is never going to work, because FMediaTextureResource inherits from FTextureResource.

Ah thanks, worked perfectly! I missed the public TextureRHI of FTexture.