diff --git a/rendering/cacher.cpp b/rendering/cacher.cpp index 35fd02f72..740571810 100644 --- a/rendering/cacher.cpp +++ b/rendering/cacher.cpp @@ -28,7 +28,6 @@ #include -#include #include #include #include diff --git a/rendering/exportthread.cpp b/rendering/exportthread.cpp index 06cc9970c..da05b6194 100644 --- a/rendering/exportthread.cpp +++ b/rendering/exportthread.cpp @@ -40,7 +40,6 @@ extern "C" { #include #include -#include #include #include diff --git a/rendering/framebufferobject.cpp b/rendering/framebufferobject.cpp index 10a2cbb96..6ca510443 100644 --- a/rendering/framebufferobject.cpp +++ b/rendering/framebufferobject.cpp @@ -70,12 +70,44 @@ void FramebufferObject::Destroy() ctx_ = nullptr; } -const GLuint &FramebufferObject::buffer() +void FramebufferObject::BindBuffer() const +{ + if (ctx_ == nullptr) { + return; + } + ctx_->functions()->glBindFramebuffer(GL_TEXTURE_2D, buffer_); +} + +void FramebufferObject::ReleaseBuffer() const +{ + if (ctx_ == nullptr) { + return; + } + ctx_->functions()->glBindFramebuffer(GL_TEXTURE_2D, 0); +} + +void FramebufferObject::BindTexture() const +{ + if (ctx_ == nullptr) { + return; + } + ctx_->functions()->glBindTexture(GL_TEXTURE_2D, texture_); +} + +void FramebufferObject::ReleaseTexture() const +{ + if (ctx_ == nullptr) { + return; + } + ctx_->functions()->glBindTexture(GL_TEXTURE_2D, 0); +} + +const GLuint &FramebufferObject::buffer() const { return buffer_; } -const GLuint &FramebufferObject::texture() +const GLuint &FramebufferObject::texture() const { return texture_; } diff --git a/rendering/framebufferobject.h b/rendering/framebufferobject.h index fc5644392..6f2b5764a 100644 --- a/rendering/framebufferobject.h +++ b/rendering/framebufferobject.h @@ -13,8 +13,14 @@ public: void Create(QOpenGLContext* ctx, int width, int height); void Destroy(); - const GLuint& buffer(); - const GLuint& texture(); + const GLuint& buffer() const; + const GLuint& texture() const; + + void BindBuffer() const; + void ReleaseBuffer() const; + + void BindTexture() const; + void ReleaseTexture() const; private: QOpenGLContext* ctx_; GLuint buffer_; diff --git a/rendering/renderfunctions.cpp b/rendering/renderfunctions.cpp index f38817648..55f534e59 100644 --- a/rendering/renderfunctions.cpp +++ b/rendering/renderfunctions.cpp @@ -24,7 +24,6 @@ extern "C" { #include } -#include #include #include #include @@ -86,8 +85,8 @@ void draw_clip(QOpenGLContext* ctx, GLuint fbo, GLuint texture, bool clear) { ctx->functions()->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); } -GLuint draw_clip(QOpenGLFramebufferObject* fbo, GLuint texture, bool clear) { - fbo->bind(); +GLuint draw_clip(const FramebufferObject& fbo, GLuint texture, bool clear) { + fbo.BindBuffer(); if (clear) { glClear(GL_COLOR_BUFFER_BIT); @@ -99,9 +98,9 @@ GLuint draw_clip(QOpenGLFramebufferObject* fbo, GLuint texture, bool clear) { glBindTexture(GL_TEXTURE_2D, 0); - fbo->release(); + fbo.ReleaseBuffer(); - return fbo->texture(); + return fbo.texture(); } void process_effect(Clip* c, @@ -140,7 +139,7 @@ void process_effect(Clip* c, } else { // if the source texture is not already a framebuffer texture, // we'll need to make it one before drawing a superimpose effect on it - if (composite_texture != c->fbo[0]->texture() && composite_texture != c->fbo[1]->texture()) { + if (composite_texture != c->fbo[0].texture() && composite_texture != c->fbo[1].texture()) { draw_clip(c->fbo[!fbo_switcher], composite_texture, true); } @@ -167,10 +166,10 @@ GLuint compose_sequence(ComposeSequenceParams ¶ms) { playhead = rescale_frame_number(playhead, params.nests.at(i)->sequence->frame_rate, s->frame_rate); } - if (params.video && params.nests.last()->fbo != nullptr) { - params.nests.last()->fbo[0]->bind(); + if (params.video && !params.nests.last()->fbo.isEmpty()) { + params.nests.last()->fbo[0].BindBuffer(); glClear(GL_COLOR_BUFFER_BIT); - final_fbo = params.nests.last()->fbo[0]->handle(); + final_fbo = params.nests.last()->fbo[0].buffer(); } } @@ -325,14 +324,14 @@ GLuint compose_sequence(ComposeSequenceParams ¶ms) { } // prepare framebuffers for backend drawing operations - if (c->fbo == nullptr) { + if (c->fbo.isEmpty()) { // create 3 fbos for nested sequences, 2 for most clips int fbo_count = (c->media() != nullptr && c->media()->get_type() == MEDIA_TYPE_SEQUENCE) ? 3 : 2; - c->fbo = new QOpenGLFramebufferObject* [size_t(fbo_count)]; + c->fbo.resize(fbo_count); for (int j=0;jfbo[j] = new QOpenGLFramebufferObject(video_width, video_height); + c->fbo[j].Create(params.ctx, video_width, video_height); } } @@ -473,9 +472,9 @@ GLuint compose_sequence(ComposeSequenceParams ¶ms) { GLuint backend_tex_1; GLuint backend_tex_2; if (params.nests.size() > 0) { - back_buffer_1 = params.nests.last()->fbo[1]->handle(); - backend_tex_1 = params.nests.last()->fbo[1]->texture(); - backend_tex_2 = params.nests.last()->fbo[2]->texture(); + back_buffer_1 = params.nests.last()->fbo[1].buffer(); + backend_tex_1 = params.nests.last()->fbo[1].texture(); + backend_tex_2 = params.nests.last()->fbo[2].texture(); } else { back_buffer_1 = params.backend_buffer1; backend_tex_1 = params.backend_attachment1; @@ -531,7 +530,7 @@ GLuint compose_sequence(ComposeSequenceParams ¶ms) { // copy front buffer to back buffer (only if we're using a blending mode) if (coords.blendmode >= 0) { if (params.nests.size() > 0) { - draw_clip(params.ctx, params.nests.last()->fbo[2]->handle(), params.nests.last()->fbo[0]->texture(), true); + draw_clip(params.ctx, params.nests.last()->fbo[2].buffer(), params.nests.last()->fbo[0].texture(), true); } else { draw_clip(params.ctx, params.backend_buffer2, params.main_attachment, true); } @@ -665,11 +664,9 @@ GLuint compose_sequence(ComposeSequenceParams ¶ms) { glPopMatrix(); } -// qDebug() << "compose sequence took" << QDateTime::currentMSecsSinceEpoch() - time; - - if (!params.nests.isEmpty() && params.nests.last()->fbo != nullptr) { + if (!params.nests.isEmpty() && !params.nests.last()->fbo.isEmpty()) { // returns nested clip's texture - return params.nests.last()->fbo[0]->texture(); + return params.nests.last()->fbo[0].texture(); } return 0; diff --git a/timeline/clip.cpp b/timeline/clip.cpp index 75afae44b..5a6c97408 100644 --- a/timeline/clip.cpp +++ b/timeline/clip.cpp @@ -56,7 +56,6 @@ Clip::Clip(Sequence* s) : closing_transition = nullptr; undeletable = false; replaced = false; - fbo = nullptr; open_ = false; reset(); @@ -515,18 +514,7 @@ void Clip::Close(bool wait) { } // delete framebuffers - if (fbo != nullptr) { - // delete 3 fbos for nested sequences, 2 for most clips - int fbo_count = (media() != nullptr && media()->get_type() == MEDIA_TYPE_SEQUENCE) ? 3 : 2; - - for (int j=0;j fbo; QOpenGLTexture* texture; long texture_frame; diff --git a/ui/viewerwidget.cpp b/ui/viewerwidget.cpp index 581c6a11c..6c0c7238d 100644 --- a/ui/viewerwidget.cpp +++ b/ui/viewerwidget.cpp @@ -28,7 +28,6 @@ extern "C" { #include #include #include -#include #include #include #include