]> git.tdb.fi Git - libs/gl.git/blob - source/materials/unlitmaterial.cpp
Migrate from LoadableTypeRegistry to TypeRegistry
[libs/gl.git] / source / materials / unlitmaterial.cpp
1 #include "unlitmaterial.h"
2
3 using namespace std;
4
5 namespace Msp {
6 namespace GL {
7
8 const Tag UnlitMaterial::texture_tags[] =
9 {
10         Tag("color_tex"),
11         Tag()
12 };
13
14 UnlitMaterial::UnlitMaterial():
15         texture(0),
16         vertex_color(false)
17 {
18         set_color(Color(1.0f));
19 }
20
21 void UnlitMaterial::fill_program_info(string &module_name, map<string, int> &spec_values) const
22 {
23         module_name = "unlit.glsl";
24         spec_values["use_texture"] = (texture!=0);
25         spec_values["use_vertex_color"] = vertex_color;
26 }
27
28 #pragma GCC diagnostic push
29 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
30 void UnlitMaterial::attach_textures_to(Texturing &texturing, ProgramData &tex_shdata) const
31 {
32         attach_texture_to(texture, texturing, tex_shdata, "color_tex");
33 }
34 #pragma GCC diagnostic pop
35
36 const Texture *UnlitMaterial::get_texture(Tag tag) const
37 {
38         if(tag==texture_tags[0])
39                 return texture;
40         else
41                 return 0;
42 }
43
44 void UnlitMaterial::set_texture(const Texture *tex)
45 {
46         texture = tex;
47 }
48
49 void UnlitMaterial::set_color(const Color &c)
50 {
51         color = c;
52         shdata.uniform("unlit_material.color", color);
53 }
54
55 void UnlitMaterial::set_vertex_color(bool vc)
56 {
57         vertex_color = vc;
58 }
59
60
61 DataFile::Loader::ActionMap UnlitMaterial::Loader::shared_actions;
62
63 UnlitMaterial::Loader::Loader(UnlitMaterial &m):
64         DerivedObjectLoader<UnlitMaterial, Material::PropertyLoader<UnlitMaterial> >(m)
65 {
66         set_actions(shared_actions);
67 }
68
69 UnlitMaterial::Loader::Loader(UnlitMaterial &m, Collection &c):
70         DerivedObjectLoader<UnlitMaterial, Material::PropertyLoader<UnlitMaterial> >(m, c)
71 {
72         set_actions(shared_actions);
73 }
74
75 void UnlitMaterial::Loader::init_actions()
76 {
77         Material::PropertyLoader<UnlitMaterial>::init_actions();
78         add("texture", &Loader::property_texture, &UnlitMaterial::set_texture);
79         add_property("color", &UnlitMaterial::set_color, 0, true);
80         add("vertex_color", &UnlitMaterial::vertex_color);
81 }
82
83 } // namespace GL
84 } // namespace Msp