Friends | |
void | sphere_revolve_cb (void *data, const GLUvec4 *position, const GLUvec4 *normal, const GLUvec4 *tangent, const GLUvec4 *uv) |
void | sphere_begin_cb (void *data, GLenum mode) |
void | sphere_index_cb (void *data, unsigned index) |
void | sphere_end_cb (void *data) |
GLUsphereProducer decorator to implement call-backs
To generate the sphere data, the GLUsphereProducer
class interfaces with various C functions that use a call-back mechanism. These call-backs are analogous the emit_vertex
, emit_begin
, emit_index
, and emit_end
methods that GLUsphereProducer
subclasses will provide.
However, these methods are all protected
. As a result the non-class call-back functions cannot call these methods unless they are friend
functions. It is undesireable to expose the implementation detail in the application-facing header file. This can be worked around by creating a dummy subclass of GLUsphereProducer
that only contains the friend
function declarations. Pointers to GLUsphereProducer
objects can be cast to pointers to GLUsphereFriend
objects without side-effect.
This is arguably a mis-use of the "decorator" pattern, but it is the most efficient way to do this.