Page 1 of 1

Spritebatch Atlas Creator & Example

Posted: Mon Feb 01, 2016 3:02 pm
by drunken_munki
Hello all

I have recently upgraded all my engine logic to use sprite-batches with large unevenly sized images.

For now, I have cut out some of the code and made a stand-alone example for your perusal. Nothing too fancy though, just does the following:

Creates an atlas from different sized graphics assets (automated) and packed in height order (first idea from head).

The atlas is saved out with quad information, and is loaded in on the next run.

and Demonstrates rendering some quads with a sprite-batch.


Edit* Question for you guys:

What is the significance of the spritebatch 'maxsprites ' ?

spriteBatch = love.graphics.newSpriteBatch( image, maxsprites )

Is there some sort of performance hit. I just can't see why there is a limit. Thank you all.

Re: Sritebatch Atlas Creator & Example

Posted: Mon Feb 01, 2016 5:30 pm
by bobbyjones
The limit is probably because you can't create a batch without a specified amount. In c++ and opengl things are not as flexible as lua. I would assume the batch is like an array where you can not resize it after it is created.

Re: Spritebatch Atlas Creator & Example

Posted: Tue Feb 02, 2016 3:16 pm
by RainbowOverdose
You could write an ensureCapacity function if you really need it and emulate a dinamic behavior for that spritebatch, but, there must be some other way to do it since Lua uses table for everything... So ensure sapacity probably is not a good choise in this case :huh:

Re: Spritebatch Atlas Creator & Example

Posted: Tue Feb 02, 2016 10:01 pm
by bobbyjones
RainbowOverdose wrote:You could write an ensureCapacity function if you really need it and emulate a dinamic behavior for that spritebatch, but, there must be some other way to do it since Lua uses table for everything... So ensure sapacity probably is not a good choise in this case :huh:
Lua uses tables but not the actual code that creates the batch. So a dynamic batch probably not possible and if it is resizing would be slow.

Re: Spritebatch Atlas Creator & Example

Posted: Tue Feb 02, 2016 10:25 pm
by RainbowOverdose
bobbyjones wrote:
RainbowOverdose wrote:You could write an ensureCapacity function if you really need it and emulate a dinamic behavior for that spritebatch, but, there must be some other way to do it since Lua uses table for everything... So ensure sapacity probably is not a good choise in this case :huh:
Lua uses tables but not the actual code that creates the batch. So a dynamic batch probably not possible and if it is resizing would be slow.
Did you ever emulated a linked list with an array? it's possible, but, you are right, it's slow.

Re: Spritebatch Atlas Creator & Example

Posted: Tue Feb 02, 2016 10:54 pm
by slime
drunken_munki wrote: What is the significance of the spritebatch 'maxsprites ' ?

spriteBatch = love.graphics.newSpriteBatch( image, maxsprites )

Is there some sort of performance hit. I just can't see why there is a limit. Thank you all.
It determines the amount of video memory (and regular memory) that the SpriteBatch uses. It also affects how much data is copied from main memory to video memory when the SpriteBatch is drawn (or if [wiki]SpriteBatch:flush[/wiki] is called), for streaming SpriteBatches.

There is a performance hit (and a memory increase) for specifying a much higher number than what you actually use.

Re: Spritebatch Atlas Creator & Example

Posted: Wed Feb 03, 2016 12:19 pm
by drunken_munki
It determines the amount of video memory (and regular memory) that the SpriteBatch uses. It also affects how much data is copied from main memory to video memory when the SpriteBatch is drawn (or if SpriteBatch:flush is called), for streaming SpriteBatches.

There is a performance hit (and a memory increase) for specifying a much higher number than what you actually use.
Interesting, thanks for that. I will probably do some testing when I get a chance and I'll post the results.