Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
struct Renderable { virtual ~Renderable() {} };
struct SelfRenderable : Renderable {
virtual void Render(Renderer& render) = 0;
};
class Renderer {
com_ptr<ID3D10Device> device;
public:
std::unordered_map<std::type_index, std::function<void(Renderer& renderer, const Renderable& renderable)>> rendering_functions;
void Render(Renderable& renderable) {
if (rendering_functions.find(typeid(renderable)) ! rendering_functions.end())
return rendering_functions[typeid(renderable)](*this, renderable);
if (auto self = dynamic_cast<SelfRenderable*>(&renderable))
return self->Render(*this);
assert(false);
}
void RenderText(std::string text, Rectangle where) { ... }
void RenderImage(Image i, Rectangle where) { ... }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.