BsD3D11Driver.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsD3D11Driver.h"
  4. #include "BsD3D11VideoModeInfo.h"
  5. #include "Error/BsException.h"
  6. namespace bs { namespace ct
  7. {
  8. D3D11Driver::D3D11Driver(const D3D11Driver &ob)
  9. {
  10. mAdapterNumber = ob.mAdapterNumber;
  11. mAdapterIdentifier = ob.mAdapterIdentifier;
  12. mDXGIAdapter = ob.mDXGIAdapter;
  13. if(mDXGIAdapter)
  14. mDXGIAdapter->AddRef();
  15. construct();
  16. }
  17. D3D11Driver::D3D11Driver(UINT32 adapterNumber, IDXGIAdapter* pDXGIAdapter)
  18. {
  19. mAdapterNumber = adapterNumber;
  20. mDXGIAdapter = pDXGIAdapter;
  21. if(mDXGIAdapter)
  22. mDXGIAdapter->AddRef();
  23. pDXGIAdapter->GetDesc(&mAdapterIdentifier);
  24. construct();
  25. }
  26. D3D11Driver::~D3D11Driver()
  27. {
  28. SAFE_RELEASE(mDXGIAdapter);
  29. }
  30. void D3D11Driver::construct()
  31. {
  32. assert(mDXGIAdapter != nullptr);
  33. UINT32 outputIdx = 0;
  34. IDXGIOutput* output = nullptr;
  35. while(mDXGIAdapter->EnumOutputs(outputIdx, &output) != DXGI_ERROR_NOT_FOUND)
  36. {
  37. outputIdx++;
  38. SAFE_RELEASE(output);
  39. }
  40. mNumOutputs = outputIdx;
  41. mVideoModeInfo = bs_shared_ptr_new<D3D11VideoModeInfo>(mDXGIAdapter);
  42. }
  43. D3D11Driver& D3D11Driver::operator=(const D3D11Driver& ob)
  44. {
  45. mAdapterNumber = ob.mAdapterNumber;
  46. mAdapterIdentifier = ob.mAdapterIdentifier;
  47. if(ob.mDXGIAdapter)
  48. ob.mDXGIAdapter->AddRef();
  49. SAFE_RELEASE(mDXGIAdapter);
  50. mDXGIAdapter = ob.mDXGIAdapter;
  51. return *this;
  52. }
  53. String D3D11Driver::getDriverName() const
  54. {
  55. size_t size = wcslen(mAdapterIdentifier.Description);
  56. char* str = (char*)bs_alloc((UINT32)(size + 1));
  57. wcstombs(str, mAdapterIdentifier.Description, size);
  58. str[size] = '\0';
  59. String Description = str;
  60. bs_free(str);
  61. return String(Description );
  62. }
  63. String D3D11Driver::getDriverDescription() const
  64. {
  65. size_t size = wcslen(mAdapterIdentifier.Description);
  66. char* str = (char*)bs_alloc((UINT32)(size + 1));
  67. wcstombs(str, mAdapterIdentifier.Description, size);
  68. str[size] = '\0';
  69. String driverDescription = str;
  70. bs_free(str);
  71. StringUtil::trim(driverDescription);
  72. return driverDescription;
  73. }
  74. DXGI_OUTPUT_DESC D3D11Driver::getOutputDesc(UINT32 adapterOutputIdx) const
  75. {
  76. DXGI_OUTPUT_DESC desc;
  77. IDXGIOutput* output = nullptr;
  78. if(mDXGIAdapter->EnumOutputs(adapterOutputIdx, &output) == DXGI_ERROR_NOT_FOUND)
  79. {
  80. BS_EXCEPT(InvalidParametersException, "Cannot find output with the specified index: " + toString(adapterOutputIdx));
  81. }
  82. output->GetDesc(&desc);
  83. SAFE_RELEASE(output);
  84. return desc;
  85. }
  86. }}