]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/rendertarget.cpp
Remove RenderBuffer and always use textures as framebuffer attachments
[libs/gl.git] / source / render / rendertarget.cpp
index f2f12d50c441fc70cf2439a025057dac13ff4b05..426b2d5257d0ccebb770242f989ef75c45f38283 100644 (file)
@@ -1,8 +1,9 @@
 #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;
 
@@ -137,42 +138,37 @@ void RenderTarget::init(unsigned w, unsigned h, unsigned s, const RenderTargetFo
 
                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
@@ -193,16 +189,13 @@ void RenderTarget::set_debug_name(const string &name)
        {
                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;