X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fpipeline.cpp;h=de98b2d383283d4822d1ed7e9b684ac60ed98e4b;hp=570014d3692e4ab1405e22761b90511a02379020;hb=f14435e58bfa0fa697a06ba9a454bb30cd37d9d8;hpb=25c81b4953dd38993250321b9407ce8b0139cbeb diff --git a/source/pipeline.cpp b/source/pipeline.cpp index 570014d3..de98b2d3 100644 --- a/source/pipeline.cpp +++ b/source/pipeline.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2009-2011 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include "blend.h" #include "camera.h" #include "effect.h" @@ -28,9 +21,13 @@ Pipeline::Pipeline(unsigned w, unsigned h, bool d): width(w), height(h), hdr(d), + samples(0), fbo(0), color_buf(0), - depth_buf(0) + depth_buf(0), + fbo_ms(0), + color_buf_ms(0), + depth_buf_ms(0) { } Pipeline::~Pipeline() @@ -40,6 +37,20 @@ Pipeline::~Pipeline() delete depth_buf; } +void Pipeline::set_hdr(bool h) +{ + hdr = h; + if(!postproc.empty()) + create_fbos(); +} + +void Pipeline::set_multisample(unsigned s) +{ + samples = s; + if(!postproc.empty()) + create_fbos(); +} + void Pipeline::set_camera(const Camera *c) { camera = c; @@ -115,22 +126,8 @@ void Pipeline::add_postprocessor(PostProcessor &pp) { postproc.push_back(&pp); if(!fbo) + create_fbos(); { - fbo = new Framebuffer; - - color_buf = new Texture2D; - color_buf->set_min_filter(NEAREST); - color_buf->set_mag_filter(NEAREST); - color_buf->set_wrap(CLAMP_TO_EDGE); - color_buf->storage((hdr ? RGB16F : RGB), width, height); - fbo->attach(COLOR_ATTACHMENT0, *color_buf, 0); - - depth_buf = new Texture2D; - depth_buf->set_min_filter(NEAREST); - depth_buf->set_mag_filter(NEAREST); - depth_buf->set_wrap(CLAMP_TO_EDGE); - depth_buf->storage(DEPTH_COMPONENT, width, height); - fbo->attach(DEPTH_ATTACHMENT, *depth_buf, 0); } } @@ -160,8 +157,9 @@ void Pipeline::render_all() const if(fbo) { - fbo->bind(); - fbo->clear(COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT); + Framebuffer *f = (fbo_ms ? fbo_ms : fbo); + f->bind(); + f->clear(COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT); } for(vector::const_iterator i=effects.begin(); i!=effects.end(); ++i) @@ -175,13 +173,60 @@ void Pipeline::render_all() const (*--i)->cleanup(); if(fbo) + { + if(fbo_ms) + fbo->blit_from(*fbo_ms, COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT, false); Framebuffer::unbind(); + } // XXX Need two color buffer textures to handle multiple post-processors correctly for(vector::const_iterator i=postproc.begin(); i!=postproc.end(); ++i) (*i)->render(*color_buf, *depth_buf); } +void Pipeline::create_fbos() +{ + delete fbo; + delete color_buf; + delete depth_buf; + + delete fbo_ms; + fbo_ms = 0; + delete color_buf_ms; + color_buf_ms = 0; + delete depth_buf_ms; + depth_buf_ms = 0; + + fbo = new Framebuffer; + + color_buf = new Texture2D; + color_buf->set_min_filter(NEAREST); + color_buf->set_mag_filter(NEAREST); + color_buf->set_wrap(CLAMP_TO_EDGE); + color_buf->storage((hdr ? RGB16F : RGB), width, height); + fbo->attach(COLOR_ATTACHMENT0, *color_buf, 0); + + depth_buf = new Texture2D; + depth_buf->set_min_filter(NEAREST); + depth_buf->set_mag_filter(NEAREST); + depth_buf->set_wrap(CLAMP_TO_EDGE); + depth_buf->storage(DEPTH_COMPONENT, width, height); + fbo->attach(DEPTH_ATTACHMENT, *depth_buf, 0); + + if(samples) + { + fbo_ms = new Framebuffer; + + color_buf_ms = new Renderbuffer; + color_buf_ms->storage_multisample(samples, (hdr ? RGB16F : RGB), width, height); + fbo_ms->attach(COLOR_ATTACHMENT0, *color_buf_ms); + + depth_buf_ms = new Renderbuffer; + depth_buf_ms->storage_multisample(samples, DEPTH_COMPONENT, width, height); + fbo_ms->attach(DEPTH_ATTACHMENT, *depth_buf_ms); + } +} + Pipeline::Slot::Slot(const Renderable *r): renderable(r)