Hello,
I have written some code that creates a texture at runtime by modifiying pixel values, and then compresses the texture to the DXT format. This works fine in the Editor build, but when I compile my game for the Development or Shipping config, I get the following compile error:
2>LINK : fatal error LNK1181: cannot open input file 'C:\work\Epic Games\4.10\Engine\Binaries\Win64\UE4-TextureCompressor.lib'
It appears that this module is in the “Developer” folder, rather than the “Runtime” or “Editor” folders. What does it mean to be a “Developer” module? How can I compress a texture at runtime? I’ve added the “TextureCompressor” module to the list of PublicDependencyModuleNames in my game project’s .Build.cs file.
For reference, here is my code:
/** Allocate render target for writing uncompressed texture to */
TArray<FImage> generatedMips;
FImage &generatedImage = generatedMips[generatedMips.Add(FImage())];
generatedImage.Init(m_targetTexSize.X, m_targetTexSize.Y, ERawImageFormat::BGRA8);
FMemory::Memzero(generatedImage.RawData.GetData(), generatedImage.RawData.Num());
/// image generation here
/// ...
/** Compress the created texture */
ITextureCompressorModule* Compressor = &FModuleManager::LoadModuleChecked<ITextureCompressorModule>(TEXTURE_COMPRESSOR_MODULENAME);
TArray<FImage> CompositeSourceMips;
TArray<FCompressedImage2D> CompressedMips;
FTextureBuildSettings BuildSettings;
BuildSettings.TextureFormatName = TEXT("DXT5");
BuildSettings.MipGenSettings = TextureMipGenSettings::TMGS_NoMipmaps;
if (Compressor->BuildTexture(generatedMips, CompositeSourceMips, BuildSettings, CompressedMips))
{
UTexture2D *newTex = UTexture2D::CreateTransient(m_targetTexSize.X, m_targetTexSize.Y, PF_DXT5/*m_source->GetPixelFormat()*/);
newTex->NeverStream = true;
newTex->CompressionSettings = TextureCompressionSettings::TC_Default;
FTexture2DMipMap& targetMip = newTex->PlatformData->Mips[0];
int32 size = targetMip.BulkData.GetBulkDataSize();
FColor* targetData = static_cast<FColor*>(targetMip.BulkData.Lock(LOCK_READ_WRITE));
FMemory::Memcpy(targetData, CompressedMips[0].RawData.GetData(), size);
targetMip.BulkData.Unlock();
newTex->UpdateResource();
return newTex;
}