简体   繁体   中英

Efficiently drawing many textures in android with OpenGL ES 2.0

I am writing an android app, which needs to draw a huge amount of pictures aligned in a grid. The plan is to draw about 2000 pictures (building up a mosaic). Each of these pictures has a size of 1024x1024. Of course I ran there into heavy efficiency problems.

Right now I am using OpenGL ES 2.0 for drawing. I have one thread loading the images from resources into bitmap objects and passing them to a central pool. The rendering thread of OpenGL then takes an image from this pool, loads the image data from the bitmap to the GPU and draws it at the right cell of a built up grid.

This is horribly slow. I measured some times on this procedure using the android emulator. I got about 60ms for loading a resource into a bitmap object. Loading bitmap into GPU + drawing it takes about 15ms.

I don't have a clear idea on how to speed this up and do this with at least like 30 FPS. My ideas at this moment are to use an external library for loading bitmaps and maybe use the NDK to speed things up. Also I know about texture atlas and batching up my draws. I could implement this, but as my problems are with loading images from resources on runtime I didn't try it for now.

Maybe someone can give me an advice on how to do this efficiently.

Thank you everyone.

First of all, I just want to make it clear, since I think your title is a but misleading - your real problem is not drawing but loading, according to your description. You did not really say if you have a drawing problem (you mentioned the fps for loading and drawing).

You did not mention all the requirements, for example - how soon do you need to draw all of them? Maybe you can, for example, load the first X as part of the app loading, so when the app loads the textures are already created and can be drawn, and in the meantime in the dedicated thread load another X, and so on... Another approach would be to have low resolution images and high resolution images, load the low resolution first and replace later (on-demand, for example). I'm not sure if this is reasonable memory-wise for 2000 images, but you can check that.

Also, I would suggest taking a look at Rajawali - it is a nice framework, with good examples including for multiple textures (there's also examples app in Google Play). Perhaps it could help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM