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"
26 Stores data for a complete 3D object. An Object must always have a Mesh, and
27 may also have a Technique to determine its appearance. Textures and material
28 specified by the Technique may be overridden. Simple textured objects are also
29 possible without a Technique.
31 It is possible to use a single Object for rendering multiple identical or
32 similar objects. See class ObjectInstance.
34 class Object: public Renderable
37 std::vector<const Mesh *> meshes;
38 const Technique *technique;
39 std::vector<const Texture *> textures;
40 const Texture *main_texture;
41 const Material *material;
44 class Loader: public DataFile::Loader
47 typedef DataFile::Collection Collection;
54 Loader(Object &, Collection &);
56 Object &get_object() const { return obj; }
57 Collection &get_collection() const { return coll; }
59 virtual void finish();
60 void lod_mesh(unsigned, const std::string &);
61 void material_inline();
62 void mesh(const std::string &);
63 void shader_texture(const std::string &);
64 void technique(const std::string &);
65 void texture(const std::string &);
71 const Technique *get_technique() const { return technique; }
73 virtual bool has_pass(const Tag &) const;
76 Renders the object. A tag can be provided to render a non-default pass.
78 virtual void render(const Tag &tag=Tag()) const;
81 Renders the object with an instance. The instance's hook functions are
82 called before and after drawing the mesh. A tag may also be given to render
85 virtual void render(const ObjectInstance &, const Tag &tag=Tag()) const;
88 Renders multiple instances of the object in one go. This may improve
89 performance, as the object-specific render setup only has to be done once.
90 Each instance's hook functions will be called before and after drawing the
93 template<typename Iter>
94 void render(Iter begin, Iter end, const Tag &tag=Tag()) const
96 const ObjectPass *pass=get_pass(tag);
98 for(Iter i=begin; i!=end; ++i)
99 render_instance(**i, tag);
103 const ObjectPass *get_pass(const Tag &) const;
104 void setup_render(const ObjectPass *) const;
105 void finish_render(const ObjectPass *) const;
106 void render_instance(const ObjectInstance &, const Tag &) const;