fixed various issues with threading

This commit is contained in:
itsmattkc
2019-01-15 22:01:51 +11:00
parent 13d30ab06a
commit e1ec2f6fbe
16 changed files with 339 additions and 115 deletions
+24 -5
View File
@@ -7,12 +7,16 @@
#include "ui/renderfunctions.h"
#include "playback/playback.h"
#include "project/sequence.h"
RenderThread::RenderThread() :
share_ctx(nullptr),
ctx(nullptr),
frameBuffer(0),
texColorBuffer(0)
texColorBuffer(0),
tex_width(-1),
tex_height(-1),
queued(false)
{
surface.create();
}
@@ -27,7 +31,10 @@ void RenderThread::run() {
bool running = true;
while (running) {
waitCond.wait(&mutex);
if (!queued) {
waitCond.wait(&mutex);
}
queued = false;
if (share_ctx != nullptr) {
if (ctx == nullptr) {
@@ -48,12 +55,20 @@ void RenderThread::run() {
ctx->functions()->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer);
// gen texture
if (texColorBuffer == 0) {
if (texColorBuffer == 0 || tex_width != seq->width || tex_height != seq->height) {\
if (texColorBuffer > 0) {
ctx->functions()->glFramebufferTexture2D(
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0
);
glDeleteTextures(1, &texColorBuffer);
}
glGenTextures(1, &texColorBuffer);
glBindTexture(GL_TEXTURE_2D, texColorBuffer);
glTexImage2D(
GL_TEXTURE_2D, 0, GL_RGB, 1920, 1080, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr
GL_TEXTURE_2D, 0, GL_RGB, seq->width, seq->height, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr
);
tex_width = seq->width;
tex_height = seq->height;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
ctx->functions()->glFramebufferTexture2D(
@@ -70,12 +85,15 @@ void RenderThread::run() {
// release
ctx->functions()->glBindFramebuffer(GL_FRAMEBUFFER, 0);
emit ready();
}
}
}
if (ctx != nullptr) {
if (frameBuffer != 0) ctx->functions()->glDeleteFramebuffers(1, &frameBuffer);
if (texColorBuffer > 0) glDeleteTextures(1, &texColorBuffer);
if (frameBuffer > 0) ctx->functions()->glDeleteFramebuffers(1, &frameBuffer);
ctx->doneCurrent();
delete ctx;
}
@@ -110,5 +128,6 @@ void RenderThread::paint() {
void RenderThread::start_render(QOpenGLContext *share, Sequence *s, int idivider) {
share_ctx = share;
seq = s;
queued = true;
waitCond.wakeAll();
}