relationship between the model and the renderer
- by acrilige
I tried to build a simple graphics engine, and faced with this problems:
i have a list of models that i need to draw, and object (renderer) that implements IRenderer interface with method DrawObject(Object* obj). Implementation of renderer depends on using graphics library (opengl/directx).
1st question: model should not know nothing about renderer implementation, but in this case where can i hold (cache) information that depends on renderer implementation? For example, if model have this definition:
class Model
{
public:
Model();
Vertex* GetVertices() const;
private:
Vertex* m_vertices;
};
what is the best way to cache, for example, vertex buffer of this model for dx11? Hold it in renderer object?
2nd question: what is the best way for model to say renderer HOW it must be rendered (for example with texture, bump mapping, or may be just in one color). I thought it can be done with flags, like this:
model-SetRenderOptions(RENDER_TEXTURE | RENDER_BUMPMAPPING | RENDER_LIGHTING);
and in Renderer::DrawModel method check for each flag.
But looks like it will become uncomfortable with the options count growth...