autobatch: Automates the use of SpriteBatches when drawing

Showcase your libraries, tools and other projects that help your fellow love users.
rxi
Prole
Posts: 47
Joined: Sun Mar 02, 2014 10:22 pm

autobatch: Automates the use of SpriteBatches when drawing

Post by rxi »

Image

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.
Whatthefuck
Party member
Posts: 106
Joined: Sat Jun 21, 2014 3:45 pm

Re: autobatch: Automates the use of SpriteBatches when drawing

Post by Whatthefuck »

I prefer manually controlling the sprites in a spritesheet, but this is a great module regardless.

Really nice work dude!
User avatar
slime
Solid Snayke
Posts: 3131
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: autobatch: Automates the use of SpriteBatches when drawing

Post by slime »

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.
rxi
Prole
Posts: 47
Joined: Sun Mar 02, 2014 10:22 pm

Re: autobatch: Automates the use of SpriteBatches when drawing

Post by rxi »

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.
Good catch! Just pushed a commit to flush when :send() and :sendColor() are used. Thanks!
asmageddon
Prole
Posts: 13
Joined: Mon Apr 09, 2012 1:39 pm

Re: autobatch: Automates the use of SpriteBatches when drawing

Post by asmageddon »

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.
User avatar
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

Re: autobatch: Automates the use of SpriteBatches when drawing

Post by undef »

Great Idea!
twitter | steam | indieDB

Check out quadrant on Steam!
alloyed
Citizen
Posts: 80
Joined: Thu May 28, 2015 8:45 pm
Contact:

Re: autobatch: Automates the use of SpriteBatches when drawing

Post by alloyed »

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.
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
Prole
Posts: 13
Joined: Mon Apr 09, 2012 1:39 pm

Re: autobatch: Automates the use of SpriteBatches when drawing

Post by asmageddon »

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.
User avatar
slime
Solid Snayke
Posts: 3131
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: autobatch: Automates the use of SpriteBatches when drawing

Post by slime »

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.
asmageddon
Prole
Posts: 13
Joined: Mon Apr 09, 2012 1:39 pm

Re: autobatch: Automates the use of SpriteBatches when drawing

Post by asmageddon »

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.
Post Reply

Who is online

Users browsing this forum: No registered users and 41 guests