]> git.tdb.fi Git - libs/gl.git/blob - source/renderable.h
Change the setup/finish_frame interface to be non-const
[libs/gl.git] / source / renderable.h
1 #ifndef MSP_GL_RENDERABLE_H_
2 #define MSP_GL_RENDERABLE_H_
3
4 #include <string>
5 #include <msp/geometry/boundingsphere.h>
6 #include "tag.h"
7
8 namespace Msp {
9 namespace GL {
10
11 class Matrix;
12 class Renderer;
13
14 /**
15 Base class for renderable objects.  Rendering is performed with the help of a
16 Renderer object.
17
18 The render methods take a Tag to identify a render pass.  It is most commonly
19 used together with Techniques and Pipelines to implement multipass rendering.
20
21 The setup_frame and finish_frame methods provide a mechanism for performing
22 once-per-frame operations.  This is most useful for effects, which may need to
23 do auxiliary rendering.  With complex rendering hierarchies, these methods may
24 be called multiple times for one frame, but it's guaranteed that no rendering
25 will occur before a setup_frame call or after a finish_frame call.
26 */
27 class Renderable
28 {
29 protected:
30         Renderable() { }
31 public:
32         virtual ~Renderable() { }
33
34         /** Returns a key used for grouping Renderables in an InstanceScene.  The
35         returned value is treated as opaque. */
36         virtual long get_instance_key() const { return 0; }
37
38         /** Returns the model matrix of the Renderable.  Null is returned if no such
39         matrix exists. */
40         virtual const Matrix *get_matrix() const { return 0; }
41
42         /** Returns a bounding sphere that completely encloses the Renderable.  The
43         bounding sphere is expressed in the renderable's coordinates.  Null is
44         returned if the bounding sphere cannot be determined. */
45         virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return 0; }
46
47         /** Called when starting to render a new frame. */
48         virtual void setup_frame(Renderer &) { }
49
50         /** Called when a complete frame has been rendered. */
51         virtual void finish_frame() { }
52
53         /** Renders the Renderable.  Implementors should take care to return the
54         renderer to the state it was in, for example by using Renderer::Push. */
55         virtual void render(Renderer &, const Tag & = Tag()) const = 0;
56 };
57
58 } // namespace Msp
59 } // namespace GL
60
61 #endif