
Mathias Gaunard wrote:
Michael Marcin wrote:
If texture has to be constructible from key then texture has to have direct access to file and image loading functionality. I can't pass any information other than the key to the construction site without resorting to singletons.
What's the problem with making your image loaders singletons? As far as I can think, they're the perfect candidates.
When loading a texture in OpenGL the texture is bound to the current OpenGL context which is stored per thread. OpenGL textures must be destroyed and recreated when you change resolution because you must also destroy and recreate your OpenGL context. A thread can have multiple contexts but only 1 may be current at time. The collection of textures, which flyweight stores in its factory, is logically bound to the current render context on the current thread. A singleton isn't really a good fit for a flyweight factory of OpenGL textures. As for the image loaders themselves for at least some of them I have to create multiple instances in order to use them concurrently. -- Michael Marcin