began draft of internal node rendering structure

This commit is contained in:
itsmattkc
2019-07-10 23:06:09 -04:00
parent f38e6b876d
commit d76691a9ef
38 changed files with 1617 additions and 14 deletions
+24
View File
@@ -0,0 +1,24 @@
# Olive - Non-Linear Video Editor
# Copyright (C) 2019 Olive Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set(OLIVE_SOURCES
${OLIVE_SOURCES}
render/renderer/renderer.h
render/renderer/renderer.cpp
render/renderer/rendererthread.h
render/renderer/rendererthread.cpp
PARENT_SCOPE
)
+70
View File
@@ -0,0 +1,70 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "renderer.h"
Renderer::Renderer() :
started_(false)
{
}
void Renderer::Start()
{
if (started_) {
return;
}
threads_.resize(QThread::idealThreadCount());
for (int i=0;i<threads_.size();i++) {
threads_[i] = new RendererThread();
threads_[i]->run();
}
started_ = true;
}
void Renderer::Stop()
{
if (!started_) {
return;
}
started_ = false;
for (int i=0;i<threads_.size();i++) {
threads_[i]->Cancel();
delete threads_[i];
}
threads_.clear();
}
/*RendererThread *Renderer::CurrentThread()
{
for (int i=0;i<threads_.size();i++) {
if (threads_.at(i) == QThread::currentThread()) {
return threads_.at(i);
}
}
return nullptr;
}*/
+43
View File
@@ -0,0 +1,43 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef RENDERER_H
#define RENDERER_H
#include "render/renderer/rendererthread.h"
class Renderer
{
public:
Renderer();
void Start();
void Stop();
//RendererThread* CurrentThread();
private:
QVector<RendererThread*> threads_;
bool started_;
};
#endif // RENDERER_H
+106
View File
@@ -0,0 +1,106 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "rendererthread.h"
#include <QDebug>
RendererThread::RendererThread() :
cancelled_(false)
{
}
bool RendererThread::Queue(Node *n, const rational& time)
{
// If the thread is inactive, tryLock() will succeed
if (mutex_.tryLock()) {
// The mutex is locked in the calling thread now, so we can change the active Node
node_ = n;
time_ = time;
// We can now wake up our main thread
wait_cond_.wakeAll();
mutex_.unlock();
// Wait for thread to start before returning
caller_mutex_.lock();
caller_mutex_.unlock();
return true;
}
return false;
}
void RendererThread::Cancel()
{
// Escape main loop
cancelled_ = true;
// Wait until thread is finished before returning
wait();
}
void RendererThread::run()
{
// Create OpenGL context (automatically destroys any existing if there is one)
if (!ctx_.create()) {
qWarning() << tr("Failed to create OpenGL context in thread %1").arg(reinterpret_cast<quintptr>(this));
return;
}
// Create offscreen surface
surface_.create();
// Make context current on that surface
if (!ctx_.makeCurrent(&surface_)) {
qWarning() << tr("Failed to makeCurrent() on offscreen surface in thread %1").arg(reinterpret_cast<quintptr>(this));
surface_.destroy();
return;
}
// Lock mutex for main loop
mutex_.lock();
// Main loop (use Cancel() to exit it)
while (!cancelled_) {
// Lock the caller mutex (used in Queue() for thread synchronization)
caller_mutex_.lock();
// Main waiting condition
wait_cond_.wait(&mutex_);
// Unlock the caller mutex
caller_mutex_.unlock();
// Process the Node
node_->Process(time_);
}
// Release OpenGL context
ctx_.doneCurrent();
// Destroy offscreen surface
surface_.destroy();
// Unlock mutex before exiting
mutex_.unlock();
}
+68
View File
@@ -0,0 +1,68 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef RENDERTHREAD_H
#define RENDERTHREAD_H
#include <QMutex>
#include <QOffscreenSurface>
#include <QOpenGLContext>
#include <QThread>
#include <QWaitCondition>
#include "node/node.h"
#include "render/texturebuffer.h"
class RendererThread : public QThread
{
public:
RendererThread();
QOpenGLContext* context();
TextureBuffer* buffer();
bool Queue(Node* n, const rational &time);
void Cancel();
virtual void run() override;
private:
QOpenGLContext ctx_;
QOffscreenSurface surface_;
TextureBuffer buffer_;
QWaitCondition wait_cond_;
QMutex mutex_;
QMutex caller_mutex_;
Node* node_;
rational time_;
bool cancelled_;
};
#endif // RENDERTHREAD_H