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 textures.reserve(f.size());
19 unsigned samples = f.get_samples();
20 for(FrameAttachment a: f)
22 PixelFormat pf = get_attachment_pixelformat(a);
26 Texture2DMultisample *tex2d_ms = new Texture2DMultisample;
27 tex2d_ms->storage(pf, width, height, samples);
28 fbo.attach(a, *tex2d_ms);
29 textures.push_back(tex2d_ms);
33 Texture2D *tex2d = new Texture2D;
34 tex2d->storage(pf, width, height, 1);
35 fbo.attach(a, *tex2d);
36 textures.push_back(tex2d);
41 RenderTarget::~RenderTarget()
43 for(Texture *t: textures)
47 const Texture2D &RenderTarget::get_target_texture(unsigned i) const
49 if(i>=textures.size())
50 throw out_of_range("RenderTarget::get_target_texture");
51 if(fbo.get_format().get_samples()>1)
52 throw invalid_operation("RenderTarget::get_target_texture");
54 return *static_cast<const Texture2D *>(textures[i]);
57 const Texture2D &RenderTarget::get_target_texture(FrameAttachment fa) const
59 int index = fbo.get_format().index(fa);
63 return get_target_texture(index);
66 void RenderTarget::set_debug_name(const string &name)
69 fbo.set_debug_name(name+" [FBO]");
71 for(FrameAttachment a: fbo.get_format())
73 unsigned attach_pt = get_attach_point(a);
76 if(attach_pt==get_attach_point(DEPTH_ATTACHMENT))
77 tex_name = name+"/depth";
78 else if(attach_pt==get_attach_point(STENCIL_ATTACHMENT))
79 tex_name = name+"/stencil";
81 tex_name = Msp::format("%s/color%d", name, attach_pt);
83 textures[i++]->set_debug_name(tex_name+".tex");