Created
June 2, 2015 14:10
-
-
Save Gerjo/7d3d9eaae71aef371410 to your computer and use it in GitHub Desktop.
Abusing static local variables?
This file contains hidden or 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
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