Skip to content

Commit

Permalink
Oculus Rift|Client|test_appfw: Revised VR functionality
Browse files Browse the repository at this point in the history
Also tweaking frame begin/end, window redraw requests.
  • Loading branch information
skyjake committed Aug 19, 2014
1 parent 685db4b commit 41404ba
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 51 deletions.
4 changes: 2 additions & 2 deletions doomsday/client/include/render/vr.h
Expand Up @@ -39,11 +39,11 @@ void VR_ConsoleRegister();
/**
* Returns the horizontal field of view in Oculus Rift in degrees.
*/
float VR_RiftFovX();
//float VR_RiftFovX();

/**
* Load Oculus Rift parameters via Rift SDK.
*/
bool VR_LoadRiftParameters();
//bool VR_LoadRiftParameters();

#endif // CLIENT_RENDER_VR_H
2 changes: 1 addition & 1 deletion doomsday/client/src/busymode.cpp
Expand Up @@ -499,7 +499,7 @@ void BusyMode_Loop(void)
!Con_IsProgressAnimationCompleted())
{
// Let's keep running the busy loop.
ClientWindowSystem::main().draw();
//ClientWindowSystem::main().draw();
return;
}

Expand Down
8 changes: 8 additions & 0 deletions doomsday/client/src/clientapp.cpp
Expand Up @@ -34,6 +34,7 @@
#include <de/ByteArrayFile>
#include <de/ArrayValue>
#include <de/DictionaryValue>
#include <de/VRConfig>
#include <de/c_wrapper.h>
#include <de/Garbage>

