BsD3D11DriverList.cpp 1.7 KB

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