renderer: re-use the same opengl instance for all background rendering

Previously the OpenGL instance was tied to each render/cache task,
creating and destroying it each time one started and stopped. This was
completely unnecessary since the instance holds no state and can be
shared by all of the render tasks without having to expensively start
a new one.
This commit is contained in:
itsmattkc
2020-06-19 17:06:14 +10:00
parent ab74c1579e
commit b2a3cede2c
7 changed files with 52 additions and 41 deletions
+26
View File
@@ -33,6 +33,8 @@
OLIVE_NAMESPACE_ENTER
OpenGLProxy* OpenGLProxy::instance_ = nullptr;
OpenGLProxy::OpenGLProxy(QObject *parent) :
QObject(parent),
ctx_(nullptr),
@@ -48,6 +50,30 @@ OpenGLProxy::~OpenGLProxy()
surface_.destroy();
}
void OpenGLProxy::CreateInstance()
{
instance_ = new OpenGLProxy();
QThread* proxy_thread = new QThread();
proxy_thread->start(QThread::IdlePriority);
instance_->moveToThread(proxy_thread);
if (!instance_->Init()) {
DestroyInstance();
}
}
void OpenGLProxy::DestroyInstance()
{
if (instance_) {
instance_->thread()->quit();
instance_->thread()->wait();
instance_->thread()->deleteLater();
instance_->deleteLater();
instance_ = nullptr;
}
}
bool OpenGLProxy::Init()
{
// Create context object