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?
(Disclaimer: I'm neither a GameEngine nor a C++ performance expert, so take this with a grain of salt)
There are some existing game engines that use the visitor approach, e.g. GamePlay3D. For performance reasons, you probably should exclude non-visible objects from the rendering routine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With