Skip to content

Commit

Permalink
Oculus Rift|UI: Added slider for configuring pixel density
Browse files Browse the repository at this point in the history
Allows for a quality/performance tradeoff.
  • Loading branch information
skyjake committed Aug 23, 2014
1 parent 6cab0f6 commit 13efd92
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
5 changes: 5 additions & 0 deletions doomsday/client/net.dengine.client.pack/modules/appconfig.de
Expand Up @@ -78,5 +78,10 @@ def setDefaults(d)
# Master server settings.
record d.masterServer
d.masterServer.apiUrl = "www.dengine.net/master.php"

# VR/3D settings.
record d.vr
record d.vr.oculusRift
d.vr.oculusRift.pixelDensity = 1.0
end

13 changes: 12 additions & 1 deletion doomsday/client/src/ui/dialogs/vrsettingsdialog.cpp
Expand Up @@ -24,6 +24,8 @@
#include "api_console.h"
#include <doomsday/console/exec.h>

#include <de/App>
#include <de/VariableSliderWidget>
#include <de/SignalAction>
#include "CommandAction"

Expand All @@ -37,6 +39,7 @@ DENG_GUI_PIMPL(VRSettingsDialog)
CVarSliderWidget *dominantEye;
CVarSliderWidget *humanHeight;
CVarSliderWidget *ipd;
VariableSliderWidget *riftDensity;
CVarSliderWidget *riftSamples;
ButtonWidget *riftReset;
ButtonWidget *riftSetup;
Expand Down Expand Up @@ -74,6 +77,10 @@ DENG_GUI_PIMPL(VRSettingsDialog)

if(vrCfg().oculusRift().isReady())
{
area.add(riftDensity = new VariableSliderWidget(App::config()["vr.oculusRift.pixelDensity"],
Ranged(0.5, 1.0), .01));
riftDensity->setPrecision(2);

area.add(riftReset = new ButtonWidget);
riftReset->setText(tr("Recenter Tracking"));
riftReset->setAction(new CommandAction("resetriftpose"));
Expand Down Expand Up @@ -128,11 +135,15 @@ VRSettingsDialog::VRSettingsDialog(String const &name)
sampleLabel->setTextLineAlignment(ui::AlignRight);

layout.setCellAlignment(Vector2i(0, 5), ui::AlignLeft);
layout.append(*ovrLabel, 2) << *sampleLabel << *d->riftSamples;
layout.append(*ovrLabel, 2);

LabelWidget *utilLabel = LabelWidget::newWithText(tr("Utilities:"), &area());
if(vrCfg().oculusRift().isReady())
{
layout << *sampleLabel << *d->riftSamples
<< *LabelWidget::newWithText(tr("Pixel Density:"), &area())
<< *d->riftDensity;

layout << *utilLabel << *d->riftReset
<< Const(0) << *d->riftSetup
<< Const(0) << *d->desktopSetup;
Expand Down
21 changes: 18 additions & 3 deletions doomsday/libappfw/src/vr/oculusrift.cpp
Expand Up @@ -47,6 +47,7 @@ Vector3f quaternionToPRYAngles(Quatf const &q)

DENG2_PIMPL(OculusRift)
, DENG2_OBSERVES(Canvas, KeyEvent)
, DENG2_OBSERVES(Variable, Change)
, public Lockable
{
#ifdef DENG_HAVE_OCULUS_API
Expand All @@ -69,6 +70,7 @@ DENG2_PIMPL(OculusRift)

bool inited = false;
bool frameOngoing = false;
bool densityChanged = false;
//Vector2f screenSize;
//float lensSeparationDistance;
//Vector4f hmdWarpParam;
Expand Down Expand Up @@ -131,11 +133,16 @@ DENG2_PIMPL(OculusRift)
return window->transform().as<VRWindowTransform>().unwarpedFramebuffer();
}

void variableValueChanged(Variable &, Value const &)
{
densityChanged = true;
}

void resizeFramebuffer()
{
Sizei size[2];
ovrFovPort fovMax;
float density = 0.75f;
float density = App::config().getf("vr.oculusRift.pixelDensity", 1.f);
for(int eye = 0; eye < 2; ++eye)
{
// Use the default FOV.
Expand All @@ -162,8 +169,6 @@ DENG2_PIMPL(OculusRift)

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

/// @todo Apply chosen pixel density here.

framebuffer().resize(GLFramebuffer::Size(size[0].w + size[1].w,
max(size[0].h, size[1].h)));
uint const w = framebuffer().size().x;
Expand Down Expand Up @@ -197,6 +202,8 @@ DENG2_PIMPL(OculusRift)
// If there is no Oculus Rift connected, do nothing.
if(!hmd) return;

App::config()["vr.oculusRift.pixelDensity"].audienceForChange() += this;

DENG2_GUARD(this);

// Configure for orientation and position tracking.
Expand Down Expand Up @@ -278,6 +285,8 @@ DENG2_PIMPL(OculusRift)

LOG_GL_MSG("Stopping Oculus Rift rendering");

App::config()["vr.oculusRift.pixelDensity"].audienceForChange() -= this;

ovrHmd_ConfigureRendering(hmd, NULL, 0, NULL, NULL);

framebuffer().glDeinit();
Expand Down Expand Up @@ -380,6 +389,12 @@ DENG2_PIMPL(OculusRift)
DENG2_ASSERT(isReady());
DENG2_ASSERT(!frameOngoing);

if(densityChanged)
{
densityChanged = false;
resizeFramebuffer();
}

frameOngoing = true;
timing = ovrHmd_BeginFrame(hmd, 0);
}
Expand Down

0 comments on commit 13efd92

Please sign in to comment.