Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fitting test #29

Open
DavidPeicho opened this issue Jul 16, 2022 · 3 comments
Open

Fitting test #29

DavidPeicho opened this issue Jul 16, 2022 · 3 comments

Comments

@DavidPeicho
Copy link

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.

@nical
Copy link
Owner

nical commented Jul 18, 2022

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?

@DavidPeicho
Copy link
Author

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.

@nical
Copy link
Owner

nical commented Jul 18, 2022

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants