guillotiere
guillotiere copied to clipboard
Fitting test
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.
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?
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.
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).