]> git.tdb.fi Git - libs/gl.git/blob - source/objectinstance.h
Refresh lighting and culling uniforms if the camera changes in pop_state
[libs/gl.git] / source / objectinstance.h
1 #ifndef MSP_GL_OBJETCINSTANCE_H_
2 #define MSP_GL_OBJETCINSTANCE_H_
3
4 #include <string>
5 #include "object.h"
6 #include "renderable.h"
7
8 namespace Msp {
9 namespace GL {
10
11 class ProgramData;
12
13 /**
14 Represents a single instance of an Object.  A derived class can overload the
15 hook functions to specify a model matrix and other instance-specific parameters
16 for the rendered objects.
17
18 ObjectInstances can benefit from being put in an InstanceScene, which will
19 render all instances of the same object consecutively.
20 */
21 class ObjectInstance: public Renderable
22 {
23 protected:
24         const Object &object;
25
26 public:
27         ObjectInstance(const Object &);
28
29         const Object &get_object() const { return object; }
30         virtual long get_instance_key() const { return reinterpret_cast<long>(&object); }
31
32         virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return object.get_bounding_sphere(); }
33
34         virtual void render(const Tag &tag = Tag()) const;
35         virtual void render(Renderer &, const Tag & = Tag()) const;
36
37         /** Hook function, called from Object just before rendering the mesh.
38         Renderer state will have been pushed before this is called. */
39         virtual void setup_render(Renderer &, const Tag &) const { }
40
41         /** Hook function, called from Object right after rendering the mesh.  Since
42         Object takes care of pushing Renderer state, this rarely needs to do
43         anything. */
44         virtual void finish_render(Renderer &, const Tag &) const { }
45
46         virtual unsigned get_level_of_detail(const Renderer &) const { return 0; }
47 };
48
49 } // namespace GL
50 } // namespaec Msp
51
52 #endif