]> git.tdb.fi Git - libs/gl.git/blob - source/material.cpp
Redesign the material system
[libs/gl.git] / source / material.cpp
1 #include "basicmaterial.h"
2 #include "gl.h"
3 #include "resources.h"
4 #include "texturing.h"
5
6 using namespace std;
7
8 namespace Msp {
9 namespace GL {
10
11 void Material::attach_texture_to(const Texture *tex, Texturing &texturing, ProgramData &tex_shdata, const string &name) const
12 {
13         if(!tex)
14                 return;
15
16         int unit = texturing.find_free_unit(name);
17         if(unit<0)
18                 throw runtime_error("no free texunit");
19         texturing.attach(unit, *tex);
20         tex_shdata.uniform(name, unit);
21 }
22
23 Material::MaterialRegistry &Material::get_material_registry()
24 {
25         static MaterialRegistry registry;
26         static bool initialized = false;
27         if(!initialized)
28         {
29                 registry.register_type<BasicMaterial>("basic");
30         }
31         return registry;
32 }
33
34
35 DataFile::Loader::ActionMap Material::GenericLoader::shared_actions;
36
37 Material::GenericLoader::GenericLoader(DataFile::Collection *c):
38         coll(c)
39 {
40         set_actions(shared_actions);
41 }
42
43 void Material::GenericLoader::init_actions()
44 {
45         get_material_registry().add_all(*this);
46 }
47
48 } // namespace GL
49 } // namespace Msp