]> git.tdb.fi Git - libs/gl.git/blob - source/object.h
Add class Renderable
[libs/gl.git] / source / object.h
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_GL_OBJECT_H_
9 #define MSP_GL_OBJECT_H_
10
11 #include <vector>
12 #include <msp/datafile/collection.h>
13 #include "objectpass.h"
14 #include "renderable.h"
15
16 namespace Msp {
17 namespace GL {
18
19 class Material;
20 class Mesh;
21 class ObjectInstance;
22 class Program;
23 class ProgramData;
24 class Texture;
25
26 /**
27 Stores data for a complete 3D object.  This includes a mesh, a shader and data
28 for it and a number of textures.  Only the mesh is mandatory, other components
29 are optional.
30
31 See also class ObjectInstance.
32 */
33 class Object: public Renderable
34 {
35 private:
36         std::vector<Mesh *> meshes;
37         std::vector<Texture *> textures;
38         std::map<std::string, ObjectPass> passes;
39         Material *material;
40         ObjectPass *normal_pass;
41
42 public:
43         class Loader: public DataFile::Loader
44         {
45         public:
46                 typedef DataFile::Collection Collection;
47
48         protected:
49                 Object &obj;
50                 Collection &coll;
51         private:
52                 std::vector<std::string> textures;
53         
54         public:
55                 Loader(Object &, Collection &);
56                 ~Loader();
57
58                 Object &get_object() const { return obj; }
59                 Collection &get_collection() const { return coll; }
60         private:
61                 void lod_mesh(unsigned, const std::string &);
62                 void material_inline();
63                 void mesh(const std::string &);
64                 void pass(const std::string &);
65                 void shader(const std::string &);
66                 void texture(const std::string &);
67         };
68
69         Object();
70         ~Object();
71
72         virtual bool has_pass(const std::string &) const;
73         const ObjectPass &get_pass(const std::string &) const;
74
75         /**
76         Renders the object.  If an ObjectInstance is provided, its hook functions
77         are called.
78         */
79         virtual void render() const;
80         virtual void render(const ObjectInstance &) const;
81         virtual void render(const std::string &) const;
82         virtual void render(const std::string &, const ObjectInstance &) const;
83
84         /**
85         Renders multiple instances of the object in one go.  This may be a
86         performance improvement, as the object-specific render setup only has to be
87         done once.
88         */
89         void render(const std::list<const ObjectInstance *> &) const;
90         void render(const std::string &, const std::list<const ObjectInstance *> &) const;
91 private:
92         void setup_render(const ObjectPass &) const;
93         void finish_render(const ObjectPass &) const;
94         void render(const ObjectPass &, const ObjectInstance *) const;
95         void render(const ObjectPass &, const std::list<const ObjectInstance *> &) const;
96 };
97
98 } // namespace GL
99 } // namespace Msp
100
101 #endif