merged effects into node structure

This commit is contained in:
itsmattkc
2019-04-12 21:50:52 +10:00
parent 4e4d2b1881
commit b21745f694
127 changed files with 1674 additions and 867 deletions
+6 -6
View File
@@ -62,7 +62,7 @@ void apply_audio_effects(Clip* clip, double timecode_start, AVFrame* frame, int
timecode_end = timecode_start + samples_to_seconds(nb_samples, frame->channels, frame->sample_rate);
for (int j=0;j<clip->effects.size();j++) {
Effect* e = clip->effects.at(j).get();
Node* e = clip->effects.at(j).get();
if (e->IsEnabled()) {
e->process_audio(timecode_start, timecode_end, reinterpret_cast<float**>(frame->data), nb_samples, nb_channels, kTransitionNone);
}
@@ -805,7 +805,7 @@ void Cacher::CacheVideoWorker() {
void Cacher::Reset() {
// if we seek to a whole other place in the timeline, we'll need to reset the cache with new values
if (clip->media() == nullptr) {
if (clip->type() == Track::kTypeAudio) {
if (clip->type() == olive::kTypeAudio) {
// a null-media audio clip is usually an auto-generated sound clip such as Tone or Noise
reached_end = false;
audio_target_frame = playhead_;
@@ -871,7 +871,7 @@ Cacher::Cacher(Clip* c) :
void Cacher::OpenWorker() {
// set some defaults for the audio cacher
if (clip->type() == Track::kTypeAudio) {
if (clip->type() == olive::kTypeAudio) {
audio_reset_ = false;
frame_sample_index_ = -1;
audio_buffer_write = 0;
@@ -879,7 +879,7 @@ void Cacher::OpenWorker() {
reached_end = false;
if (clip->media() == nullptr) {
if (clip->type() == Track::kTypeAudio) {
if (clip->type() == olive::kTypeAudio) {
frame_ = av_frame_alloc();
frame_->format = kDestSampleFmt;
frame_->channel_layout = clip->track()->sequence()->audio_layout;
@@ -1127,7 +1127,7 @@ void Cacher::OpenWorker() {
}
void Cacher::CacheWorker() {
if (clip->type() == Track::kTypeVideo) {
if (clip->type() == olive::kTypeVideo) {
// clip is a video track, start caching video
CacheVideoWorker();
} else {
@@ -1218,7 +1218,7 @@ void Cacher::Open()
caching_ = true;
queued_ = false;
start((clip->type() == Track::kTypeVideo) ? QThread::HighPriority : QThread::TimeCriticalPriority);
start((clip->type() == olive::kTypeVideo) ? QThread::HighPriority : QThread::TimeCriticalPriority);
}
void Cacher::Cache(long playhead, bool scrubbing, QVector<Clip*>& nests, int playback_speed)
+25 -22
View File
@@ -34,7 +34,7 @@ extern "C" {
#include "timeline/clip.h"
#include "timeline/sequence.h"
#include "project/media.h"
#include "effects/effect.h"
#include "nodes/node.h"
#include "project/footage.h"
#include "effects/transition.h"
#include "ui/collapsiblewidget.h"
@@ -110,7 +110,6 @@ void olive::rendering::Blit(QOpenGLShaderProgram* pipeline, bool flipped, QMatri
pipeline->setUniformValue("mvp_matrix", matrix);
pipeline->setUniformValue("texture", 0);
GLuint vertex_location = pipeline->attributeLocation("a_position");
m_vbo.bind();
func->glEnableVertexAttribArray(vertex_location);
@@ -176,7 +175,7 @@ GLuint draw_clip(QOpenGLContext* ctx,
void process_effect(QOpenGLContext* ctx,
QOpenGLShaderProgram* pipeline,
Clip* c,
Effect* e,
Node* e,
double timecode,
GLTextureCoords& coords,
GLuint& composite_texture,
@@ -184,11 +183,11 @@ void process_effect(QOpenGLContext* ctx,
bool& texture_failed,
int data) {
if (e->IsEnabled()) {
if (e->Flags() & Effect::CoordsFlag) {
if (e->Flags() & Node::CoordsFlag) {
e->process_coords(timecode, coords, data);
}
bool can_process_shaders = ((e->Flags() & Effect::ShaderFlag) && olive::runtime_config.shaders_are_enabled);
if (can_process_shaders || (e->Flags() & Effect::SuperimposeFlag)) {
bool can_process_shaders = ((e->Flags() & Node::ShaderFlag) && olive::runtime_config.shaders_are_enabled);
if (can_process_shaders || (e->Flags() & Node::SuperimposeFlag)) {
if (!e->is_open()) {
e->open();
@@ -201,7 +200,7 @@ void process_effect(QOpenGLContext* ctx,
fbo_switcher = !fbo_switcher;
}
}
if (e->Flags() & Effect::SuperimposeFlag) {
if (e->Flags() & Node::SuperimposeFlag) {
GLuint superimpose_texture = e->process_superimpose(ctx, timecode);
if (superimpose_texture == 0) {
@@ -227,7 +226,7 @@ void process_effect(QOpenGLContext* ctx,
}
GLuint olive::rendering::compose_sequence(ComposeSequenceParams &params) {
GLuint final_fbo = params.type == Track::kTypeVideo ? params.main_buffer->buffer() : 0;
GLuint final_fbo = params.type == olive::kTypeVideo ? params.main_buffer->buffer() : 0;
Sequence* s = params.seq;
long playhead = s->playhead;
@@ -240,7 +239,7 @@ GLuint olive::rendering::compose_sequence(ComposeSequenceParams &params) {
playhead = rescale_frame_number(playhead, params.nests.at(i)->track()->sequence()->frame_rate, s->frame_rate);
}
if (params.type == Track::kTypeVideo && !params.nests.last()->fbo.isEmpty()) {
if (params.type == olive::kTypeVideo && !params.nests.last()->fbo.isEmpty()) {
params.nests.last()->fbo.at(0).BindBuffer();
params.ctx->functions()->glClear(GL_COLOR_BUFFER_BIT);
final_fbo = params.nests.last()->fbo.at(0).buffer();
@@ -270,7 +269,7 @@ GLuint olive::rendering::compose_sequence(ComposeSequenceParams &params) {
Footage* m = c->media()->to_footage();
// does the clip have a valid media source?
if (!m->invalid && !(c->type() == Track::kTypeAudio && !is_audio_device_set())) {
if (!m->invalid && !(c->type() == olive::kTypeAudio && !is_audio_device_set())) {
// is the media process and ready?
if (m->ready) {
@@ -287,7 +286,7 @@ GLuint olive::rendering::compose_sequence(ComposeSequenceParams &params) {
clip_is_active = true;
// increment audio track count
if (c->type() == Track::kTypeAudio) audio_track_count++;
if (c->type() == olive::kTypeAudio) audio_track_count++;
} else if (c->IsOpen()) {
@@ -321,7 +320,7 @@ GLuint olive::rendering::compose_sequence(ComposeSequenceParams &params) {
// track sorting is only necessary for video clips
// audio clips are mixed equally, so we skip sorting for those
if (params.type == Track::kTypeVideo) {
if (params.type == olive::kTypeVideo) {
// insertion sort by track
for (int j=0;j<current_clips.size();j++) {
@@ -344,7 +343,7 @@ GLuint olive::rendering::compose_sequence(ComposeSequenceParams &params) {
QMatrix4x4 projection;
if (params.type == Track::kTypeVideo) {
if (params.type == olive::kTypeVideo) {
// set default coordinates based on the sequence, with 0 in the direct center
params.ctx->functions()->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
@@ -370,7 +369,7 @@ GLuint olive::rendering::compose_sequence(ComposeSequenceParams &params) {
if (got_mutex && c->IsOpen()) {
// if clip is a video clip
if (c->type() == Track::kTypeVideo) {
if (c->type() == olive::kTypeVideo) {
// textureID variable contains texture to be drawn on screen at the end
GLuint textureID = 0;
@@ -504,7 +503,6 @@ GLuint olive::rendering::compose_sequence(ComposeSequenceParams &params) {
coords.texture_top_right = QVector2D(1.0f, 0.0f);
coords.texture_bottom_left = QVector2D(0.0f, 1.0f);
coords.texture_bottom_right = QVector2D(1.0f, 1.0f);
coords.blendmode = -1;
coords.opacity = 1.0;
// == EFFECT CODE START ==
@@ -515,7 +513,7 @@ GLuint olive::rendering::compose_sequence(ComposeSequenceParams &params) {
// run through all of the clip's effects
for (int j=0;j<c->effects.size();j++) {
Effect* e = c->effects.at(j).get();
Node* e = c->effects.at(j).get();
process_effect(params.ctx, params.pipeline, c, e, timecode, coords, textureID, fbo_switcher, params.texture_failed, kTransitionNone);
}
@@ -685,9 +683,11 @@ GLuint olive::rendering::compose_sequence(ComposeSequenceParams &params) {
// copy front buffer to back buffer (only if we're using a blending mode)
/*
if (coords.blendmode >= 0) {
draw_clip(params.ctx, params.pipeline, back_buffer_2, comp_texture, true);
}
*/
@@ -700,7 +700,7 @@ GLuint olive::rendering::compose_sequence(ComposeSequenceParams &params) {
params.ctx->functions()->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, final_fbo);
// Check if we're using a blend mode (< 0 means no blend mode)
if (coords.blendmode < 0) {
//if (coords.blendmode < 0) {
params.ctx->functions()->glBindTexture(GL_TEXTURE_2D, backend_tex_1);
@@ -708,7 +708,9 @@ GLuint olive::rendering::compose_sequence(ComposeSequenceParams &params) {
params.ctx->functions()->glBindTexture(GL_TEXTURE_2D, 0);
} else {
//} else {
/*
// load background texture into texture unit 0
params.ctx->functions()->glActiveTexture(GL_TEXTURE0 + 0); // Texture unit 0
@@ -739,7 +741,9 @@ GLuint olive::rendering::compose_sequence(ComposeSequenceParams &params) {
params.ctx->functions()->glActiveTexture(GL_TEXTURE0 + 0); // Texture unit 0
params.ctx->functions()->glBindTexture(GL_TEXTURE_2D, 0);
}
*/
//}
// unbind framebuffer
params.ctx->functions()->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
@@ -750,7 +754,7 @@ GLuint olive::rendering::compose_sequence(ComposeSequenceParams &params) {
// == END FINAL DRAW ON SEQUENCE BUFFER ==
}
}
} else if (c->type() == Track::kTypeAudio) {
} else if (c->type() == olive::kTypeAudio) {
if (c->media() != nullptr && c->media()->get_type() == MEDIA_TYPE_SEQUENCE) {
params.nests.append(c);
compose_sequence(params);
@@ -795,11 +799,10 @@ void olive::rendering::compose_audio(Viewer* viewer, Sequence* seq, int playback
params.viewer = viewer;
params.ctx = nullptr;
params.seq = seq;
params.type = Track::kTypeAudio;
params.type = olive::kTypeAudio;
params.gizmos = nullptr;
params.wait_for_mutexes = wait_for_mutexes;
params.playback_speed = playback_speed;
params.blend_mode_program = nullptr;
compose_sequence(params);
}
+4 -17
View File
@@ -28,7 +28,7 @@
namespace OCIO = OCIO_NAMESPACE::v1;
#include "timeline/sequence.h"
#include "effects/effect.h"
#include "nodes/node.h"
#include "panels/viewer.h"
/**
@@ -80,16 +80,16 @@ struct ComposeSequenceParams {
/**
* @brief Set compose mode to video or audio
*
* Accepts Track::kTypeVideo to render video, Track::kTypeAudio if this function should render audio.
* Accepts olive::kTypeVideo to render video, olive::kTypeAudio if this function should render audio.
*/
Track::Type type;
olive::TrackType type;
/**
* @brief Set to the Effect whose gizmos were chosen to be drawn on screen
*
* The currently active Effect that compose_sequence() will update the gizmos of.
*/
Effect* gizmos;
Node* gizmos;
/**
* @brief A variable that compose_sequence() will set to **TRUE** if any of the clips couldn't be shown.
@@ -138,19 +138,6 @@ struct ComposeSequenceParams {
*/
int playback_speed;
/**
* @brief Blending mode shader
*
* Used only for video rendering. Never accessed with audio rendering.
*
* A program containing the current active
* blending mode shader that can be bound during rendering. Must be compiled and linked beforehand. See
* RenderThread::blend_mode_program for how this is properly set up.
*
* \see ComposeSequenceParams::video
*/
QOpenGLShaderProgram* blend_mode_program;
/**
* @brief Premultiply alpha shader
*
+5 -14
View File
@@ -40,7 +40,6 @@ RenderThread::RenderThread() :
gizmos(nullptr),
share_ctx(nullptr),
ctx(nullptr),
blend_mode_program(nullptr),
seq(nullptr),
tex_width(-1),
tex_height(-1),
@@ -50,7 +49,8 @@ RenderThread::RenderThread() :
ocio_shader(nullptr),
running(true),
ocio_config_date(0),
front_buffer_switcher(false)
front_buffer_switcher(false),
pipeline_program(nullptr)
{
surface.create();
}
@@ -101,17 +101,10 @@ void RenderThread::run() {
back_buffer_2.Create(ctx, seq->width, seq->height);
}
// If there's no blending mode shader, create it now
if (blend_mode_program == nullptr) {
// If there's no pipeline shader, create it now
if (pipeline_program == nullptr) {
delete_shaders();
blend_mode_program = std::make_shared<QOpenGLShaderProgram>();
blend_mode_program->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/internalshaders/common.vert");
olive::effects_loaded.lock();
blend_mode_program->addShaderFromSourceCode(QOpenGLShader::Fragment, olive::generated_blending_shader);
olive::effects_loaded.unlock();
blend_mode_program->link();
pipeline_program = olive::shader::GetPipeline();
}
@@ -206,11 +199,10 @@ void RenderThread::paint() {
params.viewer = nullptr;
params.ctx = ctx;
params.seq = seq;
params.type = Track::kTypeVideo;
params.type = olive::kTypeVideo;
params.texture_failed = false;
params.wait_for_mutexes = true;
params.playback_speed = playback_speed_;
params.blend_mode_program = blend_mode_program.get();
params.pipeline = pipeline_program.get();
params.backend_buffer1 = &back_buffer_1;
params.backend_buffer2 = &back_buffer_2;
@@ -380,7 +372,6 @@ void RenderThread::delete_buffers() {
}
void RenderThread::delete_shaders() {
blend_mode_program = nullptr;
pipeline_program = nullptr;
}
+2 -3
View File
@@ -30,7 +30,7 @@
#include <QOpenGLShaderProgram>
#include "timeline/sequence.h"
#include "effects/effect.h"
#include "nodes/node.h"
#include "rendering/framebufferobject.h"
#include "qopenglshaderprogramptr.h"
@@ -44,7 +44,7 @@ public:
QMutex* get_texture_mutex();
const GLuint& get_texture();
Effect* gizmos;
Node* gizmos;
void paint();
void start_render(QOpenGLContext* share,
Sequence *s,
@@ -94,7 +94,6 @@ private:
QOffscreenSurface surface;
QOpenGLContext* share_ctx;
QOpenGLContext* ctx;
QOpenGLShaderProgramPtr blend_mode_program;
QOpenGLShaderProgramPtr pipeline_program;
FramebufferObject back_buffer_1;