]> git.tdb.fi Git - libs/gl.git/blob - source/object.h
Use DevIL for loading images
[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
15 namespace Msp {
16 namespace GL {
17
18 class Material;
19 class Mesh;
20 class ObjectInstance;
21 class Program;
22 class ProgramData;
23 class Texture;
24
25 /**
26 Stores data for a complete 3D object.  This includes a mesh, a shader and data
27 for it and a number of textures.  Only the mesh is mandatory, other components
28 are optional.
29
30 See also class ObjectInstance.
31 */
32 class Object
33 {
34 private:
35         std::vector<Mesh *> meshes;
36         std::vector<Texture *> textures;
37         std::map<std::string, ObjectPass> passes;
38         Material *material;
39         ObjectPass *normal_pass;
40
41 public:
42         class Loader: public DataFile::Loader
43         {
44         public:
45                 typedef DataFile::Collection Collection;
46
47         protected:
48                 Object &obj;
49                 Collection &coll;
50         private:
51                 std::vector<std::string> textures;
52         
53         public:
54                 Loader(Object &, Collection &);
55                 ~Loader();
56
57                 Object &get_object() const { return obj; }
58                 Collection &get_collection() const { return coll; }
59         private:
60                 void lod_mesh(unsigned, const std::string &);
61                 void material_inline();
62                 void mesh(const std::string &);
63                 void pass(const std::string &);
64                 void shader(const std::string &);
65                 void texture(const std::string &);
66         };
67
68         Object();
69         ~Object();
70
71         bool has_pass(const std::string &) const;
72         const ObjectPass &get_pass(const std::string &) const;
73
74         /**
75         Renders the object.  If an ObjectInstance is provided, its hook functions
76         are called.
77         */
78         void render(const ObjectInstance * =0) const;
79         void render(const std::string &, const ObjectInstance *) const;
80
81         /**
82         Renders multiple instances of the object in one go.  This may be a
83         performance improvement, as the object-specific render setup only has to be
84         done once.
85         */
86         void render(const std::list<const ObjectInstance *> &) const;
87         void render(const std::string &, const std::list<const ObjectInstance *> &) const;
88 private:
89         void setup_render(const ObjectPass &) const;
90         void finish_render(const ObjectPass &) const;
91         void render(const ObjectPass &, const ObjectInstance *) const;
92         void render(const ObjectPass &, const std::list<const ObjectInstance *> &) const;
93 };
94
95 } // namespace GL
96 } // namespace Msp
97
98 #endif