Boost logo

Boost :

Subject: Re: [boost] [flyweight] key value with objects not constructible from a key
From: Michael Marcin (mike.marcin_at_[hidden])
Date: 2008-11-13 01:46:43


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

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk