Determining DirectX Version

The interface that provides access to DirectX devices is ID3D9GraphicsWindow (for DirectX 9). DirectX 10 is no longer supported.

To determine whether DirectX 9 is enabled in a viewport, or whether DirectX 9 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));
}


// Returns true if the active window supports DirectX 9 
bool DoesActiveViewSupportDirectX9()
{
  // get the currently active viewport
  ViewExp* view = GetCOREInterface()->GetActiveViewport();

  // check if DirectX 9 windows are available
  bool b = GetDirectX9Window(view) ;

  // always release the viewport to avoid causing a memory lead
  GetCOREInterface()->ReleaseViewport(view);

  return b;
}