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