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?

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.

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

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.