Large scrolling background in OpenGL ES

≯℡__Kan透↙ 提交于 2019-11-30 23:54:53

That's the fast way of doing it. Things you can do to improve performance:

  • Try different texture-formats. Presumably the SDK docs have details on the preferred format, and presumably smaller is better.
  • Cull out entirely offscreen tiles yourself
  • Split the image into smaller textures

I'm assuming you're drawing at a 1:1 zoom-level; is that the case?

Edit: Oops. Having read your question more carefully, I have to offer another piece of advice: Timings made on the simulator are worthless.

The quick solution:

  • Create a geometry matrix of tiles (quads preferably) so that there is at least one row/column of off-screen tiles on all sides of the viewable area.

  • Map textures to all those tiles.

  • As soon as one tile is outside the viewable area you can release this texture and bind a new one.

  • Move the tiles using a modulo of the tile width and tile height as position (so that the tile will reposition itself at its starting pos when it have moved exactly one tile in length). Also remember to remap the textures during that operation. This allows you to have a very small grid/very little texture memory loaded at any given time. Which I guess is especially important in GL ES.

If you have memory to spare and are still plagued with slow load speed (although you shouldn't for that amount of textures). You could build a texture streaming engine that preloads textures into faster memory (whatever that may be on your target device) when you reach a new area. Mapping as textures will in that case go from that faster memory when needed. Just be sure that you are able to preload it without using up all memory and remember to release it dynamically when not needed.

Here is a link to a GL (not ES) tile engine. I haven't used it myself so I cannot vouch for its functionality but it might be able to help you: http://www.mesa3d.org/brianp/TR.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!