Remove RenderBuffer and always use textures as framebuffer attachments
authorMikko Rasa <tdb@tdb.fi>
Sun, 12 Sep 2021 22:01:51 +0000 (01:01 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 13 Sep 2021 16:54:38 +0000 (19:54 +0300)
Originally textures could not have multiple samples, but now they can.
Vulkan only has images which are used for both purposes.

16 files changed:
extensions/arb_texture_multisample.glext [new file with mode: 0644]
extensions/arb_texture_storage_multisample.glext [new file with mode: 0644]
source/builders/sequencebuilder.cpp
source/core/framebuffer.cpp
source/core/framebuffer.h
source/core/renderbuffer.cpp [deleted file]
source/core/renderbuffer.h [deleted file]
source/core/texture2dmultisample.cpp [new file with mode: 0644]
source/core/texture2dmultisample.h [new file with mode: 0644]
source/effects/environmentmap.cpp
source/effects/environmentmap.h
source/effects/sky.cpp
source/render/rendertarget.cpp
source/render/rendertarget.h
source/render/sequence.cpp
source/render/sequence.h

diff --git a/extensions/arb_texture_multisample.glext b/extensions/arb_texture_multisample.glext
new file mode 100644 (file)
index 0000000..15414ae
--- /dev/null
@@ -0,0 +1 @@
+extension ARB_texture_multisample
diff --git a/extensions/arb_texture_storage_multisample.glext b/extensions/arb_texture_storage_multisample.glext
new file mode 100644 (file)
index 0000000..e596e8e
--- /dev/null
@@ -0,0 +1 @@
+extension ARB_texture_storage_multisample
index 12e7bdf3df96ea43c415e3674c5ffdf19d7cf764..337df4769b33aa15d2c7831a46f46356cffc0ce1 100644 (file)
@@ -3,7 +3,6 @@
 #include <msp/strings/format.h>
 #include "deviceinfo.h"
 #include "error.h"
-#include "renderbuffer.h"
 #include "sequence.h"
 #include "sequencebuilder.h"
 #include "sequencetemplate.h"
index 4dbb30929e05dc38ff822c981b51e251613f61bb..93a726868c040d6464382ead82c148d58ed20c08 100644 (file)
@@ -8,8 +8,8 @@
 #include "error.h"
 #include "framebuffer.h"
 #include "misc.h"
-#include "renderbuffer.h"
 #include "texture2d.h"
+#include "texture2dmultisample.h"
 #include "texture3d.h"
 #include "windowview.h"
 
@@ -106,37 +106,31 @@ void Framebuffer::update() const
                const Attachment &attch = attachments[i];
                if(dirty&(1<<i))
                {
-                       if(attch.type==GL_RENDERBUFFER)
-                       {
-                               if(ARB_direct_state_access)
-                                       glNamedFramebufferRenderbuffer(id, attch.attachment, GL_RENDERBUFFER, attch.rbuf->get_id());
-                               else
-                                       glFramebufferRenderbuffer(GL_FRAMEBUFFER, attch.attachment, GL_RENDERBUFFER, attch.rbuf->get_id());
-                       }
-                       else if(attch.type)
+                       if(attch.tex)
                        {
+                               GLenum type = attch.tex->get_target();
                                if(ARB_direct_state_access)
                                {
-                                       if(attch.type==GL_TEXTURE_2D || attch.layer<0)
+                                       if(type==GL_TEXTURE_2D || type==GL_TEXTURE_2D_MULTISAMPLE || attch.layer<0)
                                                glNamedFramebufferTexture(id, attch.attachment, attch.tex->get_id(), attch.level);
                                        else
                                                glNamedFramebufferTextureLayer(id, attch.attachment, attch.tex->get_id(), attch.level, attch.layer);
                                }
-                               else if(attch.type==GL_TEXTURE_2D)
-                                       glFramebufferTexture2D(GL_FRAMEBUFFER, attch.attachment, attch.type, attch.tex->get_id(), attch.level);
+                               else if(type==GL_TEXTURE_2D || type==GL_TEXTURE_2D_MULTISAMPLE)
+                                       glFramebufferTexture2D(GL_FRAMEBUFFER, attch.attachment, type, attch.tex->get_id(), attch.level);
                                else if(attch.layer<0)
                                        glFramebufferTexture(GL_FRAMEBUFFER, attch.attachment, attch.tex->get_id(), attch.level);
-                               else if(attch.type==GL_TEXTURE_2D_ARRAY)
+                               else if(type==GL_TEXTURE_2D_ARRAY)
                                        glFramebufferTextureLayer(GL_FRAMEBUFFER, attch.attachment, attch.tex->get_id(), attch.level, attch.layer);
-                               else if(attch.type==GL_TEXTURE_3D)
-                                       glFramebufferTexture3D(GL_FRAMEBUFFER, attch.attachment, attch.type, attch.tex->get_id(), attch.level, attch.layer);
-                               else if(attch.type==GL_TEXTURE_CUBE_MAP)
+                               else if(type==GL_TEXTURE_3D)
+                                       glFramebufferTexture3D(GL_FRAMEBUFFER, attch.attachment, type, attch.tex->get_id(), attch.level, attch.layer);
+                               else if(type==GL_TEXTURE_CUBE_MAP)
                                        glFramebufferTexture2D(GL_FRAMEBUFFER, attch.attachment, TextureCube::enumerate_faces(attch.layer), attch.tex->get_id(), attch.level);
                        }
                        else if(ARB_direct_state_access)
-                               glNamedFramebufferRenderbuffer(id, attch.attachment, 0, 0);
+                               glNamedFramebufferTexture(id, attch.attachment, 0, 0);
                        else
-                               glFramebufferRenderbuffer(GL_FRAMEBUFFER, attch.attachment, 0, 0);
+                               glFramebufferTexture2D(GL_FRAMEBUFFER, attch.attachment, GL_TEXTURE_2D, 0, 0);
                }
 
                if(attch.attachment>=COLOR_ATTACHMENT0 && attch.attachment<=COLOR_ATTACHMENT3)
@@ -176,26 +170,28 @@ void Framebuffer::update() const
 void Framebuffer::check_size()
 {
        for(vector<Attachment>::iterator i=attachments.begin(); i!=attachments.end(); ++i)
-               if(i->type)
+               if(i->tex)
                {
-                       if(i->type==GL_RENDERBUFFER)
-                       {
-                               width = i->rbuf->get_width();
-                               height = i->rbuf->get_height();
-                       }
-                       else if(i->type==GL_TEXTURE_2D)
+                       GLenum type = i->tex->get_target();
+                       if(type==GL_TEXTURE_2D)
                        {
                                Texture2D *tex = static_cast<Texture2D *>(i->tex);
                                width = max(tex->get_width()>>i->level, 1U);
                                height = max(tex->get_height()>>i->level, 1U);
                        }
-                       else if(i->type==GL_TEXTURE_3D || i->type==GL_TEXTURE_2D_ARRAY)
+                       else if(type==GL_TEXTURE_2D_MULTISAMPLE)
+                       {
+                               Texture2DMultisample *tex = static_cast<Texture2DMultisample *>(i->tex);
+                               width = tex->get_width();
+                               height = tex->get_height();
+                       }
+                       else if(type==GL_TEXTURE_3D || type==GL_TEXTURE_2D_ARRAY)
                        {
                                Texture3D *tex = static_cast<Texture3D *>(i->tex);
                                width = max(tex->get_width()>>i->level, 1U);
                                height = max(tex->get_height()>>i->level, 1U);
                        }
-                       else if(i->type==GL_TEXTURE_CUBE_MAP)
+                       else if(type==GL_TEXTURE_CUBE_MAP)
                        {
                                width = max(static_cast<TextureCube *>(i->tex)->get_size()>>i->level, 1U);
                                height = width;
@@ -213,7 +209,7 @@ unsigned Framebuffer::get_attachment_index(FramebufferAttachment attch)
        return attachments.size()-1;
 }
 
-void Framebuffer::set_texture_attachment(FramebufferAttachment attch, Texture &tex, unsigned level, int layer)
+void Framebuffer::set_attachment(FrameAttachment attch, Texture &tex, unsigned level, int layer)
 {
        if(!id)
                throw invalid_operation("Framebuffer::attach");
@@ -224,47 +220,41 @@ void Framebuffer::set_texture_attachment(FramebufferAttachment attch, Texture &t
        check_size();
 }
 
-void Framebuffer::attach(FramebufferAttachment attch, Renderbuffer &rbuf)
+void Framebuffer::attach(FramebufferAttachment attch, Texture2D &tex, unsigned level)
 {
-       if(!id)
-               throw invalid_operation("Framebuffer::attach");
-
-       unsigned i = get_attachment_index(attch);
-       attachments[i].set(rbuf);
-       dirty |= 1<<i;
-       check_size();
+       tex.allocate(level);
+       set_attachment(attch, tex, level, 0);
 }
 
-void Framebuffer::attach(FramebufferAttachment attch, Texture2D &tex, unsigned level)
+void Framebuffer::attach(FramebufferAttachment attch, Texture2DMultisample &tex)
 {
-       tex.allocate(level);
-       set_texture_attachment(attch, tex, level, 0);
+       set_attachment(attch, tex, 0, 0);
 }
 
 void Framebuffer::attach(FramebufferAttachment attch, Texture3D &tex, unsigned layer, unsigned level)
 {
        tex.allocate(level);
-       set_texture_attachment(attch, tex, level, layer);
+       set_attachment(attch, tex, level, layer);
 }
 
 void Framebuffer::attach(FramebufferAttachment attch, TextureCube &tex, TextureCubeFace face, unsigned level)
 {
        tex.allocate(level);
-       set_texture_attachment(attch, tex, level, TextureCube::get_face_index(face));
+       set_attachment(attch, tex, level, TextureCube::get_face_index(face));
 }
 
 void Framebuffer::attach_layered(FramebufferAttachment attch, Texture3D &tex, unsigned level)
 {
        static Require _req(ARB_geometry_shader4);
        tex.allocate(level);
-       set_texture_attachment(attch, tex, level, -1);
+       set_attachment(attch, tex, level, -1);
 }
 
 void Framebuffer::attach_layered(FramebufferAttachment attch, TextureCube &tex, unsigned level)
 {
        static Require _req(ARB_geometry_shader4);
        tex.allocate(level);
-       set_texture_attachment(attch, tex, level, -1);
+       set_attachment(attch, tex, level, -1);
 }
 
 void Framebuffer::detach(FramebufferAttachment attch)
@@ -312,22 +302,13 @@ Framebuffer &Framebuffer::system()
 
 Framebuffer::Attachment::Attachment(FramebufferAttachment a):
        attachment(a),
-       type(0),
+       tex(0),
        level(0),
        layer(0)
 { }
 
-void Framebuffer::Attachment::set(Renderbuffer &r)
-{
-       type = GL_RENDERBUFFER;
-       rbuf = &r;
-       level = 0;
-       layer = 0;
-}
-
 void Framebuffer::Attachment::set(Texture &t, unsigned l, int z)
 {
-       type = t.get_target();
        tex = &t;
        level = l;
        layer = z;
@@ -335,7 +316,7 @@ void Framebuffer::Attachment::set(Texture &t, unsigned l, int z)
 
 void Framebuffer::Attachment::clear()
 {
-       type = 0;
+       tex = 0;
 }
 
 } // namespace GL
index 275f516e8d4d3b22acca3393a48065cb5d5422fb..9fe59bf774b929474869cb2f5ba60b3970ba6804 100644 (file)
@@ -12,9 +12,9 @@
 namespace Msp {
 namespace GL {
 
-class Renderbuffer;
 class Texture;
 class Texture2D;
+class Texture2DMultisample;
 class Texture3D;
 class WindowView;
 
@@ -63,8 +63,8 @@ common application is rendering to a texture, which can then be used for
 fullscreen shader effects.
 
 A framebuffer consist of a number of logical buffers, such as color and depth
-buffers.  Renderbuffers and Textures can be attached to the logical buffers.  At
-least one image must be attached for the framebuffer to be usable.
+buffers.  Textures can be attached to the logical buffers.  At least one image
+must be attached for the framebuffer to be usable.
 
 Requires the GL_EXT_framebuffer_object extension.  The blit functions require
 the GL_EXT_framebuffer_blit extension.
@@ -75,17 +75,11 @@ private:
        struct Attachment
        {
                FramebufferAttachment attachment;
-               GLenum type;
-               union
-               {
-                       Renderbuffer *rbuf;
-                       Texture *tex;
-               };
+               Texture *tex;
                unsigned level;
                int layer;
 
                Attachment(FramebufferAttachment);
-               void set(Renderbuffer &);
                void set(Texture &, unsigned, int);
                void clear();
        };
@@ -109,10 +103,10 @@ private:
        void update() const;
        void check_size();
        unsigned get_attachment_index(FramebufferAttachment);
-       void set_texture_attachment(FramebufferAttachment, Texture &, unsigned, int);
+       void set_attachment(FramebufferAttachment, Texture &, unsigned, int);
 public:
-       void attach(FramebufferAttachment attch, Renderbuffer &rbuf);
        void attach(FramebufferAttachment attch, Texture2D &tex, unsigned level = 0);
+       void attach(FramebufferAttachment attch, Texture2DMultisample &tex);
        void attach(FramebufferAttachment attch, Texture3D &tex, unsigned layer, unsigned level = 0);
        void attach(FramebufferAttachment attch, TextureCube &tex, TextureCubeFace face, unsigned level = 0);
        void attach_layered(FramebufferAttachment attch, Texture3D &tex, unsigned level = 0);
diff --git a/source/core/renderbuffer.cpp b/source/core/renderbuffer.cpp
deleted file mode 100644 (file)
index 844fcd3..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-#include <msp/gl/extensions/arb_direct_state_access.h>
-#include <msp/gl/extensions/ext_framebuffer_multisample.h>
-#include <msp/gl/extensions/ext_framebuffer_object.h>
-#include <msp/gl/extensions/khr_debug.h>
-#include "deviceinfo.h"
-#include "renderbuffer.h"
-
-using namespace std;
-
-namespace Msp {
-namespace GL {
-
-Renderbuffer::Renderbuffer()
-{
-       static Require _req(EXT_framebuffer_object);
-
-       if(ARB_direct_state_access)
-               glCreateRenderbuffers(1, &id);
-       else
-               glGenRenderbuffers(1, &id);
-}
-
-Renderbuffer::~Renderbuffer()
-{
-       glDeleteRenderbuffers(1, &id);
-}
-
-void Renderbuffer::storage(PixelFormat fmt, unsigned wd, unsigned ht)
-{
-       require_pixelformat(fmt);
-       width = wd;
-       height = ht;
-       GLenum gl_fmt = get_gl_pixelformat(fmt);
-       if(ARB_direct_state_access)
-               glNamedRenderbufferStorage(id, gl_fmt, width, height);
-       else
-       {
-               glBindRenderbuffer(GL_RENDERBUFFER, id);
-               glRenderbufferStorage(GL_RENDERBUFFER, gl_fmt, width, height);
-               glBindRenderbuffer(GL_RENDERBUFFER, 0);
-       }
-}
-
-unsigned Renderbuffer::get_max_samples()
-{
-       return Limits::get_global().max_samples;
-}
-
-void Renderbuffer::storage_multisample(unsigned samples, PixelFormat fmt, unsigned wd, unsigned ht)
-{
-       if(!samples)
-               return storage(fmt, wd, ht);
-
-       static Require _req(EXT_framebuffer_multisample);
-       if(samples>Limits::get_global().max_samples)
-               throw out_of_range("Renderbuffer::storage_multisample");
-
-       require_pixelformat(fmt);
-
-       width = wd;
-       height = ht;
-       GLenum gl_fmt = get_gl_pixelformat(fmt);
-       if(ARB_direct_state_access)
-               glNamedRenderbufferStorageMultisample(id, samples, gl_fmt, width, height);
-       else
-       {
-               glBindRenderbuffer(GL_RENDERBUFFER, id);
-               glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, gl_fmt, width, height);
-               glBindRenderbuffer(GL_RENDERBUFFER, 0);
-       }
-}
-
-void Renderbuffer::set_debug_name(const string &name)
-{
-#ifdef DEBUG
-       if(KHR_debug)
-               glObjectLabel(GL_RENDERBUFFER, id, name.size(), name.c_str());
-#else
-       (void)name;
-#endif
-}
-
-} // namespace GL
-} // namespace Msp
diff --git a/source/core/renderbuffer.h b/source/core/renderbuffer.h
deleted file mode 100644 (file)
index 84ed3f2..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-#ifndef MSP_GL_RENDERBUFFER_H_
-#define MSP_GL_RENDERBUFFER_H_
-
-#include "pixelformat.h"
-
-namespace Msp {
-namespace GL {
-
-/**
-A Renderbuffer contains a single renderable image.  It can be attached to a
-Framebuffer to provide a logical buffer that is required to render the scene
-correctly but that is not needed as a texture later.  Renderbuffers also
-provide a capability for multisampling, which is not available in textures.
-
-Requires the GL_EXT_framebuffer_object extension.  Multisample renderbuffers
-additionally require the GL_EXT_framebuffer_multisample extension.
-*/
-class Renderbuffer
-{
-private:
-       unsigned id;
-       unsigned width;
-       unsigned height;
-
-public:
-       Renderbuffer();
-       ~Renderbuffer();
-
-       unsigned get_id() const { return id; }
-       unsigned get_width() const { return width; }
-       unsigned get_height() const { return height; }
-
-       /** Allocates storage for the renderbuffer. */
-       void storage(PixelFormat fmt, unsigned wd, unsigned ht);
-
-       /** Returns the maximum supported sample count for multisampling.  If
-       multisampling is not supported, returns 0. */
-       DEPRECATED static unsigned get_max_samples();
-
-       /** Allocates multisample storage for the renderbuffer.  All attachments in
-       a framebuffer must have the same number of samples.  To transfer the
-       contents to a texture for furter processing, use the framebuffer blit
-       functions.*/
-       void storage_multisample(unsigned samples, PixelFormat fmt, unsigned wd, unsigned ht);
-
-       void set_debug_name(const std::string &);
-};
-
-} // namespace GL
-} // namespace Msp
-
-#endif
diff --git a/source/core/texture2dmultisample.cpp b/source/core/texture2dmultisample.cpp
new file mode 100644 (file)
index 0000000..18e21b7
--- /dev/null
@@ -0,0 +1,73 @@
+#include <msp/gl/extensions/arb_direct_state_access.h>
+#include <msp/gl/extensions/arb_texture_multisample.h>
+#include <msp/gl/extensions/arb_texture_storage_multisample.h>
+#include "deviceinfo.h"
+#include "error.h"
+#include "texture2dmultisample.h"
+
+using namespace std;
+
+namespace Msp {
+namespace GL {
+
+Texture2DMultisample::Texture2DMultisample():
+       Texture(GL_TEXTURE_2D_MULTISAMPLE),
+       width(0),
+       height(0)
+{
+       static Require _req(ARB_texture_multisample);
+}
+
+void Texture2DMultisample::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned sm)
+{
+       if(width>0)
+       {
+               if(fmt!=format || wd!=width || ht!=height || sm!=samples)
+                       throw incompatible_data("Texture2DMultisample::storage");
+               return;
+       }
+       if(wd==0 || ht==0)
+               throw invalid_argument("Texture2DMultisample::storage");
+       if(!sm || sm>Limits::get_global().max_samples)
+               throw invalid_argument("Texture2DMultisample::storage");
+
+       set_format(fmt);
+       width = wd;
+       height = ht;
+       samples = sm;
+
+       bool direct = ARB_texture_storage_multisample && ARB_direct_state_access;
+       if(!direct)
+       {
+               glActiveTexture(GL_TEXTURE0);
+               glBindTexture(target, id);
+       }
+
+       GLenum gl_fmt = get_gl_pixelformat(storage_fmt);
+       if(ARB_texture_storage_multisample)
+       {
+               if(ARB_direct_state_access)
+                       glTextureStorage2DMultisample(id, samples, gl_fmt, width, height, false);
+               else
+                       glTexStorage2DMultisample(target, samples, gl_fmt, width, height, false);
+       }
+       else
+               glTexImage2DMultisample(target, samples, gl_fmt, width, height, false);
+       apply_swizzle();
+
+       if(!direct)
+               glBindTexture(target, 0);
+}
+
+void Texture2DMultisample::image(const Graphics::Image &, unsigned)
+{
+       throw invalid_operation("Texture2DMultisample::image");
+}
+
+UInt64 Texture2DMultisample::get_data_size() const
+{
+       return id ? width*height*get_pixel_size(format)*samples : 0;
+}
+
+} // namespace GL
+} // namespace Msp
diff --git a/source/core/texture2dmultisample.h b/source/core/texture2dmultisample.h
new file mode 100644 (file)
index 0000000..cb086f0
--- /dev/null
@@ -0,0 +1,34 @@
+#ifndef MSP_GL_TEXTURE2DMULTISAMPLE_H_
+#define MSP_GL_TEXTURE2DMULTISAMPLE_H_
+
+#include "texture.h"
+
+namespace Msp {
+namespace GL {
+
+class Texture2DMultisample: public Texture
+{
+private:
+       unsigned width;
+       unsigned height;
+       unsigned samples;
+
+public:
+       Texture2DMultisample();
+
+       void storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned sm);
+
+       virtual void image(const Graphics::Image &, unsigned = 0);
+
+       unsigned get_width() const { return width; }
+       unsigned get_height() const { return height; }
+
+       virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; }
+       virtual UInt64 get_data_size() const;
+       virtual void unload() { }
+};
+
+} // namespace GL
+} // namespace Msp
+
+#endif
index 1cefde1be840649cab8dab4059366299116d5a10..5002e0f88b786ae90440fb7e3e3b9a0aa487562e 100644 (file)
@@ -57,7 +57,7 @@ void EnvironmentMap::init(unsigned s, PixelFormat f, unsigned l)
        update_delay = 0;
 
        env_tex.storage(f, size, l);
-       depth_buf.storage(DEPTH_COMPONENT32F, size, size);
+       depth_buf.storage(DEPTH_COMPONENT32F, size, size, 1);
        for(unsigned i=0; i<6; ++i)
        {
                TextureCubeFace face = TextureCube::enumerate_faces(i);
index 4936d162781aac4087fcfdf26eb318abdac69ec5..e02687b71184c37b3b11c0a30c8f1b75862e3774 100644 (file)
@@ -6,7 +6,7 @@
 #include "framebuffer.h"
 #include "matrix.h"
 #include "programdata.h"
-#include "renderbuffer.h"
+#include "texture2d.h"
 #include "texturecube.h"
 #include "vector.h"
 
@@ -36,7 +36,7 @@ private:
        unsigned size;
        Renderable &environment;
        TextureCube env_tex;
-       Renderbuffer depth_buf;
+       Texture2D depth_buf;
        Face faces[6];
 
        TextureCube irradiance;
index a210efc94f578e35c7593fab4277d3150ac4575e..23819db36c006cb1f8cb8d53f67cb922686810f1 100644 (file)
@@ -4,6 +4,7 @@
 #include "mesh.h"
 #include "renderer.h"
 #include "resources.h"
+#include "texture2d.h"
 #include "sky.h"
 
 using namespace std;
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;
index 030e45775f19898ef1e29914000e7e2ac8d1a660..f13d23d9683a12b2828272125a610570b52c28ca 100644 (file)
@@ -2,11 +2,13 @@
 #define RENDERTARGET_H_
 
 #include "framebuffer.h"
-#include "texture2d.h"
 
 namespace Msp {
 namespace GL {
 
+class Texture;
+class Texture2D;
+
 enum RenderOutput
 {
        RENDER_COLOR = 0|3,
@@ -49,17 +51,11 @@ PixelFormat get_output_pixelformat(unsigned char);
 class RenderTarget
 {
 private:
-       union TargetBuffer
-       {
-               Texture2D *texture;
-               Renderbuffer *buffer;
-       };
-
        unsigned width;
        unsigned height;
        unsigned samples;
        RenderTargetFormat format;
-       std::vector<TargetBuffer> buffers;
+       std::vector<Texture *> textures;
        Framebuffer fbo;
 
 public:
index 472b572fa4adcc1f6806cf6e80a66c677a0cb355..aaa1ef12a2238e209973c708446672b3ba865ed6 100644 (file)
@@ -4,7 +4,6 @@
 #include "framebuffer.h"
 #include "lighting.h"
 #include "postprocessor.h"
-#include "renderbuffer.h"
 #include "renderer.h"
 #include "sequence.h"
 #include "texture2d.h"
index be8ed30621a08403842616c11d09fbab877359d3..8e6c45af491e2265ba4699f3555ffb399646ecc5 100644 (file)
@@ -7,7 +7,6 @@
 #include "depthtest.h"
 #include "framebuffer.h"
 #include "renderable.h"
-#include "renderbuffer.h"
 #include "rendertarget.h"
 #include "stenciltest.h"
 #include "texture2d.h"