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