From: Mikko Rasa Date: Tue, 20 Sep 2016 23:37:53 +0000 (+0300) Subject: Work around a calling convention mismatch between MinGW and VC++ X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=39628c9575865e0be5ae44875989c01ac151ccd2;p=libs%2Fvr.git Work around a calling convention mismatch between MinGW and VC++ --- 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)); }