Skip to content

Commit

Permalink
Debug|libappfw|libgui: Working on Oculus Rift rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Aug 19, 2014
1 parent 29d2ef1 commit 685db4b
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 27 deletions.
15 changes: 7 additions & 8 deletions doomsday/libappfw/src/basewindow.cpp
Expand Up @@ -156,22 +156,21 @@ void BaseWindow::swapBuffers()

void BaseWindow::preDraw()
{
#ifdef DENG_HAVE_OCULUS_API
// Make sure Oculus Rift rendering is (de)initialized as needed.
auto &vr = DENG2_BASE_GUI_APP->vr();
if(vr.mode() == VRConfig::OculusRift)
{
vr.oculusRift().init();
vr.oculusRift().beginFrame();
}
else
{
vr.oculusRift().deinit();
}
#endif
}

void BaseWindow::postDraw()
{
auto &vr = DENG2_BASE_GUI_APP->vr();
if(vr.mode() == VRConfig::OculusRift)
{
vr.oculusRift().endFrame();
}

// The timer loop was paused when the frame was requested to be drawn.
DENG2_GUI_APP->loop().resume();
}
Expand Down
4 changes: 4 additions & 0 deletions doomsday/libappfw/src/guirootwidget.cpp
Expand Up @@ -20,6 +20,7 @@
#include "de/GuiWidget"
#include "de/BaseGuiApp"
#include "de/Style"
#include "de/BaseWindow"

#include <de/CanvasWindow>
#include <de/TextureBank>
Expand Down Expand Up @@ -320,6 +321,9 @@ void GuiRootWidget::update()
window().canvas().makeCurrent();

RootWidget::update();

// Request a window draw so that the updated content becomes visible.
window().as<BaseWindow>().draw();
}
}

Expand Down
72 changes: 56 additions & 16 deletions doomsday/libappfw/src/vr/oculusrift.cpp
Expand Up @@ -22,6 +22,7 @@
#include "de/VRWindowTransform"

#include <de/GLFramebuffer>
#include <de/GLState>
#include <de/Lockable>
#include <de/Guard>
#include <de/App>
Expand Down Expand Up @@ -91,17 +92,18 @@ DENG2_PIMPL(OculusRift)
#ifdef DENG_HAVE_OCULUS_API
ovr_Initialize();
hmd = ovrHmd_Create(0);

if(!hmd && App::commandLine().has("-ovrdebug"))
{
hmd = ovrHmd_CreateDebug(ovrHmd_DK2);
}

if(hmd)
{
LOG_INPUT_NOTE("HMD: %s (%s) %i.%i @ %ix%i pixels")
<< hmd->ProductName << hmd->Manufacturer
LOG_INPUT_NOTE("HMD: %s (%s) %i.%i %ix%i pixels")
<< String(hmd->ProductName) << String(hmd->Manufacturer)
<< hmd->FirmwareMajor << hmd->FirmwareMinor
<< hmd->Resolution.w << hmd->Resolution.h;

// Configure for orientation and position tracking.
ovrHmd_ConfigureTracking(hmd, ovrTrackingCap_Orientation |
ovrTrackingCap_MagYawCorrection |
ovrTrackingCap_Position, 0);
<< hmd->Resolution.w << hmd->Resolution.h;
}
#endif
}
Expand Down Expand Up @@ -153,11 +155,13 @@ DENG2_PIMPL(OculusRift)

aspect = comboXTan / comboYTan;

LOGDEV_GL_MSG("Aspect ratio: %f") << aspect;

// Calculate the horizontal total FOV in degrees that the renderer will use
// for clipping.
fovXDegrees = 2 * atanf(comboXTan);
fovXDegrees = radianToDegree(2 * atanf(comboXTan));

LOGDEV_GL_MSG("Using clip FOV of %.2f degrees") << fovXDegrees;
LOGDEV_GL_MSG("Clip FOV: %.2f degrees") << fovXDegrees;

/// @todo Apply chosen pixel density here.

Expand All @@ -166,7 +170,9 @@ DENG2_PIMPL(OculusRift)
uint const w = framebuffer().size().x;
uint const h = framebuffer().size().y;

LOG_GL_VERBOSE("Framebuffer size is ") << framebuffer().size().asText();
//framebuffer().colorTexture().setFilter(gl::Linear, gl::Linear, gl::MipNone);

LOG_GL_VERBOSE("Framebuffer size: ") << framebuffer().size().asText();

