#include <msp/core/algorithm.h>
#include <msp/core/maputils.h>
#include <msp/strings/format.h>
+#include "deviceinfo.h"
#include "error.h"
-#include "renderbuffer.h"
#include "sequence.h"
#include "sequencebuilder.h"
#include "sequencetemplate.h"
+#include "view.h"
using namespace std;
SequenceBuilder::SequenceBuilder(const SequenceTemplate &t):
tmpl(t)
{
- const vector<SequenceTemplate::Step> &steps = tmpl.get_steps();
- for(vector<SequenceTemplate::Step>::const_iterator i=steps.begin(); i!=steps.end(); ++i)
- renderables[i->slot_name] = i->default_renderable;
- const vector<SequenceTemplate::PostProcessor> &postprocs = tmpl.get_postprocessors();
- for(SequenceTemplate::PostProcessorArray::const_iterator i=postprocs.begin(); i!=postprocs.end(); ++i)
- if(!i->slot_name.empty())
- postprocessors[i->slot_name] = 0;
+ for(const SequenceTemplate::Step &s: tmpl.get_steps())
+ renderables[s.slot_name] = s.default_renderable;
+ for(const SequenceTemplate::PostProcessor &p: tmpl.get_postprocessors())
+ if(!p.slot_name.empty())
+ postprocessors[p.slot_name] = 0;
}
void SequenceBuilder::set_renderable(const string &name, Renderable &rend)
sequence.set_debug_name(debug_name);
#endif
- sequence.set_hdr(tmpl.get_hdr());
- sequence.set_alpha(tmpl.get_alpha());
- unsigned samples = min(tmpl.get_maximum_multisample(), Renderbuffer::get_max_samples());
- if(samples<tmpl.get_required_multisample())
- throw invalid_operation("SequenceBuilder::build");
-
- sequence.set_multisample(samples);
+ sequence.set_clear_enabled(tmpl.is_clear_enabled());
+ if(tmpl.is_clear_enabled())
+ {
+ sequence.set_clear_colors(tmpl.get_clear_colors());
+ sequence.set_clear_depth(tmpl.get_clear_depth());
+ sequence.set_clear_stencil(tmpl.get_clear_stencil());
+ }
- const vector<SequenceTemplate::Step> &steps = tmpl.get_steps();
- for(vector<SequenceTemplate::Step>::const_iterator i=steps.begin(); i!=steps.end(); ++i)
+ for(const SequenceTemplate::Step &s: tmpl.get_steps())
{
- Renderable *renderable = get_item(renderables, i->slot_name);
+ Renderable *renderable = get_item(renderables, s.slot_name);
if(!renderable)
continue;
- Sequence::Step &step = sequence.add_step(i->tag, *renderable);
- step.set_blend(i->blend.get());
- step.set_depth_test(i->depth_test.get());
- step.set_lighting(i->lighting);
+ Sequence::Step &step = sequence.add_step(s.tag, *renderable);
+ step.set_depth_test(s.depth_test);
+ step.set_stencil_test(s.stencil_test);
+ step.set_lighting(s.lighting);
}
- const SequenceTemplate::PostProcessorArray &postprocs = tmpl.get_postprocessors();
- for(SequenceTemplate::PostProcessorArray::const_iterator i=postprocs.begin(); i!=postprocs.end(); ++i)
+#ifdef DEBUG
+ unsigned index = 0;
+#endif
+ for(const SequenceTemplate::PostProcessor &p: tmpl.get_postprocessors())
{
PostProcessor *proc = 0;
- if(!i->slot_name.empty())
- proc = get_item(postprocessors, i->slot_name);
+ if(!p.slot_name.empty())
+ proc = get_item(postprocessors, p.slot_name);
if(proc)
sequence.add_postprocessor(*proc);
- else if(i->postprocessor_template)
+ else if(p.postprocessor_template)
{
- proc = i->postprocessor_template->create(sequence.get_width(), sequence.get_height());
+ proc = p.postprocessor_template->create(sequence.get_width(), sequence.get_height());
if(proc)
{
#ifdef DEBUG
if(!debug_name.empty())
- proc->set_debug_name(format("%s/%d.pproc", debug_name, i-postprocs.begin()));
+ proc->set_debug_name(format("%s/%d.pproc", debug_name, index++));
#endif
sequence.add_postprocessor_owned(proc);
}
}
}
+Sequence *SequenceBuilder::build() const
+{
+ RefPtr<Sequence> sequence = new Sequence();
+ build(*sequence);
+ return sequence.release();
+}
+
Sequence *SequenceBuilder::build(unsigned w, unsigned h) const
{
- RefPtr<Sequence> sequence = new Sequence(w, h);
+ RefPtr<Sequence> sequence = new Sequence(w, h, create_frame_format());
build(*sequence);
return sequence.release();
}
Sequence *SequenceBuilder::build(const View &view) const
{
- RefPtr<Sequence> sequence = new Sequence(view);
+ RefPtr<Sequence> sequence = new Sequence(view.get_width(), view.get_height(), create_frame_format());
build(*sequence);
return sequence.release();
}
Sequence *SequenceBuilder::build(const Framebuffer &fbo) const
{
- RefPtr<Sequence> sequence = new Sequence(fbo);
+ RefPtr<Sequence> sequence = new Sequence(fbo.get_width(), fbo.get_height(), create_frame_format());
build(*sequence);
return sequence.release();
}
+FrameFormat SequenceBuilder::create_frame_format() const
+{
+ unsigned samples = min(tmpl.get_maximum_multisample(), DeviceInfo::get_global().limits.max_samples);
+ if(samples<tmpl.get_required_multisample())
+ throw invalid_operation("SequenceBuilder::create_frame_format");
+
+ PixelComponents color_comp = (tmpl.get_alpha() ? RGBA : RGB);
+ DataType color_type = (tmpl.get_hdr() ? HALF_FLOAT : UNSIGNED_BYTE);
+ PixelFormat color_pf = make_pixelformat(color_comp, color_type);
+
+ return (COLOR_ATTACHMENT,color_pf, DEPTH_ATTACHMENT).set_samples(samples);
+}
+
} // namespace GL
} // namespace Msp