autobatch: Automates the use of SpriteBatches when drawing
autobatch: Automates the use of SpriteBatches when drawing
autobatch is a small module which when dropped into an existing project, will override the love.graphics functions so that SpriteBatches are automatically used in cases where an image is drawn multiple times in a row. No changes to your project's code need to be made, besides calling require() on the module at the top of your main.lua file.
In the best case scenario -- where the same image is being drawn lots of times back-to-back and a SpriteBatch is not already being used -- autobatch can offer a significant boost in performance. In the worst case scenario the module should have little noticeable effect, with a possible slight reduction in performance (the module should be omitted in such cases).
There are a couple of demo projects (the gif above is of one) in the demo directory -- you can press [space] to toggle the use of the module on these.
-
- Party member
- Posts: 106
- Joined: Sat Jun 21, 2014 3:45 pm
Re: autobatch: Automates the use of SpriteBatches when drawing
I prefer manually controlling the sprites in a spritesheet, but this is a great module regardless.
Really nice work dude!
Really nice work dude!
- slime
- Solid Snayke
- Posts: 3161
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: autobatch: Automates the use of SpriteBatches when drawing
Nifty! It doesn't seem to handle Shader:send calls though, which require a flush if were any draw calls before the Shader:send that used the same shader and same batch.
Re: autobatch: Automates the use of SpriteBatches when drawing
Good catch! Just pushed a commit to flush when :send() and :sendColor() are used. Thanks!slime wrote:Nifty! It doesn't seem to handle Shader:send calls though, which require a flush if were any draw calls before the Shader:send that used the same shader and same batch.
-
- Prole
- Posts: 13
- Joined: Mon Apr 09, 2012 1:39 pm
Re: autobatch: Automates the use of SpriteBatches when drawing
Ah! Awesome thing. I thought of doing something like that myself, a fair while ago, but never got around to it. I might take it for a spin sometime, see if I can integrate my texture atlas into it somehow, to allow batching even when the original images aren't the same.
Re: autobatch: Automates the use of SpriteBatches when drawing
If you're already using a texture atlas you shouldn't have to do anything special: both love.graphics.draw(img, ...) and love.graphics.draw(img, quad, ...) can be batched the same way.asmageddon wrote:Ah! Awesome thing. I thought of doing something like that myself, a fair while ago, but never got around to it. I might take it for a spin sometime, see if I can integrate my texture atlas into it somehow, to allow batching even when the original images aren't the same.
-
- Prole
- Posts: 13
- Joined: Mon Apr 09, 2012 1:39 pm
Re: autobatch: Automates the use of SpriteBatches when drawing
Yeah but that doesn't seamlessly improve the performance of code not using a texture atlas, and I think that would be a really nice feature.
- slime
- Solid Snayke
- Posts: 3161
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: autobatch: Automates the use of SpriteBatches when drawing
There are edge-case pitfalls to watch out for when switching from regular images to a texture atlas (e.g. border extrusion, wrap modes, shader or Mesh access of texture coordinates, etc.). I don't think automatically doing it is necessarily a good idea because it can cause subtle issues that are hard to track down.
-
- Prole
- Posts: 13
- Joined: Mon Apr 09, 2012 1:39 pm
Re: autobatch: Automates the use of SpriteBatches when drawing
You do make a fair point :c I suppose it could still be nice if it was used only for drawing images directly, without shadders or wrapping, and included some padding in the atlas to prevent bleeding.
Who is online
Users browsing this forum: Ahrefs [Bot], Amazon [Bot] and 1 guest