Showing the changes to interface/src/Application.cpp (1 of 452 files). Show all
Unified · Split
| @@ -9,11 +9,9 @@ · 8 unmodified lines | ||
| 9 | 9 | // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html |
| 10 | 10 | // |
| 11 | 11 | |
| 12 | −#include <sstream> | |
| 12 | +#include "Application.h" | |
| 13 | 13 | |
| 14 | −#include <stdlib.h> | |
| 15 | −#include <cmath> | |
| 16 | −#include <math.h> | |
| 14 | +#include <sstream> | |
| 17 | 15 | |
| 18 | 16 | #include <glm/glm.hpp> |
| 19 | 17 | #include <glm/gtx/component_wise.hpp> |
| @@ -21,9 +19,6 @@ · 1 unmodified line | ||
| 21 | 19 | #include <glm/gtx/vector_angle.hpp> |
| 22 | 20 | #include <glm/gtc/type_ptr.hpp> |
| 23 | 21 | |
| 24 | −// include this before QGLWidget, which includes an earlier version of OpenGL | |
| 25 | −#include "InterfaceConfig.h" | |
| 26 | − | |
| 27 | 22 | #include <QAbstractNativeEventFilter> |
| 28 | 23 | #include <QActionGroup> |
| 29 | 24 | #include <QColorDialog> |
| @@ -58,13 +53,13 @@ · 28 unmodified lines | ||
| 58 | 53 | #include <AccountManager.h> |
| 59 | 54 | #include <AddressManager.h> |
| 60 | 55 | #include <CursorManager.h> |
| 61 | −#include <AmbientOcclusionEffect.h> | |
| 62 | 56 | #include <AudioInjector.h> |
| 63 | 57 | #include <AutoUpdater.h> |
| 64 | 58 | #include <DeferredLightingEffect.h> |
| 65 | 59 | #include <DependencyManager.h> |
| 66 | 60 | #include <EntityScriptingInterface.h> |
| 67 | 61 | #include <ErrorDialog.h> |
| 62 | +#include <FramebufferCache.h> | |
| 68 | 63 | #include <gpu/Batch.h> |
| 69 | 64 | #include <gpu/Context.h> |
| 70 | 65 | #include <gpu/GLBackend.h> |
| @@ -80,11 +75,10 @@ · 9 unmodified lines | ||
| 80 | 75 | #include <ObjectMotionState.h> |
| 81 | 76 | #include <OctalCode.h> |
| 82 | 77 | #include <OctreeSceneStats.h> |
| 83 | −#include <PacketHeaders.h> | |
| 78 | +#include <udt/PacketHeaders.h> | |
| 84 | 79 | #include <PathUtils.h> |
| 85 | 80 | #include <PerfStat.h> |
| 86 | 81 | #include <PhysicsEngine.h> |
| 87 | −#include <ProgramObject.h> | |
| 88 | 82 | #include <RenderDeferredTask.h> |
| 89 | 83 | #include <ResourceCache.h> |
| 90 | 84 | #include <SceneScriptingInterface.h> |
| @@ -92,15 +86,15 @@ · 1 unmodified line | ||
| 92 | 86 | #include <SettingHandle.h> |
| 93 | 87 | #include <SimpleAverage.h> |
| 94 | 88 | #include <SoundCache.h> |
| 95 | −#include <TextRenderer.h> | |
| 89 | +#include <TextureCache.h> | |
| 96 | 90 | #include <Tooltip.h> |
| 97 | 91 | #include <UserActivityLogger.h> |
| 98 | 92 | #include <UUID.h> |
| 99 | 93 | #include <VrMenu.h> |
| 100 | 94 | |
| 101 | −#include "Application.h" | |
| 102 | 95 | #include "AudioClient.h" |
| 103 | 96 | #include "DiscoverabilityManager.h" |
| 97 | +#include "GLCanvas.h" | |
| 104 | 98 | #include "InterfaceVersion.h" |
| 105 | 99 | #include "LODManager.h" |
| 106 | 100 | #include "Menu.h" |
| @@ -121,6 +115,7 @@ · 14 unmodified lines | ||
| 121 | 115 | #include "devices/MIDIManager.h" |
| 122 | 116 | #include "devices/OculusManager.h" |
| 123 | 117 | #include "devices/TV3DManager.h" |
| 118 | +#include "devices/3Dconnexion.h" | |
| 124 | 119 | |
| 125 | 120 | #include "scripting/AccountScriptingInterface.h" |
| 126 | 121 | #include "scripting/AudioDeviceScriptingInterface.h" |
| @@ -175,8 +170,6 @@ public: · 48 unmodified lines | ||
| 175 | 170 | using namespace std; |
| 176 | 171 | |
| 177 | 172 | // Starfield information |
| 178 | −static unsigned STARFIELD_NUM_STARS = 50000; | |
| 179 | −static unsigned STARFIELD_SEED = 1; | |
| 180 | 173 | static uint8_t THROTTLED_IDLE_TIMER_DELAY = 10; |
| 181 | 174 | |
| 182 | 175 | const qint64 MAXIMUM_CACHE_SIZE = 10 * BYTES_PER_GIGABYTES; // 10GB |
| @@ -272,8 +265,9 @@ bool setupEssentials(int& argc, char** argv) { · 89 unmodified lines | ||
| 272 | 265 | auto audio = DependencyManager::set<AudioClient>(); |
| 273 | 266 | auto audioScope = DependencyManager::set<AudioScope>(); |
| 274 | 267 | auto deferredLightingEffect = DependencyManager::set<DeferredLightingEffect>(); |
| 275 | − auto ambientOcclusionEffect = DependencyManager::set<AmbientOcclusionEffect>(); | |
| 276 | 268 | auto textureCache = DependencyManager::set<TextureCache>(); |
| 269 | + auto framebufferCache = DependencyManager::set<FramebufferCache>(); | |
| 270 | + | |
| 277 | 271 | auto animationCache = DependencyManager::set<AnimationCache>(); |
| 278 | 272 | auto ddeFaceTracker = DependencyManager::set<DdeFaceTracker>(); |
| 279 | 273 | auto modelBlender = DependencyManager::set<ModelBlender>(); |
| @@ -304,7 +298,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 24 unmodified lines | ||
| 304 | 298 | _window(new MainWindow(desktop())), |
| 305 | 299 | _toolWindow(NULL), |
| 306 | 300 | _friendsWindow(NULL), |
| 307 | − _datagramProcessor(), | |
| 308 | 301 | _undoStack(), |
| 309 | 302 | _undoStackScriptingInterface(&_undoStack), |
| 310 | 303 | _frameCount(0), |
| @@ -322,7 +315,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 11 unmodified lines | ||
| 322 | 315 | _previousScriptLocation("LastScriptLocation"), |
| 323 | 316 | _scriptsLocationHandle("scriptsLocation"), |
| 324 | 317 | _fieldOfView("fieldOfView", DEFAULT_FIELD_OF_VIEW_DEGREES), |
| 325 | − _viewTransform(), | |
| 326 | 318 | _scaleMirror(1.0f), |
| 327 | 319 | _rotateMirror(0.0f), |
| 328 | 320 | _raiseMirror(0.0f), |
| @@ -339,8 +331,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 10 unmodified lines | ||
| 339 | 331 | _lastNackTime(usecTimestampNow()), |
| 340 | 332 | _lastSendDownstreamAudioStats(usecTimestampNow()), |
| 341 | 333 | _isVSyncOn(true), |
| 334 | + _isThrottleFPSEnabled(true), | |
| 342 | 335 | _aboutToQuit(false), |
| 343 | 336 | _notifiedPacketVersionMismatchThisDomain(false), |
| 337 | + _glWidget(new GLCanvas()), | |
| 344 | 338 | _domainConnectionRefusals(QList<QString>()), |
| 345 | 339 | _maxOctreePPS(maxOctreePacketsPerSecond.get()), |
| 346 | 340 | _lastFaceTrackerUpdate(0), |
| @@ -371,24 +365,17 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 24 unmodified lines | ||
| 371 | 365 | _bookmarks = new Bookmarks(); // Before setting up the menu |
| 372 | 366 | |
| 373 | 367 | _runningScriptsWidget = new RunningScriptsWidget(_window); |
| 374 | − _renderEngine->addTask(render::TaskPointer(new RenderDeferredTask())); | |
| 368 | + _renderEngine->addTask(make_shared<RenderDeferredTask>()); | |
| 375 | 369 | _renderEngine->registerScene(_main3DScene); |
| 376 | − | |
| 370 | + | |
| 377 | 371 | // start the nodeThread so its event loop is running |
| 378 | 372 | QThread* nodeThread = new QThread(this); |
| 379 | − nodeThread->setObjectName("Datagram Processor Thread"); | |
| 373 | + nodeThread->setObjectName("NodeList Thread"); | |
| 380 | 374 | nodeThread->start(); |
| 381 | 375 | |
| 382 | 376 | // make sure the node thread is given highest priority |
| 383 | 377 | nodeThread->setPriority(QThread::TimeCriticalPriority); |
| 384 | 378 | |
| 385 | − _datagramProcessor = new DatagramProcessor(nodeList.data()); | |
| 386 | − | |
| 387 | − // have the NodeList use deleteLater from DM customDeleter | |
| 388 | − nodeList->setCustomDeleter([](Dependency* dependency) { | |
| 389 | − static_cast<NodeList*>(dependency)->deleteLater(); | |
| 390 | − }); | |
| 391 | − | |
| 392 | 379 | // setup a timer for domain-server check ins |
| 393 | 380 | QTimer* domainCheckInTimer = new QTimer(nodeList.data()); |
| 394 | 381 | connect(domainCheckInTimer, &QTimer::timeout, nodeList.data(), &NodeList::sendDomainServerCheckIn); |
| @@ -404,9 +391,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 9 unmodified lines | ||
| 404 | 391 | ResourceCache* geometryCache = geometryCacheP.data(); |
| 405 | 392 | connect(this, &Application::checkBackgroundDownloads, geometryCache, &ResourceCache::checkAsynchronousGets); |
| 406 | 393 | |
| 407 | − // connect the DataProcessor processDatagrams slot to the QUDPSocket readyRead() signal | |
| 408 | − connect(&nodeList->getNodeSocket(), &QUdpSocket::readyRead, _datagramProcessor, &DatagramProcessor::processDatagrams); | |
| 409 | − | |
| 410 | 394 | // put the audio processing on a separate thread |
| 411 | 395 | QThread* audioThread = new QThread(); |
| 412 | 396 | audioThread->setObjectName("Audio Thread"); |
| @@ -417,14 +401,27 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 4 unmodified lines | ||
| 417 | 401 | audioIO->setOrientationGetter(getOrientationForAudio); |
| 418 | 402 | |
| 419 | 403 | audioIO->moveToThread(audioThread); |
| 404 | + | |
| 405 | + auto& audioScriptingInterface = AudioScriptingInterface::getInstance(); | |
| 406 | + | |
| 420 | 407 | connect(audioThread, &QThread::started, audioIO.data(), &AudioClient::start); |
| 421 | 408 | connect(audioIO.data(), &AudioClient::destroyed, audioThread, &QThread::quit); |
| 422 | 409 | connect(audioThread, &QThread::finished, audioThread, &QThread::deleteLater); |
| 423 | 410 | connect(audioIO.data(), &AudioClient::muteToggled, this, &Application::audioMuteToggled); |
| 424 | − connect(audioIO.data(), &AudioClient::receivedFirstPacket, | |
| 425 | − &AudioScriptingInterface::getInstance(), &AudioScriptingInterface::receivedFirstPacket); | |
| 426 | − connect(audioIO.data(), &AudioClient::disconnected, | |
| 427 | − &AudioScriptingInterface::getInstance(), &AudioScriptingInterface::disconnected); | |
| 411 | + connect(audioIO.data(), &AudioClient::mutedByMixer, &audioScriptingInterface, &AudioScriptingInterface::mutedByMixer); | |
| 412 | + connect(audioIO.data(), &AudioClient::receivedFirstPacket, &audioScriptingInterface, &AudioScriptingInterface::receivedFirstPacket); | |
| 413 | + connect(audioIO.data(), &AudioClient::disconnected, &audioScriptingInterface, &AudioScriptingInterface::disconnected); | |
| 414 | + connect(audioIO.data(), &AudioClient::muteEnvironmentRequested, [](glm::vec3 position, float radius) { | |
| 415 | + auto audioClient = DependencyManager::get<AudioClient>(); | |
| 416 | + float distance = glm::distance(DependencyManager::get<AvatarManager>()->getMyAvatar()->getPosition(), | |
| 417 | + position); | |
| 418 | + bool shouldMute = !audioClient->isMuted() && (distance < radius); | |
| 419 | + | |
| 420 | + if (shouldMute) { | |
| 421 | + audioClient->toggleMute(); | |
| 422 | + AudioScriptingInterface::getInstance().environmentMuted(); | |
| 423 | + } | |
| 424 | + }); | |
| 428 | 425 | |
| 429 | 426 | audioThread->start(); |
| 430 | 427 | |
| @@ -457,7 +454,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 26 unmodified lines | ||
| 457 | 454 | connect(nodeList.data(), &NodeList::uuidChanged, _myAvatar, &MyAvatar::setSessionUUID); |
| 458 | 455 | connect(nodeList.data(), &NodeList::uuidChanged, this, &Application::setSessionUUID); |
| 459 | 456 | connect(nodeList.data(), &NodeList::limitOfSilentDomainCheckInsReached, nodeList.data(), &NodeList::reset); |
| 460 | − connect(nodeList.data(), &NodeList::packetVersionMismatch, this, &Application::notifyPacketVersionMismatch); | |
| 457 | + connect(&nodeList->getPacketReceiver(), &PacketReceiver::packetVersionMismatch, | |
| 458 | + this, &Application::notifyPacketVersionMismatch); | |
| 461 | 459 | |
| 462 | 460 | // connect to appropriate slots on AccountManager |
| 463 | 461 | AccountManager& accountManager = AccountManager::getInstance(); |
| @@ -537,7 +535,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 73 unmodified lines | ||
| 537 | 535 | // the GL surface |
| 538 | 536 | _glWidget->setCursor(Qt::BlankCursor); |
| 539 | 537 | #endif |
| 540 | − | |
| 538 | + | |
| 541 | 539 | // enable mouse tracking; otherwise, we only get drag events |
| 542 | 540 | _glWidget->setMouseTracking(true); |
| 543 | 541 | |
| @@ -571,10 +569,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 27 unmodified lines | ||
| 571 | 569 | |
| 572 | 570 | // hook up bandwidth estimator |
| 573 | 571 | QSharedPointer<BandwidthRecorder> bandwidthRecorder = DependencyManager::get<BandwidthRecorder>(); |
| 574 | − connect(nodeList.data(), SIGNAL(dataSent(const quint8, const int)), | |
| 575 | − bandwidthRecorder.data(), SLOT(updateOutboundData(const quint8, const int))); | |
| 576 | − connect(nodeList.data(), SIGNAL(dataReceived(const quint8, const int)), | |
| 577 | − bandwidthRecorder.data(), SLOT(updateInboundData(const quint8, const int))); | |
| 572 | + connect(nodeList.data(), &LimitedNodeList::dataSent, | |
| 573 | + bandwidthRecorder.data(), &BandwidthRecorder::updateOutboundData); | |
| 574 | + connect(&nodeList->getPacketReceiver(), &PacketReceiver::dataReceived, | |
| 575 | + bandwidthRecorder.data(), &BandwidthRecorder::updateInboundData); | |
| 578 | 576 | |
| 579 | 577 | connect(&_myAvatar->getSkeletonModel(), &SkeletonModel::skeletonLoaded, |
| 580 | 578 | this, &Application::checkSkeleton, Qt::QueuedConnection); |
| @@ -606,7 +604,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 25 unmodified lines | ||
| 606 | 604 | _settingsTimer.setSingleShot(false); |
| 607 | 605 | _settingsTimer.setInterval(SAVE_SETTINGS_INTERVAL); |
| 608 | 606 | _settingsThread.start(); |
| 609 | − | |
| 607 | + | |
| 610 | 608 | if (Menu::getInstance()->isOptionChecked(MenuOption::IndependentMode)) { |
| 611 | 609 | Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, true); |
| 612 | 610 | cameraMenuChanged(); |
| @@ -637,10 +635,16 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 24 unmodified lines | ||
| 637 | 635 | ddeTracker->init(); |
| 638 | 636 | connect(ddeTracker.data(), &FaceTracker::muteToggled, this, &Application::faceTrackerMuteToggled); |
| 639 | 637 | #endif |
| 640 | − | |
| 638 | + | |
| 641 | 639 | auto applicationUpdater = DependencyManager::get<AutoUpdater>(); |
| 642 | 640 | connect(applicationUpdater.data(), &AutoUpdater::newVersionIsAvailable, dialogsManager.data(), &DialogsManager::showUpdateDialog); |
| 643 | 641 | applicationUpdater->checkForUpdate(); |
| 642 | + | |
| 643 | + // the 3Dconnexion device wants to be initiliazed after a window is displayed. | |
| 644 | + ConnexionClient::init(); | |
| 645 | + | |
| 646 | + auto& packetReceiver = nodeList->getPacketReceiver(); | |
| 647 | + packetReceiver.registerListener(PacketType::DomainConnectionDenied, this, "handleDomainConnectionDeniedPacket"); | |
| 644 | 648 | } |
| 645 | 649 | |
| 646 | 650 | void Application::aboutToQuit() { |
| @@ -653,8 +657,10 @@ void Application::aboutToQuit() { · 6 unmodified lines | ||
| 653 | 657 | void Application::cleanupBeforeQuit() { |
| 654 | 658 | |
| 655 | 659 | _entities.clear(); // this will allow entity scripts to properly shutdown |
| 656 | − | |
| 657 | − _datagramProcessor->shutdown(); // tell the datagram processor we're shutting down, so it can short circuit | |
| 660 | + | |
| 661 | + // tell the packet receiver we're shutting down, so it can drop packets | |
| 662 | + DependencyManager::get<NodeList>()->getPacketReceiver().setShouldDropPackets(true); | |
| 663 | + | |
| 658 | 664 | _entities.shutdown(); // tell the entities system we're shutting down, so it will stop running scripts |
| 659 | 665 | ScriptEngine::stopAllScripts(this); // stop all currently running global scripts |
| 660 | 666 | |
| @@ -731,12 +737,15 @@ Application::~Application() { · 70 unmodified lines | ||
| 731 | 737 | DependencyManager::destroy<OffscreenUi>(); |
| 732 | 738 | DependencyManager::destroy<AvatarManager>(); |
| 733 | 739 | DependencyManager::destroy<AnimationCache>(); |
| 740 | + DependencyManager::destroy<FramebufferCache>(); | |
| 734 | 741 | DependencyManager::destroy<TextureCache>(); |
| 735 | 742 | DependencyManager::destroy<GeometryCache>(); |
| 736 | 743 | DependencyManager::destroy<ScriptCache>(); |
| 737 | 744 | DependencyManager::destroy<SoundCache>(); |
| 738 | 745 | |
| 739 | 746 | QThread* nodeThread = DependencyManager::get<NodeList>()->thread(); |
| 747 | + | |
| 748 | + // remove the NodeList from the DependencyManager | |
| 740 | 749 | DependencyManager::destroy<NodeList>(); |
| 741 | 750 | |
| 742 | 751 | // ask the node thread to quit and wait until it is done |
| @@ -745,6 +754,7 @@ Application::~Application() { · 2 unmodified lines | ||
| 745 | 754 | |
| 746 | 755 | Leapmotion::destroy(); |
| 747 | 756 | RealSense::destroy(); |
| 757 | + ConnexionClient::destroy(); | |
| 748 | 758 | |
| 749 | 759 | qInstallMessageHandler(NULL); // NOTE: Do this as late as possible so we continue to get our log messages |
| 750 | 760 | } |
| @@ -762,32 +772,9 @@ void Application::initializeGL() { · 11 unmodified lines | ||
| 762 | 772 | } |
| 763 | 773 | #endif |
| 764 | 774 | |
| 765 | − qCDebug(interfaceapp) << "GL Version: " << QString((const char*) glGetString(GL_VERSION)); | |
| 766 | − qCDebug(interfaceapp) << "GL Shader Language Version: " << QString((const char*) glGetString(GL_SHADING_LANGUAGE_VERSION)); | |
| 767 | − qCDebug(interfaceapp) << "GL Vendor: " << QString((const char*) glGetString(GL_VENDOR)); | |
| 768 | − qCDebug(interfaceapp) << "GL Renderer: " << QString((const char*) glGetString(GL_RENDERER)); | |
| 769 | − | |
| 770 | − #ifdef WIN32 | |
| 771 | − GLenum err = glewInit(); | |
| 772 | − if (GLEW_OK != err) { | |
| 773 | − /* Problem: glewInit failed, something is seriously wrong. */ | |
| 774 | − qCDebug(interfaceapp, "Error: %s\n", glewGetErrorString(err)); | |
| 775 | − } | |
| 776 | − qCDebug(interfaceapp, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); | |
| 777 | − | |
| 778 | − if (wglewGetExtension("WGL_EXT_swap_control")) { | |
| 779 | − int swapInterval = wglGetSwapIntervalEXT(); | |
| 780 | − qCDebug(interfaceapp, "V-Sync is %s\n", (swapInterval > 0 ? "ON" : "OFF")); | |
| 781 | − } | |
| 782 | − #endif | |
| 783 | − | |
| 784 | −#if defined(Q_OS_LINUX) | |
| 785 | − // TODO: Write the correct code for Linux... | |
| 786 | − /* if (wglewGetExtension("WGL_EXT_swap_control")) { | |
| 787 | − int swapInterval = wglGetSwapIntervalEXT(); | |
| 788 | − qCDebug(interfaceapp, "V-Sync is %s\n", (swapInterval > 0 ? "ON" : "OFF")); | |
| 789 | − }*/ | |
| 790 | −#endif | |
| 775 | + // Where the gpuContext is initialized and where the TRUE Backend is created and assigned | |
| 776 | + gpu::Context::init<gpu::GLBackend>(); | |
| 777 | + _gpuContext = std::make_shared<gpu::Context>(); | |
| 791 | 778 | |
| 792 | 779 | initDisplay(); |
| 793 | 780 | qCDebug(interfaceapp, "Initialized Display."); |
| @@ -876,8 +863,9 @@ void Application::paintGL() { · 82 unmodified lines | ||
| 876 | 863 | _glWidget->makeCurrent(); |
| 877 | 864 | |
| 878 | 865 | auto lodManager = DependencyManager::get<LODManager>(); |
| 879 | − gpu::Context context(new gpu::GLBackend()); | |
| 880 | − RenderArgs renderArgs(&context, nullptr, getViewFrustum(), lodManager->getOctreeSizeScale(), | |
| 866 | + | |
| 867 | + | |
| 868 | + RenderArgs renderArgs(_gpuContext, nullptr, getViewFrustum(), lodManager->getOctreeSizeScale(), | |
| 881 | 869 | lodManager->getBoundaryLevelAdjust(), RenderArgs::DEFAULT_RENDER_MODE, |
| 882 | 870 | RenderArgs::MONO, RenderArgs::RENDER_DEBUG_NONE); |
| 883 | 871 | |
| @@ -887,25 +875,56 @@ void Application::paintGL() { · 3 unmodified lines | ||
| 887 | 875 | OculusManager::beginFrameTiming(); |
| 888 | 876 | } |
| 889 | 877 | |
| 890 | − | |
| 878 | + | |
| 891 | 879 | PerformanceWarning::setSuppressShortTimings(Menu::getInstance()->isOptionChecked(MenuOption::SuppressShortTimings)); |
| 892 | 880 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); |
| 893 | 881 | PerformanceWarning warn(showWarnings, "Application::paintGL()"); |
| 894 | 882 | resizeGL(); |
| 895 | 883 | |
| 884 | + // Before anything else, let's sync up the gpuContext with the true glcontext used in case anything happened | |
| 885 | + renderArgs._context->syncCache(); | |
| 886 | + | |
| 887 | + if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) { | |
| 888 | + auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferDepthColor(); | |
| 889 | + | |
| 890 | + renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE; | |
| 891 | + renderRearViewMirror(&renderArgs, _mirrorViewRect); | |
| 892 | + renderArgs._renderMode = RenderArgs::DEFAULT_RENDER_MODE; | |
| 893 | + | |
| 894 | + { | |
| 895 | + float ratio = ((float)QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale()); | |
| 896 | + auto mirrorViewport = glm::ivec4(0, 0, _mirrorViewRect.width() * ratio, _mirrorViewRect.height() * ratio); | |
| 897 | + auto mirrorViewportDest = mirrorViewport; | |
| 898 | + | |
| 899 | + auto selfieFbo = DependencyManager::get<FramebufferCache>()->getSelfieFramebuffer(); | |
| 900 | + gpu::Batch batch; | |
| 901 | + batch.setFramebuffer(selfieFbo); | |
| 902 | + batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0f, 0.0f, 0.0f, 0.0f)); | |
| 903 | + batch.blit(primaryFbo, mirrorViewport, selfieFbo, mirrorViewportDest); | |
| 904 | + batch.setFramebuffer(nullptr); | |
| 905 | + renderArgs._context->render(batch); | |
| 906 | + } | |
| 907 | + } | |
| 908 | + | |
| 896 | 909 | { |
| 897 | 910 | PerformanceTimer perfTimer("renderOverlay"); |
| 911 | + | |
| 912 | + // NOTE: There is no batch associated with this renderArgs | |
| 913 | + // the ApplicationOverlay class assumes it's viewport is setup to be the device size | |
| 914 | + QSize size = qApp->getDeviceSize(); | |
| 915 | + renderArgs._viewport = glm::ivec4(0, 0, size.width(), size.height()); | |
| 898 | 916 | _applicationOverlay.renderOverlay(&renderArgs); |
| 899 | 917 | } |
| 900 | 918 | |
| 901 | − glEnable(GL_LINE_SMOOTH); | |
| 902 | − | |
| 903 | 919 | if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON || _myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) { |
| 904 | 920 | Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, _myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN); |
| 905 | 921 | Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, !(_myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN)); |
| 906 | 922 | Application::getInstance()->cameraMenuChanged(); |
| 907 | 923 | } |
| 908 | 924 | |
| 925 | + // The render mode is default or mirror if the camera is in mirror mode, assigned further below | |
| 926 | + renderArgs._renderMode = RenderArgs::DEFAULT_RENDER_MODE; | |
| 927 | + | |
| 909 | 928 | if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) { |
| 910 | 929 | // Always use the default eye position, not the actual head eye position. |
| 911 | 930 | // Using the latter will cause the camera to wobble with idle animations, |
| @@ -942,6 +961,7 @@ void Application::paintGL() { · 30 unmodified lines | ||
| 942 | 961 | glm::vec3(0, _raiseMirror * _myAvatar->getScale(), 0) + |
| 943 | 962 | (_myAvatar->getOrientation() * glm::quat(glm::vec3(0.0f, _rotateMirror, 0.0f))) * |
| 944 | 963 | glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_FULLSCREEN_DISTANCE * _scaleMirror); |
| 964 | + renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE; | |
| 945 | 965 | } |
| 946 | 966 | |
| 947 | 967 | // Update camera position |
| @@ -949,17 +969,6 @@ void Application::paintGL() { · 1 unmodified line | ||
| 949 | 969 | _myCamera.update(1.0f / _fps); |
| 950 | 970 | } |
| 951 | 971 | |
| 952 | − // Sync up the View Furstum with the camera | |
| 953 | − // FIXME: it's happening again in the updateSHadow and it shouldn't, this should be the place | |
| 954 | − loadViewFrustum(_myCamera, _viewFrustum); | |
| 955 | − | |
| 956 | − if (getShadowsEnabled()) { | |
| 957 | − renderArgs._renderMode = RenderArgs::SHADOW_RENDER_MODE; | |
| 958 | − updateShadowMap(&renderArgs); | |
| 959 | − } | |
| 960 | − | |
| 961 | − renderArgs._renderMode = RenderArgs::DEFAULT_RENDER_MODE; | |
| 962 | − | |
| 963 | 972 | if (OculusManager::isConnected()) { |
| 964 | 973 | //When in mirror mode, use camera rotation. Otherwise, use body rotation |
| 965 | 974 | if (_myCamera.getMode() == CAMERA_MODE_MIRROR) { |
| @@ -971,40 +980,24 @@ void Application::paintGL() { · 5 unmodified lines | ||
| 971 | 980 | TV3DManager::display(&renderArgs, _myCamera); |
| 972 | 981 | } else { |
| 973 | 982 | PROFILE_RANGE(__FUNCTION__ "/mainRender"); |
| 974 | − | |
| 975 | − auto primaryFBO = DependencyManager::get<TextureCache>()->getPrimaryFramebuffer(); | |
| 976 | − GLuint fbo = gpu::GLBackend::getFramebufferID(primaryFBO); | |
| 977 | − glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); | |
| 978 | − glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
| 979 | − | |
| 980 | 983 | // Viewport is assigned to the size of the framebuffer |
| 981 | − QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize(); | |
| 982 | − glViewport(0, 0, size.width(), size.height()); | |
| 984 | + QSize size = DependencyManager::get<FramebufferCache>()->getFrameBufferSize(); | |
| 983 | 985 | renderArgs._viewport = glm::ivec4(0, 0, size.width(), size.height()); |
| 984 | − | |
| 985 | − glMatrixMode(GL_MODELVIEW); | |
| 986 | − glPushMatrix(); | |
| 987 | − glLoadIdentity(); | |
| 988 | − displaySide(&renderArgs, _myCamera); | |
| 989 | − glPopMatrix(); | |
| 990 | 986 | |
| 991 | − renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE; | |
| 992 | − if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) { | |
| 993 | − renderRearViewMirror(&renderArgs, _mirrorViewRect); | |
| 994 | − } | |
| 995 | 987 | |
| 996 | − renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE; | |
| 988 | + displaySide(&renderArgs, _myCamera); | |
| 997 | 989 | |
| 998 | − auto finalFbo = DependencyManager::get<TextureCache>()->getPrimaryFramebuffer(); | |
| 990 | + { | |
| 991 | + auto geometryCache = DependencyManager::get<GeometryCache>(); | |
| 992 | + auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferDepthColor(); | |
| 993 | + gpu::Batch batch; | |
| 994 | + batch.blit(primaryFbo, glm::ivec4(0, 0, _renderResolution.x, _renderResolution.y), | |
| 995 | + nullptr, glm::ivec4(0, 0, _glWidget->getDeviceSize().width(), _glWidget->getDeviceSize().height())); | |
| 999 | 996 | |
| 1000 | − glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); | |
| 1001 | − glBindFramebuffer(GL_READ_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(finalFbo)); | |
| 1002 | − glBlitFramebuffer(0, 0, _renderResolution.x, _renderResolution.y, | |
| 1003 | − 0, 0, _glWidget->getDeviceSize().width(), _glWidget->getDeviceSize().height(), | |
| 1004 | − GL_COLOR_BUFFER_BIT, GL_LINEAR); | |
| 1005 | − glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); | |
| 1006 | − | |
| 1007 | − glBindTexture(GL_TEXTURE_2D, 0); // ??? | |
| 997 | + batch.setFramebuffer(nullptr); | |
| 998 | + | |
| 999 | + renderArgs._context->render(batch); | |
| 1000 | + } | |
| 1008 | 1001 | |
| 1009 | 1002 | _compositor.displayOverlayTexture(&renderArgs); |
| 1010 | 1003 | } |
| @@ -1019,7 +1012,15 @@ void Application::paintGL() { · 8 unmodified lines | ||
| 1019 | 1012 | OculusManager::endFrameTiming(); |
| 1020 | 1013 | } |
| 1021 | 1014 | _frameCount++; |
| 1015 | + _numFramesSinceLastResize++; | |
| 1022 | 1016 | Stats::getInstance()->setRenderDetails(renderArgs._details); |
| 1017 | + | |
| 1018 | + | |
| 1019 | + // Reset the gpu::Context Stages | |
| 1020 | + // Back to the default framebuffer; | |
| 1021 | + gpu::Batch batch; | |
| 1022 | + batch.resetStages(); | |
| 1023 | + renderArgs._context->render(batch); | |
| 1023 | 1024 | } |
| 1024 | 1025 | |
| 1025 | 1026 | void Application::runTests() { |
| @@ -1072,13 +1073,11 @@ void Application::resizeGL() { · 46 unmodified lines | ||
| 1072 | 1073 | } |
| 1073 | 1074 | |
| 1074 | 1075 | if (_renderResolution != toGlm(renderSize)) { |
| 1076 | + _numFramesSinceLastResize = 0; | |
| 1075 | 1077 | _renderResolution = toGlm(renderSize); |
| 1076 | − DependencyManager::get<TextureCache>()->setFrameBufferSize(renderSize); | |
| 1078 | + DependencyManager::get<FramebufferCache>()->setFrameBufferSize(renderSize); | |
| 1077 | 1079 | |
| 1078 | − glViewport(0, 0, _renderResolution.x, _renderResolution.y); // shouldn't this account for the menu??? | |
| 1079 | − | |
| 1080 | − updateProjectionMatrix(); | |
| 1081 | − glLoadIdentity(); | |
| 1080 | + loadViewFrustum(_myCamera, _viewFrustum); | |
| 1082 | 1081 | } |
| 1083 | 1082 | |
| 1084 | 1083 | resetCameras(_myCamera, _renderResolution); |
| @@ -1088,32 +1087,6 @@ void Application::resizeGL() { · 3 unmodified lines | ||
| 1088 | 1087 | auto canvasSize = _glWidget->size(); |
| 1089 | 1088 | offscreenUi->resize(canvasSize); |
| 1090 | 1089 | _glWidget->makeCurrent(); |
| 1091 | − | |
| 1092 | −} | |
| 1093 | − | |
| 1094 | −void Application::updateProjectionMatrix() { | |
| 1095 | − updateProjectionMatrix(_myCamera); | |
| 1096 | −} | |
| 1097 | − | |
| 1098 | −void Application::updateProjectionMatrix(Camera& camera, bool updateViewFrustum) { | |
| 1099 | − _projectionMatrix = camera.getProjection(); | |
| 1100 | − | |
| 1101 | − glMatrixMode(GL_PROJECTION); | |
| 1102 | − glLoadMatrixf(glm::value_ptr(_projectionMatrix)); | |
| 1103 | − | |
| 1104 | − // Tell our viewFrustum about this change, using the application camera | |
| 1105 | − if (updateViewFrustum) { | |
| 1106 | − loadViewFrustum(camera, _viewFrustum); | |
| 1107 | − } | |
| 1108 | − | |
| 1109 | − glMatrixMode(GL_MODELVIEW); | |
| 1110 | −} | |
| 1111 | − | |
| 1112 | −void Application::controlledBroadcastToNodes(const QByteArray& packet, const NodeSet& destinationNodeTypes) { | |
| 1113 | − foreach(NodeType_t type, destinationNodeTypes) { | |
| 1114 | − // Perform the broadcast for one type | |
| 1115 | − DependencyManager::get<NodeList>()->broadcastToNodes(packet, NodeSet() << type); | |
| 1116 | − } | |
| 1117 | 1090 | } |
| 1118 | 1091 | |
| 1119 | 1092 | bool Application::importSVOFromURL(const QString& urlString) { |
| @@ -1262,12 +1235,6 @@ void Application::keyPressEvent(QKeyEvent* event) { · 142 unmodified lines | ||
| 1262 | 1235 | Menu::getInstance()->triggerOption(MenuOption::Stars); |
| 1263 | 1236 | break; |
| 1264 | 1237 | |
| 1265 | − case Qt::Key_W: | |
| 1266 | − if (isOption && !isShifted && !isMeta) { | |
| 1267 | − Menu::getInstance()->triggerOption(MenuOption::Wireframe); | |
| 1268 | − } | |
| 1269 | − break; | |
| 1270 | − | |
| 1271 | 1238 | case Qt::Key_S: |
| 1272 | 1239 | if (isShifted && isMeta && !isOption) { |
| 1273 | 1240 | Menu::getInstance()->triggerOption(MenuOption::SuppressShortTimings); |
| @@ -1527,6 +1494,7 @@ void Application::focusOutEvent(QFocusEvent* event) { · 253 unmodified lines | ||
| 1527 | 1494 | _keyboardMouseDevice.focusOutEvent(event); |
| 1528 | 1495 | SixenseManager::getInstance().focusOutEvent(); |
| 1529 | 1496 | SDL2Manager::getInstance()->focusOutEvent(); |
| 1497 | + ConnexionData::getInstance().focusOutEvent(); | |
| 1530 | 1498 | |
| 1531 | 1499 | // synthesize events for keys currently pressed, since we may not get their release events |
| 1532 | 1500 | foreach (int key, _keysPressed) { |
| @@ -1568,7 +1536,9 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { · 35 unmodified lines | ||
| 1568 | 1536 | return; |
| 1569 | 1537 | } |
| 1570 | 1538 | |
| 1571 | − _keyboardMouseDevice.mouseMoveEvent(event, deviceID); | |
| 1539 | + if (deviceID == 0) { | |
| 1540 | + _keyboardMouseDevice.mouseMoveEvent(event, deviceID); | |
| 1541 | + } | |
| 1572 | 1542 | |
| 1573 | 1543 | } |
| 1574 | 1544 | |
| @@ -1589,7 +1559,9 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { · 14 unmodified lines | ||
| 1589 | 1559 | |
| 1590 | 1560 | |
| 1591 | 1561 | if (activeWindow() == _window) { |
| 1592 | − _keyboardMouseDevice.mousePressEvent(event); | |
| 1562 | + if (deviceID == 0) { | |
| 1563 | + _keyboardMouseDevice.mousePressEvent(event); | |
| 1564 | + } | |
| 1593 | 1565 | |
| 1594 | 1566 | if (event->button() == Qt::LeftButton) { |
| 1595 | 1567 | _mouseDragStarted = getTrueMouse(); |
| @@ -1629,7 +1601,9 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { · 33 unmodified lines | ||
| 1629 | 1601 | } |
| 1630 | 1602 | |
| 1631 | 1603 | if (activeWindow() == _window) { |
| 1632 | − _keyboardMouseDevice.mouseReleaseEvent(event); | |
| 1604 | + if (deviceID == 0) { | |
| 1605 | + _keyboardMouseDevice.mouseReleaseEvent(event); | |
| 1606 | + } | |
| 1633 | 1607 | |
| 1634 | 1608 | if (event->button() == Qt::LeftButton) { |
| 1635 | 1609 | _mousePressed = false; |
| @@ -1775,10 +1749,21 @@ bool Application::acceptSnapshot(const QString& urlString) { · 139 unmodified lines | ||
| 1775 | 1749 | } |
| 1776 | 1750 | |
| 1777 | 1751 | void Application::sendPingPackets() { |
| 1778 | − QByteArray pingPacket = DependencyManager::get<NodeList>()->constructPingPacket(); | |
| 1779 | − controlledBroadcastToNodes(pingPacket, NodeSet() | |
| 1780 | − << NodeType::EntityServer | |
| 1781 | − << NodeType::AudioMixer << NodeType::AvatarMixer); | |
| 1752 | + | |
| 1753 | + auto nodeList = DependencyManager::get<NodeList>(); | |
| 1754 | + | |
| 1755 | + nodeList->eachMatchingNode([](const SharedNodePointer& node)->bool { | |
| 1756 | + switch (node->getType()) { | |
| 1757 | + case NodeType::AvatarMixer: | |
| 1758 | + case NodeType::AudioMixer: | |
| 1759 | + case NodeType::EntityServer: | |
| 1760 | + return true; | |
| 1761 | + default: | |
| 1762 | + return false; | |
| 1763 | + } | |
| 1764 | + }, [nodeList](const SharedNodePointer& node) { | |
| 1765 | + nodeList->sendPacket(nodeList->constructPingPacket(), *node); | |
| 1766 | + }); | |
| 1782 | 1767 | } |
| 1783 | 1768 | |
| 1784 | 1769 | // Every second, check the frame rates and other stuff |
| @@ -1791,7 +1776,6 @@ void Application::checkFPS() { · 6 unmodified lines | ||
| 1791 | 1776 | |
| 1792 | 1777 | _fps = (float)_frameCount / diffTime; |
| 1793 | 1778 | _frameCount = 0; |
| 1794 | − _datagramProcessor->resetCounters(); | |
| 1795 | 1779 | _timerStart.start(); |
| 1796 | 1780 | } |
| 1797 | 1781 | |
| @@ -1857,11 +1841,15 @@ void Application::idle() { · 59 unmodified lines | ||
| 1857 | 1841 | _idleLoopMeasuredJitter = _idleLoopStdev.getStDev(); |
| 1858 | 1842 | _idleLoopStdev.reset(); |
| 1859 | 1843 | } |
| 1860 | − | |
| 1861 | 1844 | } |
| 1845 | + | |
| 1862 | 1846 | // After finishing all of the above work, ensure the idle timer is set to the proper interval, |
| 1863 | − // depending on whether we're throttling or not | |
| 1864 | − idleTimer->start(_glWidget->isThrottleRendering() ? THROTTLED_IDLE_TIMER_DELAY : 1); | |
| 1847 | + // depending on whether we're throttling or not. | |
| 1848 | + // Once rendering is off on another thread we should be able to have Application::idle run at start(0) in | |
| 1849 | + // perpetuity and not expect events to get backed up. | |
| 1850 | + | |
| 1851 | + static const int IDLE_TIMER_DELAY_MS = 2; | |
| 1852 | + idleTimer->start(_glWidget->isThrottleRendering() ? THROTTLED_IDLE_TIMER_DELAY : IDLE_TIMER_DELAY_MS); | |
| 1865 | 1853 | } |
| 1866 | 1854 | |
| 1867 | 1855 | // check for any requested background downloads. |
| @@ -1944,7 +1932,6 @@ void Application::setEnableVRMode(bool enableVRMode) { · 76 unmodified lines | ||
| 1944 | 1932 | OculusManager::connect(_glWidget->context()->contextHandle()); |
| 1945 | 1933 | _glWidget->setFocus(); |
| 1946 | 1934 | _glWidget->makeCurrent(); |
| 1947 | − glClear(GL_COLOR_BUFFER_BIT); | |
| 1948 | 1935 | } |
| 1949 | 1936 | OculusManager::recalibrate(); |
| 1950 | 1937 | } else { |
| @@ -2035,13 +2022,6 @@ void Application::setActiveFaceTracker() { · 84 unmodified lines | ||
| 2035 | 2022 | #endif |
| 2036 | 2023 | } |
| 2037 | 2024 | |
| 2038 | −void Application::toggleFaceTrackerMute() { | |
| 2039 | − FaceTracker* faceTracker = getSelectedFaceTracker(); | |
| 2040 | − if (faceTracker) { | |
| 2041 | − faceTracker->toggleMute(); | |
| 2042 | − } | |
| 2043 | −} | |
| 2044 | − | |
| 2045 | 2025 | bool Application::exportEntities(const QString& filename, const QVector<EntityItemID>& entityIDs) { |
| 2046 | 2026 | QVector<EntityItemPointer> entities; |
| 2047 | 2027 | |
| @@ -2147,12 +2127,6 @@ QVector<EntityItemID> Application::pasteEntities(float x, float y, float z) { · 99 unmodified lines | ||
| 2147 | 2127 | } |
| 2148 | 2128 | |
| 2149 | 2129 | void Application::initDisplay() { |
| 2150 | − glEnable(GL_BLEND); | |
| 2151 | − glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE); | |
| 2152 | − glShadeModel(GL_SMOOTH); | |
| 2153 | − glEnable(GL_LIGHTING); | |
| 2154 | − glEnable(GL_LIGHT0); | |
| 2155 | − glEnable(GL_DEPTH_TEST); | |
| 2156 | 2130 | } |
| 2157 | 2131 | |
| 2158 | 2132 | void Application::init() { |
| @@ -2162,7 +2136,6 @@ void Application::init() { · 3 unmodified lines | ||
| 2162 | 2136 | _environment.init(); |
| 2163 | 2137 | |
| 2164 | 2138 | DependencyManager::get<DeferredLightingEffect>()->init(this); |
| 2165 | − DependencyManager::get<AmbientOcclusionEffect>()->init(this); | |
| 2166 | 2139 | |
| 2167 | 2140 | // TODO: move _myAvatar out of Application. Move relevant code to MyAvataar or AvatarManager |
| 2168 | 2141 | DependencyManager::get<AvatarManager>()->init(); |
| @@ -2258,8 +2231,8 @@ void Application::shrinkMirrorView() { · 89 unmodified lines | ||
| 2258 | 2231 | |
| 2259 | 2232 | const float HEAD_SPHERE_RADIUS = 0.1f; |
| 2260 | 2233 | |
| 2261 | −bool Application::isLookingAtMyAvatar(Avatar* avatar) { | |
| 2262 | − glm::vec3 theirLookAt = avatar->getHead()->getLookAtPosition(); | |
| 2234 | +bool Application::isLookingAtMyAvatar(AvatarSharedPointer avatar) { | |
| 2235 | + glm::vec3 theirLookAt = dynamic_pointer_cast<Avatar>(avatar)->getHead()->getLookAtPosition(); | |
| 2263 | 2236 | glm::vec3 myEyePosition = _myAvatar->getHead()->getEyePosition(); |
| 2264 | 2237 | if (pointInSphere(theirLookAt, myEyePosition, HEAD_SPHERE_RADIUS * _myAvatar->getScale())) { |
| 2265 | 2238 | return true; |
| @@ -2323,7 +2296,7 @@ void Application::updateMyAvatarLookAtPosition() { · 57 unmodified lines | ||
| 2323 | 2296 | if (lookingAt && _myAvatar != lookingAt.get()) { |
| 2324 | 2297 | // If I am looking at someone else, look directly at one of their eyes |
| 2325 | 2298 | isLookingAtSomeone = true; |
| 2326 | − Head* lookingAtHead = static_cast<Avatar*>(lookingAt.get())->getHead(); | |
| 2299 | + auto lookingAtHead = static_pointer_cast<Avatar>(lookingAt)->getHead(); | |
| 2327 | 2300 | |
| 2328 | 2301 | const float MAXIMUM_FACE_ANGLE = 65.0f * RADIANS_PER_DEGREE; |
| 2329 | 2302 | glm::vec3 lookingAtFaceOrientation = lookingAtHead->getFinalOrientationInWorldFrame() * IDENTITY_FRONT; |
| @@ -2353,23 +2326,21 @@ void Application::updateMyAvatarLookAtPosition() { · 23 unmodified lines | ||
| 2353 | 2326 | lookAtSpot = _myAvatar->getHead()->getEyePosition() + |
| 2354 | 2327 | (_myAvatar->getHead()->getFinalOrientationInWorldFrame() * glm::vec3(0.0f, 0.0f, -TREE_SCALE)); |
| 2355 | 2328 | } |
| 2356 | − } | |
| 2357 | 2329 | |
| 2358 | − // Deflect the eyes a bit to match the detected gaze from Faceshift if active. | |
| 2359 | − // DDE doesn't track eyes. | |
| 2360 | − if (tracker && typeid(*tracker) == typeid(Faceshift) && !tracker->isMuted()) { | |
| 2361 | − float eyePitch = tracker->getEstimatedEyePitch(); | |
| 2362 | − float eyeYaw = tracker->getEstimatedEyeYaw(); | |
| 2363 | − const float GAZE_DEFLECTION_REDUCTION_DURING_EYE_CONTACT = 0.1f; | |
| 2364 | − glm::vec3 origin = _myAvatar->getHead()->getEyePosition(); | |
| 2365 | − float pitchSign = (_myCamera.getMode() == CAMERA_MODE_MIRROR) ? -1.0f : 1.0f; | |
| 2366 | − float deflection = DependencyManager::get<Faceshift>()->getEyeDeflection(); | |
| 2367 | − if (isLookingAtSomeone) { | |
| 2368 | − deflection *= GAZE_DEFLECTION_REDUCTION_DURING_EYE_CONTACT; | |
| 2369 | − } | |
| 2370 | − lookAtSpot = origin + _myCamera.getRotation() * glm::quat(glm::radians(glm::vec3( | |
| 2371 | − eyePitch * pitchSign * deflection, eyeYaw * deflection, 0.0f))) * | |
| 2330 | + // Deflect the eyes a bit to match the detected gaze from the face tracker if active. | |
| 2331 | + if (tracker && !tracker->isMuted()) { | |
| 2332 | + float eyePitch = tracker->getEstimatedEyePitch(); | |
| 2333 | + float eyeYaw = tracker->getEstimatedEyeYaw(); | |
| 2334 | + const float GAZE_DEFLECTION_REDUCTION_DURING_EYE_CONTACT = 0.1f; | |
| 2335 | + glm::vec3 origin = _myAvatar->getHead()->getEyePosition(); | |
| 2336 | + float deflection = tracker->getEyeDeflection(); | |
| 2337 | + if (isLookingAtSomeone) { | |
| 2338 | + deflection *= GAZE_DEFLECTION_REDUCTION_DURING_EYE_CONTACT; | |
| 2339 | + } | |
| 2340 | + lookAtSpot = origin + _myCamera.getRotation() * glm::quat(glm::radians(glm::vec3( | |
| 2341 | + eyePitch * deflection, eyeYaw * deflection, 0.0f))) * | |
| 2372 | 2342 | glm::inverse(_myCamera.getRotation()) * (lookAtSpot - origin); |
| 2343 | + } | |
| 2373 | 2344 | } |
| 2374 | 2345 | |
| 2375 | 2346 | _myAvatar->getHead()->setLookAtPosition(lookAtSpot); |
| @@ -2438,6 +2409,12 @@ void Application::updateDialogs(float deltaTime) { · 62 unmodified lines | ||
| 2438 | 2409 | PerformanceWarning warn(showWarnings, "Application::updateDialogs()"); |
| 2439 | 2410 | auto dialogsManager = DependencyManager::get<DialogsManager>(); |
| 2440 | 2411 | |
| 2412 | + // Update audio stats dialog, if any | |
| 2413 | + AudioStatsDialog* audioStatsDialog = dialogsManager->getAudioStatsDialog(); | |
| 2414 | + if(audioStatsDialog) { | |
| 2415 | + audioStatsDialog->update(); | |
| 2416 | + } | |
| 2417 | + | |
| 2441 | 2418 | // Update bandwidth dialog, if any |
| 2442 | 2419 | BandwidthDialog* bandwidthDialog = dialogsManager->getBandwidthDialog(); |
| 2443 | 2420 | if (bandwidthDialog) { |
| @@ -2474,7 +2451,13 @@ void Application::update(float deltaTime) { · 30 unmodified lines | ||
| 2474 | 2451 | { |
| 2475 | 2452 | PerformanceTimer perfTimer("devices"); |
| 2476 | 2453 | DeviceTracker::updateAll(); |
| 2477 | − FaceTracker* tracker = getActiveFaceTracker(); | |
| 2454 | + | |
| 2455 | + FaceTracker* tracker = getSelectedFaceTracker(); | |
| 2456 | + if (tracker && Menu::getInstance()->isOptionChecked(MenuOption::MuteFaceTracking) != tracker->isMuted()) { | |
| 2457 | + tracker->toggleMute(); | |
| 2458 | + } | |
| 2459 | + | |
| 2460 | + tracker = getActiveFaceTracker(); | |
| 2478 | 2461 | if (tracker && !tracker->isMuted()) { |
| 2479 | 2462 | tracker->update(deltaTime); |
| 2480 | 2463 | |
| @@ -2518,10 +2501,18 @@ void Application::update(float deltaTime) { · 37 unmodified lines | ||
| 2518 | 2501 | _myAvatar->setDriveKeys(DOWN, _userInputMapper.getActionState(UserInputMapper::VERTICAL_DOWN)); |
| 2519 | 2502 | _myAvatar->setDriveKeys(LEFT, _userInputMapper.getActionState(UserInputMapper::LATERAL_LEFT)); |
| 2520 | 2503 | _myAvatar->setDriveKeys(RIGHT, _userInputMapper.getActionState(UserInputMapper::LATERAL_RIGHT)); |
| 2521 | − _myAvatar->setDriveKeys(ROT_UP, _userInputMapper.getActionState(UserInputMapper::PITCH_UP)); | |
| 2522 | − _myAvatar->setDriveKeys(ROT_DOWN, _userInputMapper.getActionState(UserInputMapper::PITCH_DOWN)); | |
| 2523 | − _myAvatar->setDriveKeys(ROT_LEFT, _userInputMapper.getActionState(UserInputMapper::YAW_LEFT)); | |
| 2524 | − _myAvatar->setDriveKeys(ROT_RIGHT, _userInputMapper.getActionState(UserInputMapper::YAW_RIGHT)); | |
| 2504 | + if (deltaTime > FLT_EPSILON) { | |
| 2505 | + // For rotations what we really want are meausures of "angles per second" (in order to prevent | |
| 2506 | + // fps-dependent spin rates) so we need to scale the units of the controller contribution. | |
| 2507 | + // (TODO?: maybe we should similarly scale ALL action state info, or change the expected behavior | |
| 2508 | + // controllers to provide a delta_per_second value rather than a raw delta.) | |
| 2509 | + const float EXPECTED_FRAME_RATE = 60.0f; | |
| 2510 | + float timeFactor = EXPECTED_FRAME_RATE * deltaTime; | |
| 2511 | + _myAvatar->setDriveKeys(ROT_UP, _userInputMapper.getActionState(UserInputMapper::PITCH_UP) / timeFactor); | |
| 2512 | + _myAvatar->setDriveKeys(ROT_DOWN, _userInputMapper.getActionState(UserInputMapper::PITCH_DOWN) / timeFactor); | |
| 2513 | + _myAvatar->setDriveKeys(ROT_LEFT, _userInputMapper.getActionState(UserInputMapper::YAW_LEFT) / timeFactor); | |
| 2514 | + _myAvatar->setDriveKeys(ROT_RIGHT, _userInputMapper.getActionState(UserInputMapper::YAW_RIGHT) / timeFactor); | |
| 2515 | + } | |
| 2525 | 2516 | } |
| 2526 | 2517 | _myAvatar->setDriveKeys(BOOM_IN, _userInputMapper.getActionState(UserInputMapper::BOOM_IN)); |
| 2527 | 2518 | _myAvatar->setDriveKeys(BOOM_OUT, _userInputMapper.getActionState(UserInputMapper::BOOM_OUT)); |
| @@ -2642,7 +2633,7 @@ void Application::update(float deltaTime) { · 114 unmodified lines | ||
| 2642 | 2633 | _lastQueriedTime = now; |
| 2643 | 2634 | |
| 2644 | 2635 | if (DependencyManager::get<SceneScriptingInterface>()->shouldRenderEntities()) { |
| 2645 | − queryOctree(NodeType::EntityServer, PacketTypeEntityQuery, _entityServerJurisdictions); | |
| 2636 | + queryOctree(NodeType::EntityServer, PacketType::EntityQuery, _entityServerJurisdictions); | |
| 2646 | 2637 | } |
| 2647 | 2638 | _lastQueriedViewFrustum = _viewFrustum; |
| 2648 | 2639 | } |
| @@ -2675,16 +2666,17 @@ int Application::sendNackPackets() { · 26 unmodified lines | ||
| 2675 | 2666 | return 0; |
| 2676 | 2667 | } |
| 2677 | 2668 | |
| 2678 | − int packetsSent = 0; | |
| 2679 | − char packet[MAX_PACKET_SIZE]; | |
| 2680 | − | |
| 2681 | − // iterates thru all nodes in NodeList | |
| 2669 | + // iterates through all nodes in NodeList | |
| 2682 | 2670 | auto nodeList = DependencyManager::get<NodeList>(); |
| 2683 | 2671 | |
| 2672 | + int packetsSent = 0; | |
| 2673 | + | |
| 2684 | 2674 | nodeList->eachNode([&](const SharedNodePointer& node){ |
| 2685 | 2675 | |
| 2686 | 2676 | if (node->getActiveSocket() && node->getType() == NodeType::EntityServer) { |
| 2687 | 2677 | |
| 2678 | + NLPacketList nackPacketList(PacketType::OctreeDataNack); | |
| 2679 | + | |
| 2688 | 2680 | QUuid nodeUUID = node->getUUID(); |
| 2689 | 2681 | |
| 2690 | 2682 | // if there are octree packets from this node that are waiting to be processed, |
| @@ -2700,55 +2692,36 @@ int Application::sendNackPackets() { · 9 unmodified lines | ||
| 2700 | 2692 | _octreeSceneStatsLock.unlock(); |
| 2701 | 2693 | return; |
| 2702 | 2694 | } |
| 2703 | − | |
| 2695 | + | |
| 2704 | 2696 | // get sequence number stats of node, prune its missing set, and make a copy of the missing set |
| 2705 | 2697 | SequenceNumberStats& sequenceNumberStats = _octreeServerSceneStats[nodeUUID].getIncomingOctreeSequenceNumberStats(); |
| 2706 | 2698 | sequenceNumberStats.pruneMissingSet(); |
| 2707 | 2699 | const QSet<OCTREE_PACKET_SEQUENCE> missingSequenceNumbers = sequenceNumberStats.getMissingSet(); |
| 2708 | − | |
| 2700 | + | |
| 2709 | 2701 | _octreeSceneStatsLock.unlock(); |
| 2710 | − | |
| 2702 | + | |
| 2711 | 2703 | // construct nack packet(s) for this node |
| 2712 | − int numSequenceNumbersAvailable = missingSequenceNumbers.size(); | |
| 2713 | − QSet<OCTREE_PACKET_SEQUENCE>::const_iterator missingSequenceNumbersIterator = missingSequenceNumbers.constBegin(); | |
| 2714 | − while (numSequenceNumbersAvailable > 0) { | |
| 2715 | − | |
| 2716 | − char* dataAt = packet; | |
| 2717 | − int bytesRemaining = MAX_PACKET_SIZE; | |
| 2718 | − | |
| 2719 | − // pack header | |
| 2720 | − int numBytesPacketHeader = nodeList->populatePacketHeader(packet, PacketTypeOctreeDataNack); | |
| 2721 | − dataAt += numBytesPacketHeader; | |
| 2722 | − bytesRemaining -= numBytesPacketHeader; | |
| 2723 | − | |
| 2724 | − // calculate and pack the number of sequence numbers | |
| 2725 | − int numSequenceNumbersRoomFor = (bytesRemaining - sizeof(uint16_t)) / sizeof(OCTREE_PACKET_SEQUENCE); | |
| 2726 | − uint16_t numSequenceNumbers = min(numSequenceNumbersAvailable, numSequenceNumbersRoomFor); | |
| 2727 | − uint16_t* numSequenceNumbersAt = (uint16_t*)dataAt; | |
| 2728 | − *numSequenceNumbersAt = numSequenceNumbers; | |
| 2729 | − dataAt += sizeof(uint16_t); | |
| 2730 | − | |
| 2731 | − // pack sequence numbers | |
| 2732 | − for (int i = 0; i < numSequenceNumbers; i++) { | |
| 2733 | − OCTREE_PACKET_SEQUENCE* sequenceNumberAt = (OCTREE_PACKET_SEQUENCE*)dataAt; | |
| 2734 | − *sequenceNumberAt = *missingSequenceNumbersIterator; | |
| 2735 | − dataAt += sizeof(OCTREE_PACKET_SEQUENCE); | |
| 2736 | − | |
| 2737 | − missingSequenceNumbersIterator++; | |
| 2738 | − } | |
| 2739 | − numSequenceNumbersAvailable -= numSequenceNumbers; | |
| 2740 | − | |
| 2741 | − // send it | |
| 2742 | − nodeList->writeUnverifiedDatagram(packet, dataAt - packet, node); | |
| 2743 | − packetsSent++; | |
| 2704 | + auto it = missingSequenceNumbers.constBegin(); | |
| 2705 | + while (it != missingSequenceNumbers.constEnd()) { | |
| 2706 | + OCTREE_PACKET_SEQUENCE missingNumber = *it; | |
| 2707 | + nackPacketList.writePrimitive(missingNumber); | |
| 2708 | + ++it; | |
| 2709 | + } | |
| 2710 | + | |
| 2711 | + if (nackPacketList.getNumPackets()) { | |
| 2712 | + packetsSent += nackPacketList.getNumPackets(); | |
| 2713 | + | |
| 2714 | + // send the packet list | |
| 2715 | + nodeList->sendPacketList(nackPacketList, *node); | |
| 2744 | 2716 | } |
| 2745 | 2717 | } |
| 2746 | 2718 | }); |
| 2747 | 2719 | |
| 2720 | + | |
| 2748 | 2721 | return packetsSent; |
| 2749 | 2722 | } |
| 2750 | 2723 | |
| 2751 | −void Application::queryOctree(NodeType_t serverType, PacketType packetType, NodeToJurisdictionMap& jurisdictions) { | |
| 2724 | +void Application::queryOctree(NodeType_t serverType, PacketType::Value packetType, NodeToJurisdictionMap& jurisdictions) { | |
| 2752 | 2725 | |
| 2753 | 2726 | //qCDebug(interfaceapp) << ">>> inside... queryOctree()... _viewFrustum.getFieldOfView()=" << _viewFrustum.getFieldOfView(); |
| 2754 | 2727 | bool wantExtraDebugging = getLogger()->extraDebugging(); |
| @@ -2771,9 +2744,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 16 unmodified lines | ||
| 2771 | 2744 | _octreeQuery.setOctreeSizeScale(lodManager->getOctreeSizeScale()); |
| 2772 | 2745 | _octreeQuery.setBoundaryLevelAdjust(lodManager->getBoundaryLevelAdjust()); |
| 2773 | 2746 | |
| 2774 | − unsigned char queryPacket[MAX_PACKET_SIZE]; | |
| 2775 | − | |
| 2776 | − // Iterate all of the nodes, and get a count of how many voxel servers we have... | |
| 2747 | + // Iterate all of the nodes, and get a count of how many octree servers we have... | |
| 2777 | 2748 | int totalServers = 0; |
| 2778 | 2749 | int inViewServers = 0; |
| 2779 | 2750 | int unknownJurisdictionServers = 0; |
| @@ -2840,6 +2811,8 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 60 unmodified lines | ||
| 2840 | 2811 | qCDebug(interfaceapp, "perServerPPS: %d perUnknownServer: %d", perServerPPS, perUnknownServer); |
| 2841 | 2812 | } |
| 2842 | 2813 | |
| 2814 | + auto queryPacket = NLPacket::create(packetType); | |
| 2815 | + | |
| 2843 | 2816 | nodeList->eachNode([&](const SharedNodePointer& node){ |
| 2844 | 2817 | // only send to the NodeTypes that are serverType |
| 2845 | 2818 | if (node->getActiveSocket() && node->getType() == serverType) { |
| @@ -2914,19 +2887,13 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 68 unmodified lines | ||
| 2914 | 2887 | } else { |
| 2915 | 2888 | _octreeQuery.setMaxQueryPacketsPerSecond(0); |
| 2916 | 2889 | } |
| 2917 | − // set up the packet for sending... | |
| 2918 | − unsigned char* endOfQueryPacket = queryPacket; | |
| 2919 | − | |
| 2920 | − // insert packet type/version and node UUID | |
| 2921 | − endOfQueryPacket += nodeList->populatePacketHeader(reinterpret_cast<char*>(endOfQueryPacket), packetType); | |
| 2922 | − | |
| 2923 | − // encode the query data... | |
| 2924 | − endOfQueryPacket += _octreeQuery.getBroadcastData(endOfQueryPacket); | |
| 2925 | 2890 | |
| 2926 | − int packetLength = endOfQueryPacket - queryPacket; | |
| 2891 | + // encode the query data | |
| 2892 | + int packetSize = _octreeQuery.getBroadcastData(reinterpret_cast<unsigned char*>(queryPacket->getPayload())); | |
| 2893 | + queryPacket->setPayloadSize(packetSize); | |
| 2927 | 2894 | |
| 2928 | 2895 | // make sure we still have an active socket |
| 2929 | − nodeList->writeUnverifiedDatagram(reinterpret_cast<const char*>(queryPacket), packetLength, node); | |
| 2896 | + nodeList->sendUnreliablePacket(*queryPacket, *node); | |
| 2930 | 2897 | } |
| 2931 | 2898 | }); |
| 2932 | 2899 | } |
| @@ -2990,169 +2957,6 @@ glm::vec3 Application::getSunDirection() { · 57 unmodified lines | ||
| 2990 | 2957 | // FIXME, preprocessor guard this check to occur only in DEBUG builds |
| 2991 | 2958 | static QThread * activeRenderingThread = nullptr; |
| 2992 | 2959 | |
| 2993 | −void Application::updateShadowMap(RenderArgs* renderArgs) { | |
| 2994 | − activeRenderingThread = QThread::currentThread(); | |
| 2995 | − | |
| 2996 | − PerformanceTimer perfTimer("shadowMap"); | |
| 2997 | − auto shadowFramebuffer = DependencyManager::get<TextureCache>()->getShadowFramebuffer(); | |
| 2998 | − glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(shadowFramebuffer)); | |
| 2999 | − | |
| 3000 | − glEnable(GL_DEPTH_TEST); | |
| 3001 | − glClear(GL_DEPTH_BUFFER_BIT); | |
| 3002 | − | |
| 3003 | − glm::vec3 lightDirection = getSunDirection(); | |
| 3004 | − glm::quat rotation = rotationBetween(IDENTITY_FRONT, lightDirection); | |
| 3005 | − glm::quat inverseRotation = glm::inverse(rotation); | |
| 3006 | − | |
| 3007 | − const float SHADOW_MATRIX_DISTANCES[] = { 0.0f, 2.0f, 6.0f, 14.0f, 30.0f }; | |
| 3008 | − const glm::vec2 MAP_COORDS[] = { glm::vec2(0.0f, 0.0f), glm::vec2(0.5f, 0.0f), | |
| 3009 | − glm::vec2(0.0f, 0.5f), glm::vec2(0.5f, 0.5f) }; | |
| 3010 | − | |
| 3011 | − float frustumScale = 1.0f / (_viewFrustum.getFarClip() - _viewFrustum.getNearClip()); | |
| 3012 | − loadViewFrustum(_myCamera, _viewFrustum); | |
| 3013 | − | |
| 3014 | − int matrixCount = 1; | |
| 3015 | − //int targetSize = fbo->width(); | |
| 3016 | − int sourceSize = shadowFramebuffer->getWidth(); | |
| 3017 | − int targetSize = shadowFramebuffer->getWidth(); | |
| 3018 | − float targetScale = 1.0f; | |
| 3019 | − if (Menu::getInstance()->isOptionChecked(MenuOption::CascadedShadows)) { | |
| 3020 | − matrixCount = CASCADED_SHADOW_MATRIX_COUNT; | |
| 3021 | − targetSize = sourceSize / 2; | |
| 3022 | − targetScale = 0.5f; | |
| 3023 | − } | |
| 3024 | − for (int i = 0; i < matrixCount; i++) { | |
| 3025 | − const glm::vec2& coord = MAP_COORDS[i]; | |
| 3026 | − glViewport(coord.s * sourceSize, coord.t * sourceSize, targetSize, targetSize); | |
| 3027 | − | |
| 3028 | − // if simple shadow then since the resolution is twice as much as with cascaded, cover 2 regions with the map, not just one | |
| 3029 | − int regionIncrement = (matrixCount == 1 ? 2 : 1); | |
| 3030 | − float nearScale = SHADOW_MATRIX_DISTANCES[i] * frustumScale; | |
| 3031 | − float farScale = SHADOW_MATRIX_DISTANCES[i + regionIncrement] * frustumScale; | |
| 3032 | − glm::vec3 points[] = { | |
| 3033 | − glm::mix(_viewFrustum.getNearTopLeft(), _viewFrustum.getFarTopLeft(), nearScale), | |
| 3034 | − glm::mix(_viewFrustum.getNearTopRight(), _viewFrustum.getFarTopRight(), nearScale), | |
| 3035 | − glm::mix(_viewFrustum.getNearBottomLeft(), _viewFrustum.getFarBottomLeft(), nearScale), | |
| 3036 | − glm::mix(_viewFrustum.getNearBottomRight(), _viewFrustum.getFarBottomRight(), nearScale), | |
| 3037 | − glm::mix(_viewFrustum.getNearTopLeft(), _viewFrustum.getFarTopLeft(), farScale), | |
| 3038 | − glm::mix(_viewFrustum.getNearTopRight(), _viewFrustum.getFarTopRight(), farScale), | |
| 3039 | − glm::mix(_viewFrustum.getNearBottomLeft(), _viewFrustum.getFarBottomLeft(), farScale), | |
| 3040 | − glm::mix(_viewFrustum.getNearBottomRight(), _viewFrustum.getFarBottomRight(), farScale) }; | |
| 3041 | − glm::vec3 center; | |
| 3042 | − for (size_t j = 0; j < sizeof(points) / sizeof(points[0]); j++) { | |
| 3043 | − center += points[j]; | |
| 3044 | − } | |
| 3045 | − center /= (float)(sizeof(points) / sizeof(points[0])); | |
| 3046 | − float radius = 0.0f; | |
| 3047 | − for (size_t j = 0; j < sizeof(points) / sizeof(points[0]); j++) { | |
| 3048 | − radius = qMax(radius, glm::distance(points[j], center)); | |
| 3049 | − } | |
| 3050 | − if (i < 3) { | |
| 3051 | − const float RADIUS_SCALE = 0.5f; | |
| 3052 | − _shadowDistances[i] = -glm::distance(_viewFrustum.getPosition(), center) - radius * RADIUS_SCALE; | |
| 3053 | − } | |
| 3054 | − center = inverseRotation * center; | |
| 3055 | − | |
| 3056 | − // to reduce texture "shimmer," move in texel increments | |
| 3057 | − float texelSize = (2.0f * radius) / targetSize; | |
| 3058 | − center = glm::vec3(roundf(center.x / texelSize) * texelSize, roundf(center.y / texelSize) * texelSize, | |
| 3059 | − roundf(center.z / texelSize) * texelSize); | |
| 3060 | − | |
| 3061 | − glm::vec3 minima(center.x - radius, center.y - radius, center.z - radius); | |
| 3062 | − glm::vec3 maxima(center.x + radius, center.y + radius, center.z + radius); | |
| 3063 | − | |
| 3064 | − // stretch out our extents in z so that we get all of the avatars | |
| 3065 | − minima.z -= _viewFrustum.getFarClip() * 0.5f; | |
| 3066 | − maxima.z += _viewFrustum.getFarClip() * 0.5f; | |
| 3067 | − | |
| 3068 | − // save the combined matrix for rendering | |
| 3069 | − _shadowMatrices[i] = glm::transpose(glm::translate(glm::vec3(coord, 0.0f)) * | |
| 3070 | − glm::scale(glm::vec3(targetScale, targetScale, 1.0f)) * | |
| 3071 | − glm::translate(glm::vec3(0.5f, 0.5f, 0.5f)) * glm::scale(glm::vec3(0.5f, 0.5f, 0.5f)) * | |
| 3072 | − glm::ortho(minima.x, maxima.x, minima.y, maxima.y, -maxima.z, -minima.z) * glm::mat4_cast(inverseRotation)); | |
| 3073 | − | |
| 3074 | − // update the shadow view frustum | |
| 3075 | − // glm::vec3 shadowFrustumCenter = glm::vec3((minima.x + maxima.x) * 0.5f, (minima.y + maxima.y) * 0.5f, (minima.z + maxima.z) * 0.5f); | |
| 3076 | − glm::vec3 shadowFrustumCenter = rotation * ((minima + maxima) * 0.5f); | |
| 3077 | − _shadowViewFrustum.setPosition(shadowFrustumCenter); | |
| 3078 | − _shadowViewFrustum.setOrientation(rotation); | |
| 3079 | − _shadowViewFrustum.setProjection(glm::ortho(minima.x, maxima.x, minima.y, maxima.y, minima.z, maxima.z)); | |
| 3080 | − _shadowViewFrustum.calculate(); | |
| 3081 | − | |
| 3082 | − glMatrixMode(GL_PROJECTION); | |
| 3083 | − glPushMatrix(); | |
| 3084 | − glLoadIdentity(); | |
| 3085 | − glOrtho(minima.x, maxima.x, minima.y, maxima.y, -maxima.z, -minima.z); | |
| 3086 | − | |
| 3087 | − glm::mat4 projAgain; | |
| 3088 | − glGetFloatv(GL_PROJECTION_MATRIX, (GLfloat*)&projAgain); | |
| 3089 | − | |
| 3090 | − | |
| 3091 | − glMatrixMode(GL_MODELVIEW); | |
| 3092 | − glPushMatrix(); | |
| 3093 | − glLoadIdentity(); | |
| 3094 | − glm::vec3 axis = glm::axis(inverseRotation); | |
| 3095 | − glRotatef(glm::degrees(glm::angle(inverseRotation)), axis.x, axis.y, axis.z); | |
| 3096 | − | |
| 3097 | − // store view matrix without translation, which we'll use for precision-sensitive objects | |
| 3098 | − updateUntranslatedViewMatrix(); | |
| 3099 | − | |
| 3100 | − // Equivalent to what is happening with _untranslatedViewMatrix and the _viewMatrixTranslation | |
| 3101 | − // the viewTransofmr object is updatded with the correct values and saved, | |
| 3102 | − // this is what is used for rendering the Entities and avatars | |
| 3103 | − Transform viewTransform; | |
| 3104 | − viewTransform.setRotation(rotation); | |
| 3105 | − // viewTransform.postTranslate(shadowFrustumCenter); | |
| 3106 | − setViewTransform(viewTransform); | |
| 3107 | − | |
| 3108 | − | |
| 3109 | − glEnable(GL_POLYGON_OFFSET_FILL); | |
| 3110 | − glPolygonOffset(1.1f, 4.0f); // magic numbers courtesy http://www.eecs.berkeley.edu/~ravir/6160/papers/shadowmaps.ppt | |
| 3111 | − | |
| 3112 | − { | |
| 3113 | − PerformanceTimer perfTimer("entities"); | |
| 3114 | − _entities.render(renderArgs); | |
| 3115 | − } | |
| 3116 | − | |
| 3117 | − glDisable(GL_POLYGON_OFFSET_FILL); | |
| 3118 | − | |
| 3119 | − glPopMatrix(); | |
| 3120 | − | |
| 3121 | − glMatrixMode(GL_PROJECTION); | |
| 3122 | − glPopMatrix(); | |
| 3123 | − | |
| 3124 | − glMatrixMode(GL_MODELVIEW); | |
| 3125 | − } | |
| 3126 | − | |
| 3127 | − // fbo->release(); | |
| 3128 | − | |
| 3129 | − glViewport(0, 0, _glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); | |
| 3130 | − activeRenderingThread = nullptr; | |
| 3131 | −} | |
| 3132 | − | |
| 3133 | −const GLfloat WORLD_AMBIENT_COLOR[] = { 0.525f, 0.525f, 0.6f }; | |
| 3134 | −const GLfloat WORLD_DIFFUSE_COLOR[] = { 0.6f, 0.525f, 0.525f }; | |
| 3135 | −const GLfloat WORLD_SPECULAR_COLOR[] = { 0.08f, 0.08f, 0.08f, 1.0f }; | |
| 3136 | − | |
| 3137 | −const glm::vec3 GLOBAL_LIGHT_COLOR = { 0.6f, 0.525f, 0.525f }; | |
| 3138 | − | |
| 3139 | −void Application::setupWorldLight() { | |
| 3140 | − | |
| 3141 | − // Setup 3D lights (after the camera transform, so that they are positioned in world space) | |
| 3142 | − glEnable(GL_COLOR_MATERIAL); | |
| 3143 | − glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); | |
| 3144 | − | |
| 3145 | − glm::vec3 sunDirection = getSunDirection(); | |
| 3146 | − GLfloat light_position0[] = { sunDirection.x, sunDirection.y, sunDirection.z, 0.0 }; | |
| 3147 | − glLightfv(GL_LIGHT0, GL_POSITION, light_position0); | |
| 3148 | − glLightfv(GL_LIGHT0, GL_AMBIENT, WORLD_AMBIENT_COLOR); | |
| 3149 | − glLightfv(GL_LIGHT0, GL_DIFFUSE, WORLD_DIFFUSE_COLOR); | |
| 3150 | − glLightfv(GL_LIGHT0, GL_SPECULAR, WORLD_SPECULAR_COLOR); | |
| 3151 | − glMaterialfv(GL_FRONT, GL_SPECULAR, WORLD_SPECULAR_COLOR); | |
| 3152 | − glMateriali(GL_FRONT, GL_SHININESS, 96); | |
| 3153 | − | |
| 3154 | −} | |
| 3155 | − | |
| 3156 | 2960 | bool Application::shouldRenderMesh(float largestDimension, float distanceToCamera) { |
| 3157 | 2961 | return DependencyManager::get<LODManager>()->shouldRenderMesh(largestDimension, distanceToCamera); |
| 3158 | 2962 | } |
| @@ -3173,35 +2977,25 @@ PickRay Application::computePickRay(float x, float y) const { · 14 unmodified lines | ||
| 3173 | 2977 | if (isHMDMode()) { |
| 3174 | 2978 | getApplicationCompositor().computeHmdPickRay(glm::vec2(x, y), result.origin, result.direction); |
| 3175 | 2979 | } else { |
| 3176 | − if (QThread::currentThread() == activeRenderingThread) { | |
| 3177 | − getDisplayViewFrustum()->computePickRay(x, y, result.origin, result.direction); | |
| 3178 | − } else { | |
| 3179 | − getViewFrustum()->computePickRay(x, y, result.origin, result.direction); | |
| 3180 | − } | |
| 2980 | + getViewFrustum()->computePickRay(x, y, result.origin, result.direction); | |
| 3181 | 2981 | } |
| 3182 | 2982 | return result; |
| 3183 | 2983 | } |
| 3184 | 2984 | |
| 3185 | 2985 | QImage Application::renderAvatarBillboard(RenderArgs* renderArgs) { |
| 3186 | − auto primaryFramebuffer = DependencyManager::get<TextureCache>()->getPrimaryFramebuffer(); | |
| 3187 | − glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFramebuffer)); | |
| 3188 | − | |
| 3189 | − // clear the alpha channel so the background is transparent | |
| 3190 | − glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE); | |
| 3191 | − glClearColor(0.0, 0.0, 0.0, 0.0); | |
| 3192 | − glClear(GL_COLOR_BUFFER_BIT); | |
| 3193 | − glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE); | |
| 3194 | 2986 | |
| 3195 | 2987 | const int BILLBOARD_SIZE = 64; |
| 3196 | − // TODO: Pass a RenderArgs to renderAvatarBillboard | |
| 3197 | − renderRearViewMirror(renderArgs, QRect(0, _glWidget->getDeviceHeight() - BILLBOARD_SIZE, | |
| 3198 | − BILLBOARD_SIZE, BILLBOARD_SIZE), | |
| 3199 | − true); | |
| 2988 | + | |
| 2989 | + // Need to make sure the gl context is current here | |
| 2990 | + _glWidget->makeCurrent(); | |
| 2991 | + | |
| 2992 | + renderArgs->_renderMode = RenderArgs::DEFAULT_RENDER_MODE; | |
| 2993 | + renderRearViewMirror(renderArgs, QRect(0, 0, BILLBOARD_SIZE, BILLBOARD_SIZE), true); | |
| 2994 | + | |
| 2995 | + auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferDepthColor(); | |
| 3200 | 2996 | QImage image(BILLBOARD_SIZE, BILLBOARD_SIZE, QImage::Format_ARGB32); |
| 3201 | − glReadPixels(0, 0, BILLBOARD_SIZE, BILLBOARD_SIZE, GL_BGRA, GL_UNSIGNED_BYTE, image.bits()); | |
| 3202 | − glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); | |
| 2997 | + renderArgs->_context->downloadFramebuffer(primaryFbo, glm::ivec4(0, 0, BILLBOARD_SIZE, BILLBOARD_SIZE), image); | |
| 3203 | 2998 | |
| 3204 | − glBindFramebuffer(GL_FRAMEBUFFER, 0); | |
| 3205 | 2999 | return image; |
| 3206 | 3000 | } |
| 3207 | 3001 | |
| @@ -3306,9 +3100,6 @@ namespace render { · 98 unmodified lines | ||
| 3306 | 3100 | PerformanceTimer perfTimer("stars"); |
| 3307 | 3101 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), |
| 3308 | 3102 | "Application::payloadRender<BackgroundRenderData>() ... stars..."); |
| 3309 | − if (!background->_stars.isStarsLoaded()) { | |
| 3310 | − background->_stars.generate(STARFIELD_NUM_STARS, STARFIELD_SEED); | |
| 3311 | − } | |
| 3312 | 3103 | // should be the first rendering pass - w/o depth buffer / lighting |
| 3313 | 3104 | |
| 3314 | 3105 | // compute starfield alpha based on distance from atmosphere |
| @@ -3336,7 +3127,7 @@ namespace render { · 21 unmodified lines | ||
| 3336 | 3127 | + APPROXIMATE_DISTANCE_FROM_HORIZON; |
| 3337 | 3128 | alpha = (directionY / DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON); |
| 3338 | 3129 | } |
| 3339 | − | |
| 3130 | + | |
| 3340 | 3131 | |
| 3341 | 3132 | } else if (height < closestData.getAtmosphereOuterRadius()) { |
| 3342 | 3133 | alpha = (height - closestData.getAtmosphereInnerRadius()) / |
| @@ -3356,7 +3147,7 @@ namespace render { · 13 unmodified lines | ||
| 3356 | 3147 | |
| 3357 | 3148 | // finally render the starfield |
| 3358 | 3149 | if (hasStars) { |
| 3359 | − background->_stars.render(args->_viewFrustum->getFieldOfView(), args->_viewFrustum->getAspectRatio(), args->_viewFrustum->getNearClip(), alpha); | |
| 3150 | + background->_stars.render(args, alpha); | |
| 3360 | 3151 | } |
| 3361 | 3152 | |
| 3362 | 3153 | // draw the sky dome |
| @@ -3371,16 +3162,12 @@ namespace render { · 8 unmodified lines | ||
| 3371 | 3162 | } |
| 3372 | 3163 | } else if (skyStage->getBackgroundMode() == model::SunSkyStage::SKY_BOX) { |
| 3373 | 3164 | PerformanceTimer perfTimer("skybox"); |
| 3374 | − | |
| 3165 | + | |
| 3375 | 3166 | skybox = skyStage->getSkybox(); |
| 3376 | 3167 | if (skybox) { |
| 3377 | 3168 | model::Skybox::render(batch, *(Application::getInstance()->getDisplayViewFrustum()), *skybox); |
| 3378 | 3169 | } |
| 3379 | 3170 | } |
| 3380 | − // FIX ME - If I don't call this renderBatch() here, then the atmosphere and skybox don't render, but it | |
| 3381 | − // seems like these payloadRender() methods shouldn't be doing this. We need to investigate why the engine | |
| 3382 | − // isn't rendering our batch | |
| 3383 | − gpu::GLBackend::renderBatch(batch, true); | |
| 3384 | 3171 | } |
| 3385 | 3172 | } |
| 3386 | 3173 | |
| @@ -3400,76 +3187,22 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 13 unmodified lines | ||
| 3400 | 3187 | // load the view frustum |
| 3401 | 3188 | loadViewFrustum(theCamera, _displayViewFrustum); |
| 3402 | 3189 | |
| 3403 | − // transform view according to theCamera | |
| 3404 | − // could be myCamera (if in normal mode) | |
| 3405 | − // or could be viewFrustumOffsetCamera if in offset mode | |
| 3406 | − | |
| 3407 | − glm::quat rotation = theCamera.getRotation(); | |
| 3408 | − glm::vec3 axis = glm::axis(rotation); | |
| 3409 | − glRotatef(-glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); | |
| 3410 | − | |
| 3411 | − // store view matrix without translation, which we'll use for precision-sensitive objects | |
| 3412 | − updateUntranslatedViewMatrix(-theCamera.getPosition()); | |
| 3413 | − | |
| 3414 | − // Equivalent to what is happening with _untranslatedViewMatrix and the _viewMatrixTranslation | |
| 3415 | − // the viewTransofmr object is updatded with the correct values and saved, | |
| 3416 | − // this is what is used for rendering the Entities and avatars | |
| 3417 | − Transform viewTransform; | |
| 3418 | − viewTransform.setTranslation(theCamera.getPosition()); | |
| 3419 | − viewTransform.setRotation(rotation); | |
| 3420 | − if (renderArgs->_renderSide != RenderArgs::MONO) { | |
| 3421 | − glm::mat4 invView = glm::inverse(_untranslatedViewMatrix); | |
| 3422 | − | |
| 3423 | − viewTransform.evalFromRawMatrix(invView); | |
| 3424 | − viewTransform.preTranslate(_viewMatrixTranslation); | |
| 3425 | − } | |
| 3426 | − | |
| 3427 | − setViewTransform(viewTransform); | |
| 3428 | − | |
| 3429 | − glTranslatef(_viewMatrixTranslation.x, _viewMatrixTranslation.y, _viewMatrixTranslation.z); | |
| 3430 | − | |
| 3431 | − // Setup 3D lights (after the camera transform, so that they are positioned in world space) | |
| 3432 | − { | |
| 3433 | − PerformanceTimer perfTimer("lights"); | |
| 3434 | − setupWorldLight(); | |
| 3435 | − } | |
| 3436 | − | |
| 3437 | − // setup shadow matrices (again, after the camera transform) | |
| 3438 | − int shadowMatrixCount = 0; | |
| 3439 | − if (Menu::getInstance()->isOptionChecked(MenuOption::SimpleShadows)) { | |
| 3440 | − shadowMatrixCount = 1; | |
| 3441 | − } else if (Menu::getInstance()->isOptionChecked(MenuOption::CascadedShadows)) { | |
| 3442 | − shadowMatrixCount = CASCADED_SHADOW_MATRIX_COUNT; | |
| 3443 | − } | |
| 3444 | − for (int i = shadowMatrixCount - 1; i >= 0; i--) { | |
| 3445 | − glActiveTexture(GL_TEXTURE0 + i); | |
| 3446 | − glTexGenfv(GL_S, GL_EYE_PLANE, (const GLfloat*)&_shadowMatrices[i][0]); | |
| 3447 | − glTexGenfv(GL_T, GL_EYE_PLANE, (const GLfloat*)&_shadowMatrices[i][1]); | |
| 3448 | − glTexGenfv(GL_R, GL_EYE_PLANE, (const GLfloat*)&_shadowMatrices[i][2]); | |
| 3449 | − } | |
| 3190 | + // TODO fix shadows and make them use the GPU library | |
| 3450 | 3191 | |
| 3451 | 3192 | // The pending changes collecting the changes here |
| 3452 | 3193 | render::PendingChanges pendingChanges; |
| 3453 | 3194 | |
| 3454 | 3195 | // Background rendering decision |
| 3455 | 3196 | if (BackgroundRenderData::_item == 0) { |
| 3456 | − auto backgroundRenderData = BackgroundRenderData::Pointer(new BackgroundRenderData(&_environment)); | |
| 3457 | − auto backgroundRenderPayload = render::PayloadPointer(new BackgroundRenderData::Payload(backgroundRenderData)); | |
| 3197 | + auto backgroundRenderData = make_shared<BackgroundRenderData>(&_environment); | |
| 3198 | + auto backgroundRenderPayload = make_shared<BackgroundRenderData::Payload>(backgroundRenderData); | |
| 3458 | 3199 | BackgroundRenderData::_item = _main3DScene->allocateID(); |
| 3459 | 3200 | pendingChanges.resetItem(WorldBoxRenderData::_item, backgroundRenderPayload); |
| 3460 | 3201 | } else { |
| 3461 | 3202 | |
| 3462 | 3203 | } |
| 3463 | 3204 | |
| 3464 | − if (Menu::getInstance()->isOptionChecked(MenuOption::Wireframe)) { | |
| 3465 | − glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); | |
| 3466 | − } | |
| 3467 | − | |
| 3468 | − glEnable(GL_LIGHTING); | |
| 3469 | − glEnable(GL_DEPTH_TEST); | |
| 3470 | − | |
| 3471 | 3205 | // Assuming nothing get's rendered through that |
| 3472 | − | |
| 3473 | 3206 | if (!selfAvatarOnly) { |
| 3474 | 3207 | if (DependencyManager::get<SceneScriptingInterface>()->shouldRenderEntities()) { |
| 3475 | 3208 | // render models... |
| @@ -3489,20 +3222,12 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 13 unmodified lines | ||
| 3489 | 3222 | renderArgs->_debugFlags = renderDebugFlags; |
| 3490 | 3223 | _entities.render(renderArgs); |
| 3491 | 3224 | } |
| 3492 | − | |
| 3493 | − // render the ambient occlusion effect if enabled | |
| 3494 | − if (Menu::getInstance()->isOptionChecked(MenuOption::AmbientOcclusion)) { | |
| 3495 | − PerformanceTimer perfTimer("ambientOcclusion"); | |
| 3496 | − PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), | |
| 3497 | − "Application::displaySide() ... AmbientOcclusion..."); | |
| 3498 | − DependencyManager::get<AmbientOcclusionEffect>()->render(); | |
| 3499 | − } | |
| 3500 | 3225 | } |
| 3501 | 3226 | |
| 3502 | 3227 | // Make sure the WorldBox is in the scene |
| 3503 | 3228 | if (WorldBoxRenderData::_item == 0) { |
| 3504 | − auto worldBoxRenderData = WorldBoxRenderData::Pointer(new WorldBoxRenderData()); | |
| 3505 | − auto worldBoxRenderPayload = render::PayloadPointer(new WorldBoxRenderData::Payload(worldBoxRenderData)); | |
| 3229 | + auto worldBoxRenderData = make_shared<WorldBoxRenderData>(); | |
| 3230 | + auto worldBoxRenderPayload = make_shared<WorldBoxRenderData::Payload>(worldBoxRenderData); | |
| 3506 | 3231 | |
| 3507 | 3232 | WorldBoxRenderData::_item = _main3DScene->allocateID(); |
| 3508 | 3233 | |
| @@ -3554,6 +3279,9 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 45 unmodified lines | ||
| 3554 | 3279 | renderContext._maxDrawnOverlay3DItems = sceneInterface->getEngineMaxDrawnOverlay3DItems(); |
| 3555 | 3280 | |
| 3556 | 3281 | renderContext._drawItemStatus = sceneInterface->doEngineDisplayItemStatus(); |
| 3282 | + renderContext._drawHitEffect = sceneInterface->doEngineDisplayHitEffect(); | |
| 3283 | + | |
| 3284 | + renderContext._occlusionStatus = Menu::getInstance()->isOptionChecked(MenuOption::DebugAmbientOcclusion); | |
| 3557 | 3285 | |
| 3558 | 3286 | renderArgs->_shouldRender = LODManager::shouldRender; |
| 3559 | 3287 | |
| @@ -3563,7 +3291,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 3 unmodified lines | ||
| 3563 | 3291 | |
| 3564 | 3292 | // Before the deferred pass, let's try to use the render engine |
| 3565 | 3293 | _renderEngine->run(); |
| 3566 | − | |
| 3294 | + | |
| 3567 | 3295 | auto engineRC = _renderEngine->getRenderContext(); |
| 3568 | 3296 | sceneInterface->setEngineFeedOpaqueItems(engineRC->_numFeedOpaqueItems); |
| 3569 | 3297 | sceneInterface->setEngineDrawnOpaqueItems(engineRC->_numDrawnOpaqueItems); |
| @@ -3574,10 +3302,6 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 4 unmodified lines | ||
| 3574 | 3302 | sceneInterface->setEngineFeedOverlay3DItems(engineRC->_numFeedOverlay3DItems); |
| 3575 | 3303 | sceneInterface->setEngineDrawnOverlay3DItems(engineRC->_numDrawnOverlay3DItems); |
| 3576 | 3304 | } |
| 3577 | − //Render the sixense lasers | |
| 3578 | − if (Menu::getInstance()->isOptionChecked(MenuOption::SixenseLasers)) { | |
| 3579 | − _myAvatar->renderLaserPointers(*renderArgs->_batch); | |
| 3580 | − } | |
| 3581 | 3305 | |
| 3582 | 3306 | if (!selfAvatarOnly) { |
| 3583 | 3307 | // give external parties a change to hook in |
| @@ -3587,37 +3311,9 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 3 unmodified lines | ||
| 3587 | 3311 | } |
| 3588 | 3312 | } |
| 3589 | 3313 | |
| 3590 | − if (Menu::getInstance()->isOptionChecked(MenuOption::Wireframe)) { | |
| 3591 | − glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); | |
| 3592 | − } | |
| 3593 | − | |
| 3594 | 3314 | activeRenderingThread = nullptr; |
| 3595 | 3315 | } |
| 3596 | 3316 | |
| 3597 | −void Application::updateUntranslatedViewMatrix(const glm::vec3& viewMatrixTranslation) { | |
| 3598 | − glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat*)&_untranslatedViewMatrix); | |
| 3599 | − _viewMatrixTranslation = viewMatrixTranslation; | |
| 3600 | −} | |
| 3601 | − | |
| 3602 | −void Application::setViewTransform(const Transform& view) { | |
| 3603 | − _viewTransform = view; | |
| 3604 | −} | |
| 3605 | − | |
| 3606 | −void Application::loadTranslatedViewMatrix(const glm::vec3& translation) { | |
| 3607 | − glLoadMatrixf((const GLfloat*)&_untranslatedViewMatrix); | |
| 3608 | − glTranslatef(translation.x + _viewMatrixTranslation.x, translation.y + _viewMatrixTranslation.y, | |
| 3609 | − translation.z + _viewMatrixTranslation.z); | |
| 3610 | −} | |
| 3611 | − | |
| 3612 | −void Application::getModelViewMatrix(glm::dmat4* modelViewMatrix) { | |
| 3613 | − (*modelViewMatrix) =_untranslatedViewMatrix; | |
| 3614 | − (*modelViewMatrix)[3] = _untranslatedViewMatrix * glm::vec4(_viewMatrixTranslation, 1); | |
| 3615 | −} | |
| 3616 | − | |
| 3617 | −void Application::getProjectionMatrix(glm::dmat4* projectionMatrix) { | |
| 3618 | − *projectionMatrix = _projectionMatrix; | |
| 3619 | −} | |
| 3620 | − | |
| 3621 | 3317 | void Application::computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal, |
| 3622 | 3318 | float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const { |
| 3623 | 3319 | |
| @@ -3668,9 +3364,9 @@ glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) { · 44 unmodified lines | ||
| 3668 | 3364 | } |
| 3669 | 3365 | |
| 3670 | 3366 | void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& region, bool billboard) { |
| 3367 | + auto originalViewport = renderArgs->_viewport; | |
| 3671 | 3368 | // Grab current viewport to reset it at the end |
| 3672 | − int viewport[4]; | |
| 3673 | − glGetIntegerv(GL_VIEWPORT, viewport); | |
| 3369 | + | |
| 3674 | 3370 | float aspect = (float)region.width() / region.height(); |
| 3675 | 3371 | float fov = MIRROR_FIELD_OF_VIEW; |
| 3676 | 3372 | |
| @@ -3701,43 +3397,30 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi · 24 unmodified lines | ||
| 3701 | 3397 | // This was removed in commit 71e59cfa88c6563749594e25494102fe01db38e9 but could be further |
| 3702 | 3398 | // investigated in order to adapt the technique while fixing the head rendering issue, |
| 3703 | 3399 | // but the complexity of the hack suggests that a better approach |
| 3704 | − _mirrorCamera.setPosition(_myAvatar->getHead()->getEyePosition() + | |
| 3400 | + _mirrorCamera.setPosition(_myAvatar->getDefaultEyePosition() + | |
| 3705 | 3401 | _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_DISTANCE * _myAvatar->getScale()); |
| 3706 | 3402 | } |
| 3707 | 3403 | _mirrorCamera.setProjection(glm::perspective(glm::radians(fov), aspect, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP)); |
| 3708 | 3404 | _mirrorCamera.setRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f))); |
| 3709 | 3405 | |
| 3406 | + | |
| 3710 | 3407 | // set the bounds of rear mirror view |
| 3408 | + gpu::Vec4i viewport; | |
| 3711 | 3409 | if (billboard) { |
| 3712 | − QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize(); | |
| 3713 | − glViewport(region.x(), size.height() - region.y() - region.height(), region.width(), region.height()); | |
| 3714 | − glScissor(region.x(), size.height() - region.y() - region.height(), region.width(), region.height()); | |
| 3715 | − renderArgs->_viewport = glm::ivec4(region.x(), size.height() - region.y() - region.height(), region.width(), region.height()); | |
| 3410 | + viewport = gpu::Vec4i(0, 0, region.width(), region.height()); | |
| 3716 | 3411 | } else { |
| 3717 | 3412 | // if not rendering the billboard, the region is in device independent coordinates; must convert to device |
| 3718 | − QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize(); | |
| 3719 | 3413 | float ratio = (float)QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale(); |
| 3720 | − int x = region.x() * ratio, y = region.y() * ratio, width = region.width() * ratio, height = region.height() * ratio; | |
| 3721 | − glViewport(x, size.height() - y - height, width, height); | |
| 3722 | − glScissor(x, size.height() - y - height, width, height); | |
| 3723 | − | |
| 3724 | − renderArgs->_viewport = glm::ivec4(x, size.height() - y - height, width, height); | |
| 3414 | + int width = region.width() * ratio; | |
| 3415 | + int height = region.height() * ratio; | |
| 3416 | + viewport = gpu::Vec4i(0, 0, width, height); | |
| 3725 | 3417 | } |
| 3726 | − bool updateViewFrustum = false; | |
| 3727 | − updateProjectionMatrix(_mirrorCamera, updateViewFrustum); | |
| 3728 | − glEnable(GL_SCISSOR_TEST); | |
| 3729 | − glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
| 3418 | + renderArgs->_viewport = viewport; | |
| 3730 | 3419 | |
| 3731 | 3420 | // render rear mirror view |
| 3732 | − glPushMatrix(); | |
| 3733 | 3421 | displaySide(renderArgs, _mirrorCamera, true, billboard); |
| 3734 | − glPopMatrix(); | |
| 3735 | 3422 | |
| 3736 | − // reset Viewport and projection matrix | |
| 3737 | − renderArgs->_viewport = glm::ivec4(viewport[0], viewport[1], viewport[2], viewport[3]); | |
| 3738 | − glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); | |
| 3739 | − glDisable(GL_SCISSOR_TEST); | |
| 3740 | − updateProjectionMatrix(_myCamera, updateViewFrustum); | |
| 3423 | + renderArgs->_viewport = originalViewport; | |
| 3741 | 3424 | } |
| 3742 | 3425 | |
| 3743 | 3426 | void Application::resetSensors() { |
| @@ -3824,11 +3507,24 @@ void Application::domainChanged(const QString& domainHostname) { · 80 unmodified lines | ||
| 3824 | 3507 | _domainConnectionRefusals.clear(); |
| 3825 | 3508 | } |
| 3826 | 3509 | |
| 3827 | −void Application::domainConnectionDenied(const QString& reason) { | |
| 3510 | +void Application::handleDomainConnectionDeniedPacket(QSharedPointer<NLPacket> packet) { | |
| 3511 | + // Read deny reason from packet | |
| 3512 | + quint16 reasonSize; | |
| 3513 | + packet->readPrimitive(&reasonSize); | |
| 3514 | + QString reason = QString::fromUtf8(packet->getPayload() + packet->pos(), reasonSize); | |
| 3515 | + packet->seek(packet->pos() + reasonSize); | |
| 3516 | + | |
| 3517 | + // output to the log so the user knows they got a denied connection request | |
| 3518 | + // and check and signal for an access token so that we can make sure they are logged in | |
| 3519 | + qCDebug(interfaceapp) << "The domain-server denied a connection request: " << reason; | |
| 3520 | + qCDebug(interfaceapp) << "You may need to re-log to generate a keypair so you can provide a username signature."; | |
| 3521 | + | |
| 3828 | 3522 | if (!_domainConnectionRefusals.contains(reason)) { |
| 3829 | 3523 | _domainConnectionRefusals.append(reason); |
| 3830 | 3524 | emit domainConnectionRefused(reason); |
| 3831 | 3525 | } |
| 3526 | + | |
| 3527 | + AccountManager::getInstance().checkAndSignalForAccessToken(); | |
| 3832 | 3528 | } |
| 3833 | 3529 | |
| 3834 | 3530 | void Application::connectedToDomain(const QString& hostname) { |
| @@ -3893,12 +3589,12 @@ void Application::nodeKilled(SharedNodePointer node) { · 58 unmodified lines | ||
| 3893 | 3589 | DependencyManager::get<AvatarManager>()->clearOtherAvatars(); |
| 3894 | 3590 | } |
| 3895 | 3591 | } |
| 3896 | − | |
| 3897 | −void Application::trackIncomingOctreePacket(const QByteArray& packet, const SharedNodePointer& sendingNode, bool wasStatsPacket) { | |
| 3592 | + | |
| 3593 | +void Application::trackIncomingOctreePacket(NLPacket& packet, SharedNodePointer sendingNode, bool wasStatsPacket) { | |
| 3898 | 3594 | |
| 3899 | 3595 | // Attempt to identify the sender from its address. |
| 3900 | 3596 | if (sendingNode) { |
| 3901 | − QUuid nodeUUID = sendingNode->getUUID(); | |
| 3597 | + const QUuid& nodeUUID = sendingNode->getUUID(); | |
| 3902 | 3598 | |
| 3903 | 3599 | // now that we know the node ID, let's add these stats to the stats for that node... |
| 3904 | 3600 | _octreeSceneStatsLock.lockForWrite(); |
| @@ -3910,60 +3606,54 @@ void Application::trackIncomingOctreePacket(const QByteArray& packet, const Shar · 5 unmodified lines | ||
| 3910 | 3606 | } |
| 3911 | 3607 | } |
| 3912 | 3608 | |
| 3913 | −int Application::parseOctreeStats(const QByteArray& packet, const SharedNodePointer& sendingNode) { | |
| 3609 | +int Application::processOctreeStats(NLPacket& packet, SharedNodePointer sendingNode) { | |
| 3914 | 3610 | // But, also identify the sender, and keep track of the contained jurisdiction root for this server |
| 3915 | 3611 | |
| 3916 | 3612 | // parse the incoming stats datas stick it in a temporary object for now, while we |
| 3917 | 3613 | // determine which server it belongs to |
| 3918 | − OctreeSceneStats temp; | |
| 3919 | − int statsMessageLength = temp.unpackFromMessage(reinterpret_cast<const unsigned char*>(packet.data()), packet.size()); | |
| 3614 | + int statsMessageLength = 0; | |
| 3920 | 3615 | |
| 3921 | − // quick fix for crash... why would voxelServer be NULL? | |
| 3922 | − if (sendingNode) { | |
| 3923 | − QUuid nodeUUID = sendingNode->getUUID(); | |
| 3616 | + const QUuid& nodeUUID = sendingNode->getUUID(); | |
| 3617 | + | |
| 3618 | + // now that we know the node ID, let's add these stats to the stats for that node... | |
| 3619 | + _octreeSceneStatsLock.lockForWrite(); | |
| 3620 | + | |
| 3621 | + OctreeSceneStats& octreeStats = _octreeServerSceneStats[nodeUUID]; | |
| 3622 | + statsMessageLength = octreeStats.unpackFromPacket(packet); | |
| 3623 | + | |
| 3624 | + _octreeSceneStatsLock.unlock(); | |
| 3924 | 3625 | |
| 3925 | − // now that we know the node ID, let's add these stats to the stats for that node... | |
| 3926 | − _octreeSceneStatsLock.lockForWrite(); | |
| 3927 | − if (_octreeServerSceneStats.find(nodeUUID) != _octreeServerSceneStats.end()) { | |
| 3928 | − _octreeServerSceneStats[nodeUUID].unpackFromMessage(reinterpret_cast<const unsigned char*>(packet.data()), | |
| 3929 | − packet.size()); | |
| 3930 | − } else { | |
| 3931 | − _octreeServerSceneStats[nodeUUID] = temp; | |
| 3932 | − } | |
| 3933 | − _octreeSceneStatsLock.unlock(); | |
| 3626 | + // see if this is the first we've heard of this node... | |
| 3627 | + NodeToJurisdictionMap* jurisdiction = NULL; | |
| 3628 | + QString serverType; | |
| 3629 | + if (sendingNode->getType() == NodeType::EntityServer) { | |
| 3630 | + jurisdiction = &_entityServerJurisdictions; | |
| 3631 | + serverType = "Entity"; | |
| 3632 | + } | |
| 3934 | 3633 | |
| 3634 | + jurisdiction->lockForRead(); | |
| 3635 | + if (jurisdiction->find(nodeUUID) == jurisdiction->end()) { | |
| 3636 | + jurisdiction->unlock(); | |
| 3637 | + | |
| 3935 | 3638 | VoxelPositionSize rootDetails; |
| 3936 | − voxelDetailsForCode(temp.getJurisdictionRoot(), rootDetails); | |
| 3937 | − | |
| 3938 | − // see if this is the first we've heard of this node... | |
| 3939 | − NodeToJurisdictionMap* jurisdiction = NULL; | |
| 3940 | − QString serverType; | |
| 3941 | − if (sendingNode->getType() == NodeType::EntityServer) { | |
| 3942 | − jurisdiction = &_entityServerJurisdictions; | |
| 3943 | − serverType = "Entity"; | |
| 3944 | − } | |
| 3945 | − | |
| 3946 | − jurisdiction->lockForRead(); | |
| 3947 | − if (jurisdiction->find(nodeUUID) == jurisdiction->end()) { | |
| 3948 | − jurisdiction->unlock(); | |
| 3949 | − | |
| 3950 | − qCDebug(interfaceapp, "stats from new %s server... [%f, %f, %f, %f]", | |
| 3951 | − qPrintable(serverType), | |
| 3952 | − (double)rootDetails.x, (double)rootDetails.y, (double)rootDetails.z, (double)rootDetails.s); | |
| 3639 | + voxelDetailsForCode(octreeStats.getJurisdictionRoot(), rootDetails); | |
| 3953 | 3640 | |
| 3954 | − } else { | |
| 3955 | − jurisdiction->unlock(); | |
| 3956 | − } | |
| 3957 | − // store jurisdiction details for later use | |
| 3958 | − // This is bit of fiddling is because JurisdictionMap assumes it is the owner of the values used to construct it | |
| 3959 | − // but OctreeSceneStats thinks it's just returning a reference to its contents. So we need to make a copy of the | |
| 3960 | − // details from the OctreeSceneStats to construct the JurisdictionMap | |
| 3961 | − JurisdictionMap jurisdictionMap; | |
| 3962 | − jurisdictionMap.copyContents(temp.getJurisdictionRoot(), temp.getJurisdictionEndNodes()); | |
| 3963 | − jurisdiction->lockForWrite(); | |
| 3964 | − (*jurisdiction)[nodeUUID] = jurisdictionMap; | |
| 3641 | + qCDebug(interfaceapp, "stats from new %s server... [%f, %f, %f, %f]", | |
| 3642 | + qPrintable(serverType), | |
| 3643 | + (double)rootDetails.x, (double)rootDetails.y, (double)rootDetails.z, (double)rootDetails.s); | |
| 3644 | + } else { | |
| 3965 | 3645 | jurisdiction->unlock(); |
| 3966 | 3646 | } |
| 3647 | + // store jurisdiction details for later use | |
| 3648 | + // This is bit of fiddling is because JurisdictionMap assumes it is the owner of the values used to construct it | |
| 3649 | + // but OctreeSceneStats thinks it's just returning a reference to its contents. So we need to make a copy of the | |
| 3650 | + // details from the OctreeSceneStats to construct the JurisdictionMap | |
| 3651 | + JurisdictionMap jurisdictionMap; | |
| 3652 | + jurisdictionMap.copyContents(octreeStats.getJurisdictionRoot(), octreeStats.getJurisdictionEndNodes()); | |
| 3653 | + jurisdiction->lockForWrite(); | |
| 3654 | + (*jurisdiction)[nodeUUID] = jurisdictionMap; | |
| 3655 | + jurisdiction->unlock(); | |
| 3656 | + | |
| 3967 | 3657 | return statsMessageLength; |
| 3968 | 3658 | } |
| 3969 | 3659 | |
| @@ -4103,10 +3793,13 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 133 unmodified lines | ||
| 4103 | 3793 | |
| 4104 | 3794 | // when the worker thread is started, call our engine's run.. |
| 4105 | 3795 | connect(workerThread, &QThread::started, scriptEngine, &ScriptEngine::run); |
| 4106 | − | |
| 3796 | + | |
| 4107 | 3797 | // when the thread is terminated, add both scriptEngine and thread to the deleteLater queue |
| 4108 | − connect(scriptEngine, SIGNAL(doneRunning()), scriptEngine, SLOT(deleteLater())); | |
| 4109 | − connect(workerThread, SIGNAL(finished()), workerThread, SLOT(deleteLater())); | |
| 3798 | + connect(scriptEngine, &ScriptEngine::doneRunning, scriptEngine, &ScriptEngine::deleteLater); | |
| 3799 | + connect(workerThread, &QThread::finished, workerThread, &QThread::deleteLater); | |
| 3800 | + | |
| 3801 | + // tell the thread to stop when the script engine is done | |
| 3802 | + connect(scriptEngine, &ScriptEngine::destroyed, workerThread, &QThread::quit); | |
| 4110 | 3803 | |
| 4111 | 3804 | auto nodeList = DependencyManager::get<NodeList>(); |
| 4112 | 3805 | connect(nodeList.data(), &NodeList::nodeKilled, scriptEngine, &ScriptEngine::nodeKilled); |
| @@ -4596,6 +4289,10 @@ void Application::setVSyncEnabled() { · 483 unmodified lines | ||
| 4596 | 4289 | #endif |
| 4597 | 4290 | } |
| 4598 | 4291 | |
| 4292 | +void Application::setThrottleFPSEnabled() { | |
| 4293 | + _isThrottleFPSEnabled = Menu::getInstance()->isOptionChecked(MenuOption::ThrottleFPSIfNotFocus); | |
| 4294 | +} | |
| 4295 | + | |
| 4599 | 4296 | bool Application::isVSyncOn() const { |
| 4600 | 4297 | #if defined(Q_OS_WIN) |
| 4601 | 4298 | if (wglewGetExtension("WGL_EXT_swap_control")) { |
| @@ -4742,7 +4439,11 @@ void Application::friendsWindowClosed() { · 140 unmodified lines | ||
| 4742 | 4439 | } |
| 4743 | 4440 | |
| 4744 | 4441 | void Application::postLambdaEvent(std::function<void()> f) { |
| 4745 | − QCoreApplication::postEvent(this, new LambdaEvent(f)); | |
| 4442 | + if (this->thread() == QThread::currentThread()) { | |
| 4443 | + f(); | |
| 4444 | + } else { | |
| 4445 | + QCoreApplication::postEvent(this, new LambdaEvent(f)); | |
| 4446 | + } | |
| 4746 | 4447 | } |
| 4747 | 4448 | |
| 4748 | 4449 | void Application::initPlugins() { |
| @@ -4803,7 +4504,7 @@ mat4 Application::getEyeProjection(int eye) const { · 54 unmodified lines | ||
| 4803 | 4504 | if (isHMDMode()) { |
| 4804 | 4505 | return OculusManager::getEyeProjection(eye); |
| 4805 | 4506 | } |
| 4806 | − | |
| 4507 | + | |
| 4807 | 4508 | return _viewFrustum.getProjection(); |
| 4808 | 4509 | } |
| 4809 | 4510 | |