Created
February 22, 2012 08:56
-
-
Save johnbartholomew/1883478 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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