Announcement

Collapse
No announcement yet.

Texture Memory Overload

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Texture Memory Overload

    I am dynamically loading textures at runtime and it is working perfectly. Only issue is when I m loading 1920x1080 resolution image, it increase Texture Memory by 18 to 20mb per image even if image size is couple of mb. Is there a way that I can compress the Texture after it is loaded in as I am loading around 60 to 100 images at runtime, texture memory goes over its budget and because of it some of the in game streaming texture are not able to load properly.

    Here is the code that I m using to load textures at runtime

    Code:
    UTexture2D* Texture = nullptr;
         IsValid = false;
     
         TArray<uint8> CompressedData;
         if (!FFileHelper::LoadFileToArray(CompressedData, *InImagePath))
         {
             return nullptr;
         }
         
         IImageWrapperPtr ImageWrapper = GetImageWrapperByExtention(InImagePath);
     
         if (ImageWrapper.IsValid() && ImageWrapper->SetCompressed(CompressedData.GetData(), CompressedData.Num()))
         { 
             const TArray<uint8>* UncompressedBGRA = nullptr;
             if (ImageWrapper->GetRaw(ERGBFormat::BGRA, 8, UncompressedBGRA))
             {
                 Texture = UTexture2D::CreateTransient(ImageWrapper->GetWidth(), ImageWrapper->GetHeight(), PF_B8G8R8A8);
                 if (Texture != nullptr)
                 {
                     IsValid = true;
                     
                     OutWidth = ImageWrapper->GetWidth();
                     OutHeight = ImageWrapper->GetHeight();
     
                     void* TextureData = Texture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
                     FMemory::Memcpy(TextureData, UncompressedBGRA->GetData(), UncompressedBGRA->Num());
                     Texture->PlatformData->Mips[0].BulkData.Unlock();
                     Texture->UpdateResource();
                 }
             }
         }
     
         return Texture;
    Thanks,
    Last edited by Shantaram; 04-02-2015, 05:51 PM.

    #2
    Textures must be a power of two, i.e. 16x16, 512x512, 2048x2048. My understanding is that if it isn't you have a greater impact on memory, which may be the cause of your overload.

    Simulacrum Game | Play The Alpha | Caldera Entertainment | Twitter | ArtStation

    Comment


      #3
      Originally posted by SE_JonF View Post
      Textures must be a power of two, i.e. 16x16, 512x512, 2048x2048. My understanding is that if it isn't you have a greater impact on memory, which may be the cause of your overload.
      Even if I do power of 2, Memory Footprint for loading each texture at runtime is too high.
      And if I Preload those texture, it is using same memory as image size. So is there a way inside code where I can compress it after its being loaded?

      Thanks,

      Comment

      Working...
      X