There are two separate interfaces that provide access to the DirectX devices one for DirectX 9 (ID3D9GraphicsWindow) and one for DirectX 10 (ID3D10GraphicsWindow).
To determine whether a particular version DirectX is enabled in a viewport, or whether DirectX is enable in the current viewport the following snippet can be used.
// return NULL if DirectX 9 is not being used
ID3D9GraphicsWindow* GetDirectX9Window(ViewExp* view)
{
if (!view) return NULL;
GraphicsWindow* gw = view->getGW();
if (!gw) return NULL;
return static_cast< ID3D9GraphicsWindow*>(gw->GetInterface( D3D9_GRAPHICS_WINDOW_INTERFACE_ID));
}
// return NULL if DirectX 10 is not being used
ID3D10GraphicsWindow* GetDirectX10Window(ViewExp* view)
{
if (!view) return NULL;
GraphicsWindow* gw = view->getGW();
if (!gw) return NULL;
return static_cast< ID3D10GraphicsWindow*>(gw->GetInterface( D3D10_GRAPHICS_WINDOW_INTERFACE_ID));
}
// Returns true if the active window supports DirectX 9 or DirectX 10
bool DoesActiveViewSupportDirectX()
{
// get the currently active viewport
ViewExp* view = GetCOREInterface()->GetActiveViewport();
// check if either DirectX 9 or DirectX 10 windows are available
boolb = GetDirectX9Window(view) || GetDirectX10Window(view);
// always release the viewport to avoid causing a memory lead
GetCOREInterface()->ReleaseViewport(view);
returnb;
}