BsD3D11DriverList.cpp 1.6 KB

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