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

Opengl implementation #96

Open
wants to merge 11 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
84 changes: 44 additions & 40 deletions ImportFromSDK.cmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@echo off

set PRJ_ROOT=%~dp0
set XCOPY_ARGS=/f /y

set PLUGIN_ROOT=%~dp0OSVRUnreal\Plugins\OSVR
IF NOT EXIST "%PLUGIN_ROOT%" goto ERROR_WRONG_PROJ_DIR
Expand All @@ -11,68 +12,67 @@ IF NOT EXIST "%DEST_ROOT%" goto ERROR_WRONG_PROJ_DIR
IF %1.==. (
set /p osvr32bit=Type OSVR 32bit SDK root dir:
) ELSE (
set osvr32bit=%~1
set osvr32bit="%~1"
)
IF %2.==. (
set /p osvr64bit=Type OSVR 64bit SDK root dir:
) ELSE (
set osvr64bit=%~2
set osvr64bit="%~2"
)

IF %3.==. (
set /p rm64bit=Type DirectRender 64bit SDK root dir:
) ELSE (
set rm64bit=%~3
)

IF %4.==. (
set /p osvrAndroid=Type OSVR Android SDK root dir:
) ELSE (
set osvrAndroid=%~4
set osvrAndroid="%~3"
)

set rm32bit=%rm64bit%

rem Get rid of the old
RMDIR /S /Q "%DEST_ROOT%\include" > NUL
RMDIR /S /Q "%DEST_ROOT%\lib" > NUL
del "%DEST_ROOT%\*.txt" > NUL

call :copy_arch_indep %osvr32bit% %rm32bit% %DEST_ROOT%
call :copy_arch_indep %osvr32bit% %DEST_ROOT%

call :copy_arch %osvr32bit% %rm32bit% %PLUGIN_ROOT% %DEST_ROOT% 32
call :copy_arch %osvr64bit% %rm64bit% %PLUGIN_ROOT% %DEST_ROOT% 64
call :copy_arch %osvr32bit% %PLUGIN_ROOT% %DEST_ROOT% 32
call :copy_arch %osvr64bit% %PLUGIN_ROOT% %DEST_ROOT% 64
call :copy_android %osvrAndroid% %PLUGIN_ROOT% %DEST_ROOT%

echo,
echo Done
echo Note: The 32-bit target is not yet supported. Please use the 64-bit target only for now.

goto :eof


:copy_arch_indep
rem Architecture-independent files
echo,
echo Architecture-independent files
echo,
setlocal
set SRC=%1
set SRC_RM=%2
set DEST_ROOT=%3
xcopy %SRC%\include\osvr\ClientKit "%DEST_ROOT%\include\osvr\ClientKit" /S /I /y
xcopy %SRC%\include\osvr\Util "%DEST_ROOT%\include\osvr\Util" /S /I /y
xcopy %SRC%\include\osvr\Client "%DEST_ROOT%\include\osvr\Client" /S /I /y
xcopy %SRC%\include\osvr\Common "%DEST_ROOT%\include\osvr\Common" /S /I /y
xcopy %SRC_RM%\include\osvr\RenderKit "%DEST_ROOT%\include\osvr\RenderKit" /S /I /y
set DEST_ROOT=%2
xcopy %SRC%\include\osvr\ClientKit "%DEST_ROOT%\include\osvr\ClientKit" /S /I %XCOPY_ARGS%
xcopy %SRC%\include\osvr\Util "%DEST_ROOT%\include\osvr\Util" /S /I %XCOPY_ARGS%
xcopy %SRC%\include\osvr\Client "%DEST_ROOT%\include\osvr\Client" /S /I %XCOPY_ARGS%
xcopy %SRC%\include\osvr\Common "%DEST_ROOT%\include\osvr\Common" /S /I %XCOPY_ARGS%
xcopy %SRC%\include\osvr\RenderKit "%DEST_ROOT%\include\osvr\RenderKit" /S /I %XCOPY_ARGS%
endlocal
goto :eof

:copy_android
echo,
echo Android files
echo,

set SRC=%1
set PLUGIN_ROOT=%2
set DEST_ROOT=%3
set SRC_LIB=%SRC%\NDK\osvr\builds\armeabi-v7a\lib

