BsD3D11RenderWindow.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #pragma once
  2. #include "BsD3D11Prerequisites.h"
  3. #include "BsRenderWindow.h"
  4. namespace BansheeEngine
  5. {
  6. class D3D11RenderWindow;
  7. /**
  8. * @brief Contains various properties that describe a render window.
  9. */
  10. class BS_D3D11_EXPORT D3D11RenderWindowProperties : public RenderWindowProperties
  11. {
  12. public:
  13. D3D11RenderWindowProperties(const RENDER_WINDOW_DESC& desc);
  14. virtual ~D3D11RenderWindowProperties() { }
  15. private:
  16. friend class D3D11RenderWindowCore;
  17. friend class D3D11RenderWindow;
  18. };
  19. /**
  20. * @brief Render window implementation for Windows and DirectX 11.
  21. *
  22. * @note Core thread only.
  23. */
  24. class BS_D3D11_EXPORT D3D11RenderWindowCore : public RenderWindowCore
  25. {
  26. public:
  27. /**
  28. * @copydoc RenderWindowCore::RenderWindowCore
  29. */
  30. D3D11RenderWindowCore(const RENDER_WINDOW_DESC& desc,
  31. D3D11Device& device, IDXGIFactory* DXGIFactory);
  32. ~D3D11RenderWindowCore();
  33. /**
  34. * @copydoc RenderWindowCore::move
  35. */
  36. void move(INT32 left, INT32 top);
  37. /**
  38. * @copydoc RenderWindowCore::resize
  39. */
  40. void resize(UINT32 width, UINT32 height);
  41. /**
  42. * @copydoc RenderWindowCore::setHidden
  43. */
  44. void setHidden(bool hidden);
  45. /**
  46. * @copydoc RenderWindowCore::setActive
  47. */
  48. void setActive(bool state);
  49. /**
  50. * @copydoc RenderWindowCore::setFullscreen(UINT32, UINT32, float, UINT32)
  51. */
  52. void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0);
  53. /**
  54. * @copydoc RenderWindowCore::setFullscreen(const VideoMode&)
  55. */
  56. void setFullscreen(const VideoMode& mode);
  57. /**
  58. * @copydoc RenderWindowCore::setWindowed
  59. */
  60. void setWindowed(UINT32 width, UINT32 height);
  61. /**
  62. * @copydoc RenderWindowCore::copyContentsToMemory
  63. */
  64. void copyToMemory(PixelData &dst, FrameBuffer buffer);
  65. /**
  66. * @copydoc RenderWindowCore::swapBuffers
  67. */
  68. void swapBuffers();
  69. /**
  70. * @copydoc RenderWindowCore::getCustomAttribute
  71. */
  72. void getCustomAttribute(const String& name, void* pData) const;
  73. /**
  74. * @copydoc RenderWindowCore::_windowMovedOrResized
  75. */
  76. void _windowMovedOrResized();
  77. /**
  78. * @brief Returns presentation parameters used for creating the window swap chain.
  79. */
  80. DXGI_SWAP_CHAIN_DESC* _getPresentationParameters() { return &mSwapChainDesc; }
  81. /**
  82. * @brief Returns internal window handle.
  83. */
  84. HWND _getWindowHandle() const;
  85. protected:
  86. friend class D3D11RenderWindow;
  87. /**
  88. * @copydoc CoreObjectCore::initialize
  89. */
  90. virtual void initialize();
  91. /**
  92. * @brief Creates internal resources dependent on window size.
  93. */
  94. void createSizeDependedD3DResources();
  95. /**
  96. * @brief Destroys internal resources dependent on window size.
  97. */
  98. void destroySizeDependedD3DResources();
  99. /**
  100. * @brief Queries the current DXGI device. Make sure to release the returned object when done with it.
  101. */
  102. IDXGIDevice* queryDxgiDevice();
  103. /**
  104. * @brief Creates a swap chain for the window.
  105. */
  106. void createSwapChain();
  107. /**
  108. * @brief Resizes all buffers attached to the swap chain to the specified size.
  109. */
  110. void resizeSwapChainBuffers(UINT32 width, UINT32 height);
  111. /**
  112. * @copydoc RenderWindowCore::getProperties
  113. */
  114. const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
  115. protected:
  116. D3D11Device& mDevice;
  117. IDXGIFactory* mDXGIFactory;
  118. bool mIsExternal;
  119. bool mSizing;
  120. bool mIsChild;
  121. DXGI_SAMPLE_DESC mMultisampleType;
  122. UINT32 mRefreshRateNumerator;
  123. UINT32 mRefreshRateDenominator;
  124. ID3D11Texture2D* mBackBuffer;
  125. ID3D11RenderTargetView* mRenderTargetView;
  126. TextureViewPtr mDepthStencilView;
  127. SPtr<TextureCore> mDepthStencilBuffer;
  128. IDXGISwapChain* mSwapChain;
  129. DXGI_SWAP_CHAIN_DESC mSwapChainDesc;
  130. HWND mHWnd;
  131. D3D11RenderWindowProperties mProperties;
  132. };
  133. /**
  134. * @brief Render window implementation for Windows and DirectX 11.
  135. *
  136. * @note Sim thread only.
  137. */
  138. class BS_D3D11_EXPORT D3D11RenderWindow : public RenderWindow
  139. {
  140. public:
  141. ~D3D11RenderWindow() { }
  142. /**
  143. * @copydoc RenderWindow::screenToWindowPos
  144. */
  145. void getCustomAttribute(const String& name, void* pData) const;
  146. /**
  147. * @copydoc RenderWindow::screenToWindowPos
  148. */
  149. Vector2I screenToWindowPos(const Vector2I& screenPos) const;
  150. /**
  151. * @copydoc RenderWindow::windowToScreenPos
  152. */
  153. Vector2I windowToScreenPos(const Vector2I& windowPos) const;
  154. /**
  155. * @copydoc RenderWindow::getCore
  156. */
  157. SPtr<D3D11RenderWindowCore> getCore() const;
  158. protected:
  159. friend class D3D11RenderWindowManager;
  160. friend class D3D11RenderWindowCore;
  161. D3D11RenderWindow(const RENDER_WINDOW_DESC& desc, D3D11Device& device, IDXGIFactory* DXGIFactory);
  162. /**
  163. * @copydoc RenderWindowCore::getProperties
  164. */
  165. const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
  166. /**
  167. * @brief Retrieves internal window handle.
  168. */
  169. HWND getHWnd() const;
  170. private:
  171. D3D11Device& mDevice;
  172. IDXGIFactory* mDXGIFactory;
  173. D3D11RenderWindowProperties mProperties;
  174. };
  175. }