]> 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 12e7bdf3df96ea43c415e3674c5ffdf19d7cf764..2c170511fcb5eb049c9aaccabf03d61ae1d77313 100644 (file)
@@ -3,10 +3,10 @@
 #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;
 
@@ -16,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)
@@ -51,44 +49,37 @@ void SequenceBuilder::build(Sequence &sequence) const
                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(), Limits::get_global().max_samples);
-       if(samples<tmpl.get_required_multisample())
-               throw invalid_operation("SequenceBuilder::build");
-
-       sequence.set_multisample(samples);
-
-       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);
-               step.set_depth_test(i->depth_test);
-               step.set_stencil_test(i->stencil_test);
-               step.set_lighting(i->lighting);
+               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, i-postprocs.begin()));
+                                       proc->set_debug_name(format("%s/%d.pproc", debug_name, index++));
 #endif
                                sequence.add_postprocessor_owned(proc);
                        }
@@ -96,26 +87,46 @@ void SequenceBuilder::build(Sequence &sequence) const
        }
 }
 
+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