]> git.tdb.fi Git - libs/gltk.git/blob - source/partcache.h
137bce4c37539a8c032f27b36cff0c35afc89f58
[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 #include "mspgltk_api.h"
7
8 namespace Msp {
9 namespace GLtk {
10
11 class Part;
12
13 struct CachedPart
14 {
15         const Part *part = nullptr;
16         const GL::Texture2D *texture = nullptr;
17         GL::Mesh *mesh = nullptr;
18
19         ~CachedPart();
20 };
21
22 class MSPGLTK_API PartCache
23 {
24 public:
25         class Rebuild
26         {
27         private:
28                 PartCache &cache;
29
30         public:
31                 Rebuild(PartCache &c): cache(c) { cache.begin_rebuild(); }
32                 ~Rebuild() { cache.end_rebuild(); }
33         };
34
35         typedef std::list<CachedPart> PartList;
36
37 private:
38         bool rebuilding = false;
39         PartList parts;
40         PartList::iterator next;
41         PartList::iterator current;
42
43 public:
44         void begin_rebuild();
45         void insert_special(const Part &);
46         GL::Mesh &create_mesh(const Part &, const GL::Texture2D &);
47         void end_rebuild();
48
49         const PartList &get_parts() const { return parts; }
50 };
51
52 } // namespace GLtk
53 } // namespace Msp
54
55 #endif