BsD3D11Driver.cpp 2.8 KB

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