Spritebatch Atlas Creator & Example

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
drunken_munki
Party member
Posts: 134
Joined: Tue Mar 29, 2011 11:05 pm

Spritebatch Atlas Creator & Example

Post 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.
Attachments
sb_atlas.love
Code!
(62.94 KiB) Downloaded 160 times
10_512_Quads.lua
Accompanying quads for example atlas
(660 Bytes) Downloaded 136 times
Output exaple atlas
Output exaple atlas
10_512_Atlas.png (58.67 KiB) Viewed 4023 times
Last edited by drunken_munki on Wed Nov 15, 2017 12:52 pm, edited 2 times in total.
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Sritebatch Atlas Creator & Example

Post 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.
User avatar
RainbowOverdose
Prole
Posts: 4
Joined: Sat Jan 30, 2016 12:37 pm
Location: Almería, Spain

Re: Spritebatch Atlas Creator & Example

Post 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:
Life is a cycle that knows no end.
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Spritebatch Atlas Creator & Example

Post 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.
User avatar
RainbowOverdose
Prole
Posts: 4
Joined: Sat Jan 30, 2016 12:37 pm
Location: Almería, Spain

Re: Spritebatch Atlas Creator & Example

Post 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.
Life is a cycle that knows no end.
User avatar
slime
Solid Snayke
Posts: 3148
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Spritebatch Atlas Creator & Example

Post 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.
drunken_munki
Party member
Posts: 134
Joined: Tue Mar 29, 2011 11:05 pm

Re: Spritebatch Atlas Creator & Example

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

Who is online

Users browsing this forum: No registered users and 2 guests