X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fframebuffer.cpp;h=45eaff656b65322a5d137133061e9e2ce35924ac;hb=3efe3bab1c8290bd49a957ebec0ad97e58a35fcf;hp=167b403aec18e142548c9f02f775e453e71e6cb0;hpb=160e9eea29bd10034733d59507fa1bcca36be401;p=libs%2Fgl.git diff --git a/source/core/framebuffer.cpp b/source/core/framebuffer.cpp index 167b403a..45eaff65 100644 --- a/source/core/framebuffer.cpp +++ b/source/core/framebuffer.cpp @@ -16,46 +16,28 @@ framebuffer_incomplete::framebuffer_incomplete(const std::string &reason): Framebuffer::Framebuffer(bool s): - FramebufferBackend(s), - dirty(0) -{ - if(s) - { - format = get_system_format(); - get_system_size(width, height); - } -} + FramebufferBackend(s) +{ } Framebuffer::Framebuffer(): FramebufferBackend(false) -{ - init(); -} +{ } Framebuffer::Framebuffer(FrameAttachment fa): - FramebufferBackend(false) + Framebuffer() { - init(); set_format(fa); } Framebuffer::Framebuffer(const FrameFormat &f): - FramebufferBackend(false) + Framebuffer() { - init(); set_format(f); } -void Framebuffer::init() -{ - width = 0; - height = 0; - dirty = 0; -} - void Framebuffer::set_format(const FrameFormat &fmt) { - if(!format.empty() || !id) + if(!format.empty()) throw invalid_operation("Framebuffer::set_format"); if(fmt.empty() || !is_format_supported(fmt)) throw invalid_argument("Framebuffer::set_format"); @@ -78,6 +60,7 @@ void Framebuffer::check_size() { unsigned w = 0; unsigned h = 0; + unsigned l = 1; if(const Texture2D *tex2d = dynamic_cast(a.tex)) { w = max(tex2d->get_width()>>a.level, 1U); @@ -92,30 +75,34 @@ void Framebuffer::check_size() { w = max(tex3d->get_width()>>a.level, 1U); h = max(tex3d->get_height()>>a.level, 1U); + l = (a.layer<0 ? tex3d->get_depth() : 1); } else if(const TextureCube *tex_cube = dynamic_cast(a.tex)) { w = max(tex_cube->get_size()>>a.level, 1U); h = w; + l = (a.layer<0 ? 6 : 1); } if(first) { width = w; height = h; + layers = l; first = false; } else { width = min(width, w); height = min(height, h); + layers = min(layers, l); } } } void Framebuffer::set_attachment(FrameAttachment attch, Texture &tex, unsigned level, int layer, unsigned samples) { - if(format.empty() || !id) + if(format.empty() || attachments.empty()) throw invalid_operation("Framebuffer::attach"); if((format.get_samples()>1 && samples!=format.get_samples()) || (format.get_samples()==1 && samples)) @@ -171,7 +158,7 @@ void Framebuffer::attach_layered(FrameAttachment attch, TextureCube &tex, unsign void Framebuffer::detach(FrameAttachment attch) { - if(!id) + if(attachments.empty()) throw invalid_operation("Framebuffer::detach"); int i = format.index(attch); @@ -183,20 +170,22 @@ void Framebuffer::detach(FrameAttachment attch) } } -void Framebuffer::resize(const WindowView &view) +const Texture *Framebuffer::get_attachment(FrameAttachment attch) const { - if(id) - throw invalid_operation("Framebuffer::resize"); + if(attachments.empty()) + return 0; - width = view.get_width(); - height = view.get_height(); + int i = format.index(attch); + return (i>=0 ? attachments[i].tex : 0); } -void Framebuffer::require_complete() const +const Texture *Framebuffer::get_attachment(unsigned i) const { - if(!id) - return; + return (i