]> git.tdb.fi Git - libs/gl.git/blob - source/object.h
Separate main and shader textures in Object
[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<const Mesh *> meshes;
37         std::vector<const Texture *> textures;
38         const Texture *main_texture;
39         std::map<unsigned, ObjectPass> passes;
40         const Material *material;
41         ObjectPass *normal_pass;
42
43 public:
44         class Loader: public DataFile::Loader
45         {
46         public:
47                 typedef DataFile::Collection Collection;
48
49         protected:
50                 Object &obj;
51                 Collection &coll;
52         private:
53                 std::vector<std::string> textures;
54         
55         public:
56                 Loader(Object &, Collection &);
57
58                 Object &get_object() const { return obj; }
59                 Collection &get_collection() const { return coll; }
60         private:
61                 virtual void finish();
62                 void lod_mesh(unsigned, const std::string &);
63                 void material_inline();
64                 void mesh(const std::string &);
65                 void pass(const std::string &);
66                 void shader(const std::string &);
67                 void shader_texture(const std::string &);
68                 void texture(const std::string &);
69         };
70
71         Object();
72         ~Object();
73
74         virtual bool has_pass(const Tag &) const;
75         const ObjectPass &get_pass(const Tag &) const;
76
77         /**
78         Renders the object.  A tag can be provided to render a non-default pass.
79         */
80         virtual void render(const Tag &tag=Tag()) const;
81
82         /**
83         Renders the object with an instance.  The instance's hook functions are
84         called before and after drawing the mesh.  A tag may also be given to render
85         a non-default pass.
86         */
87         virtual void render(const ObjectInstance &, const Tag &tag=Tag()) const;
88
89         /**
90         Renders multiple instances of the object in one go.  This may improve
91         performance, as the object-specific render setup only has to be done once.
92         Each instance's hook functions will be called before and after drawing the
93         mesh.
94         */
95         void render(const std::list<const ObjectInstance *> &, const Tag &tag=Tag()) const;
96 private:
97         void setup_render(const ObjectPass &) const;
98         void finish_render(const ObjectPass &) const;
99         void render(const ObjectPass &, const ObjectInstance *) const;
100         void render(const ObjectPass &, const std::list<const ObjectInstance *> &) const;
101 };
102
103 } // namespace GL
104 } // namespace Msp
105
106 #endif