for %%F in (%SRC_LIB%\libcrystax.so,%SRC_LIB%\libfunctionality.so,%SRC_LIB%\libgnustl_shared.so,%SRC_LIB%\libjsoncpp.so,%SRC_LIB%\libosvrAnalysisPluginKit.so,%SRC_LIB%\libosvrClient.so,%SRC_LIB%\libosvrClientKit.so,%SRC_LIB%\libosvrCommon.so,%SRC_LIB%\libosvrConnection.so,%SRC_LIB%\libosvrJointClientKit.so,%SRC_LIB%\libosvrPluginHost.so,%SRC_LIB%\libosvrServer.so,%SRC_LIB%\libosvrUtil.so,%SRC_LIB%\libosvrVRPNServer.so) do (
echo xcopy %%F "%DEST_ROOT%\bin\Android\armeabi-v7a\" /Y
xcopy %%F "%DEST_ROOT%\bin\Android\armeabi-v7a\" /Y
rem echo xcopy %%F "%DEST_ROOT%\bin\Android\armeabi-v7a\" %XCOPY_ARGS%
xcopy %%F "%DEST_ROOT%\bin\Android\armeabi-v7a\" %XCOPY_ARGS%
)

endlocal
Expand All @@ -82,26 +82,31 @@ goto :eof
rem Architecture-dependent files
setlocal
set SRC=%1
set SRC_RM=%2
set PLUGIN_ROOT=%3
set DEST_ROOT=%4
set BITS=%5
set PLUGIN_ROOT=%2
set DEST_ROOT=%3
set BITS=%4
echo,
echo Architecture-dependent files %BITS%
echo,

copy "%SRC%\osvr-ver.txt" "%DEST_ROOT%\Win%BITS%osvr-ver.txt" /y
echo.> "%DEST_ROOT%\Win%BITS%osvr-ver.txt"
rem echo xcopy %SRC%\bin\osvr-ver.txt "%DEST_ROOT%\Win%BITS%osvr-ver.txt" /i %XCOPY_ARGS%
xcopy %SRC%\bin\osvr-ver.txt "%DEST_ROOT%\Win%BITS%osvr-ver.txt" %XCOPY_ARGS%

rem One copy to the bin directory, for use in deployment.
call :copy_dll %SRC% %SRC_RM% %DEST_ROOT%\bin %BITS%
call :copy_dll %SRC% %DEST_ROOT%\bin %BITS%

rem One copy to the plugin Binaries directory, for editor support.
call :copy_dll %SRC% %SRC_RM% %PLUGIN_ROOT%\Binaries %BITS%
call :copy_dll %SRC% %PLUGIN_ROOT%\Binaries %BITS%

rem libs
for %%F in (%SRC%\lib\osvrClientKit.lib) do (
xcopy %%F "%DEST_ROOT%\lib\Win%BITS%\" /Y
xcopy %%F "%DEST_ROOT%\lib\Win%BITS%\" %XCOPY_ARGS%
)

