melonjs / melonJS

a fresh, modern & lightweight HTML5 game engine
https://melonjs.org
MIT License
5.93k stars 643 forks source link

fix batch drawing for primitive shapes #1172

Closed obiot closed 1 year ago

obiot commented 1 year ago

Describe the bug Running the https://github.com/Shirajuki/js-game-rendering-benchmark benchmark actually shows that batching primitive shapes drawing is actually broken in melonJS. for sprite based games, sprite batching is actually working, and primitive batching does not really matter, unless it heavily relies on manually drawing shapes everywhere, but this is still something to be fixed (noticed also the flickering when drawing sprites in the benchmark, which is a side effect of the broken primitive batching).

To Reproduce

  1. Go to `https://github.com/Shirajuki/js-game-rendering-benchmark)'
  2. Select melonJS
  3. Click on Stroke of Fill
  4. See the performance drop when count is 2500 or higher, especially for fill operations

Expected behavior at least maintain 60fps when count is at 2500 stroke of fill operations (even Pixi fps is dropping at 5000 and higher)

Device :

Additional context

Proposed solution:

  1. make sure that all primitive drawing use the same type (e.g. gl.LINES, GL.LINE_STRIP, gl_LINE_LOOP) to enable batching :

  2. use different vertex buffer instance for quads (sprite) and primitive drawing. Right now the default compositor "re-use" the Quad Vertex Buffer, leading to a waste of unused data when drawing shapes

  3. talking about the compositor, finally split the compositor into two different ones. One to draw quads/sprites, and one to draw primitives/shapes. This way they can both managed data and batching independently. There was some initial work done but it was never really finished.

Any other idea/suggestion, feel free to comment.

obiot commented 1 year ago

this one is done !

obiot commented 1 year ago

see #1178 and #1179 as a follow up ticket.