]> git.tdb.fi Git - libs/gl.git/blobdiff - source/materials/unlitmaterial.cpp
Implement an unlit material type
[libs/gl.git] / source / materials / unlitmaterial.cpp
diff --git a/source/materials/unlitmaterial.cpp b/source/materials/unlitmaterial.cpp
new file mode 100644 (file)
index 0000000..5eddd66
--- /dev/null
@@ -0,0 +1,70 @@
+#include "unlitmaterial.h"
+
+using namespace std;
+
+namespace Msp {
+namespace GL {
+
+UnlitMaterial::UnlitMaterial():
+       texture(0),
+       vertex_color(false)
+{
+       set_tint(Color(1.0f));
+}
+
+string UnlitMaterial::create_program_source() const
+{
+       string source = "import unlit;\n";
+       if(texture)
+               source += "const bool use_texture = true;\n";
+       if(vertex_color)
+               source += "const bool use_vertex_color = true;\n";
+       return source;
+}
+
+void UnlitMaterial::attach_textures_to(Texturing &texturing, ProgramData &tex_shdata) const
+{
+       attach_texture_to(texture, texturing, tex_shdata, "texture");
+}
+
+void UnlitMaterial::set_texture(const Texture *tex)
+{
+       texture = tex;
+}
+
+void UnlitMaterial::set_tint(const Color &t)
+{
+       tint = t;
+       shdata.uniform("tint", tint);
+}
+
+void UnlitMaterial::set_vertex_color(bool vc)
+{
+       vertex_color = vc;
+}
+
+
+DataFile::Loader::ActionMap UnlitMaterial::Loader::shared_actions;
+
+UnlitMaterial::Loader::Loader(UnlitMaterial &m):
+       DerivedObjectLoader<UnlitMaterial, Material::PropertyLoader<UnlitMaterial> >(m)
+{
+       set_actions(shared_actions);
+}
+
+UnlitMaterial::Loader::Loader(UnlitMaterial &m, Collection &c):
+       DerivedObjectLoader<UnlitMaterial, Material::PropertyLoader<UnlitMaterial> >(m, c)
+{
+       set_actions(shared_actions);
+}
+
+void UnlitMaterial::Loader::init_actions()
+{
+       Material::PropertyLoader<UnlitMaterial>::init_actions();
+       add("texture", &Loader::property_texture, &UnlitMaterial::set_texture);
+       add_property("tint", &UnlitMaterial::set_tint, 0, true);
+       add("vertex_color", &UnlitMaterial::vertex_color);
+}
+
+} // namespace GL
+} // namespace Msp