#endif
for(const SequenceTemplate::PostProcessor &p: tmpl.get_postprocessors())
{
- PostProcessor *proc = 0;
+ RefPtr<PostProcessor> proc = 0;
if(!p.slot_name.empty())
proc = get_item(postprocessors, p.slot_name);
if(proc)
if(!debug_name.empty())
proc->set_debug_name(format("%s/%d.pproc", debug_name, index++));
#endif
- sequence.add_postprocessor_owned(proc);
+ sequence.add_postprocessor(*proc.get());
+ sequence.add_owned(proc.release());
}
}
}
Sequence::~Sequence()
{
- for(PostProcStep &p: postproc)
- if(p.owned)
- delete p.postproc;
+ for(OwnedObject &o: owned_data)
+ o.delete_func(o.pointer);
delete target[0];
delete target[1];
delete target_ms;
}
void Sequence::add_postprocessor(PostProcessor &pp)
-{
- add_postprocessor(&pp, false);
-}
-
-void Sequence::add_postprocessor_owned(PostProcessor *pp)
-{
- add_postprocessor(pp, true);
-}
-
-void Sequence::add_postprocessor(PostProcessor *pp, bool owned)
{
if(target_format.empty())
- {
- if(owned)
- delete pp;
throw invalid_operation("Sequence::add_postprocessor");
- }
- postproc.push_back(PostProcStep(pp, owned));
+ postproc.push_back(&pp);
}
void Sequence::setup_frame(Renderer &renderer)
renderer.set_framebuffer(i+1<postproc.size() ? &target[1-j]->get_framebuffer() : out_fbo);
const Texture2D &color = target[j]->get_target_texture(COLOR_ATTACHMENT);
const Texture2D &depth = target[j]->get_target_texture(DEPTH_ATTACHMENT);
- postproc[i].postproc->render(renderer, color, depth);
+ postproc[i]->render(renderer, color, depth);
}
}
}
};
private:
- struct PostProcStep
+ struct OwnedObject
{
- PostProcessor *postproc;
- bool owned;
+ void *pointer = 0;
+ void (*delete_func)(void *) = 0;
- PostProcStep(PostProcessor *pp, bool o): postproc(pp), owned(o) { }
+ OwnedObject(void *p, void (*d)(void *)): pointer(p), delete_func(d) { }
};
std::vector<Step> steps;
- std::vector<PostProcStep> postproc;
+ std::vector<PostProcessor *> postproc;
unsigned width = 0;
unsigned height = 0;
FrameFormat target_format;
std::vector<Color> clear_colors;
float clear_depth = 1.0f;
int clear_stencil = 0;
+ std::vector<OwnedObject> owned_data;
static Tag noclear_tag;
/** Adds a postprocessor to the sequence. */
void add_postprocessor(PostProcessor &);
- /** Adds a postprocessor to the sequence, transferring ownership. The
- postprocessor will be deleted together with with sequence. It is also
- deleted if this call throws an exception. */
- void add_postprocessor_owned(PostProcessor *);
+ /** Adds an owned object, which will be deleted together with the sequence. */
+ template<typename T>
+ void add_owned(T *p)
+ { owned_data.push_back({ p, [](void *ptr){ delete static_cast<T *>(ptr); } }); }
-private:
- void add_postprocessor(PostProcessor *, bool);
-
-public:
virtual void setup_frame(Renderer &);
virtual void finish_frame();