]> git.tdb.fi Git - libs/gl.git/blob - source/resources/resources.h
Check the flat qualifier from the correct member
[libs/gl.git] / source / resources / resources.h
1 #ifndef MSP_GL_RESOURCES_H_
2 #define MSP_GL_RESOURCES_H_
3
4 #include <msp/datafile/collection.h>
5 #include "texture.h"
6
7 namespace Msp {
8 namespace GL {
9
10 class Material;
11 class Mesh;
12 class Module;
13 class Program;
14 class ResourceManager;
15 class Scene;
16 class Texture2D;
17
18 /**
19 A collection class for GL resources.
20
21 The following types of objects can be loaded:
22 Animation                          .anim
23 Armature                           .arma
24 BasicMaterial (Material)           .mat
25 Camera                             .camera
26 DirectionalLight (Light)           .light
27 Font                               .font
28 KeyFrame                           .kframe
29 Lighting                           .lightn
30 Mesh                               .mesh
31 Module                             .glsl .spv
32 Object (Renderable)                .object
33 OccludedScene (Scene, Renderable)  .scene
34 OrderedScene (Scene, Renderable)   .scene
35 PbrMaterial (Material)             .mat
36 PointLight (Light)                 .light
37 SequenceTemplate                   .seq
38 Pose                               .pose
39 Program                            .shader
40 Sampler                            .samp
41 SimpleScene (Scene, Renderable)    .scene
42 Technique                          .tech
43 Texture1D (Texture)                .tex
44 Texture2D (Texture)                .tex .png .jpg
45 Texture3D (Texture)                .tex
46 TextureCube (Texture)              .tex
47 Texture2DArray (Texture)           .tex
48 UnlitMaterial (Material)           .mat
49 ZSortedScene (Scene, Renderable)   .scene
50
51 This class is normally used by deriving from it and adding any necessary data
52 sources in the derived class.
53
54 A ResourceManager can be set to manage objects derived from Resource.  Bulk
55 data for those objects will then be loaded in the background, without blocking
56 the main thread.
57 */
58 class Resources: virtual public DataFile::Collection
59 {
60 public:
61         class Loader: public DataFile::DerivedObjectLoader<Resources, Collection::Loader>
62         {
63         public:
64                 Loader(Resources &);
65
66         private:
67                 template<typename T, typename L = typename T::GenericLoader>
68                 void generic(const std::string &);
69         };
70
71 private:
72         template<typename T>
73         class GenericResourceLoader: public T::GenericLoader
74         {
75         private:
76                 Resources &resources;
77
78         public:
79                 GenericResourceLoader(Resources &r): T::GenericLoader(r), resources(r) { }
80
81         protected:
82                 virtual void type(const DataFile::Symbol &);
83         };
84
85         ResourceManager *resource_manager;
86
87         static Resources *global_resources;
88
89 public:
90         Resources(bool = true);
91         virtual ~Resources();
92
93         static Resources &get_global();
94         static const DataFile::CollectionSource &get_builtins();
95
96         void set_resource_manager(ResourceManager *);
97
98 protected:
99         template<typename T, typename L = typename T::GenericLoader>
100         T *create_generic(const std::string &);
101
102         Mesh *create_mesh(const std::string &);
103         Texture *create_texture(const std::string &);
104         Module *create_module(const std::string &);
105         Program *create_program(const std::string &);
106
107         template<typename T>
108         static void set_debug_name(const std::string &, T &);
109 };
110
111 } // namespace GL
112 } // namespace Msp
113
114 #endif