]> git.tdb.fi Git - libs/gltk.git/blob - source/partcache.h
Reuse meshes in PartCache to avoid buffer create/delete spam
[libs/gltk.git] / source / partcache.h
1 #ifndef MSP_GLTK_PARTCACHE_H_
2 #define MSP_GLTK_PARTCACHE_H_
3
4 #include <msp/gl/mesh.h>
5 #include <msp/gl/texture2d.h>
6
7 namespace Msp {
8 namespace GLtk {
9
10 class Part;
11
12 struct CachedPart
13 {
14         const Part *part;
15         const GL::Texture2D *texture;
16         GL::Mesh *mesh;
17
18         CachedPart();
19         ~CachedPart();
20 };
21
22 class PartCache
23 {
24 public:
25         typedef std::list<CachedPart> PartList;
26
27 private:
28         PartList parts;
29         PartList::iterator next;
30         PartList::iterator current;
31
32 public:
33         void begin_rebuild();
34         void insert_special(const Part &);
35         GL::Mesh &create_mesh(const Part &, const GL::Texture2D &);
36         void end_rebuild();
37
38         const PartList &get_parts() const { return parts; }
39 };
40
41 } // namespace GLtk
42 } // namespace Msp
43
44 #endif