Skip to main content
Added more detail, fixed a couple typos.
Source Link

I think your overall approach is fine, assuming that everything works. I recommend ignoring your performance concerns until you can show that performance is bad (I got the impression that performance is a personal concern and not yet a technical one).

Your shader base class/interface MapData has a problem because it is an abstraction (there is no single way to map data for all shaders), and as such needs an abstract way to receive parameters. Here is one idea to consider:

Use an abstract parameter collection similar to the following:

//IShaderParameters.h
class IShaderParameters { 
    public:
        virtual ~IShaderParameters();
        TransformBuffer getTransformBuffer() const = 0;
        LightingBuffer getLightingBuffer() const = 0;  
}



//ShaderBase.h
//...
class ShaderBase {
//...
virtual void MapData(IShaderParameters* parameters);
//...
}

A default shader parameter class would extend IShaderParameterIShaderParameters for your general purpose shaders and specialized. Specialized shaders would receive specialized forms of IShaderParameterIShaderParameters., like so:

//WaterShaderParameters.h
//specialization extends the standard implementation
class WaterShaderParameters : public ShaderParametersBase { 
   public:
    //...
    WaterDataBuffer getWaterDataBuffer() const;
    //...
}

You'd need to guarantee that the caller knows which shader it's passing parameters to, but this is a problem that you already have.

I hope this helps. Good luck.

I think your overall approach is fine, assuming that everything works. I recommend ignoring your performance concerns until you can show that performance is bad (I got the impression that performance is a personal concern and not yet a technical one).

Your shader base class/interface MapData has a problem because it is an abstraction (there is no single way to map data for all shaders), and as such needs an abstract way to receive parameters. Here is one idea to consider:

Use an abstract parameter collection similar to the following:

//IShaderParameters.h
class IShaderParameters { 
    public:
        virtual ~IShaderParameters();
        TransformBuffer getTransformBuffer() const = 0;
        LightingBuffer getLightingBuffer() const = 0;  
}



//ShaderBase.h
//...
class ShaderBase {
//...
virtual void MapData(IShaderParameters* parameters);
//...
}

A default shader parameter class would extend IShaderParameter for your general purpose shaders and specialized shaders would receive specialized forms of IShaderParameter. You'd need to guarantee that the caller knows which shader it's passing parameters to, but this is a problem that you already have.

I hope this helps. Good luck.

I think your overall approach is fine, assuming that everything works. I recommend ignoring your performance concerns until you can show that performance is bad (I got the impression that performance is a personal concern and not yet a technical one).

Your shader base class/interface MapData has a problem because it is an abstraction (there is no single way to map data for all shaders), and as such needs an abstract way to receive parameters. Here is one idea to consider:

Use an abstract parameter collection similar to the following:

//IShaderParameters.h
class IShaderParameters { 
    public:
        virtual ~IShaderParameters();
        TransformBuffer getTransformBuffer() const = 0;
        LightingBuffer getLightingBuffer() const = 0;  
}



//ShaderBase.h
//...
class ShaderBase {
//...
virtual void MapData(IShaderParameters* parameters);
//...
}

A default shader parameter class would extend IShaderParameters for your general purpose shaders. Specialized shaders would receive specialized forms of IShaderParameters, like so:

//WaterShaderParameters.h
//specialization extends the standard implementation
class WaterShaderParameters : public ShaderParametersBase { 
   public:
    //...
    WaterDataBuffer getWaterDataBuffer() const;
    //...
}

You'd need to guarantee that the caller knows which shader it's passing parameters to, but this is a problem that you already have.

I hope this helps. Good luck.

Source Link

I think your overall approach is fine, assuming that everything works. I recommend ignoring your performance concerns until you can show that performance is bad (I got the impression that performance is a personal concern and not yet a technical one).

Your shader base class/interface MapData has a problem because it is an abstraction (there is no single way to map data for all shaders), and as such needs an abstract way to receive parameters. Here is one idea to consider:

Use an abstract parameter collection similar to the following:

//IShaderParameters.h
class IShaderParameters { 
    public:
        virtual ~IShaderParameters();
        TransformBuffer getTransformBuffer() const = 0;
        LightingBuffer getLightingBuffer() const = 0;  
}



//ShaderBase.h
//...
class ShaderBase {
//...
virtual void MapData(IShaderParameters* parameters);
//...
}

A default shader parameter class would extend IShaderParameter for your general purpose shaders and specialized shaders would receive specialized forms of IShaderParameter. You'd need to guarantee that the caller knows which shader it's passing parameters to, but this is a problem that you already have.

I hope this helps. Good luck.