3 This file is part of libmspgl
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #ifndef MSP_GL_OBJECT_H_
9 #define MSP_GL_OBJECT_H_
12 #include <msp/datafile/collection.h>
13 #include "objectpass.h"
14 #include "renderable.h"
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
31 See also class ObjectInstance.
33 class Object: public Renderable
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;
44 class Loader: public DataFile::Loader
47 typedef DataFile::Collection Collection;
53 std::vector<std::string> textures;
56 Loader(Object &, Collection &);
58 Object &get_object() const { return obj; }
59 Collection &get_collection() const { return coll; }
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 &);
74 virtual bool has_pass(const Tag &) const;
75 const ObjectPass &get_pass(const Tag &) const;
78 Renders the object. A tag can be provided to render a non-default pass.
80 virtual void render(const Tag &tag=Tag()) const;
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
87 virtual void render(const ObjectInstance &, const Tag &tag=Tag()) const;
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
95 template<typename Iter>
96 void render(Iter begin, Iter end, const Tag &tag=Tag()) const
97 { render(get_pass(tag), begin, end); }
99 void setup_render(const ObjectPass &) const;
100 void finish_render(const ObjectPass &) const;
101 void render(const ObjectPass &, const ObjectInstance *) const;
103 template<typename Iter>
104 void render(const ObjectPass &pass, Iter begin, Iter end) const
107 for(Iter i=begin; i!=end; ++i)
108 render_instance(pass, **i);
112 void render_instance(const ObjectPass &, const ObjectInstance &) const;