]> git.tdb.fi Git - libs/gl.git/blob - source/materials/unlitmaterial.cpp
d5d99c01f2196a67ca6204ef8d7f9b22a34bebb4
[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 const Texture *UnlitMaterial::get_texture(Tag tag) const
29 {
30         if(tag==texture_tags[0])
31                 return texture;
32         else
33                 return 0;
34 }
35
36 void UnlitMaterial::set_texture(const Texture *tex)
37 {
38         texture = tex;
39 }
40
41 void UnlitMaterial::set_color(const Color &c)
42 {
43         color = c;
44         shdata.uniform("unlit_material.color", color);
45 }
46
47 void UnlitMaterial::set_vertex_color(bool vc)
48 {
49         vertex_color = vc;
50 }
51
52
53 DataFile::Loader::ActionMap UnlitMaterial::Loader::shared_actions;
54
55 UnlitMaterial::Loader::Loader(UnlitMaterial &m, Collection &c):
56         DerivedObjectLoader<UnlitMaterial, Material::PropertyLoader<UnlitMaterial> >(m, c)
57 {
58         set_actions(shared_actions);
59 }
60
61 void UnlitMaterial::Loader::init_actions()
62 {
63         Material::PropertyLoader<UnlitMaterial>::init_actions();
64         add("texture", &Loader::property_texture, &UnlitMaterial::set_texture);
65         add_property("color", &UnlitMaterial::set_color, 0, true);
66         add("vertex_color", &UnlitMaterial::vertex_color);
67 }
68
69 } // namespace GL
70 } // namespace Msp