- Home /
Why do larger www textures take huge amounts of memory?
I'm downloading jpegs from the net and setting them as textures. In looking at the statistics window memory usage grows far faster than I would expect. For example the statistics for Used Textures for the following sizes:
A) 1024 x 1024 = 3 MB
B) 2048 x 2048 = 12 MB
C) 3072 x 3072 = 64 MB
D) 4096 x 4096 = 256 MB
The jump from A to B is exactly what I would expect, but the 5x jump from B to C and the 4x jump from C to D seems way out of line. Anyone know what larger texture loads use so much more memory? And can I do anything about it?
Note this was tested in the editor with a new project containing only a camera, a sphere, a material, and the following simple code (just changing the jpeg loaded):
void Start ()
{
StartCoroutine("Load");
}
IEnumerator Load()
{
string st = "http://www.mysite.com/A.jpg";
WWW www = new WWW(st);
yield return www;
renderer.material.mainTexture = www.texture;
}
Could be related to mipmapping and/or the fact that some hardware do not support texture size greater than 2048, so they need to be handled differently.
Do all your textures use the same format? (for example ARGB)
The issue occurs inside the editor with "PC and $$anonymous$$ac" standalone as the targets. The texture is loaded through the www interface, and I cannot figure out how to deter$$anonymous$$e the format it provides. I've considered mipmapping as a possibility, but other posts indicate that textures handed back by the WWW interface are not mimmapped.
You can check that with Texture2D.format and Texture2D.mipmapcount.
WWW www = new WWW(st);
yield return www;
if (www.texture != null)
{
Texture2D tex = www.texture;
Debug.Log("format: "+tex.format.ToString()
+"mipmapCount: "+text.mipmapCount);
}
See also: WWW.LoadImageIntoTexture
Thanks for the info. The format is RGB24 and mipmapCount is 1 (i.e. no mipmaps). Just to be sure, I tried
Texture2D t2d = new Texture2D(4096, 4096, TextureFormat.RGB24, false);
www.LoadImageIntoTexture(t2d);
The large memory usage is the same. This indicates to me the large memory usage is either inherent in Unity or a bug in Unity.
Answer by ScroodgeM · Jul 28, 2012 at 05:58 PM
first. don't test texture memory usage on textures with size non-power-of-two (NPOT). those textures takes more space then (height x width x bpp). try always use only POT textures for 3d rendering and especially for measurement.
second. look script below. it takes exactly 48MB of textures memory usage. feel free to use texture in script. may be your format is incorrect?
in other textures everything is same as yours result. 1024x1024 takes 3MB, 2048x2048 - 12MB, 3072x3072 - 64MB (see above), 4096x4096 - 48MB
if you still get 256B with my 4096x4096 texture, describe your measure method.
void Start() { StartCoroutine("Load"); }
IEnumerator Load()
{
string st = "http://zammyart.com/4096.jpg";
WWW www = new WWW(st);
yield return www;
Texture2D t2d = new Texture2D(4096, 4096, TextureFormat.RGB24, false);
www.LoadImageIntoTexture(t2d);
renderer.material.mainTexture = t2d;
}</pre>
You are right on the 4$$anonymous$$ image. $$anonymous$$y large test image was a couple of pixels too large. I still don't understand why a 3$$anonymous$$ x 3$$anonymous$$ image is larger than a 4k x 4$$anonymous$$ image. At worst, I would have expected them to be the same size, not have the 3$$anonymous$$ image so much larger. Thank you for spending the time to check this out.
if texture size is NPOT, it can be converted (i'm not sure about this) to POT size for 3D adapter and also kept original copy in memory for future usage. so it can take more memory then 4$$anonymous$$ texture.
just don't use NPOT textures 8)
Your answer
Follow this Question
Related Questions
What is the correct way to remove assets from memory? 1 Answer
Free memory after WWW.LoadImageIntoTexture 1 Answer
Large memory footprint increase when assigning a GUITexture from a WWW Object on iPad 1 Answer
Loading imagesequence at runtime - memory problem 1 Answer
Memory problem with WWW and Texture 2 Answers