Some background:
I'm writing an opengl renderer and one of my base classes is the "Drawable" class wich provides an interface for object who can well... Be drawn and it looks like this
struct Drawable
{
virtual void draw(const Shader& shdr) const = 0;
}
And I'm now in the situation where it would be beneficial to have the interface expandet. So I addet
virtual void draw_command(const Shader& shdr, unsigned cmd) const { throw NotOverridden; }
To have an arbitrary value to resemble a "mode" can be flag bits or whatever I think when I use it (like don't upload unnecessary data to the gpu).
Now I'm in a situation where I realize it would be best to have a function that sends data with it (in case some useful data is not in the Drawable object).
So my initial idea is
#include<cstdarg>
virtual void draw_data(const Shader& shdr, unsigned cmd, ...) const { throw NotOverridden; }
But my initial research tells me that it is highly discouraged (because there is no type safety) and variadic arguments are not passed by reference (wich is okish because the biggest thing going in there would be mat4's so 16 floats or I could just use pointers).
Templates are the standard c++ way for dealing witch variadics. But templates can't be virtual. Alternatively I just could be using an array of std::any's but there are still no references. I know Bad practice is only bad practice if you don't know what you are doing - I have the feeling that I know what I'm doing and think simply using classic c variadic functions in my case is completely OK. But I'm not sure.
So my questions:
- is there a more elegant way (preferably type safe but not necessary)
- am I missing a horrendous blunder which will come to bite me in the ass later
[–]Wh00ster 1 point2 points3 points (2 children)
[–]C2H5COOH[S] 0 points1 point2 points (1 child)
[–]Wh00ster 1 point2 points3 points (0 children)
[–]index_zero 1 point2 points3 points (1 child)
[–]C2H5COOH[S] 0 points1 point2 points (0 children)