2
0

CmD3D11Driver.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include "CmD3D11Driver.h"
  2. #include "CmException.h"
  3. namespace BansheeEngine
  4. {
  5. D3D11Driver::D3D11Driver( const D3D11Driver &ob )
  6. {
  7. mAdapterNumber = ob.mAdapterNumber;
  8. mAdapterIdentifier = ob.mAdapterIdentifier;
  9. mDXGIAdapter = ob.mDXGIAdapter;
  10. if(mDXGIAdapter)
  11. mDXGIAdapter->AddRef();
  12. init();
  13. }
  14. D3D11Driver::D3D11Driver(unsigned int adapterNumber, IDXGIAdapter* pDXGIAdapter)
  15. {
  16. mAdapterNumber = adapterNumber;
  17. mDXGIAdapter = pDXGIAdapter;
  18. if(mDXGIAdapter)
  19. mDXGIAdapter->AddRef();
  20. // get the description of the adapter
  21. pDXGIAdapter->GetDesc(&mAdapterIdentifier);
  22. init();
  23. }
  24. D3D11Driver::~D3D11Driver()
  25. {
  26. SAFE_RELEASE(mDXGIAdapter);
  27. }
  28. void D3D11Driver::init()
  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. }
  40. D3D11Driver& D3D11Driver::operator=(const D3D11Driver& ob)
  41. {
  42. mAdapterNumber = ob.mAdapterNumber;
  43. mAdapterIdentifier = ob.mAdapterIdentifier;
  44. if(ob.mDXGIAdapter)
  45. ob.mDXGIAdapter->AddRef();
  46. SAFE_RELEASE(mDXGIAdapter);
  47. mDXGIAdapter=ob.mDXGIAdapter;
  48. return *this;
  49. }
  50. String D3D11Driver::getDriverName() const
  51. {
  52. size_t size = wcslen(mAdapterIdentifier.Description);
  53. char* str = (char*)cm_alloc<ScratchAlloc>((UINT32)(size + 1));
  54. wcstombs(str, mAdapterIdentifier.Description, size);
  55. str[size] = '\0';
  56. String Description = str;
  57. cm_free<ScratchAlloc>(str);
  58. return String(Description );
  59. }
  60. String D3D11Driver::getDriverDescription() const
  61. {
  62. size_t size = wcslen(mAdapterIdentifier.Description);
  63. char* str = (char*)cm_alloc<ScratchAlloc>((UINT32)(size + 1));
  64. wcstombs(str, mAdapterIdentifier.Description, size);
  65. str[size] = '\0';
  66. String driverDescription = str;
  67. cm_free<ScratchAlloc>(str);
  68. StringUtil::trim(driverDescription);
  69. return driverDescription;
  70. }
  71. DXGI_OUTPUT_DESC D3D11Driver::getOutputDesc(UINT32 adapterOutputIdx) const
  72. {
  73. DXGI_OUTPUT_DESC desc;
  74. IDXGIOutput* output = nullptr;
  75. if(mDXGIAdapter->EnumOutputs(adapterOutputIdx, &output) == DXGI_ERROR_NOT_FOUND)
  76. {
  77. CM_EXCEPT(InvalidParametersException, "Cannot find output with the specified index: " + toString(adapterOutputIdx));
  78. }
  79. output->GetDesc(&desc);
  80. SAFE_RELEASE(output);
  81. return desc;
  82. }
  83. }