What is the order of FColor* in MipData obtained from a UTexture2D?

Hello,

I have a quick question about how the FColor pointers are stored when they are derived from a UTexture2D in the following code:

FTexture2DMipMap* TexMipMap = &TextureToFillWithRandomColors->GetPlatformData()->Mips[0];
FByteBulkData* RawImageData = &TexMipMap->BulkData;
FColor* MipData = static_cast<FColor*>( RawImageData->Lock(LOCK_READ_ONLY ) );

I have no trouble reading or writing to the pixels within the supplied to the function. I just want to know how to traverse the array of FColors.

This code is how I am going through each pixel within the texture.

if (MipData)
{
for ( int32 RowNum = 0; RowNum < TextureWidth; ++RowNum )
{
for ( int32 ColNum = 0; ColNum < TextureHeight; ++ColNum )
{
FColor& CurColor = MipData[( (ColNum*TextureWidth) + RowNum )];
//do something with CurColor
}}}

However, I get some unexpected results when trying to do something like make a horizontally striped texture or make a circle. I tried going through the code but couldn’t find an answer to how the pointers are ordered and correspond to the texture asset provided.

Is the first pointer (MipData [0]) in the top left corner? Or, where is the “origin”?
Do the pointers increment by row or column?

Hi StellerBap,

Yes they are rows of columns, so the for loops are around the correct way (not that it really matters) - just change it to “MipData[(RowNum*TextureWidth)+ColNum]”

1 Like

Thanks!

1 Like