From 39628c9575865e0be5ae44875989c01ac151ccd2 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 21 Sep 2016 02:37:53 +0300 Subject: [PATCH] Work around a calling convention mismatch between MinGW and VC++ --- source/openvr/openvrdevice.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/source/openvr/openvrdevice.cpp b/source/openvr/openvrdevice.cpp index 466a71f..f6f0bf1 100644 --- a/source/openvr/openvrdevice.cpp +++ b/source/openvr/openvrdevice.cpp @@ -50,8 +50,22 @@ OpenVRDevice::~OpenVRDevice() void OpenVRDevice::configure_view(StereoView &view) const { vr::IVRSystem *vr_sys = vr::VRSystem(); + +#if defined(__GNUC__) && defined(_WIN32) + /* Visual C++ passes the return value address as first stack parameter and + the this pointer in ecx. MinGW does the other way around. This trick + forces the function signature to match at machine code level. */ + typedef void (vr::IVRSystem::*FuncPtr)(vr::HmdMatrix34_t *, vr::EVREye); + FuncPtr get_eye_to_head_transform = reinterpret_cast(&vr::IVRSystem::GetEyeToHeadTransform); + + vr::HmdMatrix34_t left, right; + (vr_sys->*get_eye_to_head_transform)(&left, vr::Eye_Left); + (vr_sys->*get_eye_to_head_transform)(&right, vr::Eye_Right); +#else vr::HmdMatrix34_t left = vr_sys->GetEyeToHeadTransform(vr::Eye_Left); vr::HmdMatrix34_t right = vr_sys->GetEyeToHeadTransform(vr::Eye_Right); +#endif + view.set_eye_matrices(convert_matrix(left), convert_matrix(right)); } -- 2.45.2