]> git.tdb.fi Git - libs/gl.git/blob - source/renderable.h
Add a method of getting the model matrix of a Renderable
[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 class Renderable
21 {
22 protected:
23         Renderable() { }
24 public:
25         virtual ~Renderable() { }
26
27         /** Returns a key used for grouping Renderables in an InstanceScene.  The
28         returned value is treated as opaque. */
29         virtual long get_instance_key() const { return 0; }
30
31         /** Returns the model matrix of the Renderable.  Null is returned if no such
32         matrix exists. */
33         virtual const Matrix *get_matrix() const { return 0; }
34
35         /** Renders the renderable without a renderer.  This can be convenient in
36         some simple cases, but most renderables don't need to implement this
37         method. */
38         virtual void render(const Tag & = Tag()) const;
39
40         /** Renders the renderable.  Implementors should take care to return the
41         renderer to the state it was in, for example by using Renderer::Push. */
42         virtual void render(Renderer &, const Tag & = Tag()) const = 0;
43 };
44
45 } // namespace Msp
46 } // namespace GL
47
48 #endif