Merge pull request #10882 from davidkelly/dk/spectatorCameraPreview

render issue fixes
This commit is contained in:
David Kelly 2017-07-05 14:46:16 -07:00 committed by GitHub
commit 8c0697f26b
2 changed files with 21 additions and 15 deletions

View file

@ -32,13 +32,17 @@ void ResourceImageItem::setReady(bool ready) {
}
void ResourceImageItemRenderer::onUpdateTimer() {
if (_ready && _networkTexture && _networkTexture->isLoaded()) {
if(_fboMutex.tryLock()) {
invalidateFramebufferObject();
qApp->getActiveDisplayPlugin()->copyTextureToQuickFramebuffer(_networkTexture, _copyFbo, &_fenceSync);
_fboMutex.unlock();
if (_ready) {
if (_networkTexture && _networkTexture->isLoaded()) {
if(_fboMutex.tryLock()) {
invalidateFramebufferObject();
qApp->getActiveDisplayPlugin()->copyTextureToQuickFramebuffer(_networkTexture, _copyFbo, &_fenceSync);
_fboMutex.unlock();
} else {
qDebug() << "couldn't get a lock, using last frame";
}
} else {
qDebug() << "couldn't get a lock, using last frame";
_networkTexture = DependencyManager::get<TextureCache>()->getTexture(_url);
}
}
update();
@ -76,6 +80,9 @@ void ResourceImageItemRenderer::synchronize(QQuickFramebufferObject* item) {
}
QOpenGLFramebufferObject* ResourceImageItemRenderer::createFramebufferObject(const QSize& size) {
if (_copyFbo) {
delete _copyFbo;
}
QOpenGLFramebufferObjectFormat format;
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
_copyFbo = new QOpenGLFramebufferObject(size, format);
@ -85,26 +92,25 @@ QOpenGLFramebufferObject* ResourceImageItemRenderer::createFramebufferObject(con
void ResourceImageItemRenderer::render() {
auto f = QOpenGLContext::currentContext()->extraFunctions();
bool doUpdate = false;
// black background
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
if (_fenceSync) {
f->glWaitSync(_fenceSync, 0, GL_TIMEOUT_IGNORED);
f->glDeleteSync(_fenceSync);
_fenceSync = 0;
doUpdate = true;
}
if (_ready) {
_fboMutex.lock();
_copyFbo->bind();
QOpenGLFramebufferObject::blitFramebuffer(framebufferObject(), _copyFbo, GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT, GL_NEAREST);
// this clears the copyFbo texture
// so next frame starts fresh - helps
// when aspect ratio changes
_copyFbo->takeTexture();
_copyFbo->bind();
_copyFbo->release();
_fboMutex.unlock();
if (doUpdate) {
update();
}
}
glFlush();
_window->resetOpenGLState();

View file

@ -34,7 +34,7 @@ private:
NetworkTexturePointer _networkTexture;
QQuickWindow* _window;
QMutex _fboMutex;
QOpenGLFramebufferObject* _copyFbo;
QOpenGLFramebufferObject* _copyFbo { nullptr };
GLsync _fenceSync { 0 };
QTimer _updateTimer;
public slots: