back_faces(false)
{ }
-void RenderPass::finalize_material(DataFile::Collection *coll)
+void RenderPass::set_material_textures()
{
- maybe_create_material_shader(coll);
- ensure_private_shader_data();
-
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());
shprog.keep();
}
else
- throw invalid_operation("no collection");
+ throw invalid_operation("RenderPass::maybe_create_material_shader");
if(shdata)
shdata = new ProgramData(*shdata, shprog.get());
shprog_from_material = true;
}
-void RenderPass::ensure_private_shader_data()
-{
- if(!shprog)
- throw invalid_operation("RenderPass::ensure_private_shader_data");
-
- if(!shdata)
- shdata = new ProgramData(shprog.get());
- else if(shdata.refcount()>1)
- shdata = new ProgramData(*shdata);
-}
-
void RenderPass::set_shader_program(const Program *prog, const ProgramData *data)
{
shprog = prog;
shprog.keep();
shprog_from_material = false;
shdata = (data ? new ProgramData(*data) : 0);
- if(material)
- finalize_material(0);
}
Tag RenderPass::get_slotted_uniform_tag(Tag slot) const
{
material = mat;
material.keep();
- finalize_material(coll);
+ maybe_create_material_shader(coll);
+ set_material_textures();
}
void RenderPass::set_texture(Tag tag, const Texture *tex, const Sampler *samp)
add("texunit", &Loader::texunit_named);
}
+void RenderPass::Loader::finish()
+{
+ if(obj.material)
+ obj.maybe_create_material_shader(coll);
+}
+
// Temporary compatibility feature
string RenderPass::Loader::get_shader_name(const string &n)
{
Material::GenericLoader ldr(coll);
load_sub_with(ldr);
obj.material = ldr.get_material();
- obj.finalize_material(coll);
+ obj.set_material_textures();
}
void RenderPass::Loader::material(const string &name)
{
obj.material = &get_collection().get<Material>(name);
obj.material.keep();
- obj.finalize_material(coll);
+ obj.set_material_textures();
}
void RenderPass::Loader::shader(const string &n)
obj.shprog_from_material = false;
if(obj.shdata)
obj.shdata = new ProgramData(*obj.shdata, obj.shprog.get());
- if(obj.material)
- obj.finalize_material(coll);
}
void RenderPass::Loader::texture(const string &n)
{
if(!obj.shprog || obj.shprog_from_material)
throw runtime_error("Shader is required for uniforms");
- obj.ensure_private_shader_data();
+ if(!obj.shdata)
+ obj.shdata = new ProgramData(obj.shprog.get());
+ else if(obj.shdata.refcount()>1)
+ obj.shdata = new ProgramData(*obj.shdata);
load_sub(*obj.shdata);
}