History

Merge branch 'master' into plugins

Bradley Austin Davis committed 11 years ago

Commit a60e6692 parents 901dd77 939638a44 files · +554 −196Browse files

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

Unified · Split

interface/src/Application.cpp+86−76
@@ -921,6 +921,30 @@ void Application::paintGL() { · 920 unmodified lines
921921 PerformanceWarning warn(showWarnings, "Application::paintGL()");
922922 resizeGL();
923923
924+ // Before anything else, let's sync up the gpuContext with the true glcontext used in case anything happened
925+ renderArgs._context->syncCache();
926+
927+ if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
928+ auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferDepthColor();
929+
930+ renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
931+ renderRearViewMirror(&renderArgs, _mirrorViewRect);
932+ renderArgs._renderMode = RenderArgs::DEFAULT_RENDER_MODE;
933+
934+ {
935+ float ratio = ((float)QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale());
936+ auto mirrorViewport = glm::ivec4(0, 0, _mirrorViewRect.width() * ratio, _mirrorViewRect.height() * ratio);
937+ auto mirrorViewportDest = mirrorViewport;
938+
939+ auto selfieFbo = DependencyManager::get<FramebufferCache>()->getSelfieFramebuffer();
940+ gpu::Batch batch;
941+ batch.setFramebuffer(selfieFbo);
942+ batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0f, 0.0f, 0.0f, 0.0f));
943+ batch.blit(primaryFbo, mirrorViewport, selfieFbo, mirrorViewportDest);
944+ batch.setFramebuffer(nullptr);
945+ renderArgs._context->render(batch);
946+ }
947+ }
924948
925949 {
926950 PerformanceTimer perfTimer("renderOverlay");
@@ -937,10 +961,14 @@ void Application::paintGL() { · 10 unmodified lines
937961 Application::getInstance()->cameraMenuChanged();
938962 }
939963
964+ // The render mode is default or mirror if the camera is in mirror mode, assigned further below
965+ renderArgs._renderMode = RenderArgs::DEFAULT_RENDER_MODE;
966+
940967 if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) {
941968 // Always use the default eye position, not the actual head eye position.
942969 // Using the latter will cause the camera to wobble with idle animations,
943970 // or with changes from the face tracker
971+ renderArgs._renderMode = RenderArgs::DEFAULT_RENDER_MODE;
944972
945973 _myCamera.setPosition(_myAvatar->getDefaultEyePosition());
946974 if (!getActiveDisplayPlugin()->isHmd()) {
@@ -970,6 +998,7 @@ void Application::paintGL() { · 23 unmodified lines
970998 glm::vec3(0, _raiseMirror * _myAvatar->getScale(), 0) +
971999 (_myAvatar->getOrientation() * glm::quat(glm::vec3(0.0f, _rotateMirror, 0.0f))) *
9721000 glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_FULLSCREEN_DISTANCE * _scaleMirror);
1001+ renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
9731002 }
9741003
9751004 // Update camera position
@@ -977,17 +1006,15 @@ void Application::paintGL() { · 1 unmodified line
9771006 _myCamera.update(1.0f / _fps);
9781007 }
9791008
980− // Sync up the View Furstum with the camera
981− loadViewFrustum(_myCamera, _viewFrustum);
982−
983−
984− renderArgs._renderMode = RenderArgs::DEFAULT_RENDER_MODE;
9851009
9861010 // Primary rendering pass
9871011 auto framebufferCache = DependencyManager::get<FramebufferCache>();
9881012 QSize size = framebufferCache->getFrameBufferSize();
9891013 {
9901014 PROFILE_RANGE(__FUNCTION__ "/mainRender");
1015+ // Viewport is assigned to the size of the framebuffer
1016+ QSize size = DependencyManager::get<FramebufferCache>()->getFrameBufferSize();
1017+ renderArgs._viewport = glm::ivec4(0, 0, size.width(), size.height());
9911018
9921019 {
9931020 PROFILE_RANGE(__FUNCTION__ "/clear");
@@ -1019,12 +1046,6 @@ void Application::paintGL() { · 25 unmodified lines
10191046 batch.setStateScissorRect(renderArgs._viewport);
10201047 });
10211048 displaySide(&renderArgs, eyeCamera);
1022− if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror) &&
1023− !Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) {
1024−// renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
1025−// renderRearViewMirror(&renderArgs, _mirrorViewRect);
1026−// renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE;
1027− }
10281049 }, [&] {
10291050 r.moveLeft(r.width());
10301051 });
@@ -1038,13 +1059,11 @@ void Application::paintGL() { · 7 unmodified lines
10381059 batch.setStateScissorRect(renderArgs._viewport);
10391060 });
10401061 displaySide(&renderArgs, _myCamera);
1041− if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror) &&
1042− !Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) {
1043− renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
1044− renderRearViewMirror(&renderArgs, _mirrorViewRect);
1045− renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE;
1046− }
10471062 }
1063+
1064+ doInBatch(&renderArgs, [](gpu::Batch& batch){
1065+ batch.setFramebuffer(nullptr);
1066+ });
10481067 }
10491068
10501069 // Overlay Composition, needs to occur after screen space effects have completed
@@ -1089,6 +1108,7 @@ void Application::paintGL() { · 38 unmodified lines
10891108
10901109 // Ensure all operations from the previous context are complete before we try to read the fbo
10911110 #ifdef Q_OS_MAC
1111+ // FIXME once we move to core profile, use fencesync on both platforms
10921112 #else
10931113 // FIXME? make the sync a parameter to preDisplay and let the plugin manage this
10941114 glWaitSync(sync, 0, GL_TIMEOUT_IGNORED);
@@ -1104,11 +1124,11 @@ void Application::paintGL() { · 9 unmodified lines
11041124 PROFILE_RANGE(__FUNCTION__ "/bufferSwap");
11051125 displayPlugin->finishFrame();
11061126 }
1107−
1108− _offscreenContext->makeCurrent();
1109− _frameCount++;
1110− Stats::getInstance()->setRenderDetails(renderArgs._details);
11111127 }
1128+
1129+ _offscreenContext->makeCurrent();
1130+ _frameCount++;
1131+ Stats::getInstance()->setRenderDetails(renderArgs._details);
11121132 }
11131133
11141134 void Application::runTests() {
@@ -1151,6 +1171,7 @@ void Application::resizeGL() { · 36 unmodified lines
11511171 uvec2 framebufferSize = getActiveDisplayPlugin()->getRecommendedRenderSize();
11521172 uvec2 renderSize = uvec2(vec2(framebufferSize) * getRenderResolutionScale());
11531173 if (_renderResolution != renderSize) {
1174+ _numFramesSinceLastResize = 0;
11541175 _renderResolution = renderSize;
11551176 DependencyManager::get<FramebufferCache>()->setFrameBufferSize(fromGlm(renderSize));
11561177
@@ -1933,13 +1954,6 @@ void Application::idle() { · 776 unmodified lines
19331954 }
19341955 double timeSinceLastUpdate = (double)_lastTimeUpdated.nsecsElapsed() / 1000000.0;
19351956 if (timeSinceLastUpdate > targetFramePeriod) {
1936−
1937− {
1938− static const int IDLE_EVENT_PROCESS_MAX_TIME_MS = 2;
1939− PerformanceTimer perfTimer("processEvents");
1940− processEvents(QEventLoop::AllEvents, IDLE_EVENT_PROCESS_MAX_TIME_MS);
1941− }
1942−
19431957 _lastTimeUpdated.start();
19441958 {
19451959 PerformanceTimer perfTimer("update");
@@ -1978,7 +1992,7 @@ void Application::idle() { · 32 unmodified lines
19781992 // Once rendering is off on another thread we should be able to have Application::idle run at start(0) in
19791993 // perpetuity and not expect events to get backed up.
19801994
1981− static const int IDLE_TIMER_DELAY_MS = 0;
1995+ static const int IDLE_TIMER_DELAY_MS = 2;
19821996 int desiredInterval = getActiveDisplayPlugin()->isThrottled() ? THROTTLED_IDLE_TIMER_DELAY : IDLE_TIMER_DELAY_MS;
19831997
19841998 if (idleTimer->interval() != desiredInterval) {
@@ -2353,23 +2367,21 @@ void Application::updateMyAvatarLookAtPosition() { · 368 unmodified lines
23532367 lookAtSpot = _myAvatar->getHead()->getEyePosition() +
23542368 (_myAvatar->getHead()->getFinalOrientationInWorldFrame() * glm::vec3(0.0f, 0.0f, -TREE_SCALE));
23552369 }
2356− }
23572370
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))) *
2371+ // Deflect the eyes a bit to match the detected gaze from the face tracker if active.
2372+ if (tracker && !tracker->isMuted()) {
2373+ float eyePitch = tracker->getEstimatedEyePitch();
2374+ float eyeYaw = tracker->getEstimatedEyeYaw();
2375+ const float GAZE_DEFLECTION_REDUCTION_DURING_EYE_CONTACT = 0.1f;
2376+ glm::vec3 origin = _myAvatar->getHead()->getEyePosition();
2377+ float deflection = tracker->getEyeDeflection();
2378+ if (isLookingAtSomeone) {
2379+ deflection *= GAZE_DEFLECTION_REDUCTION_DURING_EYE_CONTACT;
2380+ }
2381+ lookAtSpot = origin + _myCamera.getRotation() * glm::quat(glm::radians(glm::vec3(
2382+ eyePitch * deflection, eyeYaw * deflection, 0.0f))) *
23722383 glm::inverse(_myCamera.getRotation()) * (lookAtSpot - origin);
2384+ }
23732385 }
23742386
23752387 _myAvatar->getHead()->setLookAtPosition(lookAtSpot);
@@ -2546,10 +2558,18 @@ void Application::update(float deltaTime) { · 170 unmodified lines
25462558 _myAvatar->setDriveKeys(DOWN, userInputMapper->getActionState(UserInputMapper::VERTICAL_DOWN));
25472559 _myAvatar->setDriveKeys(LEFT, userInputMapper->getActionState(UserInputMapper::LATERAL_LEFT));
25482560 _myAvatar->setDriveKeys(RIGHT, userInputMapper->getActionState(UserInputMapper::LATERAL_RIGHT));
2549− _myAvatar->setDriveKeys(ROT_UP, userInputMapper->getActionState(UserInputMapper::PITCH_UP));
2550− _myAvatar->setDriveKeys(ROT_DOWN, userInputMapper->getActionState(UserInputMapper::PITCH_DOWN));
2551− _myAvatar->setDriveKeys(ROT_LEFT, userInputMapper->getActionState(UserInputMapper::YAW_LEFT));
2552− _myAvatar->setDriveKeys(ROT_RIGHT, userInputMapper->getActionState(UserInputMapper::YAW_RIGHT));
2561+ if (deltaTime > FLT_EPSILON) {
2562+ // For rotations what we really want are meausures of "angles per second" (in order to prevent
2563+ // fps-dependent spin rates) so we need to scale the units of the controller contribution.
2564+ // (TODO?: maybe we should similarly scale ALL action state info, or change the expected behavior
2565+ // controllers to provide a delta_per_second value rather than a raw delta.)
2566+ const float EXPECTED_FRAME_RATE = 60.0f;
2567+ float timeFactor = EXPECTED_FRAME_RATE * deltaTime;
2568+ _myAvatar->setDriveKeys(ROT_UP, userInputMapper->getActionState(UserInputMapper::PITCH_UP) / timeFactor);
2569+ _myAvatar->setDriveKeys(ROT_DOWN, userInputMapper->getActionState(UserInputMapper::PITCH_DOWN) / timeFactor);
2570+ _myAvatar->setDriveKeys(ROT_LEFT, userInputMapper->getActionState(UserInputMapper::YAW_LEFT) / timeFactor);
2571+ _myAvatar->setDriveKeys(ROT_RIGHT, userInputMapper->getActionState(UserInputMapper::YAW_RIGHT) / timeFactor);
2572+ }
25532573 }
25542574 _myAvatar->setDriveKeys(BOOM_IN, userInputMapper->getActionState(UserInputMapper::BOOM_IN));
25552575 _myAvatar->setDriveKeys(BOOM_OUT, userInputMapper->getActionState(UserInputMapper::BOOM_OUT));
@@ -3190,37 +3210,25 @@ PickRay Application::computePickRay(float x, float y) const { · 634 unmodified lines
31903210 if (isHMDMode()) {
31913211 getApplicationCompositor().computeHmdPickRay(glm::vec2(x, y), result.origin, result.direction);
31923212 } else {
3193− if (QThread::currentThread() == activeRenderingThread) {
3194− getDisplayViewFrustum()->computePickRay(x, y, result.origin, result.direction);
3195− } else {
3196− getViewFrustum()->computePickRay(x, y, result.origin, result.direction);
3197− }
3213+ getViewFrustum()->computePickRay(x, y, result.origin, result.direction);
31983214 }
31993215 return result;
32003216 }
32013217
32023218 QImage Application::renderAvatarBillboard(RenderArgs* renderArgs) {
3203− auto primaryFramebuffer = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
3204− glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFramebuffer));
3205−
3206− // clear the alpha channel so the background is transparent
3207− glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
3208− glClearColor(0.0, 0.0, 0.0, 0.0);
3209− glClear(GL_COLOR_BUFFER_BIT);
3210− glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
32113219
32123220 const int BILLBOARD_SIZE = 64;
3213−#if 0
3214− renderRearViewMirror(renderArgs, QRect(0, _glWidget->getDeviceHeight() - BILLBOARD_SIZE,
3215− BILLBOARD_SIZE, BILLBOARD_SIZE),
3216− true);
3217−#endif
32183221
3222+ // Need to make sure the gl context is current here
3223+ _offscreenContext->makeCurrent();
3224+
3225+ renderArgs->_renderMode = RenderArgs::DEFAULT_RENDER_MODE;
3226+ renderRearViewMirror(renderArgs, QRect(0, 0, BILLBOARD_SIZE, BILLBOARD_SIZE), true);
3227+
3228+ auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferDepthColor();
32193229 QImage image(BILLBOARD_SIZE, BILLBOARD_SIZE, QImage::Format_ARGB32);
3220− glReadPixels(0, 0, BILLBOARD_SIZE, BILLBOARD_SIZE, GL_BGRA, GL_UNSIGNED_BYTE, image.bits());
3221− glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
3230+ renderArgs->_context->downloadFramebuffer(primaryFbo, glm::ivec4(0, 0, BILLBOARD_SIZE, BILLBOARD_SIZE), image);
32223231
3223− glBindFramebuffer(GL_FRAMEBUFFER, 0);
32243232 return image;
32253233 }
32263234
@@ -3595,16 +3603,20 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi · 368 unmodified lines
35953603 gpu::Vec4i viewport;
35963604 if (billboard) {
35973605 QSize size = DependencyManager::get<FramebufferCache>()->getFrameBufferSize();
3598− viewport = gpu::Vec4i(region.x(), size.height() - region.y() - region.height(), region.width(), region.height());
3606+ viewport = gpu::Vec4i(0, 0, region.width(), region.height());
35993607 } else {
36003608 // if not rendering the billboard, the region is in device independent coordinates; must convert to device
36013609 QSize size = DependencyManager::get<FramebufferCache>()->getFrameBufferSize();
36023610 float ratio = (float)QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale();
3603− int x = region.x() * ratio, y = region.y() * ratio, width = region.width() * ratio, height = region.height() * ratio;
3604− viewport = gpu::Vec4i(x, size.height() - y - height, width, height);
3611+ int x = region.x() * ratio;
3612+ int y = region.y() * ratio;
3613+ int width = region.width() * ratio;
3614+ int height = region.height() * ratio;
3615+ viewport = gpu::Vec4i(0, 0, width, height);
36053616 }
36063617 renderArgs->_viewport = viewport;
36073618
3619+#if 0
36083620 auto origRenderMode = renderArgs->_renderMode;
36093621 renderArgs->_renderMode = RenderArgs::MIRROR_RENDER_MODE;
36103622
@@ -3623,14 +3635,12 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi · 12 unmodified lines
36233635
36243636 bool updateViewFrustum = false;
36253637 loadViewFrustum(_mirrorCamera, _viewFrustum);
3626−
3638+#endif
3639+
36273640 // render rear mirror view
36283641 displaySide(renderArgs, _mirrorCamera, true, billboard);
36293642
36303643 renderArgs->_viewport = originalViewport;
3631−
3632− // restore renderMode
3633− renderArgs->_renderMode = origRenderMode;
36343644 }
36353645
36363646 void Application::resetSensors() {