BsD3D9RenderWindow.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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, 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::getSyncData
  135. */
  136. UINT32 getSyncData(UINT8* buffer);
  137. protected:
  138. HINSTANCE mInstance;
  139. D3D9Device* mDevice;
  140. bool mDeviceValid;
  141. bool mIsExternal;
  142. D3DMULTISAMPLE_TYPE mMultisampleType;
  143. DWORD mMultisampleQuality;
  144. UINT mDisplayFrequency;
  145. unsigned int mVSyncInterval;
  146. DWORD mStyle;
  147. DWORD mWindowedStyle;
  148. DWORD mWindowedStyleEx;
  149. bool mIsDepthBuffered;
  150. bool mIsChild;
  151. HWND mHWnd;
  152. D3D9RenderWindowProperties mProperties;
  153. };
  154. /**
  155. * @brief Render window implementation for Windows.
  156. *
  157. * @note Sim thread only.
  158. */
  159. class BS_D3D9_EXPORT D3D9RenderWindow : public RenderWindow
  160. {
  161. public:
  162. ~D3D9RenderWindow() { }
  163. /**
  164. * @copydoc RenderWindow::screenToWindowPos
  165. */
  166. void getCustomAttribute(const String& name, void* pData) const;
  167. /**
  168. * @copydoc RenderWindow::screenToWindowPos
  169. */
  170. Vector2I screenToWindowPos(const Vector2I& screenPos) const;
  171. /**
  172. * @copydoc RenderWindow::windowToScreenPos
  173. */
  174. Vector2I windowToScreenPos(const Vector2I& windowPos) const;
  175. /**
  176. * @copydoc RenderWindow::getCore
  177. */
  178. SPtr<D3D9RenderWindowCore> getCore() const;
  179. protected:
  180. friend class D3D9RenderWindowManager;
  181. friend class D3D9RenderWindowCore;
  182. D3D9RenderWindow(const RENDER_WINDOW_DESC& desc, HINSTANCE instance);
  183. /**
  184. * @copydoc RenderWindowCore::getProperties
  185. */
  186. const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
  187. /**
  188. * @copydoc RenderWindow::setSyncData
  189. */
  190. void setSyncData(UINT8* buffer, UINT32 size);
  191. /**
  192. * @brief Retrieves internal window handle.
  193. */
  194. HWND getHWnd() const;
  195. private:
  196. HINSTANCE mInstance;
  197. D3D9RenderWindowProperties mProperties;
  198. };
  199. }