]> git.tdb.fi Git - libs/gl.git/blob - source/render/renderable.h
Use default member initializers for simple types
[libs/gl.git] / source / render / renderable.h
1 #ifndef MSP_GL_RENDERABLE_H_
2 #define MSP_GL_RENDERABLE_H_
3
4 #include <msp/geometry/boundingsphere.h>
5 #include "tag.h"
6
7 namespace Msp {
8 namespace GL {
9
10 class Matrix;
11 class Renderer;
12
13 /**
14 Base class for renderable objects.  Rendering is performed with the help of a
15 Renderer object.
16
17 The render method takes a Tag to identify a render method.  It can be used with
18 a Technique to select alternative rendering methods, such as simplified shaders
19 for a depth-only shadow pass.
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() = default;
31 public:
32         virtual ~Renderable() = default;
33
34         /** Returns the model matrix of the Renderable.  Null is returned if no such
35         matrix exists.  The matrix should be in world space for some effects to work
36         correctly. */
37         virtual const Matrix *get_matrix() const { return 0; }
38
39         /** Returns a bounding sphere that completely encloses the Renderable.  The
40         bounding sphere is expressed in the renderable's coordinates.  Null is
41         returned if the bounding sphere cannot be determined. */
42         virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return 0; }
43
44         /** Called when starting to render a new frame. */
45         virtual void setup_frame(Renderer &) { }
46
47         /** Called when a complete frame has been rendered. */
48         virtual void finish_frame() { }
49
50         /** Renders the Renderable.  Implementors should take care to return the
51         renderer to the state it was in, for example by using Renderer::Push. */
52         virtual void render(Renderer &, Tag = Tag()) const = 0;
53 };
54
55 } // namespace Msp
56 } // namespace GL
57
58 #endif