X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fmaterials%2Frenderpass.cpp;h=a055f4786bfed69a39c871087d31b47a123c6f1c;hb=5008778dbb1840bf7c6d479800d2b932f8386fb2;hp=9a7ceef782075ee38821aa5ae9b45f1b6e13c425;hpb=fe9836f2d8d7abb0480582c544611a5b248310cc;p=libs%2Fgl.git diff --git a/source/materials/renderpass.cpp b/source/materials/renderpass.cpp index 9a7ceef7..a055f478 100644 --- a/source/materials/renderpass.cpp +++ b/source/materials/renderpass.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include "error.h" #include "renderpass.h" @@ -9,7 +8,6 @@ #include "renderer.h" #include "texture.h" #include "texture2d.h" -#include "uniform.h" using namespace std; @@ -61,7 +59,7 @@ void RenderPass::set_shader_program(const Program *prog, const ProgramData *data Tag RenderPass::get_slotted_uniform_tag(Tag slot) const { - map::const_iterator i = uniform_slots.find(slot); + auto i = uniform_slots.find(slot); if(i==uniform_slots.end()) return Tag(); return i->second; @@ -76,7 +74,7 @@ void RenderPass::set_material(const Material *mat) void RenderPass::set_texture(Tag tag, const Texture *tex, const Sampler *samp) { - vector::iterator i = find_member(textures, tag, &TextureSlot::tag); + auto i = find_member(textures, tag, &TextureSlot::tag); if(i==textures.end()) { textures.push_back(TextureSlot(tag)); @@ -89,41 +87,10 @@ void RenderPass::set_texture(Tag tag, const Texture *tex, const Sampler *samp) Tag RenderPass::get_texture_tag(const string &slot) const { - vector::const_iterator i = find_member(textures, slot, &TextureSlot::slot_name); + auto i = find_member(textures, slot, &TextureSlot::slot_name); return (i!=textures.end() ? i->tag : Tag()); } -void RenderPass::set_texture(unsigned index, const Texture *tex, const Sampler *samp) -{ - if(!shprog) - throw invalid_operation("RenderPass::set_texture"); - - const vector &uniforms = shprog->get_uniforms(); - for(vector::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i) - if(is_image(i->type) && i->binding==static_cast(index)) - return set_texture(i->tag, tex, samp); - - if(shdata) - { - const vector &tags = shdata->get_uniform_tags(); - for(vector::const_iterator i=tags.begin(); i!=tags.end(); ++i) - { - vector::const_iterator j = find_member(uniforms, *i, &Program::UniformInfo::tag); - if(j==uniforms.end() || !is_image(j->type)) - continue; - if(const Uniform1i *uni1i = dynamic_cast(shdata->find_uniform(*i))) - if(uni1i->get()==static_cast(index)) - return set_texture(*i, tex, samp); - } - } -} - -int RenderPass::get_texture_index(const string &n) const -{ - vector::const_iterator i = find_member(textures, n, &TextureSlot::slot_name); - return (shprog && i!=textures.end() ? shprog->get_uniform_binding(i->tag) : -1); -} - void RenderPass::set_face_cull(CullMode fc) { face_cull = fc; @@ -136,8 +103,8 @@ void RenderPass::set_receive_shadows(bool rs) void RenderPass::apply(Renderer &renderer) const { - for(vector::const_iterator i=textures.begin(); i!=textures.end(); ++i) - renderer.set_texture(i->tag, i->texture, i->sampler); + for(const TextureSlot &t: textures) + renderer.set_texture(t.tag, t.texture, t.sampler); renderer.set_shader_program(shprog, shdata.get()); if(material) renderer.add_shader_data(material->get_shader_data()); @@ -182,11 +149,6 @@ void RenderPass::Loader::init_actions() add("uniforms", &Loader::uniforms); add("uniform_slot", &Loader::uniform_slot); add("uniform_slot", &Loader::uniform_slot2); - - // Deprecated - add("texunit", &Loader::texunit); - add("texunit", &Loader::texture); - add("texunit", &Loader::texunit_named); } void RenderPass::Loader::set_inline_base_name(const string &n) @@ -200,17 +162,6 @@ void RenderPass::Loader::finish() obj.maybe_create_material_shader(); } -// Temporary compatibility feature -string RenderPass::Loader::get_shader_name(const string &n) -{ - if(n.size()>=5 && !n.compare(n.size()-5, 5, ".glsl")) - { - IO::print(IO::cerr, "Warning: Loading module '%s' as shader is deprecated\n", n); - return n+".shader"; - } - return n; -} - void RenderPass::Loader::material_inline() { Material::GenericLoader ldr(coll); @@ -229,7 +180,7 @@ void RenderPass::Loader::material(const string &name) void RenderPass::Loader::shader(const string &n) { - obj.shprog = &get_collection().get(get_shader_name(n)); + obj.shprog = &get_collection().get(n); obj.shprog_from_material = false; if(obj.shdata) obj.shdata = new ProgramData(*obj.shdata, obj.shprog); @@ -237,7 +188,7 @@ void RenderPass::Loader::shader(const string &n) void RenderPass::Loader::texture(const string &n) { - vector::iterator i = find_member(obj.textures, Tag(n), &TextureSlot::tag); + auto i = find_member(obj.textures, Tag(n), &TextureSlot::tag); if(i==obj.textures.end()) { obj.textures.push_back(TextureSlot(n)); @@ -247,36 +198,6 @@ void RenderPass::Loader::texture(const string &n) load_sub_with(ldr); } -void RenderPass::Loader::texunit(unsigned) -{ - IO::print(IO::cerr, "Warning: specifying textures by unit number is deprecated and may not produce expected results"); - string name; - if(obj.shprog) - { - const vector &uniforms = obj.shprog->get_uniforms(); - for(vector::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i) - if(is_image(i->type) && i->binding>=0) - { - if(!name.empty()) - { - name.clear(); - break; - } - name = i->name; - } - } - - if(name.empty()) - throw runtime_error("Could not determine name for texture"); - - texture(name); -} - -void RenderPass::Loader::texunit_named(unsigned, const string &n) -{ - texture(n); -} - void RenderPass::Loader::uniforms() { if(!obj.shprog || obj.shprog_from_material)