MoltenEngine icon indicating copy to clipboard operation
MoltenEngine copied to clipboard

Static Sprite Batching

Open Syncaidius opened this issue 3 years ago • 0 comments

Add support for a static sprite-batching, which would avoid the cost of repopulating a sprite-batch buffer every time you want to draw large amount of sprites.

  1. Split draw and batching methods of SpriteBatcher into a base class
  2. Add StaticSpriteBatcher
  3. Use a static vertex buffer instead of dynamic
  4. Add StaticSpriteBatcher.Replace() for replacing existing sprites in the buffer without re-generating it all
  5. Add StaticSpriteBatcher.ReplaceRange() for replacing a range of sprites at once
  6. During Render() call:
    • If batch was changed, update vertex buffer via a staging buffer
    • Draw in the same way that normal SpriteBatcher does, but don't reset sprite data once finished
  7. Add SpriteBatcher.FlushToStatic(StaticSpriteBatcher destination = null) to copy the current contents to a static sprite-batcher and flush without rendering

Syncaidius avatar Mar 05 '23 16:03 Syncaidius