]> git.tdb.fi Git - libs/gl.git/blob - source/renderable.h
Notify Renderables about the start and end of a frame
[libs/gl.git] / source / renderable.h
1 #ifndef MSP_GL_RENDERABLE_H_
2 #define MSP_GL_RENDERABLE_H_
3
4 #include <string>
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.  All Renderables must support rendering with
15 a Renderer, and may optionally provide support for standalone rendering.
16
17 The render methods take a Tag to identify a render pass.  It is most commonly
18 used together with Techniques and Pipelines to implement multipass rendering.
19
20 The setup_frame and finish_frame methods provide a mechanism for performing
21 once-per-frame operations.  This is most useful for effects, which may need to
22 do auxiliary rendering.  With complex rendering hierarchies, these methods may
23 be called multiple times for one frame, but it's guaranteed that no rendering
24 will occur before a setup_frame call or after a finish_frame call.
25 */
26 class Renderable
27 {
28 protected:
29         Renderable() { }
30 public:
31         virtual ~Renderable() { }
32
33         /** Returns a key used for grouping Renderables in an InstanceScene.  The
34         returned value is treated as opaque. */
35         virtual long get_instance_key() const { return 0; }
36
37         /** Returns the model matrix of the Renderable.  Null is returned if no such
38         matrix exists. */
39         virtual const Matrix *get_matrix() const { return 0; }
40
41         /** Called when starting to render a new frame. */
42         virtual void setup_frame() const { }
43
44         /** Called when a complete frame has been rendered. */
45         virtual void finish_frame() const { }
46
47         /** Renders the renderable without a renderer.  This can be convenient in
48         some simple cases, but most renderables don't need to implement this
49         method. */
50         virtual void render(const Tag & = Tag()) const;
51
52         /** Renders the renderable.  Implementors should take care to return the
53         renderer to the state it was in, for example by using Renderer::Push. */
54         virtual void render(Renderer &, const Tag & = Tag()) const = 0;
55 };
56
57 } // namespace Msp
58 } // namespace GL
59
60 #endif