share contexts on all renderthreads
This commit is contained in:
@@ -192,7 +192,7 @@ void RendererProcessor::Start()
|
||||
threads_.resize(QThread::idealThreadCount());
|
||||
|
||||
for (int i=0;i<threads_.size();i++) {
|
||||
threads_[i] = std::make_shared<RendererThread>(width_, height_, format_, mode_);
|
||||
threads_[i] = std::make_shared<RendererThread>(QOpenGLContext::currentContext(), width_, height_, format_, mode_);
|
||||
threads_[i]->StartThread(QThread::HighPriority);
|
||||
|
||||
// Ensure this connection is "Queued" so that it always runs in this object's threaded rather than any of the
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
RendererThread::RendererThread(const int &width, const int &height, const olive::PixelFormat &format, const olive::RenderMode &mode) :
|
||||
RendererThread::RendererThread(QOpenGLContext *share_ctx, const int &width, const int &height, const olive::PixelFormat &format, const olive::RenderMode &mode) :
|
||||
share_ctx_(share_ctx),
|
||||
cancelled_(false),
|
||||
width_(width),
|
||||
height_(height),
|
||||
@@ -80,6 +81,8 @@ void RendererThread::run()
|
||||
RenderInstance instance(width_, height_, format_, mode_);
|
||||
render_instance_ = &instance;
|
||||
|
||||
instance.SetShareContext(share_ctx_);
|
||||
|
||||
// Allocate and create resources
|
||||
if (instance.Start()) {
|
||||
|
||||
|
||||
@@ -34,7 +34,8 @@ class RendererThread : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RendererThread(const int& width,
|
||||
RendererThread(QOpenGLContext* share_ctx,
|
||||
const int& width,
|
||||
const int& height,
|
||||
const olive::PixelFormat& format,
|
||||
const olive::RenderMode& mode);
|
||||
@@ -53,6 +54,8 @@ signals:
|
||||
void FinishedPath();
|
||||
|
||||
private:
|
||||
QOpenGLContext* share_ctx_;
|
||||
|
||||
QWaitCondition wait_cond_;
|
||||
|
||||
QMutex mutex_;
|
||||
|
||||
@@ -26,6 +26,7 @@ RenderInstance::RenderInstance(const int& width,
|
||||
const int& height,
|
||||
const olive::PixelFormat& format,
|
||||
const olive::RenderMode& mode) :
|
||||
share_ctx_(nullptr),
|
||||
width_(width),
|
||||
height_(height),
|
||||
format_(format),
|
||||
@@ -33,8 +34,20 @@ RenderInstance::RenderInstance(const int& width,
|
||||
{
|
||||
}
|
||||
|
||||
void RenderInstance::SetShareContext(QOpenGLContext *share)
|
||||
{
|
||||
Q_ASSERT(!IsStarted());
|
||||
|
||||
share_ctx_ = share;
|
||||
}
|
||||
|
||||
bool RenderInstance::Start()
|
||||
{
|
||||
// If we're sharing resources, set this up now
|
||||
if (share_ctx_ != nullptr) {
|
||||
ctx_.setShareContext(share_ctx_);
|
||||
}
|
||||
|
||||
// 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));
|
||||
|
||||
@@ -43,6 +43,8 @@ public:
|
||||
const olive::PixelFormat& format,
|
||||
const olive::RenderMode& mode);
|
||||
|
||||
void SetShareContext(QOpenGLContext* share);
|
||||
|
||||
bool Start();
|
||||
|
||||
void Stop();
|
||||
@@ -54,6 +56,8 @@ public:
|
||||
private:
|
||||
QOpenGLContext ctx_;
|
||||
|
||||
QOpenGLContext* share_ctx_;
|
||||
|
||||
QOffscreenSurface surface_;
|
||||
|
||||
RenderFramebuffer buffer_;
|
||||
|
||||
Reference in New Issue
Block a user