Skip to content

Instantly share code, notes, and snippets.

@Gerjo
Created June 2, 2015 14:10
Show Gist options
  • Save Gerjo/7d3d9eaae71aef371410 to your computer and use it in GitHub Desktop.
Save Gerjo/7d3d9eaae71aef371410 to your computer and use it in GitHub Desktop.
Abusing static local variables?
class Renderer {
public:
void Cube(Mat44 transform, Canvas canvas) {
// bunch of OpenGL calls.
}
// Overload without a texture.
void cube(Mat44 transform) {
// Generate a white texture, once.
static Canvas white = ([](){
Canvas canvas(16, 16);
canvas.begin();
canvas.rectangle(0, 0, canvas.width, canvas.height);
canvas.fill(Color::White);
return canvas;
}());
// Call the usual routine, along with a white texture.
cube(transform, white);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment