]> git.tdb.fi Git - libs/gl.git/blob - source/renderable.h
Fix various issues with constant condition elimination
[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 method takes a Tag to identify a render pass.  It can be used with
19 a Technique to select alternative rendering methods, such as simplified shaders
20 for a depth-only shadow pass.
21
22 The setup_frame and finish_frame methods provide a mechanism for performing
23 once-per-frame operations.  This is most useful for effects, which may need to
24 do auxiliary rendering.  With complex rendering hierarchies, these methods may
25 be called multiple times for one frame, but it's guaranteed that no rendering
26 will occur before a setup_frame call or after a finish_frame call.
27 */
28 class Renderable
29 {
30 protected:
31         Renderable() { }
32 public:
33         virtual ~Renderable() { }
34
35         /** Returns a key used for grouping Renderables in an InstanceScene.  The
36         returned value is treated as opaque. */
37         virtual long get_instance_key() const { return 0; }
38
39         /** Returns the model matrix of the Renderable.  Null is returned if no such
40         matrix exists.  The matrix should be in world space for some effects to work
41         correctly. */
42         virtual const Matrix *get_matrix() const { return 0; }
43
44         /** Returns a bounding sphere that completely encloses the Renderable.  The
45         bounding sphere is expressed in the renderable's coordinates.  Null is
46         returned if the bounding sphere cannot be determined. */
47         virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return 0; }
48
49         /** Called when starting to render a new frame. */
50         virtual void setup_frame(Renderer &) { }
51
52         /** Called when a complete frame has been rendered. */
53         virtual void finish_frame() { }
54
55         /** Renders the Renderable.  Implementors should take care to return the
56         renderer to the state it was in, for example by using Renderer::Push. */
57         virtual void render(Renderer &, const Tag & = Tag()) const = 0;
58 };
59
60 } // namespace Msp
61 } // namespace GL
62
63 #endif