So I'm trying to design a system where I have this list of renderables
std::vector<Renederable*> renderList
Where Renderable is a base class that looks like
class Renderable
{
public:
Renderable();
virual ~Renderable();
VertexShader* vertShader;
PixelShader* pixShader;
}
Then other things like Sprites or Meshes can be derived from Renderable. Where these derived classes could have different properties
class Sprite : public Renderable
{
public:
Sprite();
~sprite();
Texture* texture;
}
Class Mesh : public Renderable
{
public:
Mesh();
~Mesh();
Texture* texture;
VertexBuffer* vertices;
}
Now my idea is when I actually want to try to render these items I would pass them to their specific renderer
for(std::vector<Renderable*>::iterator i = renderList.begin(); i != RenderList.end(); ++i)
{
//Psuedo code
if(*i == Sprite)
useSpriteRenderer(i);
else if(*i == Mesh)
useMeshRenderer(i);
}
I know I would have to cast the Renderable to either a Sprite or Mesh, but is this a terrible idea as a whole?
If I give Renderable a variable to hold the type, use of a enum or something, and then cast based on that would that work?
//psudeo code
if(*i->type == SPRITE_RENDERABLE)
useSpriteRenderer((Sprite)*i);
I know that there is dynamic_cast, but I have seen people say that this not very good for performance if you do it a lot
↧