Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux support #123

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions OSVRUnreal/Plugins/OSVR/OSVR.uplugin
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}
]
}
62 changes: 34 additions & 28 deletions OSVRUnreal/Plugins/OSVR/Source/OSVR/OSVR.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
}
}
}
25 changes: 20 additions & 5 deletions OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ void FOSVR::LoadOSVRClientKitModule()
FScopeLock lock(&mModuleMutex);
if (!bModulesLoaded)
{
#if PLATFORM_WINDOWS
TArray<FString> osvrDlls;
TArray<FString> pathsToTry;

#if PLATFORM_WINDOWS
osvrDlls.Add(FString("osvrClientKit.dll"));
osvrDlls.Add(FString("osvrClient.dll"));
osvrDlls.Add(FString("osvrCommon.dll"));
Expand All @@ -78,21 +80,32 @@ void FOSVR::LoadOSVRClientKitModule()
osvrDlls.Add(FString("glew32.dll"));
osvrDlls.Add(FString("SDL2.dll"));

#if PLATFORM_64BITS
TArray<FString> 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<FString> 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)
{
Expand All @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "IOSVR.h"
#include "OSVRCustomPresent.h"
#include <osvr/RenderKit/RenderManagerC.h>
#include <osvr/util/PlatformConfig.h>
#include <osvr/Util/PlatformConfig.h>

#if OSVR_ANDROID
// @todo this may not work - if not, what headers is unreal expecting?
Expand All @@ -38,7 +38,7 @@
#include "OpenGLDrvPrivate.h"
#include "OpenGLResources.h"

typedef struct FUnrealBackBufferContainer
struct FUnrealBackBufferContainer
{
GLint displayFrameBuffer;
int width;
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

DECLARE_LOG_CATEGORY_EXTERN(OSVREntryPointLog, Log, All);

OSVR_API class OSVREntryPoint : public FTickableGameObject
class OSVR_API OSVREntryPoint : public FTickableGameObject
{
public:

Expand Down
8 changes: 7 additions & 1 deletion OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRHMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()*/);
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRPrivatePCH.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion OSVRUnreal/Plugins/OSVR/Source/OSVR/Public/IOSVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

}
}
}
Loading