Skip to content

Instantly share code, notes, and snippets.

@johnbartholomew
Created February 22, 2012 08:56
Show Gist options
  • Save johnbartholomew/1883478 to your computer and use it in GitHub Desktop.
Save johnbartholomew/1883478 to your computer and use it in GitHub Desktop.
// simplest version
struct StateCapturer {
StateCapturer() {
glPushAttrib(...);
glPushMatrix(...);
glPushTheWholeDamnWorld();
}
~StateCapturer() {
glPopEverything();
}
};
// probably the most practical version
struct StateCapturer {
StateCapturer(Renderer *r): m_renderer(r) {
assert(r);
m_renderer->PushState();
}
~StateCapturer() {
m_renderer->PopState();
}
private:
Renderer *m_renderer;
};
// alternative
struct Renderer {
...
StateCapturer *CaptureState() { return new ConcreteStateCapturer; }
};
void SomeCodeUsingA(Renderer *renderer) {
ScopedPtr<StateCapturer> saveState(renderer->CaptureState());
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment