Does Unity automatically resize runtime-generated textures so that the dimensions are powers of two?
No.
–Eric
Actually, yes. I wrote in C# the following:
Texture2D texture = new Texture2D(152, 30);
while Unity claims that texture.width == 152 and texture.height == 30, the allocated texture produces clearly visible artifacts as if it were bigger than that. I then wrote a native plugin and inspected the texture pointer retrieved with GetNativeTexturePtr() and I can confirm that the actual texture size is indeed 256x32. As a further confirmation, I applied a mainTextureScale equal to (152/256, 30/32) and the artifacts disappeared.
IMHO, this is a bug in Unity. You should either get what you asked for (a 152x30 texture) or (if that’s not possible/feasible/desirable) texture.width and texture.height should return the actual size of the allocated texture. Having texture.width and texture.height return the wrong value is totally useless and a possible source of bugs.
- Alberto
This bug appears to be fixed in Unity 4.1. Very good.
I see… I rely on this as well and will need to actually change some sloppy code from using width height to constants then when we find valid reason to actually move to 4