Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

CopyTexture of compressed texture produces texture with different in-memory size.

Discussion in 'General Graphics' started by OmgLaserGunPewPew, Jan 21, 2022.

  1. OmgLaserGunPewPew

    OmgLaserGunPewPew

    Joined:
    Sep 15, 2019
    Posts:
    3
    For example:
    Source 4096x4096 texture with RGB Compressed ETC2 4 bits compression on my android device
    upload_2022-1-21_16-54-22.png

    When i do:
    Code (CSharp):
    1. m_dst = new Texture2D(m_src.width, m_src.height, m_src.graphicsFormat, m_src.mipmapCount, UnityEngine.Experimental.Rendering.TextureCreationFlags.MipChain);
    2. m_dst.name = "Copy";
    3. Graphics.CopyTexture(m_src, m_dst);
    i get this one on my device
    upload_2022-1-21_17-6-43.png

    Both textures are in correct compression format:
    upload_2022-1-21_17-25-57.png

    Why "Copy" texture has so different size? Is it correct? My Unity version is 2020.3.3f1.
     

    Attached Files:

    Last edited: Jan 21, 2022
  2. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    692
    Maybe try with textureFormat instead of graphicsFormat?

    CopyTexture isn't your problem. The problem is when you initialize your new texture. CopyTexture is just moving data around.
     
  3. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    By default textures created at runtime have the isReadable flag enabled, which causes a copy of the texture data to exist in the CPU and counts as 2x the memory used. You need to call Apply() on the texture once after creating it to discard the CPU copy:

    https://docs.unity3d.com/ScriptReference/Texture2D.Apply.html
     
  4. OmgLaserGunPewPew

    OmgLaserGunPewPew

    Joined:
    Sep 15, 2019
    Posts:
    3
    Well, of course, I didn't think of that at all! Thank you very much!