mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 20:36:24 +02:00
Allow compile time disabling of QML surface rendering
This commit is contained in:
parent
6d45238bbd
commit
8c528be481
2 changed files with 29 additions and 4 deletions
|
@ -518,6 +518,7 @@ QOpenGLContext* OffscreenQmlSurface::getSharedContext() {
|
||||||
|
|
||||||
void OffscreenQmlSurface::cleanup() {
|
void OffscreenQmlSurface::cleanup() {
|
||||||
_isCleaned = true;
|
_isCleaned = true;
|
||||||
|
#if ENABLE_QML_RENDERING
|
||||||
_canvas->makeCurrent();
|
_canvas->makeCurrent();
|
||||||
|
|
||||||
_renderControl->invalidate();
|
_renderControl->invalidate();
|
||||||
|
@ -535,9 +536,11 @@ void OffscreenQmlSurface::cleanup() {
|
||||||
offscreenTextures.releaseSize(_size);
|
offscreenTextures.releaseSize(_size);
|
||||||
|
|
||||||
_canvas->doneCurrent();
|
_canvas->doneCurrent();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void OffscreenQmlSurface::render() {
|
void OffscreenQmlSurface::render() {
|
||||||
|
#if ENABLE_QML_RENDERING
|
||||||
if (nsightActive()) {
|
if (nsightActive()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -577,6 +580,7 @@ void OffscreenQmlSurface::render() {
|
||||||
_quickWindow->resetOpenGLState();
|
_quickWindow->resetOpenGLState();
|
||||||
_lastRenderTime = usecTimestampNow();
|
_lastRenderTime = usecTimestampNow();
|
||||||
_canvas->doneCurrent();
|
_canvas->doneCurrent();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OffscreenQmlSurface::fetchTexture(TextureAndFence& textureAndFence) {
|
bool OffscreenQmlSurface::fetchTexture(TextureAndFence& textureAndFence) {
|
||||||
|
@ -621,7 +625,9 @@ OffscreenQmlSurface::~OffscreenQmlSurface() {
|
||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
auto engine = _qmlContext->engine();
|
auto engine = _qmlContext->engine();
|
||||||
|
#if ENABLE_QML_RENDERING
|
||||||
_canvas->deleteLater();
|
_canvas->deleteLater();
|
||||||
|
#endif
|
||||||
_rootItem->deleteLater();
|
_rootItem->deleteLater();
|
||||||
_quickWindow->deleteLater();
|
_quickWindow->deleteLater();
|
||||||
releaseEngine(engine);
|
releaseEngine(engine);
|
||||||
|
@ -646,6 +652,7 @@ void OffscreenQmlSurface::disconnectAudioOutputTimer() {
|
||||||
void OffscreenQmlSurface::create() {
|
void OffscreenQmlSurface::create() {
|
||||||
qCDebug(uiLogging) << "Building QML surface";
|
qCDebug(uiLogging) << "Building QML surface";
|
||||||
|
|
||||||
|
#if ENABLE_QML_RENDERING
|
||||||
_renderControl = new QMyQuickRenderControl();
|
_renderControl = new QMyQuickRenderControl();
|
||||||
connect(_renderControl, &QQuickRenderControl::renderRequested, this, [this] { _render = true; });
|
connect(_renderControl, &QQuickRenderControl::renderRequested, this, [this] { _render = true; });
|
||||||
connect(_renderControl, &QQuickRenderControl::sceneChanged, this, [this] { _render = _polish = true; });
|
connect(_renderControl, &QQuickRenderControl::sceneChanged, this, [this] { _render = _polish = true; });
|
||||||
|
@ -662,20 +669,24 @@ void OffscreenQmlSurface::create() {
|
||||||
_quickWindow->setClearBeforeRendering(false);
|
_quickWindow->setClearBeforeRendering(false);
|
||||||
|
|
||||||
_renderControl->_renderWindow = _proxyWindow;
|
_renderControl->_renderWindow = _proxyWindow;
|
||||||
|
|
||||||
_canvas = new OffscreenGLCanvas();
|
_canvas = new OffscreenGLCanvas();
|
||||||
if (!_canvas->create(getSharedContext())) {
|
if (!_canvas->create(getSharedContext())) {
|
||||||
qFatal("Failed to create OffscreenGLCanvas");
|
qFatal("Failed to create OffscreenGLCanvas");
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
connect(_quickWindow, &QQuickWindow::focusObjectChanged, this, &OffscreenQmlSurface::onFocusObjectChanged);
|
|
||||||
|
|
||||||
// acquireEngine interrogates the GL context, so we need to have the context current here
|
// acquireEngine interrogates the GL context, so we need to have the context current here
|
||||||
if (!_canvas->makeCurrent()) {
|
if (!_canvas->makeCurrent()) {
|
||||||
qFatal("Failed to make context current for QML Renderer");
|
qFatal("Failed to make context current for QML Renderer");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
_quickWindow = new QQuickWindow();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
connect(_quickWindow, &QQuickWindow::focusObjectChanged, this, &OffscreenQmlSurface::onFocusObjectChanged);
|
||||||
|
|
||||||
|
|
||||||
// Create a QML engine.
|
// Create a QML engine.
|
||||||
auto qmlEngine = acquireEngine(_quickWindow);
|
auto qmlEngine = acquireEngine(_quickWindow);
|
||||||
|
@ -690,7 +701,10 @@ void OffscreenQmlSurface::create() {
|
||||||
// FIXME Compatibility mechanism for existing HTML and JS that uses eventBridgeWrapper
|
// FIXME Compatibility mechanism for existing HTML and JS that uses eventBridgeWrapper
|
||||||
// Find a way to flag older scripts using this mechanism and wanr that this is deprecated
|
// Find a way to flag older scripts using this mechanism and wanr that this is deprecated
|
||||||
_qmlContext->setContextProperty("eventBridgeWrapper", new EventBridgeWrapper(this, _qmlContext));
|
_qmlContext->setContextProperty("eventBridgeWrapper", new EventBridgeWrapper(this, _qmlContext));
|
||||||
|
|
||||||
|
#if ENABLE_QML_RENDERING
|
||||||
_renderControl->initialize(_canvas->getContext());
|
_renderControl->initialize(_canvas->getContext());
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !defined(Q_OS_ANDROID)
|
#if !defined(Q_OS_ANDROID)
|
||||||
// Connect with the audio client and listen for audio device changes
|
// Connect with the audio client and listen for audio device changes
|
||||||
|
@ -790,6 +804,7 @@ void OffscreenQmlSurface::resize(const QSize& newSize_, bool forceResize) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_QML_RENDERING
|
||||||
qCDebug(uiLogging) << "Offscreen UI resizing to " << newSize.width() << "x" << newSize.height();
|
qCDebug(uiLogging) << "Offscreen UI resizing to " << newSize.width() << "x" << newSize.height();
|
||||||
gl::withSavedContext([&] {
|
gl::withSavedContext([&] {
|
||||||
_canvas->makeCurrent();
|
_canvas->makeCurrent();
|
||||||
|
@ -826,6 +841,7 @@ void OffscreenQmlSurface::resize(const QSize& newSize_, bool forceResize) {
|
||||||
|
|
||||||
_canvas->doneCurrent();
|
_canvas->doneCurrent();
|
||||||
});
|
});
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QQuickItem* OffscreenQmlSurface::getRootItem() {
|
QQuickItem* OffscreenQmlSurface::getRootItem() {
|
||||||
|
@ -1008,7 +1024,9 @@ void OffscreenQmlSurface::updateQuick() {
|
||||||
|
|
||||||
if (_polish) {
|
if (_polish) {
|
||||||
PROFILE_RANGE(render_qml, "OffscreenQML polish")
|
PROFILE_RANGE(render_qml, "OffscreenQML polish")
|
||||||
|
#if ENABLE_QML_RENDERING
|
||||||
_renderControl->polishItems();
|
_renderControl->polishItems();
|
||||||
|
#endif
|
||||||
_polish = false;
|
_polish = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1299,9 +1317,11 @@ bool OffscreenQmlSurface::isPaused() const {
|
||||||
|
|
||||||
void OffscreenQmlSurface::setProxyWindow(QWindow* window) {
|
void OffscreenQmlSurface::setProxyWindow(QWindow* window) {
|
||||||
_proxyWindow = window;
|
_proxyWindow = window;
|
||||||
|
#if ENABLE_QML_RENDERING
|
||||||
if (_renderControl) {
|
if (_renderControl) {
|
||||||
_renderControl->_renderWindow = window;
|
_renderControl->_renderWindow = window;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject* OffscreenQmlSurface::getEventHandler() {
|
QObject* OffscreenQmlSurface::getEventHandler() {
|
||||||
|
|
|
@ -35,6 +35,8 @@ class QQuickWindow;
|
||||||
class QQuickItem;
|
class QQuickItem;
|
||||||
class QJSValue;
|
class QJSValue;
|
||||||
|
|
||||||
|
#define ENABLE_QML_RENDERING 0
|
||||||
|
|
||||||
// GPU resources are typically buffered for one copy being used by the renderer,
|
// GPU resources are typically buffered for one copy being used by the renderer,
|
||||||
// one copy in flight, and one copy being used by the receiver
|
// one copy in flight, and one copy being used by the receiver
|
||||||
#define GPU_RESOURCE_BUFFER_SIZE 3
|
#define GPU_RESOURCE_BUFFER_SIZE 3
|
||||||
|
@ -168,10 +170,13 @@ public slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QQuickWindow* _quickWindow { nullptr };
|
QQuickWindow* _quickWindow { nullptr };
|
||||||
QMyQuickRenderControl* _renderControl{ nullptr };
|
|
||||||
QQmlContext* _qmlContext { nullptr };
|
QQmlContext* _qmlContext { nullptr };
|
||||||
QQuickItem* _rootItem { nullptr };
|
QQuickItem* _rootItem { nullptr };
|
||||||
|
|
||||||
|
#if ENABLE_QML_RENDERING
|
||||||
|
QMyQuickRenderControl* _renderControl{ nullptr };
|
||||||
OffscreenGLCanvas* _canvas { nullptr };
|
OffscreenGLCanvas* _canvas { nullptr };
|
||||||
|
#endif
|
||||||
|
|
||||||
QTimer _updateTimer;
|
QTimer _updateTimer;
|
||||||
uint32_t _fbo { 0 };
|
uint32_t _fbo { 0 };
|
||||||
|
|
Loading…
Reference in a new issue