mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-10 20:47:22 +02:00
still broken, but added initial cut of GLsync stuff
This commit is contained in:
parent
b4c75c3f87
commit
06b59fe13e
5 changed files with 43 additions and 9 deletions
|
@ -10,11 +10,15 @@
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "ResourceImageItem.h"
|
#include "ResourceImageItem.h"
|
||||||
|
|
||||||
#include <QOpenGLFramebufferObjectFormat>
|
#include <QOpenGLFramebufferObjectFormat>
|
||||||
|
#include <QOpenGLFunctions>
|
||||||
|
#include <QOpenGLExtraFunctions>
|
||||||
|
#include <QOpenGLContext>
|
||||||
|
|
||||||
#include <DependencyManager.h>
|
#include <DependencyManager.h>
|
||||||
#include <TextureCache.h>
|
#include <TextureCache.h>
|
||||||
|
|
||||||
|
|
||||||
ResourceImageItem::ResourceImageItem(QQuickItem* parent) : QQuickFramebufferObject(parent) {
|
ResourceImageItem::ResourceImageItem(QQuickItem* parent) : QQuickFramebufferObject(parent) {
|
||||||
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(update()));
|
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(update()));
|
||||||
}
|
}
|
||||||
|
@ -55,26 +59,49 @@ void ResourceImageItemRenderer::synchronize(QQuickFramebufferObject* item) {
|
||||||
}
|
}
|
||||||
|
|
||||||
_window = resourceImageItem->window();
|
_window = resourceImageItem->window();
|
||||||
|
_window->setClearBeforeRendering(true);
|
||||||
if (_ready && !_url.isNull() && !_url.isEmpty() && (urlChanged || readyChanged || !_networkTexture)) {
|
if (_ready && !_url.isNull() && !_url.isEmpty() && (urlChanged || readyChanged || !_networkTexture)) {
|
||||||
_networkTexture = DependencyManager::get<TextureCache>()->getTexture(_url);
|
_networkTexture = DependencyManager::get<TextureCache>()->getTexture(_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_ready && _networkTexture && _networkTexture->isLoaded()) {
|
if (_ready && _networkTexture && _networkTexture->isLoaded()) {
|
||||||
if(_fboMutex.tryLock()) {
|
if(_fboMutex.tryLock()) {
|
||||||
qApp->getActiveDisplayPlugin()->copyTextureToQuickFramebuffer(_networkTexture, framebufferObject());
|
qApp->getActiveDisplayPlugin()->copyTextureToQuickFramebuffer(_networkTexture, _copyFbo, &_fenceSync);
|
||||||
_fboMutex.unlock();
|
_fboMutex.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
glFlush();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QOpenGLFramebufferObject* ResourceImageItemRenderer::createFramebufferObject(const QSize& size) {
|
QOpenGLFramebufferObject* ResourceImageItemRenderer::createFramebufferObject(const QSize& size) {
|
||||||
QOpenGLFramebufferObjectFormat format;
|
QOpenGLFramebufferObjectFormat format;
|
||||||
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
|
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
|
||||||
|
_copyFbo = new QOpenGLFramebufferObject(size, format);
|
||||||
return new QOpenGLFramebufferObject(size, format);
|
return new QOpenGLFramebufferObject(size, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceImageItemRenderer::render() {
|
void ResourceImageItemRenderer::render() {
|
||||||
|
qDebug() << "initial error" << glGetError();
|
||||||
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
QOpenGLFunctions* f = QOpenGLContext::currentContext()->functions();
|
||||||
|
QOpenGLExtraFunctions* extras = QOpenGLContext::currentContext()->extraFunctions();
|
||||||
_fboMutex.lock();
|
_fboMutex.lock();
|
||||||
_window->resetOpenGLState();
|
if (_fenceSync) {
|
||||||
|
extras->glWaitSync(_fenceSync, 0, GL_TIMEOUT_IGNORED);
|
||||||
|
qDebug() << "wait error" << glGetError();
|
||||||
|
qDebug() << "waited on fence";
|
||||||
|
}
|
||||||
|
if (_ready) {
|
||||||
|
QOpenGLFramebufferObject::blitFramebuffer(framebufferObject(), _copyFbo, GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT, GL_NEAREST);
|
||||||
|
/*f->glBindTexture(GL_TEXTURE_2D, _copyFbo->texture());
|
||||||
|
qDebug() << "bind tex error" << f->glGetError() << "texture" << _copyFbo->texture();
|
||||||
|
f->glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, _copyFbo->width(), _copyFbo->height());*/
|
||||||
|
qDebug() << "copy error" << f->glGetError();
|
||||||
|
} else {
|
||||||
|
framebufferObject()->release();
|
||||||
|
}
|
||||||
_fboMutex.unlock();
|
_fboMutex.unlock();
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,9 @@ private:
|
||||||
|
|
||||||
NetworkTexturePointer _networkTexture;
|
NetworkTexturePointer _networkTexture;
|
||||||
QQuickWindow* _window;
|
QQuickWindow* _window;
|
||||||
QOpenGLFramebufferObject* _copyFbo;
|
|
||||||
QMutex _fboMutex;
|
QMutex _fboMutex;
|
||||||
|
QOpenGLFramebufferObject* _copyFbo;
|
||||||
|
GLsync _fenceSync { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
class ResourceImageItem : public QQuickFramebufferObject {
|
class ResourceImageItem : public QQuickFramebufferObject {
|
||||||
|
|
|
@ -823,32 +823,37 @@ void OpenGLDisplayPlugin::updateCompositeFramebuffer() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLDisplayPlugin::copyTextureToQuickFramebuffer(NetworkTexturePointer networkTexture, QOpenGLFramebufferObject* target) {
|
void OpenGLDisplayPlugin::copyTextureToQuickFramebuffer(NetworkTexturePointer networkTexture, QOpenGLFramebufferObject* target, GLsync* fenceSync) {
|
||||||
auto glBackend = const_cast<OpenGLDisplayPlugin&>(*this).getGLBackend();
|
auto glBackend = const_cast<OpenGLDisplayPlugin&>(*this).getGLBackend();
|
||||||
withMainThreadContext([&] {
|
withMainThreadContext([&] {
|
||||||
GLuint sourceTexture = glBackend->getTextureID(networkTexture->getGPUTexture());
|
GLuint sourceTexture = glBackend->getTextureID(networkTexture->getGPUTexture());
|
||||||
GLuint targetTexture = target->texture();
|
GLuint targetTexture = target->texture();
|
||||||
GLuint fbo[2] {0, 0};
|
GLuint fbo[2] {0, 0};
|
||||||
|
qDebug() << "initial" << glGetError();
|
||||||
// need mipmaps for blitting texture
|
// need mipmaps for blitting texture
|
||||||
glGenerateTextureMipmap(sourceTexture);
|
glGenerateTextureMipmap(sourceTexture);
|
||||||
|
|
||||||
// create 2 fbos (one for initial texture, second for scaled one)
|
// create 2 fbos (one for initial texture, second for scaled one)
|
||||||
glCreateFramebuffers(2, fbo);
|
glCreateFramebuffers(2, fbo);
|
||||||
|
qDebug() << "error" << glGetError();
|
||||||
|
|
||||||
// setup source fbo
|
// setup source fbo
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo[0]);
|
glBindFramebuffer(GL_FRAMEBUFFER, fbo[0]);
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, sourceTexture, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, sourceTexture, 0);
|
||||||
|
qDebug() << "error" << glGetError();
|
||||||
|
|
||||||
// setup destination fbo
|
// setup destination fbo
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo[1]);
|
glBindFramebuffer(GL_FRAMEBUFFER, fbo[1]);
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, targetTexture, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, targetTexture, 0);
|
||||||
|
qDebug() << "error" << glGetError();
|
||||||
|
|
||||||
glBlitNamedFramebuffer(fbo[0], fbo[1], 0, 0, networkTexture->getWidth(), networkTexture->getHeight(), 0, 0, target->width(), target->height(), GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
glBlitNamedFramebuffer(fbo[0], fbo[1], 0, 0, networkTexture->getWidth(), networkTexture->getHeight(), 0, 0, target->width(), target->height(), GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||||
|
qDebug() << "error" << glGetError();
|
||||||
|
|
||||||
// don't delete the textures!
|
// don't delete the textures!
|
||||||
glDeleteFramebuffers(2, fbo);
|
glDeleteFramebuffers(2, fbo);
|
||||||
glFinish();
|
qDebug() << "error" << glGetError();
|
||||||
|
*fenceSync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ public:
|
||||||
// Three threads, one for rendering, one for texture transfers, one reserved for the GL driver
|
// Three threads, one for rendering, one for texture transfers, one reserved for the GL driver
|
||||||
int getRequiredThreadCount() const override { return 3; }
|
int getRequiredThreadCount() const override { return 3; }
|
||||||
|
|
||||||
void copyTextureToQuickFramebuffer(NetworkTexturePointer source, QOpenGLFramebufferObject* target);
|
void copyTextureToQuickFramebuffer(NetworkTexturePointer source, QOpenGLFramebufferObject* target, GLsync* fenceSync);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class PresentThread;
|
friend class PresentThread;
|
||||||
|
|
|
@ -63,6 +63,7 @@ namespace gpu {
|
||||||
|
|
||||||
class NetworkTexture;
|
class NetworkTexture;
|
||||||
using NetworkTexturePointer = QSharedPointer<NetworkTexture>;
|
using NetworkTexturePointer = QSharedPointer<NetworkTexture>;
|
||||||
|
typedef struct __GLsync *GLsync;
|
||||||
|
|
||||||
// Stereo display functionality
|
// Stereo display functionality
|
||||||
// TODO move out of this file don't derive DisplayPlugin from this. Instead use dynamic casting when
|
// TODO move out of this file don't derive DisplayPlugin from this. Instead use dynamic casting when
|
||||||
|
@ -212,7 +213,7 @@ public:
|
||||||
// Hardware specific stats
|
// Hardware specific stats
|
||||||
virtual QJsonObject getHardwareStats() const { return QJsonObject(); }
|
virtual QJsonObject getHardwareStats() const { return QJsonObject(); }
|
||||||
|
|
||||||
virtual void copyTextureToQuickFramebuffer(NetworkTexturePointer source, QOpenGLFramebufferObject* target) = 0;
|
virtual void copyTextureToQuickFramebuffer(NetworkTexturePointer source, QOpenGLFramebufferObject* target, GLsync* fenceSync) = 0;
|
||||||
|
|
||||||
uint32_t presentCount() const { return _presentedFrameIndex; }
|
uint32_t presentCount() const { return _presentedFrameIndex; }
|
||||||
// Time since last call to incrementPresentCount (only valid if DEBUG_PAINT_DELAY is defined)
|
// Time since last call to incrementPresentCount (only valid if DEBUG_PAINT_DELAY is defined)
|
||||||
|
|
Loading…
Reference in a new issue