It seems the only solution other than banning global SFML objects (which doesn't sound totally unreasonable)
It is the current solution, but it's definitely not convenient. SFML has globals (the default font), users too (image manager singleton, ...), it would be cool if it could work just fine.
would be to decouple context management from the lifetime of individual resource objects
It's complicated.
Resources
require a context in order to be destroyed, so the only solution would be to keep a list of all the living resources, and deallocate their internal OpenGL resources when the last context is destroyed.
But this leads to a question: if resources no longer control the lifetime of the shared context, when should this one be destroyed? Destroying it when no other context exists is not an option, we would lose all the loaded OpenGL resources (textures, shaders, fonts).
sf::Texture texture;
texture.LoadFromFile("toto.png");
sf::Texture screen;
{
sf::RenderTexture surface;
surface.Create(256, 256);
surface.Clear();
surface.Draw(sf::Sprite(texture));
surface.Display();
screen = surface.GetTexture();
}
// here, both "texture" and "screen" would be lost...
sf::RenderWindow window;
...
That's why I made it this way: I'm sure that at least one OpenGL context is existing as long as there are OpenGL resources alive.
I'm aware that my requirements for SFML are pretty high, probably higher than other OpenGL-based libraries, but this is what makes the S of SFML.