void AMyRenderTarget::setMyRenderTarget(UTextureRenderTarget2D* textureRenderTarget)
{
m_textureRenderTarget = textureRenderTarget;
m_Texture = textureRenderTarget->ConstructTexture2D(this, FString("Snapshot"), EObjectFlags::RF_NoFlags);
}
void AMyRenderTarget::GrabMyRenderTarget()
{
TextureCompressionSettings OldCompressionSettings = m_Texture->CompressionSettings;
//TextureMipGenSettings OldMipGenSettings = m_Texture->MipGenSettings;
bool OldSRGB = m_Texture->SRGB;
m_Texture->CompressionSettings = TextureCompressionSettings::TC_VectorDisplacementmap;
//m_Texture->MipGenSettings = TextureMipGenSettings::TMGS_NoMipmaps;
m_Texture->SRGB = false;
m_Texture->UpdateResource();
FColor* FormatedImageData = static_cast<FColor*>(m_Texture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_ONLY));
int j = 0;
for (int32 y = 0; y < m_Texture->PlatformData->Mips[0].SizeY; y++)
{
for (int32 x = 0; x < m_Texture->PlatformData->Mips[0].SizeX; x++)
{
int32 curPixelIndex = (y * m_Texture->PlatformData->Mips[0].SizeX) + x;
FColor pixel = FormatedImageData[curPixelIndex];
m_buf[j++] = pixel.B;
m_buf[j++] = pixel.G;
m_buf[j++] = pixel.R;
}
}
m_Texture->PlatformData->Mips[0].BulkData.Unlock();
m_Texture->CompressionSettings = OldCompressionSettings;
//m_Texture->MipGenSettings = OldMipGenSettings;
m_Texture->SRGB = OldSRGB;
m_Texture->UpdateResource();
grabBmp(m_Texture->PlatformData->Mips[0].SizeX, m_Texture->PlatformData->Mips[0].SizeY, 0, m_buf);
GEngine->AddOnScreenDebugMessage((uint64)-1, 2.0f, FColor::Emerald, FString::Printf(TEXT("width = %d height = %d num = %d"), m_Texture->PlatformData->Mips[0].SizeX, m_Texture->PlatformData->Mips[0].SizeY));
}