Skip to content

Commit

Permalink
Merge branch 'oculus-refactor' into library-lgpl
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 13, 2014
2 parents e01d144 + e0483c2 commit 05d297d
Show file tree
Hide file tree
Showing 71 changed files with 2,058 additions and 979 deletions.
5 changes: 0 additions & 5 deletions doomsday/client/client.pro
Expand Up @@ -37,7 +37,6 @@ include(../dep_deng1.pri)
include(../dep_shell.pri)
include(../dep_gui.pri)
include(../dep_appfw.pri)
include(../dep_rift.pri)

# Definitions ----------------------------------------------------------------

Expand Down Expand Up @@ -414,9 +413,7 @@ DENG_HEADERS += \
include/ui/ui2_main.h \
include/ui/ui_main.h \
include/ui/ui_panel.h \
include/ui/vrwindowtransform.h \
include/ui/windowsystem.h \
include/ui/windowtransform.h \
include/ui/zonedebug.h \
include/updater.h \
include/updater/downloaddialog.h \
Expand Down Expand Up @@ -722,7 +719,6 @@ SOURCES += \
src/ui/ui2_main.cpp \
src/ui/ui_main.cpp \
src/ui/ui_panel.cpp \
src/ui/vrwindowtransform.cpp \
src/ui/widgetactions.cpp \
src/ui/widgets/busywidget.cpp \
src/ui/widgets/consolecommandwidget.cpp \
Expand All @@ -741,7 +737,6 @@ SOURCES += \
src/ui/widgets/profilepickerwidget.cpp \
src/ui/widgets/taskbarwidget.cpp \
src/ui/windowsystem.cpp \
src/ui/windowtransform.cpp \
src/ui/zonedebug.cpp \
src/updater/downloaddialog.cpp \
src/updater/processcheckdialog.cpp \
Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/include/gl/gl_main.h
Expand Up @@ -314,6 +314,8 @@ void GL_CalcLuminance(uint8_t const *buffer, int width, int height, int comps,
colorpaletteid_t paletteId, float *brightX, float *brightY,
struct ColorRawf_s *color, float *lumSize);

void DGL_AssertNotInPrimitive(void);

// Console commands.
D_CMD(UpdateGammaRamp);

Expand Down
125 changes: 19 additions & 106 deletions doomsday/client/include/render/vr.h
Expand Up @@ -21,116 +21,29 @@
#define CLIENT_RENDER_VR_H

#include "dd_types.h"
#include "de/Vector"
#include <de/VRConfig>

