How to use ENQUEUE RENDER COMMAND

I would like to convert old code (from 4.26 to 4.27) but this code contains something removed in 4.27 of Unreal Engine.

/* OLD CODE */
ENQUEUE_UNIQUE_RENDER_COMMAND_TWOPARAMETER(
			UpdateTextureRegionsData,
			FUpdateTextureRegionsData*, RegionData, RegionData,
			bool, bFreeData, bFreeData,
			{
			for (uint32 RegionIndex = 0; RegionIndex < RegionData->NumRegions; ++RegionIndex)
			{
				int32 CurrentFirstMip = RegionData->Texture2DResource->GetCurrentFirstMip();
				if (RegionData->MipIndex >= CurrentFirstMip)
				{
					RHIUpdateTexture2D(
						RegionData->Texture2DResource->GetTexture2DRHI(),
						RegionData->MipIndex - CurrentFirstMip,
						RegionData->Regions[RegionIndex],
						RegionData->SrcPitch,
						RegionData->SrcData
						+ RegionData->Regions[RegionIndex].SrcY * RegionData->SrcPitch
						+ RegionData->Regions[RegionIndex].SrcX * RegionData->SrcBpp
						);
				}
			}
			if (bFreeData)
			{
				FMemory::Free(RegionData->Regions);
				FMemory::Free(RegionData->SrcData);
			}
			delete RegionData;
		});

I’m trying to convert this part of code especially. This is what I have now.

/* NEW CODE */
ENQUEUE_RENDER_COMMAND(UpdateTextureRegionsData)(
			[RegionData, bFreeData, Texture](FRHICommandListImmediate& RHICmdList)
			{
				for (uint32 RegionIndex = 0; RegionIndex < RegionData->NumRegions; ++RegionIndex)
				{
					int32 CurrentFirstMip = Texture->FirstResourceMemMip;
					if (RegionData->MipIndex >= CurrentFirstMip)
					{
						RHIUpdateTexture2D(
							RegionData->Texture2DResource->GetTexture2DRHI(), //THIS LINE PROVIDES ME AN ERROR
							RegionData->MipIndex - CurrentFirstMip,
							RegionData->Regions[RegionIndex],
							RegionData->SrcPitch,
							RegionData->SrcData
							+ RegionData->Regions[RegionIndex].SrcY * RegionData->SrcPitch
							+ RegionData->Regions[RegionIndex].SrcX * RegionData->SrcBpp
						);
					}
				}
				if (bFreeData) {
					FMemory::Free(RegionData->Regions);
					FMemory::Free(RegionData->SrcData);
				}
				delete RegionData;
			});

The fact is the method GetTexture2DRHI seems not existing anymore under Texture2DResource so I can’t convert properly the old code to new one.

How could I get the Texture2DRHI from Texture2DResource ?

Thanks

1 Like

Hi dorlan.nicolas,

It looks like it’s still in there (TextureResource.h, line 105) and the UE4.27 code is still referencing it - what is the error message?

1 Like

Hi, thanks for replying.

RegionData->Texture2DResource->GetTexture2DRHI(),
int32 CurrentFirstMip = RegionData->Texture2DResource->GetCurrentFirstMip();

Texture2DResource has no member GetCurrentFirstMip() and GetTexture2DRHI().

These are my errors.

1 Like

using dorian’s code; GetTexture2DRHI() exists but is returning nullptr for me

I got my answer from here
how-to-use-enqueue-render-command-in-4-27

basically replace - RegionData->Texture2DResource->GetTexture2DRHI()
with - exture->Resource->GetTexture2DRHI()

cheers,
b