guillotiere icon indicating copy to clipboard operation
guillotiere copied to clipboard

Fitting test

Open DavidPeicho opened this issue 3 years ago • 3 comments

Hey! Nice library, thanks a lot :)

Do you think it would make sense to add a dry-run of allocating a bunch of images to see if they fit? I am basically making layers of atlas, and sometimes I need to allocate a new atlas and to resize my texture data. However, Rust vector resize is crazy slow, and I would like to know beforehand how much capacity I need to pre-allocate.

I am not sure it's possible, but the algorithm looks fast enough in some case to be worth it.

DavidPeicho avatar Jul 16 '22 20:07 DavidPeicho

Hi, thanks!

I don't think the atlas allocator can do much better than what you would do manually, that is try to allocate all of the images, and if they don't fit, deallocate them. Maybe I'm not seeing what you are intending to do. Which vector are you worried about reallocating in particular?

nical avatar Jul 18 '22 12:07 nical

I basically have a list of AtlasAllocator, where each atlas corresponds to a layer. I have alongside a giant buffer that contains the texture data packed according to each layer:

[textures_for_atlas_0....textures_for_atlas_N]

Basically when trying to fit an image, I go through the atlas one by one for a fit, and eventually resize the data buffer if needed. It's quite hard to know in advance whether a list of images will fit. I guess my best solution would be to make some estimate based on the size of the input images, and pre-allocate some atlases.

DavidPeicho avatar Jul 18 '22 14:07 DavidPeicho

If I understand correctly the giant pixel buffer is what's taking a long time to reallocate. It shouldn't be an issue if you are performing all atlas allocations (or as many as you can) before before creating/filling the image buffer (which I assume you can do since you know about the image sizes enough in advance to want to do a dry run). Or you can actually do a dry run by performing the atlas allocations and deallocating them. The altas allocator isn't a huge structure so preallocating a conservative number of them shouldn't be an issue (if you are also worried about the allocation of the list of atlases).

nical avatar Jul 18 '22 15:07 nical