namespace VR {
de::VRConfig &vrCfg();

/// Menu of stereoscopic 3D modes available. Oculus Rift is the star player, but there
/// are many other options.
/// The order shown here determines the integer value in the console.
/// @todo - Add an additional console command to support symbolic versions of these mode settings
enum Stereo3DMode {
MODE_MONO = 0,
MODE_GREEN_MAGENTA,
MODE_RED_CYAN,
MODE_LEFT,
MODE_RIGHT,
MODE_TOP_BOTTOM, // 5
MODE_SIDE_BY_SIDE,
MODE_PARALLEL,
MODE_CROSSEYE,
MODE_OCULUS_RIFT,
MODE_ROW_INTERLEAVED, // 10 // NOT IMPLEMENTED YET
MODE_COLUMN_INTERLEAVED, // NOT IMPLEMENTED YET
MODE_CHECKERBOARD, // NOT IMPLEMENTED YET
MODE_QUAD_BUFFERED,
//
MODE_MAX_3D_MODE_PLUS_ONE
};
namespace VR
{
/// (UNUSED) Distance from player character to weapon sprite, in map units
extern float weaponDistance;
}

/**
* Register VR console variables.
*/
void VR_ConsoleRegister();

class RiftState {
public:
RiftState();

// Use screen size instead of resolution in case non-square pixels?
float aspect() const {return 0.5f * hScreenSize() / vScreenSize();}
const de::Vector4f& chromAbParam() const {return m_chromAbParam;}
float distortionScale() const;
float fovX() const; // in degrees
float fovY() const; // in degrees
const de::Vector4f& hmdWarpParam() const {return m_hmdWarpParam;}
float hScreenSize() const {return m_screenSize[0];}
float lensSeparationDistance() const {return m_lensSeparationDistance;}
bool loadRiftParameters();
const de::Vector2f& screenSize() const {return m_screenSize;}
float vScreenSize() const {return m_screenSize[1];}

private:
de::Vector2f m_screenSize;
float m_lensSeparationDistance;
de::Vector4f m_hmdWarpParam;
de::Vector4f m_chromAbParam;
float m_eyeToScreenDistance;
};

extern RiftState riftState;

// Console variables
Stereo3DMode mode(); ///< Currently active Stereo3DMode index
bool modeNeedsStereoGLFormat(Stereo3DMode mode);
float riftFovX(); ///< Horizontal field of view in Oculus Rift in degrees
float riftLatency(); ///< Estimated head-motion->photons latency, in seconds

extern float ipd; ///< Interpupillary distance in meters
extern float playerHeight; ///< Human player's real world height in meters
extern float dominantEye; ///< Kludge for aim-down-weapon-sight modes
extern byte swapEyes; ///< When true, inverts stereoscopic effect

// Variables below are global, but not user visible //

// Unlike most 3D modes, Oculus Rift typically uses no frustum shift.
// (or if we did, it would be different and complicated)
extern bool applyFrustumShift;

// local viewpoint relative eye position in map units,
// VR::eyeShift is ordinarily set from VR::getEyeShift()
extern float eyeShift;

extern float hudDistance; // Distance from player character to screen, in map units (not used in Rift mode, because it's used by frustum shift)
extern float weaponDistance; // (UNUSED) Distance from player character to weapon sprite, in map units

extern int riftFramebufferSamples; // Multisampling used in unwarped Rift framebuffer

/// @param eye: -1 means left eye, +1 means right eye
/// @return viewpoint eye shift in map units
float getEyeShift(float eye);

// Register console variables
void consoleRegister();

// Head tracking API

// True if Oculus Rift is enabled and can report head orientation.
bool hasHeadOrientation();

// Called to allow head orientation to change again.
void allowHeadOrientationUpdate();

void updateHeadOrientation();

// Returns current pitch, roll, yaw angles, in radians. If no head tracking is available,
// the returned values are not valid.
de::Vector3f getHeadOrientation();

// To release memory and resources when done, for tidiness.
void deleteOculusTracker();

void setRiftLatency(float latency);

// Load Oculus Rift parameters via Rift SDK
bool loadRiftParameters();
/**
* Returns the horizontal field of view in Oculus Rift in degrees.
*/
float VR_RiftFovX();

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

#endif // CLIENT_RENDER_VR_H
7 changes: 7 additions & 0 deletions doomsday/client/include/ui/clientwindow.h
Expand Up @@ -22,6 +22,7 @@
#define CLIENT_CLIENTWINDOW_H

#include <de/PersistentCanvasWindow>
#include <de/BaseWindow>
#include <de/NotificationWidget>

#include "ui/clientrootwidget.h"
Expand Down Expand Up @@ -54,6 +55,7 @@ class AlertDialog;
* Top-level window that contains a libdeng2 UI widgets. @ingroup gui
*/
class ClientWindow : public de::PersistentCanvasWindow,
public de::BaseWindow,
DENG2_OBSERVES(de::Canvas, GLInit),
DENG2_OBSERVES(de::Canvas, GLResize)
{
Expand Down Expand Up @@ -164,6 +166,11 @@ class ClientWindow : public de::PersistentCanvasWindow,
void canvasGLDraw(de::Canvas &);
void canvasGLResized(de::Canvas &);

// Implements BaseWindow:
de::Vector2f windowContentSize();
de::Canvas &windowCanvas();
void drawWindowContent();

static ClientWindow &main();

public slots:
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/dd_main.cpp
Expand Up @@ -2374,7 +2374,7 @@ int DD_GetInteger(int ddvalue)
return (int) GL_PrepareLSTexture(LST_DYNAMIC);

case DD_USING_HEAD_TRACKING:
return VR::mode() == VR::MODE_OCULUS_RIFT && VR::hasHeadOrientation();
return vrCfg().mode() == VRConfig::OculusRift && vrCfg().oculusRift().isReady();
#endif

case DD_NUMLUMPS:
Expand Down
6 changes: 4 additions & 2 deletions doomsday/client/src/gl/dgl_common.cpp
Expand Up @@ -333,9 +333,8 @@ void GL_SetVSync(dd_bool on)

#ifdef WIN32
wglSwapIntervalEXT(on? 1 : 0);
#endif

#ifdef MACOSX
#elif defined(MACOSX)
{
// Tell CGL to wait for vertical refresh.
CGLContextObj context = CGLGetCurrentContext();
Expand All @@ -346,6 +345,9 @@ void GL_SetVSync(dd_bool on)
CGLSetParameter(context, kCGLCPSwapInterval, params);
}
}

#elif defined(Q_WS_X11)
setXSwapInterval(on? 1 : 0);
#endif
}