Expand All @@ -49,6 +50,7 @@
#include "gl/gl_main.h"
#include "gl/gl_texmanager.h"
#include "ui/inputsystem.h"
#include "ui/sys_input.h"
#include "ui/clientwindowsystem.h"
#include "ui/clientwindow.h"
#include "ui/widgets/taskbarwidget.h"
Expand Down Expand Up @@ -199,6 +201,8 @@ DENG2_PIMPL(ClientApp)
{
LogBuffer::get().removeSink(logAlarm);

self.vr().oculusRift().deinit();

Sys_Shutdown();
DD_Shutdown();

Expand Down Expand Up @@ -412,6 +416,10 @@ void ClientApp::postFrame()
/// @todo Should these be here? Consider multiple windows, each having a postFrame?
/// Or maybe the frames need to be synced? Or only one of them has a postFrame?

// We will arrive here always at the same time in relation to the displayed
// frame: it is a good time to update the mouse state.
Mouse_Poll();

if(gx.EndFrame)
{
gx.EndFrame();
Expand Down
6 changes: 2 additions & 4 deletions doomsday/client/src/gl/gl_main.cpp
Expand Up @@ -181,6 +181,8 @@ void GL_AssertContextActive()

void GL_DoUpdate()
{
if(ClientApp::vr().mode() == VRConfig::OculusRift) return;

// Check for color adjustment changes.
if(oldgamma != vid_gamma || oldcontrast != vid_contrast || oldbright != vid_bright)
{
Expand All @@ -197,10 +199,6 @@ void GL_DoUpdate()

// Blit screen to video.
ClientWindow::main().swapBuffers();

// We will arrive here always at the same time in relation to the displayed
// frame: it is a good time to update the mouse state.
Mouse_Poll();
}

void GL_GetGammaRamp(DisplayColorTransfer *ramp)
Expand Down
9 changes: 6 additions & 3 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -292,6 +292,7 @@ static void unlinkMobjLumobjs()
}
}

/*
static void fieldOfViewChanged()
{
if(vrCfg().mode() == VRConfig::OculusRift)
Expand All @@ -304,7 +305,7 @@ static void fieldOfViewChanged()
if(Con_GetFloat("rend-vr-nonrift-fovx") != fieldOfView)
Con_SetFloat("rend-vr-nonrift-fovx", fieldOfView);
}
}
}*/

static void detailFactorChanged()
{
Expand Down Expand Up @@ -341,7 +342,7 @@ static void texQualityChanged()
void Rend_Register()
{
C_VAR_INT ("rend-bias", &useBias, 0, 0, 1);
C_VAR_FLOAT2("rend-camera-fov", &fieldOfView, 0, 1, 179, fieldOfViewChanged);
C_VAR_FLOAT ("rend-camera-fov", &fieldOfView, 0, 1, 179);

C_VAR_FLOAT ("rend-glow", &glowFactor, 0, 0, 2);
C_VAR_INT ("rend-glow-height", &glowHeightMax, 0, 0, 1024);
Expand Down Expand Up @@ -495,7 +496,9 @@ float Rend_FieldOfView()
{
// fieldOfView = VR::riftFovX(); // Update for culling
// return VR::riftFovX();
return fieldOfView;

// OVR tells us which FOV to use.
return vrCfg().oculusRift().fovX();
}
else
{
Expand Down
4 changes: 0 additions & 4 deletions doomsday/client/src/render/viewports.cpp
Expand Up @@ -889,10 +889,6 @@ DENG_EXTERN_C void R_RenderPlayerView(int num)

vrCfg().setEyeHeightInMapUnits(Con_GetInteger("player-eyeheight"));

// Latest possible time to check the real head angles. After this we'll be
// using the provided values.
vrCfg().oculusRift().update();

setupViewMatrix();
setupPlayerSprites();

Expand Down
56 changes: 38 additions & 18 deletions doomsday/client/src/render/vr.cpp
Expand Up @@ -31,35 +31,37 @@ namespace VR {
}

static int vrMode = VRConfig::Mono;
static float vrRiftFovX = 114.8f;
static float vrNonRiftFovX = 95.f;
//static float vrRiftFovX = 114.8f;
//static float vrNonRiftFovX = 95.f;
//static float vrRiftLatency;
//static byte autoLoadRiftParams = 1;
static int vrRiftFBSamples;
static float vrHudDistance;
static float vrRiftLatency;
static float vrPlayerHeight;
static float vrIpd;
static int vrRiftFBSamples;
static byte vrSwapEyes;
static float vrDominantEye;
static byte autoLoadRiftParams = 1;

VRConfig &vrCfg()
{
DENG2_ASSERT(DENG2_BASE_GUI_APP != 0);
return DENG2_BASE_GUI_APP->vr();
}

/*
float VR_RiftFovX()
{
return vrRiftFovX;
}
*/

static void vrConfigVariableChanged()
{
vrCfg().setDominantEye(vrDominantEye);
vrCfg().setScreenDistance(vrHudDistance);
vrCfg().setInterpupillaryDistance(vrIpd);
vrCfg().setPhysicalPlayerHeight(vrPlayerHeight);
vrCfg().oculusRift().setPredictionLatency(vrRiftLatency);
//vrCfg().oculusRift().setPredictionLatency(vrRiftLatency);
vrCfg().setRiftFramebufferSampleCount(vrRiftFBSamples);
vrCfg().setSwapEyes(vrSwapEyes);
}
Expand All @@ -68,6 +70,14 @@ static void vrConfigVariableChanged()
// see also rend_main.cpp
static void vrModeChanged()
{
if(vrMode == VRConfig::OculusRift && !vrCfg().oculusRift().isReady())
{
// Can't activate Oculus Rift mode unless the device is connected.
vrMode = VRConfig::Mono;

LOG_WARNING("Oculus Rift not connected, reverting to normal 3D mode");
}

vrCfg().setMode(VRConfig::StereoMode(vrMode));

if(ClientWindow::mainExists())
Expand All @@ -78,6 +88,17 @@ static void vrModeChanged()
win.updateCanvasFormat(); // possibly changes pixel format
}

// Make sure Oculus Rift rendering is (de)initialized as needed.
if(vrCfg().mode() == VRConfig::OculusRift)
{
vrCfg().oculusRift().init();
}
else
{
vrCfg().oculusRift().deinit();
}

/*
// Update FOV cvar accordingly.
if(vrMode == VRConfig::OculusRift)
{
Expand All @@ -91,9 +112,10 @@ static void vrModeChanged()
{
if(Con_GetFloat("rend-camera-fov") != vrNonRiftFovX)
Con_SetFloat("rend-camera-fov", vrNonRiftFovX);
}
}*/
}

/*
static void vrRiftFovXChanged()
{
if(vrCfg().mode() == VRConfig::OculusRift)
Expand All @@ -116,7 +138,7 @@ D_CMD(LoadRiftParams)
{
DENG2_UNUSED3(src, argc, argv);
return VR_LoadRiftParameters();
}
}*/

void VR_ConsoleRegister()
{
Expand All @@ -125,7 +147,7 @@ void VR_ConsoleRegister()
vrHudDistance = vrCfg().screenDistance();
vrIpd = vrCfg().interpupillaryDistance();
vrPlayerHeight = vrCfg().physicalPlayerHeight();
vrRiftLatency = vrCfg().oculusRift().predictionLatency();
//vrRiftLatency = vrCfg().oculusRift().predictionLatency();
vrRiftFBSamples = vrCfg().riftFramebufferSampleCount();
vrSwapEyes = vrCfg().swapEyes();

Expand All @@ -135,25 +157,22 @@ void VR_ConsoleRegister()
*/

C_VAR_INT2 ("rend-vr-mode", &vrMode, 0, 0, VRConfig::NUM_STEREO_MODES - 1, vrModeChanged);
C_VAR_BYTE ("rend-vr-autoload-rift-params", &autoLoadRiftParams, 0, 0, 1);
C_VAR_FLOAT2("rend-vr-nonrift-fovx", &vrNonRiftFovX, 0, 5.0f, 270.0f, vrNonRiftFovXChanged);
C_VAR_FLOAT2("rend-vr-rift-fovx", &vrRiftFovX, 0, 5.0f, 270.0f, vrRiftFovXChanged);
//C_VAR_BYTE ("rend-vr-autoload-rift-params", &autoLoadRiftParams, 0, 0, 1);
//C_VAR_FLOAT2("rend-vr-nonrift-fovx", &vrNonRiftFovX, 0, 5.0f, 270.0f, vrNonRiftFovXChanged);
//C_VAR_FLOAT2("rend-vr-rift-fovx", &vrRiftFovX, 0, 5.0f, 270.0f, vrRiftFovXChanged);
//C_VAR_FLOAT2("rend-vr-rift-latency", &vrRiftLatency, 0, 0.0f, 0.100f, vrConfigVariableChanged);

C_VAR_FLOAT2("rend-vr-dominant-eye", &vrDominantEye, 0, -1.0f, 1.0f, vrConfigVariableChanged);
C_VAR_FLOAT2("rend-vr-hud-distance", &vrHudDistance, 0, 0.01f, 40.0f, vrConfigVariableChanged);
C_VAR_FLOAT2("rend-vr-ipd", &vrIpd, 0, 0.02f, 0.1f, vrConfigVariableChanged);
C_VAR_FLOAT2("rend-vr-player-height", &vrPlayerHeight, 0, 1.0f, 2.4f, vrConfigVariableChanged);
C_VAR_FLOAT2("rend-vr-rift-latency", &vrRiftLatency, 0, 0.0f, 0.100f, vrConfigVariableChanged);
C_VAR_INT2 ("rend-vr-rift-samples", &vrRiftFBSamples, 0, 1, 4, vrConfigVariableChanged);
C_VAR_BYTE2 ("rend-vr-swap-eyes", &vrSwapEyes, 0, 0, 1, vrConfigVariableChanged);

C_CMD("loadriftparams", NULL, LoadRiftParams);
//C_CMD("loadriftparams", NULL, LoadRiftParams);
}

// Warping

/// @todo warping

#if 0
bool VR_LoadRiftParameters()
{
de::OculusRift &ovr = vrCfg().oculusRift();
Expand All @@ -173,3 +192,4 @@ bool VR_LoadRiftParameters()
}
return false;
}
#endif
29 changes: 18 additions & 11 deletions doomsday/client/src/ui/clientwindow.cpp
Expand Up @@ -637,7 +637,11 @@ DENG2_PIMPL(ClientWindow)

if(vrCfg().mode() == VRConfig::OculusRift)
{
compositor->setCompositeProjection(Matrix4f::ortho(-1.1f, 2.2f, -1.1f, 2.2f));
/// @todo Adjustable compositor depth?
compositor->setCompositeProjection(
GL_GetProjectionMatrix()
* Matrix4f::scale(Vector3f(1.f, -1.f / vrCfg().oculusRift().aspect(), 1.f))
* Matrix4f::translate(Vector3f(-.5f, -.5f, -1)));
}
else
{
Expand Down Expand Up @@ -797,9 +801,6 @@ void ClientWindow::canvasGLInit(Canvas &)

void ClientWindow::preDraw()
{
// NOTE: This occurs during the Canvas paintGL event.
BaseWindow::preDraw();

ClientApp::app().preFrame(); /// @todo what about multiwindow?

DENG_ASSERT_IN_MAIN_THREAD();
Expand All @@ -813,6 +814,9 @@ void ClientWindow::preDraw()
d->updateRootSize();
}
d->updateCompositor();

// NOTE: This occurs during the Canvas paintGL event.
BaseWindow::preDraw();
}

void ClientWindow::drawWindowContent()
Expand All @@ -823,17 +827,20 @@ void ClientWindow::drawWindowContent()

void ClientWindow::postDraw()
{
// NOTE: This occurs during the Canvas paintGL event.
/// @note This method is called during the Canvas paintGL event.

// Finish GL drawing and swap it on to the screen. Blocks until buffers
// swapped.
GL_DoUpdate();
// OVR will handle presentation in Oculus Rift mode.
if(ClientApp::vr().mode() != VRConfig::OculusRift)
{
// Finish GL drawing and swap it on to the screen. Blocks until buffers
// swapped.
GL_DoUpdate();
}

ClientApp::app().postFrame(); /// @todo what about multiwindow?
BaseWindow::postDraw();

ClientApp::app().postFrame(); /// @todo what about multiwindow?
d->updateFpsNotification(frameRate());

BaseWindow::postDraw();
}

void ClientWindow::canvasGLResized(Canvas &canvas)
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/ui/dd_input.cpp
Expand Up @@ -1485,8 +1485,8 @@ void DD_ReadHeadTracker(void)
I_GetDevice(IDEV_HEAD_TRACKER)->flags |= ID_ACTIVE;

// Get the latest values.
vrCfg().oculusRift().allowUpdate();
vrCfg().oculusRift().update();
//vrCfg().oculusRift().allowUpdate();
//vrCfg().oculusRift().update();

ddevent_t ev;

Expand Down
5 changes: 1 addition & 4 deletions doomsday/client/src/ui/widgets/gamewidget.cpp
Expand Up @@ -153,10 +153,7 @@ void GameWidget::update()
GL_ProcessDeferredTasks(FRAME_DEFERRED_UPLOAD_TIMEOUT);

// Request update of window contents.
root().as<ClientRootWidget>().window().draw();

// After the first frame, start timedemo.
//DD_CheckTimeDemo();
//root().as<ClientRootWidget>().window().draw();
}

void GameWidget::drawContent()
Expand Down
13 changes: 11 additions & 2 deletions doomsday/tests/test_appfw/src/mainwindow.cpp
Expand Up @@ -64,6 +64,8 @@ DENG2_PIMPL(MainWindow)

~Instance()
{
TestApp::vr().oculusRift().deinit();

releaseRef(cursorX);
releaseRef(cursorY);
}
Expand Down Expand Up @@ -111,6 +113,11 @@ DENG2_PIMPL(MainWindow)

contentXf.glInit();

if(TestApp::vr().mode() == VRConfig::OculusRift)
{
TestApp::vr().oculusRift().init();
}

self.raise();
self.activateWindow();
self.canvas().setFocus();
Expand Down Expand Up @@ -182,7 +189,6 @@ MainWindow::MainWindow(String const &id)
vr.setMode(VRConfig::OculusRift);
vr.setRiftFramebufferSampleCount(App::commandLine().has("--nofsaa")? 1 : 2);
vr.setPhysicalPlayerHeight(1.8f);
vr.oculusRift().setPredictionLatency(.04f);
vr.setScreenDistance(.5f);
vr.setEyeHeightInMapUnits(vr.physicalPlayerHeight() * .925f);
setCursor(Qt::BlankCursor);
Expand Down Expand Up @@ -242,7 +248,10 @@ void MainWindow::preDraw()

void MainWindow::postDraw()
{
swapBuffers();
if(TestApp::vr().mode() != VRConfig::OculusRift)
{
swapBuffers();
}
BaseWindow::postDraw();

Garbage_Recycle();
Expand Down

0 comments on commit 41404ba

Please sign in to comment.