Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

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 SOSO but got no proper answers.

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.

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.

Replacing 'design' tag as per http://meta.gamedev.stackexchange.com/a/167/40264.
Link
Vaillancourt
  • 16.4k
  • 17
  • 56
  • 61
Tweeted twitter.com/#!/StackGameDev/status/393031913692491776
Source Link
akaltar
  • 1.7k
  • 14
  • 26

Visitor-pattern vs inheritance for rendering

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.