]> git.tdb.fi Git - libs/gl.git/blob - source/resources/resources.h
Update and improve documentation
[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         bool srgb_conversion;
86         ResourceManager *resource_manager;
87
88         static Resources *global_resources;
89
90 public:
91         Resources(bool = true);
92         virtual ~Resources();
93
94         static Resources &get_global();
95         static const DataFile::CollectionSource &get_builtins();
96
97         /** Enables or disables sRGB conversion.  If enabled, textures and material
98         colors are converted from sRGB to linear color space when loaded. */
99         DEPRECATED void set_srgb_conversion(bool);
100
101         DEPRECATED bool get_srgb_conversion() const { return srgb_conversion; }
102
103         void set_resource_manager(ResourceManager *);
104
105 protected:
106         template<typename T, typename L = typename T::GenericLoader>
107         T *create_generic(const std::string &);
108
109         Mesh *create_mesh(const std::string &);
110         Texture *create_texture(const std::string &);
111         Module *create_module(const std::string &);
112         Program *create_program(const std::string &);
113
114         template<typename T>
115         static void set_debug_name(const std::string &, T &);
116 };
117
118 } // namespace GL
119 } // namespace Msp
120
121 #endif