BsD3D11RenderWindow.h 4.7 KB

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