How to Create External Textures on Android

Sep 17, 2020

External textures are OpenGL/Metal/Vulkan textures created by the platform directly on the GPU-side, for example as the result of some shader code inside a hardware video codec library. The point of external textures is to keep the texture entirely inside the graphics API and GPU driver memory, so that a CPU copy is not required before Unreal can render it.

On the Android side, you just need to make a JNI function to call into Java and retrieve the bitmap. There are examples of C++ calling Java in AndroidJNI.cpp. We recommend using a UTexture2DDynamic to make a texture from the bitmap at runtime.

If the data is just an Android Bitmap on the CPU, instead of trying to pass Unreal’s texture’s GetNativeResource to the Java code and have it use OpenGL functions on the texture, you should pass the Bitmap object reference to the C++ code and use AndroidBitmap_lockPixels() to get at its data. Then you can pass the data to the UTexture2DDynamic’s Lock and Unlock methods in order to upload the texture. The AsyncTaskDownloadImage.cpp file has an example of how to do that correctly.