You’re looking for a way to mange a texture atlas, the following threads could be a good starting point.