From: Mikko Rasa Date: Sat, 2 Oct 2021 16:23:36 +0000 (+0300) Subject: Rename RenderPass to RenderMethod X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=c0b7d6ee4a7478f5aecb1504429ec1fc846d64ed;p=libs%2Fgl.git Rename RenderPass to RenderMethod This is mostly to avoid confusion with Vulkan's render passes, which are an entirely different thing. --- diff --git a/blender/io_mspgl/export_material.py b/blender/io_mspgl/export_material.py index 8a87011a..e7c1a50d 100644 --- a/blender/io_mspgl/export_material.py +++ b/blender/io_mspgl/export_material.py @@ -7,7 +7,7 @@ def create_technique_resource(material, resources): mat_res = resources[material.name+".mat"] - st = Statement("pass", "") + st = Statement("method", "") if mat_res: st.sub.append(tech_res.create_embed_statement("material", mat_res)) @@ -31,7 +31,7 @@ def create_technique_resource(material, resources): tech_res.statements.append(st) if material.shadow_method!='NONE': - st = Statement("pass", "shadow") + st = Statement("method", "shadow") if material.render_mode=='CUSTOM': shader = material.shadow_shader or material.shader if shader.endswith(".glsl"): diff --git a/blender/io_mspgl/export_object.py b/blender/io_mspgl/export_object.py index 177641c8..32894f7e 100644 --- a/blender/io_mspgl/export_object.py +++ b/blender/io_mspgl/export_object.py @@ -150,7 +150,7 @@ class ObjectExporter: def export_stub_technique(self): from .datafile import Resource, Statement tech_res = Resource("stub.tech", "technique") - pass_st = Statement("pass", "") + pass_st = Statement("method", "") tech_res.statements.append(pass_st) mat_st = Statement("material") pass_st.sub.append(mat_st) diff --git a/source/materials/rendermethod.cpp b/source/materials/rendermethod.cpp new file mode 100644 index 00000000..a6a843ee --- /dev/null +++ b/source/materials/rendermethod.cpp @@ -0,0 +1,239 @@ +#include +#include +#include +#include "error.h" +#include "rendermethod.h" +#include "program.h" +#include "programdata.h" +#include "renderer.h" +#include "texture.h" +#include "texture2d.h" + +using namespace std; + +namespace Msp { +namespace GL { + +RenderMethod::RenderMethod(): + shprog(0), + shprog_from_material(false), + shdata(0), + material(0), + face_cull(CULL_BACK), + receive_shadows(false), + image_based_lighting(false) +{ } + +void RenderMethod::set_material_textures() +{ + 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)); +} + +void RenderMethod::maybe_create_material_shader() +{ + if(shprog && !shprog_from_material) + return; + + map extra_spec; + if(receive_shadows) + extra_spec["use_shadow_map"] = true; + if(image_based_lighting) + extra_spec["use_image_based_lighting"] = true; + + shprog = material->create_compatible_shader(extra_spec); + + if(shdata) + shdata = new ProgramData(*shdata, shprog); + + shprog_from_material = true; +} + +void RenderMethod::set_shader_program(const Program *prog, const ProgramData *data) +{ + shprog = prog; + shprog_from_material = false; + shdata = (data ? new ProgramData(*data) : 0); +} + +Tag RenderMethod::get_slotted_uniform_tag(Tag slot) const +{ + auto i = uniform_slots.find(slot); + if(i==uniform_slots.end()) + return Tag(); + return i->second; +} + +void RenderMethod::set_material(const Material *mat) +{ + material = mat; + maybe_create_material_shader(); + set_material_textures(); +} + +void RenderMethod::set_texture(Tag tag, const Texture *tex, const Sampler *samp) +{ + auto i = find_member(textures, tag, &TextureSlot::tag); + if(i==textures.end()) + { + textures.push_back(TextureSlot(tag)); + i = textures.end()-1; + } + i->texture = tex; + if(samp) + i->sampler = samp; +} + +Tag RenderMethod::get_texture_tag(const string &slot) const +{ + auto i = find_member(textures, slot, &TextureSlot::slot_name); + return (i!=textures.end() ? i->tag : Tag()); +} + +void RenderMethod::set_face_cull(CullMode fc) +{ + face_cull = fc; +} + +void RenderMethod::set_receive_shadows(bool rs) +{ + receive_shadows = rs; +} + +void RenderMethod::apply(Renderer &renderer) const +{ + 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()); + renderer.set_face_cull(face_cull); +} + +void RenderMethod::set_debug_name(const string &name) +{ +#ifdef DEBUG + if(shdata.refcount()==1) + shdata->set_debug_name(name+" [UBO]"); +#else + (void)name; +#endif +} + + +DataFile::Loader::ActionMap RenderMethod::Loader::shared_actions; + +RenderMethod::Loader::Loader(RenderMethod &p): + DataFile::CollectionObjectLoader(p, 0) +{ + set_actions(shared_actions); +} + +RenderMethod::Loader::Loader(RenderMethod &p, Collection &c): + DataFile::CollectionObjectLoader(p, &c) +{ + set_actions(shared_actions); +} + +void RenderMethod::Loader::init_actions() +{ + add("face_cull", &RenderMethod::face_cull); + add("shader", &Loader::shader); + add("image_based_lighting", &RenderMethod::image_based_lighting); + add("material", &Loader::material_inline); + add("material", &Loader::material); + add("material_slot", &RenderMethod::material_slot); + add("receive_shadows", &RenderMethod::receive_shadows); + add("texture", &Loader::texture); + add("uniforms", &Loader::uniforms); + add("uniform_slot", &Loader::uniform_slot); + add("uniform_slot", &Loader::uniform_slot2); +} + +void RenderMethod::Loader::set_inline_base_name(const string &n) +{ + inline_base_name = n; +} + +void RenderMethod::Loader::finish() +{ + if(obj.material) + obj.maybe_create_material_shader(); +} + +void RenderMethod::Loader::material_inline() +{ + Material::GenericLoader ldr(coll); + load_sub_with(ldr); + RefPtr mat = ldr.get_material(); + get_collection().add(inline_base_name+".mat", mat.get()); + obj.material = mat.release(); + obj.set_material_textures(); +} + +void RenderMethod::Loader::material(const string &name) +{ + obj.material = &get_collection().get(name); + obj.set_material_textures(); +} + +void RenderMethod::Loader::shader(const string &n) +{ + obj.shprog = &get_collection().get(n); + obj.shprog_from_material = false; + if(obj.shdata) + obj.shdata = new ProgramData(*obj.shdata, obj.shprog); +} + +void RenderMethod::Loader::texture(const string &n) +{ + auto i = find_member(obj.textures, Tag(n), &TextureSlot::tag); + if(i==obj.textures.end()) + { + obj.textures.push_back(TextureSlot(n)); + i = obj.textures.end()-1; + } + TextureSlot::Loader ldr(*i, n, coll); + load_sub_with(ldr); +} + +void RenderMethod::Loader::uniforms() +{ + if(!obj.shprog || obj.shprog_from_material) + throw runtime_error("Shader is required for uniforms"); + if(!obj.shdata) + obj.shdata = new ProgramData(obj.shprog); + else if(obj.shdata.refcount()>1) + obj.shdata = new ProgramData(*obj.shdata); + load_sub(*obj.shdata); +} + +void RenderMethod::Loader::uniform_slot(const string &name) +{ + uniform_slot2(name, name); +} + +void RenderMethod::Loader::uniform_slot2(const string &name, const string &slot) +{ + obj.uniform_slots[slot] = name; +} + + +RenderMethod::TextureSlot::Loader::Loader(TextureSlot &ts, const string &an, Collection *c): + CollectionObjectLoader(ts, c), + auto_slot_name(an) +{ + add("sampler", &TextureSlot::sampler); + add("slot", &Loader::slot_auto); + add("slot", &TextureSlot::slot_name); + add("texture", &TextureSlot::texture); +} + +void RenderMethod::TextureSlot::Loader::slot_auto() +{ + obj.slot_name = auto_slot_name; +} + +} // namespace GL +} // namespace Msp diff --git a/source/materials/rendermethod.h b/source/materials/rendermethod.h new file mode 100644 index 00000000..11c7e858 --- /dev/null +++ b/source/materials/rendermethod.h @@ -0,0 +1,119 @@ +#ifndef MSP_GL_RENDERPASS_H_ +#define MSP_GL_RENDERPASS_H_ + +#include +#include +#include "cullface.h" +#include "material.h" + +namespace Msp { +namespace GL { + +class Program; +class ProgramData; +class Renderer; +class Sampler; +class Texture; + +/** +Encapsulates the data that determines the appearance of a rendered surface. +This includes shader and data for it, material and texturing. +*/ +class RenderMethod +{ +public: + class Loader: public DataFile::CollectionObjectLoader + { + private: + std::string inline_base_name; + + static ActionMap shared_actions; + + public: + Loader(RenderMethod &); + Loader(RenderMethod &, Collection &); + private: + virtual void init_actions(); + + public: + void set_inline_base_name(const std::string &); + + private: + virtual void finish(); + + void material_inline(); + void material(const std::string &); + void shader(const std::string &); + void texture(const std::string &); + void uniforms(); + void uniform_slot(const std::string &); + void uniform_slot2(const std::string &, const std::string &); + }; + +private: + struct TextureSlot + { + class Loader: public DataFile::CollectionObjectLoader + { + private: + std::string auto_slot_name; + + public: + Loader(TextureSlot &, const std::string &, Collection *); + + private: + void slot_auto(); + }; + + Tag tag; + std::string slot_name; + const Texture *texture; + const Sampler *sampler; + + TextureSlot(Tag t): tag(t), texture(0), sampler(0) { } + }; + + const Program *shprog; + bool shprog_from_material; + RefPtr shdata; + std::map uniform_slots; + const Material *material; + std::string material_slot; + std::vector textures; + CullMode face_cull; + bool receive_shadows; + bool image_based_lighting; + +public: + RenderMethod(); + +private: + void maybe_create_material_shader(); + void set_material_textures(); + +public: + void set_shader_program(const Program *, const ProgramData *); + const Program *get_shader_program() const { return shprog; } + const ProgramData *get_shader_data() const { return shdata.get(); } + Tag get_slotted_uniform_tag(Tag) const; + void set_material(const Material *); + const Material *get_material() const { return material; } + const std::string &get_material_slot_name() const { return material_slot; } + void set_texture(Tag, const Texture *, const Sampler * = 0); + Tag get_texture_tag(const std::string &) const; + void set_face_cull(CullMode); + CullMode get_face_cull() const { return face_cull; } + void set_receive_shadows(bool); + bool get_receive_shadows() const { return receive_shadows; } + void set_image_based_lighting(bool); + bool get_image_based_lighting() const { return image_based_lighting; } + + void apply(Renderer &) const; + + void set_debug_name(const std::string &); +}; + +} // namespace GL +} // namespace Msp + +#endif diff --git a/source/materials/renderpass.cpp b/source/materials/renderpass.cpp deleted file mode 100644 index a055f478..00000000 --- a/source/materials/renderpass.cpp +++ /dev/null @@ -1,239 +0,0 @@ -#include -#include -#include -#include "error.h" -#include "renderpass.h" -#include "program.h" -#include "programdata.h" -#include "renderer.h" -#include "texture.h" -#include "texture2d.h" - -using namespace std; - -namespace Msp { -namespace GL { - -RenderPass::RenderPass(): - shprog(0), - shprog_from_material(false), - shdata(0), - material(0), - face_cull(CULL_BACK), - receive_shadows(false), - image_based_lighting(false) -{ } - -void RenderPass::set_material_textures() -{ - 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)); -} - -void RenderPass::maybe_create_material_shader() -{ - if(shprog && !shprog_from_material) - return; - - map extra_spec; - if(receive_shadows) - extra_spec["use_shadow_map"] = true; - if(image_based_lighting) - extra_spec["use_image_based_lighting"] = true; - - shprog = material->create_compatible_shader(extra_spec); - - if(shdata) - shdata = new ProgramData(*shdata, shprog); - - shprog_from_material = true; -} - -void RenderPass::set_shader_program(const Program *prog, const ProgramData *data) -{ - shprog = prog; - shprog_from_material = false; - shdata = (data ? new ProgramData(*data) : 0); -} - -Tag RenderPass::get_slotted_uniform_tag(Tag slot) const -{ - auto i = uniform_slots.find(slot); - if(i==uniform_slots.end()) - return Tag(); - return i->second; -} - -void RenderPass::set_material(const Material *mat) -{ - material = mat; - maybe_create_material_shader(); - set_material_textures(); -} - -void RenderPass::set_texture(Tag tag, const Texture *tex, const Sampler *samp) -{ - auto i = find_member(textures, tag, &TextureSlot::tag); - if(i==textures.end()) - { - textures.push_back(TextureSlot(tag)); - i = textures.end()-1; - } - i->texture = tex; - if(samp) - i->sampler = samp; -} - -Tag RenderPass::get_texture_tag(const string &slot) const -{ - auto i = find_member(textures, slot, &TextureSlot::slot_name); - return (i!=textures.end() ? i->tag : Tag()); -} - -void RenderPass::set_face_cull(CullMode fc) -{ - face_cull = fc; -} - -void RenderPass::set_receive_shadows(bool rs) -{ - receive_shadows = rs; -} - -void RenderPass::apply(Renderer &renderer) const -{ - 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()); - renderer.set_face_cull(face_cull); -} - -void RenderPass::set_debug_name(const string &name) -{ -#ifdef DEBUG - if(shdata.refcount()==1) - shdata->set_debug_name(name+" [UBO]"); -#else - (void)name; -#endif -} - - -DataFile::Loader::ActionMap RenderPass::Loader::shared_actions; - -RenderPass::Loader::Loader(RenderPass &p): - DataFile::CollectionObjectLoader(p, 0) -{ - set_actions(shared_actions); -} - -RenderPass::Loader::Loader(RenderPass &p, Collection &c): - DataFile::CollectionObjectLoader(p, &c) -{ - set_actions(shared_actions); -} - -void RenderPass::Loader::init_actions() -{ - add("face_cull", &RenderPass::face_cull); - add("shader", &Loader::shader); - add("image_based_lighting", &RenderPass::image_based_lighting); - add("material", &Loader::material_inline); - add("material", &Loader::material); - add("material_slot", &RenderPass::material_slot); - add("receive_shadows", &RenderPass::receive_shadows); - add("texture", &Loader::texture); - add("uniforms", &Loader::uniforms); - add("uniform_slot", &Loader::uniform_slot); - add("uniform_slot", &Loader::uniform_slot2); -} - -void RenderPass::Loader::set_inline_base_name(const string &n) -{ - inline_base_name = n; -} - -void RenderPass::Loader::finish() -{ - if(obj.material) - obj.maybe_create_material_shader(); -} - -void RenderPass::Loader::material_inline() -{ - Material::GenericLoader ldr(coll); - load_sub_with(ldr); - RefPtr mat = ldr.get_material(); - get_collection().add(inline_base_name+".mat", mat.get()); - obj.material = mat.release(); - obj.set_material_textures(); -} - -void RenderPass::Loader::material(const string &name) -{ - obj.material = &get_collection().get(name); - obj.set_material_textures(); -} - -void RenderPass::Loader::shader(const string &n) -{ - obj.shprog = &get_collection().get(n); - obj.shprog_from_material = false; - if(obj.shdata) - obj.shdata = new ProgramData(*obj.shdata, obj.shprog); -} - -void RenderPass::Loader::texture(const string &n) -{ - auto i = find_member(obj.textures, Tag(n), &TextureSlot::tag); - if(i==obj.textures.end()) - { - obj.textures.push_back(TextureSlot(n)); - i = obj.textures.end()-1; - } - TextureSlot::Loader ldr(*i, n, coll); - load_sub_with(ldr); -} - -void RenderPass::Loader::uniforms() -{ - if(!obj.shprog || obj.shprog_from_material) - throw runtime_error("Shader is required for uniforms"); - if(!obj.shdata) - obj.shdata = new ProgramData(obj.shprog); - else if(obj.shdata.refcount()>1) - obj.shdata = new ProgramData(*obj.shdata); - load_sub(*obj.shdata); -} - -void RenderPass::Loader::uniform_slot(const string &name) -{ - uniform_slot2(name, name); -} - -void RenderPass::Loader::uniform_slot2(const string &name, const string &slot) -{ - obj.uniform_slots[slot] = name; -} - - -RenderPass::TextureSlot::Loader::Loader(TextureSlot &ts, const string &an, Collection *c): - CollectionObjectLoader(ts, c), - auto_slot_name(an) -{ - add("sampler", &TextureSlot::sampler); - add("slot", &Loader::slot_auto); - add("slot", &TextureSlot::slot_name); - add("texture", &TextureSlot::texture); -} - -void RenderPass::TextureSlot::Loader::slot_auto() -{ - obj.slot_name = auto_slot_name; -} - -} // namespace GL -} // namespace Msp diff --git a/source/materials/renderpass.h b/source/materials/renderpass.h deleted file mode 100644 index ae9e34b8..00000000 --- a/source/materials/renderpass.h +++ /dev/null @@ -1,119 +0,0 @@ -#ifndef MSP_GL_RENDERPASS_H_ -#define MSP_GL_RENDERPASS_H_ - -#include -#include -#include "cullface.h" -#include "material.h" - -namespace Msp { -namespace GL { - -class Program; -class ProgramData; -class Renderer; -class Sampler; -class Texture; - -/** -Encapsulates the data that determines the appearance of a rendered surface. -This includes shader and data for it, material and texturing. -*/ -class RenderPass -{ -public: - class Loader: public DataFile::CollectionObjectLoader - { - private: - std::string inline_base_name; - - static ActionMap shared_actions; - - public: - Loader(RenderPass &); - Loader(RenderPass &, Collection &); - private: - virtual void init_actions(); - - public: - void set_inline_base_name(const std::string &); - - private: - virtual void finish(); - - void material_inline(); - void material(const std::string &); - void shader(const std::string &); - void texture(const std::string &); - void uniforms(); - void uniform_slot(const std::string &); - void uniform_slot2(const std::string &, const std::string &); - }; - -private: - struct TextureSlot - { - class Loader: public DataFile::CollectionObjectLoader - { - private: - std::string auto_slot_name; - - public: - Loader(TextureSlot &, const std::string &, Collection *); - - private: - void slot_auto(); - }; - - Tag tag; - std::string slot_name; - const Texture *texture; - const Sampler *sampler; - - TextureSlot(Tag t): tag(t), texture(0), sampler(0) { } - }; - - const Program *shprog; - bool shprog_from_material; - RefPtr shdata; - std::map uniform_slots; - const Material *material; - std::string material_slot; - std::vector textures; - CullMode face_cull; - bool receive_shadows; - bool image_based_lighting; - -public: - RenderPass(); - -private: - void maybe_create_material_shader(); - void set_material_textures(); - -public: - void set_shader_program(const Program *, const ProgramData *); - const Program *get_shader_program() const { return shprog; } - const ProgramData *get_shader_data() const { return shdata.get(); } - Tag get_slotted_uniform_tag(Tag) const; - void set_material(const Material *); - const Material *get_material() const { return material; } - const std::string &get_material_slot_name() const { return material_slot; } - void set_texture(Tag, const Texture *, const Sampler * = 0); - Tag get_texture_tag(const std::string &) const; - void set_face_cull(CullMode); - CullMode get_face_cull() const { return face_cull; } - void set_receive_shadows(bool); - bool get_receive_shadows() const { return receive_shadows; } - void set_image_based_lighting(bool); - bool get_image_based_lighting() const { return image_based_lighting; } - - void apply(Renderer &) const; - - void set_debug_name(const std::string &); -}; - -} // namespace GL -} // namespace Msp - -#endif diff --git a/source/materials/technique.cpp b/source/materials/technique.cpp index 122eaf73..268149f8 100644 --- a/source/materials/technique.cpp +++ b/source/materials/technique.cpp @@ -12,31 +12,31 @@ using namespace std; namespace Msp { namespace GL { -RenderPass &Technique::add_pass(Tag tag) +RenderMethod &Technique::add_method(Tag tag) { - return insert_unique(passes, tag, RenderPass())->second; + return insert_unique(methods, tag, RenderMethod())->second; } -bool Technique::has_pass(Tag tag) const +bool Technique::has_method(Tag tag) const { - return passes.count(tag); + return methods.count(tag); } -const RenderPass &Technique::get_pass(Tag tag) const +const RenderMethod &Technique::get_method(Tag tag) const { - return get_item(passes, tag); + return get_item(methods, tag); } -const RenderPass *Technique::find_pass(Tag tag) const +const RenderMethod *Technique::find_method(Tag tag) const { - auto i = passes.find(tag); - return (i!=passes.end() ? &i->second : 0); + auto i = methods.find(tag); + return (i!=methods.end() ? &i->second : 0); } bool Technique::replace_texture(const string &slot, const Texture &tex) { bool replaced = false; - for(auto &kvp: passes) + for(auto &kvp: methods) { Tag tag = kvp.second.get_texture_tag(slot); if(tag.id) @@ -52,7 +52,7 @@ bool Technique::replace_texture(const string &slot, const Texture &tex) bool Technique::replace_material(const string &slot, const Material &mat) { bool replaced = false; - for(auto &kvp: passes) + for(auto &kvp: methods) { const string &pass_slot = kvp.second.get_material_slot_name(); if(!pass_slot.empty() && pass_slot==slot) @@ -69,7 +69,7 @@ bool Technique::replace_uniforms(const ProgramData &shdata) { bool replaced = false; const vector &uniform_tags = shdata.get_uniform_tags(); - for(auto &kvp: passes) + for(auto &kvp: methods) { RefPtr new_shdata; for(Tag t: uniform_tags) @@ -95,8 +95,8 @@ bool Technique::replace_uniforms(const ProgramData &shdata) void Technique::set_debug_name(const string &name) { #ifdef DEBUG - for(auto &kvp: passes) - kvp.second.set_debug_name(format("%s [pass:%s]", name, kvp.first.str())); + for(auto &kvp: methods) + kvp.second.set_debug_name(format("%s [method:%s]", name, kvp.first.str())); #else (void)name; #endif @@ -120,7 +120,7 @@ Technique::Loader::Loader(Technique &t, Collection &c): void Technique::Loader::init_actions() { add("inherit", &Loader::inherit); - add("pass", &Loader::pass); + add("method", &Loader::method); } void Technique::Loader::set_inline_base_name(const string &n) @@ -130,27 +130,27 @@ void Technique::Loader::set_inline_base_name(const string &n) void Technique::Loader::inherit(const string &n) { - obj.passes = get_collection().get(n).get_passes(); + obj.methods = get_collection().get(n).get_methods(); InheritLoader ldr(obj, get_collection()); load_sub_with(ldr); } -void Technique::Loader::pass(const string &n) +void Technique::Loader::method(const string &n) { - RenderPass p; + RenderMethod p; if(coll) { - RenderPass::Loader ldr(p, get_collection()); - ldr.set_inline_base_name(format("%s/%s.pass", (inline_base_name.empty() ? FS::basename(get_source()) : inline_base_name), n)); + RenderMethod::Loader ldr(p, get_collection()); + ldr.set_inline_base_name(format("%s/%s.method", (inline_base_name.empty() ? FS::basename(get_source()) : inline_base_name), n)); load_sub_with(ldr); } else load_sub(p); if(!p.get_shader_program()) - throw logic_error("no shader program in pass"); + throw logic_error("no shader program in method"); - insert_unique(obj.passes, n, p); + insert_unique(obj.methods, n, p); } @@ -169,15 +169,15 @@ void Technique::InheritLoader::material(const string &slot, const string &name) return; // For backwards compatibility - RenderPass &pass = get_item(obj.passes, slot); - if(const Material *base_mat = pass.get_material()) + RenderMethod &method = get_item(obj.methods, slot); + if(const Material *base_mat = method.get_material()) { - for(auto &kvp: obj.passes) + for(auto &kvp: obj.methods) if(kvp.second.get_material()==base_mat) kvp.second.set_material(&mat); } else - pass.set_material(&mat); + method.set_material(&mat); } void Technique::InheritLoader::texture(const string &slot, const string &name) diff --git a/source/materials/technique.h b/source/materials/technique.h index c2b69bf7..4e6b908d 100644 --- a/source/materials/technique.h +++ b/source/materials/technique.h @@ -2,7 +2,7 @@ #define MSP_GL_TECHNIQUE_H_ #include -#include "renderpass.h" +#include "rendermethod.h" #include "tag.h" namespace Msp { @@ -12,7 +12,7 @@ class Material; class Texture; /** -Ties multiple tagged render passes together. +Ties multiple tagged render methods together. */ class Technique { @@ -35,7 +35,7 @@ public: private: void inherit(const std::string &); - void pass(const std::string &); + void method(const std::string &); }; private: @@ -50,14 +50,14 @@ private: void uniforms(); }; - std::map passes; + std::map methods; public: - RenderPass &add_pass(Tag); - bool has_pass(Tag) const; - const RenderPass &get_pass(Tag) const; - const RenderPass *find_pass(Tag) const; - const std::map &get_passes() const { return passes; } + RenderMethod &add_method(Tag); + bool has_method(Tag) const; + const RenderMethod &get_method(Tag) const; + const RenderMethod *find_method(Tag) const; + const std::map &get_methods() const { return methods; } bool replace_texture(const std::string &, const Texture &); bool replace_material(const std::string &, const Material &); bool replace_uniforms(const ProgramData &); diff --git a/source/render/instancearray.cpp b/source/render/instancearray.cpp index d27fa819..f6a7bb63 100644 --- a/source/render/instancearray.cpp +++ b/source/render/instancearray.cpp @@ -21,7 +21,7 @@ InstanceArray::InstanceArray(const Object &o): matrix_offset(0) { const Technique *tech = object.get_technique(); - for(const auto &kvp: tech->get_passes()) + for(const auto &kvp: tech->get_methods()) { const Program *shprog = kvp.second.get_shader_program(); if(!shprog) @@ -101,8 +101,8 @@ void InstanceArray::render(Renderer &renderer, Tag tag) const const Technique *tech = object.get_technique(); if(!tech) throw logic_error("no technique"); - const RenderPass *pass = tech->find_pass(tag); - if(!pass) + const RenderMethod *method = tech->find_method(tag); + if(!method) return; const Mesh *mesh = object.get_mesh(); @@ -112,7 +112,7 @@ void InstanceArray::render(Renderer &renderer, Tag tag) const instance_data.refresh(); Renderer::Push push(renderer); - pass->apply(renderer); + method->apply(renderer); mesh->draw_instanced(renderer, vtx_setup, instances.size()); } diff --git a/source/render/object.cpp b/source/render/object.cpp index 34eebec7..b6343474 100644 --- a/source/render/object.cpp +++ b/source/render/object.cpp @@ -130,8 +130,8 @@ const Technique *Object::get_technique(unsigned i) const void Object::render(Renderer &renderer, Tag tag) const { - const RenderPass *pass = get_pass(tag, 0); - if(!pass) + const RenderMethod *method = get_method(tag, 0); + if(!method) return; const Mesh *mesh = lods.front().mesh; @@ -139,7 +139,7 @@ void Object::render(Renderer &renderer, Tag tag) const throw logic_error("no mesh"); Renderer::Push push(renderer); - pass->apply(renderer); + method->apply(renderer); setup_render(renderer, tag); mesh->draw(renderer); @@ -149,8 +149,8 @@ void Object::render(Renderer &renderer, Tag tag) const void Object::render(Renderer &renderer, const ObjectInstance &inst, Tag tag) const { unsigned lod = min(inst.get_level_of_detail(renderer), lods.size()-1); - const RenderPass *pass = get_pass(tag, lod); - if(!pass) + const RenderMethod *method = get_method(tag, lod); + if(!method) return; const Mesh *mesh = lods[lod].mesh; @@ -158,7 +158,7 @@ void Object::render(Renderer &renderer, const ObjectInstance &inst, Tag tag) con throw logic_error("no mesh"); Renderer::Push push(renderer); - pass->apply(renderer); + method->apply(renderer); setup_render(renderer, tag); inst.setup_render(renderer, tag); @@ -167,12 +167,12 @@ void Object::render(Renderer &renderer, const ObjectInstance &inst, Tag tag) con finish_render(renderer, tag); } -const RenderPass *Object::get_pass(Tag tag, unsigned lod) const +const RenderMethod *Object::get_method(Tag tag, unsigned lod) const { const Technique *tech = lods[lod].technique; if(!tech) throw logic_error("no technique"); - return tech->find_pass(tag); + return tech->find_method(tag); } void Object::resource_loaded(Resource &res) diff --git a/source/render/object.h b/source/render/object.h index ac62c702..dea389e4 100644 --- a/source/render/object.h +++ b/source/render/object.h @@ -3,7 +3,7 @@ #include #include "renderable.h" -#include "renderpass.h" +#include "rendermethod.h" #include "resourceobserver.h" namespace Msp { @@ -118,7 +118,7 @@ protected: virtual void finish_render(Renderer &, Tag) const { } private: - const RenderPass *get_pass(Tag, unsigned) const; + const RenderMethod *get_method(Tag, unsigned) const; virtual void resource_loaded(Resource &); virtual void resource_removed(Resource &); diff --git a/source/render/renderable.h b/source/render/renderable.h index 022c8708..aa895eed 100644 --- a/source/render/renderable.h +++ b/source/render/renderable.h @@ -14,7 +14,7 @@ class Renderer; Base class for renderable objects. Rendering is performed with the help of a Renderer object. -The render method takes a Tag to identify a render pass. It can be used with +The render method takes a Tag to identify a render method. It can be used with a Technique to select alternative rendering methods, such as simplified shaders for a depth-only shadow pass. diff --git a/source/render/text.cpp b/source/render/text.cpp index 5305de4b..cb7f998e 100644 --- a/source/render/text.cpp +++ b/source/render/text.cpp @@ -27,8 +27,8 @@ void Text::set_technique(const Technique *tech, Tag tex_slot) { if(tech) { - if(!tex_slot.id && tech->has_pass(Tag())) - if(const Program *shprog = tech->get_pass(Tag()).get_shader_program()) + if(!tex_slot.id && tech->has_method(Tag())) + if(const Program *shprog = tech->get_method(Tag()).get_shader_program()) { if(shprog->get_uniform_location(Tag("font_tex"))>=0) tex_slot = "font_tex"; diff --git a/tools/viewer.cpp b/tools/viewer.cpp index 4c7b01e8..a1703ede 100644 --- a/tools/viewer.cpp +++ b/tools/viewer.cpp @@ -177,7 +177,7 @@ Viewer::Viewer(int argc, char **argv): object = new GL::Object; GL::Technique *tech = new GL::Technique; - tech->add_pass(0); + tech->add_method(0); object->set_mesh(mesh); object->set_technique(tech); renderable = object;