]> git.tdb.fi Git - libs/gl.git/commitdiff
Improve material handling in RenderMethod
authorMikko Rasa <tdb@tdb.fi>
Sat, 30 Oct 2021 20:02:39 +0000 (23:02 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 30 Oct 2021 22:28:13 +0000 (01:28 +0300)
source/materials/rendermethod.cpp

index 3208929cc2a98e1de31d8f18cb4edf12456859d0..2b4738ef46e0b2dd2a21f0fb38f463072f4368e9 100644 (file)
@@ -16,6 +16,9 @@ namespace GL {
 
 void RenderMethod::set_material_textures()
 {
+       if(!material)
+               return;
+
        const Tag *material_texture_tags = material->get_texture_tags();
        for(const Tag *tag=material_texture_tags; tag->id; ++tag)
                set_texture(*tag, material->get_texture(*tag), material->get_sampler(*tag));
@@ -23,7 +26,7 @@ void RenderMethod::set_material_textures()
 
 void RenderMethod::maybe_create_material_shader()
 {
-       if(shprog && !shprog_from_material)
+       if(!material || (shprog && !shprog_from_material))
                return;
 
        map<string, int> extra_spec;
@@ -45,6 +48,7 @@ void RenderMethod::set_shader_program(const Program *prog, const ProgramData *da
        shprog = prog;
        shprog_from_material = false;
        shdata = (data ? new ProgramData(*data) : 0);
+       maybe_create_material_shader();
 }
 
 Tag RenderMethod::get_slotted_uniform_tag(Tag slot) const
@@ -94,6 +98,7 @@ void RenderMethod::set_blend(const Blend &b)
 void RenderMethod::set_receive_shadows(bool rs)
 {
        receive_shadows = rs;
+       maybe_create_material_shader();
 }
 
 void RenderMethod::apply(Renderer &renderer) const