GFX now handles non-default adapters

The GFX (DirectX) pipeline did not respect the choice of adapter and
always went for the default one.  Normally this isn't an issue unless
you wish to target a particular adapter and display device combination.
This has been corrected.

The GFX initialize functions now attempt to find the best adapter that
matches a given display device (i.e. monitor) if one has been passed in.
To aid with choosing a display device some new monitor enumeration
methods have been added to the platform window manager.  These methods
have been exposed to the Canvas.
This commit is contained in:
DavidWyand-GG 2013-04-09 12:50:17 -04:00
parent 1ed1a41256
commit 0d77cdc270
18 changed files with 282 additions and 45 deletions

View file

@ -71,6 +71,25 @@ public:
/// @return The current desktop bit depth, or Point2I(-1,-1) if an error occurred
virtual Point2I getDesktopResolution() = 0;
// Build out the monitor list.
virtual void buildMonitorsList() {}
// Find the first monitor index that matches the given name. The actual match
// algorithm depends on the implementation. Provides a default value of -1 to
// indicate no match.
virtual S32 findFirstMatchingMonitor(const char* name) { return -1; }
// Retrieve the number of monitors. Provides a default count of 0 for systems that
// don't provide information on connected monitors.
virtual U32 getMonitorCount() { return 0; }
// Get the name of the requested monitor. Provides a default of "" for platorms
// that do not provide information on connected monitors.
virtual const char* getMonitorName(U32 index) { return ""; }
// Get the requested monitor's rectangular region.
virtual RectI getMonitorRect(U32 index) { return RectI(0, 0, 0, 0); }
/// Populate a vector with all monitors and their extents in window space.
virtual void getMonitorRegions(Vector<RectI> &regions) = 0;

View file

@ -667,6 +667,9 @@ LRESULT PASCAL Win32Window::WindowProc( HWND hWnd, UINT message, WPARAM wParam,
{
case WM_DISPLAYCHANGE:
// Update the monitor list
PlatformWindowManager::get()->buildMonitorsList();
if(window && window->isVisible() && !window->mSuppressReset && window->getVideoMode().bitDepth != wParam)
{
Con::warnf("Win32Window::WindowProc - resetting device due to display mode BPP change.");

View file

@ -52,6 +52,8 @@ Win32WindowManager::Win32WindowManager()
mCurtainWindow = NULL;
mOffscreenRender = false;
buildMonitorsList();
}
Win32WindowManager::~Win32WindowManager()
@ -106,6 +108,74 @@ S32 Win32WindowManager::getDesktopBitDepth()
}
BOOL Win32WindowManager::MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData )
{
Vector<MonitorInfo> * monitors = (Vector<MonitorInfo>*)dwData;
// Fill out the new monitor structure
monitors->increment();
MonitorInfo& monitor = monitors->last();
monitor.monitorHandle = hMonitor;
monitor.region.point.x = lprcMonitor->left;
monitor.region.point.y = lprcMonitor->top;
monitor.region.extent.x = lprcMonitor->right - lprcMonitor->left;
monitor.region.extent.y = lprcMonitor->bottom - lprcMonitor->top;
MONITORINFOEX info;
info.cbSize = sizeof(MONITORINFOEX);
if(GetMonitorInfo(hMonitor, &info))
{
monitor.name = info.szDevice;
}
return true;
}
void Win32WindowManager::buildMonitorsList()
{
// Clear the list
mMonitors.clear();
// Enumerate all monitors
EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, (U32)(void*)&mMonitors);
}
S32 Win32WindowManager::findFirstMatchingMonitor(const char* name)
{
// Try and match the first part of the output device display name. For example,
// a Monitor name of "\\.\DISPLAY1" might correspond to a display name
// of "\\.\DISPLAY1\Monitor0". If two monitors are set up in duplicate mode then
// they will have the same 'display' part in their display name.
for(U32 i=0; i<mMonitors.size(); ++i)
{
if(dStrstr(name, mMonitors[i].name) == name)
return i;
}
return -1;
}
U32 Win32WindowManager::getMonitorCount()
{
return mMonitors.size();
}
const char* Win32WindowManager::getMonitorName(U32 index)
{
if(index >= mMonitors.size())
return "";
return mMonitors[index].name.c_str();
}
RectI Win32WindowManager::getMonitorRect(U32 index)
{
if(index >= mMonitors.size())
return RectI(0, 0, 0, 0);
return mMonitors[index].region;
}
BOOL Win32WindowManager::MonitorRegionEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData )
{
Vector<RectI> * regions = (Vector<RectI>*)dwData;
@ -120,7 +190,7 @@ BOOL Win32WindowManager::MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRE
void Win32WindowManager::getMonitorRegions(Vector<RectI> &regions)
{
EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, (U32)(void*)&regions);
EnumDisplayMonitors(NULL, NULL, MonitorRegionEnumProc, (U32)(void*)&regions);
}
void Win32WindowManager::getWindows(VectorPtr<PlatformWindow*> &windows)

View file

@ -56,6 +56,16 @@ class Win32WindowManager : public PlatformWindowManager
// is intended for offscreen rendering
bool mOffscreenRender;
/// Internal structure used when enumerating monitors
struct MonitorInfo {
HMONITOR monitorHandle;
RectI region;
String name;
};
/// Array of enumerated monitors
Vector<MonitorInfo> mMonitors;
/// Callback to receive information about available monitors.
static BOOL CALLBACK MonitorEnumProc(
HMONITOR hMonitor, // handle to display monitor
@ -64,6 +74,14 @@ class Win32WindowManager : public PlatformWindowManager
LPARAM dwData // data
);
/// Callback to receive information about available monitor regions
static BOOL CALLBACK MonitorRegionEnumProc(
HMONITOR hMonitor, // handle to display monitor
HDC hdcMonitor, // handle to monitor DC
LPRECT lprcMonitor, // monitor intersection rectangle
LPARAM dwData // data
);
/// If a curtain window is present, then its HWND will be stored here.
HWND mCurtainWindow;
@ -75,6 +93,15 @@ public:
virtual S32 getDesktopBitDepth();
virtual Point2I getDesktopResolution();
/// Build out the monitors list. Also used to rebuild the list after
/// a WM_DISPLAYCHANGE message.
virtual void buildMonitorsList();
virtual S32 findFirstMatchingMonitor(const char* name);
virtual U32 getMonitorCount();
virtual const char* getMonitorName(U32 index);
virtual RectI getMonitorRect(U32 index);
virtual void getMonitorRegions(Vector<RectI> &regions);
virtual PlatformWindow *createWindow(GFXDevice *device, const GFXVideoMode &mode);
virtual void getWindows(VectorPtr<PlatformWindow*> &windows);