I really cannot decide what option is the best, I see plenty of down/upsides to both approaches and right now I’m undecided.
For example;
class DX11GBuffer
{
public:
DX11GBuffer(ID3D11DevicePtr device, ID3D11DeviceContextPtr context, D3D11_TEXTURE2D_DESC backbufferTextureDesc);
~DX11GBuffer();
void BindForGeometryStage(ID3D11DepthStencilViewPtr dsv);
// ...
}
“dsv” is not owned by the object and thus passed every frame, but it could just aswell be passed as a argument in the constructor and stored seeing as it is a smart pointer.
I guess what I am getting at is I understand there are pitfalls for keeping too much state in an object but also passing so much as function arguments means a whole lot of ASCII. Likewise defining “argument objects”, collection of data for functions, seems to add alot of overhead aswell if it is to be applied everywhere as a rule of thumb.
I guess I am looking some general guidelines on when to pass as argument vs when to store as member.
3
Member variables are variables are a “has a” relationship (the rectangle has a width). If the object does not have the variable then it should be passed into it to be used where required, if it’s related to the object itself then it should be stored in the object.
A quick way to test the relation could be seeing how much that object uses the variable. If you use it in just one unit of code, leave it as it is (being passed in) however if multiple functions within that object make use of it then storing it as a member variable would probably make more sense.
2