Visitor-pattern vs inheritance for rendering
        Posted  
        
            by 
                akaltar
            
        on Game Development
        
        See other posts from Game Development
        
            or by akaltar
        
        
        
        Published on 2013-10-23T12:34:50Z
        Indexed on 
            2013/10/23
            16:11 UTC
        
        
        Read the original article
        Hit count: 285
        
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.
© Game Development or respective owner