Android native texture loading

Hello,

[Information]
I’ve seen many posts that lead little by little to loading textures from disk natively on Android.
Though my knowledge of Android native is 0.0%
I’ve looked through many internet pages (searching with Google) for solutions.
Though I understood hardly anything besides the little parts of OpenGL.

Useful links that I’ve looked through:

I’ve adapted the iOS plugin that Unity wrote to load the texture natively on iOS.
so the iOS side is already done for both Metal and OpenGLES 3.0.
https://bitbucket.org/Unity-Technologies/iosnativecodesamples/src/520af5d726ec9888523ffc058c64f0f2ab49720e/Graphics/ExternalTexture/Assets/Plugins/iOS/NativeTexture.mm?at=2017-dev&fileviewer=file-view-default

I was hoping maybe someone already wrote this Android plugin, or could help me out get me into the right direction like what API’s to use in Android Studio.

[My Questions]
What would I need to build this?
I know I got to build ‘a plugin’ with Android Studio but should it be a .so or a .jar?
using JNI or what else?
The goal is to create an Android version of the example that Unity built for iOS.
So would be nice if it could be used like:

[DllImport ("AndroidNativeTexture")]
private static extern IntPtr CreateNativeTexture (string filePath, ref int imageWidth, ref int imageHeight);

so it could co-exist with the modified version of the iOS version of the plugin.

[Requirements]

  • OpenGLES 3.0 Support
  • Pass a string filepath for example: {Application.PersistenDataPath}/CachedFiles/Image.jpg
  • Return System.IntPtr to be used by:
Texture2D.CreateExternalTexture(width, height, TextureFormat.RGB24, false, false, texturePtr);
  • use int* imageWidth / int* imageHeight so the width and height can be used in CreateExternalTexture
  • Should be able to build an Android build using IL2CPP
  • Minimum Android API 4.4 (if that matters)

[Reason?]
This should be a bypass for LoadImage as it is slow on Android for large texture sizes such as 4096x2048
LoadImage freezes the app which is something we want to avoid but since Unity doesn’t give any option to asynchronously load an image from disk in form of JPG/PNG it kinda sucks.

[Why not use AssetBundles?]
Building lots of little asset bundles coming from multiple requests at a time is kind of worrysome. We’d want it instantly available without delay. So after uploading to the server it should be available directly

Bump, seriously none? :stuck_out_tongue: wouldve thought someone would know more about native texture loading on android

iOS seemed so easy to understand compared to Android
UIImage does most of the work but don’t know this for android

Check this : Unity Asset Store - The Best Assets for Game Making

Thank you for your reply. I’ve looked at the asset and it seems they just released it recently. The publisher’s website is live though not really filled in, which causes concern. We’ll just keep an eye on it, but may eventually develop it ourselves.

The Asset is made by a friend of mine. It basically does what you wanted to achieve. Takes in the path to the texture and a texture2d itself and renders it async. No lag whatsoever. You should look at the asset’s demo.

here’s another video that demonstrates the asset:

1 Like

hello, can you add win in runtime dds fast load? thanks