]> git.tdb.fi Git - libs/gl.git/blob - source/render/renderable.h
Move WindowView::render to the backend
[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 things which can be rendered.  Rendering is performed with the
15 help of the Renderer class.
16
17 The tag parameter of render() can be used to choose between different render
18 methods, such as simplified shaders for a depth-only shadow pass.  Typically
19 tags are defined using a Sequence.
20
21 The setup_frame() and finish_frame() functions can be overridden to perform
22 once-per-frame operations.  This is most useful for effects, which may need to
23 prepare textures or other data before actual rendering happens.  With complex
24 rendering graphs, these functions may be called multiple times for one frame,
25 but it's guaranteed that no render() calls will occur before a setup_frame()
26 call or after a finish_frame() call.
27 */
28 class Renderable
29 {
30 protected:
31         Renderable() = default;
32 public:
33         virtual ~Renderable() = default;
34
35         /** Returns the model matrix of the Renderable.  Null is returned if no such
36         matrix exists.  The matrix should be in world space for some effects to work
37         correctly. */
38         virtual const Matrix *get_matrix() const { return 0; }
39
40         /** Returns a bounding sphere that completely encloses the Renderable.  The
41         bounding sphere is expressed in the renderable's coordinates.  Null is
42         returned if the bounding sphere cannot be determined. */
43         virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return 0; }
44
45         /** Called when starting to render a new frame. */
46         virtual void setup_frame(Renderer &) { }
47
48         /** Called when a complete frame has been rendered. */
49         virtual void finish_frame() { }
50
51         /** Renders the Renderable.  Subclasses should take care to return the
52         renderer to the state it was in, for example by using Renderer::Push. */
53         virtual void render(Renderer &, Tag = Tag()) const = 0;
54 };
55
56 } // namespace Msp
57 } // namespace GL
58
59 #endif