]> git.tdb.fi Git - libs/gl.git/blobdiff - source/renderable.h
Merge branch 'animation-rework'
[libs/gl.git] / source / renderable.h
index c055cefa65b989047ff0b324ab53259204ac77c1..6e1505ca5a728c0ac1b012eb797cf00c84321ff4 100644 (file)
@@ -2,13 +2,29 @@
 #define MSP_GL_RENDERABLE_H_
 
 #include <string>
+#include <msp/geometry/boundingsphere.h>
 #include "tag.h"
 
 namespace Msp {
 namespace GL {
 
+class Matrix;
 class Renderer;
 
+/**
+Base class for renderable objects.  Rendering is performed with the help of a
+Renderer object.
+
+The render method takes a Tag to identify a render pass.  It can be used with
+a Technique to select alternative rendering methods, such as simplified shaders
+for a depth-only shadow pass.
+
+The setup_frame and finish_frame methods provide a mechanism for performing
+once-per-frame operations.  This is most useful for effects, which may need to
+do auxiliary rendering.  With complex rendering hierarchies, these methods may
+be called multiple times for one frame, but it's guaranteed that no rendering
+will occur before a setup_frame call or after a finish_frame call.
+*/
 class Renderable
 {
 protected:
@@ -16,11 +32,29 @@ protected:
 public:
        virtual ~Renderable() { }
 
-       /** Returns a key used for grouping Renderables in an InstanceScene. */
+       /** Returns a key used for grouping Renderables in an InstanceScene.  The
+       returned value is treated as opaque. */
        virtual long get_instance_key() const { return 0; }
 
-       virtual void render(const Tag & = Tag()) const;
-       virtual void render(Renderer &, const Tag & = Tag()) const;
+       /** Returns the model matrix of the Renderable.  Null is returned if no such
+       matrix exists.  The matrix should be in world space for some effects to work
+       correctly. */
+       virtual const Matrix *get_matrix() const { return 0; }
+
+       /** Returns a bounding sphere that completely encloses the Renderable.  The
+       bounding sphere is expressed in the renderable's coordinates.  Null is
+       returned if the bounding sphere cannot be determined. */
+       virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return 0; }
+
+       /** Called when starting to render a new frame. */
+       virtual void setup_frame(Renderer &) { }
+
+       /** Called when a complete frame has been rendered. */
+       virtual void finish_frame() { }
+
+       /** Renders the Renderable.  Implementors should take care to return the
+       renderer to the state it was in, for example by using Renderer::Push. */
+       virtual void render(Renderer &, const Tag & = Tag()) const = 0;
 };
 
 } // namespace Msp