#include <msp/core/maputils.h>
+#include <msp/strings/format.h>
#include "error.h"
-#include "renderbuffer.h"
#include "rendertarget.h"
+#include "texture2d.h"
+#include "texture2dmultisample.h"
using namespace std;
PixelFormat pf = get_output_pixelformat(*i);
- TargetBuffer tgt;
if(samples)
{
- tgt.buffer = new Renderbuffer;
- tgt.buffer->storage_multisample(samples, pf, width, height);
- fbo.attach(att, *tgt.buffer);
+ Texture2DMultisample *tex2d_ms = new Texture2DMultisample;
+ tex2d_ms->storage(pf, width, height, samples);
+ fbo.attach(att, *tex2d_ms);
+ textures.push_back(tex2d_ms);
}
else
{
- tgt.texture = new Texture2D;
- tgt.texture->storage(pf, width, height, 1);
- Sampler &sampler = tgt.texture->get_default_sampler();
- sampler.set_filter(NEAREST);
- sampler.set_wrap(CLAMP_TO_EDGE);
- fbo.attach(att, *tgt.texture);
+ Texture2D *tex2d = new Texture2D;
+ tex2d->storage(pf, width, height, 1);
+ fbo.attach(att, *tex2d);
+ textures.push_back(tex2d);
}
- buffers.push_back(tgt);
}
-
- fbo.require_complete();
}
RenderTarget::~RenderTarget()
{
- for(vector<TargetBuffer>::iterator i=buffers.begin(); i!=buffers.end(); ++i)
- {
- if(samples)
- delete i->buffer;
- else
- delete i->texture;
- }
-}
-
-void RenderTarget::set_texture_filter(TextureFilter filt)
-{
- if(!samples)
- {
- for(vector<TargetBuffer>::iterator i=buffers.begin(); i!=buffers.end(); ++i)
- i->texture->get_default_sampler().set_filter(filt);
- }
+ for(vector<Texture *>::iterator i=textures.begin(); i!=textures.end(); ++i)
+ delete *i;
}
const Texture2D &RenderTarget::get_target_texture(unsigned i) const
{
- if(i>=buffers.size())
+ if(i>=textures.size())
throw out_of_range("RenderTarget::get_target_texture");
if(samples)
throw invalid_operation("RenderTarget::get_target_texture");
- return *buffers[i].texture;
+ return *static_cast<const Texture2D *>(textures[i]);
}
const Texture2D &RenderTarget::get_target_texture(RenderOutput o) const
return get_target_texture(index);
}
-void RenderTarget::blit_from(const RenderTarget &other)
+void RenderTarget::set_debug_name(const string &name)
{
- fbo.blit_from(other.fbo, COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT, false);
+#ifdef DEBUG
+ fbo.set_debug_name(name+" [FBO]");
+ unsigned i = 0;
+ for(const unsigned char *j=format.begin(); j!=format.end(); ++i, ++j)
+ {
+ unsigned type = get_output_type(*j);
+
+ string tex_name;
+ if(type>=get_output_type(RENDER_DEPTH))
+ tex_name = name+"/depth";
+ else
+ tex_name = Msp::format("%s/color%d", name, type);
+
+ textures[i]->set_debug_name(tex_name+".tex2d");
+ }
+#else
+ (void)name;
+#endif
}
} // namespace GL