for(int eye = 0; eye < 2; ++eye)
{
Expand All @@ -185,9 +191,17 @@ DENG2_PIMPL(OculusRift)
if(inited) return;
inited = true;

// If there is no Oculus Rift connected, do nothing.
if(!hmd) return;

#ifdef DENG_HAVE_OCULUS_API
DENG2_GUARD(this);

// Configure for orientation and position tracking.
ovrHmd_ConfigureTracking(hmd, ovrTrackingCap_Orientation |
ovrTrackingCap_MagYawCorrection |
ovrTrackingCap_Position, 0);

LOG_GL_MSG("Initializing Oculus Rift for rendering");

// We will be rendering into the main window.
Expand Down Expand Up @@ -223,6 +237,22 @@ DENG2_PIMPL(OculusRift)
return;
}

for(int i = 0; i < 2; ++i)
{
qDebug() << "Eye:" << render[i].Eye
<< "Fov:" << render[i].Fov.LeftTan << render[i].Fov.RightTan
<< render[i].Fov.UpTan << render[i].Fov.DownTan
<< "DistortedViewport:" << render[i].DistortedViewport.Pos.x
<< render[i].DistortedViewport.Pos.y
<< render[i].DistortedViewport.Size.w
<< render[i].DistortedViewport.Size.h
<< "PixelsPerTanAngleAtCenter:" << render[i].PixelsPerTanAngleAtCenter.x
<< render[i].PixelsPerTanAngleAtCenter.y
<< "ViewAdjust:" << render[i].ViewAdjust.x
<< render[i].ViewAdjust.y
<< render[i].ViewAdjust.z;
}

ovrHmd_AttachToWindow(hmd, window->nativeHandle(), NULL, NULL);
#endif
}
Expand Down Expand Up @@ -250,9 +280,9 @@ DENG2_PIMPL(OculusRift)
/**
* Observe key events (any key) to dismiss the OVR Health and Safety warning.
*/
void keyEvent(KeyEvent const &)
void keyEvent(KeyEvent const &ev)
{
if(!window) return;
if(!window || ev.type() == Event::KeyRelease) return;

#ifdef DENG_HAVE_OCULUS_API
if(isHealthAndSafetyWarningDisplayed())
Expand Down Expand Up @@ -345,9 +375,19 @@ DENG2_PIMPL(OculusRift)

void endFrame()
{
ovrHmd_EndFrame(hmd, headPose, (ovrTexture const *) textures);
/*
GLTarget defaultTarget;
GLState::push()
.setTarget(defaultTarget)
.setViewport(Rectangleui::fromSize(defaultTarget.size()))
.apply();*/

ovrHmd_EndFrame(hmd, headPose, &textures[0].Texture);

dismissHealthAndSafetyWarningOnTap();

GLState::considerNativeStateUndefined();
//GLState::pop().apply();
}
#endif
};
Expand All @@ -370,7 +410,7 @@ void OculusRift::deinit()
void OculusRift::beginFrame()
{
#ifdef DENG_HAVE_OCULUS_API
if(!isReady() || d->frameOngoing) return;
if(!isReady() || !d->inited || d->frameOngoing) return;
d->frameOngoing = true;

// Begin the frame and acquire timing information.
Expand Down Expand Up @@ -544,7 +584,7 @@ Matrix4f OculusRift::projection(float nearDist, float farDist) const
DENG2_ASSERT(isReady());
#ifdef DENG_HAVE_OCULUS_API
return ovrMatrix4f_Projection(d->fov[d->currentEye], nearDist, farDist,
true /* right-handed */).M[0];
false /* right-handed */).M[0];
#else
DENG2_UNUSED2(nearDist, farDist);
return Matrix4f();
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libappfw/src/vrwindowtransform.cpp
Expand Up @@ -142,7 +142,7 @@ DENG2_PIMPL(VRWindowTransform)
// Use a little bit of multisampling to smooth out the magnified jagged edges.
// Note: Independent of the vid-fsaa setting because this is beneficial even when
// vid-fsaa is disabled.
unwarpedFB.setSampleCount(vrCfg.riftFramebufferSampleCount());
unwarpedFB.setSampleCount(1); //vrCfg.riftFramebufferSampleCount());

// Set render target to offscreen temporarily.
GLState::push()
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libgui/src/canvas.cpp
Expand Up @@ -249,8 +249,8 @@ Canvas::Canvas(CanvasWindow* parent, QGLWidget* shared)
: QGLWidget(parent, shared), d(new Instance(this, parent))
{
LOG_AS("Canvas");
LOGDEV_GL_VERBOSE("swap interval: ") << format().swapInterval();
LOGDEV_GL_VERBOSE("multisample: %b") << (GLFramebuffer::defaultMultisampling() > 1);
LOGDEV_GL_VERBOSE("Swap interval: ") << format().swapInterval();
LOGDEV_GL_VERBOSE("Multisampling: %b") << (GLFramebuffer::defaultMultisampling() > 1);

// We will be doing buffer swaps manually (for timing purposes).
setAutoBufferSwap(false);
Expand Down

0 comments on commit 685db4b

Please sign in to comment.