pioneerspacesim/pioneer — pull request #1007 by robn (2012-02-23 09:59:30+00:00)
Title: Renderer state capture

Based on an idea in IRC yesterday. For use in cases where the current renderer state must be saved and restored (eg #1001).

Very simple. Each renderer provides a `PushState()` and `PopState()` that will somehow save and restore renderer state. For OpenGL its the normal matrix/attribute push/pop; for something else the renderer might have to carry its own stack. Whatever.

Client that needs to preserve state creates a `Renderer::StateTicket`, passing the renderer as an argument. This causes a call to the renderers `PushState()` and returns an object (the "ticket"). When the ticket object is destroyed, `PopState()` is called and the state is restored. Constructing the ticket object this way allows the following pattern:

```
{
Graphics::Renderer::StateTicket ticket(renderer);

renderer->SetViewport(...)
renderer->SetTransform(...)
renderer->DrawFoo(...)
}
```

When `ticket` goes out of scoped, the state is restored.

Patch includes a change to `ShipSpinnerWidget` showing how it work. This resolves the same problem resolved in #1001. There doesn't appear to be any other places in the code that can benefit from this directly right now, but its a useful tool.