Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Android native texture loading

Discussion in 'Android' started by MaskedMouse, Apr 19, 2017.

  1. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    509
    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:
    https://docs.unity3d.com/Manual/PluginsForAndroid.html
    https://forum.unity3d.com/threads/native-texture-loading-on-android.383947/

    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-Technol...e.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:

    Code (CSharp):
    1. [DllImport ("AndroidNativeTexture")]
    2. 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:
    Code (CSharp):
    1. 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
     
    Last edited: Apr 27, 2017
  2. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    509
    Bump, seriously none? :p 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
     
  3. PeterGeneral

    PeterGeneral

    Joined:
    Jun 5, 2015
    Posts:
    14
  4. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    509
  5. PeterGeneral

    PeterGeneral

    Joined:
    Jun 5, 2015
    Posts:
    14
    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:
     
    LostPanda likes this.
  6. LostPanda

    LostPanda

    Joined:
    Apr 5, 2013
    Posts:
    143
    hello, can you add win in runtime dds fast load? thanks
     
unityunity