aboutsummaryrefslogtreecommitdiffstats
path: root/Samples/OculusWorldDemo/OculusWorldDemo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Samples/OculusWorldDemo/OculusWorldDemo.cpp')
-rw-r--r--Samples/OculusWorldDemo/OculusWorldDemo.cpp372
1 files changed, 248 insertions, 124 deletions
diff --git a/Samples/OculusWorldDemo/OculusWorldDemo.cpp b/Samples/OculusWorldDemo/OculusWorldDemo.cpp
index 99a924f..af62a81 100644
--- a/Samples/OculusWorldDemo/OculusWorldDemo.cpp
+++ b/Samples/OculusWorldDemo/OculusWorldDemo.cpp
@@ -6,7 +6,7 @@ Created : October 4, 2012
Authors : Michael Antonov, Andrew Reisse, Steve LaValle, Dov Katz
Peter Hoff, Dan Goodman, Bryan Croteau
-Copyright : Copyright 2012 Oculus VR, Inc. All Rights reserved.
+Copyright : Copyright 2012 Oculus VR, LLC All Rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -23,79 +23,90 @@ limitations under the License.
*************************************************************************************/
#include "OculusWorldDemo.h"
+#include "Kernel/OVR_Threads.h"
//-------------------------------------------------------------------------------------
// ***** OculusWorldDemoApp
-OculusWorldDemoApp::OculusWorldDemoApp()
- : pRender(0),
- WindowSize(1280,800),
- ScreenNumber(0),
- FirstScreenInCycle(0),
- LastVisionProcessingTime(0.),
- VisionTimesCount(0),
- VisionProcessingSum(0.),
- VisionProcessingAverage(0.),
-
- Hmd(0),
- StartTrackingCaps(0),
- UsingDebugHmd(false),
- LoadingState(LoadingState_Frame0),
- HaveVisionTracking(false),
- HavePositionTracker(false),
- HaveHMDConnected(false),
- HmdStatus(0),
- NotificationTimeout(0.0),
-
- // Initial location
- DistortionClearBlue(0),
- ShiftDown(false),
- CtrlDown(false),
- HmdSettingsChanged(false),
-
- // Modifiable options.
- RendertargetIsSharedByBothEyes(false),
- DynamicRezScalingEnabled(false),
- EnableSensor(true),
- ForceZeroIpd(false),
- DesiredPixelDensity(1.0f),
- FovSideTanMax(1.0f), // Updated based on Hmd.
- TimewarpEnabled(true),
- TimewarpNoJitEnabled(false),
- TimewarpRenderIntervalInSeconds(0.0f),
- FreezeEyeUpdate(false),
- FreezeEyeOneFrameRendered(false),
- CenterPupilDepthMeters(0.05f),
- ForceZeroHeadMovement(false),
- VsyncEnabled(true),
- MultisampleEnabled(true),
- IsLowPersistence(true),
- DynamicPrediction(true),
- DisplaySleep(false),
- PositionTrackingEnabled(true),
- PixelLuminanceOverdrive(true),
- HqAaDistortion(true),
- MirrorToWindow(true),
- SupportsSrgb(true),
-
- // Scene state
- SceneMode(Scene_World),
- GridDisplayMode(GridDisplay_None),
- GridMode(Grid_Lens),
- TextScreen(Text_None),
- BlocksShowType(0),
- BlocksCenter(0.0f, 0.0f, 0.0f)
+OculusWorldDemoApp::OculusWorldDemoApp() :
+ pRender(0),
+ WindowSize(1280,800),
+ ScreenNumber(0),
+ FirstScreenInCycle(0),
+ LastVisionProcessingTime(0.),
+ VisionTimesCount(0),
+ VisionProcessingSum(0.),
+ VisionProcessingAverage(0.),
+
+ Hmd(0),
+ StartTrackingCaps(0),
+ UsingDebugHmd(false),
+ LoadingState(LoadingState_Frame0),
+ HaveVisionTracking(false),
+ HavePositionTracker(false),
+ HaveHMDConnected(false),
+ HmdStatus(0),
+ NotificationTimeout(0.0),
+
+ // Initial location
+ DistortionClearBlue(0),
+ ShiftDown(false),
+ CtrlDown(false),
+ HmdSettingsChanged(false),
+
+ // Modifiable options.
+ RendertargetIsSharedByBothEyes(false),
+ DynamicRezScalingEnabled(false),
+ EnableSensor(true),
+ MonoscopicRender(false),
+ PositionTrackingScale(1.0f),
+ ScaleAffectsEyeHeight(false),
+ DesiredPixelDensity(1.0f),
+ FovSideTanMax(1.0f), // Updated based on Hmd.
+ FovSideTanLimit(1.0f), // Updated based on Hmd.
+ TimewarpEnabled(true),
+ TimewarpNoJitEnabled(false),
+ TimewarpRenderIntervalInSeconds(0.0f),
+ FreezeEyeUpdate(false),
+ FreezeEyeOneFrameRendered(false),
+ CenterPupilDepthMeters(0.05f),
+ ForceZeroHeadMovement(false),
+ VsyncEnabled(true),
+ MultisampleEnabled(true),
+#if defined(OVR_OS_LINUX)
+ LinuxFullscreenOnDevice(false),
+#endif
+ IsLowPersistence(true),
+ DynamicPrediction(true),
+ DisplaySleep(false),
+ PositionTrackingEnabled(true),
+ PixelLuminanceOverdrive(true),
+ HqAaDistortion(true),
+ MirrorToWindow(true),
+ SupportsSrgb(true),
+ IsLogging(false),
+
+ // Scene state
+ SceneMode(Scene_World),
+ GridDisplayMode(GridDisplay_None),
+ GridMode(Grid_Lens),
+ TextScreen(Text_None),
+ BlocksShowType(0),
+ BlocksCenter(0.0f, 0.0f, 0.0f)
{
FPS = 0.0f;
SecondsPerFrame = 0.0f;
FrameCounter = 0;
TotalFrameCounter = 0;
LastFpsUpdate = 0;
+ LastUpdate = 0.0;
EyeRenderSize[0] = EyeRenderSize[1] = Sizei(0);
DistortionClearBlue = false;
+
+ // EyeRenderDesc[], EyeTexture[] : Initialized in CalculateHmdValues()
}
OculusWorldDemoApp::~OculusWorldDemoApp()
@@ -122,6 +133,15 @@ int OculusWorldDemoApp::OnStartup(int argc, const char** argv)
// Sensor object is created from the HMD, to ensure that it is on the
// correct device.
+ #if defined(OVR_OS_WIN32)
+ OVR::Thread::SetCurrentPriority(Thread::HighestPriority);
+
+ if(OVR::Thread::GetCPUCount() >= 4) // Don't do this unless there are at least 4 processors, otherwise the process could hog the machine.
+ {
+ SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
+ }
+ #endif
+
ovr_Initialize();
Hmd = ovrHmd_Create(0);
@@ -131,7 +151,7 @@ int OculusWorldDemoApp::OnStartup(int argc, const char** argv)
Menu.SetPopupMessage("Unable to create HMD: %s", ovrHmd_GetLastError(NULL));
// If we didn't detect an Hmd, create a simulated one for debugging.
- Hmd = ovrHmd_CreateDebug(ovrHmd_DK1);
+ Hmd = ovrHmd_CreateDebug(ovrHmd_DK2);
UsingDebugHmd = true;
if (!Hmd)
{ // Failed Hmd creation.
@@ -202,13 +222,41 @@ int OculusWorldDemoApp::OnStartup(int argc, const char** argv)
InitMainFilePath();
PopulatePreloadScene();
-
+
LastUpdate = ovr_GetTimeInSeconds();
-
+
+ // Select renderer based on command line arguments.
+ for (int i = 1; i < argc; i++)
+ {
+ if (!strcmp(argv[i], "-StartPerfLog") && i < argc - 1)
+ {
+ ovrHmd_StartPerfLog(Hmd, argv[i + 1], 0);
+ }
+ }
+
return 0;
}
+// Temporary helper function. Will go away with the next release.
+// Requires a valid current OpenGL context in order to work.
+static bool MultisamplingIsSupported()
+{
+ #if defined(OVR_OS_MAC)
+ const char* pVersion = (const char*)glGetString(GL_VERSION);
+ int majorVersion = 0;
+ if(pVersion)
+ {
+ sscanf(pVersion, "%d", &majorVersion); // On Mac the gl version string begins with major.minor
+ return (majorVersion >= 3);
+ }
+ return false;
+ #else
+ return true;
+ #endif
+}
+
+
bool OculusWorldDemoApp::SetupWindowAndRendering(int argc, const char** argv)
{
// *** Window creation
@@ -254,14 +302,17 @@ bool OculusWorldDemoApp::SetupWindowAndRendering(int argc, const char** argv)
}
pPlatform->SetWindowTitle(title);
- // Enable multi-sampling by default.
- RenderParams.Display = DisplayId(Hmd->DisplayDeviceName, Hmd->DisplayId);
- RenderParams.Multisample = 1;
- RenderParams.Resolution = Hmd->Resolution;
-
if (OVR_strcmp(graphics, "GL") == 0 && !(Hmd->HmdCaps & ovrHmdCap_ExtendDesktop))
SupportsSrgb = false;
+ // Enable multi-sampling by default if possible.
+ MultisampleEnabled = MultisamplingIsSupported();
+
+ RenderParams.Display = DisplayId(Hmd->DisplayDeviceName, Hmd->DisplayId);
+ RenderParams.SrgbBackBuffer = SupportsSrgb && false; // don't create sRGB back-buffer for OWD
+ RenderParams.Multisample = MultisampleEnabled ? 1 : 0;
+ RenderParams.Resolution = Hmd->Resolution;
+
//RenderParams.Fullscreen = true;
pRender = pPlatform->SetupGraphics(OVR_DEFAULT_RENDER_DEVICE_SET,
graphics, RenderParams);
@@ -336,15 +387,21 @@ void OculusWorldDemoApp::PopulateOptionMenu()
Menu.AddBool( "Sensor Toggle 'F6'", &EnableSensor).
AddShortcutKey(Key_F6).
SetNotify(this, &OWD::HmdSensorToggle);
- Menu.AddBool( "Render Target.Zero IPD 'F7'", &ForceZeroIpd).
+ Menu.AddBool( "Render Target.Monoscopic Render 'F7'", &MonoscopicRender).
AddShortcutKey(Key_F7).
SetNotify(this, &OWD::HmdSettingChangeFreeRTs);
- Menu.AddFloat("Render Target.Max Fov", &FovSideTanMax, 0.2f, FovSideTanLimit, 0.02f,
+ Menu.AddFloat( "Render Target.Max Fov", &FovSideTanMax, 0.2f, FovSideTanLimit, 0.02f,
"%.1f Degrees", 1.0f, &FormatMaxFromSideTan).
SetNotify(this, &OWD::HmdSettingChange).
AddShortcutUpKey(Key_I).AddShortcutDownKey(Key_K);
- Menu.AddFloat("Render Target.Pixel Density", &DesiredPixelDensity, 0.5f, 1.5, 0.025f, "%3.2f", 1.0f).
+ Menu.AddFloat("Render Target.Pixel Density", &DesiredPixelDensity, 0.5f, 2.5, 0.025f, "%3.2f", 1.0f).
SetNotify(this, &OWD::HmdSettingChange);
+
+ if(MultisamplingIsSupported())
+ Menu.AddBool("Render Target.MultiSample 'F4'", &MultisampleEnabled) .AddShortcutKey(Key_F4).SetNotify(this, &OWD::MultisampleChange);
+
+ Menu.AddBool("Render Target.High Quality Distortion 'F5'", &HqAaDistortion).AddShortcutKey(Key_F5).SetNotify(this, &OWD::HmdSettingChange);
+ //Menu.AddBool("Render Target.sRGB Distortion 'F6'", &SupportsSrgb).AddShortcutKey(Key_F6).SetNotify(this, &OWD::MultisampleChange);
Menu.AddEnum( "Render Target.Distortion Clear Color", &DistortionClearBlue).
SetNotify(this, &OWD::DistortionClearColorChange).
AddEnumValue("Black", 0).
@@ -360,16 +417,19 @@ void OculusWorldDemoApp::PopulateOptionMenu()
AddShortcutUpKey(Key_J).AddShortcutDownKey(Key_U);
// First page properties
- Menu.AddFloat("User Eye Height", &ThePlayer.UserEyeHeight, 0.2f, 2.5f, 0.02f,
- "%4.2f m").SetNotify(this, &OWD::EyeHeightChange).
- AddShortcutUpKey(Key_Equal).AddShortcutDownKey(Key_Minus);
- Menu.AddFloat("Center Pupil Depth", &CenterPupilDepthMeters, 0.0f, 0.2f, 0.001f,
- "%4.3f m").SetNotify(this, &OWD::CenterPupilDepthChange);
+ Menu.AddFloat("Player.Position Tracking Scale", &PositionTrackingScale, 0.00f, 50.0f, 0.05f).
+ SetNotify(this, &OWD::EyeHeightChange);
+ Menu.AddBool("Player.Scale Affects Player Height", &ScaleAffectsEyeHeight).SetNotify(this, &OWD::EyeHeightChange);
+ Menu.AddFloat("Player.User Eye Height", &ThePlayer.UserEyeHeight, 0.2f, 2.5f, 0.02f,
+ "%4.2f m").SetNotify(this, &OWD::EyeHeightChange).
+ AddShortcutUpKey(Key_Equal).AddShortcutDownKey(Key_Minus);
+ Menu.AddFloat("Player.Center Pupil Depth", &CenterPupilDepthMeters, 0.0f, 0.2f, 0.001f,
+ "%4.3f m").SetNotify(this, &OWD::CenterPupilDepthChange);
+
Menu.AddBool("Body Relative Motion",&ThePlayer.bMotionRelativeToBody).AddShortcutKey(Key_E);
Menu.AddBool("Zero Head Movement", &ForceZeroHeadMovement) .AddShortcutKey(Key_F7, ShortcutKey::Shift_RequireOn);
Menu.AddBool("VSync 'V'", &VsyncEnabled) .AddShortcutKey(Key_V).SetNotify(this, &OWD::HmdSettingChange);
- Menu.AddBool("MultiSample 'F4'", &MultisampleEnabled) .AddShortcutKey(Key_F4).SetNotify(this, &OWD::MultisampleChange);
- Menu.AddBool("High Quality Distortion", &HqAaDistortion) .AddShortcutKey(Key_F5).SetNotify(this, &OWD::HmdSettingChange);
+ Menu.AddBool("Logging 'L'", &IsLogging).AddShortcutKey(Key_L).SetNotify(this, &OWD::ToggleLogging);
Menu.AddTrigger("Recenter HMD pose 'R'").AddShortcutKey(Key_R).SetNotify(this, &OWD::ResetHmdPose);
// Add DK2 options to menu only for that headset.
@@ -408,11 +468,11 @@ void OculusWorldDemoApp::CalculateHmdValues()
eyeFov[1] = FovPort::Min(eyeFov[1], FovPort(FovSideTanMax));
- if (ForceZeroIpd)
+ if (MonoscopicRender)
{
- // ForceZeroIpd does three things:
+ // MonoscopicRender does three things:
// 1) Sets FOV to maximum symmetrical FOV based on both eyes
- // 2) Sets eye ViewAdjust values to 0.0 (effective IPD == 0)
+ // 2) Sets eye HmdToEyeViewOffset values to 0.0 (effective IPD == 0)
// 3) Uses only the Left texture for rendering.
eyeFov[0] = FovPort::Max(eyeFov[0], eyeFov[1]);
@@ -427,7 +487,7 @@ void OculusWorldDemoApp::CalculateHmdValues()
EyeRenderSize[1] = EyeRenderSize[0];
// Store texture pointers that will be passed for rendering.
- EyeTexture[0] = RenderTargets[Rendertarget_Left].Tex;
+ EyeTexture[0] = RenderTargets[Rendertarget_Left].OvrTex;
EyeTexture[0].Header.TextureSize = textureSize;
EyeTexture[0].Header.RenderViewport = Recti(EyeRenderSize[0]);
// Right eye is the same.
@@ -455,14 +515,13 @@ void OculusWorldDemoApp::CalculateHmdValues()
// Store texture pointers that will be passed for rendering.
// Same texture is used, but with different viewports.
- EyeTexture[0] = RenderTargets[Rendertarget_BothEyes].Tex;
+ EyeTexture[0] = RenderTargets[Rendertarget_BothEyes].OvrTex;
EyeTexture[0].Header.TextureSize = rtSize;
EyeTexture[0].Header.RenderViewport = Recti(Vector2i(0), EyeRenderSize[0]);
- EyeTexture[1] = RenderTargets[Rendertarget_BothEyes].Tex;
+ EyeTexture[1] = RenderTargets[Rendertarget_BothEyes].OvrTex;
EyeTexture[1].Header.TextureSize = rtSize;
EyeTexture[1].Header.RenderViewport = Recti(Vector2i((rtSize.w+1)/2, 0), EyeRenderSize[1]);
}
-
else
{
Sizei tex0Size = EnsureRendertargetAtLeastThisBig(Rendertarget_Left, recommenedTex0Size);
@@ -472,15 +531,17 @@ void OculusWorldDemoApp::CalculateHmdValues()
EyeRenderSize[1] = Sizei::Min(tex1Size, recommenedTex1Size);
// Store texture pointers and viewports that will be passed for rendering.
- EyeTexture[0] = RenderTargets[Rendertarget_Left].Tex;
+ EyeTexture[0] = RenderTargets[Rendertarget_Left].OvrTex;
EyeTexture[0].Header.TextureSize = tex0Size;
EyeTexture[0].Header.RenderViewport = Recti(EyeRenderSize[0]);
- EyeTexture[1] = RenderTargets[Rendertarget_Right].Tex;
+ EyeTexture[1] = RenderTargets[Rendertarget_Right].OvrTex;
EyeTexture[1].Header.TextureSize = tex1Size;
EyeTexture[1].Header.RenderViewport = Recti(EyeRenderSize[1]);
}
}
+ DrawEyeTargets = MultisampleEnabled ? MsaaRenderTargets : RenderTargets;
+
// Hmd caps.
unsigned hmdCaps = (VsyncEnabled ? 0 : ovrHmdCap_NoVSync);
if (IsLowPersistence)
@@ -523,19 +584,22 @@ void OculusWorldDemoApp::CalculateHmdValues()
distortionCaps |= ovrDistortionCap_ProfileNoTimewarpSpinWaits;
if(HqAaDistortion)
distortionCaps |= ovrDistortionCap_HqDistortion;
+#if defined(OVR_OS_LINUX)
+ if (LinuxFullscreenOnDevice)
+ distortionCaps |= ovrDistortionCap_LinuxDevFullscreen;
+#endif
- if (!ovrHmd_ConfigureRendering( Hmd, &config, distortionCaps,
- eyeFov, EyeRenderDesc ))
+ if (!ovrHmd_ConfigureRendering( Hmd, &config, distortionCaps, eyeFov, EyeRenderDesc ))
{
// Fail exit? TBD
return;
}
- if (ForceZeroIpd)
+ if (MonoscopicRender)
{
// Remove IPD adjust
- EyeRenderDesc[0].ViewAdjust = Vector3f(0);
- EyeRenderDesc[1].ViewAdjust = Vector3f(0);
+ EyeRenderDesc[0].HmdToEyeViewOffset = Vector3f(0);
+ EyeRenderDesc[1].HmdToEyeViewOffset = Vector3f(0);
}
unsigned sensorCaps = ovrTrackingCap_Orientation|ovrTrackingCap_MagYawCorrection;
@@ -557,9 +621,9 @@ void OculusWorldDemoApp::CalculateHmdValues()
Vector2f orthoScale1 = Vector2f(1.0f) / Vector2f(EyeRenderDesc[1].PixelsPerTanAngleAtCenter);
OrthoProjection[0] = ovrMatrix4f_OrthoSubProjection(Projection[0], orthoScale0, orthoDistance,
- EyeRenderDesc[0].ViewAdjust.x);
+ EyeRenderDesc[0].HmdToEyeViewOffset.x);
OrthoProjection[1] = ovrMatrix4f_OrthoSubProjection(Projection[1], orthoScale1, orthoDistance,
- EyeRenderDesc[1].ViewAdjust.x);
+ EyeRenderDesc[1].HmdToEyeViewOffset.x);
// all done
HmdSettingsChanged = false;
@@ -576,15 +640,20 @@ Sizei OculusWorldDemoApp::EnsureRendertargetAtLeastThisBig(int rtNum, Sizei requ
Sizei newRTSize;
RenderTarget& rt = RenderTargets[rtNum];
+ RenderTarget& msrt = MsaaRenderTargets[rtNum];
if (!rt.pTex)
{
// Hmmm... someone nuked my texture. Rez change or similar. Make sure we reallocate.
- rt.Tex.Header.TextureSize = Sizei(0);
+ rt.OvrTex.Header.TextureSize = Sizei(0);
+
+ if(MultisampleEnabled)
+ msrt.OvrTex.Header.TextureSize = Sizei(0);
+
newRTSize = requestedSize;
}
else
{
- newRTSize = rt.Tex.Header.TextureSize;
+ newRTSize = rt.OvrTex.Header.TextureSize;
}
// %50 linear growth each time is a nice balance between being too greedy
@@ -603,20 +672,30 @@ Sizei OculusWorldDemoApp::EnsureRendertargetAtLeastThisBig(int rtNum, Sizei requ
newRTSize = Sizei::Max(Sizei::Min(newRTSize, Sizei(4096)), Sizei(64));
// Does that require actual reallocation?
- if (Sizei(rt.Tex.Header.TextureSize) != newRTSize)
+ if (Sizei(rt.OvrTex.Header.TextureSize) != newRTSize)
{
- int format = Texture_RGBA | Texture_RenderTarget | (MultisampleEnabled ? 4 : 1);
+ int format = Texture_RGBA | Texture_RenderTarget;
if (SupportsSrgb)
format |= Texture_SRGB;
rt.pTex = *pRender->CreateTexture(format, newRTSize.w, newRTSize.h, NULL);
rt.pTex->SetSampleMode(Sample_ClampBorder | Sample_Linear);
+
+ // Configure texture for SDK Rendering.
+ rt.OvrTex = rt.pTex->Get_ovrTexture();
+
+ if(MultisampleEnabled)
+ {
+ int msaaformat = format | 4; // 4 is MSAA rate
+ msrt.pTex = *pRender->CreateTexture(msaaformat, newRTSize.w, newRTSize.h, NULL);
+ msrt.pTex->SetSampleMode(Sample_ClampBorder | Sample_Linear);
- // Configure texture for SDK Rendering.
- rt.Tex = rt.pTex->Get_ovrTexture();
+ // Configure texture for SDK Rendering.
+ msrt.OvrTex = rt.pTex->Get_ovrTexture();
+ }
}
-
+
return newRTSize;
}
@@ -670,7 +749,7 @@ void OculusWorldDemoApp::OnKey(OVR::KeyCode key, int chr, bool down, int modifie
// Back to primary windowed
if (!down) ChangeDisplay ( true, false, false );
break;
-
+
case Key_F9:
// Cycle through displays, going fullscreen on each one.
if (!down) ChangeDisplay ( false, true, false );
@@ -753,10 +832,6 @@ Matrix4f OculusWorldDemoApp::CalculateViewFromPose(const Posef& pose)
// Transform the position of the center eye in the real world (i.e. sitting in your chair)
// into the frame of the player's virtual body.
- // It is important to have head movement in scale with IPD.
- // If you shrink one, you should also shrink the other.
- // So with zero IPD (i.e. everything at infinity),
- // head movement should also be zero.
Vector3f viewPos = ForceZeroHeadMovement ? ThePlayer.BodyPos : worldPose.Translation;
Matrix4f view = Matrix4f::LookAtRH(viewPos, viewPos + forward, up);
@@ -866,17 +941,25 @@ void OculusWorldDemoApp::OnIdle()
pRender->BeginScene(PostProcess_None);
- if (ForceZeroIpd)
+ ovrTrackingState hmdState;
+ ovrVector3f hmdToEyeViewOffset[2] = { EyeRenderDesc[0].HmdToEyeViewOffset, EyeRenderDesc[1].HmdToEyeViewOffset };
+ ovrHmd_GetEyePoses(Hmd, 0, hmdToEyeViewOffset, EyeRenderPose, &hmdState);
+
+ // It is important to have head movement in scale with IPD.
+ // If you shrink one, you should also shrink the other.
+ // So with zero IPD (i.e. everything at infinity),
+ // head movement should also be zero.
+ EyeRenderPose[0].Position = ((Vector3f)EyeRenderPose[0].Position) * PositionTrackingScale;
+ EyeRenderPose[1].Position = ((Vector3f)EyeRenderPose[1].Position) * PositionTrackingScale;
+
+ if (MonoscopicRender)
{
// Zero IPD eye rendering: draw into left eye only,
// re-use texture for right eye.
- pRender->SetRenderTarget(RenderTargets[Rendertarget_Left].pTex);
+ pRender->SetRenderTarget(DrawEyeTargets[Rendertarget_Left].pTex);
pRender->Clear();
- EyeRenderPose[0] =
- EyeRenderPose[1] = ovrHmd_GetEyePose(Hmd, ovrEye_Left);
-
- View = CalculateViewFromPose(EyeRenderPose[0]);
+ View = CalculateViewFromPose(hmdState.HeadPose.ThePose);
RenderEyeView(ovrEye_Left);
// Note: Second eye gets texture is (initialized to same value above).
}
@@ -884,14 +967,13 @@ void OculusWorldDemoApp::OnIdle()
else if (RendertargetIsSharedByBothEyes)
{
// Shared render target eye rendering; set up RT once for both eyes.
- pRender->SetRenderTarget(RenderTargets[Rendertarget_BothEyes].pTex);
+ pRender->SetRenderTarget(DrawEyeTargets[Rendertarget_BothEyes].pTex);
pRender->Clear();
for (int eyeIndex = 0; eyeIndex < ovrEye_Count; eyeIndex++)
{
ovrEyeType eye = Hmd->EyeRenderOrder[eyeIndex];
- EyeRenderPose[eye] = ovrHmd_GetEyePose(Hmd, eye);
View = CalculateViewFromPose(EyeRenderPose[eye]);
RenderEyeView(eye);
}
@@ -899,22 +981,39 @@ void OculusWorldDemoApp::OnIdle()
else
{
+
// Separate eye rendering - each eye gets its own render target.
for (int eyeIndex = 0; eyeIndex < ovrEye_Count; eyeIndex++)
{
ovrEyeType eye = Hmd->EyeRenderOrder[eyeIndex];
pRender->SetRenderTarget(
- RenderTargets[(eye == 0) ? Rendertarget_Left : Rendertarget_Right].pTex);
+ DrawEyeTargets[(eye == 0) ? Rendertarget_Left : Rendertarget_Right].pTex);
pRender->Clear();
- EyeRenderPose[eye] = ovrHmd_GetEyePose(Hmd, eye);
View = CalculateViewFromPose(EyeRenderPose[eye]);
RenderEyeView(eye);
}
}
pRender->SetDefaultRenderTarget();
- pRender->FinishScene();
+ pRender->FinishScene();
+
+ if(MultisampleEnabled)
+ {
+ if (MonoscopicRender)
+ {
+ pRender->ResolveMsaa(MsaaRenderTargets[Rendertarget_Left].pTex, RenderTargets[Rendertarget_Left].pTex);
+ }
+ else if (RendertargetIsSharedByBothEyes)
+ {
+ pRender->ResolveMsaa(MsaaRenderTargets[Rendertarget_BothEyes].pTex, RenderTargets[Rendertarget_BothEyes].pTex);
+ }
+ else
+ {
+ for (int eyeIndex = 0; eyeIndex < ovrEye_Count; eyeIndex++)
+ pRender->ResolveMsaa(MsaaRenderTargets[eyeIndex].pTex, RenderTargets[eyeIndex].pTex);
+ }
+ }
}
/*
@@ -1072,8 +1171,6 @@ void OculusWorldDemoApp::UpdateVisionProcessingTime(const ovrTrackingState& trac
void OculusWorldDemoApp::RenderEyeView(ovrEyeType eye)
{
Recti renderViewport = EyeTexture[eye].Header.RenderViewport;
- Matrix4f viewAdjust = Matrix4f::Translation(Vector3f(EyeRenderDesc[eye].ViewAdjust));
-
// *** 3D - Configures Viewport/Projection and Render
@@ -1088,7 +1185,7 @@ void OculusWorldDemoApp::RenderEyeView(ovrEyeType eye)
{
if (SceneMode != Scene_OculusCubes)
{
- MainScene.Render(pRender, viewAdjust * View);
+ MainScene.Render(pRender, View);
RenderAnimatedBlocks(eye, ovr_GetTimeInSeconds());
}
@@ -1097,12 +1194,12 @@ void OculusWorldDemoApp::RenderEyeView(ovrEyeType eye)
// Draw scene cubes overlay. Red if position tracked, blue otherwise.
Scene sceneCubes = (HmdStatus & ovrStatus_PositionTracked) ?
RedCubesScene : BlueCubesScene;
- sceneCubes.Render(pRender, viewAdjust * View * baseTranslate * baseYaw);
+ sceneCubes.Render(pRender, View * baseTranslate * baseYaw);
}
else if (SceneMode == Scene_OculusCubes)
{
- OculusCubesScene.Render(pRender, viewAdjust * View * baseTranslate * baseYaw);
+ OculusCubesScene.Render(pRender, View * baseTranslate * baseYaw);
}
}
@@ -1189,7 +1286,7 @@ void OculusWorldDemoApp::RenderTextInfoHud(float textHeight)
// Rendered size changes based on selected options & dynamic rendering.
int pixelSizeWidth = EyeTexture[0].Header.RenderViewport.Size.w +
- ((!ForceZeroIpd) ?
+ ((!MonoscopicRender) ?
EyeTexture[1].Header.RenderViewport.Size.w : 0);
int pixelSizeHeight = ( EyeTexture[0].Header.RenderViewport.Size.h +
EyeTexture[1].Header.RenderViewport.Size.h ) / 2;
@@ -1306,7 +1403,10 @@ void OculusWorldDemoApp::HmdSettingChangeFreeRTs(OptionVar*)
HmdSettingsChanged = true;
// Cause the RTs to be recreated with the new mode.
for ( int rtNum = 0; rtNum < Rendertarget_LAST; rtNum++ )
- RenderTargets[rtNum].pTex = NULL;
+ {
+ RenderTargets[rtNum].pTex = NULL;
+ MsaaRenderTargets[rtNum].pTex = NULL;
+ }
}
void OculusWorldDemoApp::MultisampleChange(OptionVar*)
@@ -1327,6 +1427,18 @@ void OculusWorldDemoApp::DistortionClearColorChange(OptionVar*)
clearColor[(int)DistortionClearBlue], 4);
}
+void OculusWorldDemoApp::ToggleLogging(OptionVar*)
+{
+ if (IsLogging)
+ {
+ ovrHmd_StartPerfLog(Hmd, "OWDLog.csv", 0);
+ }
+ else
+ {
+ ovrHmd_StopPerfLog(Hmd);
+ }
+}
+
void OculusWorldDemoApp::ResetHmdPose(OptionVar* /* = 0 */)
{
ovrHmd_RecenterPose(Hmd);
@@ -1340,7 +1452,6 @@ void OculusWorldDemoApp::ProcessDeviceNotificationQueue()
// TBD: Process device plug & Unplug
}
-
//-----------------------------------------------------------------------------
void OculusWorldDemoApp::ChangeDisplay ( bool bBackToWindowed, bool bNextFullscreen,
bool bFullWindowDebugging )
@@ -1422,6 +1533,10 @@ void OculusWorldDemoApp::ChangeDisplay ( bool bBackToWindowed, bool bNextFullscr
}
// Always restore windowed mode before going to next screen, even if we were already fullscreen.
+#if defined(OVR_OS_LINUX)
+ LinuxFullscreenOnDevice = false;
+ HmdSettingsChanged = true;
+#endif
pPlatform->SetFullscreen(RenderParams, Display_Window);
if ( screenNumberToSwitchTo >= 0 )
{
@@ -1429,6 +1544,15 @@ void OculusWorldDemoApp::ChangeDisplay ( bool bBackToWindowed, bool bNextFullscr
RenderParams.Display = pPlatform->GetDisplay(screenNumberToSwitchTo);
pRender->SetParams(RenderParams);
pPlatform->SetFullscreen(RenderParams, Display_Fullscreen);
+
+#if defined(OVR_OS_LINUX)
+ DisplayId HMD (Hmd->DisplayDeviceName, Hmd->DisplayId);
+ if (pPlatform->GetDisplay(screenNumberToSwitchTo) == HMD)
+ {
+ LinuxFullscreenOnDevice = true;
+ HmdSettingsChanged = true;
+ }
+#endif
}
}