BsD3D9RenderWindow.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #pragma once
  2. #include "BsD3D9Prerequisites.h"
  3. #include "BsRenderWindow.h"
  4. #include "BsD3D9Device.h"
  5. namespace BansheeEngine
  6. {
  7. class D3D9RenderWindow;
  8. /**
  9. * @brief Contains various properties that describe a render window.
  10. */
  11. class BS_D3D9_EXPORT D3D9RenderWindowProperties : public RenderWindowProperties
  12. {
  13. public:
  14. D3D9RenderWindowProperties(const RENDER_WINDOW_DESC& desc);
  15. virtual ~D3D9RenderWindowProperties() { }
  16. private:
  17. friend class D3D9RenderWindowCore;
  18. friend class D3D9RenderWindow;
  19. };
  20. /**
  21. * @brief Render window implementation for Windows.
  22. *
  23. * @note Core thread only.
  24. */
  25. class BS_D3D9_EXPORT D3D9RenderWindowCore : public RenderWindowCore
  26. {
  27. public:
  28. D3D9RenderWindowCore(const RENDER_WINDOW_DESC& desc, UINT32 windowId, HINSTANCE instance);
  29. ~D3D9RenderWindowCore();
  30. /**
  31. * @copydoc RenderWindowCore::setFullscreen(UINT32, UINT32, float, UINT32)
  32. */
  33. void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0);
  34. /**
  35. * @copydoc RenderWindowCore::setFullscreen(const VideoMode&)
  36. */
  37. void setFullscreen(const VideoMode& mode);
  38. /**
  39. * @copydoc RenderWindowCore::setWindowed
  40. */
  41. void setWindowed(UINT32 width, UINT32 height);
  42. /**
  43. * @copydoc RenderWindowCore::setHidden
  44. */
  45. void setHidden(bool hidden);
  46. /**
  47. * @copydoc RenderWindowCore::minimize
  48. */
  49. void minimize();
  50. /**
  51. * @copydoc RenderWindowCore::maximize
  52. */
  53. void maximize();
  54. /**
  55. * @copydoc RenderWindowCore::restore
  56. */
  57. void restore();
  58. /**
  59. * @copydoc RenderWindowCore::move
  60. */
  61. void move(INT32 left, INT32 top);
  62. /**
  63. * @copydoc RenderWindowCore::resize
  64. */
  65. void resize(UINT32 width, UINT32 height);
  66. /**
  67. * @copydoc RenderWindowCore::getCustomAttribute
  68. */
  69. void getCustomAttribute(const String& name, void* pData) const;
  70. /**
  71. * @copydoc RenderWindowCore::copyContentsToMemory
  72. */
  73. void copyToMemory(PixelData &dst, FrameBuffer buffer);
  74. /**
  75. * @copydoc RenderWindowCore::swapBuffers
  76. */
  77. void swapBuffers();
  78. /**
  79. * @copydoc RenderWindowCore::_windowMovedOrResized
  80. */
  81. void _windowMovedOrResized();
  82. /**
  83. * @brief Gets internal Win32 window handle.
  84. */
  85. HWND _getWindowHandle() const;
  86. /**
  87. * @brief Gets the DirectX 9 device object that manages this window.
  88. */
  89. IDirect3DDevice9* _getD3D9Device() const;
  90. /**
  91. * @brief Gets the device that manages this window.
  92. */
  93. D3D9Device* _getDevice() const;
  94. /**
  95. * @brief Sets the device that manages this window.
  96. */
  97. void _setDevice(D3D9Device* device);
  98. /**
  99. * @brief Build the presentation parameters used with this window.
  100. */
  101. void _buildPresentParameters(D3DPRESENT_PARAMETERS* presentParams) const;
  102. /**
  103. * @brief Accessor for render surface.
  104. */
  105. IDirect3DSurface9* _getRenderSurface() const;
  106. /**
  107. * @brief Returns true if this window use depth buffer.
  108. */
  109. bool _isDepthBuffered() const;
  110. /**
  111. * @brief Validate the device for this window.
  112. */
  113. bool _validateDevice();
  114. protected:
  115. friend class D3D9RenderWindow;
  116. /**
  117. * @copydoc CoreObjectCore::initialize
  118. */
  119. virtual void initialize();
  120. /**
  121. * @brief Updates window coordinates and size from actual values provided by Windows.
  122. */
  123. void updateWindowRect();
  124. /**
  125. * @brief Calculates window size based on provided client area size and currently set window style.
  126. */
  127. void getAdjustedWindowSize(UINT32 clientWidth, UINT32 clientHeight,
  128. DWORD style, UINT32* winWidth, UINT32* winHeight);
  129. /**
  130. * @copydoc RenderWindowCore::getProperties
  131. */
  132. const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
  133. /**
  134. * @copydoc RenderWindowCore::getSyncedProperties
  135. */
  136. RenderWindowProperties& getSyncedProperties() override { return mSyncedProperties; }
  137. /**
  138. * @copydoc RenderWindowCore::syncProperties
  139. */
  140. void syncProperties() override;
  141. protected:
  142. HINSTANCE mInstance;
  143. D3D9Device* mDevice;
  144. bool mDeviceValid;
  145. bool mIsExternal;
  146. D3DMULTISAMPLE_TYPE mMultisampleType;
  147. DWORD mMultisampleQuality;
  148. UINT mDisplayFrequency;
  149. unsigned int mVSyncInterval;
  150. DWORD mStyle;
  151. DWORD mWindowedStyle;
  152. DWORD mWindowedStyleEx;
  153. bool mIsDepthBuffered;
  154. bool mIsChild;
  155. HWND mHWnd;
  156. D3D9RenderWindowProperties mProperties;
  157. D3D9RenderWindowProperties mSyncedProperties;
  158. };
  159. /**
  160. * @brief Render window implementation for Windows.
  161. *
  162. * @note Sim thread only.
  163. */
  164. class BS_D3D9_EXPORT D3D9RenderWindow : public RenderWindow
  165. {
  166. public:
  167. ~D3D9RenderWindow() { }
  168. /**
  169. * @copydoc RenderWindow::screenToWindowPos
  170. */
  171. void getCustomAttribute(const String& name, void* pData) const;
  172. /**
  173. * @copydoc RenderWindow::screenToWindowPos
  174. */
  175. Vector2I screenToWindowPos(const Vector2I& screenPos) const;
  176. /**
  177. * @copydoc RenderWindow::windowToScreenPos
  178. */
  179. Vector2I windowToScreenPos(const Vector2I& windowPos) const;
  180. /**
  181. * @copydoc RenderWindow::getCore
  182. */
  183. SPtr<D3D9RenderWindowCore> getCore() const;
  184. protected:
  185. friend class D3D9RenderWindowManager;
  186. friend class D3D9RenderWindowCore;
  187. D3D9RenderWindow(const RENDER_WINDOW_DESC& desc, UINT32 windowId, HINSTANCE instance);
  188. /**
  189. * @copydoc RenderWindowCore::getProperties
  190. */
  191. const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
  192. /**
  193. * @copydoc RenderWindow::syncProperties
  194. */
  195. void syncProperties() override;
  196. /**
  197. * @brief Retrieves internal window handle.
  198. */
  199. HWND getHWnd() const;
  200. private:
  201. HINSTANCE mInstance;
  202. D3D9RenderWindowProperties mProperties;
  203. };
  204. }