seq_res.statements.append(ss)
scene_res = resources[scene.name+".scene"]
+ seq_res.statements.append(seq_res.create_reference_statement("renderable", "content", scene_res))
+
lighting_res = resources[scene.name+".lightn"]
any_opaque = False
ss = Statement("step", "", "content")
ss.sub.append(Statement("depth_test", Token("LEQUAL")))
ss.sub.append(seq_res.create_reference_statement("lighting", lighting_res))
- ss.sub.append(seq_res.create_reference_statement("scene", scene_res))
seq_res.statements.append(ss)
if any_blended:
ss = Statement("step", "blended", "content")
ss.sub.append(Statement("depth_test", Token("LEQUAL")))
ss.sub.append(seq_res.create_reference_statement("lighting", lighting_res))
- ss.sub.append(seq_res.create_reference_statement("scene", scene_res))
seq_res.statements.append(ss)
if scene.use_ao:
- ss = Statement("ambient_occlusion")
+ ss = Statement("postprocessor")
+ ss.sub.append(Statement("type", Token("ambient_occlusion")))
ss.sub.append(Statement("occlusion_radius", scene.ao_distance))
ss.sub.append(Statement("samples", scene.ao_samples))
seq_res.statements.append(ss)
if scene.use_hdr:
- seq_res.statements.append(Statement("bloom"))
- ss = Statement("colorcurve")
+ ss = Statement("postprocessor")
+ ss.sub.append(Statement("type", Token("bloom")))
+ seq_res.statements.append(ss)
+
+ ss = Statement("postprocessor")
+ ss.sub.append(Statement("type", Token("colorcurve")))
ss.sub.append(Statement("exposure_adjust", scene.exposure))
ss.sub.append(Statement("srgb"))
seq_res.statements.append(ss)
else:
# Add a colorcurve with linear response to convert into sRGB color space
- ss = Statement("colorcurve")
+ ss = Statement("postprocessor")
+ ss.sub.append(Statement("type", Token("colorcurve")))
ss.sub.append(Statement("brightness_response", 1.0))
ss.sub.append(Statement("srgb"))
seq_res.statements.append(ss)
SequenceBuilder::SequenceBuilder(const SequenceTemplate &t):
tmpl(t)
{
- for(const SequenceTemplate::Step &s: tmpl.get_steps())
- renderables[s.slot_name] = s.default_renderable;
+ for(const SequenceTemplate::Renderable &r: tmpl.get_renderables())
+ renderables[r.slot_name] = r.renderable;
for(const SequenceTemplate::PostProcessor &p: tmpl.get_postprocessors())
if(!p.slot_name.empty())
postprocessors[p.slot_name] = 0;
for(const SequenceTemplate::Step &s: tmpl.get_steps())
{
- Renderable *renderable = get_item(renderables, s.slot_name);
+ Renderable *renderable = get_item(renderables, s.renderable_name);
if(!renderable)
continue;
delete p.postprocessor_template;
}
-
-SequenceTemplate::PostProcessorRegistry &SequenceTemplate::get_postprocessor_registry()
+template<>
+SequenceTemplate::TemplateRegistry<GL::PostProcessor> &SequenceTemplate::get_registry<GL::PostProcessor>()
{
- static PostProcessorRegistry registry;
+ static TemplateRegistry<GL::PostProcessor> registry;
static bool initialized = false;
if(!initialized)
{
- registry.register_type<AmbientOcclusion>("ambient_occlusion");
- registry.register_type<Bloom>("bloom");
- registry.register_type<ColorCurve>("colorcurve");
+ registry.register_type<AmbientOcclusion::Template>("ambient_occlusion");
+ registry.register_type<Bloom::Template>("bloom");
+ registry.register_type<ColorCurve::Template>("colorcurve");
initialized = true;
}
return registry;
{ }
-SequenceTemplate::PostProcLoader::PostProcLoader()
-{
- get_postprocessor_registry().invoke_all(*this);
-}
-
-
SequenceTemplate::Loader::Loader(SequenceTemplate &t, Collection &c):
- DataFile::CollectionObjectLoader<SequenceTemplate, Resources>(t, &c)
+ CollectionObjectLoader<SequenceTemplate>(t, &c)
{
add("hdr", &SequenceTemplate::hdr);
add("alpha", &SequenceTemplate::alpha);
add("multisample", &Loader::multisample);
add("multisample", &Loader::multisample_range);
add("postprocessor", &Loader::postprocessor);
+ add("postprocessor", &Loader::postprocessor_with_slot);
+ add("renderable", &Loader::renderable);
+ add("renderable", &Loader::renderable_with_default);
add("step", &Loader::step);
- add("step", &Loader::step_with_slot);
-
- // Deprecated
- add("pass", &Loader::step_with_slot);
-}
-
-void SequenceTemplate::Loader::postprocessor_loaded()
-{
- obj.postprocessors.push_back(get_postprocessor_template());
}
void SequenceTemplate::Loader::clear()
obj.max_multisample = max;
}
-void SequenceTemplate::Loader::postprocessor(const string &slot)
+void SequenceTemplate::Loader::postprocessor()
{
- PostProcLoader ldr;
+ postprocessor_with_slot(string());
+}
+
+void SequenceTemplate::Loader::postprocessor_with_slot(const string &slot)
+{
+ TemplateLoader<GL::PostProcessor> ldr(get_collection());
load_sub_with(ldr);
PostProcessor pp;
- pp.postprocessor_template = ldr.get_postprocessor_template();
+ pp.postprocessor_template = ldr.get_object();
pp.slot_name = slot;
obj.postprocessors.push_back(pp);
}
-void SequenceTemplate::Loader::step(const string &tag)
+void SequenceTemplate::Loader::renderable(const string &slot)
{
- step_with_slot(tag, string());
+ Renderable rend;
+ rend.slot_name = slot;
+ obj.renderables.push_back(rend);
}
-void SequenceTemplate::Loader::step_with_slot(const string &tag, const string &rend)
+void SequenceTemplate::Loader::renderable_with_default(const string &slot, const string &name)
+{
+ Renderable rend;
+ rend.renderable = &get_collection().get<GL::Renderable>(name);
+ rend.slot_name = slot;
+ obj.renderables.push_back(rend);
+}
+
+void SequenceTemplate::Loader::step(const string &tag, const string &rend)
{
Step stp;
stp.tag = tag;
- stp.slot_name = rend;
- Step::Loader ldr(stp, *coll);
+ stp.renderable_name = rend;
+ Step::Loader ldr(stp, get_collection());
ldr.set_inline_base_name(format("%s/%d.step", get_source(), obj.steps.size()));
load_sub_with(ldr);
add("depth_test", &Loader::depth_compare);
add("lighting", &Loader::lighting);
add("lighting", &Loader::lighting_inline);
- add("object", &Loader::object);
- add("scene", &Loader::scene);
add("stencil_test", &Loader::stencil_test);
}
obj.lighting = &get_collection().get<Lighting>(name);
}
-void SequenceTemplate::Step::Loader::object(const string &name)
-{
- obj.default_renderable = &get_collection().get<GL::Object>(name);
-}
-
-void SequenceTemplate::Step::Loader::scene(const string &name)
-{
- obj.default_renderable = &get_collection().get<Scene>(name);
-}
-
void SequenceTemplate::Step::Loader::stencil_test()
{
load_sub(obj.stencil_test);
#include <string>
#include <vector>
#include <msp/core/typeregistry.h>
+#include <msp/datafile/dynamicobjectloader.h>
#include <msp/datafile/objectloader.h>
#include "depthtest.h"
#include "postprocessor.h"
class SequenceTemplate
{
private:
- class PostProcLoader: virtual public DataFile::Loader
+ template<typename T>
+ class TemplateLoader: public DataFile::DynamicObjectLoader<typename T::Template>
{
- private:
- template<typename T>
- struct AddPostProc
- {
- void operator()(const std::string &kw, PostProcLoader &ldr) const { ldr.add(kw, &PostProcLoader::postprocessor<T>); }
- };
-
- protected:
- RefPtr<PostProcessor::Template> postproc;
+ friend class SequenceTemplate;
public:
- PostProcLoader();
-
- PostProcessor::Template *get_postprocessor_template() { return postproc.release(); }
-
- protected:
- virtual void postprocessor_loaded() { }
+ TemplateLoader(typename DataFile::DynamicObjectLoader<typename T::Template>::Collection &c): DataFile::DynamicObjectLoader<typename T::Template>(&c) { }
private:
- template<typename T>
- void postprocessor();
-
- friend class SequenceTemplate;
+ virtual typename DataFile::DynamicObjectLoader<typename T::Template>::TypeRegistry &get_type_registry() const { return get_registry<T>(); }
};
+ template<typename T>
+ using TemplateRegistry = typename TemplateLoader<T>::TypeRegistry;
+
public:
- class Loader: public DataFile::CollectionObjectLoader<SequenceTemplate, Resources>, public PostProcLoader
+ class Loader: public DataFile::CollectionObjectLoader<SequenceTemplate>
{
public:
Loader(SequenceTemplate &, Collection &);
private:
- virtual void postprocessor_loaded();
void clear();
void multisample(unsigned);
void multisample_range(unsigned, unsigned);
- void postprocessor(const std::string &);
- void step(const std::string &);
- void step_with_slot(const std::string &, const std::string &);
+ void postprocessor();
+ void postprocessor_with_slot(const std::string &);
+ void renderable(const std::string &);
+ void renderable_with_default(const std::string &, const std::string &);
+ void step(const std::string &, const std::string &);
+ };
+
+ struct Renderable
+ {
+ GL::Renderable *renderable = 0;
+ std::string slot_name;
};
struct Step
void depth_compare(Predicate);
void lighting(const std::string &);
void lighting_inline();
- void object(const std::string &);
- void scene(const std::string &);
void stencil_test();
};
const Lighting *lighting = 0;
DepthTest depth_test;
StencilTest stencil_test;
- std::string slot_name;
- Renderable *default_renderable = 0;
+ std::string renderable_name;
};
struct PostProcessor
void stencil(int);
};
- typedef TypeRegistry<PostProcLoader::AddPostProc, PostProcLoader &> PostProcessorRegistry;
-
bool hdr = false;
bool alpha = false;
unsigned required_multisample = 0;
unsigned max_multisample = 0;
+ std::vector<Renderable> renderables;
std::vector<Step> steps;
std::vector<PostProcessor> postprocessors;
bool clear_enabled = false;
bool get_alpha() const { return alpha; }
unsigned get_required_multisample() const { return required_multisample; }
unsigned get_maximum_multisample() const { return max_multisample; }
+ const std::vector<Renderable> &get_renderables() const { return renderables; }
const std::vector<Step> &get_steps() const { return steps; }
const std::vector<PostProcessor> &get_postprocessors() const { return postprocessors; }
bool is_clear_enabled() const { return clear_enabled; }
template<typename T>
static void register_postprocessor(const std::string &);
+
private:
- static PostProcessorRegistry &get_postprocessor_registry();
+ template<typename T>
+ static TemplateRegistry<T> &get_registry();
};
template<typename T>
void SequenceTemplate::register_postprocessor(const std::string &kw)
{
- get_postprocessor_registry().register_type<T>(kw);
-}
-
-template<typename T>
-void SequenceTemplate::PostProcLoader::postprocessor()
-{
- if(postproc)
- throw std::logic_error("Only one postprocessor allowed per slot");
- RefPtr<typename T::Template> pp = new typename T::Template;
- load_sub(*pp);
- postproc = pp;
- pp = 0;
- postprocessor_loaded();
+ get_registry<GL::PostProcessor>().register_type<typename T::Template>(kw);
}
} // namespace GL