BsD3D11Driver.cpp 2.4 KB

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