History

Merge branch 'master' of https://github.com/highfidelity/hifi into correct-target-frame-rate

Howard Stearns committed 10 years ago

Commit fa0ad1f2 parents d51785a 5bbff75216 files · +2817 −2540Browse files

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

Unified · Split

interface/src/Application.cpp+60−67
@@ -44,6 +44,9 @@ · 43 unmodified lines
4444
4545 #include <QtNetwork/QNetworkDiskCache>
4646
47+#include <gl/Config.h>
48+#include <QtGui/QOpenGLContext>
49+
4750 #include <AccountManager.h>
4851 #include <AddressManager.h>
4952 #include <ApplicationVersion.h>
@@ -110,8 +113,6 @@ · 60 unmodified lines
110113 #include "devices/EyeTracker.h"
111114 #include "devices/Faceshift.h"
112115 #include "devices/Leapmotion.h"
113−#include "devices/MIDIManager.h"
114−#include "devices/RealSense.h"
115116 #include "DiscoverabilityManager.h"
116117 #include "GLCanvas.h"
117118 #include "InterfaceActionFactory.h"
@@ -149,6 +150,8 @@ · 31 unmodified lines
149150 #include "ui/Stats.h"
150151 #include "ui/UpdateDialog.h"
151152 #include "Util.h"
153+#include "InterfaceParentFinder.h"
154+
152155
153156
154157 // ON WIndows PC, NVidia Optimus laptop, we want to enable NVIDIA GPU
@@ -297,6 +300,7 @@ bool setupEssentials(int& argc, char** argv) { · 142 unmodified lines
297300 DependencyManager::registerInheritance<LimitedNodeList, NodeList>();
298301 DependencyManager::registerInheritance<AvatarHashMap, AvatarManager>();
299302 DependencyManager::registerInheritance<EntityActionFactoryInterface, InterfaceActionFactory>();
303+ DependencyManager::registerInheritance<SpatialParentFinder, InterfaceParentFinder>();
300304
301305 Setting::init();
302306
@@ -345,6 +349,7 @@ bool setupEssentials(int& argc, char** argv) { · 42 unmodified lines
345349 DependencyManager::set<MessagesClient>();
346350 DependencyManager::set<UserInputMapper>();
347351 DependencyManager::set<controller::ScriptingInterface, ControllerScriptingInterface>();
352+ DependencyManager::set<InterfaceParentFinder>();
348353 return true;
349354 }
350355
@@ -615,6 +620,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 264 unmodified lines
615620
616621 // enable mouse tracking; otherwise, we only get drag events
617622 _glWidget->setMouseTracking(true);
623+ _glWidget->makeCurrent();
624+ _glWidget->initializeGL();
618625
619626 _offscreenContext = new OffscreenGLCanvas();
620627 _offscreenContext->create(_glWidget->context()->contextHandle());
@@ -719,12 +726,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : · 98 unmodified lines
719726 // set the local loopback interface for local sounds from audio scripts
720727 AudioScriptingInterface::getInstance().setLocalAudioInterface(audioIO.data());
721728
722−#ifdef HAVE_RTMIDI
723− // setup the MIDIManager
724− MIDIManager& midiManagerInstance = MIDIManager::getInstance();
725− midiManagerInstance.openDefaultPort();
726−#endif
727−
728729 this->installEventFilter(this);
729730
730731 // initialize our face trackers after loading the menu settings
@@ -970,7 +971,6 @@ Application::~Application() { · 239 unmodified lines
970971 nodeThread->wait();
971972
972973 Leapmotion::destroy();
973− RealSense::destroy();
974974
975975 #if 0
976976 ConnexionClient::getInstance().destroy();
@@ -1141,7 +1141,7 @@ void Application::paintGL() { · 164 unmodified lines
11411141 _lastInstantaneousFps = instantaneousFps;
11421142
11431143 auto displayPlugin = getActiveDisplayPlugin();
1144− displayPlugin->preRender();
1144+ // FIXME not needed anymore?
11451145 _offscreenContext->makeCurrent();
11461146
11471147 // update the avatar with a fresh HMD pose
@@ -1196,6 +1196,9 @@ void Application::paintGL() { · 48 unmodified lines
11961196 QSize size = getDeviceSize();
11971197 renderArgs._viewport = glm::ivec4(0, 0, size.width(), size.height());
11981198 _applicationOverlay.renderOverlay(&renderArgs);
1199+ gpu::FramebufferPointer overlayFramebuffer = _applicationOverlay.getOverlayFramebuffer();
1200+
1201+
11991202 }
12001203
12011204 {
@@ -1250,7 +1253,7 @@ void Application::paintGL() { · 48 unmodified lines
12501253 * glm::quat(glm::vec3(0.0f, PI + _rotateMirror, 0.0f)) * hmdRotation);
12511254 glm::vec3 hmdOffset = extractTranslation(myAvatar->getHMDSensorMatrix());
12521255 _myCamera.setPosition(myAvatar->getDefaultEyePosition()
1253− + glm::vec3(0, _raiseMirror * myAvatar->getScale(), 0)
1256+ + glm::vec3(0, _raiseMirror * myAvatar->getAvatarScale(), 0)
12541257 + (myAvatar->getOrientation() * glm::quat(glm::vec3(0.0f, _rotateMirror, 0.0f))) *
12551258 glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_FULLSCREEN_DISTANCE * _scaleMirror
12561259 + (myAvatar->getOrientation() * glm::quat(glm::vec3(0.0f, PI + _rotateMirror, 0.0f))) * hmdOffset);
@@ -1258,7 +1261,7 @@ void Application::paintGL() { · 1 unmodified line
12581261 _myCamera.setRotation(myAvatar->getWorldAlignedOrientation()
12591262 * glm::quat(glm::vec3(0.0f, PI + _rotateMirror, 0.0f)));
12601263 _myCamera.setPosition(myAvatar->getDefaultEyePosition()
1261− + glm::vec3(0, _raiseMirror * myAvatar->getScale(), 0)
1264+ + glm::vec3(0, _raiseMirror * myAvatar->getAvatarScale(), 0)
12621265 + (myAvatar->getOrientation() * glm::quat(glm::vec3(0.0f, _rotateMirror, 0.0f))) *
12631266 glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_FULLSCREEN_DISTANCE * _scaleMirror);
12641267 }
@@ -1309,6 +1312,13 @@ void Application::paintGL() { · 44 unmodified lines
13091312 auto baseProjection = renderArgs._viewFrustum->getProjection();
13101313 auto hmdInterface = DependencyManager::get<HMDScriptingInterface>();
13111314 float IPDScale = hmdInterface->getIPDScale();
1315+
1316+ // Tell the plugin what pose we're using to render. In this case we're just using the
1317+ // unmodified head pose because the only plugin that cares (the Oculus plugin) uses it
1318+ // for rotational timewarp. If we move to support positonal timewarp, we need to
1319+ // ensure this contains the full pose composed with the eye offsets.
1320+ mat4 headPose = displayPlugin->getHeadPose(_frameCount);
1321+
13121322 // FIXME we probably don't need to set the projection matrix every frame,
13131323 // only when the display plugin changes (or in non-HMD modes when the user
13141324 // changes the FOV manually, which right now I don't think they can.
@@ -1324,12 +1334,7 @@ void Application::paintGL() { · 9 unmodified lines
13241334 mat4 eyeOffsetTransform = glm::translate(mat4(), eyeOffset * -1.0f * IPDScale);
13251335 eyeOffsets[eye] = eyeOffsetTransform;
13261336
1327− // Tell the plugin what pose we're using to render. In this case we're just using the
1328− // unmodified head pose because the only plugin that cares (the Oculus plugin) uses it
1329− // for rotational timewarp. If we move to support positonal timewarp, we need to
1330− // ensure this contains the full pose composed with the eye offsets.
1331− mat4 headPose = displayPlugin->getHeadPose();
1332− displayPlugin->setEyeRenderPose(eye, headPose);
1337+ displayPlugin->setEyeRenderPose(_frameCount, eye, headPose);
13331338
13341339 eyeProjections[eye] = displayPlugin->getProjection(eye, baseProjection);
13351340 });
@@ -1344,6 +1349,7 @@ void Application::paintGL() { · 8 unmodified lines
13441349 }
13451350
13461351 // Overlay Composition, needs to occur after screen space effects have completed
1352+ // FIXME migrate composition into the display plugins
13471353 {
13481354 PROFILE_RANGE(__FUNCTION__ "/compositor");
13491355 PerformanceTimer perfTimer("compositor");
@@ -1372,44 +1378,40 @@ void Application::paintGL() { · 22 unmodified lines
13721378 {
13731379 PROFILE_RANGE(__FUNCTION__ "/pluginOutput");
13741380 PerformanceTimer perfTimer("pluginOutput");
1375− auto primaryFbo = framebufferCache->getPrimaryFramebuffer();
1376− GLuint finalTexture = gpu::GLBackend::getTextureID(primaryFbo->getRenderBuffer(0));
1377− // Ensure the rendering context commands are completed when rendering
1378− GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
1379− // Ensure the sync object is flushed to the driver thread before releasing the context
1380− // CRITICAL for the mac driver apparently.
1381− glFlush();
1382− _offscreenContext->doneCurrent();
1383−
1384− // Switches to the display plugin context
1385− displayPlugin->preDisplay();
1386− // Ensure all operations from the previous context are complete before we try to read the fbo
1387− glWaitSync(sync, 0, GL_TIMEOUT_IGNORED);
1388− glDeleteSync(sync);
1389− uint64_t displayStart = usecTimestampNow();
1381+ auto primaryFramebuffer = framebufferCache->getPrimaryFramebuffer();
1382+ auto scratchFramebuffer = framebufferCache->getFramebuffer();
1383+ gpu::doInBatch(renderArgs._context, [=](gpu::Batch& batch) {
1384+ gpu::Vec4i rect;
1385+ rect.z = size.width();
1386+ rect.w = size.height();
1387+ batch.setFramebuffer(scratchFramebuffer);
1388+ batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0f, 0.0f, 0.0f, 0.0f));
1389+ batch.blit(primaryFramebuffer, rect, scratchFramebuffer, rect);
1390+ batch.setFramebuffer(nullptr);
1391+ });
1392+ auto finalTexturePointer = scratchFramebuffer->getRenderBuffer(0);
1393+ GLuint finalTexture = gpu::GLBackend::getTextureID(finalTexturePointer);
1394+ Q_ASSERT(0 != finalTexture);
13901395
1391− {
1392− PROFILE_RANGE(__FUNCTION__ "/pluginDisplay");
1393− PerformanceTimer perfTimer("pluginDisplay");
1394− displayPlugin->display(finalTexture, toGlm(size));
1395− }
1396+ Q_ASSERT(!_lockedFramebufferMap.contains(finalTexture));
1397+ _lockedFramebufferMap[finalTexture] = scratchFramebuffer;
13961398
1399+ uint64_t displayStart = usecTimestampNow();
1400+ Q_ASSERT(QOpenGLContext::currentContext() == _offscreenContext->getContext());
13971401 {
1398− PROFILE_RANGE(__FUNCTION__ "/bufferSwap");
1399− PerformanceTimer perfTimer("bufferSwap");
1400− displayPlugin->finishFrame();
1402+ PROFILE_RANGE(__FUNCTION__ "/pluginSubmitScene");
1403+ PerformanceTimer perfTimer("pluginSubmitScene");
1404+ displayPlugin->submitSceneTexture(_frameCount, finalTexture, toGlm(size));
14011405 }
1406+ Q_ASSERT(QOpenGLContext::currentContext() == _offscreenContext->getContext());
1407+
14021408 uint64_t displayEnd = usecTimestampNow();
14031409 const float displayPeriodUsec = (float)(displayEnd - displayStart); // usecs
14041410 _lastPaintWait = displayPeriodUsec / (float)USECS_PER_SECOND;
1405−
14061411 }
14071412
14081413 {
1409− PerformanceTimer perfTimer("makeCurrent");
1410− _offscreenContext->makeCurrent();
14111414 Stats::getInstance()->setRenderDetails(renderArgs._details);
1412−
14131415 // Reset the gpu::Context Stages
14141416 // Back to the default framebuffer;
14151417 gpu::doInBatch(renderArgs._context, [=](gpu::Batch& batch) {
@@ -2519,7 +2521,6 @@ void Application::init() { · 1103 unmodified lines
25192521 qCDebug(interfaceapp) << "Loaded settings";
25202522
25212523 Leapmotion::init();
2522− RealSense::init();
25232524
25242525 // fire off an immediate domain-server check in now that settings are loaded
25252526 DependencyManager::get<NodeList>()->sendDomainServerCheckIn();
@@ -2618,7 +2619,7 @@ void Application::updateMyAvatarLookAtPosition() { · 92 unmodified lines
26182619 lookAtPosition.x = -lookAtPosition.x;
26192620 }
26202621 if (isHMD) {
2621− glm::mat4 headPose = getActiveDisplayPlugin()->getHeadPose();
2622+ glm::mat4 headPose = getActiveDisplayPlugin()->getHeadPose(_frameCount);
26222623 glm::quat hmdRotation = glm::quat_cast(headPose);
26232624 lookAtSpot = _myCamera.getPosition() + myAvatar->getOrientation() * (hmdRotation * lookAtPosition);
26242625 } else {
@@ -3075,6 +3076,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 450 unmodified lines
30753076 // These will be the same for all servers, so we can set them up once and then reuse for each server we send to.
30763077 _octreeQuery.setWantLowResMoving(true);
30773078 _octreeQuery.setWantDelta(true);
3079+ _octreeQuery.setWantCompression(true);
30783080
30793081 _octreeQuery.setCameraPosition(_viewFrustum.getPosition());
30803082 _octreeQuery.setCameraOrientation(_viewFrustum.getOrientation());
@@ -3322,7 +3324,7 @@ MyAvatar* Application::getMyAvatar() const { · 241 unmodified lines
33223324 return DependencyManager::get<AvatarManager>()->getMyAvatar();
33233325 }
33243326
3325−const glm::vec3& Application::getAvatarPosition() const {
3327+glm::vec3 Application::getAvatarPosition() const {
33263328 return getMyAvatar()->getPosition();
33273329 }
33283330
@@ -4069,10 +4071,6 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 740 unmodified lines
40694071 scriptEngine->registerGlobalObject("Scene", DependencyManager::get<SceneScriptingInterface>().data());
40704072
40714073 scriptEngine->registerGlobalObject("ScriptDiscoveryService", this->getRunningScriptsWidget());
4072−
4073−#ifdef HAVE_RTMIDI
4074− scriptEngine->registerGlobalObject("MIDI", &MIDIManager::getInstance());
4075−#endif
40764074 }
40774075
40784076 bool Application::canAcceptURL(const QString& urlString) {
@@ -4520,7 +4518,7 @@ void Application::takeSnapshot() { · 441 unmodified lines
45204518 player->setMedia(QUrl::fromLocalFile(inf.absoluteFilePath()));
45214519 player->play();
45224520
4523− QString fileName = Snapshot::saveSnapshot(_glWidget->grabFrameBuffer());
4521+ QString fileName = Snapshot::saveSnapshot(getActiveDisplayPlugin()->getScreenshot());
45244522
45254523 AccountManager& accountManager = AccountManager::getInstance();
45264524 if (!accountManager.isLoggedIn()) {
@@ -4531,7 +4529,6 @@ void Application::takeSnapshot() { · 4 unmodified lines
45314529 _snapshotShareDialog = new SnapshotShareDialog(fileName, _glWidget);
45324530 }
45334531 _snapshotShareDialog->show();
4534−
45354532 }
45364533
45374534 float Application::getRenderResolutionScale() const {
@@ -4714,10 +4711,6 @@ const DisplayPlugin* Application::getActiveDisplayPlugin() const { · 176 unmodified lines
47144711 return ((Application*)this)->getActiveDisplayPlugin();
47154712 }
47164713
4717−bool _activatingDisplayPlugin{ false };
4718−QVector<QPair<QString, QString>> _currentDisplayPluginActions;
4719−QVector<QPair<QString, QString>> _currentInputPluginActions;
4720−
47214714 static void addDisplayPluginToMenu(DisplayPluginPointer displayPlugin, bool active = false) {
47224715 auto menu = Menu::getInstance();
47234716 QString name = displayPlugin->getName();
@@ -4747,9 +4740,10 @@ void Application::updateDisplayMode() { · 23 unmodified lines
47474740 bool first = true;
47484741 foreach(auto displayPlugin, displayPlugins) {
47494742 addDisplayPluginToMenu(displayPlugin, first);
4750− QObject::connect(displayPlugin.get(), &DisplayPlugin::requestRender, [this] {
4751− paintGL();
4752− });
4743+ // This must be a queued connection to avoid a deadlock
4744+ QObject::connect(displayPlugin.get(), &DisplayPlugin::requestRender,
4745+ this, &Application::paintGL, Qt::QueuedConnection);
4746+
47534747 QObject::connect(displayPlugin.get(), &DisplayPlugin::recommendedFramebufferSizeChanged, [this](const QSize & size) {
47544748 resizeGL();
47554749 });
@@ -4791,19 +4785,18 @@ void Application::updateDisplayMode() { · 35 unmodified lines
47914785 return;
47924786 }
47934787
4794− if (!_currentDisplayPluginActions.isEmpty()) {
4788+
4789+ if (!_pluginContainer->currentDisplayActions().isEmpty()) {
47954790 auto menu = Menu::getInstance();
4796− foreach(auto itemInfo, _currentDisplayPluginActions) {
4791+ foreach(auto itemInfo, _pluginContainer->currentDisplayActions()) {
47974792 menu->removeMenuItem(itemInfo.first, itemInfo.second);
47984793 }
4799− _currentDisplayPluginActions.clear();
4794+ _pluginContainer->currentDisplayActions().clear();
48004795 }
48014796
48024797 if (newDisplayPlugin) {
48034798 _offscreenContext->makeCurrent();
4804− _activatingDisplayPlugin = true;
48054799 newDisplayPlugin->activate();
4806− _activatingDisplayPlugin = false;
48074800 _offscreenContext->makeCurrent();
48084801 offscreenUi->resize(fromGlm(newDisplayPlugin->getRecommendedUiSize()));
48094802 _offscreenContext->makeCurrent();
@@ -4929,7 +4922,7 @@ mat4 Application::getEyeOffset(int eye) const { · 119 unmodified lines
49294922
49304923 mat4 Application::getHMDSensorPose() const {
49314924 if (isHMDMode()) {
4932− return getActiveDisplayPlugin()->getHeadPose();
4925+ return getActiveDisplayPlugin()->getHeadPose(_frameCount);
49334926 }
49344927 return mat4();
49354928 }

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