BsD3D11DriverList.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "BsD3D11DriverList.h"
  2. #include "BsD3D11Driver.h"
  3. #include "BsException.h"
  4. namespace BansheeEngine
  5. {
  6. D3D11DriverList::D3D11DriverList(IDXGIFactory* dxgiFactory)
  7. {
  8. enumerate(dxgiFactory);
  9. }
  10. D3D11DriverList::~D3D11DriverList(void)
  11. {
  12. for(size_t i = 0; i < mDriverList.size(); i++)
  13. {
  14. bs_delete(mDriverList[i]);
  15. }
  16. mDriverList.clear();
  17. }
  18. void D3D11DriverList::enumerate(IDXGIFactory* dxgiFactory)
  19. {
  20. UINT32 adapterIdx = 0;
  21. IDXGIAdapter* dxgiAdapter = nullptr;
  22. HRESULT hr;
  23. while((hr = dxgiFactory->EnumAdapters(adapterIdx, &dxgiAdapter)) != DXGI_ERROR_NOT_FOUND)
  24. {
  25. if( FAILED(hr) )
  26. {
  27. SAFE_RELEASE(dxgiAdapter);
  28. BS_EXCEPT(InternalErrorException, "Enumerating adapters failed.");
  29. }
  30. mDriverList.push_back(bs_new<D3D11Driver>(adapterIdx, dxgiAdapter));
  31. SAFE_RELEASE(dxgiAdapter);
  32. adapterIdx++;
  33. }
  34. }
  35. UINT32 D3D11DriverList::count() const
  36. {
  37. return (UINT32)mDriverList.size();
  38. }
  39. D3D11Driver* D3D11DriverList::item(UINT32 idx) const
  40. {
  41. return mDriverList.at(idx);
  42. }
  43. D3D11Driver* D3D11DriverList::item(const String &name) const
  44. {
  45. for (auto it = mDriverList.begin(); it != mDriverList.end(); ++it)
  46. {
  47. if ((*it)->getDriverDescription() == name)
  48. return (*it);
  49. }
  50. BS_EXCEPT(InvalidParametersException, "Cannot find video mode with the specified name.");
  51. }
  52. }