BsD3D9RenderWindow.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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::move
  48. */
  49. void move(INT32 left, INT32 top);
  50. /**
  51. * @copydoc RenderWindowCore::resize
  52. */
  53. void resize(UINT32 width, UINT32 height);
  54. /**
  55. * @copydoc RenderWindowCore::getCustomAttribute
  56. */
  57. void getCustomAttribute(const String& name, void* pData) const;
  58. /**
  59. * @copydoc RenderWindowCore::copyContentsToMemory
  60. */
  61. void copyToMemory(PixelData &dst, FrameBuffer buffer);
  62. /**
  63. * @copydoc RenderWindowCore::swapBuffers
  64. */
  65. void swapBuffers();
  66. /**
  67. * @copydoc RenderWindowCore::_windowMovedOrResized
  68. */
  69. void _windowMovedOrResized();
  70. /**
  71. * @brief Gets internal Win32 window handle.
  72. */
  73. HWND _getWindowHandle() const;
  74. /**
  75. * @brief Gets the DirectX 9 device object that manages this window.
  76. */
  77. IDirect3DDevice9* _getD3D9Device() const;
  78. /**
  79. * @brief Gets the device that manages this window.
  80. */
  81. D3D9Device* _getDevice() const;
  82. /**
  83. * @brief Sets the device that manages this window.
  84. */
  85. void _setDevice(D3D9Device* device);
  86. /**
  87. * @brief Build the presentation parameters used with this window.
  88. */
  89. void _buildPresentParameters(D3DPRESENT_PARAMETERS* presentParams) const;
  90. /**
  91. * @brief Accessor for render surface.
  92. */
  93. IDirect3DSurface9* _getRenderSurface() const;
  94. /**
  95. * @brief Returns true if this window use depth buffer.
  96. */
  97. bool _isDepthBuffered() const;
  98. /**
  99. * @brief Validate the device for this window.
  100. */
  101. bool _validateDevice();
  102. protected:
  103. friend class D3D9RenderWindow;
  104. /**
  105. * @copydoc CoreObjectCore::initialize
  106. */
  107. virtual void initialize();
  108. /**
  109. * @brief Updates window coordinates and size from actual values provided by Windows.
  110. */
  111. void updateWindowRect();
  112. /**
  113. * @brief Calculates window size based on provided client area size and currently set window style.
  114. */
  115. void getAdjustedWindowSize(UINT32 clientWidth, UINT32 clientHeight,
  116. DWORD style, UINT32* winWidth, UINT32* winHeight);
  117. /**
  118. * @copydoc RenderWindowCore::getProperties
  119. */
  120. const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
  121. protected:
  122. HINSTANCE mInstance;
  123. D3D9Device* mDevice;
  124. bool mDeviceValid;
  125. bool mIsExternal;
  126. D3DMULTISAMPLE_TYPE mMultisampleType;
  127. DWORD mMultisampleQuality;
  128. UINT mDisplayFrequency;
  129. unsigned int mVSyncInterval;
  130. DWORD mStyle;
  131. DWORD mWindowedStyle;
  132. DWORD mWindowedStyleEx;
  133. bool mIsDepthBuffered;
  134. bool mIsChild;
  135. HWND mHWnd;
  136. D3D9RenderWindowProperties mProperties;
  137. };
  138. /**
  139. * @brief Render window implementation for Windows.
  140. *
  141. * @note Sim thread only.
  142. */
  143. class BS_D3D9_EXPORT D3D9RenderWindow : public RenderWindow
  144. {
  145. public:
  146. ~D3D9RenderWindow() { }
  147. /**
  148. * @copydoc RenderWindow::screenToWindowPos
  149. */
  150. void getCustomAttribute(const String& name, void* pData) const;
  151. /**
  152. * @copydoc RenderWindow::screenToWindowPos
  153. */
  154. Vector2I screenToWindowPos(const Vector2I& screenPos) const;
  155. /**
  156. * @copydoc RenderWindow::windowToScreenPos
  157. */
  158. Vector2I windowToScreenPos(const Vector2I& windowPos) const;
  159. /**
  160. * @copydoc RenderWindow::getCore
  161. */
  162. SPtr<D3D9RenderWindowCore> getCore() const;
  163. protected:
  164. friend class D3D9RenderWindowManager;
  165. friend class D3D9RenderWindowCore;
  166. D3D9RenderWindow(const RENDER_WINDOW_DESC& desc, HINSTANCE instance);
  167. /**
  168. * @copydoc RenderWindowCore::getProperties
  169. */
  170. const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
  171. /**
  172. * @brief Retrieves internal window handle.
  173. */
  174. HWND getHWnd() const;
  175. private:
  176. HINSTANCE mInstance;
  177. D3D9RenderWindowProperties mProperties;
  178. };
  179. }