]> git.tdb.fi Git - libs/gltk.git/blob - source/partcache.h
71684738f0980922de8db5346d88249f53a058b5
[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() = default;
20         CachedPart(CachedPart &&);
21         CachedPart &operator=(CachedPart &&);
22         ~CachedPart();
23 };
24
25 class MSPGLTK_API PartCache
26 {
27 public:
28         class Rebuild
29         {
30         private:
31                 PartCache &cache;
32
33         public:
34                 Rebuild(PartCache &c): cache(c) { cache.begin_rebuild(); }
35                 ~Rebuild() { cache.end_rebuild(); }
36         };
37
38 private:
39         bool rebuilding = false;
40         std::vector<CachedPart> parts;
41         std::vector<CachedPart>::iterator next;
42         std::vector<CachedPart>::iterator current;
43
44 public:
45         void begin_rebuild();
46         void insert_special(const Part &);
47         GL::Mesh &create_mesh(const Part &, const GL::Texture2D &);
48         void end_rebuild();
49
50         const std::vector<CachedPart> &get_parts() const { return parts; }
51 };
52
53 } // namespace GLtk
54 } // namespace Msp
55
56 #endif