]> git.tdb.fi Git - libs/gl.git/blob - source/resources/resources.h
Load textures in a type-generic way
[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.  Most useful as a base class for an
20 application-specific collection.
21 */
22 class Resources: virtual public DataFile::Collection
23 {
24 public:
25         class Loader: public DataFile::DerivedObjectLoader<Resources, Collection::Loader>
26         {
27         public:
28                 Loader(Resources &);
29
30         private:
31                 template<typename T, typename L = typename T::GenericLoader>
32                 void generic(const std::string &);
33         };
34
35 private:
36         template<typename T>
37         class GenericResourceLoader: public T::GenericLoader
38         {
39         private:
40                 Resources &resources;
41
42         public:
43                 GenericResourceLoader(Resources &r): T::GenericLoader(r), resources(r) { }
44
45         protected:
46                 virtual void type(const DataFile::Symbol &);
47         };
48
49         bool srgb_conversion;
50         ResourceManager *resource_manager;
51
52         static Resources *global_resources;
53
54 public:
55         Resources(bool = true);
56         virtual ~Resources();
57
58         static Resources &get_global();
59         static const DataFile::CollectionSource &get_builtins();
60
61         /** Enables or disables sRGB conversion.  If enabled, textures and material
62         colors are converted from sRGB to linear color space when loaded. */
63         DEPRECATED void set_srgb_conversion(bool);
64
65         DEPRECATED bool get_srgb_conversion() const { return srgb_conversion; }
66
67         void set_resource_manager(ResourceManager *);
68
69 protected:
70         template<typename T, typename L = typename T::GenericLoader>
71         T *create_generic(const std::string &);
72
73         Mesh *create_mesh(const std::string &);
74         Texture *create_texture(const std::string &);
75         Module *create_module(const std::string &);
76         Program *create_program(const std::string &);
77
78         template<typename T>
79         static void set_debug_name(const std::string &, T &);
80 };
81
82 } // namespace GL
83 } // namespace Msp
84
85 #endif