Wrapping an opengl object into a c++ class with copying -
how done?
for example might have texture class. of course hold gluint id, , maybe other fields such width , height. when object needs copied whatever reason, user-defined copy constructor needed.
now, in case of opengl texture, possible copy texture object. shader programs, or fbos? these can't copied easily. how people go doing this? should reference counted? should copying disabled on objects? should copying disabled on objects can't copied?
what best way go this? in advance answers.
for texture there may point copying it, shader object less (in experience). objects copying makes sense, don't want want make explicit.
either use wrapper class by-value (so handle opengl entity) , uses reference counting internally, or consider wrapper class instance own opengl entity , use reference counting on wrapper class (using std::shared_ptr example).
in latter case implement copy-constructor on entities makes sense. however, in order avoid unintentional use resort private constructor , public static factory function on entity returns new instance smart pointer, not mistakenly used by-value. in case makes more sense have explicit "copy/clone" member function (easier use , allows polymorphism).
in former case copy-constructor increments reference count, need add explicit member copying appropriate anyway.
i go latter option way... i'm used passing resource-intensive objects around smart pointers , don't see point in reimplementing functionality in custom handles.
Comments
Post a Comment