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