Skip to content

Double-buffer native VR implementation #245

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

Open
wants to merge 7 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
2,154 changes: 207 additions & 1,947 deletions OSVR-Unity/Assets/OSVRUnity/Sample/Demo/Scenes/OSVR-UnityVR-Android-Demo.unity

Large diffs are not rendered by default.

2,711 changes: 2,087 additions & 624 deletions OSVR-Unity/Assets/OSVRUnity/Sample/Demo/Scenes/OSVR-UnityVR-Demo.unity

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions OSVR-Unity/Assets/OSVRUnity/src/ClientKit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ private void EnsureStarted()
if (!_osvrServerError)
{
_osvrServerError = true;
Debug.LogError("[OSVR-Unity] OSVR Server not detected. Start OSVR Server and restart the application.");
Debug.LogError("[OSVR-Unity] ClientKit:: OSVR Server not detected. Start OSVR Server and restart the application.");
}
}
else if (_osvrServerError)
{
Debug.Log("[OSVR-Unity] OSVR Server connection established. You can ignore previous errors about the server not being detected.");
Debug.Log("[OSVR-Unity] ClientKit:: OSVR Server connection established. You can ignore previous errors about the server not being detected.");
_osvrServerError = false;
}

Expand All @@ -161,17 +161,18 @@ void Awake()
Destroy(this.gameObject);
}
}
EnsureStarted();
}

void Start()
{
Debug.Log("[OSVR-Unity] In Start()");
Debug.Log("[OSVR-Unity] In ClientKit::Start()");
EnsureStarted();
}

void OnEnable()
{
Debug.Log("[OSVR-Unity] In OnEnable()");
Debug.Log("[OSVR-Unity] In ClientKit::OnEnable()");
EnsureStarted();
}

Expand All @@ -181,10 +182,11 @@ void Update()
_contextObject.update();
}

void LateUpdate()
//is there any merit to using lateupdate?
/* void LateUpdate()
{
_contextObject.update();
}
}*/

void Stop()
{
Expand All @@ -194,7 +196,7 @@ void Stop()
{
if (null != _contextObject)
{
Debug.Log("[OSVR-Unity] Shutting down OSVR.");
Debug.Log("[OSVR-Unity] ClientKit::Shutting down OSVR.");
_contextObject.Dispose();
_contextObject = null;
#if UNITY_STANDALONE_WIN || UNITY_ANDROID
Expand Down
2 changes: 1 addition & 1 deletion OSVR-Unity/Assets/OSVRUnity/src/DisplayController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void SetupDisplay()
//create RenderBuffers in RenderManager
if(UseRenderManager && RenderManager != null)
{
RenderManager.ConstructBuffers();
RenderManager.CreateBuffers();
}
SetRenderParams();
}
Expand Down
36 changes: 26 additions & 10 deletions OSVR-Unity/Assets/OSVRUnity/src/OsvrRenderManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ private struct OSVR_ViewportDescription
public double height; //< Last pixel on the right of the viewport in pixels
}

public const int RENDER_EVENT = 0;
public const int SHUTDOWN_EVENT = 1;
public const int CREATE_RENDERMANAGER_EVENT = 0;
public const int CREATE_RENDERBUFFERS_EVENT = 1;
public const int UPDATE_RENDERINFO_EVENT = 2;
public const int RENDER_EVENT = 3;
public const int RESET_YAW_EVENT = 4;
public const int SET_ROOM_ROTATION_EVENT = 5;
public const int CLEAR_ROOM_ROTATION_EVENT = 6;
public const int SHUTDOWN_RENDERMANAGER_EVENT = 7;

private const string PluginName = "osvrUnityRenderingPlugin";

[UnmanagedFunctionPointer(CallingConvention.Winapi)]
Expand All @@ -73,13 +79,18 @@ private struct OSVR_ViewportDescription
//Create and Register RenderBuffers
[DllImport(PluginName)]
private static extern Byte
ConstructRenderBuffers();
CreateRenderBuffers();

//Create a RenderManager object in the plugin, passing in a ClientContext
[DllImport(PluginName)]
private static extern Byte
CreateRenderManagerFromUnity(OSVR.ClientKit.SafeClientContextHandle /*OSVR_ClientContext*/ ctx);

//Pass a ClientContext to the Unity rendering plugin
[DllImport(PluginName)]
private static extern Byte
SetOsvrClientContextFromUnity(OSVR.ClientKit.SafeClientContextHandle /*OSVR_ClientContext*/ ctx);

[DllImport(PluginName)]
private static extern OSVR.ClientKit.Pose3
GetEyePose(int eye);
Expand Down Expand Up @@ -109,7 +120,7 @@ private static extern void
// If so, change the return type here to Byte
[DllImport(PluginName)]
private static extern int
SetColorBufferFromUnity(System.IntPtr texturePtr, int eye);
SetColorBufferFromUnity(System.IntPtr texturePtr, int eye, int buffer);

[DllImport(PluginName)]
private static extern void
Expand Down Expand Up @@ -195,11 +206,16 @@ public int InitRenderManager()
return CreateRenderManager(ClientKit.instance.context);
}

public int SetOsvrClientContext()
{
return SetOsvrClientContextFromUnity(ClientKit.instance.context.ContextHandle);
}

//Create and Register RenderBuffers in RenderManager
//Called after RM is created and after Unity RenderTexture's are created and assigned via SetEyeColorBuffer
public int ConstructBuffers()
public int CreateBuffers()
{
return ConstructRenderBuffers();
return CreateRenderBuffers();
}

public void SetNearClippingPlaneDistance(float near)
Expand All @@ -222,7 +238,7 @@ public void SetRoomRotationUsingHead()
{
#if UNITY_5_2 || UNITY_5_3 || UNITY_5_4 || UNITY_5_5 || UNITY_5_6 || UNITY_2017
ClientKit.instance.context.SetRoomRotationUsingHead();
GL.IssuePluginEvent(GetRenderEventFunc(), 3);
GL.IssuePluginEvent(GetRenderEventFunc(), SET_ROOM_ROTATION_EVENT);
#endif
}

Expand All @@ -231,7 +247,7 @@ public void ClearRoomToWorldTransform()
{
#if UNITY_5_2 || UNITY_5_3 || UNITY_5_4 || UNITY_5_5 || UNITY_5_6 || UNITY_2017
ClientKit.instance.context.ClearRoomToWorldTransform();
GL.IssuePluginEvent(GetRenderEventFunc(), 4);
GL.IssuePluginEvent(GetRenderEventFunc(), CLEAR_ROOM_ROTATION_EVENT);
#endif
}

Expand Down Expand Up @@ -311,9 +327,9 @@ public int CreateRenderManager(OSVR.ClientKit.ClientContext clientContext)
}

//Pass pointer to eye-camera RenderTexture to the Unity Rendering Plugin
public void SetEyeColorBuffer(IntPtr colorBuffer, int eye)
public void SetEyeColorBuffer(IntPtr colorBuffer, int eye, int buffer)
{
SetColorBufferFromUnity(colorBuffer, eye);
SetColorBufferFromUnity(colorBuffer, eye, buffer);
}

//Get a pointer to the plugin's rendering function
Expand Down
Loading