• Advertisement
Sign in to follow this  

Decoupling rendering from entities

This topic is 3772 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everybody, I'm looking for a solution to decouple my rendering code from the actual entities, means that I want to use textures, effects etc depending on the current use, like that: - different shaders/textures for different quality settings - different shaders for special purposes (z-pass that just writes the depth into a texture) I think the strategy pattern will be useful here, but how would you guys implement this in a rendering engine? Something like this?
interface IEffectStrategy
{
    void LoadEffect(string name);
    void UnloadEffect();
    void SetParameter(string param, string value);
    void Update();
    void BeginDraw();
    void EndDraw();
}

class Entity : xxx
{
    public IEffectStrategy drawStategy;

    public void Update()
    {
        drawStrategy.SetParameter("worldMatrix", matWorld);
        drawStrategy.SetParameter("someOtherParam", param);
        drawStrategy.Update();
        ...
    }

    public void Draw()
    {
        drawStrategy.BeginDraw();

        // DrawIndexPrimitives etc ...
         
        drawStrategy.EndDraw();
    }
}

class Program
{
    class Method()
    {
        Entity car = new Entity();
        car.drawStategy = new HighDetailShader();
        // or
        car.drawStategy = new ZPassShader();
    
        ...
    }
}

How did you do this in your engine or what techniques would you guys suggest? regards

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement