aboutsummaryrefslogtreecommitdiffstats
path: root/Samples/OculusRoomTiny
diff options
context:
space:
mode:
Diffstat (limited to 'Samples/OculusRoomTiny')
-rw-r--r--Samples/OculusRoomTiny/OculusRoomModel.cpp4
-rw-r--r--Samples/OculusRoomTiny/Projects/Win/VS2010/OculusRoomTiny.vcxproj1
-rw-r--r--Samples/OculusRoomTiny/Projects/Win/VS2010/OculusRoomTiny.vcxproj.filters3
-rw-r--r--Samples/OculusRoomTiny/Projects/Win/VS2012/OculusRoomTiny.vcxproj1
-rw-r--r--Samples/OculusRoomTiny/Projects/Win/VS2012/OculusRoomTiny.vcxproj.filters3
-rw-r--r--Samples/OculusRoomTiny/Projects/Win/VS2013/OculusRoomTiny.vcxproj1
-rw-r--r--Samples/OculusRoomTiny/Projects/Win/VS2013/OculusRoomTiny.vcxproj.filters3
-rw-r--r--Samples/OculusRoomTiny/RenderTiny_D3D11_Device.cpp114
-rw-r--r--Samples/OculusRoomTiny/RenderTiny_D3D11_Device.h72
-rw-r--r--Samples/OculusRoomTiny/Win32_OculusRoomTiny.cpp40
-rw-r--r--Samples/OculusRoomTiny/Win32_OculusRoomTiny_Util.cpp16
11 files changed, 168 insertions, 90 deletions
diff --git a/Samples/OculusRoomTiny/OculusRoomModel.cpp b/Samples/OculusRoomTiny/OculusRoomModel.cpp
index a7776a0..544e8c8 100644
--- a/Samples/OculusRoomTiny/OculusRoomModel.cpp
+++ b/Samples/OculusRoomTiny/OculusRoomModel.cpp
@@ -257,7 +257,7 @@ void PopulateRoomScene(Scene* scene, RenderDevice* render)
// Render a debug marker static in rift (special request for eye-tracking)
-void renderSphere(RenderDevice* render, Vector3f ViewAdjust, float metresLeft, float metresUp, float metresAway, float metresRadius,
+void renderSphere(RenderDevice* render, Vector3f HmdToEyeViewOffset, float metresLeft, float metresUp, float metresAway, float metresRadius,
unsigned char red,unsigned char green,unsigned char blue)
{
//Get textures, if haven't already
@@ -295,7 +295,7 @@ void renderSphere(RenderDevice* render, Vector3f ViewAdjust, float metresLeft, f
//Render object
Matrix4f view = Matrix4f::LookAtRH(Vector3f(0,0,0), Vector3f(0,0,0) + Vector3f(0,0,1), Vector3f(0,1,0));
- scene->Render(render, Matrix4f::Translation(ViewAdjust) * view);
+ scene->Render(render, Matrix4f::Translation(HmdToEyeViewOffset) * view);
//Delete object
delete scene;
diff --git a/Samples/OculusRoomTiny/Projects/Win/VS2010/OculusRoomTiny.vcxproj b/Samples/OculusRoomTiny/Projects/Win/VS2010/OculusRoomTiny.vcxproj
index 9e3c1b1..0d66997 100644
--- a/Samples/OculusRoomTiny/Projects/Win/VS2010/OculusRoomTiny.vcxproj
+++ b/Samples/OculusRoomTiny/Projects/Win/VS2010/OculusRoomTiny.vcxproj
@@ -183,7 +183,6 @@
<ItemGroup>
<ClInclude Include="../../../RenderTiny_D3D11_Device.h" />
<ClInclude Include="..\..\..\..\CommonSrc\Platform\Win32_Gamepad.h" />
- <ClInclude Include="..\..\..\HSWDisplay_Util.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
diff --git a/Samples/OculusRoomTiny/Projects/Win/VS2010/OculusRoomTiny.vcxproj.filters b/Samples/OculusRoomTiny/Projects/Win/VS2010/OculusRoomTiny.vcxproj.filters
index 51fe5fe..8b74b17 100644
--- a/Samples/OculusRoomTiny/Projects/Win/VS2010/OculusRoomTiny.vcxproj.filters
+++ b/Samples/OculusRoomTiny/Projects/Win/VS2010/OculusRoomTiny.vcxproj.filters
@@ -19,9 +19,6 @@
<ClInclude Include="../../../RenderTiny_D3D11_Device.h">
<Filter>Util</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\HSWDisplay_Util.h">
- <Filter>Util</Filter>
- </ClInclude>
<ClInclude Include="..\..\..\..\CommonSrc\Platform\Win32_Gamepad.h">
<Filter>CommonSrc</Filter>
</ClInclude>
diff --git a/Samples/OculusRoomTiny/Projects/Win/VS2012/OculusRoomTiny.vcxproj b/Samples/OculusRoomTiny/Projects/Win/VS2012/OculusRoomTiny.vcxproj
index cc9dd3e..40c892f 100644
--- a/Samples/OculusRoomTiny/Projects/Win/VS2012/OculusRoomTiny.vcxproj
+++ b/Samples/OculusRoomTiny/Projects/Win/VS2012/OculusRoomTiny.vcxproj
@@ -191,7 +191,6 @@
<ItemGroup>
<ClInclude Include="../../../RenderTiny_D3D11_Device.h" />
<ClInclude Include="..\..\..\..\CommonSrc\Platform\Win32_Gamepad.h" />
- <ClInclude Include="..\..\..\HSWDisplay_Util.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
diff --git a/Samples/OculusRoomTiny/Projects/Win/VS2012/OculusRoomTiny.vcxproj.filters b/Samples/OculusRoomTiny/Projects/Win/VS2012/OculusRoomTiny.vcxproj.filters
index 4b0ebdd..0cf3c0e 100644
--- a/Samples/OculusRoomTiny/Projects/Win/VS2012/OculusRoomTiny.vcxproj.filters
+++ b/Samples/OculusRoomTiny/Projects/Win/VS2012/OculusRoomTiny.vcxproj.filters
@@ -27,9 +27,6 @@
<ClInclude Include="../../../RenderTiny_D3D11_Device.h">
<Filter>Util</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\HSWDisplay_Util.h">
- <Filter>Util</Filter>
- </ClInclude>
<ClInclude Include="..\..\..\..\CommonSrc\Platform\Win32_Gamepad.h">
<Filter>CommonSrc</Filter>
</ClInclude>
diff --git a/Samples/OculusRoomTiny/Projects/Win/VS2013/OculusRoomTiny.vcxproj b/Samples/OculusRoomTiny/Projects/Win/VS2013/OculusRoomTiny.vcxproj
index a85b395..15b514d 100644
--- a/Samples/OculusRoomTiny/Projects/Win/VS2013/OculusRoomTiny.vcxproj
+++ b/Samples/OculusRoomTiny/Projects/Win/VS2013/OculusRoomTiny.vcxproj
@@ -201,7 +201,6 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\CommonSrc\Platform\Win32_Gamepad.h" />
- <ClInclude Include="..\..\..\HSWDisplay_Util.h" />
<ClInclude Include="..\..\..\RenderTiny_D3D11_Device.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
diff --git a/Samples/OculusRoomTiny/Projects/Win/VS2013/OculusRoomTiny.vcxproj.filters b/Samples/OculusRoomTiny/Projects/Win/VS2013/OculusRoomTiny.vcxproj.filters
index 4beea60..a55d446 100644
--- a/Samples/OculusRoomTiny/Projects/Win/VS2013/OculusRoomTiny.vcxproj.filters
+++ b/Samples/OculusRoomTiny/Projects/Win/VS2013/OculusRoomTiny.vcxproj.filters
@@ -30,9 +30,6 @@
<ClInclude Include="..\..\..\RenderTiny_D3D11_Device.h">
<Filter>Util</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\HSWDisplay_Util.h">
- <Filter>Util</Filter>
- </ClInclude>
<ClInclude Include="..\..\..\..\CommonSrc\Platform\Win32_Gamepad.h">
<Filter>CommonSrc</Filter>
</ClInclude>
diff --git a/Samples/OculusRoomTiny/RenderTiny_D3D11_Device.cpp b/Samples/OculusRoomTiny/RenderTiny_D3D11_Device.cpp
index 24035da..1e085e8 100644
--- a/Samples/OculusRoomTiny/RenderTiny_D3D11_Device.cpp
+++ b/Samples/OculusRoomTiny/RenderTiny_D3D11_Device.cpp
@@ -5,7 +5,7 @@ Content : RenderDevice implementation for D3DX10/11.
Created : September 10, 2012
Authors : Andrew Reisse
-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.
@@ -191,7 +191,7 @@ static const char* FShaderSrcs[FShader_Count] =
//-------------------------------------------------------------------------------------
// ***** Buffer
-bool Buffer::Data(int use, const void *buffer, size_t size)
+bool Buffer::Data(int use, const void* buffer, size_t size)
{
if (D3DBuffer && Size >= size)
{
@@ -281,7 +281,7 @@ void* Buffer::Map(size_t start, size_t size, int flags)
return NULL;
}
-bool Buffer::Unmap(void *m)
+bool Buffer::Unmap(void* m)
{
OVR_UNUSED(m);
@@ -324,28 +324,43 @@ template<> void Shader<Shader_Pixel, ID3D11PixelShader>::SetUniformBuffer(Buffer
//-------------------------------------------------------------------------------------
// ***** Shader Base
-ShaderBase::ShaderBase(RenderDevice* r, ShaderStage stage)
- : Stage(stage), Ren(r), UniformData(0)
+ShaderBase::ShaderBase(RenderDevice* r, ShaderStage stage) :
+ Stage(stage),
+ Ren(r),
+ UniformData(NULL),
+ UniformsSize(-1)
+{
+}
+
+ShaderBase::ShaderBase(ShaderStage s) :
+ Stage(s),
+ Ren(NULL),
+ UniformData(NULL),
+ UniformsSize(-1)
{
}
ShaderBase::~ShaderBase()
{
- if (UniformData)
- OVR_FREE(UniformData);
+ if (UniformData)
+ {
+ OVR_FREE(UniformData);
+ UniformData = NULL;
+ }
}
bool ShaderBase::SetUniform(const char* name, int n, const float* v)
{
- for(unsigned i = 0; i < UniformInfo.GetSize(); i++)
+ for (int i = 0; i < UniformInfo.GetSizeI(); i++)
{
- if (!strcmp(UniformInfo[i].Name.ToCStr(), name))
+ if (UniformInfo[i].Name == name)
{
memcpy(UniformData + UniformInfo[i].Offset, v, n * sizeof(float));
- return 1;
+ return true;
}
}
- return 0;
+
+ return false;
}
bool ShaderBase::SetUniformBool(const char* name, int n, const bool* v)
@@ -424,10 +439,19 @@ void ShaderBase::UpdateBuffer(Buffer* buf)
//-------------------------------------------------------------------------------------
// ***** Texture
//
-Texture::Texture(RenderDevice* ren, int fmt, int w, int h)
- : Ren(ren), Tex(NULL), TexSv(NULL), TexRtv(NULL), TexDsv(NULL), Width(w), Height(h)
+Texture::Texture(RenderDevice* ren, int fmt, int w, int h) :
+ Ren(ren),
+ Tex(NULL),
+ TexSv(NULL),
+ TexRtv(NULL),
+ TexDsv(NULL),
+ Sampler(NULL),
+ Width(w),
+ Height(h),
+ Samples(0)
{
OVR_UNUSED(fmt);
+
Sampler = Ren->GetSamplerState(0);
}
@@ -599,20 +623,58 @@ void ShaderFill::Set(PrimitiveType prim) const
//-------------------------------------------------------------------------------------
// ***** Render Device
-RenderDevice::RenderDevice(const RendererParams& p, HWND window)
-{
+RenderDevice::RenderDevice(const RendererParams& p, HWND window) :
+ WindowWidth(0),
+ WindowHeight(0),
+ Params(),
+ Proj(),
+ pTextVertexBuffer(),
+ LightingBuffer(),
+ DXGIFactory(),
+ Window(window),
+ Device(),
+ Context(),
+ SwapChain(),
+ Adapter(),
+ FullscreenOutput(),
+ FSDesktopX(-1),
+ FSDesktopY(-1),
+ BackBuffer(),
+ BackBufferRT(),
+ CurRenderTarget(),
+ CurDepthBuffer(),
+ Rasterizer(),
+ BlendState(),
+ //D3DViewport()
+ //DepthStates();
+ CurDepthState(),
+ ModelVertexIL(),
+ //SamplerStates(),
+ StdUniforms(),
+ //UniformBuffers(),
+ //MaxTextureSet(),
+ //VertexShaders(),
+ //PixelShaders(),
+ //CommonUniforms(),
+ DefaultFill(),
+ QuadVertexBuffer(),
+ DepthBuffers()
+{
+ memset(&D3DViewport, 0, sizeof(D3DViewport));
+ memset(MaxTextureSet, 0, sizeof(MaxTextureSet));
+
RECT rc;
if (p.Resolution == Sizei(0))
{
GetClientRect(window, &rc);
- WindowWidth = rc.right - rc.left;
- WindowHeight= rc.bottom - rc.top;
+ WindowWidth = rc.right - rc.left;
+ WindowHeight = rc.bottom - rc.top;
}
else
{
// TBD: Rename from WindowHeight or use Resolution from params for surface
- WindowWidth = p.Resolution.w;
- WindowHeight= p.Resolution.h;
+ WindowWidth = p.Resolution.w;
+ WindowHeight = p.Resolution.h;
}
Window = window;
@@ -620,13 +682,13 @@ RenderDevice::RenderDevice(const RendererParams& p, HWND window)
DXGIFactory = NULL;
HRESULT hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)(&DXGIFactory.GetRawRef()));
- if (FAILED(hr))
+ if (FAILED(hr))
return;
// Find the adapter & output (monitor) to use for fullscreen, based on the reported name of the HMD's monitor.
if (Params.MonitorName.GetLength() > 0)
{
- for(UINT AdapterIndex = 0; ; AdapterIndex++)
+ for (UINT AdapterIndex = 0; ; AdapterIndex++)
{
Adapter = NULL;
HRESULT hr = DXGIFactory->EnumAdapters(AdapterIndex, &Adapter.GetRawRef());
@@ -648,11 +710,16 @@ RenderDevice::RenderDevice(const RendererParams& p, HWND window)
if (!Adapter)
{
- DXGIFactory->EnumAdapters(0, &Adapter.GetRawRef());
+ hr = DXGIFactory->EnumAdapters(0, &Adapter.GetRawRef());
+ if (FAILED(hr) || !Adapter)
+ {
+ OVR_DEBUG_LOG(("WARNING: No graphics adapter."));
+ OVR_ASSERT(false);
+ }
}
int flags = 0;
- //int flags = D3D11_CREATE_DEVICE_DEBUG;
+ //int flags = D3D11_CREATE_DEVICE_DEBUG;
Device = NULL;
Context = NULL;
@@ -933,6 +1000,7 @@ bool RenderDevice::RecreateSwapChain()
{
Context->OMSetRenderTargets(1, &BackBufferRT.GetRawRef(), depthBuffer->TexDsv);
}
+
return true;
}
diff --git a/Samples/OculusRoomTiny/RenderTiny_D3D11_Device.h b/Samples/OculusRoomTiny/RenderTiny_D3D11_Device.h
index e6e4a2e..a5404ad 100644
--- a/Samples/OculusRoomTiny/RenderTiny_D3D11_Device.h
+++ b/Samples/OculusRoomTiny/RenderTiny_D3D11_Device.h
@@ -5,7 +5,7 @@ Content : RenderDevice implementation header for D3DX10.
Created : September 10, 2012
Authors : Andrew Reisse
-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.
@@ -125,12 +125,12 @@ class ShaderBase : public RefCountBase<ShaderBase>
friend class ShaderSet;
protected:
- ShaderStage Stage;
+ ShaderStage Stage;
public:
- RenderDevice* Ren;
- unsigned char* UniformData;
- int UniformsSize;
+ RenderDevice* Ren;
+ unsigned char* UniformData;
+ int UniformsSize;
enum VarType
{
@@ -141,14 +141,15 @@ public:
struct Uniform
{
- String Name;
+ String Name;
VarType Type;
- int Offset, Size;
+ int Offset;
+ int Size;
};
Array<Uniform> UniformInfo;
ShaderBase(RenderDevice* r, ShaderStage stage);
- ShaderBase(ShaderStage s) : Stage(s) {}
+ ShaderBase(ShaderStage s);
~ShaderBase();
@@ -165,11 +166,12 @@ public:
void UpdateBuffer(Buffer* b);
};
+
template<ShaderStage SStage, class D3DShaderType>
class Shader : public ShaderBase
{
public:
- D3DShaderType* D3DShader;
+ D3DShaderType* D3DShader;
Shader(RenderDevice* r, D3DShaderType* s) : ShaderBase(r, SStage), D3DShader(s) {}
Shader(RenderDevice* r, ID3D10Blob* s) : ShaderBase(r, SStage)
@@ -301,6 +303,7 @@ public:
void SetInputLayout(void* newIL) { InputLayout = (void*)newIL; }
};
+
// Buffer for vertex or index data. Some renderers require separate buffers, so that
// is recommended. Some renderers cannot have high-performance buffers which are readable,
// so reading in Map should not be relied on.
@@ -323,7 +326,13 @@ public:
bool Dynamic;
public:
- Buffer(RenderDevice* r) : Ren(r), Size(0), Use(0) {}
+ Buffer(RenderDevice* r) :
+ Ren(r),
+ Size(0),
+ Use(0),
+ Dynamic(false)
+ {
+ }
virtual ~Buffer() {}
ID3D11Buffer* GetBuffer()
@@ -336,11 +345,12 @@ public:
return Size;
}
virtual void* Map(size_t start, size_t size, int flags = 0);
- virtual bool Unmap(void *m);
+ virtual bool Unmap(void* m);
// Allocates a buffer, optionally filling it with data.
virtual bool Data(int use, const void* buffer, size_t size);
};
+
class Texture : public RefCountBase<Texture>
{
public:
@@ -524,7 +534,7 @@ public:
// Node implementation.
virtual NodeType GetType() const { return Node_Model; }
- virtual void Render(const Matrix4f& ltw, RenderDevice* ren);
+ virtual void Render(const Matrix4f& ltw, RenderDevice* ren);
// Returns the index next added vertex will have.
@@ -559,7 +569,7 @@ public:
class Container : public Node
{
public:
- Array<Ptr<Node> > Nodes;
+ Array< Ptr<Node> > Nodes;
Container() { }
~Container() { }
@@ -568,7 +578,7 @@ public:
virtual void Render(const Matrix4f& ltw, RenderDevice* ren);
- void Add(Node *n) { Nodes.PushBack(n); }
+ void Add(Node* n) { Nodes.PushBack(n); }
void Clear() { Nodes.Clear(); }
};
@@ -630,7 +640,13 @@ struct RendererParams
// MacOS
long DisplayId;
- RendererParams(int ms = 1) : Multisample(ms), Fullscreen(0), Resolution(0) {}
+ RendererParams(int ms = 1) :
+ Multisample(ms),
+ Fullscreen(0),
+ Resolution(0),
+ DisplayId(-1)
+ {
+ }
bool IsDisplaySet() const
{
@@ -638,10 +654,9 @@ struct RendererParams
}
};
+
class RenderDevice : public RefCountBase<RenderDevice>
{
-
-
protected:
int WindowWidth, WindowHeight;
RendererParams Params;
@@ -703,7 +718,6 @@ public:
Array<Ptr<Texture> > DepthBuffers;
public:
-
// Slave parameters are used to create a renderer that uses an externally
// specified device.
struct SlaveRendererParams
@@ -727,7 +741,6 @@ public:
// Creates a "slave" renderer existing device.
static RenderDevice* CreateSlaveDevice(const SlaveRendererParams& srp);
-
// Constructor helper
void initShadersAndStates();
@@ -735,8 +748,7 @@ public:
D3D11_INPUT_ELEMENT_DESC * DistortionMeshVertexDesc, int num_elements);
-
- void UpdateMonitorOutputs();
+ void UpdateMonitorOutputs();
void SetViewport(int x, int y, int w, int h) { SetViewport(Recti(x,y,w,h)); }
// Set viewport ignoring any adjustments used for the stereo mode.
@@ -757,11 +769,11 @@ public:
virtual void Clear(float r = 0, float g = 0, float b = 0, float a = 1, float depth = 1);
// Resources
- virtual Buffer* CreateBuffer();
- virtual Texture* CreateTexture(int format, int width, int height, const void* data, int mipcount=1);
+ virtual Buffer* CreateBuffer();
+ virtual Texture* CreateTexture(int format, int width, int height, const void* data, int mipcount=1);
// Placeholder texture to come in externally
- virtual Texture* CreatePlaceholderTexture(int format);
+ virtual Texture* CreatePlaceholderTexture(int format);
virtual ShaderSet* CreateShaderSet() { return new ShaderSet; }
@@ -796,10 +808,10 @@ public:
virtual void Render(const ShaderFill* fill, Buffer* vertices, Buffer* indices,int stride,
const Matrix4f& matrix, int offset, int count, PrimitiveType prim = Prim_Triangles, bool updateUniformData = true);
- virtual ShaderFill *CreateSimpleFill() { return DefaultFill; }
- ShaderFill * CreateTextureFill(Texture* tex);
+ virtual ShaderFill* CreateSimpleFill() { return DefaultFill; }
+ ShaderFill* CreateTextureFill(Texture* tex);
- virtual ShaderBase *LoadBuiltinShader(ShaderStage stage, int shader);
+ virtual ShaderBase* LoadBuiltinShader(ShaderStage stage, int shader);
bool RecreateSwapChain();
virtual ID3D10Blob* CompileShader(const char* profile, const char* src, const char* mainName = "main");
@@ -811,16 +823,16 @@ public:
int GetNumMipLevels(int w, int h);
-// Filter an rgba image with a 2x2 box filter, for mipmaps.
+// Filter an RGBA image with a 2x2 box filter, for mipmaps.
// Image size must be a power of 2.
void FilterRgba2x2(const uint8_t* src, int w, int h, uint8_t* dest);
-}}
+
+}} // namespace OVR::RenderTiny
//Anything including this file, uses these
using namespace OVR;
using namespace OVR::RenderTiny;
-
#endif
diff --git a/Samples/OculusRoomTiny/Win32_OculusRoomTiny.cpp b/Samples/OculusRoomTiny/Win32_OculusRoomTiny.cpp
index 74a46e5..0bc50ed 100644
--- a/Samples/OculusRoomTiny/Win32_OculusRoomTiny.cpp
+++ b/Samples/OculusRoomTiny/Win32_OculusRoomTiny.cpp
@@ -33,7 +33,7 @@ limitations under the License.
// Choose whether the SDK performs rendering/distortion, or the application.
#define SDK_RENDER 1 //Do NOT switch until you have viewed and understood the Health and Safety message.
//Disabling this makes it a non-compliant app, and not suitable for demonstration. In place for development only.
-const bool FullScreen = true; //Should be true for correct timing. Use false for debug only.
+const bool FullScreen = true; // Set to false for direct mode (recommended), true for extended mode operation.
// Include Non-SDK supporting Utilities from other files
@@ -44,7 +44,7 @@ bool Util_RespondToControls (float & EyeYaw, Vector3f & EyePos, Quatf Pos
void PopulateRoomScene (Scene* scene, RenderDevice* render);
//Structures for the application
-ovrHmd HMD;
+ovrHmd HMD = 0;
ovrEyeRenderDesc EyeRenderDesc[2];
ovrRecti EyeRenderViewport[2];
RenderDevice* pRender = 0;
@@ -69,14 +69,17 @@ int Init()
{
// Initializes LibOVR, and the Rift
ovr_Initialize();
- HMD = ovrHmd_Create(0);
if (!HMD)
{
- MessageBoxA(NULL,"Oculus Rift not detected.","", MB_OK);
- return(1);
+ HMD = ovrHmd_Create(0);
+ if (!HMD)
+ {
+ MessageBoxA(NULL, "Oculus Rift not detected.", "", MB_OK);
+ return(1);
+ }
+ if (HMD->ProductName[0] == '\0')
+ MessageBoxA(NULL, "Rift detected, display not enabled.", "", MB_OK);
}
- if (HMD->ProductName[0] == '\0')
- MessageBoxA(NULL,"Rift detected, display not enabled.","", MB_OK);
//Setup Window and Graphics - use window frame if relying on Oculus driver
const int backBufferMultisample = 1;
@@ -244,10 +247,15 @@ void ProcessAndRender()
// Adjust eye position and rotation from controls, maintaining y position from HMD.
static float BodyYaw(3.141592f);
static Vector3f HeadPos(0.0f, 1.6f, -5.0f);
+ static ovrTrackingState HmdState;
+
+ ovrVector3f hmdToEyeViewOffset[2] = { EyeRenderDesc[0].HmdToEyeViewOffset, EyeRenderDesc[1].HmdToEyeViewOffset };
+ ovrHmd_GetEyePoses(HMD, 0, hmdToEyeViewOffset, eyeRenderPose, &HmdState);
+
HeadPos.y = ovrHmd_GetFloat(HMD, OVR_KEY_EYE_HEIGHT, HeadPos.y);
- bool freezeEyeRender = Util_RespondToControls(BodyYaw, HeadPos, eyeRenderPose[1].Orientation);
+ bool freezeEyeRender = Util_RespondToControls(BodyYaw, HeadPos, HmdState.HeadPose.ThePose.Orientation);
- pRender->BeginScene();
+ pRender->BeginScene();
// Render the two undistorted eye views into their render buffers.
if (!freezeEyeRender) // freeze to debug for time warp
@@ -259,21 +267,20 @@ void ProcessAndRender()
for (int eyeIndex = 0; eyeIndex < ovrEye_Count; eyeIndex++)
{
ovrEyeType eye = HMD->EyeRenderOrder[eyeIndex];
- eyeRenderPose[eye] = ovrHmd_GetEyePose(HMD, eye);
// Get view and projection matrices
- Matrix4f rollPitchYaw = Matrix4f::RotationY(BodyYaw);
- Matrix4f finalRollPitchYaw = rollPitchYaw * Matrix4f(eyeRenderPose[eye].Orientation);
- Vector3f finalUp = finalRollPitchYaw.Transform(Vector3f(0,1,0));
- Vector3f finalForward = finalRollPitchYaw.Transform(Vector3f(0,0,-1));
- Vector3f shiftedEyePos = HeadPos + rollPitchYaw.Transform(eyeRenderPose[eye].Position);
+ Matrix4f rollPitchYaw = Matrix4f::RotationY(BodyYaw);
+ Matrix4f finalRollPitchYaw = rollPitchYaw * Matrix4f(eyeRenderPose[eye].Orientation);
+ Vector3f finalUp = finalRollPitchYaw.Transform(Vector3f(0,1,0));
+ Vector3f finalForward = finalRollPitchYaw.Transform(Vector3f(0,0,-1));
+ Vector3f shiftedEyePos = HeadPos + rollPitchYaw.Transform(eyeRenderPose[eye].Position);
Matrix4f view = Matrix4f::LookAtRH(shiftedEyePos, shiftedEyePos + finalForward, finalUp);
Matrix4f proj = ovrMatrix4f_Projection(EyeRenderDesc[eye].Fov, 0.01f, 10000.0f, true);
pRender->SetViewport(Recti(EyeRenderViewport[eye]));
pRender->SetProjection(proj);
pRender->SetDepthMode(true, true);
- pRoomScene->Render(pRender, Matrix4f::Translation(EyeRenderDesc[eye].ViewAdjust) * view);
+ pRoomScene->Render(pRender, view);
}
}
pRender->FinishScene();
@@ -365,6 +372,7 @@ void Release(void)
#endif
ovrHmd_Destroy(HMD);
+ HMD = 0;
Util_ReleaseWindowAndGraphics(pRender);
if (pRoomScene) delete pRoomScene;
diff --git a/Samples/OculusRoomTiny/Win32_OculusRoomTiny_Util.cpp b/Samples/OculusRoomTiny/Win32_OculusRoomTiny_Util.cpp
index f371ce1..2810a5a 100644
--- a/Samples/OculusRoomTiny/Win32_OculusRoomTiny_Util.cpp
+++ b/Samples/OculusRoomTiny/Win32_OculusRoomTiny_Util.cpp
@@ -134,7 +134,7 @@ bool Util_RespondToControls(float & EyeYaw, Vector3f & EyePos, Quatf PoseOrienta
if (localMoveVector.y > 1) localMoveVector.y = 1;
//rotate according to gamepad input
- const float gamepad_sensitivity = .025;
+ const float gamepad_sensitivity = .025f;
GamepadYaw = -gamepad_sensitivity * LastGamepadState.RX;
EyeYaw += GamepadYaw;
@@ -186,7 +186,7 @@ LRESULT CALLBACK systemWindowProc(HWND arg_hwnd, UINT msg, WPARAM wp, LPARAM lp)
case WM_KEYDOWN: OnKey((unsigned)wp, true); break;
case WM_KEYUP: OnKey((unsigned)wp, false); break;
case WM_CREATE: SetTimer(hWnd, 0, 100, NULL); break;
- case WM_TIMER: KillTimer(hWnd, 0);
+ case WM_TIMER: KillTimer(hWnd, 0); break;
case WM_SETFOCUS:
SetCursorPos(WindowCenter.x, WindowCenter.y);
@@ -207,18 +207,20 @@ LRESULT CALLBACK systemWindowProc(HWND arg_hwnd, UINT msg, WPARAM wp, LPARAM lp)
}
+static LPCWSTR WindowClassName = L"OVRAppWindow";
+
HWND Util_InitWindowAndGraphics(Recti vp, int fullscreen, int multiSampleCount, bool UseAppWindowFrame, RenderDevice ** returnedDevice)
{
RendererParams renderParams;
// Window
- WNDCLASS wc;
+ WNDCLASSW wc;
memset(&wc, 0, sizeof(wc));
- wc.lpszClassName = L"OVRAppWindow";
+ wc.lpszClassName = WindowClassName;
wc.style = CS_OWNDC;
wc.lpfnWndProc = systemWindowProc;
wc.cbWndExtra = NULL;
- RegisterClass(&wc);
+ RegisterClassW(&wc);
DWORD wsStyle = WS_POPUP;
DWORD sizeDivisor = 1;
@@ -234,7 +236,7 @@ HWND Util_InitWindowAndGraphics(Recti vp, int fullscreen, int multiSampleCount,
RECT winSize = { 0, 0, vp.w / sizeDivisor, vp.h / sizeDivisor};
AdjustWindowRect(&winSize, wsStyle, false);
- hWnd = CreateWindowA("OVRAppWindow", "OculusRoomTiny",
+ hWnd = CreateWindowW(WindowClassName, L"OculusRoomTiny",
wsStyle |WS_VISIBLE,
vp.x, vp.y,
winSize.right-winSize.left, winSize.bottom-winSize.top,
@@ -265,7 +267,7 @@ void Util_ReleaseWindowAndGraphics(RenderDevice * prender)
{
// Release window resources.
::DestroyWindow(hWnd);
- UnregisterClass(L"OVRAppWindow", hInstance);
+ UnregisterClassW(WindowClassName, hInstance);
}
}