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))
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"):
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)
--- /dev/null
+#include <msp/core/algorithm.h>
+#include <msp/datafile/collection.h>
+#include <msp/strings/format.h>
+#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<string, int> 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<RenderMethod>(p, 0)
+{
+ set_actions(shared_actions);
+}
+
+RenderMethod::Loader::Loader(RenderMethod &p, Collection &c):
+ DataFile::CollectionObjectLoader<RenderMethod>(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<Material> 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<Material>(name);
+ obj.set_material_textures();
+}
+
+void RenderMethod::Loader::shader(const string &n)
+{
+ obj.shprog = &get_collection().get<Program>(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<TextureSlot>(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
--- /dev/null
+#ifndef MSP_GL_RENDERPASS_H_
+#define MSP_GL_RENDERPASS_H_
+
+#include <msp/core/refptr.h>
+#include <msp/datafile/objectloader.h>
+#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<RenderMethod>
+ {
+ 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<TextureSlot>
+ {
+ 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<ProgramData> shdata;
+ std::map<Tag, Tag> uniform_slots;
+ const Material *material;
+ std::string material_slot;
+ std::vector<TextureSlot> 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
+++ /dev/null
-#include <msp/core/algorithm.h>
-#include <msp/datafile/collection.h>
-#include <msp/strings/format.h>
-#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<string, int> 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<RenderPass>(p, 0)
-{
- set_actions(shared_actions);
-}
-
-RenderPass::Loader::Loader(RenderPass &p, Collection &c):
- DataFile::CollectionObjectLoader<RenderPass>(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<Material> 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<Material>(name);
- obj.set_material_textures();
-}
-
-void RenderPass::Loader::shader(const string &n)
-{
- obj.shprog = &get_collection().get<Program>(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<TextureSlot>(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
+++ /dev/null
-#ifndef MSP_GL_RENDERPASS_H_
-#define MSP_GL_RENDERPASS_H_
-
-#include <msp/core/refptr.h>
-#include <msp/datafile/objectloader.h>
-#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<RenderPass>
- {
- 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<TextureSlot>
- {
- 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<ProgramData> shdata;
- std::map<Tag, Tag> uniform_slots;
- const Material *material;
- std::string material_slot;
- std::vector<TextureSlot> 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
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)
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)
{
bool replaced = false;
const vector<Tag> &uniform_tags = shdata.get_uniform_tags();
- for(auto &kvp: passes)
+ for(auto &kvp: methods)
{
RefPtr<ProgramData> new_shdata;
for(Tag t: uniform_tags)
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
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)
void Technique::Loader::inherit(const string &n)
{
- obj.passes = get_collection().get<Technique>(n).get_passes();
+ obj.methods = get_collection().get<Technique>(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);
}
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)
#define MSP_GL_TECHNIQUE_H_
#include <map>
-#include "renderpass.h"
+#include "rendermethod.h"
#include "tag.h"
namespace Msp {
class Texture;
/**
-Ties multiple tagged render passes together.
+Ties multiple tagged render methods together.
*/
class Technique
{
private:
void inherit(const std::string &);
- void pass(const std::string &);
+ void method(const std::string &);
};
private:
void uniforms();
};
- std::map<Tag, RenderPass> passes;
+ std::map<Tag, RenderMethod> 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<Tag, RenderPass> &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<Tag, RenderMethod> &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 &);
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)
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();
instance_data.refresh();
Renderer::Push push(renderer);
- pass->apply(renderer);
+ method->apply(renderer);
mesh->draw_instanced(renderer, vtx_setup, instances.size());
}
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;
throw logic_error("no mesh");
Renderer::Push push(renderer);
- pass->apply(renderer);
+ method->apply(renderer);
setup_render(renderer, tag);
mesh->draw(renderer);
void Object::render(Renderer &renderer, const ObjectInstance &inst, Tag tag) const
{
unsigned lod = min<unsigned>(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;
throw logic_error("no mesh");
Renderer::Push push(renderer);
- pass->apply(renderer);
+ method->apply(renderer);
setup_render(renderer, tag);
inst.setup_render(renderer, tag);
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)
#include <vector>
#include "renderable.h"
-#include "renderpass.h"
+#include "rendermethod.h"
#include "resourceobserver.h"
namespace Msp {
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 &);
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.
{
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";
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;