diff --git a/OSVRUnreal/Plugins/OSVR/OSVR.uplugin b/OSVRUnreal/Plugins/OSVR/OSVR.uplugin index 4082511..2deca9f 100644 --- a/OSVRUnreal/Plugins/OSVR/OSVR.uplugin +++ b/OSVRUnreal/Plugins/OSVR/OSVR.uplugin @@ -17,13 +17,13 @@ "Name": "OSVR", "Type": "Runtime", "LoadingPhase": "PreDefault", - "WhitelistPlatforms": [ "Win32", "Win64" ] + "WhitelistPlatforms": [ "Win32", "Win64", "Linux"] }, { "Name": "OSVRInput", "Type": "Runtime", "LoadingPhase": "PreDefault", - "WhitelistPlatforms": [ "Win32", "Win64" ] + "WhitelistPlatforms": [ "Win32", "Win64", "Linux" ] } ] } diff --git a/OSVRUnreal/Plugins/OSVR/Source/OSVR/OSVR.Build.cs b/OSVRUnreal/Plugins/OSVR/Source/OSVR/OSVR.Build.cs index e685def..a2d5f44 100644 --- a/OSVRUnreal/Plugins/OSVR/Source/OSVR/OSVR.Build.cs +++ b/OSVRUnreal/Plugins/OSVR/Source/OSVR/OSVR.Build.cs @@ -8,38 +8,39 @@ public OSVR(TargetInfo Target) PrivateIncludePathModuleNames.Add("TargetPlatform"); var EngineDir = Path.GetFullPath(BuildConfiguration.RelativeEnginePath); - var openglDrvPrivatePath = Path.Combine(EngineDir, @"Source\Runtime\OpenGLDrv\Private"); - var openglPath = Path.Combine(EngineDir, @"Source\ThirdParty\OpenGL"); + var openglDrvPrivatePath = Path.Combine(EngineDir, @"Source/Runtime/OpenGLDrv/Private"); + var openglPath = Path.Combine(EngineDir, @"Source/ThirdParty/OpenGL"); PrivateIncludePaths.AddRange( new string[] { - "OSVR/Private", + "OSVR/Private", openglDrvPrivatePath, - openglPath - // ... add other private include paths required here ... - } - ); + openglPath, + // ... add other private include paths required here ... + "/media/u/build/OSVR/install/include/" + }); PrivateDependencyModuleNames.AddRange( new string[] - { - "OSVRClientKit", - "Core", - "CoreUObject", // Provides Actors and Structs - "Engine", // Used by Actor - "Slate", // Used by InputDevice to fire bespoke FKey events - "InputCore", // Provides LOCTEXT and other Input features - "InputDevice", // Provides IInputInterface - "RHI", - "RenderCore", - "Renderer", - "ShaderCore", - "HeadMountedDisplay", - "Json", - "OpenGLDrv" - // ... add private dependencies that you statically link with here ... - } - ); + { + "OSVRClientKit", + "Core", + "CoreUObject", // Provides Actors and Structs + "Engine", // Used by Actor + "Slate", // Used by InputDevice to fire bespoke FKey events + "InputCore", // Provides LOCTEXT and other Input features + "InputDevice", // Provides IInputInterface + "RHI", + "RenderCore", + "Renderer", + "ShaderCore", + "HeadMountedDisplay", + "Json", + "OpenGLDrv", + "SDL2" + // ... add private dependencies that you statically link with here ... + }); + if(UEBuildConfiguration.bBuildEditor == true) { PrivateDependencyModuleNames.Add("UnrealEd"); @@ -55,9 +56,14 @@ public OSVR(TargetInfo Target) PrivateIncludePaths.AddRange( new string[] { - Path.Combine(EngineDir, @"Source\Runtime\Windows\D3D11RHI\Private"), - Path.Combine(EngineDir, @"Source\Runtime\Windows\D3D11RHI\Private\Windows") - }); + Path.Combine(EngineDir, @"Source\Runtime\Windows\D3D11RHI\Private"), + Path.Combine(EngineDir, @"Source\Runtime\Windows\D3D11RHI\Private\Windows") + }); + } + + if (Target.Platform == UnrealTargetPlatform.Linux) + { + Definitions.Add("OSVR_UNREAL_OPENGL_ENABLED=1"); } } } diff --git a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVR.cpp b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVR.cpp index 9dc6fde..7b723e3 100644 --- a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVR.cpp +++ b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVR.cpp @@ -67,8 +67,10 @@ void FOSVR::LoadOSVRClientKitModule() FScopeLock lock(&mModuleMutex); if (!bModulesLoaded) { -#if PLATFORM_WINDOWS TArray osvrDlls; + TArray pathsToTry; + +#if PLATFORM_WINDOWS osvrDlls.Add(FString("osvrClientKit.dll")); osvrDlls.Add(FString("osvrClient.dll")); osvrDlls.Add(FString("osvrCommon.dll")); @@ -78,21 +80,32 @@ void FOSVR::LoadOSVRClientKitModule() osvrDlls.Add(FString("glew32.dll")); osvrDlls.Add(FString("SDL2.dll")); -#if PLATFORM_64BITS - TArray pathsToTry; +#if PLATFORM_64BITS pathsToTry.Add(FPaths::GamePluginsDir() / "OSVR/Source/OSVRClientKit/bin/Win64/"); pathsToTry.Add(FPaths::EngineDir() / "Plugins/Runtime/OSVR/Source/OSVRClientKit/bin/Win64/"); pathsToTry.Add(FPaths::EngineDir() / "Binaries/ThirdParty/OSVRClientKit/bin/Win64/"); pathsToTry.Add(FPaths::EngineDir() / "Source/ThirdParty/OSVRClientKit/bin/Win64/"); #else - TArray pathsToTry; pathsToTry.Add(FPaths::GamePluginsDir() / "OSVR/Source/OSVRClientKit/bin/Win32/"); pathsToTry.Add(FPaths::EngineDir() / "Plugins/Runtime/OSVR/Source/OSVRClientKit/bin/Win32/"); pathsToTry.Add(FPaths::EngineDir() / "Binaries/ThirdParty/OSVRClientKit/bin/Win32/"); pathsToTry.Add(FPaths::EngineDir() / "Source/ThirdParty/OSVRClientKit/bin/Win32/"); #endif +#elif PLATFORM_LINUX + osvrDlls.Add(FString("libosvrClientKit.so")); + osvrDlls.Add(FString("libosvrClient.so")); + osvrDlls.Add(FString("libosvrCommon.so")); + osvrDlls.Add(FString("libosvrUtil.so")); + osvrDlls.Add(FString("libosvrRenderManager.so")); + osvrDlls.Add(FString("libjsoncpp.so")); + osvrDlls.Add(FString("libGLEW.so")); + osvrDlls.Add(FString("libSDL2-2.0.so")); + + pathsToTry.Add(FPaths::GamePluginsDir() / "OSVR/Source/OSVRClientKit/bin/Linux/"); + pathsToTry.Add(FPaths::EngineDir() / "Plugins/Runtime/OSVR/Source/OSVRClientKit/bin/Linux/"); +#endif FString osvrClientKitLibPath; for (auto& it : pathsToTry) { @@ -117,10 +130,12 @@ void FOSVR::LoadOSVRClientKitModule() if (!libHandle) { UE_LOG(OSVRLog, Warning, TEXT("FAILED to load %s"), *path); + } else { + UE_LOG(OSVRLog, Warning, TEXT("Loaded %s"), *path); } } FPlatformProcess::PopDllDirectory(*osvrClientKitLibPath); -#endif + bModulesLoaded = true; } } diff --git a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRCustomPresent.h b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRCustomPresent.h index db813b1..3f2dc87 100644 --- a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRCustomPresent.h +++ b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRCustomPresent.h @@ -236,7 +236,8 @@ class FOSVRCustomPresent : public FRHICustomPresent OSVR_ReturnCode rc; OSVR_RenderInfoCount numRenderInfo; - OSVR_Pose3 ret = { 0 }; + OSVR_Pose3 ret; + rc = osvrRenderManagerGetNumRenderInfoInCollection(renderInfoCollection, &numRenderInfo); if (rc != OSVR_RETURN_SUCCESS) { diff --git a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRCustomPresentOpenGL.h b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRCustomPresentOpenGL.h index 5f77137..b085dc4 100644 --- a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRCustomPresentOpenGL.h +++ b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRCustomPresentOpenGL.h @@ -20,7 +20,7 @@ #include "IOSVR.h" #include "OSVRCustomPresent.h" #include -#include +#include #if OSVR_ANDROID // @todo this may not work - if not, what headers is unreal expecting? @@ -38,7 +38,7 @@ #include "OpenGLDrvPrivate.h" #include "OpenGLResources.h" -typedef struct FUnrealBackBufferContainer +struct FUnrealBackBufferContainer { GLint displayFrameBuffer; int width; @@ -105,7 +105,7 @@ class FUnrealOSVRRenderManagerOpenGLToolkit { return ConvertBool(((FUnrealOSVRRenderManagerOpenGLToolkit*)data)->handleEvents()); } - static OSVR_CBool getDisplayFrameBufferImpl(void* data, size_t display, GLint* displayFrameBufferOut) + static OSVR_CBool getDisplayFrameBufferImpl(void* data, size_t display, GLuint* displayFrameBufferOut) { return ConvertBool(((FUnrealOSVRRenderManagerOpenGLToolkit*)data)->getDisplayFrameBuffer(display, displayFrameBufferOut)); } @@ -185,7 +185,7 @@ class FUnrealOSVRRenderManagerOpenGLToolkit { return true; } - bool getDisplayFrameBuffer(size_t display, GLint* displayFrameBufferOut) + bool getDisplayFrameBuffer(size_t display, GLuint* displayFrameBufferOut) { (*displayFrameBufferOut) = mBackBufferContainer->displayFrameBuffer; return true; @@ -286,7 +286,7 @@ class FOpenGLCustomPresent : public FOSVRCustomPresent mRenderInfos.Empty(); for (size_t i = 0; i < numRenderInfo; i++) { - OSVR_RenderInfoOpenGL renderInfo = { 0 }; + OSVR_RenderInfoOpenGL renderInfo; rc = osvrRenderManagerGetRenderInfoFromCollectionOpenGL(renderInfoCollection, i, &renderInfo); check(rc == OSVR_RETURN_SUCCESS); @@ -383,8 +383,8 @@ class FOpenGLCustomPresent : public FOSVRCustomPresent check(renderInfoCollection); OSVR_ReturnCode rc; - OSVR_Pose3 ret = { 0 }; - OSVR_RenderInfoOpenGL renderInfo = { 0 }; + OSVR_Pose3 ret; + OSVR_RenderInfoOpenGL renderInfo; rc = osvrRenderManagerGetRenderInfoFromCollectionOpenGL(renderInfoCollection, index, &renderInfo); if (rc != OSVR_RETURN_SUCCESS) diff --git a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVREntryPoint.cpp b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVREntryPoint.cpp index 9184263..6fd97f1 100644 --- a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVREntryPoint.cpp +++ b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVREntryPoint.cpp @@ -103,3 +103,8 @@ OSVRInterfaceCollection* OSVREntryPoint::GetInterfaceCollection() return InterfaceCollection.Get(); } #endif + +// hack to add a dummy implementation of this missing function for Linux until OSVR gets patched +#if LINUX +void osvrClientAttemptServerAutoStart() {} +#endif diff --git a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVREntryPoint.h b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVREntryPoint.h index 6c5a2e9..cf80fe6 100644 --- a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVREntryPoint.h +++ b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVREntryPoint.h @@ -22,7 +22,7 @@ DECLARE_LOG_CATEGORY_EXTERN(OSVREntryPointLog, Log, All); -OSVR_API class OSVREntryPoint : public FTickableGameObject +class OSVR_API OSVREntryPoint : public FTickableGameObject { public: diff --git a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRHMD.cpp b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRHMD.cpp index 87c0944..da24132 100644 --- a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRHMD.cpp +++ b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRHMD.cpp @@ -94,7 +94,6 @@ void FOSVRHMD::StartCustomPresent() #if PLATFORM_WINDOWS else { - // currently, FCustomPresent creates its own client context, so no need to // synchronize with the one from FOSVREntryPoint. mCustomPresent = new FDirect3D11CustomPresent(nullptr/*mOSVREntryPoint->GetClientContext()*/); @@ -215,6 +214,13 @@ void FOSVRHMD::UpdateHeadPose(bool renderThread, FQuat& lastHmdOrientation, FVec { //OSVR_ReturnCode returnCode; FScopeLock lock(mOSVREntryPoint->GetClientContextMutex()); + + if(!mCustomPresent) + { + UE_LOG(OSVRHMDLog, Warning, TEXT("Skipping head pose update because mCustomPresent is not initialized yet!")); + return; + } + OSVR_Pose3 pose = mCustomPresent->GetHeadPoseFromCachedRenderInfoCollection(renderThread, true); // RenderManager gives us the eye-from-space pose, and we need the inverse of that diff --git a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRPrivatePCH.h b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRPrivatePCH.h index 1b7bd99..db6397e 100644 --- a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRPrivatePCH.h +++ b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRPrivatePCH.h @@ -37,7 +37,10 @@ // in the background and no way to switch apps). #define OSVR_UNREAL_DEBUG_FORCED_WINDOWMODE 0 +// If not explicitly enabled (e.g. for Linux), keep OpenGL support off +#ifndef OSVR_UNREAL_OPENGL_ENABLED #define OSVR_UNREAL_OPENGL_ENABLED 0 +#endif //// Set to 1 to enable OpenGL RenderManager support on Windows, which is currently //// in beta form. There are known issues: diff --git a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRRender.cpp b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRRender.cpp index f0ad259..f06de9a 100644 --- a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRRender.cpp +++ b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRRender.cpp @@ -147,6 +147,8 @@ void FOSVRHMD::CalculateRenderTargetSize(const FViewport& Viewport, uint32& InOu if (!mCustomPresent->IsInitialized() && IsInRenderingThread() && !mCustomPresent->Initialize()) { mCustomPresent = nullptr; + UE_LOG(OSVRHMDLog, Error, TEXT("Failed to initialise CustomPresent!")); + return; } // this only happens once, the first time this is called. I don't know why. diff --git a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Public/IOSVR.h b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Public/IOSVR.h index df8abd7..e34574a 100644 --- a/OSVRUnreal/Plugins/OSVR/Source/OSVR/Public/IOSVR.h +++ b/OSVRUnreal/Plugins/OSVR/Source/OSVR/Public/IOSVR.h @@ -29,7 +29,7 @@ class FOSVRHMD; * The public interface to this module. In most cases, this interface is only public to sibling modules * within this plugin. */ -OSVR_API class IOSVR : public IHeadMountedDisplayModule +class OSVR_API IOSVR : public IHeadMountedDisplayModule { public: /** Returns the key into the HMDPluginPriority section of the config file for this module */ diff --git a/OSVRUnreal/Plugins/OSVR/Source/OSVRClientKit/OSVRClientKit.Build.cs b/OSVRUnreal/Plugins/OSVR/Source/OSVRClientKit/OSVRClientKit.Build.cs index bf3ed2b..02de63d 100644 --- a/OSVRUnreal/Plugins/OSVR/Source/OSVRClientKit/OSVRClientKit.Build.cs +++ b/OSVRUnreal/Plugins/OSVR/Source/OSVRClientKit/OSVRClientKit.Build.cs @@ -64,5 +64,40 @@ public OSVRClientKit(TargetInfo Target) //System.Console.WriteLine("xmlPath: {0}", xmlPath); AdditionalPropertiesForReceipt.Add(new ReceiptProperty("AndroidPlugin", xmlPath)); } + else if(Target.Platform == UnrealTargetPlatform.Linux) + { + string PlatformAbbrev = "Linux"; + + PublicLibraryPaths.Add(String.Format("{0}/bin/{1}", ModuleDirectory, PlatformAbbrev)); + PublicAdditionalLibraries.Add("osvrClientKit"); + PublicAdditionalLibraries.Add("osvrRenderManager"); + + var osvrDlls = new string[] { + "libosvrClientKit.so", + "libosvrClient.so", + "libosvrCommon.so", + "libosvrUtil.so", + "libosvrRenderManager.so", + "libjsoncpp.so", + "libGLEW.so", + "libSDL2-2.0.so" + }; + + PublicDelayLoadDLLs.AddRange(osvrDlls); + + string baseBinaryDirectory = ModuleDirectory + "/bin"; + if (!System.IO.Directory.Exists(baseBinaryDirectory)) + { + baseBinaryDirectory = "$(EngineDir)/Binaries/ThirdParty/OSVRClientKit/bin"; + } + + string DllFormat = "{0}/{1}/{2}"; + foreach (var dll in osvrDlls) + { + var src = String.Format(DllFormat, baseBinaryDirectory, PlatformAbbrev, dll); + RuntimeDependencies.Add(new RuntimeDependency(src)); + } + + } } } diff --git a/OSVRUnreal/Plugins/OSVR/Source/OSVRInput/OSVRInput.Build.cs b/OSVRUnreal/Plugins/OSVR/Source/OSVRInput/OSVRInput.Build.cs index 5248c72..b5853a7 100644 --- a/OSVRUnreal/Plugins/OSVR/Source/OSVRInput/OSVRInput.Build.cs +++ b/OSVRUnreal/Plugins/OSVR/Source/OSVRInput/OSVRInput.Build.cs @@ -10,35 +10,33 @@ public OSVRInput(TargetInfo Target) var openglPath = Path.Combine(EngineDir, @"Source\ThirdParty\OpenGL"); PrivateIncludePaths.AddRange( new string[] { - "OSVR/Private", + "OSVR/Private", openglDrvPrivatePath, - openglPath - // ... add other private include paths required here ... - } - ); - - + openglPath, + // ... add other private include paths required here ... + "/media/u/build/OSVR/install/include/" + }); PrivateDependencyModuleNames.AddRange( new string[] - { - "OSVRClientKit", - "OSVR", - "Core", - "CoreUObject", // Provides Actors and Structs - "Engine", // Used by Actor - "Slate", // Used by InputDevice to fire bespoke FKey events - "InputCore", // Provides LOCTEXT and other Input features - "InputDevice", // Provides IInputInterface - "RHI", - "RenderCore", - "Renderer", - "ShaderCore", - "HeadMountedDisplay", - "Json", - "OpenGLDrv" - // ... add private dependencies that you statically link with here ... - } + { + "OSVRClientKit", + "OSVR", + "Core", + "CoreUObject", // Provides Actors and Structs + "Engine", // Used by Actor + "Slate", // Used by InputDevice to fire bespoke FKey events + "InputCore", // Provides LOCTEXT and other Input features + "InputDevice", // Provides IInputInterface + "RHI", + "RenderCore", + "Renderer", + "ShaderCore", + "HeadMountedDisplay", + "Json", + "OpenGLDrv" + // ... add private dependencies that you statically link with here ... + } ); AddEngineThirdPartyPrivateStaticDependencies(Target, "OpenGL"); @@ -56,9 +54,9 @@ public OSVRInput(TargetInfo Target) // Required for some private headers needed for the rendering support. PrivateIncludePaths.AddRange( new string[] { - Path.Combine(EngineDir, @"Source\Runtime\Windows\D3D11RHI\Private"), - Path.Combine(EngineDir, @"Source\Runtime\Windows\D3D11RHI\Private\Windows") - }); + Path.Combine(EngineDir, @"Source\Runtime\Windows\D3D11RHI\Private"), + Path.Combine(EngineDir, @"Source\Runtime\Windows\D3D11RHI\Private\Windows") + }); } } } diff --git a/OSVRUnreal/Plugins/OSVR/Source/OSVRInput/Private/OSVRInputDevice.cpp b/OSVRUnreal/Plugins/OSVR/Source/OSVRInput/Private/OSVRInputDevice.cpp index ea2d5f7..011793b 100644 --- a/OSVRUnreal/Plugins/OSVR/Source/OSVRInput/Private/OSVRInputDevice.cpp +++ b/OSVRUnreal/Plugins/OSVR/Source/OSVRInput/Private/OSVRInputDevice.cpp @@ -51,12 +51,12 @@ class OSVRButton public: OSVRButton() {} OSVRButton(OSVRButtonType _type, FName _key, const FString& _ifacePath) : - type(_type), key(_key), ifacePath(_ifacePath) + key(_key), ifacePath(_ifacePath), type(_type) { } OSVRButton(OSVRButtonType _type, OSVRThresholdType _thresholdType, float _threshold, FName _key, const FString& _ifacePath) : - type(_type), thresholdType(_thresholdType), threshold(_threshold), key(_key), ifacePath(_ifacePath) + threshold(_threshold), key(_key), ifacePath(_ifacePath), type(_type), thresholdType(_thresholdType) { }