Consider a 2D simulation with the following properties:
- Entities fill the screen and move around, and sometimes die and disappear
- Every entity has a unique, procedurally generated set of textures as its "sprite". Given the procedural nature, the textures are generated at runtime. The chance of any two entities having the same texture is extremely low
- A maximum of 5,000 entities will ever exist at once on the screen (there is no max to the number of entities that can exist in any given playthrough - when they die, the memory is freed)
- The sprites should be drawn back to front so foreground entities overlap entities "behind" them.
- The sim is compatible with OpenGL 3.0
- GL_MAX_TEXTURE_SIZE is 2048 for compatibility with older mobile devices
- Textures have transparency, so a z-buffer would not work for draw order
If I am not mistaken, there are two general approaches to this problem:
- Dynamically update a texture atlas with each entity's newly generated texture at runtime. When an entity dies, remove its textures too leave blank space for new ones. The advantage here is that you only need 1 draw call. The disadvantage is that the texture atlas makes the system impossible. If you have a 2048x2048 atlas and your sprites are 64x64, you can only generate 1024 sprites before you run out of space. If each entity consists of 5 sprites for animation purposes, only around 200 entities could exist at any one time. You also have to continually update the texture at runtime.
- Create an individual texture object for each individual enemy and do a draw call for each one. The advantage here is that you can continually create new textures as much as you want (within memory limits). The disadvantage is obviously the potentially huge number of draw calls (up to 5,000 for the entities alone, not including background textures, etc.)
So #1 seems to be completely out of the question. Is #2 the only way to accomplish this, or is there a better method I haven't considered?