I am working on an OpenGL-based app that needs to be able to generate a changing set of textures on the fly.
From my initial reading it sounds like it would be a really bad idea to use a separate texture for each image that I need to draw as the operation of binding a texture so that is can be used for rendering is really slow.
The preferred approach would be to combine many of these needed images into a single bigger image and binding that texture once and drawing only excerpts from it (sprites).
Unfortunately my images can have very different sizes and become needed and obsolete in somewhat unpredictable ways.
So, what I need is a sort of memory manager that maintains a list of used and free regions in my texture(s) and can allocate/dispose areas for new/obsolete images.
It's basically what every program needs to do for memory management (allocate and dispose variables of different size in the heap), except it's a 2D problem, since I'm allocating rectangles inside a big square rather than short "lines" in a longer one.
Is there a name for the problem I am trying to solve and is there a (or multiple) standard/best-practice approach(es)?
(A quick clarification: I'm not looking for ways to handle the reference counting and such to figure out which images are no longer used. I'm looking for a way to reserve new rectangles in a patch-work of existing ones and gaps, that minimizes (eliminates?) any re-arranging of the other rectangles.)
UPDATE:
I came up with an idea for a different approach but decided to post it as a new question to investigate.