]> git.tdb.fi Git - libs/gl.git/commitdiff
Add a utility class for switching renderables
authorMikko Rasa <tdb@tdb.fi>
Thu, 5 Jul 2018 18:29:29 +0000 (21:29 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 5 Jul 2018 18:29:50 +0000 (21:29 +0300)
source/slot.cpp [new file with mode: 0644]
source/slot.h [new file with mode: 0644]

diff --git a/source/slot.cpp b/source/slot.cpp
new file mode 100644 (file)
index 0000000..07dabf0
--- /dev/null
@@ -0,0 +1,45 @@
+#include <msp/gl/renderer.h>
+#include "slot.h"
+
+namespace Msp {
+namespace GL {
+
+Slot::Slot():
+       renderable(0)
+{ }
+
+void Slot::set(Renderable *r)
+{
+       renderable = r;
+}
+
+const Matrix *Slot::get_matrix() const
+{
+       return renderable ? renderable->get_matrix() : 0;
+}
+
+const Geometry::BoundingSphere<float, 3> *Slot::get_bounding_sphere() const
+{
+       return renderable ? renderable->get_bounding_sphere() : 0;
+}
+
+void Slot::setup_frame(Renderer &renderer)
+{
+       if(renderable)
+               renderable->setup_frame(renderer);
+}
+
+void Slot::finish_frame()
+{
+       if(renderable)
+               renderable->finish_frame();
+}
+
+void Slot::render(Renderer &renderer, const Tag &tag) const
+{
+       if(renderable)
+               renderer.render(*renderable, tag);
+}
+
+} // namespace GL
+} // namespace Msp
diff --git a/source/slot.h b/source/slot.h
new file mode 100644 (file)
index 0000000..ad86301
--- /dev/null
@@ -0,0 +1,34 @@
+#ifndef MSP_GL_SLOT_H_
+#define MSP_GL_SLOT_H_
+
+#include "renderable.h"
+
+namespace Msp {
+namespace GL {
+
+/**
+A container for a single renderable.  Can be used if a part of the scene graph
+needs to be switched without affecting the rest.
+*/
+class Slot: public Renderable
+{
+private:
+       Renderable *renderable;
+
+public:
+       Slot();
+
+       void set(Renderable *);
+       Renderable *get() const { return renderable; }
+
+       virtual const Matrix *get_matrix() const;
+       virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const;
+       virtual void setup_frame(Renderer &);
+       virtual void finish_frame();
+       virtual void render(Renderer &, const Tag &) const;
+};
+
+} // namespace GL
+} // namespace Msp
+
+#endif