From c0b7d6ee4a7478f5aecb1504429ec1fc846d64ed Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 2 Oct 2021 19:23:36 +0300 Subject: [PATCH] Rename RenderPass to RenderMethod This is mostly to avoid confusion with Vulkan's render passes, which are an entirely different thing. --- blender/io_mspgl/export_material.py | 4 +- blender/io_mspgl/export_object.py | 2 +- .../{renderpass.cpp => rendermethod.cpp} | 68 +++++++++---------- .../{renderpass.h => rendermethod.h} | 10 +-- source/materials/technique.cpp | 52 +++++++------- source/materials/technique.h | 18 ++--- source/render/instancearray.cpp | 8 +-- source/render/object.cpp | 16 ++--- source/render/object.h | 4 +- source/render/renderable.h | 2 +- source/render/text.cpp | 4 +- tools/viewer.cpp | 2 +- 12 files changed, 95 insertions(+), 95 deletions(-) rename source/materials/{renderpass.cpp => rendermethod.cpp} (67%) rename source/materials/{renderpass.h => rendermethod.h} (93%) 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/renderpass.cpp b/source/materials/rendermethod.cpp similarity index 67% rename from source/materials/renderpass.cpp rename to source/materials/rendermethod.cpp index a055f478..a6a843ee 100644 --- a/source/materials/renderpass.cpp +++ b/source/materials/rendermethod.cpp @@ -2,7 +2,7 @@ #include #include #include "error.h" -#include "renderpass.h" +#include "rendermethod.h" #include "program.h" #include "programdata.h" #include "renderer.h" @@ -14,7 +14,7 @@ using namespace std; namespace Msp { namespace GL { -RenderPass::RenderPass(): +RenderMethod::RenderMethod(): shprog(0), shprog_from_material(false), shdata(0), @@ -24,14 +24,14 @@ RenderPass::RenderPass(): image_based_lighting(false) { } -void RenderPass::set_material_textures() +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 RenderPass::maybe_create_material_shader() +void RenderMethod::maybe_create_material_shader() { if(shprog && !shprog_from_material) return; @@ -50,14 +50,14 @@ void RenderPass::maybe_create_material_shader() shprog_from_material = true; } -void RenderPass::set_shader_program(const Program *prog, const ProgramData *data) +void RenderMethod::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 +Tag RenderMethod::get_slotted_uniform_tag(Tag slot) const { auto i = uniform_slots.find(slot); if(i==uniform_slots.end()) @@ -65,14 +65,14 @@ Tag RenderPass::get_slotted_uniform_tag(Tag slot) const return i->second; } -void RenderPass::set_material(const Material *mat) +void RenderMethod::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) +void RenderMethod::set_texture(Tag tag, const Texture *tex, const Sampler *samp) { auto i = find_member(textures, tag, &TextureSlot::tag); if(i==textures.end()) @@ -85,23 +85,23 @@ void RenderPass::set_texture(Tag tag, const Texture *tex, const Sampler *samp) i->sampler = samp; } -Tag RenderPass::get_texture_tag(const string &slot) const +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 RenderPass::set_face_cull(CullMode fc) +void RenderMethod::set_face_cull(CullMode fc) { face_cull = fc; } -void RenderPass::set_receive_shadows(bool rs) +void RenderMethod::set_receive_shadows(bool rs) { receive_shadows = rs; } -void RenderPass::apply(Renderer &renderer) const +void RenderMethod::apply(Renderer &renderer) const { for(const TextureSlot &t: textures) renderer.set_texture(t.tag, t.texture, t.sampler); @@ -111,7 +111,7 @@ void RenderPass::apply(Renderer &renderer) const renderer.set_face_cull(face_cull); } -void RenderPass::set_debug_name(const string &name) +void RenderMethod::set_debug_name(const string &name) { #ifdef DEBUG if(shdata.refcount()==1) @@ -122,47 +122,47 @@ void RenderPass::set_debug_name(const string &name) } -DataFile::Loader::ActionMap RenderPass::Loader::shared_actions; +DataFile::Loader::ActionMap RenderMethod::Loader::shared_actions; -RenderPass::Loader::Loader(RenderPass &p): - DataFile::CollectionObjectLoader(p, 0) +RenderMethod::Loader::Loader(RenderMethod &p): + DataFile::CollectionObjectLoader(p, 0) { set_actions(shared_actions); } -RenderPass::Loader::Loader(RenderPass &p, Collection &c): - DataFile::CollectionObjectLoader(p, &c) +RenderMethod::Loader::Loader(RenderMethod &p, Collection &c): + DataFile::CollectionObjectLoader(p, &c) { set_actions(shared_actions); } -void RenderPass::Loader::init_actions() +void RenderMethod::Loader::init_actions() { - add("face_cull", &RenderPass::face_cull); + add("face_cull", &RenderMethod::face_cull); add("shader", &Loader::shader); - add("image_based_lighting", &RenderPass::image_based_lighting); + add("image_based_lighting", &RenderMethod::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("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 RenderPass::Loader::set_inline_base_name(const string &n) +void RenderMethod::Loader::set_inline_base_name(const string &n) { inline_base_name = n; } -void RenderPass::Loader::finish() +void RenderMethod::Loader::finish() { if(obj.material) obj.maybe_create_material_shader(); } -void RenderPass::Loader::material_inline() +void RenderMethod::Loader::material_inline() { Material::GenericLoader ldr(coll); load_sub_with(ldr); @@ -172,13 +172,13 @@ void RenderPass::Loader::material_inline() obj.set_material_textures(); } -void RenderPass::Loader::material(const string &name) +void RenderMethod::Loader::material(const string &name) { obj.material = &get_collection().get(name); obj.set_material_textures(); } -void RenderPass::Loader::shader(const string &n) +void RenderMethod::Loader::shader(const string &n) { obj.shprog = &get_collection().get(n); obj.shprog_from_material = false; @@ -186,7 +186,7 @@ void RenderPass::Loader::shader(const string &n) obj.shdata = new ProgramData(*obj.shdata, obj.shprog); } -void RenderPass::Loader::texture(const string &n) +void RenderMethod::Loader::texture(const string &n) { auto i = find_member(obj.textures, Tag(n), &TextureSlot::tag); if(i==obj.textures.end()) @@ -198,7 +198,7 @@ void RenderPass::Loader::texture(const string &n) load_sub_with(ldr); } -void RenderPass::Loader::uniforms() +void RenderMethod::Loader::uniforms() { if(!obj.shprog || obj.shprog_from_material) throw runtime_error("Shader is required for uniforms"); @@ -209,18 +209,18 @@ void RenderPass::Loader::uniforms() load_sub(*obj.shdata); } -void RenderPass::Loader::uniform_slot(const string &name) +void RenderMethod::Loader::uniform_slot(const string &name) { uniform_slot2(name, name); } -void RenderPass::Loader::uniform_slot2(const string &name, const string &slot) +void RenderMethod::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): +RenderMethod::TextureSlot::Loader::Loader(TextureSlot &ts, const string &an, Collection *c): CollectionObjectLoader(ts, c), auto_slot_name(an) { @@ -230,7 +230,7 @@ RenderPass::TextureSlot::Loader::Loader(TextureSlot &ts, const string &an, Colle add("texture", &TextureSlot::texture); } -void RenderPass::TextureSlot::Loader::slot_auto() +void RenderMethod::TextureSlot::Loader::slot_auto() { obj.slot_name = auto_slot_name; } diff --git a/source/materials/renderpass.h b/source/materials/rendermethod.h similarity index 93% rename from source/materials/renderpass.h rename to source/materials/rendermethod.h index ae9e34b8..11c7e858 100644 --- a/source/materials/renderpass.h +++ b/source/materials/rendermethod.h @@ -19,10 +19,10 @@ 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 +class RenderMethod { public: - class Loader: public DataFile::CollectionObjectLoader + class Loader: public DataFile::CollectionObjectLoader { private: std::string inline_base_name; @@ -30,8 +30,8 @@ public: static ActionMap shared_actions; public: - Loader(RenderPass &); - Loader(RenderPass &, Collection &); + Loader(RenderMethod &); + Loader(RenderMethod &, Collection &); private: virtual void init_actions(); @@ -85,7 +85,7 @@ private: bool image_based_lighting; public: - RenderPass(); + RenderMethod(); private: void maybe_create_material_shader(); 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; -- 2.45.2