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(const UInt16 *i=f.begin(); i!=f.end(); ++i)
22 FrameAttachment fa = static_cast<FrameAttachment>(*i);
23 PixelFormat pf = get_attachment_pixelformat(*i);
27 Texture2DMultisample *tex2d_ms = new Texture2DMultisample;
28 tex2d_ms->storage(pf, width, height, samples);
29 fbo.attach(fa, *tex2d_ms);
30 textures.push_back(tex2d_ms);
34 Texture2D *tex2d = new Texture2D;
35 tex2d->storage(pf, width, height, 1);
36 fbo.attach(fa, *tex2d);
37 textures.push_back(tex2d);
42 RenderTarget::~RenderTarget()
44 for(Texture *t: textures)
48 const Texture2D &RenderTarget::get_target_texture(unsigned i) const
50 if(i>=textures.size())
51 throw out_of_range("RenderTarget::get_target_texture");
52 if(fbo.get_format().get_samples()>1)
53 throw invalid_operation("RenderTarget::get_target_texture");
55 return *static_cast<const Texture2D *>(textures[i]);
58 const Texture2D &RenderTarget::get_target_texture(FrameAttachment fa) const
60 int index = fbo.get_format().index(fa);
64 return get_target_texture(index);
67 void RenderTarget::set_debug_name(const string &name)
70 fbo.set_debug_name(name+" [FBO]");
71 const FrameFormat &fmt = fbo.get_format();
73 for(const UInt16 *j=fmt.begin(); j!=fmt.end(); ++i, ++j)
75 unsigned attach_pt = get_attach_point(static_cast<FrameAttachment>(*j));
78 if(attach_pt==get_attach_point(DEPTH_ATTACHMENT))
79 tex_name = name+"/depth";
80 else if(attach_pt==get_attach_point(STENCIL_ATTACHMENT))
81 tex_name = name+"/stencil";
83 tex_name = Msp::format("%s/color%d", name, attach_pt);
85 textures[i]->set_debug_name(tex_name+".tex2d");