From 4a28361e058ed2ef6f827111b179bf7be41710ae Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 3 Sep 2015 22:12:21 -0700 Subject: [PATCH] Fix mirror to display on Oculus --- .../oculus/OculusDisplayPlugin.cpp | 52 +++++-------------- 1 file changed, 12 insertions(+), 40 deletions(-) diff --git a/libraries/display-plugins/src/display-plugins/oculus/OculusDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/oculus/OculusDisplayPlugin.cpp index 2ed5e69fe7..c8d9993e5a 100644 --- a/libraries/display-plugins/src/display-plugins/oculus/OculusDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/oculus/OculusDisplayPlugin.cpp @@ -310,8 +310,6 @@ void OculusDisplayPlugin::activate() { // not needed since the structure was zeroed on init, but explicit sceneLayer.ColorTexture[1] = nullptr; - PerformanceTimer::setActive(true); - if (!OVR_SUCCESS(ovr_ConfigureTracking(_hmd, ovrTrackingCap_Orientation | ovrTrackingCap_Position | ovrTrackingCap_MagYawCorrection, 0))) { qFatal("Could not attach to sensor device"); @@ -322,15 +320,12 @@ void OculusDisplayPlugin::activate() { void OculusDisplayPlugin::customizeContext() { WindowOpenGLDisplayPlugin::customizeContext(); #if (OVR_MAJOR_VERSION >= 6) - //_texture = DependencyManager::get()-> - // getImageTexture(PathUtils::resourcesPath() + "/images/cube_texture.png"); - uvec2 mirrorSize = toGlm(_window->geometry().size()); - _sceneFbo = SwapFboPtr(new SwapFramebufferWrapper(_hmd)); _sceneFbo->Init(getRecommendedRenderSize()); #endif enableVsync(false); - isVsyncEnabled(); + // Only enable mirroring if we know vsync is disabled + _enableMirror = !isVsyncEnabled(); } void OculusDisplayPlugin::deactivate() { @@ -338,7 +333,6 @@ void OculusDisplayPlugin::deactivate() { makeCurrent(); _sceneFbo.reset(); doneCurrent(); - PerformanceTimer::setActive(false); WindowOpenGLDisplayPlugin::deactivate(); @@ -355,6 +349,16 @@ void OculusDisplayPlugin::display(GLuint finalTexture, const glm::uvec2& sceneSi // controlling vsync wglSwapIntervalEXT(0); + // screen mirroring + if (_enableMirror) { + auto windowSize = toGlm(_window->size()); + Context::Viewport(windowSize.x, windowSize.y); + glBindTexture(GL_TEXTURE_2D, finalTexture); + GLenum err = glGetError(); + Q_ASSERT(0 == err); + drawUnitQuad(); + } + _sceneFbo->Bound([&] { auto size = _sceneFbo->size; Context::Viewport(size.x, size.y); @@ -369,25 +373,7 @@ void OculusDisplayPlugin::display(GLuint finalTexture, const glm::uvec2& sceneSi }); auto windowSize = toGlm(_window->size()); - - /* - Two alternatives for mirroring to the screen, the first is to copy our own composited - scene to the window framebuffer, before distortion. Note this only works if we're doing - ui compositing ourselves, and not relying on the Oculus SDK compositor (or we don't want - the UI visible in the output window (unlikely). This should be done before - _sceneFbo->Increment or we're be using the wrong texture - */ - if (_enableMirror) { - _sceneFbo->Bound(Framebuffer::Target::Read, [&] { - glBlitFramebuffer( - 0, 0, _sceneFbo->size.x, _sceneFbo->size.y, - 0, 0, windowSize.x, windowSize.y, - GL_COLOR_BUFFER_BIT, GL_NEAREST); - }); - } - { - PerformanceTimer("OculusSubmit"); ovrViewScaleDesc viewScaleDesc; viewScaleDesc.HmdSpaceToWorldScaleInMeters = 1.0f; viewScaleDesc.HmdToEyeViewOffset[0] = _eyeOffsets[0]; @@ -401,20 +387,6 @@ void OculusDisplayPlugin::display(GLuint finalTexture, const glm::uvec2& sceneSi } _sceneFbo->Increment(); - /* - The other alternative for mirroring is to use the Oculus mirror texture support, which - will contain the post-distorted and fully composited scene regardless of how many layers - we send. - Currently generates an error. - */ - //auto mirrorSize = _mirrorFbo->size; - //_mirrorFbo->Bound(Framebuffer::Target::Read, [&] { - // Context::BlitFramebuffer( - // 0, mirrorSize.y, mirrorSize.x, 0, - // 0, 0, windowSize.x, windowSize.y, - // BufferSelectBit::ColorBuffer, BlitFilter::Nearest); - //}); - ++_frameIndex; #endif }