]> git.tdb.fi Git - libs/gl.git/blobdiff - source/builders/sequencebuilder.cpp
Allow creating sequences without size
[libs/gl.git] / source / builders / sequencebuilder.cpp
index c45d0cc67c6b2b8ba03f6688aa5e6709bf890fb8..2c170511fcb5eb049c9aaccabf03d61ae1d77313 100644 (file)
@@ -1,10 +1,12 @@
 #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;
 
@@ -14,13 +16,11 @@ namespace GL {
 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)
@@ -33,66 +33,100 @@ void SequenceBuilder::set_postprocessor(const string &name, PostProcessor &pproc
        get_item(postprocessors, name) = &pproc;
 }
 
-void SequenceBuilder::build(Sequence &sequence) const
+void SequenceBuilder::set_debug_name(const string &name)
 {
-       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");
+#ifdef DEBUG
+       debug_name = name;
+#else
+       (void)name;
+#endif
+}
 
-       sequence.set_multisample(samples);
+void SequenceBuilder::build(Sequence &sequence) const
+{
+#ifdef DEBUG
+       if(!debug_name.empty())
+               sequence.set_debug_name(debug_name);
+#endif
 
-       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.get());
+               Sequence::Step &step = sequence.add_step(s.tag, *renderable);
+               step.set_blend(s.blend);
+               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, 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(), Limits::get_global().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