From 54dfc33b38848c6d8a76effcec3227fbaa9f4151 Mon Sep 17 00:00:00 2001 From: David Kelly Date: Wed, 14 Jun 2017 14:36:37 -0700 Subject: [PATCH] initial skeleton of qml objects --- .../resources/qml/hifi/SpectatorCamera.qml | 26 ++++++++--------- interface/src/Application.cpp | 18 ++++++------ interface/src/ui/ResourceImageItem.cpp | 28 +++++++++++++++++++ interface/src/ui/ResourceImageItem.h | 27 ++++++++++++++++++ 4 files changed, 78 insertions(+), 21 deletions(-) create mode 100644 interface/src/ui/ResourceImageItem.cpp create mode 100644 interface/src/ui/ResourceImageItem.h diff --git a/interface/resources/qml/hifi/SpectatorCamera.qml b/interface/resources/qml/hifi/SpectatorCamera.qml index 544fc72927..37e8fdee01 100644 --- a/interface/resources/qml/hifi/SpectatorCamera.qml +++ b/interface/resources/qml/hifi/SpectatorCamera.qml @@ -11,6 +11,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +import Hifi 1.0 as Hifi import QtQuick 2.5 import QtQuick.Controls 1.4 import "../styles-uit" @@ -25,7 +26,7 @@ Rectangle { id: spectatorCamera; // Style color: hifi.colors.baseGray; - + // // TITLE BAR START // @@ -64,7 +65,7 @@ Rectangle { // // TITLE BAR END // - + // // SPECTATOR APP DESCRIPTION START // @@ -139,7 +140,7 @@ Rectangle { // Alignment horizontalAlignment: Text.AlignHLeft; verticalAlignment: Text.AlignVCenter; - + MouseArea { anchors.fill: parent; hoverEnabled: enabled; @@ -163,7 +164,7 @@ Rectangle { // SPECTATOR APP DESCRIPTION END // - + // // SPECTATOR CONTROLS START // @@ -193,19 +194,18 @@ Rectangle { } // Spectator Camera Preview - Image { + Rectangle { id: spectatorCameraPreview; height: 250; anchors.left: parent.left; anchors.top: cameraToggleCheckBox.bottom; anchors.topMargin: 20; anchors.right: parent.right; - fillMode: Image.PreserveAspectFit; - horizontalAlignment: Image.AlignHCenter; - verticalAlignment: Image.AlignVCenter; - source: "http://1.bp.blogspot.com/-1GABEq__054/T03B00j_OII/AAAAAAAAAa8/jo55LcvEPHI/s1600/Winning.jpg"; + Hifi.ResourceImageItem { + anchors.fill: parent; + } } - + // "Monitor Shows" Switch Label Glyph HiFiGlyphs { id: monitorShowsSwitchLabelGlyph; @@ -259,7 +259,7 @@ Rectangle { sendToScript({method: 'changeSwitchViewFromControllerPreference', params: checked}); } } - } + } // // SPECTATOR CONTROLS END // @@ -272,11 +272,11 @@ Rectangle { // // Relevant Variables: // None - // + // // Arguments: // message: The message sent from the SpectatorCamera JavaScript. // Messages are in format "{method, params}", like json-rpc. - // + // // Description: // Called when a message is received from spectatorCamera.js. // diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ee1292f4bf..ca4954860a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -170,6 +170,7 @@ #if defined(Q_OS_MAC) || defined(Q_OS_WIN) #include "SpeechRecognizer.h" #endif +#include "ui/ResourceImageItem.h" #include "ui/AddressBarDialog.h" #include "ui/AvatarInputs.h" #include "ui/DialogsManager.h" @@ -214,7 +215,7 @@ static QTimer pingTimer; static const int MAX_CONCURRENT_RESOURCE_DOWNLOADS = 16; -// For processing on QThreadPool, we target a number of threads after reserving some +// For processing on QThreadPool, we target a number of threads after reserving some // based on how many are being consumed by the application and the display plugin. However, // we will never drop below the 'min' value static const int MIN_PROCESSING_THREAD_POOL_SIZE = 1; @@ -1247,7 +1248,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo // Add periodic checks to send user activity data static int CHECK_NEARBY_AVATARS_INTERVAL_MS = 10000; static int NEARBY_AVATAR_RADIUS_METERS = 10; - + // setup the stats interval depending on if the 1s faster hearbeat was requested static const QString FAST_STATS_ARG = "--fast-heartbeat"; static int SEND_STATS_INTERVAL_MS = arguments().indexOf(FAST_STATS_ARG) != -1 ? 1000 : 10000; @@ -1397,10 +1398,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo _autoSwitchDisplayModeSupportedHMDPlugin = nullptr; foreach(DisplayPluginPointer displayPlugin, PluginManager::getInstance()->getDisplayPlugins()) { - if (displayPlugin->isHmd() && + if (displayPlugin->isHmd() && displayPlugin->getSupportsAutoSwitch()) { _autoSwitchDisplayModeSupportedHMDPlugin = displayPlugin; - _autoSwitchDisplayModeSupportedHMDPluginName = + _autoSwitchDisplayModeSupportedHMDPluginName = _autoSwitchDisplayModeSupportedHMDPlugin->getName(); _previousHMDWornStatus = _autoSwitchDisplayModeSupportedHMDPlugin->isDisplayVisible(); @@ -1653,7 +1654,7 @@ void Application::aboutToQuit() { } getActiveDisplayPlugin()->deactivate(); - if (_autoSwitchDisplayModeSupportedHMDPlugin + if (_autoSwitchDisplayModeSupportedHMDPlugin && _autoSwitchDisplayModeSupportedHMDPlugin->isSessionActive()) { _autoSwitchDisplayModeSupportedHMDPlugin->endSession(); } @@ -1918,6 +1919,7 @@ void Application::initializeUi() { LoginDialog::registerType(); Tooltip::registerType(); UpdateDialog::registerType(); + qmlRegisterType("Hifi", 1, 0, "ResourceImageItem"); qmlRegisterType("Hifi", 1, 0, "Preference"); auto offscreenUi = DependencyManager::get(); @@ -5231,7 +5233,7 @@ void Application::clearDomainOctreeDetails() { skyStage->setBackgroundMode(model::SunSkyStage::SKY_DEFAULT); _recentlyClearedDomain = true; - + DependencyManager::get()->clearUnusedResources(); DependencyManager::get()->clearUnusedResources(); DependencyManager::get()->clearUnusedResources(); @@ -5793,7 +5795,7 @@ bool Application::displayAvatarAttachmentConfirmationDialog(const QString& name) } } -void Application::toggleRunningScriptsWidget() const { +void Application::toggleRunningScriptsWidget() const { auto scriptEngines = DependencyManager::get(); bool scriptsRunning = !scriptEngines->getRunningScripts().isEmpty(); auto tabletScriptingInterface = DependencyManager::get(); @@ -5892,7 +5894,7 @@ void Application::showDialog(const QString& desktopURL, const QString& tabletURL if (!hmd->getShouldShowTablet() && !isHMDMode()) { hmd->openTablet(); } - + } } diff --git a/interface/src/ui/ResourceImageItem.cpp b/interface/src/ui/ResourceImageItem.cpp new file mode 100644 index 0000000000..b1869d5ed2 --- /dev/null +++ b/interface/src/ui/ResourceImageItem.cpp @@ -0,0 +1,28 @@ +// +// ResourceImageItem.cpp +// +// Created by David Kelly and Howard Stearns on 2017/06/08 +// Copyright 2017 High Fidelity, Inc. + +// Distributed under the Apache License, Version 2.0 +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "ResourceImageItem.h" +#include +#include +#include + +QOpenGLFramebufferObject* ResourceImageItemRenderer::createFramebufferObject(const QSize& size) { + QOpenGLFramebufferObjectFormat format; + format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); + return new QOpenGLFramebufferObject(size, format); +} + +void ResourceImageItemRenderer::render() { + auto texture = DependencyManager::get()->getTexture(QUrl("resource://spectatorCameraFrame")); + if (texture) { + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture->getGPUTexture(), 0); + } + +} diff --git a/interface/src/ui/ResourceImageItem.h b/interface/src/ui/ResourceImageItem.h new file mode 100644 index 0000000000..6d8b33ae64 --- /dev/null +++ b/interface/src/ui/ResourceImageItem.h @@ -0,0 +1,27 @@ +// +// ResourceImageItem.h +// +// Created by David Kelly and Howard Stearns on 2017/06/08 +// Copyright 2017 High Fidelity, Inc. + +// Distributed under the Apache License, Version 2.0 +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#pragma once +#ifndef hifi_ResourceImageItem_h +#define hifi_ResourceImageItem_h + +#include +#include + +class ResourceImageItemRenderer : public QQuickFramebufferObject::Renderer, protected QOpenGLFunctions { + QOpenGLFramebufferObject* createFramebufferObject(const QSize& size); + void render(); +}; + +class ResourceImageItem : public QQuickFramebufferObject { + QQuickFramebufferObject::Renderer* createRenderer() const { return new ResourceImageItemRenderer; } +}; + +#endif // hifi_ResourceImageItem_h