gramods
CallbackRenderer.hh
1 
2 #ifndef GRAMODS_GRAPHICS_CALLBACKRENDERER
3 #define GRAMODS_GRAPHICS_CALLBACKRENDERER
4 
5 #include <gmGraphics/Renderer.hh>
6 
7 BEGIN_NAMESPACE_GMGRAPHICS;
8 
21  : public Renderer {
22 
23 public:
24 
30  typedef std::function<void(void)> SetupFunction;
31 
38  typedef std::function<void(const Camera &, const Eigen::Affine3f &)>
40 
47  typedef std::function<void(
48  const Camera &, const Eigen::Affine3f &, float &, float &)>
50 
54  void render(const Camera &camera, const Eigen::Affine3f &Mm) override {
55  if (!has_been_setup) {
56  if (setup_function) setup_function();
57  has_been_setup = true;
58  }
59  if (render_function) render_function(camera, Mm);
60  }
61 
68  void getNearFar(const Camera &camera,
69  const Eigen::Affine3f &Mm,
70  float &near,
71  float &far) override {
72  if (!nearfar_function) return;
73  nearfar_function(camera, Mm, near, far);
74  }
75 
80  void setCallback(SetupFunction func) { setup_function = func; }
81 
86  void setCallback(RenderFunction func) { render_function = func; }
87 
92  void setCallback(NearFarFunction func) { nearfar_function = func; }
93 
94 private:
95 
96  SetupFunction setup_function;
97  RenderFunction render_function;
98  NearFarFunction nearfar_function;
99  bool has_been_setup = false;
100 
101 };
102 
103 END_NAMESPACE_GMGRAPHICS;
104 
105 #endif
A renderer that defers rendering to a callback function.
Definition: CallbackRenderer.hh:21
void setCallback(RenderFunction func)
Sets the callback that should be called upon calls to the render method.
Definition: CallbackRenderer.hh:86
void render(const Camera &camera, const Eigen::Affine3f &Mm) override
Performs rendering of 3D objects in the scene.
Definition: CallbackRenderer.hh:54
std::function< void(const Camera &, const Eigen::Affine3f &)> RenderFunction
The signature of the rendering function that provides the actual graphics.
Definition: CallbackRenderer.hh:39
void setCallback(NearFarFunction func)
Sets the callback that should be called to get optimal near and far plane distances.
Definition: CallbackRenderer.hh:92
std::function< void(void)> SetupFunction
The signature of a setup function that prepares a renderer.
Definition: CallbackRenderer.hh:30
void getNearFar(const Camera &camera, const Eigen::Affine3f &Mm, float &near, float &far) override
Extracts the currently optimal near and far plane distances.
Definition: CallbackRenderer.hh:68
void setCallback(SetupFunction func)
Sets the callback that should be called to set up GL for rendering.
Definition: CallbackRenderer.hh:80
std::function< void(const Camera &, const Eigen::Affine3f &, float &, float &)> NearFarFunction
The signature of an optional function that returns the currently optimal near and far plane distances...
Definition: CallbackRenderer.hh:49
The base of graphics Camera implementations.
Definition: Camera.hh:19
The base of graphics Renderer implementations.
Definition: Renderer.hh:17