Okay, this got me further into it- but sadly not to an actual solution.
After reading here Not Found| Oculus and slightly between the lines elsewhere and doing my own experimentation, this is how I think OculusInitPlugin works:
UnitySetGraphicsDevice runs, which actual just runs EnumDisplayDevice() on each of the displays. My PC has about 7 of them, including two graphics cards. For each display, it gets the DeviceName, which is something like ‘\.\DISPLAY1\Monitor0’ which tells us almost nothing.
This is where the guessing starts- OculusInitPlugin talks to the Oculus Runtime, which knows which Display/Monitor the Rift is. It gets the monitor name (‘\.\DISPLAY1\Monitor0’ perhaps) from the Runtime- and if it matches the one that it’s currently looking at, it sets it as the active monitor and gets on with it.
Why this doesn’t work for our game? I’m not sure. I assume _DirectToRift is doing something very similar, and that works fine.
With my hacky dll, I can loop through each of the displays and check their names, but they’re never named “rift” or anything, just DisplayX\MonitorY.
thep, can you comment on a way to cast from the “void* device” passed into UnitySetGraphicsDevice to the LPCWSTR that EnumDisplayDevices takes? I tried a simple cast, but it blows up:
…
LPCWSTR lpd = static_cast(device);
if (EnumDisplayDevices(lpd,0,&dd2,0))
…
Again, I come back to thinking there’s some logic in OculusInitPlugin that is causing us to fail out of the block.
Thoughts?
My current plugin code, for the curious:
#include "UnityPluginInterface.h"
#include <windows.h>
#include <stdio.h>
#include <vector>
// --------------------------------------------------------------------------
// UnitySetGraphicsDevice
static int g_DeviceType = -1;
extern "C" void EXPORT_API UnitySetGraphicsDevice (void* device, int deviceType, int eventType)
{
if (eventType == 0 && deviceType != 4)
{
LPCWSTR lpd = static_cast<LPCWSTR>(device);
//string test = lpd.DeviceString;
DISPLAY_DEVICE dd;
memset(&dd, 0, sizeof(DISPLAY_DEVICE));
dd.cb = sizeof(dd);
DISPLAY_DEVICE dd2;
memset(&dd2, 0, sizeof(DISPLAY_DEVICE));
dd2.cb = sizeof(dd2);
int i = 0;
while (EnumDisplayDevices(NULL, i, &dd, 0))
{
printf(("Device Name: %s Device String: %s"), dd.DeviceName, dd.DeviceString);
if (EnumDisplayDevices(dd.DeviceName, 0, &dd2, 0))
{
printf(("Monitor Name: %s Monitor String: %s"), dd2.DeviceName, dd2.DeviceString);
}
i++;
}
}
}