开发者

Best way to render 2d animated sprites openGl ES

I am writing a 2d game on the android and I am targeting phones with that have a minimum OpenGl ES 1.1 support.

I am currently looking at creating my animated sprite class which is basically a quad that has a changing texture on it to provide animation.

I wanted to stick to Opengl 1.1 so am avoiding shaders and was wondering how other people have approached the implementation of开发者_如何学Python animated sprites.

My thoughts initially were to either:

  1. Have a single vertex buffer object with one texture coordinate set, then use lots of pre loaded textures that would be swapped at runtime in the correct order.
  2. Have just one texture sprite sheet and modify texture coordinates at runtime to display the coorect subsection of the sprite sheet.

Is there a more clever or more efficient way to do this without shaders?

Thanks


Choose #2 if you have only the two options.

However, I recommend making and caching all of quad vertex set for each sprite frames into vertex buffer on memory closest to GPU. Or just generate new sprite quad vertex and specify them for each drawing. This is trade off problem between performance vs memory by caching. Think about memory consumption vertices for single frame.

  1. Changing GPU internal state is a lot expensive operation. Of course, including texture object swapping. Avoid this as much as possible. This is the reason huge texture atlas are used on traditional game development.

  2. Transferring resources (including vertices) to VRAM (closest memory to GPU) may be expensive because they need to be copied over slower bus. This is similar with server-client situation. GPU+VRAM is server, CPU+RAM is client connected through PCI-bus network. However this can be vary by system structure and memory/bus model.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