History

Merge branch 'console' into console-dev

Stephen Birarda committed 10 years ago

Commit 6b4db272 parents c886cde 948bc45258 files · +11167 −3435Browse files

Showing the changes to interface/src/Application.cpp (1 of 258 files). Show all

Unified · Split

interface/src/Application.cpp+85−121
@@ -92,6 +92,7 @@ · 91 unmodified lines
9292 #include <RenderableWebEntityItem.h>
9393 #include <RenderDeferredTask.h>
9494 #include <ResourceCache.h>
95+#include <RenderScriptingInterface.h>
9596 #include <SceneScriptingInterface.h>
9697 #include <RecordingScriptingInterface.h>
9798 #include <ScriptCache.h>
@@ -104,6 +105,7 @@ · 6 unmodified lines
104105 #include <VrMenu.h>
105106 #include <recording/Deck.h>
106107 #include <recording/Recorder.h>
108+#include <QmlWebWindowClass.h>
107109
108110 #include "AnimDebugDraw.h"
109111 #include "AudioClient.h"
@@ -344,6 +346,7 @@ bool setupEssentials(int& argc, char** argv) { · 234 unmodified lines
344346 #endif
345347 DependencyManager::set<DiscoverabilityManager>();
346348 DependencyManager::set<SceneScriptingInterface>();
349+ DependencyManager::set<RenderScriptingInterface>();
347350 DependencyManager::set<OffscreenUi>();
348351 DependencyManager::set<AutoUpdater>();
349352 DependencyManager::set<PathUtils>();
@@ -365,6 +368,17 @@ Cube3DOverlay* _keyboardFocusHighlight{ nullptr }; · 15 unmodified lines
365368 int _keyboardFocusHighlightID{ -1 };
366369 PluginContainer* _pluginContainer;
367370
371+
372+// FIXME hack access to the internal share context for the Chromium helper
373+// Normally we'd want to use QWebEngine::initialize(), but we can't because
374+// our primary context is a QGLWidget, which can't easily be initialized to share
375+// from a QOpenGLContext.
376+//
377+// So instead we create a new offscreen context to share with the QGLWidget,
378+// and manually set THAT to be the shared context for the Chromium helper
379+OffscreenGLCanvas* _chromiumShareContext { nullptr };
380+Q_GUI_EXPORT void qt_gl_set_global_share_context(QOpenGLContext *context);
381+
368382 Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
369383 QApplication(argc, argv),
370384 _dependencyManagerIsSetup(setupEssentials(argc, argv)),
@@ -626,6 +640,11 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 255 unmodified lines
626640 _glWidget->makeCurrent();
627641 _glWidget->initializeGL();
628642
643+ _chromiumShareContext = new OffscreenGLCanvas();
644+ _chromiumShareContext->create(_glWidget->context()->contextHandle());
645+ _chromiumShareContext->makeCurrent();
646+ qt_gl_set_global_share_context(_chromiumShareContext->getContext());
647+
629648 _offscreenContext = new OffscreenGLCanvas();
630649 _offscreenContext->create(_glWidget->context()->contextHandle());
631650 _offscreenContext->makeCurrent();
@@ -689,13 +708,37 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 57 unmodified lines
689708 } else if (action == controller::toInt(controller::Action::CONTEXT_MENU)) {
690709 VrMenu::toggle(); // show context menu even on non-stereo displays
691710 } else if (action == controller::toInt(controller::Action::RETICLE_X)) {
692− auto globalPos = QCursor::pos();
693− globalPos.setX(globalPos.x() + state);
694− QCursor::setPos(globalPos);
711+ auto oldPos = QCursor::pos();
712+ auto newPos = oldPos;
713+ newPos.setX(oldPos.x() + state);
714+ QCursor::setPos(newPos);
715+
716+
717+ // NOTE: This is some debugging code we will leave in while debugging various reticle movement strategies,
718+ // remove it after we're done
719+ const float REASONABLE_CHANGE = 50.0f;
720+ glm::vec2 oldPosG = { oldPos.x(), oldPos.y() };
721+ glm::vec2 newPosG = { newPos.x(), newPos.y() };
722+ auto distance = glm::distance(oldPosG, newPosG);
723+ if (distance > REASONABLE_CHANGE) {
724+ qDebug() << "Action::RETICLE_X... UNREASONABLE CHANGE! distance:" << distance << " oldPos:" << oldPosG << " newPos:" << newPosG;
725+ }
726+
695727 } else if (action == controller::toInt(controller::Action::RETICLE_Y)) {
696− auto globalPos = QCursor::pos();
697− globalPos.setY(globalPos.y() + state);
698− QCursor::setPos(globalPos);
728+ auto oldPos = QCursor::pos();
729+ auto newPos = oldPos;
730+ newPos.setY(oldPos.y() + state);
731+ QCursor::setPos(newPos);
732+
733+ // NOTE: This is some debugging code we will leave in while debugging various reticle movement strategies,
734+ // remove it after we're done
735+ const float REASONABLE_CHANGE = 50.0f;
736+ glm::vec2 oldPosG = { oldPos.x(), oldPos.y() };
737+ glm::vec2 newPosG = { newPos.x(), newPos.y() };
738+ auto distance = glm::distance(oldPosG, newPosG);
739+ if (distance > REASONABLE_CHANGE) {
740+ qDebug() << "Action::RETICLE_Y... UNREASONABLE CHANGE! distance:" << distance << " oldPos:" << oldPosG << " newPos:" << newPosG;
741+ }
699742 }
700743 }
701744 });
@@ -709,9 +752,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 7 unmodified lines
709752 _applicationStateDevice->addInputVariant(QString("ComfortMode"), controller::StateController::ReadLambda([]() -> float {
710753 return (float)Menu::getInstance()->isOptionChecked(MenuOption::ComfortMode);
711754 }));
712− _applicationStateDevice->addInputVariant(QString("Grounded"), controller::StateController::ReadLambda([]() -> float {
713− return (float)qApp->getMyAvatar()->getCharacterController()->onGround();
714− }));
755+ _applicationStateDevice->addInputVariant(QString("Grounded"), controller::StateController::ReadLambda([]() -> float {
756+ return (float)qApp->getMyAvatar()->getCharacterController()->onGround();
757+ }));
715758
716759 userInputMapper->registerDevice(_applicationStateDevice);
717760
@@ -1164,26 +1207,15 @@ void Application::paintGL() { · 446 unmodified lines
11641207
11651208 if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
11661209 PerformanceTimer perfTimer("Mirror");
1167− auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferDepthColor();
1210+ auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
11681211
11691212 renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
1213+ renderArgs._blitFramebuffer = DependencyManager::get<FramebufferCache>()->getSelfieFramebuffer();
1214+
11701215 renderRearViewMirror(&renderArgs, _mirrorViewRect);
1171− renderArgs._renderMode = RenderArgs::DEFAULT_RENDER_MODE;
11721216
1173− {
1174− float ratio = ((float)QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale());
1175− // Flip the src and destination rect horizontally to do the mirror
1176− auto mirrorRect = glm::ivec4(0, 0, _mirrorViewRect.width() * ratio, _mirrorViewRect.height() * ratio);
1177− auto mirrorRectDest = glm::ivec4(mirrorRect.z, mirrorRect.y, mirrorRect.x, mirrorRect.w);
1178−
1179− auto selfieFbo = DependencyManager::get<FramebufferCache>()->getSelfieFramebuffer();
1180− gpu::doInBatch(renderArgs._context, [=](gpu::Batch& batch) {
1181− batch.setFramebuffer(selfieFbo);
1182− batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0f, 0.0f, 0.0f, 0.0f));
1183− batch.blit(primaryFbo, mirrorRect, selfieFbo, mirrorRectDest);
1184− batch.setFramebuffer(nullptr);
1185− });
1186− }
1217+ renderArgs._blitFramebuffer.reset();
1218+ renderArgs._renderMode = RenderArgs::DEFAULT_RENDER_MODE;
11871219 }
11881220
11891221 {
@@ -1263,15 +1295,14 @@ void Application::paintGL() { · 73 unmodified lines
12631295 hmdOffset.x = -hmdOffset.x;
12641296
12651297 _myCamera.setPosition(myAvatar->getDefaultEyePosition()
1266− + glm::vec3(0, _raiseMirror * myAvatar->getAvatarScale(), 0)
1298+ + glm::vec3(0, _raiseMirror * myAvatar->getUniformScale(), 0)
12671299 + mirrorBodyOrientation * glm::vec3(0.0f, 0.0f, 1.0f) * MIRROR_FULLSCREEN_DISTANCE * _scaleMirror
12681300 + mirrorBodyOrientation * hmdOffset);
1269−
12701301 } else {
12711302 _myCamera.setRotation(myAvatar->getWorldAlignedOrientation()
12721303 * glm::quat(glm::vec3(0.0f, PI + _rotateMirror, 0.0f)));
12731304 _myCamera.setPosition(myAvatar->getDefaultEyePosition()
1274− + glm::vec3(0, _raiseMirror * myAvatar->getAvatarScale(), 0)
1305+ + glm::vec3(0, _raiseMirror * myAvatar->getUniformScale(), 0)
12751306 + (myAvatar->getOrientation() * glm::quat(glm::vec3(0.0f, _rotateMirror, 0.0f))) *
12761307 glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_FULLSCREEN_DISTANCE * _scaleMirror);
12771308 }
@@ -1355,65 +1386,11 @@ void Application::paintGL() { · 77 unmodified lines
13551386 renderArgs._context->setStereoProjections(eyeProjections);
13561387 renderArgs._context->setStereoViews(eyeOffsets);
13571388 }
1389+ renderArgs._blitFramebuffer = finalFramebuffer;
13581390 displaySide(&renderArgs, _myCamera);
1359− renderArgs._context->enableStereo(false);
13601391
1361− // Blit primary to final FBO
1362− auto primaryFbo = framebufferCache->getPrimaryFramebuffer();
1363−
1364− if (renderArgs._renderMode == RenderArgs::MIRROR_RENDER_MODE) {
1365− if (displayPlugin->isStereo()) {
1366− gpu::doInBatch(renderArgs._context, [=](gpu::Batch& batch) {
1367− gpu::Vec4i srcRectLeft;
1368− srcRectLeft.z = size.width() / 2;
1369− srcRectLeft.w = size.height();
1370−
1371− gpu::Vec4i srcRectRight;
1372− srcRectRight.x = size.width() / 2;
1373− srcRectRight.z = size.width();
1374− srcRectRight.w = size.height();
1375−
1376− gpu::Vec4i destRectLeft;
1377− destRectLeft.x = srcRectLeft.z;
1378− destRectLeft.z = srcRectLeft.x;
1379− destRectLeft.y = srcRectLeft.y;
1380− destRectLeft.w = srcRectLeft.w;
1381−
1382− gpu::Vec4i destRectRight;
1383− destRectRight.x = srcRectRight.z;
1384− destRectRight.z = srcRectRight.x;
1385− destRectRight.y = srcRectRight.y;
1386− destRectRight.w = srcRectRight.w;
1387−
1388− batch.setFramebuffer(finalFramebuffer);
1389− batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0f, 0.0f, 1.0f, 0.0f));
1390− // BLit left to right and right to left in stereo
1391− batch.blit(primaryFbo, srcRectRight, finalFramebuffer, destRectLeft);
1392− batch.blit(primaryFbo, srcRectLeft, finalFramebuffer, destRectRight);
1393− });
1394− } else {
1395− gpu::doInBatch(renderArgs._context, [=](gpu::Batch& batch) {
1396− gpu::Vec4i srcRect;
1397− srcRect.z = size.width();
1398− srcRect.w = size.height();
1399− gpu::Vec4i destRect;
1400− destRect.x = size.width();
1401− destRect.y = 0;
1402− destRect.z = 0;
1403− destRect.w = size.height();
1404− batch.setFramebuffer(finalFramebuffer);
1405− batch.blit(primaryFbo, srcRect, finalFramebuffer, destRect);
1406− });
1407− }
1408− } else {
1409− gpu::doInBatch(renderArgs._context, [=](gpu::Batch& batch) {
1410− gpu::Vec4i rect;
1411− rect.z = size.width();
1412− rect.w = size.height();
1413− batch.setFramebuffer(finalFramebuffer);
1414− batch.blit(primaryFbo, rect, finalFramebuffer, rect);
1415− });
1416− }
1392+ renderArgs._blitFramebuffer.reset();
1393+ renderArgs._context->enableStereo(false);
14171394 }
14181395
14191396 // Overlay Composition, needs to occur after screen space effects have completed
@@ -1421,7 +1398,9 @@ void Application::paintGL() { · 1 unmodified line
14211398 {
14221399 PROFILE_RANGE(__FUNCTION__ "/compositor");
14231400 PerformanceTimer perfTimer("compositor");
1401+
14241402 auto primaryFbo = finalFramebuffer;
1403+
14251404 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFbo));
14261405 if (displayPlugin->isStereo()) {
14271406 QRect currentViewport(QPoint(0, 0), QSize(size.width() / 2, size.height()));
@@ -1446,7 +1425,9 @@ void Application::paintGL() { · 18 unmodified lines
14461425 {
14471426 PROFILE_RANGE(__FUNCTION__ "/pluginOutput");
14481427 PerformanceTimer perfTimer("pluginOutput");
1428+
14491429 auto finalTexturePointer = finalFramebuffer->getRenderBuffer(0);
1430+
14501431 GLuint finalTexture = gpu::GLBackend::getTextureID(finalTexturePointer);
14511432 Q_ASSERT(0 != finalTexture);
14521433
@@ -2574,7 +2555,7 @@ void Application::init() { · 1121 unmodified lines
25742555
25752556 _environment.init();
25762557
2577− DependencyManager::get<DeferredLightingEffect>()->init(this);
2558+ DependencyManager::get<DeferredLightingEffect>()->init();
25782559
25792560 DependencyManager::get<AvatarManager>()->init();
25802561 _myCamera.setMode(CAMERA_MODE_FIRST_PERSON);
@@ -2992,6 +2973,9 @@ void Application::update(float deltaTime) { · 411 unmodified lines
29922973 _physicsEngine->changeObjects(motionStates);
29932974
29942975 myAvatar->prepareForPhysicsSimulation();
2976+ _physicsEngine->forEachAction([&](EntityActionPointer action) {
2977+ action->prepareForPhysicsSimulation();
2978+ });
29952979
29962980 getEntities()->getTree()->withWriteLock([&] {
29972981 _physicsEngine->stepSimulation();
@@ -3404,7 +3388,7 @@ QImage Application::renderAvatarBillboard(RenderArgs* renderArgs) { · 406 unmodified lines
34043388 renderArgs->_renderMode = RenderArgs::DEFAULT_RENDER_MODE;
34053389 renderRearViewMirror(renderArgs, QRect(0, 0, BILLBOARD_SIZE, BILLBOARD_SIZE), true);
34063390
3407− auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferDepthColor();
3391+ auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
34083392 QImage image(BILLBOARD_SIZE, BILLBOARD_SIZE, QImage::Format_ARGB32);
34093393 renderArgs->_context->downloadFramebuffer(primaryFbo, glm::ivec4(0, 0, BILLBOARD_SIZE, BILLBOARD_SIZE), image);
34103394
@@ -3674,34 +3658,19 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 263 unmodified lines
36743658 // For now every frame pass the renderContext
36753659 {
36763660 PerformanceTimer perfTimer("EngineRun");
3677− render::RenderContext renderContext;
3678−
3679− auto sceneInterface = DependencyManager::get<SceneScriptingInterface>();
36803661
3681− renderContext._cullOpaque = sceneInterface->doEngineCullOpaque();
3682− renderContext._sortOpaque = sceneInterface->doEngineSortOpaque();
3683− renderContext._renderOpaque = sceneInterface->doEngineRenderOpaque();
3684− renderContext._cullTransparent = sceneInterface->doEngineCullTransparent();
3685− renderContext._sortTransparent = sceneInterface->doEngineSortTransparent();
3686− renderContext._renderTransparent = sceneInterface->doEngineRenderTransparent();
3687−
3688− renderContext._maxDrawnOpaqueItems = sceneInterface->getEngineMaxDrawnOpaqueItems();
3689− renderContext._maxDrawnTransparentItems = sceneInterface->getEngineMaxDrawnTransparentItems();
3690− renderContext._maxDrawnOverlay3DItems = sceneInterface->getEngineMaxDrawnOverlay3DItems();
3691−
3692− renderContext._drawItemStatus = sceneInterface->doEngineDisplayItemStatus();
3693− if (Menu::getInstance()->isOptionChecked(MenuOption::PhysicsShowOwned)) {
3694− renderContext._drawItemStatus |= render::showNetworkStatusFlag;
3695− }
3696− renderContext._drawHitEffect = sceneInterface->doEngineDisplayHitEffect();
3697−
3698− renderContext._occlusionStatus = Menu::getInstance()->isOptionChecked(MenuOption::DebugAmbientOcclusion);
3699− renderContext._fxaaStatus = Menu::getInstance()->isOptionChecked(MenuOption::Antialiasing);
3662+ auto renderInterface = DependencyManager::get<RenderScriptingInterface>();
3663+ auto renderContext = renderInterface->getRenderContext();
37003664
37013665 renderArgs->_shouldRender = LODManager::shouldRender;
3702−
3703− renderContext.args = renderArgs;
37043666 renderArgs->_viewFrustum = getDisplayViewFrustum();
3667+ renderContext.setArgs(renderArgs);
3668+
3669+ bool occlusionStatus = Menu::getInstance()->isOptionChecked(MenuOption::DebugAmbientOcclusion);
3670+ bool antialiasingStatus = Menu::getInstance()->isOptionChecked(MenuOption::Antialiasing);
3671+ bool showOwnedStatus = Menu::getInstance()->isOptionChecked(MenuOption::PhysicsShowOwned);
3672+ renderContext.setOptions(occlusionStatus, antialiasingStatus, showOwnedStatus);
3673+
37053674 _renderEngine->setRenderContext(renderContext);
37063675
37073676 // Before the deferred pass, let's try to use the render engine
@@ -3709,15 +3678,8 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 1 unmodified line
37093678 _renderEngine->run();
37103679 myAvatar->endRenderRun();
37113680
3712− auto engineRC = _renderEngine->getRenderContext();
3713− sceneInterface->setEngineFeedOpaqueItems(engineRC->_numFeedOpaqueItems);
3714− sceneInterface->setEngineDrawnOpaqueItems(engineRC->_numDrawnOpaqueItems);
3715−
3716− sceneInterface->setEngineFeedTransparentItems(engineRC->_numFeedTransparentItems);
3717− sceneInterface->setEngineDrawnTransparentItems(engineRC->_numDrawnTransparentItems);
3718−
3719− sceneInterface->setEngineFeedOverlay3DItems(engineRC->_numFeedOverlay3DItems);
3720− sceneInterface->setEngineDrawnOverlay3DItems(engineRC->_numDrawnOverlay3DItems);
3681+ auto engineContext = _renderEngine->getRenderContext();
3682+ renderInterface->setItemCounts(engineContext->getItemsConfig());
37213683 }
37223684
37233685 activeRenderingThread = nullptr;
@@ -4143,6 +4105,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 419 unmodified lines
41434105 LocationScriptingInterface::locationSetter);
41444106
41454107 scriptEngine->registerFunction("WebWindow", WebWindowClass::constructor, 1);
4108+ scriptEngine->registerFunction("OverlayWebWindow", QmlWebWindowClass::constructor);
41464109
41474110 scriptEngine->registerGlobalObject("Menu", MenuScriptingInterface::getInstance());
41484111 scriptEngine->registerGlobalObject("Stats", Stats::getInstance());
@@ -4171,11 +4134,12 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 22 unmodified lines
41714134 scriptEngine->registerFunction("HMD", "getHUDLookAtPosition3D", HMDScriptingInterface::getHUDLookAtPosition3D, 0);
41724135
41734136 scriptEngine->registerGlobalObject("Scene", DependencyManager::get<SceneScriptingInterface>().data());
4137+ scriptEngine->registerGlobalObject("Render", DependencyManager::get<RenderScriptingInterface>().data());
41744138
41754139 scriptEngine->registerGlobalObject("ScriptDiscoveryService", this->getRunningScriptsWidget());
41764140 }
41774141
4178−bool Application::canAcceptURL(const QString& urlString) {
4142+bool Application::canAcceptURL(const QString& urlString) const {
41794143 QUrl url(urlString);
41804144 if (urlString.startsWith(HIFI_URL_SCHEME)) {
41814145 return true;