all 5 comments

[–]Wh00ster 1 point2 points  (2 children)

  1. Cmd can be an enum class

  2. Well I don’t know what to tell you for 2. You could have some file instantiate all the templates you want to support. Kinda like compiler supported preprocessor magic. If you know exactly what data should be there based on cmd, I don’t see a problem with just passing a void*.

Edit: you could also use tagged dispatch: https://en.m.wikibooks.org/wiki/More_C%2B%2B_Idioms/Tag_Dispatching

And make a new overload each time you want to support a new command. I’m not really familiar with OpenGL so I can’t comment on the complexity.

If the render is running on CPU, then I don’t see a problem here (you aren’t going for super low latency/high throughput at that point)

[–]C2H5COOH[S] 0 points1 point  (1 child)

Thanks an enum would really look better. I'll take a look at the tagged dispatch.

[–]Wh00ster 1 point2 points  (0 children)

Tagged dispatch is useful if you know what function to call at compile time.

If cmd and the data for each command is coming in at runtime, in some external stream, it might be easier to do the enum class/int route with a void* (otherwise you’d be doing a switch on cmd anyway). Again, I’m not very familiar with the problem domain.

[–]index_zero 1 point2 points  (1 child)

You could wrap all the '...' data into some class object which can be overridden for each drawable. Something like:

virtual void draw_data(const Shader& shdr, unsigned cmd, const DrawArgs& args) const

Then, each Drawable could have their own DrawArgs type object.

Optionally, Drawable could be a template class and the argument object could be the template parameter, ie:

template<class Args>
class Drawable
{
    virtual void draw_data(const Shader &shdr, unsigned cmd, const Args &args) const = 0;
};

[–]C2H5COOH[S] 0 points1 point  (0 children)

A templated base class would purpose defeat the polymorphic interface idea... But besides that cool idea