for %%F in (%SRC_RM%\lib\osvrRenderManager.lib) do (
xcopy %%F "%DEST_ROOT%\lib\Win%BITS%\" /Y
for %%F in (%SRC%\lib\osvrRenderManager.lib) do (
rem echo xcopy %%F "%DEST_ROOT%\lib\Win%BITS%\" %XCOPY_ARGS%
xcopy %%F "%DEST_ROOT%\lib\Win%BITS%\" %XCOPY_ARGS%
)

endlocal
Expand All @@ -111,15 +116,14 @@ goto :eof
rem Copy DLL files
setlocal
set SRC=%1
set SRC_RM=%2
set DEST=%3
set BITS=%4
set DEST=%2
set BITS=%3
for %%F in (%SRC%\bin\osvrClientKit.dll,%SRC%\bin\osvrClient.dll,%SRC%\bin\osvrUtil.dll,%SRC%\bin\osvrCommon.dll) do (
xcopy %%F "%DEST%\Win%BITS%\" /Y
xcopy %%F "%DEST%\Win%BITS%\" %XCOPY_ARGS%
)
for %%F in (%SRC_RM%\osvrRenderManager.dll,%SRC_RM%\d3dcompiler_47.dll,%SRC_RM%\glew32.dll,%SRC_RM%\SDL2.dll) do (
echo xcopy %%F "%DEST%\Win%BITS%\" /Y
xcopy %%F "%DEST%\Win%BITS%\" /Y
for %%F in (%SRC%\bin\osvrRenderManager.dll,%SRC%\bin\d3dcompiler_47.dll,%SRC%\bin\glew32.dll,%SRC%\bin\SDL2.dll) do (
rem echo xcopy %%F "%DEST%\Win%BITS%\" %XCOPY_ARGS%
xcopy %%F "%DEST%\Win%BITS%\" %XCOPY_ARGS%
)
endlocal
goto :eof
Expand Down
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": [ "Win64" ]
"WhitelistPlatforms": [ "Win32", "Win64" ]
},
{
"Name": "OSVRInput",
"Type": "Runtime",
"LoadingPhase": "PreDefault",
"WhitelistPlatforms": [ "Win64" ]
"WhitelistPlatforms": [ "Win32", "Win64" ]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class FCurrentCustomPresent : public FOSVRCustomPresent<ID3D11Device>
rc = osvrRenderManagerStartPresentRenderBuffers(&presentState);
check(rc == OSVR_RETURN_SUCCESS);
check(mRenderBuffers.Num() == mRenderInfos.Num() && mRenderBuffers.Num() == mViewportDescriptions.Num());
for (size_t i = 0; i < mRenderBuffers.Num(); i++)
for (int32 i = 0; i < mRenderBuffers.Num(); i++)
{
rc = osvrRenderManagerPresentRenderBufferD3D11(presentState, mRenderBuffers[i], mRenderInfos[i], mViewportDescriptions[i]);
check(rc == OSVR_RETURN_SUCCESS);
Expand Down Expand Up @@ -373,7 +373,7 @@ class FCurrentCustomPresent : public FOSVRCustomPresent<ID3D11Device>
hr = osvrRenderManagerStartRegisterRenderBuffers(&state);
check(hr == OSVR_RETURN_SUCCESS);

for (size_t i = 0; i < mRenderBuffers.Num(); i++)
for (int32 i = 0; i < mRenderBuffers.Num(); i++)
{
hr = osvrRenderManagerRegisterRenderBufferD3D11(state, mRenderBuffers[i]);
check(hr == OSVR_RETURN_SUCCESS);
Expand Down
21 changes: 16 additions & 5 deletions OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVREntryPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,23 @@ DEFINE_LOG_CATEGORY(OSVREntryPointLog);

OSVREntryPoint::OSVREntryPoint()
{
// avoid BuildCookRun hangs
if (IsRunningCommandlet() || IsRunningDedicatedServer())
{
UE_LOG(OSVREntryPointLog, Display, TEXT("OSVREntryPoint::OSVREntryPoint(): running as commandlet or dedicated server - skipping client context startup."));
return;
}

osvrClientAttemptServerAutoStart();

osvrClientContext = osvrClientInit("com.osvr.unreal.plugin");

{
bool bClientContextOK = false;
bool bFailure = false;
auto begin = FDateTime::Now().GetSecond();
auto end = begin + 3;
while (FDateTime::Now().GetSecond() < end && !bClientContextOK && !bFailure)
bool bFailure = false;
auto begin = FDateTime::Now().GetTicks();
auto end = begin + 3 * ETimespan::TicksPerSecond;
while (FDateTime::Now().GetTicks() < end && !bClientContextOK && !bFailure)
{
bClientContextOK = osvrClientCheckStatus(osvrClientContext) == OSVR_RETURN_SUCCESS;
if (!bClientContextOK)
Expand Down Expand Up @@ -71,7 +78,11 @@ OSVREntryPoint::~OSVREntryPoint()
InterfaceCollection = nullptr;
#endif

osvrClientShutdown(osvrClientContext);
if (osvrClientContext)
{
osvrClientShutdown(osvrClientContext);
}

osvrClientReleaseAutoStartedServer();
}

Expand Down
19 changes: 15 additions & 4 deletions OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRHMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "SharedPointer.h"
#include "SceneViewport.h"
#include "OSVREntryPoint.h"
#include "OSVRCustomPresentOpenGL.h"
#include "OSVRCustomPresentD3D11.h"

#include "Runtime/Core/Public/Misc/DateTime.h"

Expand All @@ -32,6 +34,7 @@
#include "AllowWindowsPlatformTypes.h"
#include <osvr/Util/ReturnCodesC.h>
#include <osvr/RenderKit/RenderManagerD3D11C.h>
#include <osvr/RenderKit/RenderManagerOpenGLC.h>
#include "HideWindowsPlatformTypes.h"
#else
#include <osvr/RenderKit/RenderManagerOpenGLC.h>
Expand Down Expand Up @@ -69,11 +72,19 @@ void FOSVRHMD::OnEndPlay()
void FOSVRHMD::StartCustomPresent()
{
#if PLATFORM_WINDOWS
if (!mCustomPresent && IsPCPlatform(GMaxRHIShaderPlatform) && !IsOpenGLPlatform(GMaxRHIShaderPlatform))
if (!mCustomPresent)
{
// currently, FCustomPresent creates its own client context, so no need to
// synchronize with the one from FOSVREntryPoint.
mCustomPresent = new FCurrentCustomPresent(nullptr/*osvrClientContext*/, mScreenScale);
if (IsOpenGLPlatform(GMaxRHIShaderPlatform))
{
mCustomPresent = new FOpenGLCustomPresent(nullptr/*osvrClientContext*/, mScreenScale);
}
else
{

// currently, FCustomPresent creates its own client context, so no need to
// synchronize with the one from FOSVREntryPoint.
mCustomPresent = new FDirect3D11CustomPresent(nullptr/*osvrClientContext*/, mScreenScale);
}
}
#endif
}
Expand Down
8 changes: 2 additions & 6 deletions OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRHMD.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@

#include <osvr/ClientKit/DisplayC.h>

#if PLATFORM_WINDOWS
#include "OSVRCustomPresentD3D11.h"
#else
#include "OSVRCustomPresentOpenGL.h"
#endif
#include "OSVRCustomPresent.h"

DECLARE_LOG_CATEGORY_EXTERN(OSVRHMDLog, Log, All);

Expand Down Expand Up @@ -207,5 +203,5 @@ class FOSVRHMD : public IHeadMountedDisplay, public ISceneViewExtension, public

OSVRHMDDescription HMDDescription;
OSVR_DisplayConfig DisplayConfig;
TRefCountPtr<FCurrentCustomPresent> mCustomPresent;
TRefCountPtr<FOSVRCustomPresent> mCustomPresent;
};
26 changes: 23 additions & 3 deletions OSVRUnreal/Plugins/OSVR/Source/OSVR/Private/OSVRRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ void FOSVRHMD::DrawDistortionMesh_RenderThread(FRenderingCompositePassContext& C
void FOSVRHMD::RenderTexture_RenderThread(FRHICommandListImmediate& rhiCmdList, FTexture2DRHIParamRef backBuffer, FTexture2DRHIParamRef srcTexture) const
{
check(IsInRenderingThread());
if (mCustomPresent && mCustomPresent->IsInitialized())
{
// the current custom present implementation may be allowing Unreal to
// allocate its render textures. If so, this is the first time we get
// access to the texture that was created.
mCustomPresent->RenderTexture_RenderThread(rhiCmdList, backBuffer, srcTexture);
}

// @todo should we add an FCustomPresent function
// to ask if we should draw the preview? The OpenGL
// custom present can draw distortion directly into
// the preview window for instance, making this
// redundant.
const uint32 viewportWidth = backBuffer->GetSizeX();
const uint32 viewportHeight = backBuffer->GetSizeY();

Expand All @@ -53,6 +66,8 @@ void FOSVRHMD::RenderTexture_RenderThread(FRHICommandListImmediate& rhiCmdList,
SetGlobalBoundShaderState(rhiCmdList, featureLevel, boundShaderState, RendererModule->GetFilterVertexDeclaration().VertexDeclarationRHI, *vertexShader, *pixelShader);

pixelShader->SetParameters(rhiCmdList, TStaticSamplerState<SF_Bilinear>::GetRHI(), srcTexture);

// @todo: do we need to ask mCustomPresent whether we should draw the preview or not?
RendererModule->DrawRectangle(
rhiCmdList,
0, 0, // X, Y
Expand Down Expand Up @@ -93,11 +108,15 @@ void FOSVRHMD::GetTimewarpMatrices_RenderThread(const struct FRenderingComposite
void FOSVRHMD::PreRenderViewFamily_RenderThread(FRHICommandListImmediate& RHICmdList, FSceneViewFamily& ViewFamily)
{
check(IsInRenderingThread());
if (mCustomPresent && !mCustomPresent->IsInitialized())
if (mCustomPresent)
{
mCustomPresent->Initialize();
// @todo make Initialize lazy and remove this if block
if(!mCustomPresent->IsInitialized())
{
mCustomPresent->Initialize();
}
}

FQuat lastHmdOrientation, hmdOrientation;
FVector lastHmdPosition, hmdPosition;
UpdateHeadPose(lastHmdOrientation, lastHmdPosition, hmdOrientation, hmdPosition);
Expand Down Expand Up @@ -192,6 +211,7 @@ void FOSVRHMD::UpdateViewport(bool bUseSeparateRenderTarget, const FViewport& In
bool FOSVRHMD::AllocateRenderTargetTexture(uint32 index, uint32 sizeX, uint32 sizeY, uint8 format, uint32 numMips, uint32 flags, uint32 targetableTextureFlags, FTexture2DRHIRef& outTargetableTexture, FTexture2DRHIRef& outShaderResourceTexture, uint32 numSamples)
{
check(index == 0);
check(IsInRenderingThread());
if (mCustomPresent && mCustomPresent->IsInitialized())
{
return mCustomPresent->AllocateRenderTargetTexture(index, sizeX, sizeY, format, numMips, flags, targetableTextureFlags, outTargetableTexture, outShaderResourceTexture, numSamples);
Expand Down
Loading