Skip to content

New data types #32

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 9 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
67 changes: 59 additions & 8 deletions OsvrRenderingPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ static double s_nearClipDistance = 0.1;
static double s_farClipDistance = 1000.0;
/// @todo is this redundant? (given renderParams)
static double s_ipd = 0.063;
//cached viewport values
static std::uint32_t viewportWidth = 0;
static std::uint32_t viewportHeight = 0;

#if defined(ENABLE_LOGGING) && defined(ENABLE_LOGFILE)
static std::ofstream s_debugLogFile;
Expand Down Expand Up @@ -634,7 +637,7 @@ inline void CleanupBufferD3D11(osvr::renderkit::RenderBuffer &rb) {

OSVR_ReturnCode UNITY_INTERFACE_API ConstructRenderBuffers() {
if (!s_deviceType) {
DebugLog("Device type not supported.");
DebugLog("[OSVR Rendering Plugin] Device type not supported.");
return OSVR_RETURN_FAILURE;
}
UpdateRenderInfo();
Expand Down Expand Up @@ -677,17 +680,65 @@ void UNITY_INTERFACE_API SetIPD(double ipdMeters) {
}

osvr::renderkit::OSVR_ViewportDescription UNITY_INTERFACE_API
GetViewport(int eye) {
return s_renderInfo[eye].viewport;
GetViewport(std::uint8_t eye) {
osvr::renderkit::OSVR_ViewportDescription viewportDescription;
if (s_renderInfo.size() > 0 && eye <= s_renderInfo.size() - 1)
{
viewportDescription = s_renderInfo[eye].viewport;

//cache the viewport width and height
//patches issue where sometimes empty viewport is returned
//@todo fix the real cause of why this method bugs out occasionally on some machines, more often on others
if (viewportWidth == 0 && s_renderInfo[eye].viewport.width != 0)
{
viewportWidth = s_renderInfo[eye].viewport.width;
}
if (viewportHeight == 0 && s_renderInfo[eye].viewport.height != 0)
{
viewportHeight = s_renderInfo[eye].viewport.height;
}
}
else
{
//we shouldn't be here unless we hit a bug, in which case, we avoid error by returning cached viewport values
std::string errorLog = "[OSVR Rendering Plugin] Error in GetViewport, returning cached values. Eye = " + std::to_string(int(eye));
DebugLog(errorLog.c_str());
viewportDescription.left = 0;
viewportDescription.lower = 0;
viewportDescription.width = viewportWidth;
viewportDescription.height = viewportHeight;
}
return viewportDescription;
}

osvr::renderkit::OSVR_ProjectionMatrix UNITY_INTERFACE_API
GetProjectionMatrix(int eye) {
return s_renderInfo[eye].projection;
GetProjectionMatrix(std::uint8_t eye) {
osvr::renderkit::OSVR_ProjectionMatrix pm;
if (s_renderInfo.size() > 0 && eye <= s_renderInfo.size() - 1)
{
pm = s_renderInfo[eye].projection;
}
else
{
std::string errorLog = "[OSVR Rendering Plugin] Error in GetProjectionMatrix, returning default values. Eye = " + std::to_string(int(eye));
DebugLog(errorLog.c_str());
}
return pm;
}

OSVR_Pose3 UNITY_INTERFACE_API GetEyePose(int eye) {
return s_renderInfo[eye].pose;
OSVR_Pose3 UNITY_INTERFACE_API GetEyePose(std::uint8_t eye) {
OSVR_Pose3 pose;
osvrPose3SetIdentity(&pose);
if (s_renderInfo.size() > 0 && eye <= s_renderInfo.size() - 1)
{
pose = s_renderInfo[eye].pose;
}
else
{
std::string errorLog = "[OSVR Rendering Plugin] Error in GetEyePose, returning default values. Eye = " + std::to_string(int(eye));
DebugLog(errorLog.c_str());
}
return pose;
}

// --------------------------------------------------------------------------
Expand All @@ -703,7 +754,7 @@ OSVR_Pose3 UNITY_INTERFACE_API GetEyePose(int eye) {
// to set up needed texture pointers only at initialization time.
// For more reference, see:
// http://docs.unity3d.com/ScriptReference/Texture.GetNativeTexturePtr.html
int UNITY_INTERFACE_API SetColorBufferFromUnity(void *texturePtr, int eye) {
int UNITY_INTERFACE_API SetColorBufferFromUnity(void *texturePtr, std::uint8_t eye) {
if (!s_deviceType) {
return OSVR_RETURN_FAILURE;
}
Expand Down
9 changes: 5 additions & 4 deletions OsvrRenderingPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Sensics, Inc.
#include <osvr/RenderKit/RenderKitGraphicsTransforms.h>
#include <osvr/Util/ClientOpaqueTypesC.h>
#include <osvr/Util/ReturnCodesC.h>
#include <cstdint>

typedef void(UNITY_INTERFACE_API *DebugFnPtr)(const char *);

Expand All @@ -45,26 +46,26 @@ ConstructRenderBuffers();
UNITY_INTERFACE_EXPORT OSVR_ReturnCode UNITY_INTERFACE_API
CreateRenderManagerFromUnity(OSVR_ClientContext context);

UNITY_INTERFACE_EXPORT OSVR_Pose3 UNITY_INTERFACE_API GetEyePose(int eye);
UNITY_INTERFACE_EXPORT OSVR_Pose3 UNITY_INTERFACE_API GetEyePose(std::uint8_t eye);

UNITY_INTERFACE_EXPORT osvr::renderkit::OSVR_ProjectionMatrix
UNITY_INTERFACE_API
GetProjectionMatrix(int eye);
GetProjectionMatrix(std::uint8_t eye);

UNITY_INTERFACE_EXPORT UnityRenderingEvent UNITY_INTERFACE_API
GetRenderEventFunc();

UNITY_INTERFACE_EXPORT osvr::renderkit::OSVR_ViewportDescription
UNITY_INTERFACE_API
GetViewport(int eye);
GetViewport(std::uint8_t eye);

UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API LinkDebug(DebugFnPtr d);

UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API OnRenderEvent(int eventID);

/// @todo should return OSVR_ReturnCode
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API
SetColorBufferFromUnity(void *texturePtr, int eye);
SetColorBufferFromUnity(void *texturePtr, std::uint8_t eye);

UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API
SetFarClipDistance(double distance);
Expand Down