History

cleaning

ericrius1 committed 11 years ago

Commit 47bc8f52 parents b4a9469 b46a430452 files · +16984 −14547Browse files

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

Unified · Split

interface/src/Application.cpp+324−623
@@ -9,11 +9,9 @@ · 8 unmodified lines
99 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
1010 //
1111
12−#include <sstream>
12+#include "Application.h"
1313
14−#include <stdlib.h>
15−#include <cmath>
16−#include <math.h>
14+#include <sstream>
1715
1816 #include <glm/glm.hpp>
1917 #include <glm/gtx/component_wise.hpp>
@@ -21,9 +19,6 @@ · 1 unmodified line
2119 #include <glm/gtx/vector_angle.hpp>
2220 #include <glm/gtc/type_ptr.hpp>
2321
24−// include this before QGLWidget, which includes an earlier version of OpenGL
25−#include "InterfaceConfig.h"
26−
2722 #include <QAbstractNativeEventFilter>
2823 #include <QActionGroup>
2924 #include <QColorDialog>
@@ -58,13 +53,13 @@ · 28 unmodified lines
5853 #include <AccountManager.h>
5954 #include <AddressManager.h>
6055 #include <CursorManager.h>
61−#include <AmbientOcclusionEffect.h>
6256 #include <AudioInjector.h>
6357 #include <AutoUpdater.h>
6458 #include <DeferredLightingEffect.h>
6559 #include <DependencyManager.h>
6660 #include <EntityScriptingInterface.h>
6761 #include <ErrorDialog.h>
62+#include <FramebufferCache.h>
6863 #include <gpu/Batch.h>
6964 #include <gpu/Context.h>
7065 #include <gpu/GLBackend.h>
@@ -80,11 +75,10 @@ · 9 unmodified lines
8075 #include <ObjectMotionState.h>
8176 #include <OctalCode.h>
8277 #include <OctreeSceneStats.h>
83−#include <PacketHeaders.h>
78+#include <udt/PacketHeaders.h>
8479 #include <PathUtils.h>
8580 #include <PerfStat.h>
8681 #include <PhysicsEngine.h>
87−#include <ProgramObject.h>
8882 #include <RenderDeferredTask.h>
8983 #include <ResourceCache.h>
9084 #include <SceneScriptingInterface.h>
@@ -92,15 +86,15 @@ · 1 unmodified line
9286 #include <SettingHandle.h>
9387 #include <SimpleAverage.h>
9488 #include <SoundCache.h>
95−#include <TextRenderer.h>
89+#include <TextureCache.h>
9690 #include <Tooltip.h>
9791 #include <UserActivityLogger.h>
9892 #include <UUID.h>
9993 #include <VrMenu.h>
10094
101−#include "Application.h"
10295 #include "AudioClient.h"
10396 #include "DiscoverabilityManager.h"
97+#include "GLCanvas.h"
10498 #include "InterfaceVersion.h"
10599 #include "LODManager.h"
106100 #include "Menu.h"
@@ -121,6 +115,7 @@ · 14 unmodified lines
121115 #include "devices/MIDIManager.h"
122116 #include "devices/OculusManager.h"
123117 #include "devices/TV3DManager.h"
118+#include "devices/3Dconnexion.h"
124119
125120 #include "scripting/AccountScriptingInterface.h"
126121 #include "scripting/AudioDeviceScriptingInterface.h"
@@ -175,8 +170,6 @@ public: · 48 unmodified lines
175170 using namespace std;
176171
177172 // Starfield information
178−static unsigned STARFIELD_NUM_STARS = 50000;
179−static unsigned STARFIELD_SEED = 1;
180173 static uint8_t THROTTLED_IDLE_TIMER_DELAY = 10;
181174
182175 const qint64 MAXIMUM_CACHE_SIZE = 10 * BYTES_PER_GIGABYTES; // 10GB
@@ -272,8 +265,9 @@ bool setupEssentials(int& argc, char** argv) { · 89 unmodified lines
272265 auto audio = DependencyManager::set<AudioClient>();
273266 auto audioScope = DependencyManager::set<AudioScope>();
274267 auto deferredLightingEffect = DependencyManager::set<DeferredLightingEffect>();
275− auto ambientOcclusionEffect = DependencyManager::set<AmbientOcclusionEffect>();
276268 auto textureCache = DependencyManager::set<TextureCache>();
269+ auto framebufferCache = DependencyManager::set<FramebufferCache>();
270+
277271 auto animationCache = DependencyManager::set<AnimationCache>();
278272 auto ddeFaceTracker = DependencyManager::set<DdeFaceTracker>();
279273 auto modelBlender = DependencyManager::set<ModelBlender>();
@@ -304,7 +298,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 24 unmodified lines
304298 _window(new MainWindow(desktop())),
305299 _toolWindow(NULL),
306300 _friendsWindow(NULL),
307− _datagramProcessor(),
308301 _undoStack(),
309302 _undoStackScriptingInterface(&_undoStack),
310303 _frameCount(0),
@@ -322,7 +315,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 11 unmodified lines
322315 _previousScriptLocation("LastScriptLocation"),
323316 _scriptsLocationHandle("scriptsLocation"),
324317 _fieldOfView("fieldOfView", DEFAULT_FIELD_OF_VIEW_DEGREES),
325− _viewTransform(),
326318 _scaleMirror(1.0f),
327319 _rotateMirror(0.0f),
328320 _raiseMirror(0.0f),
@@ -339,8 +331,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 10 unmodified lines
339331 _lastNackTime(usecTimestampNow()),
340332 _lastSendDownstreamAudioStats(usecTimestampNow()),
341333 _isVSyncOn(true),
334+ _isThrottleFPSEnabled(true),
342335 _aboutToQuit(false),
343336 _notifiedPacketVersionMismatchThisDomain(false),
337+ _glWidget(new GLCanvas()),
344338 _domainConnectionRefusals(QList<QString>()),
345339 _maxOctreePPS(maxOctreePacketsPerSecond.get()),
346340 _lastFaceTrackerUpdate(0),
@@ -371,24 +365,17 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 24 unmodified lines
371365 _bookmarks = new Bookmarks(); // Before setting up the menu
372366
373367 _runningScriptsWidget = new RunningScriptsWidget(_window);
374− _renderEngine->addTask(render::TaskPointer(new RenderDeferredTask()));
368+ _renderEngine->addTask(make_shared<RenderDeferredTask>());
375369 _renderEngine->registerScene(_main3DScene);
376−
370+
377371 // start the nodeThread so its event loop is running
378372 QThread* nodeThread = new QThread(this);
379− nodeThread->setObjectName("Datagram Processor Thread");
373+ nodeThread->setObjectName("NodeList Thread");
380374 nodeThread->start();
381375
382376 // make sure the node thread is given highest priority
383377 nodeThread->setPriority(QThread::TimeCriticalPriority);
384378
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−
392379 // setup a timer for domain-server check ins
393380 QTimer* domainCheckInTimer = new QTimer(nodeList.data());
394381 connect(domainCheckInTimer, &QTimer::timeout, nodeList.data(), &NodeList::sendDomainServerCheckIn);
@@ -404,9 +391,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 9 unmodified lines
404391 ResourceCache* geometryCache = geometryCacheP.data();
405392 connect(this, &Application::checkBackgroundDownloads, geometryCache, &ResourceCache::checkAsynchronousGets);
406393
407− // connect the DataProcessor processDatagrams slot to the QUDPSocket readyRead() signal
408− connect(&nodeList->getNodeSocket(), &QUdpSocket::readyRead, _datagramProcessor, &DatagramProcessor::processDatagrams);
409−
410394 // put the audio processing on a separate thread
411395 QThread* audioThread = new QThread();
412396 audioThread->setObjectName("Audio Thread");
@@ -417,14 +401,27 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 4 unmodified lines
417401 audioIO->setOrientationGetter(getOrientationForAudio);
418402
419403 audioIO->moveToThread(audioThread);
404+
405+ auto& audioScriptingInterface = AudioScriptingInterface::getInstance();
406+
420407 connect(audioThread, &QThread::started, audioIO.data(), &AudioClient::start);
421408 connect(audioIO.data(), &AudioClient::destroyed, audioThread, &QThread::quit);
422409 connect(audioThread, &QThread::finished, audioThread, &QThread::deleteLater);
423410 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+ });
428425
429426 audioThread->start();
430427
@@ -457,7 +454,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 26 unmodified lines
457454 connect(nodeList.data(), &NodeList::uuidChanged, _myAvatar, &MyAvatar::setSessionUUID);
458455 connect(nodeList.data(), &NodeList::uuidChanged, this, &Application::setSessionUUID);
459456 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);
461459
462460 // connect to appropriate slots on AccountManager
463461 AccountManager& accountManager = AccountManager::getInstance();
@@ -537,7 +535,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 73 unmodified lines
537535 // the GL surface
538536 _glWidget->setCursor(Qt::BlankCursor);
539537 #endif
540−
538+
541539 // enable mouse tracking; otherwise, we only get drag events
542540 _glWidget->setMouseTracking(true);
543541
@@ -571,10 +569,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 27 unmodified lines
571569
572570 // hook up bandwidth estimator
573571 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);
578576
579577 connect(&_myAvatar->getSkeletonModel(), &SkeletonModel::skeletonLoaded,
580578 this, &Application::checkSkeleton, Qt::QueuedConnection);
@@ -606,7 +604,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 25 unmodified lines
606604 _settingsTimer.setSingleShot(false);
607605 _settingsTimer.setInterval(SAVE_SETTINGS_INTERVAL);
608606 _settingsThread.start();
609−
607+
610608 if (Menu::getInstance()->isOptionChecked(MenuOption::IndependentMode)) {
611609 Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, true);
612610 cameraMenuChanged();
@@ -637,10 +635,16 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 24 unmodified lines
637635 ddeTracker->init();
638636 connect(ddeTracker.data(), &FaceTracker::muteToggled, this, &Application::faceTrackerMuteToggled);
639637 #endif
640−
638+
641639 auto applicationUpdater = DependencyManager::get<AutoUpdater>();
642640 connect(applicationUpdater.data(), &AutoUpdater::newVersionIsAvailable, dialogsManager.data(), &DialogsManager::showUpdateDialog);
643641 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");
644648 }
645649
646650 void Application::aboutToQuit() {
@@ -653,8 +657,10 @@ void Application::aboutToQuit() { · 6 unmodified lines
653657 void Application::cleanupBeforeQuit() {
654658
655659 _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+
658664 _entities.shutdown(); // tell the entities system we're shutting down, so it will stop running scripts
659665 ScriptEngine::stopAllScripts(this); // stop all currently running global scripts
660666
@@ -731,12 +737,15 @@ Application::~Application() { · 70 unmodified lines
731737 DependencyManager::destroy<OffscreenUi>();
732738 DependencyManager::destroy<AvatarManager>();
733739 DependencyManager::destroy<AnimationCache>();
740+ DependencyManager::destroy<FramebufferCache>();
734741 DependencyManager::destroy<TextureCache>();
735742 DependencyManager::destroy<GeometryCache>();
736743 DependencyManager::destroy<ScriptCache>();
737744 DependencyManager::destroy<SoundCache>();
738745
739746 QThread* nodeThread = DependencyManager::get<NodeList>()->thread();
747+
748+ // remove the NodeList from the DependencyManager
740749 DependencyManager::destroy<NodeList>();
741750
742751 // ask the node thread to quit and wait until it is done
@@ -745,6 +754,7 @@ Application::~Application() { · 2 unmodified lines
745754
746755 Leapmotion::destroy();
747756 RealSense::destroy();
757+ ConnexionClient::destroy();
748758
749759 qInstallMessageHandler(NULL); // NOTE: Do this as late as possible so we continue to get our log messages
750760 }
@@ -762,32 +772,9 @@ void Application::initializeGL() { · 11 unmodified lines
762772 }
763773 #endif
764774
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>();
791778
792779 initDisplay();
793780 qCDebug(interfaceapp, "Initialized Display.");
@@ -876,8 +863,9 @@ void Application::paintGL() { · 82 unmodified lines
876863 _glWidget->makeCurrent();
877864
878865 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(),
881869 lodManager->getBoundaryLevelAdjust(), RenderArgs::DEFAULT_RENDER_MODE,
882870 RenderArgs::MONO, RenderArgs::RENDER_DEBUG_NONE);
883871
@@ -887,25 +875,56 @@ void Application::paintGL() { · 3 unmodified lines
887875 OculusManager::beginFrameTiming();
888876 }
889877
890−
878+
891879 PerformanceWarning::setSuppressShortTimings(Menu::getInstance()->isOptionChecked(MenuOption::SuppressShortTimings));
892880 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
893881 PerformanceWarning warn(showWarnings, "Application::paintGL()");
894882 resizeGL();
895883
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+
896909 {
897910 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());
898916 _applicationOverlay.renderOverlay(&renderArgs);
899917 }
900918
901− glEnable(GL_LINE_SMOOTH);
902−
903919 if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON || _myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) {
904920 Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, _myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN);
905921 Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, !(_myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN));
906922 Application::getInstance()->cameraMenuChanged();
907923 }
908924
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+
909928 if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) {
910929 // Always use the default eye position, not the actual head eye position.
911930 // Using the latter will cause the camera to wobble with idle animations,
@@ -942,6 +961,7 @@ void Application::paintGL() { · 30 unmodified lines
942961 glm::vec3(0, _raiseMirror * _myAvatar->getScale(), 0) +
943962 (_myAvatar->getOrientation() * glm::quat(glm::vec3(0.0f, _rotateMirror, 0.0f))) *
944963 glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_FULLSCREEN_DISTANCE * _scaleMirror);
964+ renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
945965 }
946966
947967 // Update camera position
@@ -949,17 +969,6 @@ void Application::paintGL() { · 1 unmodified line
949969 _myCamera.update(1.0f / _fps);
950970 }
951971
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−
963972 if (OculusManager::isConnected()) {
964973 //When in mirror mode, use camera rotation. Otherwise, use body rotation
965974 if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
@@ -971,40 +980,24 @@ void Application::paintGL() { · 5 unmodified lines
971980 TV3DManager::display(&renderArgs, _myCamera);
972981 } else {
973982 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−
980983 // 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();
983985 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();
990986
991− renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
992− if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
993− renderRearViewMirror(&renderArgs, _mirrorViewRect);
994− }
995987
996− renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE;
988+ displaySide(&renderArgs, _myCamera);
997989
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()));
999996
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+ }
10081001
10091002 _compositor.displayOverlayTexture(&renderArgs);
10101003 }
@@ -1019,7 +1012,15 @@ void Application::paintGL() { · 8 unmodified lines
10191012 OculusManager::endFrameTiming();
10201013 }
10211014 _frameCount++;
1015+ _numFramesSinceLastResize++;
10221016 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);
10231024 }
10241025
10251026 void Application::runTests() {
@@ -1072,13 +1073,11 @@ void Application::resizeGL() { · 46 unmodified lines
10721073 }
10731074
10741075 if (_renderResolution != toGlm(renderSize)) {
1076+ _numFramesSinceLastResize = 0;
10751077 _renderResolution = toGlm(renderSize);
1076− DependencyManager::get<TextureCache>()->setFrameBufferSize(renderSize);
1078+ DependencyManager::get<FramebufferCache>()->setFrameBufferSize(renderSize);
10771079
1078− glViewport(0, 0, _renderResolution.x, _renderResolution.y); // shouldn't this account for the menu???
1079−
1080− updateProjectionMatrix();
1081− glLoadIdentity();
1080+ loadViewFrustum(_myCamera, _viewFrustum);
10821081 }
10831082
10841083 resetCameras(_myCamera, _renderResolution);
@@ -1088,32 +1087,6 @@ void Application::resizeGL() { · 3 unmodified lines
10881087 auto canvasSize = _glWidget->size();
10891088 offscreenUi->resize(canvasSize);
10901089 _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− }
11171090 }
11181091
11191092 bool Application::importSVOFromURL(const QString& urlString) {
@@ -1262,12 +1235,6 @@ void Application::keyPressEvent(QKeyEvent* event) { · 142 unmodified lines
12621235 Menu::getInstance()->triggerOption(MenuOption::Stars);
12631236 break;
12641237
1265− case Qt::Key_W:
1266− if (isOption && !isShifted && !isMeta) {
1267− Menu::getInstance()->triggerOption(MenuOption::Wireframe);
1268− }
1269− break;
1270−
12711238 case Qt::Key_S:
12721239 if (isShifted && isMeta && !isOption) {
12731240 Menu::getInstance()->triggerOption(MenuOption::SuppressShortTimings);
@@ -1527,6 +1494,7 @@ void Application::focusOutEvent(QFocusEvent* event) { · 253 unmodified lines
15271494 _keyboardMouseDevice.focusOutEvent(event);
15281495 SixenseManager::getInstance().focusOutEvent();
15291496 SDL2Manager::getInstance()->focusOutEvent();
1497+ ConnexionData::getInstance().focusOutEvent();
15301498
15311499 // synthesize events for keys currently pressed, since we may not get their release events
15321500 foreach (int key, _keysPressed) {
@@ -1568,7 +1536,9 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { · 35 unmodified lines
15681536 return;
15691537 }
15701538
1571− _keyboardMouseDevice.mouseMoveEvent(event, deviceID);
1539+ if (deviceID == 0) {
1540+ _keyboardMouseDevice.mouseMoveEvent(event, deviceID);
1541+ }
15721542
15731543 }
15741544
@@ -1589,7 +1559,9 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { · 14 unmodified lines
15891559
15901560
15911561 if (activeWindow() == _window) {
1592− _keyboardMouseDevice.mousePressEvent(event);
1562+ if (deviceID == 0) {
1563+ _keyboardMouseDevice.mousePressEvent(event);
1564+ }
15931565
15941566 if (event->button() == Qt::LeftButton) {
15951567 _mouseDragStarted = getTrueMouse();
@@ -1629,7 +1601,9 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { · 33 unmodified lines
16291601 }
16301602
16311603 if (activeWindow() == _window) {
1632− _keyboardMouseDevice.mouseReleaseEvent(event);
1604+ if (deviceID == 0) {
1605+ _keyboardMouseDevice.mouseReleaseEvent(event);
1606+ }
16331607
16341608 if (event->button() == Qt::LeftButton) {
16351609 _mousePressed = false;
@@ -1775,10 +1749,21 @@ bool Application::acceptSnapshot(const QString& urlString) { · 139 unmodified lines
17751749 }
17761750
17771751 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+ });
17821767 }
17831768
17841769 // Every second, check the frame rates and other stuff
@@ -1791,7 +1776,6 @@ void Application::checkFPS() { · 6 unmodified lines
17911776
17921777 _fps = (float)_frameCount / diffTime;
17931778 _frameCount = 0;
1794− _datagramProcessor->resetCounters();
17951779 _timerStart.start();
17961780 }
17971781
@@ -1857,11 +1841,15 @@ void Application::idle() { · 59 unmodified lines
18571841 _idleLoopMeasuredJitter = _idleLoopStdev.getStDev();
18581842 _idleLoopStdev.reset();
18591843 }
1860−
18611844 }
1845+
18621846 // 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);
18651853 }
18661854
18671855 // check for any requested background downloads.
@@ -1944,7 +1932,6 @@ void Application::setEnableVRMode(bool enableVRMode) { · 76 unmodified lines
19441932 OculusManager::connect(_glWidget->context()->contextHandle());
19451933 _glWidget->setFocus();
19461934 _glWidget->makeCurrent();
1947− glClear(GL_COLOR_BUFFER_BIT);
19481935 }
19491936 OculusManager::recalibrate();
19501937 } else {
@@ -2035,13 +2022,6 @@ void Application::setActiveFaceTracker() { · 84 unmodified lines
20352022 #endif
20362023 }
20372024
2038−void Application::toggleFaceTrackerMute() {
2039− FaceTracker* faceTracker = getSelectedFaceTracker();
2040− if (faceTracker) {
2041− faceTracker->toggleMute();
2042− }
2043−}
2044−
20452025 bool Application::exportEntities(const QString& filename, const QVector<EntityItemID>& entityIDs) {
20462026 QVector<EntityItemPointer> entities;
20472027
@@ -2147,12 +2127,6 @@ QVector<EntityItemID> Application::pasteEntities(float x, float y, float z) { · 99 unmodified lines
21472127 }
21482128
21492129 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);
21562130 }
21572131
21582132 void Application::init() {
@@ -2162,7 +2136,6 @@ void Application::init() { · 3 unmodified lines
21622136 _environment.init();
21632137
21642138 DependencyManager::get<DeferredLightingEffect>()->init(this);
2165− DependencyManager::get<AmbientOcclusionEffect>()->init(this);
21662139
21672140 // TODO: move _myAvatar out of Application. Move relevant code to MyAvataar or AvatarManager
21682141 DependencyManager::get<AvatarManager>()->init();
@@ -2258,8 +2231,8 @@ void Application::shrinkMirrorView() { · 89 unmodified lines
22582231
22592232 const float HEAD_SPHERE_RADIUS = 0.1f;
22602233
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();
22632236 glm::vec3 myEyePosition = _myAvatar->getHead()->getEyePosition();
22642237 if (pointInSphere(theirLookAt, myEyePosition, HEAD_SPHERE_RADIUS * _myAvatar->getScale())) {
22652238 return true;
@@ -2323,7 +2296,7 @@ void Application::updateMyAvatarLookAtPosition() { · 57 unmodified lines
23232296 if (lookingAt && _myAvatar != lookingAt.get()) {
23242297 // If I am looking at someone else, look directly at one of their eyes
23252298 isLookingAtSomeone = true;
2326− Head* lookingAtHead = static_cast<Avatar*>(lookingAt.get())->getHead();
2299+ auto lookingAtHead = static_pointer_cast<Avatar>(lookingAt)->getHead();
23272300
23282301 const float MAXIMUM_FACE_ANGLE = 65.0f * RADIANS_PER_DEGREE;
23292302 glm::vec3 lookingAtFaceOrientation = lookingAtHead->getFinalOrientationInWorldFrame() * IDENTITY_FRONT;
@@ -2353,23 +2326,21 @@ void Application::updateMyAvatarLookAtPosition() { · 23 unmodified lines
23532326 lookAtSpot = _myAvatar->getHead()->getEyePosition() +
23542327 (_myAvatar->getHead()->getFinalOrientationInWorldFrame() * glm::vec3(0.0f, 0.0f, -TREE_SCALE));
23552328 }
2356− }
23572329
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))) *
23722342 glm::inverse(_myCamera.getRotation()) * (lookAtSpot - origin);
2343+ }
23732344 }
23742345
23752346 _myAvatar->getHead()->setLookAtPosition(lookAtSpot);
@@ -2438,6 +2409,12 @@ void Application::updateDialogs(float deltaTime) { · 62 unmodified lines
24382409 PerformanceWarning warn(showWarnings, "Application::updateDialogs()");
24392410 auto dialogsManager = DependencyManager::get<DialogsManager>();
24402411
2412+ // Update audio stats dialog, if any
2413+ AudioStatsDialog* audioStatsDialog = dialogsManager->getAudioStatsDialog();
2414+ if(audioStatsDialog) {
2415+ audioStatsDialog->update();
2416+ }
2417+
24412418 // Update bandwidth dialog, if any
24422419 BandwidthDialog* bandwidthDialog = dialogsManager->getBandwidthDialog();
24432420 if (bandwidthDialog) {
@@ -2474,7 +2451,13 @@ void Application::update(float deltaTime) { · 30 unmodified lines
24742451 {
24752452 PerformanceTimer perfTimer("devices");
24762453 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();
24782461 if (tracker && !tracker->isMuted()) {
24792462 tracker->update(deltaTime);
24802463
@@ -2518,10 +2501,18 @@ void Application::update(float deltaTime) { · 37 unmodified lines
25182501 _myAvatar->setDriveKeys(DOWN, _userInputMapper.getActionState(UserInputMapper::VERTICAL_DOWN));
25192502 _myAvatar->setDriveKeys(LEFT, _userInputMapper.getActionState(UserInputMapper::LATERAL_LEFT));
25202503 _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+ }
25252516 }
25262517 _myAvatar->setDriveKeys(BOOM_IN, _userInputMapper.getActionState(UserInputMapper::BOOM_IN));
25272518 _myAvatar->setDriveKeys(BOOM_OUT, _userInputMapper.getActionState(UserInputMapper::BOOM_OUT));
@@ -2642,7 +2633,7 @@ void Application::update(float deltaTime) { · 114 unmodified lines
26422633 _lastQueriedTime = now;
26432634
26442635 if (DependencyManager::get<SceneScriptingInterface>()->shouldRenderEntities()) {
2645− queryOctree(NodeType::EntityServer, PacketTypeEntityQuery, _entityServerJurisdictions);
2636+ queryOctree(NodeType::EntityServer, PacketType::EntityQuery, _entityServerJurisdictions);
26462637 }
26472638 _lastQueriedViewFrustum = _viewFrustum;
26482639 }
@@ -2675,16 +2666,17 @@ int Application::sendNackPackets() { · 26 unmodified lines
26752666 return 0;
26762667 }
26772668
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
26822670 auto nodeList = DependencyManager::get<NodeList>();
26832671
2672+ int packetsSent = 0;
2673+
26842674 nodeList->eachNode([&](const SharedNodePointer& node){
26852675
26862676 if (node->getActiveSocket() && node->getType() == NodeType::EntityServer) {
26872677
2678+ NLPacketList nackPacketList(PacketType::OctreeDataNack);
2679+
26882680 QUuid nodeUUID = node->getUUID();
26892681
26902682 // if there are octree packets from this node that are waiting to be processed,
@@ -2700,55 +2692,36 @@ int Application::sendNackPackets() { · 9 unmodified lines
27002692 _octreeSceneStatsLock.unlock();
27012693 return;
27022694 }
2703−
2695+
27042696 // get sequence number stats of node, prune its missing set, and make a copy of the missing set
27052697 SequenceNumberStats& sequenceNumberStats = _octreeServerSceneStats[nodeUUID].getIncomingOctreeSequenceNumberStats();
27062698 sequenceNumberStats.pruneMissingSet();
27072699 const QSet<OCTREE_PACKET_SEQUENCE> missingSequenceNumbers = sequenceNumberStats.getMissingSet();
2708−
2700+
27092701 _octreeSceneStatsLock.unlock();
2710−
2702+
27112703 // 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);
27442716 }
27452717 }
27462718 });
27472719
2720+
27482721 return packetsSent;
27492722 }
27502723
2751−void Application::queryOctree(NodeType_t serverType, PacketType packetType, NodeToJurisdictionMap& jurisdictions) {
2724+void Application::queryOctree(NodeType_t serverType, PacketType::Value packetType, NodeToJurisdictionMap& jurisdictions) {
27522725
27532726 //qCDebug(interfaceapp) << ">>> inside... queryOctree()... _viewFrustum.getFieldOfView()=" << _viewFrustum.getFieldOfView();
27542727 bool wantExtraDebugging = getLogger()->extraDebugging();
@@ -2771,9 +2744,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 16 unmodified lines
27712744 _octreeQuery.setOctreeSizeScale(lodManager->getOctreeSizeScale());
27722745 _octreeQuery.setBoundaryLevelAdjust(lodManager->getBoundaryLevelAdjust());
27732746
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...
27772748 int totalServers = 0;
27782749 int inViewServers = 0;
27792750 int unknownJurisdictionServers = 0;
@@ -2840,6 +2811,8 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 60 unmodified lines
28402811 qCDebug(interfaceapp, "perServerPPS: %d perUnknownServer: %d", perServerPPS, perUnknownServer);
28412812 }
28422813
2814+ auto queryPacket = NLPacket::create(packetType);
2815+
28432816 nodeList->eachNode([&](const SharedNodePointer& node){
28442817 // only send to the NodeTypes that are serverType
28452818 if (node->getActiveSocket() && node->getType() == serverType) {
@@ -2914,19 +2887,13 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 68 unmodified lines
29142887 } else {
29152888 _octreeQuery.setMaxQueryPacketsPerSecond(0);
29162889 }
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);
29252890
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);
29272894
29282895 // make sure we still have an active socket
2929− nodeList->writeUnverifiedDatagram(reinterpret_cast<const char*>(queryPacket), packetLength, node);
2896+ nodeList->sendUnreliablePacket(*queryPacket, *node);
29302897 }
29312898 });
29322899 }
@@ -2990,169 +2957,6 @@ glm::vec3 Application::getSunDirection() { · 57 unmodified lines
29902957 // FIXME, preprocessor guard this check to occur only in DEBUG builds
29912958 static QThread * activeRenderingThread = nullptr;
29922959
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−
31562960 bool Application::shouldRenderMesh(float largestDimension, float distanceToCamera) {
31572961 return DependencyManager::get<LODManager>()->shouldRenderMesh(largestDimension, distanceToCamera);
31582962 }
@@ -3173,35 +2977,25 @@ PickRay Application::computePickRay(float x, float y) const { · 14 unmodified lines
31732977 if (isHMDMode()) {
31742978 getApplicationCompositor().computeHmdPickRay(glm::vec2(x, y), result.origin, result.direction);
31752979 } 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);
31812981 }
31822982 return result;
31832983 }
31842984
31852985 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);
31942986
31952987 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();
32002996 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);
32032998
3204− glBindFramebuffer(GL_FRAMEBUFFER, 0);
32052999 return image;
32063000 }
32073001
@@ -3306,9 +3100,6 @@ namespace render { · 98 unmodified lines
33063100 PerformanceTimer perfTimer("stars");
33073101 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
33083102 "Application::payloadRender<BackgroundRenderData>() ... stars...");
3309− if (!background->_stars.isStarsLoaded()) {
3310− background->_stars.generate(STARFIELD_NUM_STARS, STARFIELD_SEED);
3311− }
33123103 // should be the first rendering pass - w/o depth buffer / lighting
33133104
33143105 // compute starfield alpha based on distance from atmosphere
@@ -3336,7 +3127,7 @@ namespace render { · 21 unmodified lines
33363127 + APPROXIMATE_DISTANCE_FROM_HORIZON;
33373128 alpha = (directionY / DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON);
33383129 }
3339−
3130+
33403131
33413132 } else if (height < closestData.getAtmosphereOuterRadius()) {
33423133 alpha = (height - closestData.getAtmosphereInnerRadius()) /
@@ -3356,7 +3147,7 @@ namespace render { · 13 unmodified lines
33563147
33573148 // finally render the starfield
33583149 if (hasStars) {
3359− background->_stars.render(args->_viewFrustum->getFieldOfView(), args->_viewFrustum->getAspectRatio(), args->_viewFrustum->getNearClip(), alpha);
3150+ background->_stars.render(args, alpha);
33603151 }
33613152
33623153 // draw the sky dome
@@ -3371,16 +3162,12 @@ namespace render { · 8 unmodified lines
33713162 }
33723163 } else if (skyStage->getBackgroundMode() == model::SunSkyStage::SKY_BOX) {
33733164 PerformanceTimer perfTimer("skybox");
3374−
3165+
33753166 skybox = skyStage->getSkybox();
33763167 if (skybox) {
33773168 model::Skybox::render(batch, *(Application::getInstance()->getDisplayViewFrustum()), *skybox);
33783169 }
33793170 }
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);
33843171 }
33853172 }
33863173
@@ -3400,76 +3187,22 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 13 unmodified lines
34003187 // load the view frustum
34013188 loadViewFrustum(theCamera, _displayViewFrustum);
34023189
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
34503191
34513192 // The pending changes collecting the changes here
34523193 render::PendingChanges pendingChanges;
34533194
34543195 // Background rendering decision
34553196 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);
34583199 BackgroundRenderData::_item = _main3DScene->allocateID();
34593200 pendingChanges.resetItem(WorldBoxRenderData::_item, backgroundRenderPayload);
34603201 } else {
34613202
34623203 }
34633204
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−
34713205 // Assuming nothing get's rendered through that
3472−
34733206 if (!selfAvatarOnly) {
34743207 if (DependencyManager::get<SceneScriptingInterface>()->shouldRenderEntities()) {
34753208 // render models...
@@ -3489,20 +3222,12 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 13 unmodified lines
34893222 renderArgs->_debugFlags = renderDebugFlags;
34903223 _entities.render(renderArgs);
34913224 }
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− }
35003225 }
35013226
35023227 // Make sure the WorldBox is in the scene
35033228 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);
35063231
35073232 WorldBoxRenderData::_item = _main3DScene->allocateID();
35083233
@@ -3554,6 +3279,9 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 45 unmodified lines
35543279 renderContext._maxDrawnOverlay3DItems = sceneInterface->getEngineMaxDrawnOverlay3DItems();
35553280
35563281 renderContext._drawItemStatus = sceneInterface->doEngineDisplayItemStatus();
3282+ renderContext._drawHitEffect = sceneInterface->doEngineDisplayHitEffect();
3283+
3284+ renderContext._occlusionStatus = Menu::getInstance()->isOptionChecked(MenuOption::DebugAmbientOcclusion);
35573285
35583286 renderArgs->_shouldRender = LODManager::shouldRender;
35593287
@@ -3563,7 +3291,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 3 unmodified lines
35633291
35643292 // Before the deferred pass, let's try to use the render engine
35653293 _renderEngine->run();
3566−
3294+
35673295 auto engineRC = _renderEngine->getRenderContext();
35683296 sceneInterface->setEngineFeedOpaqueItems(engineRC->_numFeedOpaqueItems);
35693297 sceneInterface->setEngineDrawnOpaqueItems(engineRC->_numDrawnOpaqueItems);
@@ -3574,10 +3302,6 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 4 unmodified lines
35743302 sceneInterface->setEngineFeedOverlay3DItems(engineRC->_numFeedOverlay3DItems);
35753303 sceneInterface->setEngineDrawnOverlay3DItems(engineRC->_numDrawnOverlay3DItems);
35763304 }
3577− //Render the sixense lasers
3578− if (Menu::getInstance()->isOptionChecked(MenuOption::SixenseLasers)) {
3579− _myAvatar->renderLaserPointers(*renderArgs->_batch);
3580− }
35813305
35823306 if (!selfAvatarOnly) {
35833307 // give external parties a change to hook in
@@ -3587,37 +3311,9 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 3 unmodified lines
35873311 }
35883312 }
35893313
3590− if (Menu::getInstance()->isOptionChecked(MenuOption::Wireframe)) {
3591− glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
3592− }
3593−
35943314 activeRenderingThread = nullptr;
35953315 }
35963316
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−
36213317 void Application::computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal,
36223318 float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const {
36233319
@@ -3668,9 +3364,9 @@ glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) { · 44 unmodified lines
36683364 }
36693365
36703366 void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& region, bool billboard) {
3367+ auto originalViewport = renderArgs->_viewport;
36713368 // Grab current viewport to reset it at the end
3672− int viewport[4];
3673− glGetIntegerv(GL_VIEWPORT, viewport);
3369+
36743370 float aspect = (float)region.width() / region.height();
36753371 float fov = MIRROR_FIELD_OF_VIEW;
36763372
@@ -3701,43 +3397,30 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi · 24 unmodified lines
37013397 // This was removed in commit 71e59cfa88c6563749594e25494102fe01db38e9 but could be further
37023398 // investigated in order to adapt the technique while fixing the head rendering issue,
37033399 // but the complexity of the hack suggests that a better approach
3704− _mirrorCamera.setPosition(_myAvatar->getHead()->getEyePosition() +
3400+ _mirrorCamera.setPosition(_myAvatar->getDefaultEyePosition() +
37053401 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_DISTANCE * _myAvatar->getScale());
37063402 }
37073403 _mirrorCamera.setProjection(glm::perspective(glm::radians(fov), aspect, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP));
37083404 _mirrorCamera.setRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f)));
37093405
3406+
37103407 // set the bounds of rear mirror view
3408+ gpu::Vec4i viewport;
37113409 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());
37163411 } else {
37173412 // if not rendering the billboard, the region is in device independent coordinates; must convert to device
3718− QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize();
37193413 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);
37253417 }
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;
37303419
37313420 // render rear mirror view
3732− glPushMatrix();
37333421 displaySide(renderArgs, _mirrorCamera, true, billboard);
3734− glPopMatrix();
37353422
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;
37413424 }
37423425
37433426 void Application::resetSensors() {
@@ -3824,11 +3507,24 @@ void Application::domainChanged(const QString& domainHostname) { · 80 unmodified lines
38243507 _domainConnectionRefusals.clear();
38253508 }
38263509
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+
38283522 if (!_domainConnectionRefusals.contains(reason)) {
38293523 _domainConnectionRefusals.append(reason);
38303524 emit domainConnectionRefused(reason);
38313525 }
3526+
3527+ AccountManager::getInstance().checkAndSignalForAccessToken();
38323528 }
38333529
38343530 void Application::connectedToDomain(const QString& hostname) {
@@ -3893,12 +3589,12 @@ void Application::nodeKilled(SharedNodePointer node) { · 58 unmodified lines
38933589 DependencyManager::get<AvatarManager>()->clearOtherAvatars();
38943590 }
38953591 }
3896−
3897−void Application::trackIncomingOctreePacket(const QByteArray& packet, const SharedNodePointer& sendingNode, bool wasStatsPacket) {
3592+
3593+void Application::trackIncomingOctreePacket(NLPacket& packet, SharedNodePointer sendingNode, bool wasStatsPacket) {
38983594
38993595 // Attempt to identify the sender from its address.
39003596 if (sendingNode) {
3901− QUuid nodeUUID = sendingNode->getUUID();
3597+ const QUuid& nodeUUID = sendingNode->getUUID();
39023598
39033599 // now that we know the node ID, let's add these stats to the stats for that node...
39043600 _octreeSceneStatsLock.lockForWrite();
@@ -3910,60 +3606,54 @@ void Application::trackIncomingOctreePacket(const QByteArray& packet, const Shar · 5 unmodified lines
39103606 }
39113607 }
39123608
3913−int Application::parseOctreeStats(const QByteArray& packet, const SharedNodePointer& sendingNode) {
3609+int Application::processOctreeStats(NLPacket& packet, SharedNodePointer sendingNode) {
39143610 // But, also identify the sender, and keep track of the contained jurisdiction root for this server
39153611
39163612 // parse the incoming stats datas stick it in a temporary object for now, while we
39173613 // 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;
39203615
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();
39243625
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+ }
39343633
3634+ jurisdiction->lockForRead();
3635+ if (jurisdiction->find(nodeUUID) == jurisdiction->end()) {
3636+ jurisdiction->unlock();
3637+
39353638 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);
39533640
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 {
39653645 jurisdiction->unlock();
39663646 }
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+
39673657 return statsMessageLength;
39683658 }
39693659
@@ -4103,10 +3793,13 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 133 unmodified lines
41033793
41043794 // when the worker thread is started, call our engine's run..
41053795 connect(workerThread, &QThread::started, scriptEngine, &ScriptEngine::run);
4106−
3796+
41073797 // 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);
41103803
41113804 auto nodeList = DependencyManager::get<NodeList>();
41123805 connect(nodeList.data(), &NodeList::nodeKilled, scriptEngine, &ScriptEngine::nodeKilled);
@@ -4596,6 +4289,10 @@ void Application::setVSyncEnabled() { · 483 unmodified lines
45964289 #endif
45974290 }
45984291
4292+void Application::setThrottleFPSEnabled() {
4293+ _isThrottleFPSEnabled = Menu::getInstance()->isOptionChecked(MenuOption::ThrottleFPSIfNotFocus);
4294+}
4295+
45994296 bool Application::isVSyncOn() const {
46004297 #if defined(Q_OS_WIN)
46014298 if (wglewGetExtension("WGL_EXT_swap_control")) {
@@ -4742,7 +4439,11 @@ void Application::friendsWindowClosed() { · 140 unmodified lines
47424439 }
47434440
47444441 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+ }
47464447 }
47474448
47484449 void Application::initPlugins() {
@@ -4803,7 +4504,7 @@ mat4 Application::getEyeProjection(int eye) const { · 54 unmodified lines
48034504 if (isHMDMode()) {
48044505 return OculusManager::getEyeProjection(eye);
48054506 }
4806−
4507+
48074508 return _viewFrustum.getProjection();
48084509 }
48094510

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t