Expand Down
5 changes: 5 additions & 0 deletions doomsday/client/src/gl/dgl_draw.cpp
Expand Up @@ -297,6 +297,11 @@ DENG_EXTERN_C void DGL_Begin(dglprimtype_t mode)
DGL_QUAD_STRIP ? GL_QUAD_STRIP : GL_QUADS);
}

void DGL_AssertNotInPrimitive(void)
{
DENG_ASSERT(!inPrim);
}

#undef DGL_End
DENG_EXTERN_C void DGL_End(void)
{
Expand Down
22 changes: 12 additions & 10 deletions doomsday/client/src/gl/gl_main.cpp
Expand Up @@ -104,11 +104,11 @@ static void videoVsyncChanged()
{
if(novideo || !WindowSystem::hasMain()) return;

#if defined(WIN32) || defined(MACOSX)
//#if defined(WIN32) || defined(MACOSX)
GL_SetVSync(Con_GetByte("vid-vsync") != 0);
#else
WindowSystem::main().updateCanvasFormat();
#endif
//#else
// WindowSystem::main().updateCanvasFormat();
//#endif
}

void GL_Register()
Expand Down Expand Up @@ -192,7 +192,7 @@ void GL_DoUpdate()

// Blit screen to video.
ClientWindow::main().swapBuffers(
VR::modeNeedsStereoGLFormat(VR::mode())? gl::SwapStereoBuffers : gl::SwapMonoBuffer);
vrCfg().needsStereoGLFormat()? gl::SwapStereoBuffers : gl::SwapMonoBuffer);

// 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.
Expand Down Expand Up @@ -340,6 +340,8 @@ dd_bool GL_EarlyInit()
// Initialize the renderer into a 2D state.
GL_Init2DState();

GL_SetVSync(true); // will be overridden from vid-vsync

initGLOk = true;
return true;
}
Expand Down Expand Up @@ -562,9 +564,9 @@ Matrix4f GL_GetProjectionMatrix()
// We're assuming pixels are squares.
float aspect = viewpw / (float) viewph;

if (VR::mode() == VR::MODE_OCULUS_RIFT)
if (vrCfg().mode() == VRConfig::OculusRift)
{
aspect = VR::riftState.aspect();
aspect = vrCfg().oculusRift().aspect();
// A little trigonometry to apply aspect ratio to angles
float x = tan(0.5 * de::degreeToRadian(Rend_FieldOfView()));
yfov = de::radianToDegree(2.0 * atan2(x/aspect, 1.0f));
Expand All @@ -586,15 +588,15 @@ Matrix4f GL_GetProjectionMatrix()
* applies the viewpoint shift.
*/
float frustumShift = 0;
if (VR::applyFrustumShift)
if (vrCfg().frustumShift())
{
frustumShift = VR::eyeShift * glNearClip / VR::hudDistance;
frustumShift = vrCfg().eyeShift() * glNearClip / vrCfg().screenDistance();
}

return Matrix4f::frustum(-fW - frustumShift, fW - frustumShift,
-fH, fH,
glNearClip, glFarClip) *
Matrix4f::translate(Vector3f(-VR::eyeShift, 0, 0)) *
Matrix4f::translate(Vector3f(-vrCfg().eyeShift(), 0, 0)) *
Matrix4f::scale(Vector3f(1, 1, -1));
}

