libGDX Pixmap and Texture performance

人走茶凉 提交于 2020-01-06 03:26:30

问题


I have a huge amount of 2d images in my game, with multiple layers. I use spritebatch() and orthographicCamera(). I have some basic questions about performances :

  1. Does using Atlas is the faster way to load images ?
  2. What is faster to work with, Pixmap (and convert to texture before draw) or Textures?
  3. When i make a multiple layer image, should I use Texture.draw (or Pixmap.draw for Pixmap), make a final image and then render it ? Or should i render everything in the spritebatch.begin() and spritebatch.end()?
  4. Is there a way to track "dirty sprites" (the part of the screen that changed between two frames) and render only this region to increase performance?
  5. Also, how can I see the memory amount taken by the program resources, and how should I manage it? (maybe this question is a little more difficult)

Thank you for your help (any other general advice is welcome)


回答1:


  1. Yes, this reduces the number of times textures need to be swapped while rendering. This is typically much faster than using separate images.

  2. Not sure what you mean by this, a Pixmap should only be used for textures which need to change dynamically or generated as a form of caching. Anything dynamic (changing many times per second to once per frame) should be done using shaders if possible.

  3. Use sprite batch when possible as it reduces the number of draw calls. Typically, Pixmaps should be used only when absolutely needed or you have multiple layers you want to cache together. Caching implies it doesn't change super frequent (i.e. should only change every couple seconds). Since Pixmap relies on using CPU it is very slow if large parts of it are changed often. You also take the hit of having to update textures after you make changes.

  4. No, this has to be done by yourself... This very rarely is worth the effort and usually there are other easier approaches such as reducing draw calls and culling instead... However, this is very application specific and this is something you will need to experiment with to see what works best for your application.

  5. Many profiling and monitoring tools exist VisualVM for desktop. Android 4.0+ has really good developer tools to keep track of things and the Android development environment will provide information on when GCs occur, memory usage, etc. Of course profiling itself will reduce performance/behavior of your application. Runtime.getRuntime() also provides some good memory information about the running JVM.

General Advice:

There is no silver bullet, everything is application specific and while I have suggested and answered your questions for the general case, not everything applies to all situations. You will have to experiment with your application to find out what works best for you. Also, don't get stuck worrying too much about performance and design, the goal is to make a software product. If you spend too much time worrying about performance then you will never finish any project you start. My best advice is to take a shot at it and learn from the experience. You will make mistakes, we all do, but experience will always help mitigate that.



来源:https://stackoverflow.com/questions/24217460/libgdx-pixmap-and-texture-performance

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