#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);
- 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);
}
}
RenderTarget::~RenderTarget()
{
- for(vector<TargetBuffer>::iterator i=buffers.begin(); i!=buffers.end(); ++i)
- {
- if(samples)
- delete i->buffer;
- else
- delete i->texture;
- }
+ 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
{
unsigned type = get_output_type(*j);
- string buf_name;
+ string tex_name;
if(type>=get_output_type(RENDER_DEPTH))
- buf_name = name+"/depth";
+ tex_name = name+"/depth";
else
- buf_name = Msp::format("%s/color%d", name, type);
+ tex_name = Msp::format("%s/color%d", name, type);
- if(samples)
- buffers[i].buffer->set_debug_name(buf_name+".rbuf");
- else
- buffers[i].texture->set_debug_name(buf_name+".tex2d");
+ textures[i]->set_debug_name(tex_name+".tex2d");
}
#else
(void)name;