Let say, for this example, that I have World class. World has collection of Models :
class World
{
public:
map<string, Model*> Models;
};
Model would be abstract class for all entities in application, for example car, ball, mountain, or cube.
And the question is - what's the best practice for managing effects for that models. Let say, that I've got 4 effect files : base1.fx, base2.fx, base3.fx, bas4.fx. Each of them has class interface, which might be bound to model ( IBaseEffect1, IBaseEffect2, IBaseEffect3, IBaseEffect4 ).
Now, should I consider each model independent, and do something like:
Cube1.Bind(IBaseEffect2);
Car.Bind(IBaseEffect3);
Where model would have ability to manage effect, so I would make:
World::Render()
{
foreach model -> Render();
}
Which is actual solution for my engine.
Or better would be to manage effects independent, and do something like:
IBaseEffect1.SetAsActual();
foreach Model which should be considered for effect1 -> Render();
IBaseEffect2.SetAsActual();
foreach Model which should be considered for effect2 -> Render();
etc...
Maybe my whole point of view is wrong, and it should be made other way ?
I think you should use both of your methods. That is:
model->Bind(effect);
Models which have to be rendered in a fixed order (e.g. transparent objects) should be processed in a different way unless all of them share the same effect.