Fix mirror to display on Oculus

This commit is contained in:
Brad Davis 2015-09-03 22:12:21 -07:00
parent 41daea7d92
commit 4a28361e05

View file

@ -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<TextureCache>()->
// 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
}