From a8d343bbf1a1adb2c4fb23c23835b22464b1d9d5 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Tue, 12 May 2015 23:58:21 -0700 Subject: [PATCH] Working on web entities --- examples/edit.js | 7 ++- examples/html/entityProperties.html | 2 - interface/resources/qml/WebEntity.qml | 43 ++---------------- interface/src/Application.cpp | 10 +++-- .../src/RenderableWebEntityItem.cpp | 44 +++++++++++++------ .../src/RenderableWebEntityItem.h | 8 +++- libraries/entities/src/EntityItemProperties.h | 1 - libraries/entities/src/EntityTypes.h | 12 ++--- .../src/AbstractViewStateInterface.h | 7 ++- .../render-utils/src/OffscreenQmlSurface.cpp | 5 +-- 10 files changed, 64 insertions(+), 75 deletions(-) diff --git a/examples/edit.js b/examples/edit.js index 750ae9e4c8..e034392df0 100644 --- a/examples/edit.js +++ b/examples/edit.js @@ -438,18 +438,17 @@ var toolBar = (function () { } if (newWebButton === toolBar.clicked(clickedOverlay)) { - print("Web"); var position = getPositionToCreateEntity(); if (position.x > 0 && position.y > 0 && position.z > 0) { placingEntityID = Entities.addEntity({ type: "Web", position: grid.snapToSurface(grid.snapToGrid(position, false, DEFAULT_DIMENSIONS), DEFAULT_DIMENSIONS), - dimensions: { x: 0.65, y: 0.3, z: 0.01 }, - source: "http://www.slashdot.org", + dimensions: { x: 1.6, y: 0.9, z: 0.01 }, + sourceUrl: "https://highfidelity.com/", }); } else { - print("Can't create box: Text would be out of bounds."); + print("Can't create Web Entity: would be out of bounds."); } return true; } diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index ad16302ba4..1b004bbd3a 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -283,7 +283,6 @@ allSections.push(elModelSections); var elWebSourceURL = document.getElementById("property-web-source-url"); - var elTextSections = document.querySelectorAll(".text-section"); allSections.push(elTextSections); var elTextText = document.getElementById("property-text-text"); @@ -1039,7 +1038,6 @@ -
Model URL
diff --git a/interface/resources/qml/WebEntity.qml b/interface/resources/qml/WebEntity.qml index a9d8350244..0eb943cac7 100644 --- a/interface/resources/qml/WebEntity.qml +++ b/interface/resources/qml/WebEntity.qml @@ -2,44 +2,9 @@ import QtQuick 2.3 import QtQuick.Controls 1.2 import QtWebKit 3.0 -Item { +WebView { id: root - implicitHeight: 600 - implicitWidth: 800 - Rectangle { - anchors.margins: 120 - color: "#7f0000ff" - anchors.right: parent.horizontalCenter - anchors.bottom: parent.bottom - anchors.left: parent.left - anchors.top: parent.top - anchors.rightMargin: 10 - anchors.leftMargin: 10 - anchors.bottomMargin: 10 - anchors.topMargin: 10 - } - - Rectangle { - color: "#7Fff0000" - anchors.left: parent.horizontalCenter - anchors.leftMargin: 10 - anchors.top: parent.top - anchors.margins: 120 - anchors.right: parent.right - anchors.topMargin: 10 - anchors.bottomMargin: 10 - anchors.bottom: parent.bottom - anchors.rightMargin: 10 -/* - ScrollView { - id: scrollView - anchors.fill: parent - WebView { - id: webview - objectName: "webview" - anchors.fill: parent - } - } -*/ - } + objectName: "webview" + anchors.fill: parent + url: "about:blank" } diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index abb4f09cf8..199f91f087 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3102,7 +3102,7 @@ ViewFrustum* Application::getViewFrustum() { #ifdef DEBUG if (QThread::currentThread() == activeRenderingThread) { // FIXME, should this be an assert? -// qWarning() << "Calling Application::getViewFrustum() from the active rendering thread, did you mean Application::getDisplayViewFrustum()?"; + qWarning() << "Calling Application::getViewFrustum() from the active rendering thread, did you mean Application::getDisplayViewFrustum()?"; } #endif return &_viewFrustum; @@ -3112,7 +3112,7 @@ const ViewFrustum* Application::getViewFrustum() const { #ifdef DEBUG if (QThread::currentThread() == activeRenderingThread) { // FIXME, should this be an assert? -// qWarning() << "Calling Application::getViewFrustum() from the active rendering thread, did you mean Application::getDisplayViewFrustum()?"; + qWarning() << "Calling Application::getViewFrustum() from the active rendering thread, did you mean Application::getDisplayViewFrustum()?"; } #endif return &_viewFrustum; @@ -3122,7 +3122,7 @@ ViewFrustum* Application::getDisplayViewFrustum() { #ifdef DEBUG if (QThread::currentThread() != activeRenderingThread) { // FIXME, should this be an assert? -// qWarning() << "Calling Application::getDisplayViewFrustum() from outside the active rendering thread or outside rendering, did you mean Application::getViewFrustum()?"; + qWarning() << "Calling Application::getDisplayViewFrustum() from outside the active rendering thread or outside rendering, did you mean Application::getViewFrustum()?"; } #endif return &_displayViewFrustum; @@ -4688,3 +4688,7 @@ void Application::setMaxOctreePacketsPerSecond(int maxOctreePPS) { int Application::getMaxOctreePacketsPerSecond() { return _maxOctreePPS; } + +AbstractViewStateInterface* AbstractViewStateInterface::instance() { + return qApp; +} diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp index 487a6cfbb4..25fad4c066 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -34,23 +35,43 @@ RenderableWebEntityItem::RenderableWebEntityItem(const EntityItemID& entityItemI WebEntityItem(entityItemID, properties) { } +RenderableWebEntityItem::~RenderableWebEntityItem() { + if (_webSurface) { + _webSurface->pause(); + _webSurface->disconnect(_connection); + if (_texture) { + _webSurface->releaseTexture(_texture); + _texture = 0; + } + _webSurface.clear(); + } +} + void RenderableWebEntityItem::render(RenderArgs* args) { QOpenGLContext * currentContext = QOpenGLContext::currentContext(); QSurface * currentSurface = currentContext->surface(); if (!_webSurface) { - _webSurface = new OffscreenQmlSurface(); + _webSurface = QSharedPointer(new OffscreenQmlSurface()); _webSurface->create(currentContext); _webSurface->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath() + "/qml/")); _webSurface->load("WebEntity.qml"); _webSurface->resume(); updateQmlSourceUrl(); - QObject::connect(_webSurface, &OffscreenQmlSurface::textureUpdated, [&](GLuint textureId) { + _connection = QObject::connect(_webSurface.data(), &OffscreenQmlSurface::textureUpdated, [&](GLuint textureId) { _webSurface->lockTexture(textureId); assert(!glGetError()); std::swap(_texture, textureId); if (textureId) { _webSurface->releaseTexture(textureId); } + if (_texture) { + _webSurface->makeCurrent(); + glBindTexture(GL_TEXTURE_2D, _texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glBindTexture(GL_TEXTURE_2D, 0); + _webSurface->doneCurrent(); + } }); } @@ -77,7 +98,7 @@ void RenderableWebEntityItem::render(RenderArgs* args) { glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - float alpha = 1.0f; //getBackgroundAlpha(); + float alpha = 1.0f; static const glm::vec2 texMin(0); static const glm::vec2 texMax(1); glm::vec2 topLeft(-halfDimensions.x, -halfDimensions.y); @@ -88,13 +109,8 @@ void RenderableWebEntityItem::render(RenderArgs* args) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } - - - // TODO: Determine if we want these entities to have the deferred lighting effect? I think we do, so that the color - // used for a sphere, or box have the same look as those used on a text entity. - DependencyManager::get()->renderQuad(topLeft, bottomRight, - texMin, texMax, glm::vec4(1)); - + DependencyManager::get()->renderQuad( + topLeft, bottomRight, texMin, texMax, glm::vec4(1)); if (_texture) { glBindTexture(GL_TEXTURE_2D, 0); glEnable(GL_TEXTURE_2D); @@ -106,8 +122,10 @@ void RenderableWebEntityItem::render(RenderArgs* args) { void RenderableWebEntityItem::setSourceUrl(const QString& value) { if (_sourceUrl != value) { _sourceUrl = value; - // Update the offscreen display - updateQmlSourceUrl(); + AbstractViewStateInterface::instance()->postLambdaEvent([this] { + // Update the offscreen display + updateQmlSourceUrl(); + }); } } @@ -115,7 +133,7 @@ void RenderableWebEntityItem::updateQmlSourceUrl() { if (!_webSurface) { return; } - auto webView = _webSurface->getRootItem()->findChild("webview"); + auto webView = _webSurface->getRootItem(); if (!webView) { return; } diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.h b/libraries/entities-renderer/src/RenderableWebEntityItem.h index c926314b66..6d94a6d90c 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.h +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.h @@ -9,6 +9,8 @@ #ifndef hifi_RenderableWebEntityItem_h #define hifi_RenderableWebEntityItem_h +#include + #include class OffscreenQmlSurface; @@ -18,14 +20,16 @@ public: static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); RenderableWebEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties); - virtual void render(RenderArgs* args); + ~RenderableWebEntityItem(); + virtual void render(RenderArgs* args); virtual void setSourceUrl(const QString& value); private: void updateQmlSourceUrl(); - OffscreenQmlSurface* _webSurface{ nullptr }; + QSharedPointer _webSurface; + QMetaObject::Connection _connection; uint32_t _texture{ 0 }; }; diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 46c4c39e10..a1ca4d5eff 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -141,7 +141,6 @@ public: DEFINE_PROPERTY_GROUP(Atmosphere, atmosphere, AtmospherePropertyGroup); DEFINE_PROPERTY_GROUP(Skybox, skybox, SkyboxPropertyGroup); DEFINE_PROPERTY_REF(PROP_SOURCE_URL, SourceUrl, sourceUrl, QString); - static QString getBackgroundModeString(BackgroundMode mode); diff --git a/libraries/entities/src/EntityTypes.h b/libraries/entities/src/EntityTypes.h index 7d6bfaf7e5..b3de3dfc8e 100644 --- a/libraries/entities/src/EntityTypes.h +++ b/libraries/entities/src/EntityTypes.h @@ -30,16 +30,16 @@ class EntityTypes { public: typedef enum EntityType_t { Unknown, - Box, - Light, - Line, Model, - ParticleEffect, + Box, Sphere, + Light, Text, - Web, + ParticleEffect, Zone, - LAST = Zone + Web, + Line, + LAST = Line } EntityType; static const QString& getEntityTypeName(EntityType entityType); diff --git a/libraries/render-utils/src/AbstractViewStateInterface.h b/libraries/render-utils/src/AbstractViewStateInterface.h index 8ba8ba33c7..c7b69943af 100644 --- a/libraries/render-utils/src/AbstractViewStateInterface.h +++ b/libraries/render-utils/src/AbstractViewStateInterface.h @@ -13,6 +13,7 @@ #define hifi_AbstractViewStateInterface_h #include +#include class Transform; class QThread; @@ -37,7 +38,7 @@ public: /// overrides environment data virtual void overrideEnvironmentData(const EnvironmentData& newData) = 0; virtual void endOverrideEnvironmentData() = 0; - + /// gets the shadow view frustum for rendering the view state virtual ViewFrustum* getShadowViewFrustum() = 0; @@ -53,6 +54,10 @@ public: virtual PickRay computePickRay(float x, float y) const = 0; virtual const glm::vec3& getAvatarPosition() const = 0; + + virtual void postLambdaEvent(std::function f) = 0; + + static AbstractViewStateInterface* instance(); }; diff --git a/libraries/render-utils/src/OffscreenQmlSurface.cpp b/libraries/render-utils/src/OffscreenQmlSurface.cpp index 1893c77595..70213a9935 100644 --- a/libraries/render-utils/src/OffscreenQmlSurface.cpp +++ b/libraries/render-utils/src/OffscreenQmlSurface.cpp @@ -1,8 +1,5 @@ // -// OffscreenUi.cpp -// interface/src/render-utils -// -// Created by Bradley Austin Davis on 2015-04-04 +// Created by Bradley Austin Davis on 2015-05-13 // Copyright 2015 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0.