- Home /
How can I load pre-compressed textures at run-time (without using assetBundles)
I am wanting to download textures from the web onto the iPhone to use in-game. The textures are generated on a server (not in an assetBundle). I can retrieve the textures as .jpeg or as .pvr with a full mip-map chain. I would prefer the latter for better performance, but I noticed that Texture2D.LoadImage() only allows me to read a byte array of jpeg or png data. Is there either
- A way to create a texture from the raw pvr data?
- A way to (efficiently) compress the jpeg data as pvr at run-time and/or (ideally) to save the compressed result to retrieve it later without needing to re-compress it?
I guess alternatively: are assetBundles the only way to get a pre-compressed texture into a game at run-time?
I'm in a similar boat. I'd like to load pre-compressed textures from external sources. Right now I'm using .png files which are compressed at runtime. Another post mentioned unity support for .dds files. I can produce those externally but I'm not sure yet how to read them in using Unity's API.
Answer by jonas-echterhoff · May 09, 2010 at 08:08 PM
At the moment, using AssetBundles is the only way to load compressed textures into Unity at runtime. The solution Lucas points out will of course work, but it won't let you directly upload compressed texture data to the gpu. You could set up a pipeline on the server, which automatically starts the Unity editor from the command line to create the asset bundles as needed.
Answer by Lucas Meijer 1 · May 09, 2010 at 08:46 AM
You can use Texture2D.GetPixels() and Texture2D.SetPixels(), each of which takes a mipmap parameter. So what you could do in this case is parse the data that comes from your server yourself, and manually create a new Texture2D, and then manually set all pixels for all mipmap levels. You could even make your server output a bunch of pngs. one for each mipmap level, and then use Unity's png importer to do the heavy lifting for you, and just move over the colors into your texture under construction.
Update: see Jonas' answer instead, as my approach indeed doesn't DXT compress the texture at runtime. Note to self: add feature.
Answer by ddt · Apr 16, 2012 at 03:51 AM
Is there a way to get raw images loaded all the way to the GPU (ARGB32 is fine) asynchronously?
I don't know any way to do this without AssetBundles, and it forces you to import the assets, which tends to swell up my awesomely tight PNG formats.
Thanks!
ddt@davetaylor.name
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Texture loading via www.texture not loading! 2 Answers
Tile loading issue 2 Answers
Load Texture at Run time from file 1 Answer
loading from disk, saving to database 0 Answers