Visitor-pattern vs inheritance for rendering
- by akaltar
I have a game engine that currently uses inheritance to provide a generic interface to do rendering:
class renderable
{
public:
void render();
};
Each class calls the gl_* functions itself, this makes the code hard to optimize and hard to implement something like setting the quality of rendering:
class sphere : public renderable
{
public:
void render()
{
glDrawElements(...);
}
};
I was thinking about implementing a system where I would create a Renderer class that would render my objects:
class sphere
{
void render( renderer* r )
{
r->renderme( *this );
}
};
class renderer
{
renderme( sphere& sphere )
{
// magically get render resources here
// magically render a sphere here
}
};
My main problem is where should I store the VBOs and where should I Create them when using this method?
Should I even use this approach or stick to the current one, perhaps something else?
PS: I already asked this question on SO but got no proper answers.