How to read data from a UTexture2D in C++

僤鯓⒐⒋嵵緔 提交于 2019-12-04 19:35:02

I figured that out. You have to get the UTexture2D's RHI texture reference first, and then use RHILockTexture2D to read it's data, and you have to do it in the RenderThread. The following code just an example:

FTexture2DResource* uTex2DRes = (FTexture2DResource*)(RealSenseDelegator->VideoTexturePixelDepth)->Resource;
float* cpuDataPtr = (float*)RHILockTexture2D(
        uTex2DRes->GetTexture2DRHI(),
        0,
        RLM_ReadOnly,
        destStride,
        false);

for (uint32 j = 0; j < 480; j++) {
    for (uint32 i = 0; i < 640; i++) {
        uint32 idx = j * 640 + i;

        // TODO Read the pixel data right here

    }
}
RHIUnlockTexture2D(uTex2DRes->GetTexture2DRHI(), 0, false);

To do this in the Render Thread, you have to use the Macro such as ENQUEUE_UNIQUE_RENDER_COMMAND_ONEPARAMETER // If you just one to pass one parameter to the render thread, use this one.+

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!