Search Unity

Feedback Expose TextureUtil API

Discussion in 'Editor & General Support' started by Peter77, Nov 3, 2019.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    The TextureUtil contains such useful functionality, please make it public.

    Methods such as
    GetStorageMemorySizeLong
    ,
    GetRuntimeMemorySizeLong
    ,
    GetTextureFormat
    and
    GetTextureFormatString
    are so crucial to have when writing custom editor tools, yet they are inaccessible to us.

    In pretty much every project I end up in reflection hell, just to get access to things like mentioned above. I would be able to write more robust editor tools if the TextureUtils class is accessible.
     
    Noisecrime and Vectorbox like this.
  2. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,054
    Agreed, just looking into this myself as there appears to be no runtime or even good editor method to get a textures memory requirements.

    Edit:
    For anyone interested in accessing this api I stumbled upon a nice gist here.
    https://gist.github.com/seibe/762f8f2e3c4e06a8f894f812127e3e33
    Certainly saved me time trying to dig into reflection again.

    I guess there are no official methods for calculating projected memory usage for a specific texture ( e.g. creating a RenderTexture of some format ). So i've been writing my own and comparing the results to Unity's which I would assume just looks at the actual size of the data.

    There is definitely some weird things with say anti-aliasing using more memory than I expected. From Unity's numbers it looks like there is an additional pixelCount * bytesPerPixel at mipmap level 0 on top of what you would normally expect. Other gotchas are compressed formats not going down to exactly 1 pixel for final mipmap level and for 3D volumes depth isn't mipmaped which is understandable but has got me thinking how that might affect volumetric data at mipmapped levels.

    Anyway, regardless would still be nice to get the Unity size for a texture in the editor as that is useful information in of itself.
     
    Last edited: Nov 12, 2019
    Peter77 likes this.
  3. AljoshaD

    AljoshaD

    Unity Technologies

    Joined:
    May 27, 2019
    Posts:
    233
    Thanks for this feedback! We will investigate if/how we can make these public.
     
    lang_fox, Noisecrime and Peter77 like this.