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