1 #include <msp/core/maputils.h>
2 #include <msp/strings/format.h>
4 #include "rendertarget.h"
6 #include "texture2dmultisample.h"
13 RenderTarget::RenderTarget(unsigned w, unsigned h, const FrameFormat &f):
18 bool multisample = (f.get_samples()>1);
19 textures.reserve(f.size()*(1+multisample));
20 unsigned samples = f.get_samples();
21 for(FrameAttachment a: f)
23 PixelFormat pf = get_attachment_pixelformat(a);
25 Texture2D *tex2d = new Texture2D;
26 tex2d->storage(pf, width, height, 1);
30 Texture2DMultisample *tex2d_ms = new Texture2DMultisample;
31 tex2d_ms->storage(pf, width, height, samples);
32 fbo.attach(a, *tex2d_ms, tex2d);
33 textures.push_back(tex2d_ms);
34 textures.push_back(tex2d);
38 fbo.attach(a, *tex2d);
39 textures.push_back(tex2d);
44 RenderTarget::~RenderTarget()
46 for(Texture *t: textures)
50 const Texture2D &RenderTarget::get_target_texture(unsigned i) const
52 if(i>=textures.size())
53 throw out_of_range("RenderTarget::get_target_texture");
54 if(fbo.get_format().get_samples()>1)
57 return *static_cast<const Texture2D *>(textures[i]);
60 const Texture2D &RenderTarget::get_target_texture(FrameAttachment fa) const
62 int index = fbo.get_format().index(fa);
66 return get_target_texture(index);
69 void RenderTarget::set_debug_name(const string &name)
72 fbo.set_debug_name(name+" [FBO]");
73 bool multisample = (fbo.get_format().get_samples()>1);
75 for(FrameAttachment a: fbo.get_format())
77 unsigned attach_pt = get_attach_point(a);
80 if(attach_pt==get_attach_point(DEPTH_ATTACHMENT))
81 tex_name = name+"/depth";
82 else if(attach_pt==get_attach_point(STENCIL_ATTACHMENT))
83 tex_name = name+"/stencil";
85 tex_name = Msp::format("%s/color%d", name, attach_pt);
87 textures[i++]->set_debug_name(tex_name+".tex");
89 textures[i++]->set_debug_name(tex_name+"_resolve.tex");