Expand Down
6 changes: 6 additions & 0 deletions doomsday/client/src/gl/sys_opengl.cpp
Expand Up @@ -419,6 +419,12 @@ void Sys_GLPrintExtensions(void)
printExtensions(QString((char const *) ((GLubyte const *(__stdcall *)(HDC))wglGetExtensionsStringARB)(wglGetCurrentDC())).split(" ", QString::SkipEmptyParts));
}
#endif

#ifdef Q_WS_X11
// List GLX extensions.
LOG_GL_MSG(" Extensions (GLX):");
printExtensions(QString(getGLXExtensionsString()).split(" ", QString::SkipEmptyParts));
#endif
}

dd_bool Sys_GLCheckError()
Expand Down
18 changes: 10 additions & 8 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -291,14 +291,16 @@ static void unlinkMobjLumobjs()
}
}

static void fieldOfViewChanged() {
if (VR::mode() == VR::MODE_OCULUS_RIFT) {
if (Con_GetFloat("rend-vr-rift-fovx") != fieldOfView)
static void fieldOfViewChanged()
{
if(vrCfg().mode() == VRConfig::OculusRift)
{
if(Con_GetFloat("rend-vr-rift-fovx") != fieldOfView)
Con_SetFloat("rend-vr-rift-fovx", fieldOfView);
}
else
{
if (Con_GetFloat("rend-vr-nonrift-fovx") != fieldOfView)
if(Con_GetFloat("rend-vr-nonrift-fovx") != fieldOfView)
Con_SetFloat("rend-vr-nonrift-fovx", fieldOfView);
}
}
Expand Down Expand Up @@ -427,7 +429,7 @@ void Rend_Register()
LensFx_Register();
fx::Vignette::consoleRegister();
fx::LensFlares::consoleRegister();
VR::consoleRegister();
VR_ConsoleRegister();
}

static void reportWallSectionDrawn(Line &line)
Expand Down Expand Up @@ -484,7 +486,7 @@ bool Rend_IsMTexDetails()

float Rend_FieldOfView()
{
if (VR::mode() == VR::MODE_OCULUS_RIFT)
if(vrCfg().mode() == VRConfig::OculusRift)
{
// fieldOfView = VR::riftFovX(); // Update for culling
// return VR::riftFovX();
Expand Down Expand Up @@ -538,9 +540,9 @@ Matrix4f Rend_GetModelViewMatrix(int consoleNum, bool useAngles)
* these values and is syncing with them independently (however, game has more
* latency).
*/
if((VR::mode() == VR::MODE_OCULUS_RIFT) && VR::hasHeadOrientation())
if((vrCfg().mode() == VRConfig::OculusRift) && vrCfg().oculusRift().isReady())
{
Vector3f const pry = VR::getHeadOrientation();
Vector3f const pry = vrCfg().oculusRift().headOrientation();

// Use angles directly from the Rift for best response.
roll = -radianToDegree(pry[1]);
Expand Down
6 changes: 4 additions & 2 deletions doomsday/client/src/render/viewports.cpp
Expand Up @@ -868,9 +868,11 @@ DENG_EXTERN_C void R_RenderPlayerView(int num)
// Setup for rendering the frame.
R_SetupFrame(player);

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

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

R_SetupPlayerSprites();

Expand Down Expand Up @@ -1322,7 +1324,7 @@ angle_t viewer_t::angle() const
{
// Apply the actual, current yaw offset. The game has omitted the "body yaw"
// portion from the value already.
a += (fixed_t)(radianToDegree(VR::getHeadOrientation()[2]) / 180 * ANGLE_180);
a += (fixed_t)(radianToDegree(vrCfg().oculusRift().headOrientation()[2]) / 180 * ANGLE_180);
}
return a;
}

0 comments on commit 05d297d

Please sign in to comment.